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
|
|---|---|---|---|---|---|---|---|---|
Honry/crosswalk-test-suite
|
webapi/tct-csp-w3c-tests/csp-py/csp_frame-src_cross-origin_multi_allowed_one-manual.py
|
30
|
2514
|
def main(request, response):
import simplejson as json
f = file('config.json')
source = f.read()
s = json.JSONDecoder().decode(source)
url1 = "http://" + s['host'] + ":" + str(s['ports']['http'][1])
url2 = "http://" + s['host'] + ":" + str(s['ports']['http'][0])
_CSP = "frame-src " + url1 + " " + url2
response.headers.set("Content-Security-Policy", _CSP)
response.headers.set("X-Content-Security-Policy", _CSP)
response.headers.set("X-WebKit-CSP", _CSP)
return """<!DOCTYPE html>
<!--
Copyright (c) 2013 Intel Corporation.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of works must retain the original copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the original 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 Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this work without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "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 INTEL CORPORATION 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.
Authors:
Hao, Yunfei <yunfeix.hao@intel.com>
-->
<html>
<head>
<title>CSP Test: csp_frame-src_cross-origin_allowed_one</title>
<link rel="author" title="Intel" href="http://www.intel.com"/>
<link rel="help" href="http://www.w3.org/TR/2012/CR-CSP-20121115/#frame-src"/>
<meta name="flags" content=""/>
<meta charset="utf-8"/>
</head>
<body>
<p>Test passes if there is a filled green square.</p>
<iframe frameborder="no" border="0" src='""" + url1 + """/tests/csp/support/green-100x100.png'/>
</body>
</html> """
|
bsd-3-clause
|
[
318,
2446,
8,
1069,
12,
1177,
304,
272,
492,
13804,
465,
2022,
272,
289,
275,
570,
360,
888,
14,
1001,
358,
272,
1350,
275,
289,
14,
739,
342,
272,
308,
275,
2022,
14,
6243,
8326,
1252,
2708,
8,
1365,
9,
272,
1166,
17,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
17,
566,
272,
1166,
18,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
16,
566,
272,
485,
30635,
275,
298,
1943,
13,
2164,
298,
435,
1166,
17,
435,
298,
298,
435,
1166,
18,
272,
1177,
14,
2139,
14,
409,
480,
2714,
13,
7676,
13,
4845,
401,
485,
30635,
9,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
2714,
13,
7676,
13,
4845,
401,
485,
30635,
9,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
21666,
13,
30635,
401,
485,
30635,
9,
272,
372,
8894,
1,
16556,
3517,
30,
199,
25273,
199,
7384,
334,
67,
9,
6171,
20619,
11098,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
1530,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
10,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
769,
523,
402,
3704,
436,
314,
2569,
6450,
14,
199,
10,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
4245,
12,
523,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
523,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
10,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
523,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
523,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3359,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
37,
8253,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
2817,
1384,
26,
267,
869,
8035,
12,
1488,
324,
771,
73,
665,
89,
324,
771,
1148,
14,
2411,
79,
32,
22264,
14,
957,
30,
199,
199,
31647,
199,
199,
28,
1360,
30,
523,
665,
2993,
30,
272,
665,
1213,
30,
30635,
1379,
26,
286,
681,
63,
1943,
13,
2164,
63,
7925,
13,
6493,
63,
6541,
63,
368,
1108,
1213,
30,
272,
665,
1073,
4668,
628,
2502,
2,
2538,
628,
27528,
2,
4369,
628,
1014,
921,
1544,
14,
22264,
14,
957,
7897,
272,
665,
1073,
4668,
628,
3437,
2,
4369,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
7409,
15,
2944,
13,
30635,
13,
7409,
845,
1046,
12645,
1943,
13,
2164,
7897,
272,
665,
2024,
536,
628,
2469,
2,
1564,
9287,
3133,
272,
665,
2024,
5960,
628,
1624,
13,
24,
7897,
523,
3068,
2993,
30,
523,
665,
2030,
30,
272,
665,
80,
30,
774,
14933,
340,
2337,
365,
282,
13457,
12431,
12386,
9758,
80,
30,
272,
665,
20052,
2787,
8665,
628,
889,
2,
9162,
628,
16,
2,
2928,
534,
624,
435,
1166,
17,
435,
408,
15,
2219,
15,
30608,
15,
4058,
15,
7731,
13,
1960,
88,
1960,
14,
4524,
22619,
523,
3068,
2030,
30,
199,
1108,
1360,
30,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
492,
13804,
465,
2022,
272,
289,
275,
570,
360,
888,
14,
1001,
358,
272,
1350,
275,
289,
14,
739,
342,
272,
308,
275,
2022,
14,
6243,
8326,
1252,
2708,
8,
1365,
9,
272,
1166,
17,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
17,
566,
272,
1166,
18,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
16,
566,
272,
485,
30635,
275,
298,
1943,
13,
2164,
298,
435,
1166,
17,
435,
298,
298,
435,
1166,
18,
272,
1177,
14,
2139,
14,
409,
480,
2714,
13,
7676,
13,
4845,
401,
485,
30635,
9,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
2714,
13,
7676,
13,
4845,
401,
485,
30635,
9,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
21666,
13,
30635,
401,
485,
30635,
9,
272,
372,
8894,
1,
16556,
3517,
30,
199,
25273,
199,
7384,
334,
67,
9,
6171,
20619,
11098,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
1530,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
10,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
769,
523,
402,
3704,
436,
314,
2569,
6450,
14,
199,
10,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
4245,
12,
523,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
523,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
10,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
523,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
523,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3359,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
37,
8253,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
2817,
1384,
26,
267,
869,
8035,
12,
1488,
324,
771,
73,
665,
89,
324,
771,
1148,
14,
2411,
79,
32,
22264,
14,
957,
30,
199,
199,
31647,
199,
199,
28,
1360,
30,
523,
665,
2993,
30,
272,
665,
1213,
30,
30635,
1379,
26,
286,
681,
63,
1943,
13,
2164,
63,
7925,
13,
6493,
63,
6541,
63,
368,
1108,
1213,
30,
272,
665,
1073,
4668,
628,
2502,
2,
2538,
628,
27528,
2,
4369,
628,
1014,
921,
1544,
14,
22264,
14,
957,
7897,
272,
665,
1073,
4668,
628,
3437,
2,
4369,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
7409,
15,
2944,
13,
30635,
13,
7409,
845,
1046,
12645,
1943,
13,
2164,
7897,
272,
665,
2024,
536,
628,
2469,
2,
1564,
9287,
3133,
272,
665,
2024,
5960,
628,
1624,
13,
24,
7897,
523,
3068,
2993,
30,
523,
665,
2030,
30,
272,
665,
80,
30,
774,
14933,
340,
2337,
365,
282,
13457,
12431,
12386,
9758,
80,
30,
272,
665,
20052,
2787,
8665,
628,
889,
2,
9162,
628,
16,
2,
2928,
534,
624,
435,
1166,
17,
435,
408,
15,
2219,
15,
30608,
15,
4058,
15,
7731,
13,
1960,
88,
1960,
14,
4524,
22619,
523,
3068,
2030,
30,
199,
1108,
1360,
30,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
bnoordhuis/suv
|
deps/gyp/test/mac/gyptest-sourceless-module.py
|
200
|
2485
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that bundles that have no 'sources' (pure resource containers) work.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='sourceless-module')
# Just needs to build without errors.
test.build('test.gyp', 'empty_bundle', chdir='sourceless-module')
test.built_file_must_not_exist(
'empty_bundle.bundle', chdir='sourceless-module')
# Needs to build, and contain a resource.
test.build('test.gyp', 'resource_bundle', chdir='sourceless-module')
test.built_file_must_exist(
'resource_bundle.bundle/Contents/Resources/foo.manifest',
chdir='sourceless-module')
test.built_file_must_not_exist(
'resource_bundle.bundle/Contents/MacOS/resource_bundle',
chdir='sourceless-module')
# Build an app containing an actionless bundle.
test.build(
'test.gyp',
'bundle_dependent_on_resource_bundle_no_actions',
chdir='sourceless-module')
test.built_file_must_exist(
'bundle_dependent_on_resource_bundle_no_actions.app/Contents/Resources/'
'mac_resource_bundle_no_actions.bundle/Contents/Resources/empty.txt',
chdir='sourceless-module')
# Needs to build and cause the bundle to be built.
test.build(
'test.gyp', 'dependent_on_resource_bundle', chdir='sourceless-module')
test.built_file_must_exist(
'resource_bundle.bundle/Contents/Resources/foo.manifest',
chdir='sourceless-module')
test.built_file_must_not_exist(
'resource_bundle.bundle/Contents/MacOS/resource_bundle',
chdir='sourceless-module')
# TODO(thakis): shared_libraries that have no sources but depend on static
# libraries currently only work with the ninja generator. This is used by
# chrome/mac's components build.
if test.format == 'ninja':
# Check that an executable depending on a resource framework links fine too.
test.build(
'test.gyp', 'dependent_on_resource_framework', chdir='sourceless-module')
test.built_file_must_exist(
'resource_framework.framework/Resources/foo.manifest',
chdir='sourceless-module')
test.built_file_must_exist(
'resource_framework.framework/resource_framework',
chdir='sourceless-module')
test.pass_test()
|
isc
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
626,
27206,
626,
1172,
949,
283,
4553,
7,
334,
5115,
2073,
15333,
9,
1736,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
13245,
356,
523,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8675,
297,
283,
1875,
297,
283,
8701,
1105,
819,
511,
14,
1065,
63,
6179,
360,
396,
14,
6179,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
13870,
4839,
370,
1900,
1928,
2552,
14,
523,
511,
14,
1506,
360,
396,
14,
6179,
297,
283,
1667,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1667,
63,
6469,
14,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
29613,
370,
1900,
12,
436,
1395,
282,
2073,
14,
523,
511,
14,
1506,
360,
396,
14,
6179,
297,
283,
1927,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
13745,
15,
1421,
14,
6418,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
3399,
3100,
15,
1927,
63,
6469,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
6516,
376,
1145,
3035,
376,
1595,
2003,
8844,
14,
523,
511,
14,
1506,
8,
489,
283,
396,
14,
6179,
297,
489,
283,
6469,
63,
7106,
63,
265,
63,
1927,
63,
6469,
63,
889,
63,
3723,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
6469,
63,
7106,
63,
265,
63,
1927,
63,
6469,
63,
889,
63,
3723,
14,
571,
15,
11383,
15,
13745,
4805,
881,
283,
3088,
63,
1927,
63,
6469,
63,
889,
63,
3723,
14,
6469,
15,
11383,
15,
13745,
15,
1667,
14,
2424,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
29613,
370,
1900,
436,
7675,
314,
8844,
370,
506,
6137,
14,
523,
511,
14,
1506,
8,
489,
283,
396,
14,
6179,
297,
283,
7106,
63,
265,
63,
1927,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
13745,
15,
1421,
14,
6418,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
3399,
3100,
15,
1927,
63,
6469,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
3254,
8,
273,
1151,
374,
304,
5709,
63,
10159,
626,
1172,
949,
5274,
1325,
11687,
641,
2955,
523,
327,
8363,
5544,
1454,
1736,
543,
314,
14822,
4306,
14,
221,
961,
365,
1202,
701,
523,
327,
18221,
15,
3088,
1159,
7323,
1900,
14,
523,
340,
511,
14,
908,
508,
283,
8675,
356,
272,
327,
2670,
626,
376,
7286,
10298,
641,
282,
2073,
10059,
6220,
15701,
4634,
14,
272,
511,
14,
1506,
8,
2126,
283,
396,
14,
6179,
297,
283,
7106,
63,
265,
63,
1927,
63,
4857,
297,
13097,
534,
1365,
2003,
13,
578,
358,
339,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
267,
283,
1927,
63,
4857,
14,
4857,
15,
13745,
15,
1421,
14,
6418,
297,
267,
13097,
534,
1365,
2003,
13,
578,
358,
272,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
267,
283,
1927,
63,
4857,
14,
4857,
15,
1927,
63,
4857,
297,
267,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
1529,
63,
396,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
626,
27206,
626,
1172,
949,
283,
4553,
7,
334,
5115,
2073,
15333,
9,
1736,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
13245,
356,
523,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8675,
297,
283,
1875,
297,
283,
8701,
1105,
819,
511,
14,
1065,
63,
6179,
360,
396,
14,
6179,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
13870,
4839,
370,
1900,
1928,
2552,
14,
523,
511,
14,
1506,
360,
396,
14,
6179,
297,
283,
1667,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1667,
63,
6469,
14,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
29613,
370,
1900,
12,
436,
1395,
282,
2073,
14,
523,
511,
14,
1506,
360,
396,
14,
6179,
297,
283,
1927,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
13745,
15,
1421,
14,
6418,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
3399,
3100,
15,
1927,
63,
6469,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
6516,
376,
1145,
3035,
376,
1595,
2003,
8844,
14,
523,
511,
14,
1506,
8,
489,
283,
396,
14,
6179,
297,
489,
283,
6469,
63,
7106,
63,
265,
63,
1927,
63,
6469,
63,
889,
63,
3723,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
6469,
63,
7106,
63,
265,
63,
1927,
63,
6469,
63,
889,
63,
3723,
14,
571,
15,
11383,
15,
13745,
4805,
881,
283,
3088,
63,
1927,
63,
6469,
63,
889,
63,
3723,
14,
6469,
15,
11383,
15,
13745,
15,
1667,
14,
2424,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
29613,
370,
1900,
436,
7675,
314,
8844,
370,
506,
6137,
14,
523,
511,
14,
1506,
8,
489,
283,
396,
14,
6179,
297,
283,
7106,
63,
265,
63,
1927,
63,
6469,
297,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
13745,
15,
1421,
14,
6418,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
523,
511,
14,
11730,
63,
493,
63,
7790,
63,
1397,
63,
4494,
8,
489,
283,
1927,
63,
6469,
14,
6469,
15,
11383,
15,
3399,
3100,
15,
1927,
63,
6469,
297,
489,
13097,
534,
1365,
2003,
13,
578,
358,
819,
327,
3254,
8,
273,
1151,
374,
304,
5709,
63,
10159,
626,
1172,
949,
5274,
1325,
11687,
641,
2955,
523,
327,
8363,
5544,
1454,
1736,
543,
314,
14822,
4306,
14,
221,
961,
365,
1202,
701,
523,
327,
18221,
15,
3088,
1159,
7323,
1900,
14,
523,
340,
511,
14,
908,
508,
283,
8675,
356,
272,
327,
2670,
626,
376,
7286,
10298,
641,
282,
2073,
10059,
6220,
15701,
4634,
14,
272,
511,
14,
1506,
8,
2126,
283,
396,
14,
6179,
297,
283,
7106,
63,
265,
63,
1927,
63,
4857,
297,
13097,
534,
1365,
2003,
13,
578,
358,
339,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
267,
283,
1927,
63,
4857,
14,
4857,
15,
13745,
15,
1421,
14,
6418,
297,
267,
13097,
534,
1365,
2003,
13,
578,
358,
272,
511,
14,
11730,
63,
493,
63,
7790,
63,
4494,
8,
267,
283,
1927,
63,
4857,
14,
4857,
15,
1927,
63,
4857,
297,
267,
13097,
534,
1365,
2003,
13,
578,
358,
819,
511,
14,
1529,
63,
396,
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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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 datetime
import json
import testtools
import time
import yaml
from blazarclient import exception
from oslo_serialization import jsonutils
from tacker.plugins.common import constants as evt_constants
from tacker.tests import constants
from tacker.tests.functional import base
from tacker.tests.utils import read_file
HYPERVISORS = []
def hypervisors():
global HYPERVISORS
client = base.BaseTackerTest.novaclient()
hypervisor_list = client.hypervisors.list()
for hypervisor in hypervisor_list:
if hypervisor.running_vms == 0:
HYPERVISORS.append(hypervisor)
return HYPERVISORS
class VnfTestReservationMonitor(base.BaseTackerTest):
def _test_vnf_tosca_reservation(self, vnfd_file, vnf_name,
lease_id, param_values=None):
input_yaml = read_file(vnfd_file)
tosca_dict = yaml.safe_load(input_yaml)
# TODO(niraj-singh): It's not possible to pass parameters through
# parameter file due to Bug #1799683. Once this bug is fixed, no need
# to update vnfd yaml.
vdu_prop = tosca_dict['topology_template']['node_templates']['VDU1']
vdu_prop['properties']['flavor'] = param_values.get('flavor')
vdu_prop['properties']['reservation_metadata']['id'] =\
param_values.get('server_group_id')
vdu_prop['properties']['reservation_metadata']['resource_type'] =\
param_values.get('resource_type')
policies = tosca_dict['topology_template']['policies']
policies[0]['RSV']['reservation']['properties']['lease_id'] =\
param_values.get('lease_id')
tosca_arg = {'vnfd': {'name': vnf_name,
'attributes': {'vnfd': tosca_dict}}}
blazarclient = self.blazarclient()
# Create vnfd with tosca template
vnfd_instance = self.client.create_vnfd(body=tosca_arg)
self.assertIsNotNone(vnfd_instance)
# Create vnf with vnfd_id
vnfd_id = vnfd_instance['vnfd']['id']
self.addCleanup(self.client.delete_vnfd, vnfd_id)
vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
vnf_instance = self.client.create_vnf(body=vnf_arg)
self.validate_vnf_instance(vnfd_instance, vnf_instance)
vnf_id = vnf_instance['vnf']['id']
def _get_reservation_policy(vnfd_dict):
policies = vnfd_dict['topology_template'].get('policies', [])
res_policy = dict()
for policy_dict in policies:
for name, policy in policy_dict.items():
if policy['type'] == constants.POLICY_RESERVATION:
reservations = policy['reservation']
for reserv_key, reserv_value in reservations.items():
if reserv_key == 'properties':
continue
for policy_action in reserv_value:
res_policy[reserv_key] = policy_action
return res_policy
def _check_lease_event_status():
lease_event_status = _verify_and_get_lease_event_status()
self.assertEqual(lease_event_status, constants.LEASE_EVENT_STATUS,
"Lease %(lease_id)s with status %(status)s is"
" expected to be %(target)s" %
{"lease_id": lease_id,
"status": lease_event_status,
"target": constants.LEASE_EVENT_STATUS})
def _verify_and_get_lease_event_status():
start_time = int(time.time())
while ((int(time.time()) - start_time) <
constants.LEASE_CHECK_EVENT_TIMEOUT):
lease_detail = blazarclient.lease.get(lease_id)
lease_events = lease_detail.get('events')
for event in lease_events:
lease_event_status = event.get('status')
if ((event.get('event_type') ==
constants.START_LEASE_EVET_TYPE) and (
lease_event_status ==
constants.LEASE_EVENT_STATUS)):
return lease_event_status
time.sleep(constants.LEASE_CHECK_SLEEP_TIME)
def _wait_vnf_active_and_assert_vdu_count(vdu_count, scale_type=None):
self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf = self.client.show_vnf(vnf_id)['vnf']
# {"VDU1": ["10.0.0.14", "10.0.0.5"]}
if scale_type == 'scaling-in' and vdu_count == 0:
self.assertFalse(jsonutils.loads(vnf.get('mgmt_ip_address',
'{}')),
"Once scaling-in completes, mgmt_ip_address"
" should be empty.")
elif scale_type == 'scaling-out':
self.assertEqual(vdu_count, len(json.loads(
vnf['mgmt_ip_address'])['VDU1']))
elif vdu_count == 0 and scale_type is None:
self.assertIsNone(vnf['mgmt_ip_address'])
reservation_policy = _get_reservation_policy(tosca_dict)
_wait_vnf_active_and_assert_vdu_count(0)
# trigger alarm for start action
start_action = reservation_policy.get('start_actions')
scaling_out_action = start_action + '-out'
_check_lease_event_status()
# scaling-out action
self.trigger_vnf(vnf_id, 'start_actions', scaling_out_action)
time.sleep(constants.SCALE_SLEEP_TIME)
# checking VDU's count after scaling out
_wait_vnf_active_and_assert_vdu_count(2, scale_type='scaling-out')
time.sleep(constants.SCALE_WINDOW_SLEEP_TIME)
# trigger alarm for before end action
before_end_action = reservation_policy.get('before_end_actions')
scaling_in_action = before_end_action + '-in'
# scaling-in action
self.trigger_vnf(vnf_id, 'before_end_actions', scaling_in_action)
time.sleep(constants.SCALE_SLEEP_TIME)
# checking VDU's count after scaling in
_wait_vnf_active_and_assert_vdu_count(0, scale_type='scaling-in')
self.verify_vnf_crud_events(
vnf_id, evt_constants.RES_EVT_SCALE,
evt_constants.ACTIVE, cnt=2)
self.verify_vnf_crud_events(
vnf_id, evt_constants.RES_EVT_SCALE,
evt_constants.PENDING_SCALE_OUT, cnt=1)
self.verify_vnf_crud_events(
vnf_id, evt_constants.RES_EVT_SCALE,
evt_constants.PENDING_SCALE_IN, cnt=1)
try:
self.client.delete_vnf(vnf_id)
except Exception:
assert False, (
"Failed to delete vnf %s after the reservation test" % vnf_id)
# Wait for delete vnf_instance
self.addCleanup(self.wait_until_vnf_delete, vnf_id,
constants.VNF_CIRROS_DELETE_TIMEOUT)
def _get_instance_reservation(self):
blazarclient = self.blazarclient()
reservations = [{'disk_gb': 0,
'vcpus': 1, 'memory_mb': 1,
'amount': 2, 'affinity': True,
'resource_properties': '',
'resource_type': 'virtual:instance'}]
events = []
start_date = (datetime.datetime.utcnow() + datetime.timedelta(
minutes=2)).strftime("%Y-%m-%d %H:%M")
end_date = (datetime.datetime.utcnow() + datetime.timedelta(
minutes=30)).strftime("%Y-%m-%d %H:%M")
host_added = False
for hypervisor in HYPERVISORS:
try:
blazar_host = blazarclient.host.create(
hypervisor.hypervisor_hostname)
host_added = True
break
except exception.BlazarClientException:
pass
if not host_added:
self.skipTest("Skip test as Blazar failed to create host from one"
" of available hypervisors '%s' as it found some"
" instances were running on them" %
",".join([hypervisor.hypervisor_hostname
for hypervisor in HYPERVISORS]))
instance_reservation = blazarclient.lease.create(
'test-reservation', start_date, end_date, reservations, events)
self.addCleanup(
blazarclient.host.delete, blazar_host.get('id'))
self.addCleanup(
blazarclient.lease.delete, instance_reservation['id'])
return instance_reservation, blazar_host
@testtools.skipIf(len(hypervisors()) == 0,
'Skip test as there are no'
' hypervisors available in nova')
def test_vnf_alarm_scale_with_instance_reservation(self):
instance_reservation, blazar_host = self._get_instance_reservation()
lease_id = str(instance_reservation['reservations'][0]['lease_id'])
flavor_id = str(instance_reservation['reservations'][0]['flavor_id'])
server_group_id = str(
instance_reservation['reservations'][0]['server_group_id'])
param_to_create_lease = {'lease_id': lease_id,
'flavor': flavor_id,
'server_group_id': server_group_id,
'resource_type': 'virtual_instance'}
self._test_vnf_tosca_reservation(
'sample-tosca-vnfd-instance-reservation.yaml',
'VNFD1', lease_id, param_to_create_lease)
|
apache-2.0
|
[
3,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2197,
199,
646,
2022,
199,
646,
30741,
199,
646,
900,
199,
646,
8864,
199,
199,
504,
330,
416,
90,
285,
1258,
492,
1919,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
307,
564,
281,
14,
5265,
14,
2330,
492,
5262,
465,
16330,
63,
5559,
199,
504,
307,
564,
281,
14,
2219,
492,
5262,
199,
504,
307,
564,
281,
14,
2219,
14,
15481,
492,
1300,
199,
504,
307,
564,
281,
14,
2219,
14,
1208,
492,
1586,
63,
493,
421,
199,
16255,
4227,
11793,
4149,
275,
942,
421,
199,
318,
10342,
27215,
837,
272,
2288,
869,
57,
4227,
11793,
4149,
272,
1890,
275,
1300,
14,
1563,
52,
564,
281,
774,
14,
889,
15367,
864,
342,
272,
21724,
63,
513,
275,
1890,
14,
9547,
27215,
14,
513,
342,
272,
367,
21724,
315,
21724,
63,
513,
26,
267,
340,
21724,
14,
5720,
63,
16092,
508,
378,
26,
288,
869,
57,
4227,
11793,
4149,
14,
740,
8,
18237,
9,
272,
372,
869,
57,
4227,
11793,
4149,
421,
199,
533,
812,
9914,
774,
497,
8213,
13189,
8,
1095,
14,
1563,
52,
564,
281,
774,
304,
339,
347,
485,
396,
63,
6002,
70,
63,
475,
7101,
63,
20522,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
2892,
31199,
63,
344,
12,
1215,
63,
1459,
29,
403,
304,
267,
1324,
63,
5963,
275,
1586,
63,
493,
8,
6002,
2592,
63,
493,
9,
267,
370,
7101,
63,
807,
275,
8864,
14,
3489,
63,
912,
8,
1210,
63,
5963,
9,
398,
327,
3254,
8,
8445,
345,
74,
13,
1044,
72,
304,
2779,
1159,
440,
3962,
370,
986,
2633,
4012,
267,
327,
2725,
570,
7037,
370,
21605,
327,
1196,
1020,
25689,
14,
19468,
642,
6519,
365,
6317,
12,
949,
1929,
267,
327,
370,
1678,
373,
78,
2592,
8864,
14,
267,
373,
2033,
63,
4469,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
2545,
54,
4980,
17,
418,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
6081,
418,
275,
1215,
63,
1459,
14,
362,
360,
6081,
358,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
20522,
63,
2343,
2545,
344,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1000,
63,
923,
63,
344,
358,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
20522,
63,
2343,
2545,
1927,
63,
466,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1927,
63,
466,
358,
267,
14118,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
11767,
418,
267,
14118,
59,
16,
2733,
50,
4985,
2545,
20522,
2545,
3282,
2545,
1756,
63,
344,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1756,
63,
344,
358,
398,
370,
7101,
63,
1273,
275,
791,
6002,
2592,
356,
791,
354,
356,
373,
9914,
63,
354,
12,
2892,
283,
2987,
356,
791,
6002,
2592,
356,
370,
7101,
63,
807,
4863,
93,
267,
330,
416,
90,
285,
1258,
275,
291,
14,
21244,
90,
285,
1258,
342,
398,
327,
2790,
373,
78,
2592,
543,
370,
7101,
1978,
267,
373,
78,
2592,
63,
842,
275,
291,
14,
1258,
14,
981,
63,
6002,
2592,
8,
2030,
29,
475,
7101,
63,
1273,
9,
267,
291,
14,
10389,
8,
6002,
2592,
63,
842,
9,
398,
327,
2790,
373,
9914,
543,
373,
78,
2592,
63,
344,
267,
373,
78,
2592,
63,
344,
275,
373,
78,
2592,
63,
842,
459,
6002,
2592,
2545,
344,
418,
267,
291,
14,
12808,
8,
277,
14,
1258,
14,
1807,
63,
6002,
2592,
12,
373,
78,
2592,
63,
344,
9,
398,
373,
9914,
63,
1273,
275,
791,
6002,
70,
356,
791,
6002,
2592,
63,
344,
356,
373,
78,
2592,
63,
344,
12,
283,
354,
356,
373,
9914,
63,
354,
4863,
267,
373,
9914,
63,
842,
275,
291,
14,
1258,
14,
981,
63,
6002,
70,
8,
2030,
29,
6002,
70,
63,
1273,
9,
398,
291,
14,
3502,
63,
6002,
70,
63,
842,
8,
6002,
2592,
63,
842,
12,
373,
9914,
63,
842,
9,
398,
373,
9914,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
344,
418,
398,
347,
485,
362,
63,
20522,
63,
3185,
8,
6002,
2592,
63,
807,
304,
288,
14118,
275,
373,
78,
2592,
63,
807,
459,
10775,
63,
1160,
2278,
362,
360,
11767,
297,
3073,
288,
522,
63,
3185,
275,
1211,
342,
288,
367,
4592,
63,
807,
315,
14118,
26,
355,
367,
536,
12,
4592,
315,
4592,
63,
807,
14,
1744,
837,
490,
340,
4592,
459,
466,
418,
508,
5262,
14,
15976,
63,
22697,
54,
2594,
26,
717,
31494,
275,
4592,
459,
20522,
418,
717,
367,
295,
7297,
63,
498,
12,
295,
7297,
63,
585,
315,
31494,
14,
1744,
837,
1169,
340,
295,
7297,
63,
498,
508,
283,
3282,
356,
1816,
1980,
1169,
367,
4592,
63,
1287,
315,
295,
7297,
63,
585,
26,
1816,
522,
63,
3185,
59,
264,
7297,
63,
498,
61,
275,
4592,
63,
1287,
288,
372,
522,
63,
3185,
398,
347,
485,
1074,
63,
1756,
63,
1430,
63,
1205,
837,
288,
31199,
63,
1430,
63,
1205,
275,
485,
4712,
63,
460,
63,
362,
63,
1756,
63,
1430,
63,
1205,
342,
288,
291,
14,
629,
8,
1756,
63,
1430,
63,
1205,
12,
5262,
14,
17177,
63,
8193,
63,
6305,
12,
2490,
298,
2553,
482,
2818,
1756,
63,
344,
9,
83,
543,
2004,
2818,
1205,
9,
83,
365,
2,
2490,
298,
1420,
370,
506,
2818,
1375,
9,
83,
2,
450,
2490,
2420
] |
[
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2197,
199,
646,
2022,
199,
646,
30741,
199,
646,
900,
199,
646,
8864,
199,
199,
504,
330,
416,
90,
285,
1258,
492,
1919,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
307,
564,
281,
14,
5265,
14,
2330,
492,
5262,
465,
16330,
63,
5559,
199,
504,
307,
564,
281,
14,
2219,
492,
5262,
199,
504,
307,
564,
281,
14,
2219,
14,
15481,
492,
1300,
199,
504,
307,
564,
281,
14,
2219,
14,
1208,
492,
1586,
63,
493,
421,
199,
16255,
4227,
11793,
4149,
275,
942,
421,
199,
318,
10342,
27215,
837,
272,
2288,
869,
57,
4227,
11793,
4149,
272,
1890,
275,
1300,
14,
1563,
52,
564,
281,
774,
14,
889,
15367,
864,
342,
272,
21724,
63,
513,
275,
1890,
14,
9547,
27215,
14,
513,
342,
272,
367,
21724,
315,
21724,
63,
513,
26,
267,
340,
21724,
14,
5720,
63,
16092,
508,
378,
26,
288,
869,
57,
4227,
11793,
4149,
14,
740,
8,
18237,
9,
272,
372,
869,
57,
4227,
11793,
4149,
421,
199,
533,
812,
9914,
774,
497,
8213,
13189,
8,
1095,
14,
1563,
52,
564,
281,
774,
304,
339,
347,
485,
396,
63,
6002,
70,
63,
475,
7101,
63,
20522,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
2892,
31199,
63,
344,
12,
1215,
63,
1459,
29,
403,
304,
267,
1324,
63,
5963,
275,
1586,
63,
493,
8,
6002,
2592,
63,
493,
9,
267,
370,
7101,
63,
807,
275,
8864,
14,
3489,
63,
912,
8,
1210,
63,
5963,
9,
398,
327,
3254,
8,
8445,
345,
74,
13,
1044,
72,
304,
2779,
1159,
440,
3962,
370,
986,
2633,
4012,
267,
327,
2725,
570,
7037,
370,
21605,
327,
1196,
1020,
25689,
14,
19468,
642,
6519,
365,
6317,
12,
949,
1929,
267,
327,
370,
1678,
373,
78,
2592,
8864,
14,
267,
373,
2033,
63,
4469,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
2545,
54,
4980,
17,
418,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
6081,
418,
275,
1215,
63,
1459,
14,
362,
360,
6081,
358,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
20522,
63,
2343,
2545,
344,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1000,
63,
923,
63,
344,
358,
267,
373,
2033,
63,
4469,
459,
3282,
2545,
20522,
63,
2343,
2545,
1927,
63,
466,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1927,
63,
466,
358,
267,
14118,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
11767,
418,
267,
14118,
59,
16,
2733,
50,
4985,
2545,
20522,
2545,
3282,
2545,
1756,
63,
344,
418,
26447,
288,
1215,
63,
1459,
14,
362,
360,
1756,
63,
344,
358,
398,
370,
7101,
63,
1273,
275,
791,
6002,
2592,
356,
791,
354,
356,
373,
9914,
63,
354,
12,
2892,
283,
2987,
356,
791,
6002,
2592,
356,
370,
7101,
63,
807,
4863,
93,
267,
330,
416,
90,
285,
1258,
275,
291,
14,
21244,
90,
285,
1258,
342,
398,
327,
2790,
373,
78,
2592,
543,
370,
7101,
1978,
267,
373,
78,
2592,
63,
842,
275,
291,
14,
1258,
14,
981,
63,
6002,
2592,
8,
2030,
29,
475,
7101,
63,
1273,
9,
267,
291,
14,
10389,
8,
6002,
2592,
63,
842,
9,
398,
327,
2790,
373,
9914,
543,
373,
78,
2592,
63,
344,
267,
373,
78,
2592,
63,
344,
275,
373,
78,
2592,
63,
842,
459,
6002,
2592,
2545,
344,
418,
267,
291,
14,
12808,
8,
277,
14,
1258,
14,
1807,
63,
6002,
2592,
12,
373,
78,
2592,
63,
344,
9,
398,
373,
9914,
63,
1273,
275,
791,
6002,
70,
356,
791,
6002,
2592,
63,
344,
356,
373,
78,
2592,
63,
344,
12,
283,
354,
356,
373,
9914,
63,
354,
4863,
267,
373,
9914,
63,
842,
275,
291,
14,
1258,
14,
981,
63,
6002,
70,
8,
2030,
29,
6002,
70,
63,
1273,
9,
398,
291,
14,
3502,
63,
6002,
70,
63,
842,
8,
6002,
2592,
63,
842,
12,
373,
9914,
63,
842,
9,
398,
373,
9914,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
344,
418,
398,
347,
485,
362,
63,
20522,
63,
3185,
8,
6002,
2592,
63,
807,
304,
288,
14118,
275,
373,
78,
2592,
63,
807,
459,
10775,
63,
1160,
2278,
362,
360,
11767,
297,
3073,
288,
522,
63,
3185,
275,
1211,
342,
288,
367,
4592,
63,
807,
315,
14118,
26,
355,
367,
536,
12,
4592,
315,
4592,
63,
807,
14,
1744,
837,
490,
340,
4592,
459,
466,
418,
508,
5262,
14,
15976,
63,
22697,
54,
2594,
26,
717,
31494,
275,
4592,
459,
20522,
418,
717,
367,
295,
7297,
63,
498,
12,
295,
7297,
63,
585,
315,
31494,
14,
1744,
837,
1169,
340,
295,
7297,
63,
498,
508,
283,
3282,
356,
1816,
1980,
1169,
367,
4592,
63,
1287,
315,
295,
7297,
63,
585,
26,
1816,
522,
63,
3185,
59,
264,
7297,
63,
498,
61,
275,
4592,
63,
1287,
288,
372,
522,
63,
3185,
398,
347,
485,
1074,
63,
1756,
63,
1430,
63,
1205,
837,
288,
31199,
63,
1430,
63,
1205,
275,
485,
4712,
63,
460,
63,
362,
63,
1756,
63,
1430,
63,
1205,
342,
288,
291,
14,
629,
8,
1756,
63,
1430,
63,
1205,
12,
5262,
14,
17177,
63,
8193,
63,
6305,
12,
2490,
298,
2553,
482,
2818,
1756,
63,
344,
9,
83,
543,
2004,
2818,
1205,
9,
83,
365,
2,
2490,
298,
1420,
370,
506,
2818,
1375,
9,
83,
2,
450,
2490,
2420,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Kiiv/CouchPotatoServer
|
couchpotato/core/media/movie/providers/trailer/youtube_dl/extractor/daum.py
|
16
|
2754
|
# encoding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
compat_urllib_parse,
)
class DaumIE(InfoExtractor):
_VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:v/|.*?clipid=)(?P<id>[^?#&]+)'
IE_NAME = 'daum.net'
_TESTS = [{
'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
'info_dict': {
'id': '52554690',
'ext': 'mp4',
'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
'upload_date': '20130831',
'duration': 3868,
},
}, {
'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
'only_matching': True,
}, {
'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
'only_matching': True,
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
canonical_url = 'http://tvpot.daum.net/v/%s' % video_id
webpage = self._download_webpage(canonical_url, video_id)
full_id = self._search_regex(
r'<iframe src="http://videofarm.daum.net/controller/video/viewer/Video.html\?.*?vid=(.+?)[&"]',
webpage, 'full id')
query = compat_urllib_parse.urlencode({'vid': full_id})
info = self._download_xml(
'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
'Downloading video info')
urls = self._download_xml(
'http://videofarm.daum.net/controller/api/open/v1_2/MovieData.apixml?' + query,
video_id, 'Downloading video formats info')
formats = []
for format_el in urls.findall('result/output_list/output_list'):
profile = format_el.attrib['profile']
format_query = compat_urllib_parse.urlencode({
'vid': full_id,
'profile': profile,
})
url_doc = self._download_xml(
'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
video_id, note='Downloading video data for %s format' % profile)
format_url = url_doc.find('result/url').text
formats.append({
'url': format_url,
'format_id': profile,
})
return {
'id': video_id,
'title': info.find('TITLE').text,
'formats': formats,
'thumbnail': self._og_search_thumbnail(webpage),
'description': info.find('CONTENTS').text,
'duration': int(info.find('DURATION').text),
'upload_date': info.find('REGDTTM').text[:8],
}
|
gpl-3.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
199,
9,
421,
199,
533,
577,
65,
453,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
14173,
4537,
983,
453,
4537,
846,
32576,
86,
15,
92,
6697,
2764,
3150,
29,
18168,
48,
28,
344,
13489,
31,
3,
6,
29716,
272,
15292,
63,
2339,
275,
283,
983,
453,
14,
846,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2768,
14,
1117,
31,
2764,
3150,
29,
24334,
1477,
24495,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24334,
1477,
24495,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
1802,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
12127,
2192,
297,
288,
283,
5553,
356,
650,
15430,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
86,
371,
20,
68,
8048,
2846,
588,
89,
34,
385,
89,
3210,
2910,
74,
34,
90,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
1780,
31282,
6524,
7351,
2789,
57,
5,
1194,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
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,
11358,
63,
633,
275,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
3149,
83,
7,
450,
3991,
63,
344,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13109,
63,
633,
12,
3991,
63,
344,
9,
267,
2615,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7601,
20052,
2928,
628,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
3722,
15,
16645,
15,
9166,
14,
1360,
29635,
6697,
5017,
2687,
11198,
2788,
6,
23793,
288,
9248,
12,
283,
2861,
1305,
358,
267,
1827,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
3252,
5017,
356,
2615,
63,
344,
1552,
267,
2256,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2354,
8672,
14,
1117,
14069,
435,
1827,
12,
3991,
63,
344,
12,
288,
283,
18085,
3991,
2256,
358,
267,
8187,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
1451,
14,
439,
1148,
757,
14069,
435,
1827,
12,
288,
3991,
63,
344,
12,
283,
18085,
3991,
6752,
2256,
358,
398,
6752,
275,
942,
267,
367,
1475,
63,
352,
315,
8187,
14,
6452,
360,
1099,
15,
1199,
63,
513,
15,
1199,
63,
513,
735,
288,
4690,
275,
1475,
63,
352,
14,
6640,
459,
2913,
418,
288,
1475,
63,
1131,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
2561,
355,
283,
5017,
356,
2615,
63,
344,
12,
355,
283,
2913,
356,
4690,
12,
288,
3828,
288,
1166,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
6592,
14,
439,
1148,
757,
14069,
435,
1475,
63,
1131,
12,
355,
3991,
63,
344,
12,
5317,
534,
18085,
3991,
666,
367,
450,
83,
1475,
7,
450,
4690,
9,
288,
1475,
63,
633,
275,
1166,
63,
1301,
14,
1623,
360,
1099,
15,
633,
1959,
505,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
1475,
63,
633,
12,
355,
283,
908,
63,
344,
356,
4690,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2256,
14,
1623,
360,
19091,
1959,
505,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
2256,
14,
1623,
360,
9663,
51,
1959,
505,
12,
288,
283,
5553,
356,
1109,
8,
815,
14,
1623,
360,
36,
15301,
1959,
505,
395,
288,
283,
5064,
63,
602,
356,
2256,
14,
1623,
360,
5616,
36,
1481,
45,
1959,
505,
1491,
24,
467,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
199,
9,
421,
199,
533,
577,
65,
453,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
77,
20316,
6993,
14173,
4537,
983,
453,
4537,
846,
32576,
86,
15,
92,
6697,
2764,
3150,
29,
18168,
48,
28,
344,
13489,
31,
3,
6,
29716,
272,
15292,
63,
2339,
275,
283,
983,
453,
14,
846,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2768,
14,
1117,
31,
2764,
3150,
29,
24334,
1477,
24495,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24334,
1477,
24495,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
1802,
356,
283,
13203,
33,
499,
2970,
3452,
10148,
234,
251,
169,
100,
235,
18,
1227,
170,
249,
235,
446,
499,
168,
115,
223,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
12127,
2192,
297,
288,
283,
5553,
356,
650,
15430,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
86,
371,
20,
68,
8048,
2846,
588,
89,
34,
385,
89,
3210,
2910,
74,
34,
90,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
15,
1780,
31282,
6524,
7351,
2789,
57,
5,
1194,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
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,
11358,
63,
633,
275,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
86,
3149,
83,
7,
450,
3991,
63,
344,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13109,
63,
633,
12,
3991,
63,
344,
9,
267,
2615,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7601,
20052,
2928,
628,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
3722,
15,
16645,
15,
9166,
14,
1360,
29635,
6697,
5017,
2687,
11198,
2788,
6,
23793,
288,
9248,
12,
283,
2861,
1305,
358,
267,
1827,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
3252,
5017,
356,
2615,
63,
344,
1552,
267,
2256,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
6993,
14173,
14,
983,
453,
14,
846,
15,
7548,
15,
17492,
2354,
8672,
14,
1117,
14069,
435,
1827,
12,
3991,
63,
344,
12,
288,
283,
18085,
3991,
2256,
358,
267,
8187,
275,
291,
423,
4249,
63,
1652,
8,
288,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
1451,
14,
439,
1148,
757,
14069,
435,
1827,
12,
288,
3991,
63,
344,
12,
283,
18085,
3991,
6752,
2256,
358,
398,
6752,
275,
942,
267,
367,
1475,
63,
352,
315,
8187,
14,
6452,
360,
1099,
15,
1199,
63,
513,
15,
1199,
63,
513,
735,
288,
4690,
275,
1475,
63,
352,
14,
6640,
459,
2913,
418,
288,
1475,
63,
1131,
275,
8434,
63,
4078,
63,
1122,
14,
10738,
2561,
355,
283,
5017,
356,
2615,
63,
344,
12,
355,
283,
2913,
356,
4690,
12,
288,
3828,
288,
1166,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
283,
1014,
921,
5624,
1618,
5362,
14,
983,
453,
14,
846,
15,
5538,
15,
1246,
15,
1490,
15,
86,
17,
63,
18,
15,
19088,
6592,
14,
439,
1148,
757,
14069,
435,
1475,
63,
1131,
12,
355,
3991,
63,
344,
12,
5317,
534,
18085,
3991,
666,
367,
450,
83,
1475,
7,
450,
4690,
9,
288,
1475,
63,
633,
275,
1166,
63,
1301,
14,
1623,
360,
1099,
15,
633,
1959,
505,
288,
6752,
14,
740,
2561,
355,
283,
633,
356,
1475,
63,
633,
12,
355,
283,
908,
63,
344,
356,
4690,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2256,
14,
1623,
360,
19091,
1959,
505,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
8311,
356,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
395,
288,
283,
1802,
356,
2256,
14,
1623,
360,
9663,
51,
1959,
505,
12,
288,
283,
5553,
356,
1109,
8,
815,
14,
1623,
360,
36,
15301,
1959,
505,
395,
288,
283,
5064,
63,
602,
356,
2256,
14,
1623,
360,
5616,
36,
1481,
45,
1959,
505,
1491,
24,
467,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
okwow123/djangol2
|
example/env/lib/python2.7/site-packages/pip/_vendor/html5lib/constants.py
|
249
|
86469
|
from __future__ import absolute_import, division, unicode_literals
import string
import gettext
_ = gettext.gettext
EOF = None
E = {
"null-character":
_("Null character in input stream, replaced with U+FFFD."),
"invalid-codepoint":
_("Invalid codepoint in stream."),
"incorrectly-placed-solidus":
_("Solidus (/) incorrectly placed in tag."),
"incorrect-cr-newline-entity":
_("Incorrect CR newline entity, replaced with LF."),
"illegal-windows-1252-entity":
_("Entity used with illegal number (windows-1252 reference)."),
"cant-convert-numeric-entity":
_("Numeric entity couldn't be converted to character "
"(codepoint U+%(charAsInt)08x)."),
"illegal-codepoint-for-numeric-entity":
_("Numeric entity represents an illegal codepoint: "
"U+%(charAsInt)08x."),
"numeric-entity-without-semicolon":
_("Numeric entity didn't end with ';'."),
"expected-numeric-entity-but-got-eof":
_("Numeric entity expected. Got end of file instead."),
"expected-numeric-entity":
_("Numeric entity expected but none found."),
"named-entity-without-semicolon":
_("Named entity didn't end with ';'."),
"expected-named-entity":
_("Named entity expected. Got none."),
"attributes-in-end-tag":
_("End tag contains unexpected attributes."),
'self-closing-flag-on-end-tag':
_("End tag contains unexpected self-closing flag."),
"expected-tag-name-but-got-right-bracket":
_("Expected tag name. Got '>' instead."),
"expected-tag-name-but-got-question-mark":
_("Expected tag name. Got '?' instead. (HTML doesn't "
"support processing instructions.)"),
"expected-tag-name":
_("Expected tag name. Got something else instead"),
"expected-closing-tag-but-got-right-bracket":
_("Expected closing tag. Got '>' instead. Ignoring '</>'."),
"expected-closing-tag-but-got-eof":
_("Expected closing tag. Unexpected end of file."),
"expected-closing-tag-but-got-char":
_("Expected closing tag. Unexpected character '%(data)s' found."),
"eof-in-tag-name":
_("Unexpected end of file in the tag name."),
"expected-attribute-name-but-got-eof":
_("Unexpected end of file. Expected attribute name instead."),
"eof-in-attribute-name":
_("Unexpected end of file in attribute name."),
"invalid-character-in-attribute-name":
_("Invalid character in attribute name"),
"duplicate-attribute":
_("Dropped duplicate attribute on tag."),
"expected-end-of-tag-name-but-got-eof":
_("Unexpected end of file. Expected = or end of tag."),
"expected-attribute-value-but-got-eof":
_("Unexpected end of file. Expected attribute value."),
"expected-attribute-value-but-got-right-bracket":
_("Expected attribute value. Got '>' instead."),
'equals-in-unquoted-attribute-value':
_("Unexpected = in unquoted attribute"),
'unexpected-character-in-unquoted-attribute-value':
_("Unexpected character in unquoted attribute"),
"invalid-character-after-attribute-name":
_("Unexpected character after attribute name."),
"unexpected-character-after-attribute-value":
_("Unexpected character after attribute value."),
"eof-in-attribute-value-double-quote":
_("Unexpected end of file in attribute value (\")."),
"eof-in-attribute-value-single-quote":
_("Unexpected end of file in attribute value (')."),
"eof-in-attribute-value-no-quotes":
_("Unexpected end of file in attribute value."),
"unexpected-EOF-after-solidus-in-tag":
_("Unexpected end of file in tag. Expected >"),
"unexpected-character-after-solidus-in-tag":
_("Unexpected character after / in tag. Expected >"),
"expected-dashes-or-doctype":
_("Expected '--' or 'DOCTYPE'. Not found."),
"unexpected-bang-after-double-dash-in-comment":
_("Unexpected ! after -- in comment"),
"unexpected-space-after-double-dash-in-comment":
_("Unexpected space after -- in comment"),
"incorrect-comment":
_("Incorrect comment."),
"eof-in-comment":
_("Unexpected end of file in comment."),
"eof-in-comment-end-dash":
_("Unexpected end of file in comment (-)"),
"unexpected-dash-after-double-dash-in-comment":
_("Unexpected '-' after '--' found in comment."),
"eof-in-comment-double-dash":
_("Unexpected end of file in comment (--)."),
"eof-in-comment-end-space-state":
_("Unexpected end of file in comment."),
"eof-in-comment-end-bang-state":
_("Unexpected end of file in comment."),
"unexpected-char-in-comment":
_("Unexpected character in comment found."),
"need-space-after-doctype":
_("No space after literal string 'DOCTYPE'."),
"expected-doctype-name-but-got-right-bracket":
_("Unexpected > character. Expected DOCTYPE name."),
"expected-doctype-name-but-got-eof":
_("Unexpected end of file. Expected DOCTYPE name."),
"eof-in-doctype-name":
_("Unexpected end of file in DOCTYPE name."),
"eof-in-doctype":
_("Unexpected end of file in DOCTYPE."),
"expected-space-or-right-bracket-in-doctype":
_("Expected space or '>'. Got '%(data)s'"),
"unexpected-end-of-doctype":
_("Unexpected end of DOCTYPE."),
"unexpected-char-in-doctype":
_("Unexpected character in DOCTYPE."),
"eof-in-innerhtml":
_("XXX innerHTML EOF"),
"unexpected-doctype":
_("Unexpected DOCTYPE. Ignored."),
"non-html-root":
_("html needs to be the first start tag."),
"expected-doctype-but-got-eof":
_("Unexpected End of file. Expected DOCTYPE."),
"unknown-doctype":
_("Erroneous DOCTYPE."),
"expected-doctype-but-got-chars":
_("Unexpected non-space characters. Expected DOCTYPE."),
"expected-doctype-but-got-start-tag":
_("Unexpected start tag (%(name)s). Expected DOCTYPE."),
"expected-doctype-but-got-end-tag":
_("Unexpected end tag (%(name)s). Expected DOCTYPE."),
"end-tag-after-implied-root":
_("Unexpected end tag (%(name)s) after the (implied) root element."),
"expected-named-closing-tag-but-got-eof":
_("Unexpected end of file. Expected end tag (%(name)s)."),
"two-heads-are-not-better-than-one":
_("Unexpected start tag head in existing head. Ignored."),
"unexpected-end-tag":
_("Unexpected end tag (%(name)s). Ignored."),
"unexpected-start-tag-out-of-my-head":
_("Unexpected start tag (%(name)s) that can be in head. Moved."),
"unexpected-start-tag":
_("Unexpected start tag (%(name)s)."),
"missing-end-tag":
_("Missing end tag (%(name)s)."),
"missing-end-tags":
_("Missing end tags (%(name)s)."),
"unexpected-start-tag-implies-end-tag":
_("Unexpected start tag (%(startName)s) "
"implies end tag (%(endName)s)."),
"unexpected-start-tag-treated-as":
_("Unexpected start tag (%(originalName)s). Treated as %(newName)s."),
"deprecated-tag":
_("Unexpected start tag %(name)s. Don't use it!"),
"unexpected-start-tag-ignored":
_("Unexpected start tag %(name)s. Ignored."),
"expected-one-end-tag-but-got-another":
_("Unexpected end tag (%(gotName)s). "
"Missing end tag (%(expectedName)s)."),
"end-tag-too-early":
_("End tag (%(name)s) seen too early. Expected other end tag."),
"end-tag-too-early-named":
_("Unexpected end tag (%(gotName)s). Expected end tag (%(expectedName)s)."),
"end-tag-too-early-ignored":
_("End tag (%(name)s) seen too early. Ignored."),
"adoption-agency-1.1":
_("End tag (%(name)s) violates step 1, "
"paragraph 1 of the adoption agency algorithm."),
"adoption-agency-1.2":
_("End tag (%(name)s) violates step 1, "
"paragraph 2 of the adoption agency algorithm."),
"adoption-agency-1.3":
_("End tag (%(name)s) violates step 1, "
"paragraph 3 of the adoption agency algorithm."),
"adoption-agency-4.4":
_("End tag (%(name)s) violates step 4, "
"paragraph 4 of the adoption agency algorithm."),
"unexpected-end-tag-treated-as":
_("Unexpected end tag (%(originalName)s). Treated as %(newName)s."),
"no-end-tag":
_("This element (%(name)s) has no end tag."),
"unexpected-implied-end-tag-in-table":
_("Unexpected implied end tag (%(name)s) in the table phase."),
"unexpected-implied-end-tag-in-table-body":
_("Unexpected implied end tag (%(name)s) in the table body phase."),
"unexpected-char-implies-table-voodoo":
_("Unexpected non-space characters in "
"table context caused voodoo mode."),
"unexpected-hidden-input-in-table":
_("Unexpected input with type hidden in table context."),
"unexpected-form-in-table":
_("Unexpected form in table context."),
"unexpected-start-tag-implies-table-voodoo":
_("Unexpected start tag (%(name)s) in "
"table context caused voodoo mode."),
"unexpected-end-tag-implies-table-voodoo":
_("Unexpected end tag (%(name)s) in "
"table context caused voodoo mode."),
"unexpected-cell-in-table-body":
_("Unexpected table cell start tag (%(name)s) "
"in the table body phase."),
"unexpected-cell-end-tag":
_("Got table cell end tag (%(name)s) "
"while required end tags are missing."),
"unexpected-end-tag-in-table-body":
_("Unexpected end tag (%(name)s) in the table body phase. Ignored."),
"unexpected-implied-end-tag-in-table-row":
_("Unexpected implied end tag (%(name)s) in the table row phase."),
"unexpected-end-tag-in-table-row":
_("Unexpected end tag (%(name)s) in the table row phase. Ignored."),
"unexpected-select-in-select":
_("Unexpected select start tag in the select phase "
"treated as select end tag."),
"unexpected-input-in-select":
_("Unexpected input start tag in the select phase."),
"unexpected-start-tag-in-select":
_("Unexpected start tag token (%(name)s in the select phase. "
"Ignored."),
"unexpected-end-tag-in-select":
_("Unexpected end tag (%(name)s) in the select phase. Ignored."),
"unexpected-table-element-start-tag-in-select-in-table":
_("Unexpected table element start tag (%(name)s) in the select in table phase."),
"unexpected-table-element-end-tag-in-select-in-table":
_("Unexpected table element end tag (%(name)s) in the select in table phase."),
"unexpected-char-after-body":
_("Unexpected non-space characters in the after body phase."),
"unexpected-start-tag-after-body":
_("Unexpected start tag token (%(name)s)"
" in the after body phase."),
"unexpected-end-tag-after-body":
_("Unexpected end tag token (%(name)s)"
" in the after body phase."),
"unexpected-char-in-frameset":
_("Unexpected characters in the frameset phase. Characters ignored."),
"unexpected-start-tag-in-frameset":
_("Unexpected start tag token (%(name)s)"
" in the frameset phase. Ignored."),
"unexpected-frameset-in-frameset-innerhtml":
_("Unexpected end tag token (frameset) "
"in the frameset phase (innerHTML)."),
"unexpected-end-tag-in-frameset":
_("Unexpected end tag token (%(name)s)"
" in the frameset phase. Ignored."),
"unexpected-char-after-frameset":
_("Unexpected non-space characters in the "
"after frameset phase. Ignored."),
"unexpected-start-tag-after-frameset":
_("Unexpected start tag (%(name)s)"
" in the after frameset phase. Ignored."),
"unexpected-end-tag-after-frameset":
_("Unexpected end tag (%(name)s)"
" in the after frameset phase. Ignored."),
"unexpected-end-tag-after-body-innerhtml":
_("Unexpected end tag after body(innerHtml)"),
"expected-eof-but-got-char":
_("Unexpected non-space characters. Expected end of file."),
"expected-eof-but-got-start-tag":
_("Unexpected start tag (%(name)s)"
". Expected end of file."),
"expected-eof-but-got-end-tag":
_("Unexpected end tag (%(name)s)"
". Expected end of file."),
"eof-in-table":
_("Unexpected end of file. Expected table content."),
"eof-in-select":
_("Unexpected end of file. Expected select content."),
"eof-in-frameset":
_("Unexpected end of file. Expected frameset content."),
"eof-in-script-in-script":
_("Unexpected end of file. Expected script content."),
"eof-in-foreign-lands":
_("Unexpected end of file. Expected foreign content"),
"non-void-element-with-trailing-solidus":
_("Trailing solidus not allowed on element %(name)s"),
"unexpected-html-element-in-foreign-content":
_("Element %(name)s not allowed in a non-html context"),
"unexpected-end-tag-before-html":
_("Unexpected end tag (%(name)s) before html."),
"XXX-undefined-error":
_("Undefined error (this sucks and should be fixed)"),
}
namespaces = {
"html": "http://www.w3.org/1999/xhtml",
"mathml": "http://www.w3.org/1998/Math/MathML",
"svg": "http://www.w3.org/2000/svg",
"xlink": "http://www.w3.org/1999/xlink",
"xml": "http://www.w3.org/XML/1998/namespace",
"xmlns": "http://www.w3.org/2000/xmlns/"
}
scopingElements = frozenset((
(namespaces["html"], "applet"),
(namespaces["html"], "caption"),
(namespaces["html"], "html"),
(namespaces["html"], "marquee"),
(namespaces["html"], "object"),
(namespaces["html"], "table"),
(namespaces["html"], "td"),
(namespaces["html"], "th"),
(namespaces["mathml"], "mi"),
(namespaces["mathml"], "mo"),
(namespaces["mathml"], "mn"),
(namespaces["mathml"], "ms"),
(namespaces["mathml"], "mtext"),
(namespaces["mathml"], "annotation-xml"),
(namespaces["svg"], "foreignObject"),
(namespaces["svg"], "desc"),
(namespaces["svg"], "title"),
))
formattingElements = frozenset((
(namespaces["html"], "a"),
(namespaces["html"], "b"),
(namespaces["html"], "big"),
(namespaces["html"], "code"),
(namespaces["html"], "em"),
(namespaces["html"], "font"),
(namespaces["html"], "i"),
(namespaces["html"], "nobr"),
(namespaces["html"], "s"),
(namespaces["html"], "small"),
(namespaces["html"], "strike"),
(namespaces["html"], "strong"),
(namespaces["html"], "tt"),
(namespaces["html"], "u")
))
specialElements = frozenset((
(namespaces["html"], "address"),
(namespaces["html"], "applet"),
(namespaces["html"], "area"),
(namespaces["html"], "article"),
(namespaces["html"], "aside"),
(namespaces["html"], "base"),
(namespaces["html"], "basefont"),
(namespaces["html"], "bgsound"),
(namespaces["html"], "blockquote"),
(namespaces["html"], "body"),
(namespaces["html"], "br"),
(namespaces["html"], "button"),
(namespaces["html"], "caption"),
(namespaces["html"], "center"),
(namespaces["html"], "col"),
(namespaces["html"], "colgroup"),
(namespaces["html"], "command"),
(namespaces["html"], "dd"),
(namespaces["html"], "details"),
(namespaces["html"], "dir"),
(namespaces["html"], "div"),
(namespaces["html"], "dl"),
(namespaces["html"], "dt"),
(namespaces["html"], "embed"),
(namespaces["html"], "fieldset"),
(namespaces["html"], "figure"),
(namespaces["html"], "footer"),
(namespaces["html"], "form"),
(namespaces["html"], "frame"),
(namespaces["html"], "frameset"),
(namespaces["html"], "h1"),
(namespaces["html"], "h2"),
(namespaces["html"], "h3"),
(namespaces["html"], "h4"),
(namespaces["html"], "h5"),
(namespaces["html"], "h6"),
(namespaces["html"], "head"),
(namespaces["html"], "header"),
(namespaces["html"], "hr"),
(namespaces["html"], "html"),
(namespaces["html"], "iframe"),
# Note that image is commented out in the spec as "this isn't an
# element that can end up on the stack, so it doesn't matter,"
(namespaces["html"], "image"),
(namespaces["html"], "img"),
(namespaces["html"], "input"),
(namespaces["html"], "isindex"),
(namespaces["html"], "li"),
(namespaces["html"], "link"),
(namespaces["html"], "listing"),
(namespaces["html"], "marquee"),
(namespaces["html"], "menu"),
(namespaces["html"], "meta"),
(namespaces["html"], "nav"),
(namespaces["html"], "noembed"),
(namespaces["html"], "noframes"),
(namespaces["html"], "noscript"),
(namespaces["html"], "object"),
(namespaces["html"], "ol"),
(namespaces["html"], "p"),
(namespaces["html"], "param"),
(namespaces["html"], "plaintext"),
(namespaces["html"], "pre"),
(namespaces["html"], "script"),
(namespaces["html"], "section"),
(namespaces["html"], "select"),
(namespaces["html"], "style"),
(namespaces["html"], "table"),
(namespaces["html"], "tbody"),
(namespaces["html"], "td"),
(namespaces["html"], "textarea"),
(namespaces["html"], "tfoot"),
(namespaces["html"], "th"),
(namespaces["html"], "thead"),
(namespaces["html"], "title"),
(namespaces["html"], "tr"),
(namespaces["html"], "ul"),
(namespaces["html"], "wbr"),
(namespaces["html"], "xmp"),
(namespaces["svg"], "foreignObject")
))
htmlIntegrationPointElements = frozenset((
(namespaces["mathml"], "annotaion-xml"),
(namespaces["svg"], "foreignObject"),
(namespaces["svg"], "desc"),
(namespaces["svg"], "title")
))
mathmlTextIntegrationPointElements = frozenset((
(namespaces["mathml"], "mi"),
(namespaces["mathml"], "mo"),
(namespaces["mathml"], "mn"),
(namespaces["mathml"], "ms"),
(namespaces["mathml"], "mtext")
))
spaceCharacters = frozenset((
"\t",
"\n",
"\u000C",
" ",
"\r"
))
tableInsertModeElements = frozenset((
"table",
"tbody",
"tfoot",
"thead",
"tr"
))
asciiLowercase = frozenset(string.ascii_lowercase)
asciiUppercase = frozenset(string.ascii_uppercase)
asciiLetters = frozenset(string.ascii_letters)
digits = frozenset(string.digits)
hexDigits = frozenset(string.hexdigits)
asciiUpper2Lower = dict([(ord(c), ord(c.lower()))
for c in string.ascii_uppercase])
# Heading elements need to be ordered
headingElements = (
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
)
voidElements = frozenset((
"base",
"command",
"event-source",
"link",
"meta",
"hr",
"br",
"img",
"embed",
"param",
"area",
"col",
"input",
"source",
"track"
))
cdataElements = frozenset(('title', 'textarea'))
rcdataElements = frozenset((
'style',
'script',
'xmp',
'iframe',
'noembed',
'noframes',
'noscript'
))
booleanAttributes = {
"": frozenset(("irrelevant",)),
"style": frozenset(("scoped",)),
"img": frozenset(("ismap",)),
"audio": frozenset(("autoplay", "controls")),
"video": frozenset(("autoplay", "controls")),
"script": frozenset(("defer", "async")),
"details": frozenset(("open",)),
"datagrid": frozenset(("multiple", "disabled")),
"command": frozenset(("hidden", "disabled", "checked", "default")),
"hr": frozenset(("noshade")),
"menu": frozenset(("autosubmit",)),
"fieldset": frozenset(("disabled", "readonly")),
"option": frozenset(("disabled", "readonly", "selected")),
"optgroup": frozenset(("disabled", "readonly")),
"button": frozenset(("disabled", "autofocus")),
"input": frozenset(("disabled", "readonly", "required", "autofocus", "checked", "ismap")),
"select": frozenset(("disabled", "readonly", "autofocus", "multiple")),
"output": frozenset(("disabled", "readonly")),
}
# entitiesWindows1252 has to be _ordered_ and needs to have an index. It
# therefore can't be a frozenset.
entitiesWindows1252 = (
8364, # 0x80 0x20AC EURO SIGN
65533, # 0x81 UNDEFINED
8218, # 0x82 0x201A SINGLE LOW-9 QUOTATION MARK
402, # 0x83 0x0192 LATIN SMALL LETTER F WITH HOOK
8222, # 0x84 0x201E DOUBLE LOW-9 QUOTATION MARK
8230, # 0x85 0x2026 HORIZONTAL ELLIPSIS
8224, # 0x86 0x2020 DAGGER
8225, # 0x87 0x2021 DOUBLE DAGGER
710, # 0x88 0x02C6 MODIFIER LETTER CIRCUMFLEX ACCENT
8240, # 0x89 0x2030 PER MILLE SIGN
352, # 0x8A 0x0160 LATIN CAPITAL LETTER S WITH CARON
8249, # 0x8B 0x2039 SINGLE LEFT-POINTING ANGLE QUOTATION MARK
338, # 0x8C 0x0152 LATIN CAPITAL LIGATURE OE
65533, # 0x8D UNDEFINED
381, # 0x8E 0x017D LATIN CAPITAL LETTER Z WITH CARON
65533, # 0x8F UNDEFINED
65533, # 0x90 UNDEFINED
8216, # 0x91 0x2018 LEFT SINGLE QUOTATION MARK
8217, # 0x92 0x2019 RIGHT SINGLE QUOTATION MARK
8220, # 0x93 0x201C LEFT DOUBLE QUOTATION MARK
8221, # 0x94 0x201D RIGHT DOUBLE QUOTATION MARK
8226, # 0x95 0x2022 BULLET
8211, # 0x96 0x2013 EN DASH
8212, # 0x97 0x2014 EM DASH
732, # 0x98 0x02DC SMALL TILDE
8482, # 0x99 0x2122 TRADE MARK SIGN
353, # 0x9A 0x0161 LATIN SMALL LETTER S WITH CARON
8250, # 0x9B 0x203A SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
339, # 0x9C 0x0153 LATIN SMALL LIGATURE OE
65533, # 0x9D UNDEFINED
382, # 0x9E 0x017E LATIN SMALL LETTER Z WITH CARON
376 # 0x9F 0x0178 LATIN CAPITAL LETTER Y WITH DIAERESIS
)
xmlEntities = frozenset(('lt;', 'gt;', 'amp;', 'apos;', 'quot;'))
entities = {
"AElig": "\xc6",
"AElig;": "\xc6",
"AMP": "&",
"AMP;": "&",
"Aacute": "\xc1",
"Aacute;": "\xc1",
"Abreve;": "\u0102",
"Acirc": "\xc2",
"Acirc;": "\xc2",
"Acy;": "\u0410",
"Afr;": "\U0001d504",
"Agrave": "\xc0",
"Agrave;": "\xc0",
"Alpha;": "\u0391",
"Amacr;": "\u0100",
"And;": "\u2a53",
"Aogon;": "\u0104",
"Aopf;": "\U0001d538",
"ApplyFunction;": "\u2061",
"Aring": "\xc5",
"Aring;": "\xc5",
"Ascr;": "\U0001d49c",
"Assign;": "\u2254",
"Atilde": "\xc3",
"Atilde;": "\xc3",
"Auml": "\xc4",
"Auml;": "\xc4",
"Backslash;": "\u2216",
"Barv;": "\u2ae7",
"Barwed;": "\u2306",
"Bcy;": "\u0411",
"Because;": "\u2235",
"Bernoullis;": "\u212c",
"Beta;": "\u0392",
"Bfr;": "\U0001d505",
"Bopf;": "\U0001d539",
"Breve;": "\u02d8",
"Bscr;": "\u212c",
"Bumpeq;": "\u224e",
"CHcy;": "\u0427",
"COPY": "\xa9",
"COPY;": "\xa9",
"Cacute;": "\u0106",
"Cap;": "\u22d2",
"CapitalDifferentialD;": "\u2145",
"Cayleys;": "\u212d",
"Ccaron;": "\u010c",
"Ccedil": "\xc7",
"Ccedil;": "\xc7",
"Ccirc;": "\u0108",
"Cconint;": "\u2230",
"Cdot;": "\u010a",
"Cedilla;": "\xb8",
"CenterDot;": "\xb7",
"Cfr;": "\u212d",
"Chi;": "\u03a7",
"CircleDot;": "\u2299",
"CircleMinus;": "\u2296",
"CirclePlus;": "\u2295",
"CircleTimes;": "\u2297",
"ClockwiseContourIntegral;": "\u2232",
"CloseCurlyDoubleQuote;": "\u201d",
"CloseCurlyQuote;": "\u2019",
"Colon;": "\u2237",
"Colone;": "\u2a74",
"Congruent;": "\u2261",
"Conint;": "\u222f",
"ContourIntegral;": "\u222e",
"Copf;": "\u2102",
"Coproduct;": "\u2210",
"CounterClockwiseContourIntegral;": "\u2233",
"Cross;": "\u2a2f",
"Cscr;": "\U0001d49e",
"Cup;": "\u22d3",
"CupCap;": "\u224d",
"DD;": "\u2145",
"DDotrahd;": "\u2911",
"DJcy;": "\u0402",
"DScy;": "\u0405",
"DZcy;": "\u040f",
"Dagger;": "\u2021",
"Darr;": "\u21a1",
"Dashv;": "\u2ae4",
"Dcaron;": "\u010e",
"Dcy;": "\u0414",
"Del;": "\u2207",
"Delta;": "\u0394",
"Dfr;": "\U0001d507",
"DiacriticalAcute;": "\xb4",
"DiacriticalDot;": "\u02d9",
"DiacriticalDoubleAcute;": "\u02dd",
"DiacriticalGrave;": "`",
"DiacriticalTilde;": "\u02dc",
"Diamond;": "\u22c4",
"DifferentialD;": "\u2146",
"Dopf;": "\U0001d53b",
"Dot;": "\xa8",
"DotDot;": "\u20dc",
"DotEqual;": "\u2250",
"DoubleContourIntegral;": "\u222f",
"DoubleDot;": "\xa8",
"DoubleDownArrow;": "\u21d3",
"DoubleLeftArrow;": "\u21d0",
"DoubleLeftRightArrow;": "\u21d4",
"DoubleLeftTee;": "\u2ae4",
"DoubleLongLeftArrow;": "\u27f8",
"DoubleLongLeftRightArrow;": "\u27fa",
"DoubleLongRightArrow;": "\u27f9",
"DoubleRightArrow;": "\u21d2",
"DoubleRightTee;": "\u22a8",
"DoubleUpArrow;": "\u21d1",
"DoubleUpDownArrow;": "\u21d5",
"DoubleVerticalBar;": "\u2225",
"DownArrow;": "\u2193",
"DownArrowBar;": "\u2913",
"DownArrowUpArrow;": "\u21f5",
"DownBreve;": "\u0311",
"DownLeftRightVector;": "\u2950",
"DownLeftTeeVector;": "\u295e",
"DownLeftVector;": "\u21bd",
"DownLeftVectorBar;": "\u2956",
"DownRightTeeVector;": "\u295f",
"DownRightVector;": "\u21c1",
"DownRightVectorBar;": "\u2957",
"DownTee;": "\u22a4",
"DownTeeArrow;": "\u21a7",
"Downarrow;": "\u21d3",
"Dscr;": "\U0001d49f",
"Dstrok;": "\u0110",
"ENG;": "\u014a",
"ETH": "\xd0",
"ETH;": "\xd0",
"Eacute": "\xc9",
"Eacute;": "\xc9",
"Ecaron;": "\u011a",
"Ecirc": "\xca",
"Ecirc;": "\xca",
"Ecy;": "\u042d",
"Edot;": "\u0116",
"Efr;": "\U0001d508",
"Egrave": "\xc8",
"Egrave;": "\xc8",
"Element;": "\u2208",
"Emacr;": "\u0112",
"EmptySmallSquare;": "\u25fb",
"EmptyVerySmallSquare;": "\u25ab",
"Eogon;": "\u0118",
"Eopf;": "\U0001d53c",
"Epsilon;": "\u0395",
"Equal;": "\u2a75",
"EqualTilde;": "\u2242",
"Equilibrium;": "\u21cc",
"Escr;": "\u2130",
"Esim;": "\u2a73",
"Eta;": "\u0397",
"Euml": "\xcb",
"Euml;": "\xcb",
"Exists;": "\u2203",
"ExponentialE;": "\u2147",
"Fcy;": "\u0424",
"Ffr;": "\U0001d509",
"FilledSmallSquare;": "\u25fc",
"FilledVerySmallSquare;": "\u25aa",
"Fopf;": "\U0001d53d",
"ForAll;": "\u2200",
"Fouriertrf;": "\u2131",
"Fscr;": "\u2131",
"GJcy;": "\u0403",
"GT": ">",
"GT;": ">",
"Gamma;": "\u0393",
"Gammad;": "\u03dc",
"Gbreve;": "\u011e",
"Gcedil;": "\u0122",
"Gcirc;": "\u011c",
"Gcy;": "\u0413",
"Gdot;": "\u0120",
"Gfr;": "\U0001d50a",
"Gg;": "\u22d9",
"Gopf;": "\U0001d53e",
"GreaterEqual;": "\u2265",
"GreaterEqualLess;": "\u22db",
"GreaterFullEqual;": "\u2267",
"GreaterGreater;": "\u2aa2",
"GreaterLess;": "\u2277",
"GreaterSlantEqual;": "\u2a7e",
"GreaterTilde;": "\u2273",
"Gscr;": "\U0001d4a2",
"Gt;": "\u226b",
"HARDcy;": "\u042a",
"Hacek;": "\u02c7",
"Hat;": "^",
"Hcirc;": "\u0124",
"Hfr;": "\u210c",
"HilbertSpace;": "\u210b",
"Hopf;": "\u210d",
"HorizontalLine;": "\u2500",
"Hscr;": "\u210b",
"Hstrok;": "\u0126",
"HumpDownHump;": "\u224e",
"HumpEqual;": "\u224f",
"IEcy;": "\u0415",
"IJlig;": "\u0132",
"IOcy;": "\u0401",
"Iacute": "\xcd",
"Iacute;": "\xcd",
"Icirc": "\xce",
"Icirc;": "\xce",
"Icy;": "\u0418",
"Idot;": "\u0130",
"Ifr;": "\u2111",
"Igrave": "\xcc",
"Igrave;": "\xcc",
"Im;": "\u2111",
"Imacr;": "\u012a",
"ImaginaryI;": "\u2148",
"Implies;": "\u21d2",
"Int;": "\u222c",
"Integral;": "\u222b",
"Intersection;": "\u22c2",
"InvisibleComma;": "\u2063",
"InvisibleTimes;": "\u2062",
"Iogon;": "\u012e",
"Iopf;": "\U0001d540",
"Iota;": "\u0399",
"Iscr;": "\u2110",
"Itilde;": "\u0128",
"Iukcy;": "\u0406",
"Iuml": "\xcf",
"Iuml;": "\xcf",
"Jcirc;": "\u0134",
"Jcy;": "\u0419",
"Jfr;": "\U0001d50d",
"Jopf;": "\U0001d541",
"Jscr;": "\U0001d4a5",
"Jsercy;": "\u0408",
"Jukcy;": "\u0404",
"KHcy;": "\u0425",
"KJcy;": "\u040c",
"Kappa;": "\u039a",
"Kcedil;": "\u0136",
"Kcy;": "\u041a",
"Kfr;": "\U0001d50e",
"Kopf;": "\U0001d542",
"Kscr;": "\U0001d4a6",
"LJcy;": "\u0409",
"LT": "<",
"LT;": "<",
"Lacute;": "\u0139",
"Lambda;": "\u039b",
"Lang;": "\u27ea",
"Laplacetrf;": "\u2112",
"Larr;": "\u219e",
"Lcaron;": "\u013d",
"Lcedil;": "\u013b",
"Lcy;": "\u041b",
"LeftAngleBracket;": "\u27e8",
"LeftArrow;": "\u2190",
"LeftArrowBar;": "\u21e4",
"LeftArrowRightArrow;": "\u21c6",
"LeftCeiling;": "\u2308",
"LeftDoubleBracket;": "\u27e6",
"LeftDownTeeVector;": "\u2961",
"LeftDownVector;": "\u21c3",
"LeftDownVectorBar;": "\u2959",
"LeftFloor;": "\u230a",
"LeftRightArrow;": "\u2194",
"LeftRightVector;": "\u294e",
"LeftTee;": "\u22a3",
"LeftTeeArrow;": "\u21a4",
"LeftTeeVector;": "\u295a",
"LeftTriangle;": "\u22b2",
"LeftTriangleBar;": "\u29cf",
"LeftTriangleEqual;": "\u22b4",
"LeftUpDownVector;": "\u2951",
"LeftUpTeeVector;": "\u2960",
"LeftUpVector;": "\u21bf",
"LeftUpVectorBar;": "\u2958",
"LeftVector;": "\u21bc",
"LeftVectorBar;": "\u2952",
"Leftarrow;": "\u21d0",
"Leftrightarrow;": "\u21d4",
"LessEqualGreater;": "\u22da",
"LessFullEqual;": "\u2266",
"LessGreater;": "\u2276",
"LessLess;": "\u2aa1",
"LessSlantEqual;": "\u2a7d",
"LessTilde;": "\u2272",
"Lfr;": "\U0001d50f",
"Ll;": "\u22d8",
"Lleftarrow;": "\u21da",
"Lmidot;": "\u013f",
"LongLeftArrow;": "\u27f5",
"LongLeftRightArrow;": "\u27f7",
"LongRightArrow;": "\u27f6",
"Longleftarrow;": "\u27f8",
"Longleftrightarrow;": "\u27fa",
"Longrightarrow;": "\u27f9",
"Lopf;": "\U0001d543",
"LowerLeftArrow;": "\u2199",
"LowerRightArrow;": "\u2198",
"Lscr;": "\u2112",
"Lsh;": "\u21b0",
"Lstrok;": "\u0141",
"Lt;": "\u226a",
"Map;": "\u2905",
"Mcy;": "\u041c",
"MediumSpace;": "\u205f",
"Mellintrf;": "\u2133",
"Mfr;": "\U0001d510",
"MinusPlus;": "\u2213",
"Mopf;": "\U0001d544",
"Mscr;": "\u2133",
"Mu;": "\u039c",
"NJcy;": "\u040a",
"Nacute;": "\u0143",
"Ncaron;": "\u0147",
"Ncedil;": "\u0145",
"Ncy;": "\u041d",
"NegativeMediumSpace;": "\u200b",
"NegativeThickSpace;": "\u200b",
"NegativeThinSpace;": "\u200b",
"NegativeVeryThinSpace;": "\u200b",
"NestedGreaterGreater;": "\u226b",
"NestedLessLess;": "\u226a",
"NewLine;": "\n",
"Nfr;": "\U0001d511",
"NoBreak;": "\u2060",
"NonBreakingSpace;": "\xa0",
"Nopf;": "\u2115",
"Not;": "\u2aec",
"NotCongruent;": "\u2262",
"NotCupCap;": "\u226d",
"NotDoubleVerticalBar;": "\u2226",
"NotElement;": "\u2209",
"NotEqual;": "\u2260",
"NotEqualTilde;": "\u2242\u0338",
"NotExists;": "\u2204",
"NotGreater;": "\u226f",
"NotGreaterEqual;": "\u2271",
"NotGreaterFullEqual;": "\u2267\u0338",
"NotGreaterGreater;": "\u226b\u0338",
"NotGreaterLess;": "\u2279",
"NotGreaterSlantEqual;": "\u2a7e\u0338",
"NotGreaterTilde;": "\u2275",
"NotHumpDownHump;": "\u224e\u0338",
"NotHumpEqual;": "\u224f\u0338",
"NotLeftTriangle;": "\u22ea",
"NotLeftTriangleBar;": "\u29cf\u0338",
"NotLeftTriangleEqual;": "\u22ec",
"NotLess;": "\u226e",
"NotLessEqual;": "\u2270",
"NotLessGreater;": "\u2278",
"NotLessLess;": "\u226a\u0338",
"NotLessSlantEqual;": "\u2a7d\u0338",
"NotLessTilde;": "\u2274",
"NotNestedGreaterGreater;": "\u2aa2\u0338",
"NotNestedLessLess;": "\u2aa1\u0338",
"NotPrecedes;": "\u2280",
"NotPrecedesEqual;": "\u2aaf\u0338",
"NotPrecedesSlantEqual;": "\u22e0",
"NotReverseElement;": "\u220c",
"NotRightTriangle;": "\u22eb",
"NotRightTriangleBar;": "\u29d0\u0338",
"NotRightTriangleEqual;": "\u22ed",
"NotSquareSubset;": "\u228f\u0338",
"NotSquareSubsetEqual;": "\u22e2",
"NotSquareSuperset;": "\u2290\u0338",
"NotSquareSupersetEqual;": "\u22e3",
"NotSubset;": "\u2282\u20d2",
"NotSubsetEqual;": "\u2288",
"NotSucceeds;": "\u2281",
"NotSucceedsEqual;": "\u2ab0\u0338",
"NotSucceedsSlantEqual;": "\u22e1",
"NotSucceedsTilde;": "\u227f\u0338",
"NotSuperset;": "\u2283\u20d2",
"NotSupersetEqual;": "\u2289",
"NotTilde;": "\u2241",
"NotTildeEqual;": "\u2244",
"NotTildeFullEqual;": "\u2247",
"NotTildeTilde;": "\u2249",
"NotVerticalBar;": "\u2224",
"Nscr;": "\U0001d4a9",
"Ntilde": "\xd1",
"Ntilde;": "\xd1",
"Nu;": "\u039d",
"OElig;": "\u0152",
"Oacute": "\xd3",
"Oacute;": "\xd3",
"Ocirc": "\xd4",
"Ocirc;": "\xd4",
"Ocy;": "\u041e",
"Odblac;": "\u0150",
"Ofr;": "\U0001d512",
"Ograve": "\xd2",
"Ograve;": "\xd2",
"Omacr;": "\u014c",
"Omega;": "\u03a9",
"Omicron;": "\u039f",
"Oopf;": "\U0001d546",
"OpenCurlyDoubleQuote;": "\u201c",
"OpenCurlyQuote;": "\u2018",
"Or;": "\u2a54",
"Oscr;": "\U0001d4aa",
"Oslash": "\xd8",
"Oslash;": "\xd8",
"Otilde": "\xd5",
"Otilde;": "\xd5",
"Otimes;": "\u2a37",
"Ouml": "\xd6",
"Ouml;": "\xd6",
"OverBar;": "\u203e",
"OverBrace;": "\u23de",
"OverBracket;": "\u23b4",
"OverParenthesis;": "\u23dc",
"PartialD;": "\u2202",
"Pcy;": "\u041f",
"Pfr;": "\U0001d513",
"Phi;": "\u03a6",
"Pi;": "\u03a0",
"PlusMinus;": "\xb1",
"Poincareplane;": "\u210c",
"Popf;": "\u2119",
"Pr;": "\u2abb",
"Precedes;": "\u227a",
"PrecedesEqual;": "\u2aaf",
"PrecedesSlantEqual;": "\u227c",
"PrecedesTilde;": "\u227e",
"Prime;": "\u2033",
"Product;": "\u220f",
"Proportion;": "\u2237",
"Proportional;": "\u221d",
"Pscr;": "\U0001d4ab",
"Psi;": "\u03a8",
"QUOT": "\"",
"QUOT;": "\"",
"Qfr;": "\U0001d514",
"Qopf;": "\u211a",
"Qscr;": "\U0001d4ac",
"RBarr;": "\u2910",
"REG": "\xae",
"REG;": "\xae",
"Racute;": "\u0154",
"Rang;": "\u27eb",
"Rarr;": "\u21a0",
"Rarrtl;": "\u2916",
"Rcaron;": "\u0158",
"Rcedil;": "\u0156",
"Rcy;": "\u0420",
"Re;": "\u211c",
"ReverseElement;": "\u220b",
"ReverseEquilibrium;": "\u21cb",
"ReverseUpEquilibrium;": "\u296f",
"Rfr;": "\u211c",
"Rho;": "\u03a1",
"RightAngleBracket;": "\u27e9",
"RightArrow;": "\u2192",
"RightArrowBar;": "\u21e5",
"RightArrowLeftArrow;": "\u21c4",
"RightCeiling;": "\u2309",
"RightDoubleBracket;": "\u27e7",
"RightDownTeeVector;": "\u295d",
"RightDownVector;": "\u21c2",
"RightDownVectorBar;": "\u2955",
"RightFloor;": "\u230b",
"RightTee;": "\u22a2",
"RightTeeArrow;": "\u21a6",
"RightTeeVector;": "\u295b",
"RightTriangle;": "\u22b3",
"RightTriangleBar;": "\u29d0",
"RightTriangleEqual;": "\u22b5",
"RightUpDownVector;": "\u294f",
"RightUpTeeVector;": "\u295c",
"RightUpVector;": "\u21be",
"RightUpVectorBar;": "\u2954",
"RightVector;": "\u21c0",
"RightVectorBar;": "\u2953",
"Rightarrow;": "\u21d2",
"Ropf;": "\u211d",
"RoundImplies;": "\u2970",
"Rrightarrow;": "\u21db",
"Rscr;": "\u211b",
"Rsh;": "\u21b1",
"RuleDelayed;": "\u29f4",
"SHCHcy;": "\u0429",
"SHcy;": "\u0428",
"SOFTcy;": "\u042c",
"Sacute;": "\u015a",
"Sc;": "\u2abc",
"Scaron;": "\u0160",
"Scedil;": "\u015e",
"Scirc;": "\u015c",
"Scy;": "\u0421",
"Sfr;": "\U0001d516",
"ShortDownArrow;": "\u2193",
"ShortLeftArrow;": "\u2190",
"ShortRightArrow;": "\u2192",
"ShortUpArrow;": "\u2191",
"Sigma;": "\u03a3",
"SmallCircle;": "\u2218",
"Sopf;": "\U0001d54a",
"Sqrt;": "\u221a",
"Square;": "\u25a1",
"SquareIntersection;": "\u2293",
"SquareSubset;": "\u228f",
"SquareSubsetEqual;": "\u2291",
"SquareSuperset;": "\u2290",
"SquareSupersetEqual;": "\u2292",
"SquareUnion;": "\u2294",
"Sscr;": "\U0001d4ae",
"Star;": "\u22c6",
"Sub;": "\u22d0",
"Subset;": "\u22d0",
"SubsetEqual;": "\u2286",
"Succeeds;": "\u227b",
"SucceedsEqual;": "\u2ab0",
"SucceedsSlantEqual;": "\u227d",
"SucceedsTilde;": "\u227f",
"SuchThat;": "\u220b",
"Sum;": "\u2211",
"Sup;": "\u22d1",
"Superset;": "\u2283",
"SupersetEqual;": "\u2287",
"Supset;": "\u22d1",
"THORN": "\xde",
"THORN;": "\xde",
"TRADE;": "\u2122",
"TSHcy;": "\u040b",
"TScy;": "\u0426",
"Tab;": "\t",
"Tau;": "\u03a4",
"Tcaron;": "\u0164",
"Tcedil;": "\u0162",
"Tcy;": "\u0422",
"Tfr;": "\U0001d517",
"Therefore;": "\u2234",
"Theta;": "\u0398",
"ThickSpace;": "\u205f\u200a",
"ThinSpace;": "\u2009",
"Tilde;": "\u223c",
"TildeEqual;": "\u2243",
"TildeFullEqual;": "\u2245",
"TildeTilde;": "\u2248",
"Topf;": "\U0001d54b",
"TripleDot;": "\u20db",
"Tscr;": "\U0001d4af",
"Tstrok;": "\u0166",
"Uacute": "\xda",
"Uacute;": "\xda",
"Uarr;": "\u219f",
"Uarrocir;": "\u2949",
"Ubrcy;": "\u040e",
"Ubreve;": "\u016c",
"Ucirc": "\xdb",
"Ucirc;": "\xdb",
"Ucy;": "\u0423",
"Udblac;": "\u0170",
"Ufr;": "\U0001d518",
"Ugrave": "\xd9",
"Ugrave;": "\xd9",
"Umacr;": "\u016a",
"UnderBar;": "_",
"UnderBrace;": "\u23df",
"UnderBracket;": "\u23b5",
"UnderParenthesis;": "\u23dd",
"Union;": "\u22c3",
"UnionPlus;": "\u228e",
"Uogon;": "\u0172",
"Uopf;": "\U0001d54c",
"UpArrow;": "\u2191",
"UpArrowBar;": "\u2912",
"UpArrowDownArrow;": "\u21c5",
"UpDownArrow;": "\u2195",
"UpEquilibrium;": "\u296e",
"UpTee;": "\u22a5",
"UpTeeArrow;": "\u21a5",
"Uparrow;": "\u21d1",
"Updownarrow;": "\u21d5",
"UpperLeftArrow;": "\u2196",
"UpperRightArrow;": "\u2197",
"Upsi;": "\u03d2",
"Upsilon;": "\u03a5",
"Uring;": "\u016e",
"Uscr;": "\U0001d4b0",
"Utilde;": "\u0168",
"Uuml": "\xdc",
"Uuml;": "\xdc",
"VDash;": "\u22ab",
"Vbar;": "\u2aeb",
"Vcy;": "\u0412",
"Vdash;": "\u22a9",
"Vdashl;": "\u2ae6",
"Vee;": "\u22c1",
"Verbar;": "\u2016",
"Vert;": "\u2016",
"VerticalBar;": "\u2223",
"VerticalLine;": "|",
"VerticalSeparator;": "\u2758",
"VerticalTilde;": "\u2240",
"VeryThinSpace;": "\u200a",
"Vfr;": "\U0001d519",
"Vopf;": "\U0001d54d",
"Vscr;": "\U0001d4b1",
"Vvdash;": "\u22aa",
"Wcirc;": "\u0174",
"Wedge;": "\u22c0",
"Wfr;": "\U0001d51a",
"Wopf;": "\U0001d54e",
"Wscr;": "\U0001d4b2",
"Xfr;": "\U0001d51b",
"Xi;": "\u039e",
"Xopf;": "\U0001d54f",
"Xscr;": "\U0001d4b3",
"YAcy;": "\u042f",
"YIcy;": "\u0407",
"YUcy;": "\u042e",
"Yacute": "\xdd",
"Yacute;": "\xdd",
"Ycirc;": "\u0176",
"Ycy;": "\u042b",
"Yfr;": "\U0001d51c",
"Yopf;": "\U0001d550",
"Yscr;": "\U0001d4b4",
"Yuml;": "\u0178",
"ZHcy;": "\u0416",
"Zacute;": "\u0179",
"Zcaron;": "\u017d",
"Zcy;": "\u0417",
"Zdot;": "\u017b",
"ZeroWidthSpace;": "\u200b",
"Zeta;": "\u0396",
"Zfr;": "\u2128",
"Zopf;": "\u2124",
"Zscr;": "\U0001d4b5",
"aacute": "\xe1",
"aacute;": "\xe1",
"abreve;": "\u0103",
"ac;": "\u223e",
"acE;": "\u223e\u0333",
"acd;": "\u223f",
"acirc": "\xe2",
"acirc;": "\xe2",
"acute": "\xb4",
"acute;": "\xb4",
"acy;": "\u0430",
"aelig": "\xe6",
"aelig;": "\xe6",
"af;": "\u2061",
"afr;": "\U0001d51e",
"agrave": "\xe0",
"agrave;": "\xe0",
"alefsym;": "\u2135",
"aleph;": "\u2135",
"alpha;": "\u03b1",
"amacr;": "\u0101",
"amalg;": "\u2a3f",
"amp": "&",
"amp;": "&",
"and;": "\u2227",
"andand;": "\u2a55",
"andd;": "\u2a5c",
"andslope;": "\u2a58",
"andv;": "\u2a5a",
"ang;": "\u2220",
"ange;": "\u29a4",
"angle;": "\u2220",
"angmsd;": "\u2221",
"angmsdaa;": "\u29a8",
"angmsdab;": "\u29a9",
"angmsdac;": "\u29aa",
"angmsdad;": "\u29ab",
"angmsdae;": "\u29ac",
"angmsdaf;": "\u29ad",
"angmsdag;": "\u29ae",
"angmsdah;": "\u29af",
"angrt;": "\u221f",
"angrtvb;": "\u22be",
"angrtvbd;": "\u299d",
"angsph;": "\u2222",
"angst;": "\xc5",
"angzarr;": "\u237c",
"aogon;": "\u0105",
"aopf;": "\U0001d552",
"ap;": "\u2248",
"apE;": "\u2a70",
"apacir;": "\u2a6f",
"ape;": "\u224a",
"apid;": "\u224b",
"apos;": "'",
"approx;": "\u2248",
"approxeq;": "\u224a",
"aring": "\xe5",
"aring;": "\xe5",
"ascr;": "\U0001d4b6",
"ast;": "*",
"asymp;": "\u2248",
"asympeq;": "\u224d",
"atilde": "\xe3",
"atilde;": "\xe3",
"auml": "\xe4",
"auml;": "\xe4",
"awconint;": "\u2233",
"awint;": "\u2a11",
"bNot;": "\u2aed",
"backcong;": "\u224c",
"backepsilon;": "\u03f6",
"backprime;": "\u2035",
"backsim;": "\u223d",
"backsimeq;": "\u22cd",
"barvee;": "\u22bd",
"barwed;": "\u2305",
"barwedge;": "\u2305",
"bbrk;": "\u23b5",
"bbrktbrk;": "\u23b6",
"bcong;": "\u224c",
"bcy;": "\u0431",
"bdquo;": "\u201e",
"becaus;": "\u2235",
"because;": "\u2235",
"bemptyv;": "\u29b0",
"bepsi;": "\u03f6",
"bernou;": "\u212c",
"beta;": "\u03b2",
"beth;": "\u2136",
"between;": "\u226c",
"bfr;": "\U0001d51f",
"bigcap;": "\u22c2",
"bigcirc;": "\u25ef",
"bigcup;": "\u22c3",
"bigodot;": "\u2a00",
"bigoplus;": "\u2a01",
"bigotimes;": "\u2a02",
"bigsqcup;": "\u2a06",
"bigstar;": "\u2605",
"bigtriangledown;": "\u25bd",
"bigtriangleup;": "\u25b3",
"biguplus;": "\u2a04",
"bigvee;": "\u22c1",
"bigwedge;": "\u22c0",
"bkarow;": "\u290d",
"blacklozenge;": "\u29eb",
"blacksquare;": "\u25aa",
"blacktriangle;": "\u25b4",
"blacktriangledown;": "\u25be",
"blacktriangleleft;": "\u25c2",
"blacktriangleright;": "\u25b8",
"blank;": "\u2423",
"blk12;": "\u2592",
"blk14;": "\u2591",
"blk34;": "\u2593",
"block;": "\u2588",
"bne;": "=\u20e5",
"bnequiv;": "\u2261\u20e5",
"bnot;": "\u2310",
"bopf;": "\U0001d553",
"bot;": "\u22a5",
"bottom;": "\u22a5",
"bowtie;": "\u22c8",
"boxDL;": "\u2557",
"boxDR;": "\u2554",
"boxDl;": "\u2556",
"boxDr;": "\u2553",
"boxH;": "\u2550",
"boxHD;": "\u2566",
"boxHU;": "\u2569",
"boxHd;": "\u2564",
"boxHu;": "\u2567",
"boxUL;": "\u255d",
"boxUR;": "\u255a",
"boxUl;": "\u255c",
"boxUr;": "\u2559",
"boxV;": "\u2551",
"boxVH;": "\u256c",
"boxVL;": "\u2563",
"boxVR;": "\u2560",
"boxVh;": "\u256b",
"boxVl;": "\u2562",
"boxVr;": "\u255f",
"boxbox;": "\u29c9",
"boxdL;": "\u2555",
"boxdR;": "\u2552",
"boxdl;": "\u2510",
"boxdr;": "\u250c",
"boxh;": "\u2500",
"boxhD;": "\u2565",
"boxhU;": "\u2568",
"boxhd;": "\u252c",
"boxhu;": "\u2534",
"boxminus;": "\u229f",
"boxplus;": "\u229e",
"boxtimes;": "\u22a0",
"boxuL;": "\u255b",
"boxuR;": "\u2558",
"boxul;": "\u2518",
"boxur;": "\u2514",
"boxv;": "\u2502",
"boxvH;": "\u256a",
"boxvL;": "\u2561",
"boxvR;": "\u255e",
"boxvh;": "\u253c",
"boxvl;": "\u2524",
"boxvr;": "\u251c",
"bprime;": "\u2035",
"breve;": "\u02d8",
"brvbar": "\xa6",
"brvbar;": "\xa6",
"bscr;": "\U0001d4b7",
"bsemi;": "\u204f",
"bsim;": "\u223d",
"bsime;": "\u22cd",
"bsol;": "\\",
"bsolb;": "\u29c5",
"bsolhsub;": "\u27c8",
"bull;": "\u2022",
"bullet;": "\u2022",
"bump;": "\u224e",
"bumpE;": "\u2aae",
"bumpe;": "\u224f",
"bumpeq;": "\u224f",
"cacute;": "\u0107",
"cap;": "\u2229",
"capand;": "\u2a44",
"capbrcup;": "\u2a49",
"capcap;": "\u2a4b",
"capcup;": "\u2a47",
"capdot;": "\u2a40",
"caps;": "\u2229\ufe00",
"caret;": "\u2041",
"caron;": "\u02c7",
"ccaps;": "\u2a4d",
"ccaron;": "\u010d",
"ccedil": "\xe7",
"ccedil;": "\xe7",
"ccirc;": "\u0109",
"ccups;": "\u2a4c",
"ccupssm;": "\u2a50",
"cdot;": "\u010b",
"cedil": "\xb8",
"cedil;": "\xb8",
"cemptyv;": "\u29b2",
"cent": "\xa2",
"cent;": "\xa2",
"centerdot;": "\xb7",
"cfr;": "\U0001d520",
"chcy;": "\u0447",
"check;": "\u2713",
"checkmark;": "\u2713",
"chi;": "\u03c7",
"cir;": "\u25cb",
"cirE;": "\u29c3",
"circ;": "\u02c6",
"circeq;": "\u2257",
"circlearrowleft;": "\u21ba",
"circlearrowright;": "\u21bb",
"circledR;": "\xae",
"circledS;": "\u24c8",
"circledast;": "\u229b",
"circledcirc;": "\u229a",
"circleddash;": "\u229d",
"cire;": "\u2257",
"cirfnint;": "\u2a10",
"cirmid;": "\u2aef",
"cirscir;": "\u29c2",
"clubs;": "\u2663",
"clubsuit;": "\u2663",
"colon;": ":",
"colone;": "\u2254",
"coloneq;": "\u2254",
"comma;": ",",
"commat;": "@",
"comp;": "\u2201",
"compfn;": "\u2218",
"complement;": "\u2201",
"complexes;": "\u2102",
"cong;": "\u2245",
"congdot;": "\u2a6d",
"conint;": "\u222e",
"copf;": "\U0001d554",
"coprod;": "\u2210",
"copy": "\xa9",
"copy;": "\xa9",
"copysr;": "\u2117",
"crarr;": "\u21b5",
"cross;": "\u2717",
"cscr;": "\U0001d4b8",
"csub;": "\u2acf",
"csube;": "\u2ad1",
"csup;": "\u2ad0",
"csupe;": "\u2ad2",
"ctdot;": "\u22ef",
"cudarrl;": "\u2938",
"cudarrr;": "\u2935",
"cuepr;": "\u22de",
"cuesc;": "\u22df",
"cularr;": "\u21b6",
"cularrp;": "\u293d",
"cup;": "\u222a",
"cupbrcap;": "\u2a48",
"cupcap;": "\u2a46",
"cupcup;": "\u2a4a",
"cupdot;": "\u228d",
"cupor;": "\u2a45",
"cups;": "\u222a\ufe00",
"curarr;": "\u21b7",
"curarrm;": "\u293c",
"curlyeqprec;": "\u22de",
"curlyeqsucc;": "\u22df",
"curlyvee;": "\u22ce",
"curlywedge;": "\u22cf",
"curren": "\xa4",
"curren;": "\xa4",
"curvearrowleft;": "\u21b6",
"curvearrowright;": "\u21b7",
"cuvee;": "\u22ce",
"cuwed;": "\u22cf",
"cwconint;": "\u2232",
"cwint;": "\u2231",
"cylcty;": "\u232d",
"dArr;": "\u21d3",
"dHar;": "\u2965",
"dagger;": "\u2020",
"daleth;": "\u2138",
"darr;": "\u2193",
"dash;": "\u2010",
"dashv;": "\u22a3",
"dbkarow;": "\u290f",
"dblac;": "\u02dd",
"dcaron;": "\u010f",
"dcy;": "\u0434",
"dd;": "\u2146",
"ddagger;": "\u2021",
"ddarr;": "\u21ca",
"ddotseq;": "\u2a77",
"deg": "\xb0",
"deg;": "\xb0",
"delta;": "\u03b4",
"demptyv;": "\u29b1",
"dfisht;": "\u297f",
"dfr;": "\U0001d521",
"dharl;": "\u21c3",
"dharr;": "\u21c2",
"diam;": "\u22c4",
"diamond;": "\u22c4",
"diamondsuit;": "\u2666",
"diams;": "\u2666",
"die;": "\xa8",
"digamma;": "\u03dd",
"disin;": "\u22f2",
"div;": "\xf7",
"divide": "\xf7",
"divide;": "\xf7",
"divideontimes;": "\u22c7",
"divonx;": "\u22c7",
"djcy;": "\u0452",
"dlcorn;": "\u231e",
"dlcrop;": "\u230d",
"dollar;": "$",
"dopf;": "\U0001d555",
"dot;": "\u02d9",
"doteq;": "\u2250",
"doteqdot;": "\u2251",
"dotminus;": "\u2238",
"dotplus;": "\u2214",
"dotsquare;": "\u22a1",
"doublebarwedge;": "\u2306",
"downarrow;": "\u2193",
"downdownarrows;": "\u21ca",
"downharpoonleft;": "\u21c3",
"downharpoonright;": "\u21c2",
"drbkarow;": "\u2910",
"drcorn;": "\u231f",
"drcrop;": "\u230c",
"dscr;": "\U0001d4b9",
"dscy;": "\u0455",
"dsol;": "\u29f6",
"dstrok;": "\u0111",
"dtdot;": "\u22f1",
"dtri;": "\u25bf",
"dtrif;": "\u25be",
"duarr;": "\u21f5",
"duhar;": "\u296f",
"dwangle;": "\u29a6",
"dzcy;": "\u045f",
"dzigrarr;": "\u27ff",
"eDDot;": "\u2a77",
"eDot;": "\u2251",
"eacute": "\xe9",
"eacute;": "\xe9",
"easter;": "\u2a6e",
"ecaron;": "\u011b",
"ecir;": "\u2256",
"ecirc": "\xea",
"ecirc;": "\xea",
"ecolon;": "\u2255",
"ecy;": "\u044d",
"edot;": "\u0117",
"ee;": "\u2147",
"efDot;": "\u2252",
"efr;": "\U0001d522",
"eg;": "\u2a9a",
"egrave": "\xe8",
"egrave;": "\xe8",
"egs;": "\u2a96",
"egsdot;": "\u2a98",
"el;": "\u2a99",
"elinters;": "\u23e7",
"ell;": "\u2113",
"els;": "\u2a95",
"elsdot;": "\u2a97",
"emacr;": "\u0113",
"empty;": "\u2205",
"emptyset;": "\u2205",
"emptyv;": "\u2205",
"emsp13;": "\u2004",
"emsp14;": "\u2005",
"emsp;": "\u2003",
"eng;": "\u014b",
"ensp;": "\u2002",
"eogon;": "\u0119",
"eopf;": "\U0001d556",
"epar;": "\u22d5",
"eparsl;": "\u29e3",
"eplus;": "\u2a71",
"epsi;": "\u03b5",
"epsilon;": "\u03b5",
"epsiv;": "\u03f5",
"eqcirc;": "\u2256",
"eqcolon;": "\u2255",
"eqsim;": "\u2242",
"eqslantgtr;": "\u2a96",
"eqslantless;": "\u2a95",
"equals;": "=",
"equest;": "\u225f",
"equiv;": "\u2261",
"equivDD;": "\u2a78",
"eqvparsl;": "\u29e5",
"erDot;": "\u2253",
"erarr;": "\u2971",
"escr;": "\u212f",
"esdot;": "\u2250",
"esim;": "\u2242",
"eta;": "\u03b7",
"eth": "\xf0",
"eth;": "\xf0",
"euml": "\xeb",
"euml;": "\xeb",
"euro;": "\u20ac",
"excl;": "!",
"exist;": "\u2203",
"expectation;": "\u2130",
"exponentiale;": "\u2147",
"fallingdotseq;": "\u2252",
"fcy;": "\u0444",
"female;": "\u2640",
"ffilig;": "\ufb03",
"fflig;": "\ufb00",
"ffllig;": "\ufb04",
"ffr;": "\U0001d523",
"filig;": "\ufb01",
"fjlig;": "fj",
"flat;": "\u266d",
"fllig;": "\ufb02",
"fltns;": "\u25b1",
"fnof;": "\u0192",
"fopf;": "\U0001d557",
"forall;": "\u2200",
"fork;": "\u22d4",
"forkv;": "\u2ad9",
"fpartint;": "\u2a0d",
"frac12": "\xbd",
"frac12;": "\xbd",
"frac13;": "\u2153",
"frac14": "\xbc",
"frac14;": "\xbc",
"frac15;": "\u2155",
"frac16;": "\u2159",
"frac18;": "\u215b",
"frac23;": "\u2154",
"frac25;": "\u2156",
"frac34": "\xbe",
"frac34;": "\xbe",
"frac35;": "\u2157",
"frac38;": "\u215c",
"frac45;": "\u2158",
"frac56;": "\u215a",
"frac58;": "\u215d",
"frac78;": "\u215e",
"frasl;": "\u2044",
"frown;": "\u2322",
"fscr;": "\U0001d4bb",
"gE;": "\u2267",
"gEl;": "\u2a8c",
"gacute;": "\u01f5",
"gamma;": "\u03b3",
"gammad;": "\u03dd",
"gap;": "\u2a86",
"gbreve;": "\u011f",
"gcirc;": "\u011d",
"gcy;": "\u0433",
"gdot;": "\u0121",
"ge;": "\u2265",
"gel;": "\u22db",
"geq;": "\u2265",
"geqq;": "\u2267",
"geqslant;": "\u2a7e",
"ges;": "\u2a7e",
"gescc;": "\u2aa9",
"gesdot;": "\u2a80",
"gesdoto;": "\u2a82",
"gesdotol;": "\u2a84",
"gesl;": "\u22db\ufe00",
"gesles;": "\u2a94",
"gfr;": "\U0001d524",
"gg;": "\u226b",
"ggg;": "\u22d9",
"gimel;": "\u2137",
"gjcy;": "\u0453",
"gl;": "\u2277",
"glE;": "\u2a92",
"gla;": "\u2aa5",
"glj;": "\u2aa4",
"gnE;": "\u2269",
"gnap;": "\u2a8a",
"gnapprox;": "\u2a8a",
"gne;": "\u2a88",
"gneq;": "\u2a88",
"gneqq;": "\u2269",
"gnsim;": "\u22e7",
"gopf;": "\U0001d558",
"grave;": "`",
"gscr;": "\u210a",
"gsim;": "\u2273",
"gsime;": "\u2a8e",
"gsiml;": "\u2a90",
"gt": ">",
"gt;": ">",
"gtcc;": "\u2aa7",
"gtcir;": "\u2a7a",
"gtdot;": "\u22d7",
"gtlPar;": "\u2995",
"gtquest;": "\u2a7c",
"gtrapprox;": "\u2a86",
"gtrarr;": "\u2978",
"gtrdot;": "\u22d7",
"gtreqless;": "\u22db",
"gtreqqless;": "\u2a8c",
"gtrless;": "\u2277",
"gtrsim;": "\u2273",
"gvertneqq;": "\u2269\ufe00",
"gvnE;": "\u2269\ufe00",
"hArr;": "\u21d4",
"hairsp;": "\u200a",
"half;": "\xbd",
"hamilt;": "\u210b",
"hardcy;": "\u044a",
"harr;": "\u2194",
"harrcir;": "\u2948",
"harrw;": "\u21ad",
"hbar;": "\u210f",
"hcirc;": "\u0125",
"hearts;": "\u2665",
"heartsuit;": "\u2665",
"hellip;": "\u2026",
"hercon;": "\u22b9",
"hfr;": "\U0001d525",
"hksearow;": "\u2925",
"hkswarow;": "\u2926",
"hoarr;": "\u21ff",
"homtht;": "\u223b",
"hookleftarrow;": "\u21a9",
"hookrightarrow;": "\u21aa",
"hopf;": "\U0001d559",
"horbar;": "\u2015",
"hscr;": "\U0001d4bd",
"hslash;": "\u210f",
"hstrok;": "\u0127",
"hybull;": "\u2043",
"hyphen;": "\u2010",
"iacute": "\xed",
"iacute;": "\xed",
"ic;": "\u2063",
"icirc": "\xee",
"icirc;": "\xee",
"icy;": "\u0438",
"iecy;": "\u0435",
"iexcl": "\xa1",
"iexcl;": "\xa1",
"iff;": "\u21d4",
"ifr;": "\U0001d526",
"igrave": "\xec",
"igrave;": "\xec",
"ii;": "\u2148",
"iiiint;": "\u2a0c",
"iiint;": "\u222d",
"iinfin;": "\u29dc",
"iiota;": "\u2129",
"ijlig;": "\u0133",
"imacr;": "\u012b",
"image;": "\u2111",
"imagline;": "\u2110",
"imagpart;": "\u2111",
"imath;": "\u0131",
"imof;": "\u22b7",
"imped;": "\u01b5",
"in;": "\u2208",
"incare;": "\u2105",
"infin;": "\u221e",
"infintie;": "\u29dd",
"inodot;": "\u0131",
"int;": "\u222b",
"intcal;": "\u22ba",
"integers;": "\u2124",
"intercal;": "\u22ba",
"intlarhk;": "\u2a17",
"intprod;": "\u2a3c",
"iocy;": "\u0451",
"iogon;": "\u012f",
"iopf;": "\U0001d55a",
"iota;": "\u03b9",
"iprod;": "\u2a3c",
"iquest": "\xbf",
"iquest;": "\xbf",
"iscr;": "\U0001d4be",
"isin;": "\u2208",
"isinE;": "\u22f9",
"isindot;": "\u22f5",
"isins;": "\u22f4",
"isinsv;": "\u22f3",
"isinv;": "\u2208",
"it;": "\u2062",
"itilde;": "\u0129",
"iukcy;": "\u0456",
"iuml": "\xef",
"iuml;": "\xef",
"jcirc;": "\u0135",
"jcy;": "\u0439",
"jfr;": "\U0001d527",
"jmath;": "\u0237",
"jopf;": "\U0001d55b",
"jscr;": "\U0001d4bf",
"jsercy;": "\u0458",
"jukcy;": "\u0454",
"kappa;": "\u03ba",
"kappav;": "\u03f0",
"kcedil;": "\u0137",
"kcy;": "\u043a",
"kfr;": "\U0001d528",
"kgreen;": "\u0138",
"khcy;": "\u0445",
"kjcy;": "\u045c",
"kopf;": "\U0001d55c",
"kscr;": "\U0001d4c0",
"lAarr;": "\u21da",
"lArr;": "\u21d0",
"lAtail;": "\u291b",
"lBarr;": "\u290e",
"lE;": "\u2266",
"lEg;": "\u2a8b",
"lHar;": "\u2962",
"lacute;": "\u013a",
"laemptyv;": "\u29b4",
"lagran;": "\u2112",
"lambda;": "\u03bb",
"lang;": "\u27e8",
"langd;": "\u2991",
"langle;": "\u27e8",
"lap;": "\u2a85",
"laquo": "\xab",
"laquo;": "\xab",
"larr;": "\u2190",
"larrb;": "\u21e4",
"larrbfs;": "\u291f",
"larrfs;": "\u291d",
"larrhk;": "\u21a9",
"larrlp;": "\u21ab",
"larrpl;": "\u2939",
"larrsim;": "\u2973",
"larrtl;": "\u21a2",
"lat;": "\u2aab",
"latail;": "\u2919",
"late;": "\u2aad",
"lates;": "\u2aad\ufe00",
"lbarr;": "\u290c",
"lbbrk;": "\u2772",
"lbrace;": "{",
"lbrack;": "[",
"lbrke;": "\u298b",
"lbrksld;": "\u298f",
"lbrkslu;": "\u298d",
"lcaron;": "\u013e",
"lcedil;": "\u013c",
"lceil;": "\u2308",
"lcub;": "{",
"lcy;": "\u043b",
"ldca;": "\u2936",
"ldquo;": "\u201c",
"ldquor;": "\u201e",
"ldrdhar;": "\u2967",
"ldrushar;": "\u294b",
"ldsh;": "\u21b2",
"le;": "\u2264",
"leftarrow;": "\u2190",
"leftarrowtail;": "\u21a2",
"leftharpoondown;": "\u21bd",
"leftharpoonup;": "\u21bc",
"leftleftarrows;": "\u21c7",
"leftrightarrow;": "\u2194",
"leftrightarrows;": "\u21c6",
"leftrightharpoons;": "\u21cb",
"leftrightsquigarrow;": "\u21ad",
"leftthreetimes;": "\u22cb",
"leg;": "\u22da",
"leq;": "\u2264",
"leqq;": "\u2266",
"leqslant;": "\u2a7d",
"les;": "\u2a7d",
"lescc;": "\u2aa8",
"lesdot;": "\u2a7f",
"lesdoto;": "\u2a81",
"lesdotor;": "\u2a83",
"lesg;": "\u22da\ufe00",
"lesges;": "\u2a93",
"lessapprox;": "\u2a85",
"lessdot;": "\u22d6",
"lesseqgtr;": "\u22da",
"lesseqqgtr;": "\u2a8b",
"lessgtr;": "\u2276",
"lesssim;": "\u2272",
"lfisht;": "\u297c",
"lfloor;": "\u230a",
"lfr;": "\U0001d529",
"lg;": "\u2276",
"lgE;": "\u2a91",
"lhard;": "\u21bd",
"lharu;": "\u21bc",
"lharul;": "\u296a",
"lhblk;": "\u2584",
"ljcy;": "\u0459",
"ll;": "\u226a",
"llarr;": "\u21c7",
"llcorner;": "\u231e",
"llhard;": "\u296b",
"lltri;": "\u25fa",
"lmidot;": "\u0140",
"lmoust;": "\u23b0",
"lmoustache;": "\u23b0",
"lnE;": "\u2268",
"lnap;": "\u2a89",
"lnapprox;": "\u2a89",
"lne;": "\u2a87",
"lneq;": "\u2a87",
"lneqq;": "\u2268",
"lnsim;": "\u22e6",
"loang;": "\u27ec",
"loarr;": "\u21fd",
"lobrk;": "\u27e6",
"longleftarrow;": "\u27f5",
"longleftrightarrow;": "\u27f7",
"longmapsto;": "\u27fc",
"longrightarrow;": "\u27f6",
"looparrowleft;": "\u21ab",
"looparrowright;": "\u21ac",
"lopar;": "\u2985",
"lopf;": "\U0001d55d",
"loplus;": "\u2a2d",
"lotimes;": "\u2a34",
"lowast;": "\u2217",
"lowbar;": "_",
"loz;": "\u25ca",
"lozenge;": "\u25ca",
"lozf;": "\u29eb",
"lpar;": "(",
"lparlt;": "\u2993",
"lrarr;": "\u21c6",
"lrcorner;": "\u231f",
"lrhar;": "\u21cb",
"lrhard;": "\u296d",
"lrm;": "\u200e",
"lrtri;": "\u22bf",
"lsaquo;": "\u2039",
"lscr;": "\U0001d4c1",
"lsh;": "\u21b0",
"lsim;": "\u2272",
"lsime;": "\u2a8d",
"lsimg;": "\u2a8f",
"lsqb;": "[",
"lsquo;": "\u2018",
"lsquor;": "\u201a",
"lstrok;": "\u0142",
"lt": "<",
"lt;": "<",
"ltcc;": "\u2aa6",
"ltcir;": "\u2a79",
"ltdot;": "\u22d6",
"lthree;": "\u22cb",
"ltimes;": "\u22c9",
"ltlarr;": "\u2976",
"ltquest;": "\u2a7b",
"ltrPar;": "\u2996",
"ltri;": "\u25c3",
"ltrie;": "\u22b4",
"ltrif;": "\u25c2",
"lurdshar;": "\u294a",
"luruhar;": "\u2966",
"lvertneqq;": "\u2268\ufe00",
"lvnE;": "\u2268\ufe00",
"mDDot;": "\u223a",
"macr": "\xaf",
"macr;": "\xaf",
"male;": "\u2642",
"malt;": "\u2720",
"maltese;": "\u2720",
"map;": "\u21a6",
"mapsto;": "\u21a6",
"mapstodown;": "\u21a7",
"mapstoleft;": "\u21a4",
"mapstoup;": "\u21a5",
"marker;": "\u25ae",
"mcomma;": "\u2a29",
"mcy;": "\u043c",
"mdash;": "\u2014",
"measuredangle;": "\u2221",
"mfr;": "\U0001d52a",
"mho;": "\u2127",
"micro": "\xb5",
"micro;": "\xb5",
"mid;": "\u2223",
"midast;": "*",
"midcir;": "\u2af0",
"middot": "\xb7",
"middot;": "\xb7",
"minus;": "\u2212",
"minusb;": "\u229f",
"minusd;": "\u2238",
"minusdu;": "\u2a2a",
"mlcp;": "\u2adb",
"mldr;": "\u2026",
"mnplus;": "\u2213",
"models;": "\u22a7",
"mopf;": "\U0001d55e",
"mp;": "\u2213",
"mscr;": "\U0001d4c2",
"mstpos;": "\u223e",
"mu;": "\u03bc",
"multimap;": "\u22b8",
"mumap;": "\u22b8",
"nGg;": "\u22d9\u0338",
"nGt;": "\u226b\u20d2",
"nGtv;": "\u226b\u0338",
"nLeftarrow;": "\u21cd",
"nLeftrightarrow;": "\u21ce",
"nLl;": "\u22d8\u0338",
"nLt;": "\u226a\u20d2",
"nLtv;": "\u226a\u0338",
"nRightarrow;": "\u21cf",
"nVDash;": "\u22af",
"nVdash;": "\u22ae",
"nabla;": "\u2207",
"nacute;": "\u0144",
"nang;": "\u2220\u20d2",
"nap;": "\u2249",
"napE;": "\u2a70\u0338",
"napid;": "\u224b\u0338",
"napos;": "\u0149",
"napprox;": "\u2249",
"natur;": "\u266e",
"natural;": "\u266e",
"naturals;": "\u2115",
"nbsp": "\xa0",
"nbsp;": "\xa0",
"nbump;": "\u224e\u0338",
"nbumpe;": "\u224f\u0338",
"ncap;": "\u2a43",
"ncaron;": "\u0148",
"ncedil;": "\u0146",
"ncong;": "\u2247",
"ncongdot;": "\u2a6d\u0338",
"ncup;": "\u2a42",
"ncy;": "\u043d",
"ndash;": "\u2013",
"ne;": "\u2260",
"neArr;": "\u21d7",
"nearhk;": "\u2924",
"nearr;": "\u2197",
"nearrow;": "\u2197",
"nedot;": "\u2250\u0338",
"nequiv;": "\u2262",
"nesear;": "\u2928",
"nesim;": "\u2242\u0338",
"nexist;": "\u2204",
"nexists;": "\u2204",
"nfr;": "\U0001d52b",
"ngE;": "\u2267\u0338",
"nge;": "\u2271",
"ngeq;": "\u2271",
"ngeqq;": "\u2267\u0338",
"ngeqslant;": "\u2a7e\u0338",
"nges;": "\u2a7e\u0338",
"ngsim;": "\u2275",
"ngt;": "\u226f",
"ngtr;": "\u226f",
"nhArr;": "\u21ce",
"nharr;": "\u21ae",
"nhpar;": "\u2af2",
"ni;": "\u220b",
"nis;": "\u22fc",
"nisd;": "\u22fa",
"niv;": "\u220b",
"njcy;": "\u045a",
"nlArr;": "\u21cd",
"nlE;": "\u2266\u0338",
"nlarr;": "\u219a",
"nldr;": "\u2025",
"nle;": "\u2270",
"nleftarrow;": "\u219a",
"nleftrightarrow;": "\u21ae",
"nleq;": "\u2270",
"nleqq;": "\u2266\u0338",
"nleqslant;": "\u2a7d\u0338",
"nles;": "\u2a7d\u0338",
"nless;": "\u226e",
"nlsim;": "\u2274",
"nlt;": "\u226e",
"nltri;": "\u22ea",
"nltrie;": "\u22ec",
"nmid;": "\u2224",
"nopf;": "\U0001d55f",
"not": "\xac",
"not;": "\xac",
"notin;": "\u2209",
"notinE;": "\u22f9\u0338",
"notindot;": "\u22f5\u0338",
"notinva;": "\u2209",
"notinvb;": "\u22f7",
"notinvc;": "\u22f6",
"notni;": "\u220c",
"notniva;": "\u220c",
"notnivb;": "\u22fe",
"notnivc;": "\u22fd",
"npar;": "\u2226",
"nparallel;": "\u2226",
"nparsl;": "\u2afd\u20e5",
"npart;": "\u2202\u0338",
"npolint;": "\u2a14",
"npr;": "\u2280",
"nprcue;": "\u22e0",
"npre;": "\u2aaf\u0338",
"nprec;": "\u2280",
"npreceq;": "\u2aaf\u0338",
"nrArr;": "\u21cf",
"nrarr;": "\u219b",
"nrarrc;": "\u2933\u0338",
"nrarrw;": "\u219d\u0338",
"nrightarrow;": "\u219b",
"nrtri;": "\u22eb",
"nrtrie;": "\u22ed",
"nsc;": "\u2281",
"nsccue;": "\u22e1",
"nsce;": "\u2ab0\u0338",
"nscr;": "\U0001d4c3",
"nshortmid;": "\u2224",
"nshortparallel;": "\u2226",
"nsim;": "\u2241",
"nsime;": "\u2244",
"nsimeq;": "\u2244",
"nsmid;": "\u2224",
"nspar;": "\u2226",
"nsqsube;": "\u22e2",
"nsqsupe;": "\u22e3",
"nsub;": "\u2284",
"nsubE;": "\u2ac5\u0338",
"nsube;": "\u2288",
"nsubset;": "\u2282\u20d2",
"nsubseteq;": "\u2288",
"nsubseteqq;": "\u2ac5\u0338",
"nsucc;": "\u2281",
"nsucceq;": "\u2ab0\u0338",
"nsup;": "\u2285",
"nsupE;": "\u2ac6\u0338",
"nsupe;": "\u2289",
"nsupset;": "\u2283\u20d2",
"nsupseteq;": "\u2289",
"nsupseteqq;": "\u2ac6\u0338",
"ntgl;": "\u2279",
"ntilde": "\xf1",
"ntilde;": "\xf1",
"ntlg;": "\u2278",
"ntriangleleft;": "\u22ea",
"ntrianglelefteq;": "\u22ec",
"ntriangleright;": "\u22eb",
"ntrianglerighteq;": "\u22ed",
"nu;": "\u03bd",
"num;": "#",
"numero;": "\u2116",
"numsp;": "\u2007",
"nvDash;": "\u22ad",
"nvHarr;": "\u2904",
"nvap;": "\u224d\u20d2",
"nvdash;": "\u22ac",
"nvge;": "\u2265\u20d2",
"nvgt;": ">\u20d2",
"nvinfin;": "\u29de",
"nvlArr;": "\u2902",
"nvle;": "\u2264\u20d2",
"nvlt;": "<\u20d2",
"nvltrie;": "\u22b4\u20d2",
"nvrArr;": "\u2903",
"nvrtrie;": "\u22b5\u20d2",
"nvsim;": "\u223c\u20d2",
"nwArr;": "\u21d6",
"nwarhk;": "\u2923",
"nwarr;": "\u2196",
"nwarrow;": "\u2196",
"nwnear;": "\u2927",
"oS;": "\u24c8",
"oacute": "\xf3",
"oacute;": "\xf3",
"oast;": "\u229b",
"ocir;": "\u229a",
"ocirc": "\xf4",
"ocirc;": "\xf4",
"ocy;": "\u043e",
"odash;": "\u229d",
"odblac;": "\u0151",
"odiv;": "\u2a38",
"odot;": "\u2299",
"odsold;": "\u29bc",
"oelig;": "\u0153",
"ofcir;": "\u29bf",
"ofr;": "\U0001d52c",
"ogon;": "\u02db",
"ograve": "\xf2",
"ograve;": "\xf2",
"ogt;": "\u29c1",
"ohbar;": "\u29b5",
"ohm;": "\u03a9",
"oint;": "\u222e",
"olarr;": "\u21ba",
"olcir;": "\u29be",
"olcross;": "\u29bb",
"oline;": "\u203e",
"olt;": "\u29c0",
"omacr;": "\u014d",
"omega;": "\u03c9",
"omicron;": "\u03bf",
"omid;": "\u29b6",
"ominus;": "\u2296",
"oopf;": "\U0001d560",
"opar;": "\u29b7",
"operp;": "\u29b9",
"oplus;": "\u2295",
"or;": "\u2228",
"orarr;": "\u21bb",
"ord;": "\u2a5d",
"order;": "\u2134",
"orderof;": "\u2134",
"ordf": "\xaa",
"ordf;": "\xaa",
"ordm": "\xba",
"ordm;": "\xba",
"origof;": "\u22b6",
"oror;": "\u2a56",
"orslope;": "\u2a57",
"orv;": "\u2a5b",
"oscr;": "\u2134",
"oslash": "\xf8",
"oslash;": "\xf8",
"osol;": "\u2298",
"otilde": "\xf5",
"otilde;": "\xf5",
"otimes;": "\u2297",
"otimesas;": "\u2a36",
"ouml": "\xf6",
"ouml;": "\xf6",
"ovbar;": "\u233d",
"par;": "\u2225",
"para": "\xb6",
"para;": "\xb6",
"parallel;": "\u2225",
"parsim;": "\u2af3",
"parsl;": "\u2afd",
"part;": "\u2202",
"pcy;": "\u043f",
"percnt;": "%",
"period;": ".",
"permil;": "\u2030",
"perp;": "\u22a5",
"pertenk;": "\u2031",
"pfr;": "\U0001d52d",
"phi;": "\u03c6",
"phiv;": "\u03d5",
"phmmat;": "\u2133",
"phone;": "\u260e",
"pi;": "\u03c0",
"pitchfork;": "\u22d4",
"piv;": "\u03d6",
"planck;": "\u210f",
"planckh;": "\u210e",
"plankv;": "\u210f",
"plus;": "+",
"plusacir;": "\u2a23",
"plusb;": "\u229e",
"pluscir;": "\u2a22",
"plusdo;": "\u2214",
"plusdu;": "\u2a25",
"pluse;": "\u2a72",
"plusmn": "\xb1",
"plusmn;": "\xb1",
"plussim;": "\u2a26",
"plustwo;": "\u2a27",
"pm;": "\xb1",
"pointint;": "\u2a15",
"popf;": "\U0001d561",
"pound": "\xa3",
"pound;": "\xa3",
"pr;": "\u227a",
"prE;": "\u2ab3",
"prap;": "\u2ab7",
"prcue;": "\u227c",
"pre;": "\u2aaf",
"prec;": "\u227a",
"precapprox;": "\u2ab7",
"preccurlyeq;": "\u227c",
"preceq;": "\u2aaf",
"precnapprox;": "\u2ab9",
"precneqq;": "\u2ab5",
"precnsim;": "\u22e8",
"precsim;": "\u227e",
"prime;": "\u2032",
"primes;": "\u2119",
"prnE;": "\u2ab5",
"prnap;": "\u2ab9",
"prnsim;": "\u22e8",
"prod;": "\u220f",
"profalar;": "\u232e",
"profline;": "\u2312",
"profsurf;": "\u2313",
"prop;": "\u221d",
"propto;": "\u221d",
"prsim;": "\u227e",
"prurel;": "\u22b0",
"pscr;": "\U0001d4c5",
"psi;": "\u03c8",
"puncsp;": "\u2008",
"qfr;": "\U0001d52e",
"qint;": "\u2a0c",
"qopf;": "\U0001d562",
"qprime;": "\u2057",
"qscr;": "\U0001d4c6",
"quaternions;": "\u210d",
"quatint;": "\u2a16",
"quest;": "?",
"questeq;": "\u225f",
"quot": "\"",
"quot;": "\"",
"rAarr;": "\u21db",
"rArr;": "\u21d2",
"rAtail;": "\u291c",
"rBarr;": "\u290f",
"rHar;": "\u2964",
"race;": "\u223d\u0331",
"racute;": "\u0155",
"radic;": "\u221a",
"raemptyv;": "\u29b3",
"rang;": "\u27e9",
"rangd;": "\u2992",
"range;": "\u29a5",
"rangle;": "\u27e9",
"raquo": "\xbb",
"raquo;": "\xbb",
"rarr;": "\u2192",
"rarrap;": "\u2975",
"rarrb;": "\u21e5",
"rarrbfs;": "\u2920",
"rarrc;": "\u2933",
"rarrfs;": "\u291e",
"rarrhk;": "\u21aa",
"rarrlp;": "\u21ac",
"rarrpl;": "\u2945",
"rarrsim;": "\u2974",
"rarrtl;": "\u21a3",
"rarrw;": "\u219d",
"ratail;": "\u291a",
"ratio;": "\u2236",
"rationals;": "\u211a",
"rbarr;": "\u290d",
"rbbrk;": "\u2773",
"rbrace;": "}",
"rbrack;": "]",
"rbrke;": "\u298c",
"rbrksld;": "\u298e",
"rbrkslu;": "\u2990",
"rcaron;": "\u0159",
"rcedil;": "\u0157",
"rceil;": "\u2309",
"rcub;": "}",
"rcy;": "\u0440",
"rdca;": "\u2937",
"rdldhar;": "\u2969",
"rdquo;": "\u201d",
"rdquor;": "\u201d",
"rdsh;": "\u21b3",
"real;": "\u211c",
"realine;": "\u211b",
"realpart;": "\u211c",
"reals;": "\u211d",
"rect;": "\u25ad",
"reg": "\xae",
"reg;": "\xae",
"rfisht;": "\u297d",
"rfloor;": "\u230b",
"rfr;": "\U0001d52f",
"rhard;": "\u21c1",
"rharu;": "\u21c0",
"rharul;": "\u296c",
"rho;": "\u03c1",
"rhov;": "\u03f1",
"rightarrow;": "\u2192",
"rightarrowtail;": "\u21a3",
"rightharpoondown;": "\u21c1",
"rightharpoonup;": "\u21c0",
"rightleftarrows;": "\u21c4",
"rightleftharpoons;": "\u21cc",
"rightrightarrows;": "\u21c9",
"rightsquigarrow;": "\u219d",
"rightthreetimes;": "\u22cc",
"ring;": "\u02da",
"risingdotseq;": "\u2253",
"rlarr;": "\u21c4",
"rlhar;": "\u21cc",
"rlm;": "\u200f",
"rmoust;": "\u23b1",
"rmoustache;": "\u23b1",
"rnmid;": "\u2aee",
"roang;": "\u27ed",
"roarr;": "\u21fe",
"robrk;": "\u27e7",
"ropar;": "\u2986",
"ropf;": "\U0001d563",
"roplus;": "\u2a2e",
"rotimes;": "\u2a35",
"rpar;": ")",
"rpargt;": "\u2994",
"rppolint;": "\u2a12",
"rrarr;": "\u21c9",
"rsaquo;": "\u203a",
"rscr;": "\U0001d4c7",
"rsh;": "\u21b1",
"rsqb;": "]",
"rsquo;": "\u2019",
"rsquor;": "\u2019",
"rthree;": "\u22cc",
"rtimes;": "\u22ca",
"rtri;": "\u25b9",
"rtrie;": "\u22b5",
"rtrif;": "\u25b8",
"rtriltri;": "\u29ce",
"ruluhar;": "\u2968",
"rx;": "\u211e",
"sacute;": "\u015b",
"sbquo;": "\u201a",
"sc;": "\u227b",
"scE;": "\u2ab4",
"scap;": "\u2ab8",
"scaron;": "\u0161",
"sccue;": "\u227d",
"sce;": "\u2ab0",
"scedil;": "\u015f",
"scirc;": "\u015d",
"scnE;": "\u2ab6",
"scnap;": "\u2aba",
"scnsim;": "\u22e9",
"scpolint;": "\u2a13",
"scsim;": "\u227f",
"scy;": "\u0441",
"sdot;": "\u22c5",
"sdotb;": "\u22a1",
"sdote;": "\u2a66",
"seArr;": "\u21d8",
"searhk;": "\u2925",
"searr;": "\u2198",
"searrow;": "\u2198",
"sect": "\xa7",
"sect;": "\xa7",
"semi;": ";",
"seswar;": "\u2929",
"setminus;": "\u2216",
"setmn;": "\u2216",
"sext;": "\u2736",
"sfr;": "\U0001d530",
"sfrown;": "\u2322",
"sharp;": "\u266f",
"shchcy;": "\u0449",
"shcy;": "\u0448",
"shortmid;": "\u2223",
"shortparallel;": "\u2225",
"shy": "\xad",
"shy;": "\xad",
"sigma;": "\u03c3",
"sigmaf;": "\u03c2",
"sigmav;": "\u03c2",
"sim;": "\u223c",
"simdot;": "\u2a6a",
"sime;": "\u2243",
"simeq;": "\u2243",
"simg;": "\u2a9e",
"simgE;": "\u2aa0",
"siml;": "\u2a9d",
"simlE;": "\u2a9f",
"simne;": "\u2246",
"simplus;": "\u2a24",
"simrarr;": "\u2972",
"slarr;": "\u2190",
"smallsetminus;": "\u2216",
"smashp;": "\u2a33",
"smeparsl;": "\u29e4",
"smid;": "\u2223",
"smile;": "\u2323",
"smt;": "\u2aaa",
"smte;": "\u2aac",
"smtes;": "\u2aac\ufe00",
"softcy;": "\u044c",
"sol;": "/",
"solb;": "\u29c4",
"solbar;": "\u233f",
"sopf;": "\U0001d564",
"spades;": "\u2660",
"spadesuit;": "\u2660",
"spar;": "\u2225",
"sqcap;": "\u2293",
"sqcaps;": "\u2293\ufe00",
"sqcup;": "\u2294",
"sqcups;": "\u2294\ufe00",
"sqsub;": "\u228f",
"sqsube;": "\u2291",
"sqsubset;": "\u228f",
"sqsubseteq;": "\u2291",
"sqsup;": "\u2290",
"sqsupe;": "\u2292",
"sqsupset;": "\u2290",
"sqsupseteq;": "\u2292",
"squ;": "\u25a1",
"square;": "\u25a1",
"squarf;": "\u25aa",
"squf;": "\u25aa",
"srarr;": "\u2192",
"sscr;": "\U0001d4c8",
"ssetmn;": "\u2216",
"ssmile;": "\u2323",
"sstarf;": "\u22c6",
"star;": "\u2606",
"starf;": "\u2605",
"straightepsilon;": "\u03f5",
"straightphi;": "\u03d5",
"strns;": "\xaf",
"sub;": "\u2282",
"subE;": "\u2ac5",
"subdot;": "\u2abd",
"sube;": "\u2286",
"subedot;": "\u2ac3",
"submult;": "\u2ac1",
"subnE;": "\u2acb",
"subne;": "\u228a",
"subplus;": "\u2abf",
"subrarr;": "\u2979",
"subset;": "\u2282",
"subseteq;": "\u2286",
"subseteqq;": "\u2ac5",
"subsetneq;": "\u228a",
"subsetneqq;": "\u2acb",
"subsim;": "\u2ac7",
"subsub;": "\u2ad5",
"subsup;": "\u2ad3",
"succ;": "\u227b",
"succapprox;": "\u2ab8",
"succcurlyeq;": "\u227d",
"succeq;": "\u2ab0",
"succnapprox;": "\u2aba",
"succneqq;": "\u2ab6",
"succnsim;": "\u22e9",
"succsim;": "\u227f",
"sum;": "\u2211",
"sung;": "\u266a",
"sup1": "\xb9",
"sup1;": "\xb9",
"sup2": "\xb2",
"sup2;": "\xb2",
"sup3": "\xb3",
"sup3;": "\xb3",
"sup;": "\u2283",
"supE;": "\u2ac6",
"supdot;": "\u2abe",
"supdsub;": "\u2ad8",
"supe;": "\u2287",
"supedot;": "\u2ac4",
"suphsol;": "\u27c9",
"suphsub;": "\u2ad7",
"suplarr;": "\u297b",
"supmult;": "\u2ac2",
"supnE;": "\u2acc",
"supne;": "\u228b",
"supplus;": "\u2ac0",
"supset;": "\u2283",
"supseteq;": "\u2287",
"supseteqq;": "\u2ac6",
"supsetneq;": "\u228b",
"supsetneqq;": "\u2acc",
"supsim;": "\u2ac8",
"supsub;": "\u2ad4",
"supsup;": "\u2ad6",
"swArr;": "\u21d9",
"swarhk;": "\u2926",
"swarr;": "\u2199",
"swarrow;": "\u2199",
"swnwar;": "\u292a",
"szlig": "\xdf",
"szlig;": "\xdf",
"target;": "\u2316",
"tau;": "\u03c4",
"tbrk;": "\u23b4",
"tcaron;": "\u0165",
"tcedil;": "\u0163",
"tcy;": "\u0442",
"tdot;": "\u20db",
"telrec;": "\u2315",
"tfr;": "\U0001d531",
"there4;": "\u2234",
"therefore;": "\u2234",
"theta;": "\u03b8",
"thetasym;": "\u03d1",
"thetav;": "\u03d1",
"thickapprox;": "\u2248",
"thicksim;": "\u223c",
"thinsp;": "\u2009",
"thkap;": "\u2248",
"thksim;": "\u223c",
"thorn": "\xfe",
"thorn;": "\xfe",
"tilde;": "\u02dc",
"times": "\xd7",
"times;": "\xd7",
"timesb;": "\u22a0",
"timesbar;": "\u2a31",
"timesd;": "\u2a30",
"tint;": "\u222d",
"toea;": "\u2928",
"top;": "\u22a4",
"topbot;": "\u2336",
"topcir;": "\u2af1",
"topf;": "\U0001d565",
"topfork;": "\u2ada",
"tosa;": "\u2929",
"tprime;": "\u2034",
"trade;": "\u2122",
"triangle;": "\u25b5",
"triangledown;": "\u25bf",
"triangleleft;": "\u25c3",
"trianglelefteq;": "\u22b4",
"triangleq;": "\u225c",
"triangleright;": "\u25b9",
"trianglerighteq;": "\u22b5",
"tridot;": "\u25ec",
"trie;": "\u225c",
"triminus;": "\u2a3a",
"triplus;": "\u2a39",
"trisb;": "\u29cd",
"tritime;": "\u2a3b",
"trpezium;": "\u23e2",
"tscr;": "\U0001d4c9",
"tscy;": "\u0446",
"tshcy;": "\u045b",
"tstrok;": "\u0167",
"twixt;": "\u226c",
"twoheadleftarrow;": "\u219e",
"twoheadrightarrow;": "\u21a0",
"uArr;": "\u21d1",
"uHar;": "\u2963",
"uacute": "\xfa",
"uacute;": "\xfa",
"uarr;": "\u2191",
"ubrcy;": "\u045e",
"ubreve;": "\u016d",
"ucirc": "\xfb",
"ucirc;": "\xfb",
"ucy;": "\u0443",
"udarr;": "\u21c5",
"udblac;": "\u0171",
"udhar;": "\u296e",
"ufisht;": "\u297e",
"ufr;": "\U0001d532",
"ugrave": "\xf9",
"ugrave;": "\xf9",
"uharl;": "\u21bf",
"uharr;": "\u21be",
"uhblk;": "\u2580",
"ulcorn;": "\u231c",
"ulcorner;": "\u231c",
"ulcrop;": "\u230f",
"ultri;": "\u25f8",
"umacr;": "\u016b",
"uml": "\xa8",
"uml;": "\xa8",
"uogon;": "\u0173",
"uopf;": "\U0001d566",
"uparrow;": "\u2191",
"updownarrow;": "\u2195",
"upharpoonleft;": "\u21bf",
"upharpoonright;": "\u21be",
"uplus;": "\u228e",
"upsi;": "\u03c5",
"upsih;": "\u03d2",
"upsilon;": "\u03c5",
"upuparrows;": "\u21c8",
"urcorn;": "\u231d",
"urcorner;": "\u231d",
"urcrop;": "\u230e",
"uring;": "\u016f",
"urtri;": "\u25f9",
"uscr;": "\U0001d4ca",
"utdot;": "\u22f0",
"utilde;": "\u0169",
"utri;": "\u25b5",
"utrif;": "\u25b4",
"uuarr;": "\u21c8",
"uuml": "\xfc",
"uuml;": "\xfc",
"uwangle;": "\u29a7",
"vArr;": "\u21d5",
"vBar;": "\u2ae8",
"vBarv;": "\u2ae9",
"vDash;": "\u22a8",
"vangrt;": "\u299c",
"varepsilon;": "\u03f5",
"varkappa;": "\u03f0",
"varnothing;": "\u2205",
"varphi;": "\u03d5",
"varpi;": "\u03d6",
"varpropto;": "\u221d",
"varr;": "\u2195",
"varrho;": "\u03f1",
"varsigma;": "\u03c2",
"varsubsetneq;": "\u228a\ufe00",
"varsubsetneqq;": "\u2acb\ufe00",
"varsupsetneq;": "\u228b\ufe00",
"varsupsetneqq;": "\u2acc\ufe00",
"vartheta;": "\u03d1",
"vartriangleleft;": "\u22b2",
"vartriangleright;": "\u22b3",
"vcy;": "\u0432",
"vdash;": "\u22a2",
"vee;": "\u2228",
"veebar;": "\u22bb",
"veeeq;": "\u225a",
"vellip;": "\u22ee",
"verbar;": "|",
"vert;": "|",
"vfr;": "\U0001d533",
"vltri;": "\u22b2",
"vnsub;": "\u2282\u20d2",
"vnsup;": "\u2283\u20d2",
"vopf;": "\U0001d567",
"vprop;": "\u221d",
"vrtri;": "\u22b3",
"vscr;": "\U0001d4cb",
"vsubnE;": "\u2acb\ufe00",
"vsubne;": "\u228a\ufe00",
"vsupnE;": "\u2acc\ufe00",
"vsupne;": "\u228b\ufe00",
"vzigzag;": "\u299a",
"wcirc;": "\u0175",
"wedbar;": "\u2a5f",
"wedge;": "\u2227",
"wedgeq;": "\u2259",
"weierp;": "\u2118",
"wfr;": "\U0001d534",
"wopf;": "\U0001d568",
"wp;": "\u2118",
"wr;": "\u2240",
"wreath;": "\u2240",
"wscr;": "\U0001d4cc",
"xcap;": "\u22c2",
"xcirc;": "\u25ef",
"xcup;": "\u22c3",
"xdtri;": "\u25bd",
"xfr;": "\U0001d535",
"xhArr;": "\u27fa",
"xharr;": "\u27f7",
"xi;": "\u03be",
"xlArr;": "\u27f8",
"xlarr;": "\u27f5",
"xmap;": "\u27fc",
"xnis;": "\u22fb",
"xodot;": "\u2a00",
"xopf;": "\U0001d569",
"xoplus;": "\u2a01",
"xotime;": "\u2a02",
"xrArr;": "\u27f9",
"xrarr;": "\u27f6",
"xscr;": "\U0001d4cd",
"xsqcup;": "\u2a06",
"xuplus;": "\u2a04",
"xutri;": "\u25b3",
"xvee;": "\u22c1",
"xwedge;": "\u22c0",
"yacute": "\xfd",
"yacute;": "\xfd",
"yacy;": "\u044f",
"ycirc;": "\u0177",
"ycy;": "\u044b",
"yen": "\xa5",
"yen;": "\xa5",
"yfr;": "\U0001d536",
"yicy;": "\u0457",
"yopf;": "\U0001d56a",
"yscr;": "\U0001d4ce",
"yucy;": "\u044e",
"yuml": "\xff",
"yuml;": "\xff",
"zacute;": "\u017a",
"zcaron;": "\u017e",
"zcy;": "\u0437",
"zdot;": "\u017c",
"zeetrf;": "\u2128",
"zeta;": "\u03b6",
"zfr;": "\U0001d537",
"zhcy;": "\u0436",
"zigrarr;": "\u21dd",
"zopf;": "\U0001d56b",
"zscr;": "\U0001d4cf",
"zwj;": "\u200d",
"zwnj;": "\u200c",
}
replacementCharacters = {
0x0: "\uFFFD",
0x0d: "\u000D",
0x80: "\u20AC",
0x81: "\u0081",
0x81: "\u0081",
0x82: "\u201A",
0x83: "\u0192",
0x84: "\u201E",
0x85: "\u2026",
0x86: "\u2020",
0x87: "\u2021",
0x88: "\u02C6",
0x89: "\u2030",
0x8A: "\u0160",
0x8B: "\u2039",
0x8C: "\u0152",
0x8D: "\u008D",
0x8E: "\u017D",
0x8F: "\u008F",
0x90: "\u0090",
0x91: "\u2018",
0x92: "\u2019",
0x93: "\u201C",
0x94: "\u201D",
0x95: "\u2022",
0x96: "\u2013",
0x97: "\u2014",
0x98: "\u02DC",
0x99: "\u2122",
0x9A: "\u0161",
0x9B: "\u203A",
0x9C: "\u0153",
0x9D: "\u009D",
0x9E: "\u017E",
0x9F: "\u0178",
}
encodings = {
'437': 'cp437',
'850': 'cp850',
'852': 'cp852',
'855': 'cp855',
'857': 'cp857',
'860': 'cp860',
'861': 'cp861',
'862': 'cp862',
'863': 'cp863',
'865': 'cp865',
'866': 'cp866',
'869': 'cp869',
'ansix341968': 'ascii',
'ansix341986': 'ascii',
'arabic': 'iso8859-6',
'ascii': 'ascii',
'asmo708': 'iso8859-6',
'big5': 'big5',
'big5hkscs': 'big5hkscs',
'chinese': 'gbk',
'cp037': 'cp037',
'cp1026': 'cp1026',
'cp154': 'ptcp154',
'cp367': 'ascii',
'cp424': 'cp424',
'cp437': 'cp437',
'cp500': 'cp500',
'cp775': 'cp775',
'cp819': 'windows-1252',
'cp850': 'cp850',
'cp852': 'cp852',
'cp855': 'cp855',
'cp857': 'cp857',
'cp860': 'cp860',
'cp861': 'cp861',
'cp862': 'cp862',
'cp863': 'cp863',
'cp864': 'cp864',
'cp865': 'cp865',
'cp866': 'cp866',
'cp869': 'cp869',
'cp936': 'gbk',
'cpgr': 'cp869',
'cpis': 'cp861',
'csascii': 'ascii',
'csbig5': 'big5',
'cseuckr': 'cp949',
'cseucpkdfmtjapanese': 'euc_jp',
'csgb2312': 'gbk',
'cshproman8': 'hp-roman8',
'csibm037': 'cp037',
'csibm1026': 'cp1026',
'csibm424': 'cp424',
'csibm500': 'cp500',
'csibm855': 'cp855',
'csibm857': 'cp857',
'csibm860': 'cp860',
'csibm861': 'cp861',
'csibm863': 'cp863',
'csibm864': 'cp864',
'csibm865': 'cp865',
'csibm866': 'cp866',
'csibm869': 'cp869',
'csiso2022jp': 'iso2022_jp',
'csiso2022jp2': 'iso2022_jp_2',
'csiso2022kr': 'iso2022_kr',
'csiso58gb231280': 'gbk',
'csisolatin1': 'windows-1252',
'csisolatin2': 'iso8859-2',
'csisolatin3': 'iso8859-3',
'csisolatin4': 'iso8859-4',
'csisolatin5': 'windows-1254',
'csisolatin6': 'iso8859-10',
'csisolatinarabic': 'iso8859-6',
'csisolatincyrillic': 'iso8859-5',
'csisolatingreek': 'iso8859-7',
'csisolatinhebrew': 'iso8859-8',
'cskoi8r': 'koi8-r',
'csksc56011987': 'cp949',
'cspc775baltic': 'cp775',
'cspc850multilingual': 'cp850',
'cspc862latinhebrew': 'cp862',
'cspc8codepage437': 'cp437',
'cspcp852': 'cp852',
'csptcp154': 'ptcp154',
'csshiftjis': 'shift_jis',
'csunicode11utf7': 'utf-7',
'cyrillic': 'iso8859-5',
'cyrillicasian': 'ptcp154',
'ebcdiccpbe': 'cp500',
'ebcdiccpca': 'cp037',
'ebcdiccpch': 'cp500',
'ebcdiccphe': 'cp424',
'ebcdiccpnl': 'cp037',
'ebcdiccpus': 'cp037',
'ebcdiccpwt': 'cp037',
'ecma114': 'iso8859-6',
'ecma118': 'iso8859-7',
'elot928': 'iso8859-7',
'eucjp': 'euc_jp',
'euckr': 'cp949',
'extendedunixcodepackedformatforjapanese': 'euc_jp',
'gb18030': 'gb18030',
'gb2312': 'gbk',
'gb231280': 'gbk',
'gbk': 'gbk',
'greek': 'iso8859-7',
'greek8': 'iso8859-7',
'hebrew': 'iso8859-8',
'hproman8': 'hp-roman8',
'hzgb2312': 'hz',
'ibm037': 'cp037',
'ibm1026': 'cp1026',
'ibm367': 'ascii',
'ibm424': 'cp424',
'ibm437': 'cp437',
'ibm500': 'cp500',
'ibm775': 'cp775',
'ibm819': 'windows-1252',
'ibm850': 'cp850',
'ibm852': 'cp852',
'ibm855': 'cp855',
'ibm857': 'cp857',
'ibm860': 'cp860',
'ibm861': 'cp861',
'ibm862': 'cp862',
'ibm863': 'cp863',
'ibm864': 'cp864',
'ibm865': 'cp865',
'ibm866': 'cp866',
'ibm869': 'cp869',
'iso2022jp': 'iso2022_jp',
'iso2022jp2': 'iso2022_jp_2',
'iso2022kr': 'iso2022_kr',
'iso646irv1991': 'ascii',
'iso646us': 'ascii',
'iso88591': 'windows-1252',
'iso885910': 'iso8859-10',
'iso8859101992': 'iso8859-10',
'iso885911987': 'windows-1252',
'iso885913': 'iso8859-13',
'iso885914': 'iso8859-14',
'iso8859141998': 'iso8859-14',
'iso885915': 'iso8859-15',
'iso885916': 'iso8859-16',
'iso8859162001': 'iso8859-16',
'iso88592': 'iso8859-2',
'iso885921987': 'iso8859-2',
'iso88593': 'iso8859-3',
'iso885931988': 'iso8859-3',
'iso88594': 'iso8859-4',
'iso885941988': 'iso8859-4',
'iso88595': 'iso8859-5',
'iso885951988': 'iso8859-5',
'iso88596': 'iso8859-6',
'iso885961987': 'iso8859-6',
'iso88597': 'iso8859-7',
'iso885971987': 'iso8859-7',
'iso88598': 'iso8859-8',
'iso885981988': 'iso8859-8',
'iso88599': 'windows-1254',
'iso885991989': 'windows-1254',
'isoceltic': 'iso8859-14',
'isoir100': 'windows-1252',
'isoir101': 'iso8859-2',
'isoir109': 'iso8859-3',
'isoir110': 'iso8859-4',
'isoir126': 'iso8859-7',
'isoir127': 'iso8859-6',
'isoir138': 'iso8859-8',
'isoir144': 'iso8859-5',
'isoir148': 'windows-1254',
'isoir149': 'cp949',
'isoir157': 'iso8859-10',
'isoir199': 'iso8859-14',
'isoir226': 'iso8859-16',
'isoir58': 'gbk',
'isoir6': 'ascii',
'koi8r': 'koi8-r',
'koi8u': 'koi8-u',
'korean': 'cp949',
'ksc5601': 'cp949',
'ksc56011987': 'cp949',
'ksc56011989': 'cp949',
'l1': 'windows-1252',
'l10': 'iso8859-16',
'l2': 'iso8859-2',
'l3': 'iso8859-3',
'l4': 'iso8859-4',
'l5': 'windows-1254',
'l6': 'iso8859-10',
'l8': 'iso8859-14',
'latin1': 'windows-1252',
'latin10': 'iso8859-16',
'latin2': 'iso8859-2',
'latin3': 'iso8859-3',
'latin4': 'iso8859-4',
'latin5': 'windows-1254',
'latin6': 'iso8859-10',
'latin8': 'iso8859-14',
'latin9': 'iso8859-15',
'ms936': 'gbk',
'mskanji': 'shift_jis',
'pt154': 'ptcp154',
'ptcp154': 'ptcp154',
'r8': 'hp-roman8',
'roman8': 'hp-roman8',
'shiftjis': 'shift_jis',
'tis620': 'cp874',
'unicode11utf7': 'utf-7',
'us': 'ascii',
'usascii': 'ascii',
'utf16': 'utf-16',
'utf16be': 'utf-16-be',
'utf16le': 'utf-16-le',
'utf8': 'utf-8',
'windows1250': 'cp1250',
'windows1251': 'cp1251',
'windows1252': 'cp1252',
'windows1253': 'cp1253',
'windows1254': 'cp1254',
'windows1255': 'cp1255',
'windows1256': 'cp1256',
'windows1257': 'cp1257',
'windows1258': 'cp1258',
'windows936': 'gbk',
'x-x-big5': 'big5'}
tokenTypes = {
"Doctype": 0,
"Characters": 1,
"SpaceCharacters": 2,
"StartTag": 3,
"EndTag": 4,
"EmptyTag": 5,
"Comment": 6,
"ParseError": 7
}
tagTokenTypes = frozenset((tokenTypes["StartTag"], tokenTypes["EndTag"],
tokenTypes["EmptyTag"]))
prefixes = dict([(v, k) for k, v in namespaces.items()])
prefixes["http://www.w3.org/1998/Math/MathML"] = "math"
class DataLossWarning(UserWarning):
pass
class ReparseException(Exception):
pass
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
1059,
199,
646,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
13178,
275,
488,
199,
199,
37,
275,
469,
272,
298,
2307,
13,
10856,
582,
267,
3824,
8849,
4528,
315,
1324,
2547,
12,
8717,
543,
738,
11,
28050,
7651,
272,
298,
3197,
13,
19300,
582,
267,
3824,
3364,
1233,
1403,
315,
2547,
7651,
272,
298,
15448,
590,
13,
2778,
68,
13,
18533,
527,
582,
267,
3824,
5158,
7401,
527,
334,
24793,
22743,
15090,
315,
1947,
7651,
272,
298,
15448,
13,
1556,
13,
12210,
13,
4502,
582,
267,
3824,
18298,
17101,
8057,
4642,
12,
8717,
543,
491,
38,
7651,
272,
298,
23375,
13,
8258,
13,
19364,
13,
4502,
582,
267,
3824,
7302,
1202,
543,
20282,
1329,
334,
8258,
13,
19364,
3659,
680,
1288,
272,
298,
67,
867,
13,
3916,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
21554,
1133,
506,
6702,
370,
4528,
298,
881,
7340,
19300,
738,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
680,
1288,
272,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
8469,
376,
20282,
1233,
1403,
26,
298,
881,
298,
53,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
7651,
272,
298,
6677,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
267,
3824,
14687,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
6677,
13,
4502,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
14687,
4642,
1420,
14,
24734,
1284,
402,
570,
3140,
7651,
272,
298,
2062,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
1420,
1325,
7179,
1911,
7651,
272,
298,
4579,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
267,
3824,
7989,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
4579,
13,
4502,
582,
267,
3824,
7989,
4642,
1420,
14,
24734,
7179,
7651,
272,
298,
2987,
13,
262,
13,
500,
13,
1450,
582,
267,
3824,
3005,
1947,
3509,
10537,
3004,
7651,
272,
283,
277,
13,
11707,
13,
4173,
13,
265,
13,
500,
13,
1450,
356,
267,
3824,
3005,
1947,
3509,
10537,
291,
13,
11707,
3305,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
21770,
3140,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
4790,
13,
1657,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
15539,
3140,
14,
334,
4943,
3181,
1133,
298,
881,
298,
4058,
6661,
15794,
4959,
1288,
272,
298,
2062,
13,
1450,
13,
354,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
6020,
587,
3140,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
11261,
1947,
14,
24734,
21770,
3140,
14,
20489,
6854,
11936,
22936,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
6964,
11261,
1947,
14,
25345,
1284,
402,
570,
7651,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1560,
582,
267,
3824,
6964,
11261,
1947,
14,
25345,
4528,
9487,
576,
9,
83,
7,
1911,
7651,
272,
298,
11670,
13,
262,
13,
1450,
13,
354,
582,
267,
3824,
8708,
1284,
402,
570,
315,
314,
1947,
536,
7651,
272,
298,
2062,
13,
3215,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
2225,
536,
3140,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
354,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
536,
7651,
272,
298,
3197,
13,
10856,
13,
262,
13,
3215,
13,
354,
582,
267,
3824,
3364,
4528,
315,
2225,
536,
1288,
272,
298,
11081,
13,
3215,
582,
267,
3824,
11070,
1915,
9250,
2225,
641,
1947,
7651,
272,
298,
2062,
13,
500,
13,
1618,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
275,
503,
1284,
402,
1947,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
2225,
574,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
2225,
574,
14,
24734,
21770,
3140,
7651,
272,
283,
11332,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
3824,
8708,
275,
315,
31791,
2225,
1288,
272,
283,
8953,
13,
10856,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
3824,
8708,
4528,
315,
31791,
2225,
1288,
272,
298,
3197,
13,
10856,
13,
4399,
13,
3215,
13,
354,
582,
267,
3824,
8708,
4528,
2410,
2225,
536,
7651,
272,
298,
8953,
13,
10856,
13,
4399,
13,
3215,
13,
585,
582,
267,
3824,
8708,
4528,
2410,
2225,
574,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
3157,
13,
3513,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
14749,
3471,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
4780,
13,
3513,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
334,
1959,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
889,
13,
14005,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
7651,
272,
298,
8953,
13,
13178,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
3824,
8708,
1284,
402,
570,
315,
1947,
14,
13796,
690,
1288,
272,
298,
8953,
13,
10856,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
3824,
8708,
4528,
2410,
1182,
315,
1947,
14,
13796,
690,
1288,
272,
298,
2062,
13,
6760,
397,
13,
269,
13,
6356,
582,
267,
3824,
6964,
2850,
7,
503,
283,
16556,
1370,
2832,
1911,
7651,
272,
298,
8953,
13,
66,
621,
13,
4399,
13,
3157,
13,
6760,
13,
262,
13,
3349,
582,
267,
3824,
8708,
8546,
2410,
1553,
315,
3721,
1288,
272,
298,
8953,
13,
2638,
13,
4399,
13,
3157,
13,
6760,
13,
262,
13,
3349,
582,
267,
3824,
8708,
4601,
2410,
1553,
315,
3721,
1288,
272,
298,
15448,
13,
3349,
582,
267,
3824,
18298,
3721,
7651,
272,
298,
11670,
13,
262,
13,
3349,
582,
267,
3824,
8708,
1284,
402,
570,
315,
3721
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
1059,
199,
646,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
13178,
275,
488,
199,
199,
37,
275,
469,
272,
298,
2307,
13,
10856,
582,
267,
3824,
8849,
4528,
315,
1324,
2547,
12,
8717,
543,
738,
11,
28050,
7651,
272,
298,
3197,
13,
19300,
582,
267,
3824,
3364,
1233,
1403,
315,
2547,
7651,
272,
298,
15448,
590,
13,
2778,
68,
13,
18533,
527,
582,
267,
3824,
5158,
7401,
527,
334,
24793,
22743,
15090,
315,
1947,
7651,
272,
298,
15448,
13,
1556,
13,
12210,
13,
4502,
582,
267,
3824,
18298,
17101,
8057,
4642,
12,
8717,
543,
491,
38,
7651,
272,
298,
23375,
13,
8258,
13,
19364,
13,
4502,
582,
267,
3824,
7302,
1202,
543,
20282,
1329,
334,
8258,
13,
19364,
3659,
680,
1288,
272,
298,
67,
867,
13,
3916,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
21554,
1133,
506,
6702,
370,
4528,
298,
881,
7340,
19300,
738,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
680,
1288,
272,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
8469,
376,
20282,
1233,
1403,
26,
298,
881,
298,
53,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
7651,
272,
298,
6677,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
267,
3824,
14687,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
6677,
13,
4502,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
14687,
4642,
1420,
14,
24734,
1284,
402,
570,
3140,
7651,
272,
298,
2062,
13,
6677,
13,
4502,
582,
267,
3824,
14687,
4642,
1420,
1325,
7179,
1911,
7651,
272,
298,
4579,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
267,
3824,
7989,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
4579,
13,
4502,
582,
267,
3824,
7989,
4642,
1420,
14,
24734,
7179,
7651,
272,
298,
2987,
13,
262,
13,
500,
13,
1450,
582,
267,
3824,
3005,
1947,
3509,
10537,
3004,
7651,
272,
283,
277,
13,
11707,
13,
4173,
13,
265,
13,
500,
13,
1450,
356,
267,
3824,
3005,
1947,
3509,
10537,
291,
13,
11707,
3305,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
21770,
3140,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
4790,
13,
1657,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
15539,
3140,
14,
334,
4943,
3181,
1133,
298,
881,
298,
4058,
6661,
15794,
4959,
1288,
272,
298,
2062,
13,
1450,
13,
354,
582,
267,
3824,
6964,
1947,
536,
14,
24734,
6020,
587,
3140,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
11261,
1947,
14,
24734,
21770,
3140,
14,
20489,
6854,
11936,
22936,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
6964,
11261,
1947,
14,
25345,
1284,
402,
570,
7651,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1560,
582,
267,
3824,
6964,
11261,
1947,
14,
25345,
4528,
9487,
576,
9,
83,
7,
1911,
7651,
272,
298,
11670,
13,
262,
13,
1450,
13,
354,
582,
267,
3824,
8708,
1284,
402,
570,
315,
314,
1947,
536,
7651,
272,
298,
2062,
13,
3215,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
2225,
536,
3140,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
354,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
536,
7651,
272,
298,
3197,
13,
10856,
13,
262,
13,
3215,
13,
354,
582,
267,
3824,
3364,
4528,
315,
2225,
536,
1288,
272,
298,
11081,
13,
3215,
582,
267,
3824,
11070,
1915,
9250,
2225,
641,
1947,
7651,
272,
298,
2062,
13,
500,
13,
1618,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
275,
503,
1284,
402,
1947,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
11670,
582,
267,
3824,
8708,
1284,
402,
570,
14,
13796,
2225,
574,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
267,
3824,
6964,
2225,
574,
14,
24734,
21770,
3140,
7651,
272,
283,
11332,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
3824,
8708,
275,
315,
31791,
2225,
1288,
272,
283,
8953,
13,
10856,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
3824,
8708,
4528,
315,
31791,
2225,
1288,
272,
298,
3197,
13,
10856,
13,
4399,
13,
3215,
13,
354,
582,
267,
3824,
8708,
4528,
2410,
2225,
536,
7651,
272,
298,
8953,
13,
10856,
13,
4399,
13,
3215,
13,
585,
582,
267,
3824,
8708,
4528,
2410,
2225,
574,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
3157,
13,
3513,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
14749,
3471,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
4780,
13,
3513,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
334,
1959,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
889,
13,
14005,
582,
267,
3824,
8708,
1284,
402,
570,
315,
2225,
574,
7651,
272,
298,
8953,
13,
13178,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
3824,
8708,
1284,
402,
570,
315,
1947,
14,
13796,
690,
1288,
272,
298,
8953,
13,
10856,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
3824,
8708,
4528,
2410,
1182,
315,
1947,
14,
13796,
690,
1288,
272,
298,
2062,
13,
6760,
397,
13,
269,
13,
6356,
582,
267,
3824,
6964,
2850,
7,
503,
283,
16556,
1370,
2832,
1911,
7651,
272,
298,
8953,
13,
66,
621,
13,
4399,
13,
3157,
13,
6760,
13,
262,
13,
3349,
582,
267,
3824,
8708,
8546,
2410,
1553,
315,
3721,
1288,
272,
298,
8953,
13,
2638,
13,
4399,
13,
3157,
13,
6760,
13,
262,
13,
3349,
582,
267,
3824,
8708,
4601,
2410,
1553,
315,
3721,
1288,
272,
298,
15448,
13,
3349,
582,
267,
3824,
18298,
3721,
7651,
272,
298,
11670,
13,
262,
13,
3349,
582,
267,
3824,
8708,
1284,
402,
570,
315,
3721,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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|
1
|
8926
|
##
# Copyright (c) 2006-2015 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
from uuid import uuid4
"""
Class that encapsulates the server information for a CalDAV test run.
"""
import datetime
import re
import src.xmlDefs
class serverinfo(object):
"""
Maintains information about the server being targeted.
"""
# RegEx pattern to match substitution variables
subspattern = re.compile("(?P<name>\\$[_a-zA-Z][_a-zA-Z0-9\\-]*\\:)")
def __init__(self):
self.host = ""
self.nonsslport = 80
self.sslport = 443
self.host2 = ""
self.nonsslport2 = 80
self.sslport2 = 443
self.authtype = "basic"
self.features = set()
self.user = ""
self.pswd = ""
self.waitcount = 120
self.waitdelay = 0.25
self.waitsuccess = 10
self.subsdict = {}
self.extrasubsdict = {}
# dtnow needs to be fixed to a single date at the start of the tests just in case the tests
# run over a day boundary.
self.dtnow = datetime.date.today()
def _re_subs(self, sub, mapping):
"""
Do a regex substitution via the supplied mapping, only if the mapping exists.
@param sub: string to do substitution in
@type sub: L{str}
@param mapping: mapping of substitution name to value
@type mapping: L{dict}
"""
# Helper function for .sub()
def convert(mo):
named = mo.group('name')
if named is not None and named in mapping:
return mapping[named]
else:
return named
return self.subspattern.sub(convert, sub)
def subs(self, sub, db=None):
# Special handling for relative date-times
pos = sub.find("$now.")
while pos != -1:
endpos = pos + sub[pos:].find(":")
if sub[pos:].startswith("$now.year."):
yearoffset = int(sub[pos + 10:endpos])
value = "%d" % (self.dtnow.year + yearoffset,)
elif sub[pos:].startswith("$now.month."):
monthoffset = int(sub[pos + 11:endpos])
month = self.dtnow.month + monthoffset
year = self.dtnow.year + divmod(month - 1, 12)[0]
month = divmod(month - 1, 12)[1] + 1
value = "%d%02d" % (year, month,)
elif sub[pos:].startswith("$now.week."):
weekoffset = int(sub[pos + 10:endpos])
dtoffset = self.dtnow + datetime.timedelta(days=7 * weekoffset)
value = "%d%02d%02d" % (dtoffset.year, dtoffset.month, dtoffset.day,)
else:
dayoffset = int(sub[pos + 5:endpos])
dtoffset = self.dtnow + datetime.timedelta(days=dayoffset)
value = "%d%02d%02d" % (dtoffset.year, dtoffset.month, dtoffset.day,)
sub = "%s%s%s" % (sub[:pos], value, sub[endpos + 1:])
pos = sub.find("$now.")
if sub.find("$uidrandom:") != -1:
sub = sub.replace("$uidrandom:", str(uuid4()))
if db is None:
db = self.subsdict
while '$' in sub:
newstr = self._re_subs(sub, db)
if newstr == sub:
break
sub = newstr
return sub
def addsubs(self, items, db=None):
if db is None:
db_actual = self.subsdict
else:
db_actual = db
for key, value in items.iteritems():
db_actual[key] = value
if db is None:
self.updateParams()
def hasextrasubs(self):
return len(self.extrasubsdict) > 0
def extrasubs(self, str):
return self.subs(str, self.extrasubsdict)
def addextrasubs(self, items):
processed = {}
# Various "functions" might be applied to a variable name to cause the value to
# be changed in various ways
for variable, value in items.items():
# basename() - extract just the URL last path segment from the value
if variable.startswith("basename("):
variable = variable[len("basename("):-1]
value = value.rstrip("/").split("/")[-1]
processed[variable] = value
self.addsubs(processed, self.extrasubsdict)
def newUIDs(self):
uidsubs = dict([("$uid{u}:".format(u=i), str(uuid4())) for i in range(1, 21)])
self.subsdict.update(uidsubs)
self.extrasubsdict.update(uidsubs)
return set([(v, k) for k, v in uidsubs.items()])
def parseXML(self, node):
for child in node.getchildren():
if child.tag == src.xmlDefs.ELEMENT_HOST:
try:
self.host = child.text.encode("utf-8")
except:
self.host = "localhost"
elif child.tag == src.xmlDefs.ELEMENT_NONSSLPORT:
self.nonsslport = int(child.text)
elif child.tag == src.xmlDefs.ELEMENT_SSLPORT:
self.sslport = int(child.text)
elif child.tag == src.xmlDefs.ELEMENT_HOST2:
try:
self.host2 = child.text.encode("utf-8")
except:
self.host2 = "localhost"
elif child.tag == src.xmlDefs.ELEMENT_NONSSLPORT2:
self.nonsslport2 = int(child.text)
elif child.tag == src.xmlDefs.ELEMENT_SSLPORT2:
self.sslport2 = int(child.text)
elif child.tag == src.xmlDefs.ELEMENT_AUTHTYPE:
self.authtype = child.text.encode("utf-8")
elif child.tag == src.xmlDefs.ELEMENT_WAITCOUNT:
self.waitcount = int(child.text.encode("utf-8"))
elif child.tag == src.xmlDefs.ELEMENT_WAITDELAY:
self.waitdelay = float(child.text.encode("utf-8"))
elif child.tag == src.xmlDefs.ELEMENT_WAITSUCCESS:
self.waitsuccess = int(child.text.encode("utf-8"))
elif child.tag == src.xmlDefs.ELEMENT_FEATURES:
self.parseFeatures(child)
elif child.tag == src.xmlDefs.ELEMENT_SUBSTITUTIONS:
self.parseSubstitutionsXML(child)
self.updateParams()
def parseFeatures(self, node):
for child in node.getchildren():
if child.tag == src.xmlDefs.ELEMENT_FEATURE:
self.features.add(child.text.encode("utf-8"))
def updateParams(self):
# Expand substitutions fully at this point
for k, v in self.subsdict.items():
while '$' in v:
v = self._re_subs(v, self.subsdict)
self.subsdict[k] = v
# Now cache some useful substitutions
user = "$userid1:" if "$userid1:" in self.subsdict else "$userid01:"
pswd = "$pswd1:" if "$pswd1:" in self.subsdict else "$pswd01:"
if user not in self.subsdict:
raise ValueError("Must have userid substitution")
self.user = self.subsdict[user]
if pswd not in self.subsdict:
raise ValueError("Must have pswd substitution")
self.pswd = self.subsdict[pswd]
def parseRepeatXML(self, node):
# Look for count
count = node.get(src.xmlDefs.ATTR_COUNT)
for child in node.getchildren():
self.parseSubstitutionXML(child, count)
def parseSubstitutionsXML(self, node):
for child in node.getchildren():
if child.tag == src.xmlDefs.ELEMENT_SUBSTITUTION:
self.parseSubstitutionXML(child)
elif child.tag == src.xmlDefs.ELEMENT_REPEAT:
self.parseRepeatXML(child)
def parseSubstitutionXML(self, node, repeat=None):
if node.tag == src.xmlDefs.ELEMENT_SUBSTITUTION:
key = None
value = None
for schild in node.getchildren():
if schild.tag == src.xmlDefs.ELEMENT_KEY:
key = schild.text.encode("utf-8")
elif schild.tag == src.xmlDefs.ELEMENT_VALUE:
value = schild.text.encode("utf-8") if schild.text else ""
if key and value:
if repeat:
for count in range(1, int(repeat) + 1):
self.subsdict[key % (count,)] = (value % (count,)) if "%" in value else value
else:
self.subsdict[key] = value
|
apache-2.0
|
[
309,
199,
3,
1898,
334,
67,
9,
8315,
13,
7806,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
309,
199,
504,
5377,
492,
5377,
20,
199,
199,
624,
199,
2543,
626,
22667,
15409,
314,
1654,
2556,
367,
282,
8256,
36,
6087,
511,
1255,
14,
199,
624,
199,
199,
646,
2197,
199,
646,
295,
199,
646,
2928,
14,
1652,
872,
2319,
421,
199,
533,
1654,
815,
8,
785,
304,
272,
408,
272,
16593,
8368,
83,
2556,
3595,
314,
1654,
3769,
307,
20174,
14,
272,
408,
339,
327,
5044,
920,
3851,
370,
1336,
20584,
2860,
272,
1007,
681,
2134,
275,
295,
14,
2014,
480,
2229,
48,
28,
354,
30,
1103,
4,
13040,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
1103,
13,
3672,
1103,
26,
6320,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1102,
275,
3087,
267,
291,
14,
2865,
4266,
719,
275,
5939,
267,
291,
14,
4266,
719,
275,
23865,
267,
291,
14,
1102,
18,
275,
3087,
267,
291,
14,
2865,
4266,
719,
18,
275,
5939,
267,
291,
14,
4266,
719,
18,
275,
23865,
267,
291,
14,
1178,
466,
275,
298,
4316,
2,
267,
291,
14,
3179,
275,
663,
342,
267,
291,
14,
751,
275,
3087,
267,
291,
14,
1190,
2989,
275,
3087,
267,
291,
14,
2573,
835,
275,
13960,
267,
291,
14,
2573,
5814,
275,
378,
14,
821,
267,
291,
14,
758,
1405,
1992,
275,
1616,
267,
291,
14,
9841,
807,
275,
1052,
267,
291,
14,
9975,
30327,
807,
275,
1052,
398,
327,
4487,
2131,
4839,
370,
506,
6317,
370,
282,
2849,
1434,
737,
314,
1343,
402,
314,
2295,
2951,
315,
1930,
314,
2295,
267,
327,
1255,
1806,
282,
5382,
8424,
14,
267,
291,
14,
3583,
2131,
275,
2197,
14,
602,
14,
8136,
342,
2378,
347,
485,
264,
63,
9841,
8,
277,
12,
1007,
12,
4412,
304,
267,
408,
267,
4226,
282,
5163,
20584,
4799,
314,
6841,
4412,
12,
1454,
340,
314,
4412,
3495,
14,
398,
768,
635,
1007,
26,
1059,
370,
886,
20584,
315,
267,
768,
466,
1007,
26,
491,
91,
495,
93,
267,
768,
635,
4412,
26,
4412,
402,
20584,
536,
370,
574,
267,
768,
466,
4412,
26,
491,
91,
807,
93,
267,
408,
267,
327,
11642,
805,
367,
1275,
954,
342,
267,
347,
3957,
8,
573,
304,
288,
4310,
275,
1303,
14,
923,
360,
354,
358,
288,
340,
4310,
365,
440,
488,
436,
4310,
315,
4412,
26,
355,
372,
4412,
59,
4579,
61,
288,
587,
26,
355,
372,
4310,
267,
372,
291,
14,
954,
681,
2134,
14,
954,
8,
3916,
12,
1007,
9,
2378,
347,
13868,
8,
277,
12,
1007,
12,
1592,
29,
403,
304,
398,
327,
12568,
7252,
367,
3847,
1434,
13,
4508,
267,
2086,
275,
1007,
14,
1623,
21506,
2131,
2685,
267,
1830,
2086,
1137,
446,
17,
26,
288,
26690,
275,
2086,
435,
1007,
59,
1712,
11455,
1623,
20063,
288,
340,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
3403,
30946,
355,
5361,
2743,
275,
1109,
8,
954,
59,
1712,
435,
1616,
26,
500,
1712,
566,
355,
574,
275,
2071,
68,
2,
450,
334,
277,
14,
3583,
2131,
14,
3403,
435,
5361,
2743,
4258,
288,
916,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
4482,
30946,
355,
5794,
2743,
275,
1109,
8,
954,
59,
1712,
435,
4119,
26,
500,
1712,
566,
355,
5794,
275,
291,
14,
3583,
2131,
14,
4482,
435,
5794,
2743,
355,
5361,
275,
291,
14,
3583,
2131,
14,
3403,
435,
16438,
8,
4482,
446,
413,
12,
3144,
2788,
16,
61,
355,
5794,
275,
16438,
8,
4482,
446,
413,
12,
3144,
2788,
17,
61,
435,
413,
355,
574,
275,
2071,
68,
5,
996,
68,
2,
450,
334,
3403,
12,
5794,
4258,
288,
916,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
6419,
30946,
355,
8620,
2743,
275,
1109,
8,
954,
59,
1712,
435,
1616,
26,
500,
1712,
566,
355,
366,
475,
12449,
275,
291,
14,
3583,
2131,
435,
2197,
14,
7473,
8,
4899,
29,
23,
627,
8620,
2743,
9,
355,
574,
275,
2071,
68,
5,
996,
68,
5,
996,
68,
2,
450,
334,
68,
475,
12449,
14,
3403,
12,
366,
475,
12449,
14,
4482,
12,
366,
475,
12449,
14,
2977,
4258,
288,
587,
26,
355,
5382,
2743,
275,
1109,
8,
954,
59,
1712,
435,
959,
26,
500,
1712,
566,
355,
366,
475,
12449,
275,
291,
14,
3583,
2131,
435,
2197,
14,
7473,
8,
4899,
29,
2977,
2743,
9,
355,
574,
275,
2071,
68,
5,
996,
68,
5,
996,
68,
2,
450,
334,
68,
475,
12449,
14,
3403,
12,
366,
475,
12449,
14,
4482,
12,
366,
475,
12449,
14,
2977,
4258,
288,
1007,
275,
2071,
83,
5,
83,
5,
83,
2,
450,
334,
954,
1491,
1712,
467,
574,
12,
1007,
59,
500,
1712,
435,
413,
5728,
288,
2086,
275,
1007,
14,
1623,
21506,
2131,
2685,
398,
340,
1007,
14,
1623,
21506,
1535,
2355,
9107,
1137,
446,
17,
26,
288,
1007,
275,
1007,
14,
1814,
21506,
1535,
2355,
6783,
620,
8,
2580,
20,
4059,
398,
340,
1592,
365,
488,
26,
288,
1592,
275,
291,
14,
9841,
807,
267,
1830,
25271,
315,
1007,
26,
288,
892,
495,
275,
291,
423,
264,
63,
9841,
8,
954,
12,
1592,
9,
288,
340,
892,
495,
508,
1007,
26,
355,
2059,
288,
1007,
275,
892,
495,
267,
372,
1007,
2378,
347,
1050,
9841,
8,
277,
12,
2974,
12,
1592,
29,
403,
304,
267,
340,
1592,
365,
488,
26,
288,
1592,
63,
6514,
275,
291
] |
[
199,
3,
1898,
334,
67,
9,
8315,
13,
7806,
21257,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
309,
199,
504,
5377,
492,
5377,
20,
199,
199,
624,
199,
2543,
626,
22667,
15409,
314,
1654,
2556,
367,
282,
8256,
36,
6087,
511,
1255,
14,
199,
624,
199,
199,
646,
2197,
199,
646,
295,
199,
646,
2928,
14,
1652,
872,
2319,
421,
199,
533,
1654,
815,
8,
785,
304,
272,
408,
272,
16593,
8368,
83,
2556,
3595,
314,
1654,
3769,
307,
20174,
14,
272,
408,
339,
327,
5044,
920,
3851,
370,
1336,
20584,
2860,
272,
1007,
681,
2134,
275,
295,
14,
2014,
480,
2229,
48,
28,
354,
30,
1103,
4,
13040,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
1103,
13,
3672,
1103,
26,
6320,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1102,
275,
3087,
267,
291,
14,
2865,
4266,
719,
275,
5939,
267,
291,
14,
4266,
719,
275,
23865,
267,
291,
14,
1102,
18,
275,
3087,
267,
291,
14,
2865,
4266,
719,
18,
275,
5939,
267,
291,
14,
4266,
719,
18,
275,
23865,
267,
291,
14,
1178,
466,
275,
298,
4316,
2,
267,
291,
14,
3179,
275,
663,
342,
267,
291,
14,
751,
275,
3087,
267,
291,
14,
1190,
2989,
275,
3087,
267,
291,
14,
2573,
835,
275,
13960,
267,
291,
14,
2573,
5814,
275,
378,
14,
821,
267,
291,
14,
758,
1405,
1992,
275,
1616,
267,
291,
14,
9841,
807,
275,
1052,
267,
291,
14,
9975,
30327,
807,
275,
1052,
398,
327,
4487,
2131,
4839,
370,
506,
6317,
370,
282,
2849,
1434,
737,
314,
1343,
402,
314,
2295,
2951,
315,
1930,
314,
2295,
267,
327,
1255,
1806,
282,
5382,
8424,
14,
267,
291,
14,
3583,
2131,
275,
2197,
14,
602,
14,
8136,
342,
2378,
347,
485,
264,
63,
9841,
8,
277,
12,
1007,
12,
4412,
304,
267,
408,
267,
4226,
282,
5163,
20584,
4799,
314,
6841,
4412,
12,
1454,
340,
314,
4412,
3495,
14,
398,
768,
635,
1007,
26,
1059,
370,
886,
20584,
315,
267,
768,
466,
1007,
26,
491,
91,
495,
93,
267,
768,
635,
4412,
26,
4412,
402,
20584,
536,
370,
574,
267,
768,
466,
4412,
26,
491,
91,
807,
93,
267,
408,
267,
327,
11642,
805,
367,
1275,
954,
342,
267,
347,
3957,
8,
573,
304,
288,
4310,
275,
1303,
14,
923,
360,
354,
358,
288,
340,
4310,
365,
440,
488,
436,
4310,
315,
4412,
26,
355,
372,
4412,
59,
4579,
61,
288,
587,
26,
355,
372,
4310,
267,
372,
291,
14,
954,
681,
2134,
14,
954,
8,
3916,
12,
1007,
9,
2378,
347,
13868,
8,
277,
12,
1007,
12,
1592,
29,
403,
304,
398,
327,
12568,
7252,
367,
3847,
1434,
13,
4508,
267,
2086,
275,
1007,
14,
1623,
21506,
2131,
2685,
267,
1830,
2086,
1137,
446,
17,
26,
288,
26690,
275,
2086,
435,
1007,
59,
1712,
11455,
1623,
20063,
288,
340,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
3403,
30946,
355,
5361,
2743,
275,
1109,
8,
954,
59,
1712,
435,
1616,
26,
500,
1712,
566,
355,
574,
275,
2071,
68,
2,
450,
334,
277,
14,
3583,
2131,
14,
3403,
435,
5361,
2743,
4258,
288,
916,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
4482,
30946,
355,
5794,
2743,
275,
1109,
8,
954,
59,
1712,
435,
4119,
26,
500,
1712,
566,
355,
5794,
275,
291,
14,
3583,
2131,
14,
4482,
435,
5794,
2743,
355,
5361,
275,
291,
14,
3583,
2131,
14,
3403,
435,
16438,
8,
4482,
446,
413,
12,
3144,
2788,
16,
61,
355,
5794,
275,
16438,
8,
4482,
446,
413,
12,
3144,
2788,
17,
61,
435,
413,
355,
574,
275,
2071,
68,
5,
996,
68,
2,
450,
334,
3403,
12,
5794,
4258,
288,
916,
1007,
59,
1712,
11455,
2460,
21506,
2131,
14,
6419,
30946,
355,
8620,
2743,
275,
1109,
8,
954,
59,
1712,
435,
1616,
26,
500,
1712,
566,
355,
366,
475,
12449,
275,
291,
14,
3583,
2131,
435,
2197,
14,
7473,
8,
4899,
29,
23,
627,
8620,
2743,
9,
355,
574,
275,
2071,
68,
5,
996,
68,
5,
996,
68,
2,
450,
334,
68,
475,
12449,
14,
3403,
12,
366,
475,
12449,
14,
4482,
12,
366,
475,
12449,
14,
2977,
4258,
288,
587,
26,
355,
5382,
2743,
275,
1109,
8,
954,
59,
1712,
435,
959,
26,
500,
1712,
566,
355,
366,
475,
12449,
275,
291,
14,
3583,
2131,
435,
2197,
14,
7473,
8,
4899,
29,
2977,
2743,
9,
355,
574,
275,
2071,
68,
5,
996,
68,
5,
996,
68,
2,
450,
334,
68,
475,
12449,
14,
3403,
12,
366,
475,
12449,
14,
4482,
12,
366,
475,
12449,
14,
2977,
4258,
288,
1007,
275,
2071,
83,
5,
83,
5,
83,
2,
450,
334,
954,
1491,
1712,
467,
574,
12,
1007,
59,
500,
1712,
435,
413,
5728,
288,
2086,
275,
1007,
14,
1623,
21506,
2131,
2685,
398,
340,
1007,
14,
1623,
21506,
1535,
2355,
9107,
1137,
446,
17,
26,
288,
1007,
275,
1007,
14,
1814,
21506,
1535,
2355,
6783,
620,
8,
2580,
20,
4059,
398,
340,
1592,
365,
488,
26,
288,
1592,
275,
291,
14,
9841,
807,
267,
1830,
25271,
315,
1007,
26,
288,
892,
495,
275,
291,
423,
264,
63,
9841,
8,
954,
12,
1592,
9,
288,
340,
892,
495,
508,
1007,
26,
355,
2059,
288,
1007,
275,
892,
495,
267,
372,
1007,
2378,
347,
1050,
9841,
8,
277,
12,
2974,
12,
1592,
29,
403,
304,
267,
340,
1592,
365,
488,
26,
288,
1592,
63,
6514,
275,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
|
3728
|
"""A simple but flexible modal dialog box."""
from Tkinter import *
class SimpleDialog:
def __init__(self, master,
text='', buttons=[], default=None, cancel=None,
title=None, class_=None):
if class_:
self.root = Toplevel(master, class_=class_)
else:
self.root = Toplevel(master)
if title:
self.root.title(title)
self.root.iconname(title)
self.message = Message(self.root, text=text, aspect=400)
self.message.pack(expand=1, fill=BOTH)
self.frame = Frame(self.root)
self.frame.pack()
self.num = default
self.cancel = cancel
self.default = default
self.root.bind('<Return>', self.return_event)
for num in range(len(buttons)):
s = buttons[num]
b = Button(self.frame, text=s,
command=(lambda self=self, num=num: self.done(num)))
if num == default:
b.config(relief=RIDGE, borderwidth=8)
b.pack(side=LEFT, fill=BOTH, expand=1)
self.root.protocol('WM_DELETE_WINDOW', self.wm_delete_window)
self._set_transient(master)
def _set_transient(self, master, relx=0.5, rely=0.3):
widget = self.root
widget.withdraw() # Remain invisible while we figure out the geometry
widget.transient(master)
widget.update_idletasks() # Actualize geometry information
if master.winfo_ismapped():
m_width = master.winfo_width()
m_height = master.winfo_height()
m_x = master.winfo_rootx()
m_y = master.winfo_rooty()
else:
m_width = master.winfo_screenwidth()
m_height = master.winfo_screenheight()
m_x = m_y = 0
w_width = widget.winfo_reqwidth()
w_height = widget.winfo_reqheight()
x = m_x + (m_width - w_width) * relx
y = m_y + (m_height - w_height) * rely
if x+w_width > master.winfo_screenwidth():
x = master.winfo_screenwidth() - w_width
elif x < 0:
x = 0
if y+w_height > master.winfo_screenheight():
y = master.winfo_screenheight() - w_height
elif y < 0:
y = 0
widget.geometry("+%d+%d" % (x, y))
widget.deiconify() # Become visible at the desired location
def go(self):
self.root.wait_visibility()
self.root.grab_set()
self.root.mainloop()
self.root.destroy()
return self.num
def return_event(self, event):
if self.default is None:
self.root.bell()
else:
self.done(self.default)
def wm_delete_window(self):
if self.cancel is None:
self.root.bell()
else:
self.done(self.cancel)
def done(self, num):
self.num = num
self.root.quit()
if __name__ == '__main__':
def test():
root = Tk()
def doit(root=root):
d = SimpleDialog(root,
text="This is a test dialog. "
"Would this have been an actual dialog, "
"the buttons below would have been glowing "
"in soft pink light.\n"
"Do you believe this?",
buttons=["Yes", "No", "Cancel"],
default=0,
cancel=2,
title="Test Dialog")
print d.go()
t = Button(root, text='Test', command=doit)
t.pack()
q = Button(root, text='Quit', command=t.quit)
q.pack()
t.mainloop()
test()
|
gpl-3.0
|
[
624,
33,
3486,
1325,
26841,
21698,
9592,
5689,
1041,
421,
199,
504,
16826,
492,
627,
421,
199,
533,
5870,
5619,
26,
339,
347,
636,
826,
721,
277,
12,
5288,
12,
326,
1318,
4581,
15766,
6034,
849,
29,
403,
12,
9311,
29,
403,
12,
326,
2538,
29,
403,
12,
1021,
10683,
403,
304,
267,
340,
1021,
10388,
288,
291,
14,
1231,
275,
14132,
1896,
8,
4133,
12,
1021,
10683,
533,
4602,
267,
587,
26,
288,
291,
14,
1231,
275,
14132,
1896,
8,
4133,
9,
267,
340,
2538,
26,
288,
291,
14,
1231,
14,
1213,
8,
1213,
9,
288,
291,
14,
1231,
14,
4677,
354,
8,
1213,
9,
267,
291,
14,
1188,
275,
6430,
8,
277,
14,
1231,
12,
1318,
29,
505,
12,
17435,
29,
5303,
9,
267,
291,
14,
1188,
14,
1389,
8,
4441,
29,
17,
12,
5554,
29,
28784,
9,
267,
291,
14,
1943,
275,
11726,
8,
277,
14,
1231,
9,
267,
291,
14,
1943,
14,
1389,
342,
267,
291,
14,
1507,
275,
849,
267,
291,
14,
6406,
275,
9311,
267,
291,
14,
885,
275,
849,
267,
291,
14,
1231,
14,
3409,
4827,
1767,
4206,
291,
14,
1107,
63,
1430,
9,
267,
367,
1967,
315,
1425,
8,
552,
8,
15687,
2298,
288,
308,
275,
15766,
59,
1507,
61,
288,
330,
275,
16005,
8,
277,
14,
1943,
12,
1318,
29,
83,
12,
2432,
1414,
2687,
2734,
291,
29,
277,
12,
1967,
29,
1507,
26,
291,
14,
4456,
8,
1507,
1724,
288,
340,
1967,
508,
849,
26,
355,
330,
14,
888,
8,
26557,
2829,
29,
50,
998,
4962,
12,
9162,
2063,
29,
24,
9,
288,
330,
14,
1389,
8,
2441,
29,
9894,
12,
5554,
29,
28784,
12,
6544,
29,
17,
9,
267,
291,
14,
1231,
14,
3922,
360,
13073,
63,
7014,
63,
15480,
297,
291,
14,
16240,
63,
1807,
63,
3806,
9,
267,
291,
423,
409,
63,
23387,
8,
4133,
9,
339,
347,
485,
409,
63,
23387,
8,
277,
12,
5288,
12,
4668,
88,
29,
16,
14,
21,
12,
19687,
29,
16,
14,
19,
304,
267,
3938,
275,
291,
14,
1231,
267,
3938,
14,
1045,
5485,
342,
327,
799,
973,
315,
6604,
1830,
781,
9658,
734,
314,
3400,
267,
3938,
14,
23387,
8,
4133,
9,
267,
3938,
14,
873,
63,
12000,
5054,
342,
327,
18982,
1061,
794,
3400,
2556,
267,
340,
5288,
14,
23562,
63,
374,
11663,
837,
288,
333,
63,
2063,
275,
5288,
14,
23562,
63,
2063,
342,
288,
333,
63,
3333,
275,
5288,
14,
23562,
63,
3333,
342,
288,
333,
63,
88,
275,
5288,
14,
23562,
63,
1231,
88,
342,
288,
333,
63,
89,
275,
5288,
14,
23562,
63,
1231,
89,
342,
267,
587,
26,
288,
333,
63,
2063,
275,
5288,
14,
23562,
63,
5410,
2063,
342,
288,
333,
63,
3333,
275,
5288,
14,
23562,
63,
5410,
3333,
342,
288,
333,
63,
88,
275,
333,
63,
89,
275,
378,
267,
336,
63,
2063,
275,
3938,
14,
23562,
63,
2103,
2063,
342,
267,
336,
63,
3333,
275,
3938,
14,
23562,
63,
2103,
3333,
342,
267,
671,
275,
333,
63,
88,
435,
334,
77,
63,
2063,
446,
336,
63,
2063,
9,
627,
4668,
88,
267,
612,
275,
333,
63,
89,
435,
334,
77,
63,
3333,
446,
336,
63,
3333,
9,
627,
19687,
267,
340,
671,
11,
87,
63,
2063,
690,
5288,
14,
23562,
63,
5410,
2063,
837,
288,
671,
275,
5288,
14,
23562,
63,
5410,
2063,
342,
446,
336,
63,
2063,
267,
916,
671,
665,
378,
26,
288,
671,
275,
378,
267,
340,
612,
11,
87,
63,
3333,
690,
5288,
14,
23562,
63,
5410,
3333,
837,
288,
612,
275,
5288,
14,
23562,
63,
5410,
3333,
342,
446,
336,
63,
3333,
267,
916,
612,
665,
378,
26,
288,
612,
275,
378,
267,
3938,
14,
7660,
480,
25389,
68,
25389,
68,
2,
450,
334,
88,
12,
612,
430,
267,
3938,
14,
271,
4677,
2021,
342,
327,
6423,
4352,
8917,
737,
314,
6387,
2909,
339,
347,
2621,
8,
277,
304,
267,
291,
14,
1231,
14,
2573,
63,
11269,
342,
267,
291,
14,
1231,
14,
22090,
63,
409,
342,
267,
291,
14,
1231,
14,
22644,
342,
267,
291,
14,
1231,
14,
7237,
342,
267,
372,
291,
14,
1507,
339,
347,
372,
63,
1430,
8,
277,
12,
1566,
304,
267,
340,
291,
14,
885,
365,
488,
26,
288,
291,
14,
1231,
14,
30930,
342,
267,
587,
26,
288,
291,
14,
4456,
8,
277,
14,
885,
9,
339,
347,
29835,
63,
1807,
63,
3806,
8,
277,
304,
267,
340,
291,
14,
6406,
365,
488,
26,
288,
291,
14,
1231,
14,
30930,
342,
267,
587,
26,
288,
291,
14,
4456,
8,
277,
14,
6406,
9,
339,
347,
4224,
8,
277,
12,
1967,
304,
267,
291,
14,
1507,
275,
1967,
267,
291,
14,
1231,
14,
10589,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
347,
511,
837,
267,
1738,
275,
12435,
342,
267,
347,
886,
390,
8,
1231,
29,
1231,
304,
288,
366,
275,
5870,
5619,
8,
1231,
12,
586,
1318,
628,
2765,
365,
282,
511,
9592,
14,
221,
298,
2892,
298,
55,
3857,
642,
1172,
2757,
376,
3503,
9592,
12,
298,
2892,
298,
1589,
15766,
5084,
3955,
1172,
2757,
486,
674,
316,
298,
2892,
298,
262,
11620,
299,
2292,
10540,
3134,
78,
2,
2892,
298,
2585,
1265,
506,
317,
4754,
642,
15583,
586,
15766,
6270,
12555,
401,
298,
1944,
401,
298,
9083,
2255,
586,
849,
29,
16,
12,
586,
9311,
29,
18,
12,
586,
2538,
628,
774,
30631,
531,
288,
870,
366,
14,
1939,
342,
267,
307,
275,
16005,
8,
1231,
12,
1318,
534,
774,
297,
1414,
29,
19014,
9,
267,
307,
14,
1389,
342,
267,
1894,
275,
16005,
8,
1231,
12,
1318,
534,
24145,
297,
1414,
29,
84,
14,
10589,
9,
267,
1894,
14,
1389,
342,
267,
307,
14,
22644,
342,
339,
511,
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
] |
[
33,
3486,
1325,
26841,
21698,
9592,
5689,
1041,
421,
199,
504,
16826,
492,
627,
421,
199,
533,
5870,
5619,
26,
339,
347,
636,
826,
721,
277,
12,
5288,
12,
326,
1318,
4581,
15766,
6034,
849,
29,
403,
12,
9311,
29,
403,
12,
326,
2538,
29,
403,
12,
1021,
10683,
403,
304,
267,
340,
1021,
10388,
288,
291,
14,
1231,
275,
14132,
1896,
8,
4133,
12,
1021,
10683,
533,
4602,
267,
587,
26,
288,
291,
14,
1231,
275,
14132,
1896,
8,
4133,
9,
267,
340,
2538,
26,
288,
291,
14,
1231,
14,
1213,
8,
1213,
9,
288,
291,
14,
1231,
14,
4677,
354,
8,
1213,
9,
267,
291,
14,
1188,
275,
6430,
8,
277,
14,
1231,
12,
1318,
29,
505,
12,
17435,
29,
5303,
9,
267,
291,
14,
1188,
14,
1389,
8,
4441,
29,
17,
12,
5554,
29,
28784,
9,
267,
291,
14,
1943,
275,
11726,
8,
277,
14,
1231,
9,
267,
291,
14,
1943,
14,
1389,
342,
267,
291,
14,
1507,
275,
849,
267,
291,
14,
6406,
275,
9311,
267,
291,
14,
885,
275,
849,
267,
291,
14,
1231,
14,
3409,
4827,
1767,
4206,
291,
14,
1107,
63,
1430,
9,
267,
367,
1967,
315,
1425,
8,
552,
8,
15687,
2298,
288,
308,
275,
15766,
59,
1507,
61,
288,
330,
275,
16005,
8,
277,
14,
1943,
12,
1318,
29,
83,
12,
2432,
1414,
2687,
2734,
291,
29,
277,
12,
1967,
29,
1507,
26,
291,
14,
4456,
8,
1507,
1724,
288,
340,
1967,
508,
849,
26,
355,
330,
14,
888,
8,
26557,
2829,
29,
50,
998,
4962,
12,
9162,
2063,
29,
24,
9,
288,
330,
14,
1389,
8,
2441,
29,
9894,
12,
5554,
29,
28784,
12,
6544,
29,
17,
9,
267,
291,
14,
1231,
14,
3922,
360,
13073,
63,
7014,
63,
15480,
297,
291,
14,
16240,
63,
1807,
63,
3806,
9,
267,
291,
423,
409,
63,
23387,
8,
4133,
9,
339,
347,
485,
409,
63,
23387,
8,
277,
12,
5288,
12,
4668,
88,
29,
16,
14,
21,
12,
19687,
29,
16,
14,
19,
304,
267,
3938,
275,
291,
14,
1231,
267,
3938,
14,
1045,
5485,
342,
327,
799,
973,
315,
6604,
1830,
781,
9658,
734,
314,
3400,
267,
3938,
14,
23387,
8,
4133,
9,
267,
3938,
14,
873,
63,
12000,
5054,
342,
327,
18982,
1061,
794,
3400,
2556,
267,
340,
5288,
14,
23562,
63,
374,
11663,
837,
288,
333,
63,
2063,
275,
5288,
14,
23562,
63,
2063,
342,
288,
333,
63,
3333,
275,
5288,
14,
23562,
63,
3333,
342,
288,
333,
63,
88,
275,
5288,
14,
23562,
63,
1231,
88,
342,
288,
333,
63,
89,
275,
5288,
14,
23562,
63,
1231,
89,
342,
267,
587,
26,
288,
333,
63,
2063,
275,
5288,
14,
23562,
63,
5410,
2063,
342,
288,
333,
63,
3333,
275,
5288,
14,
23562,
63,
5410,
3333,
342,
288,
333,
63,
88,
275,
333,
63,
89,
275,
378,
267,
336,
63,
2063,
275,
3938,
14,
23562,
63,
2103,
2063,
342,
267,
336,
63,
3333,
275,
3938,
14,
23562,
63,
2103,
3333,
342,
267,
671,
275,
333,
63,
88,
435,
334,
77,
63,
2063,
446,
336,
63,
2063,
9,
627,
4668,
88,
267,
612,
275,
333,
63,
89,
435,
334,
77,
63,
3333,
446,
336,
63,
3333,
9,
627,
19687,
267,
340,
671,
11,
87,
63,
2063,
690,
5288,
14,
23562,
63,
5410,
2063,
837,
288,
671,
275,
5288,
14,
23562,
63,
5410,
2063,
342,
446,
336,
63,
2063,
267,
916,
671,
665,
378,
26,
288,
671,
275,
378,
267,
340,
612,
11,
87,
63,
3333,
690,
5288,
14,
23562,
63,
5410,
3333,
837,
288,
612,
275,
5288,
14,
23562,
63,
5410,
3333,
342,
446,
336,
63,
3333,
267,
916,
612,
665,
378,
26,
288,
612,
275,
378,
267,
3938,
14,
7660,
480,
25389,
68,
25389,
68,
2,
450,
334,
88,
12,
612,
430,
267,
3938,
14,
271,
4677,
2021,
342,
327,
6423,
4352,
8917,
737,
314,
6387,
2909,
339,
347,
2621,
8,
277,
304,
267,
291,
14,
1231,
14,
2573,
63,
11269,
342,
267,
291,
14,
1231,
14,
22090,
63,
409,
342,
267,
291,
14,
1231,
14,
22644,
342,
267,
291,
14,
1231,
14,
7237,
342,
267,
372,
291,
14,
1507,
339,
347,
372,
63,
1430,
8,
277,
12,
1566,
304,
267,
340,
291,
14,
885,
365,
488,
26,
288,
291,
14,
1231,
14,
30930,
342,
267,
587,
26,
288,
291,
14,
4456,
8,
277,
14,
885,
9,
339,
347,
29835,
63,
1807,
63,
3806,
8,
277,
304,
267,
340,
291,
14,
6406,
365,
488,
26,
288,
291,
14,
1231,
14,
30930,
342,
267,
587,
26,
288,
291,
14,
4456,
8,
277,
14,
6406,
9,
339,
347,
4224,
8,
277,
12,
1967,
304,
267,
291,
14,
1507,
275,
1967,
267,
291,
14,
1231,
14,
10589,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
347,
511,
837,
267,
1738,
275,
12435,
342,
267,
347,
886,
390,
8,
1231,
29,
1231,
304,
288,
366,
275,
5870,
5619,
8,
1231,
12,
586,
1318,
628,
2765,
365,
282,
511,
9592,
14,
221,
298,
2892,
298,
55,
3857,
642,
1172,
2757,
376,
3503,
9592,
12,
298,
2892,
298,
1589,
15766,
5084,
3955,
1172,
2757,
486,
674,
316,
298,
2892,
298,
262,
11620,
299,
2292,
10540,
3134,
78,
2,
2892,
298,
2585,
1265,
506,
317,
4754,
642,
15583,
586,
15766,
6270,
12555,
401,
298,
1944,
401,
298,
9083,
2255,
586,
849,
29,
16,
12,
586,
9311,
29,
18,
12,
586,
2538,
628,
774,
30631,
531,
288,
870,
366,
14,
1939,
342,
267,
307,
275,
16005,
8,
1231,
12,
1318,
534,
774,
297,
1414,
29,
19014,
9,
267,
307,
14,
1389,
342,
267,
1894,
275,
16005,
8,
1231,
12,
1318,
534,
24145,
297,
1414,
29,
84,
14,
10589,
9,
267,
1894,
14,
1389,
342,
267,
307,
14,
22644,
342,
339,
511,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
acsone/odoo
|
addons/bus/bus.py
|
325
|
7324
|
# -*- coding: utf-8 -*-
import datetime
import json
import logging
import select
import threading
import time
import random
import simplejson
import openerp
from openerp.osv import osv, fields
from openerp.http import request
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
_logger = logging.getLogger(__name__)
TIMEOUT = 50
#----------------------------------------------------------
# Bus
#----------------------------------------------------------
def json_dump(v):
return simplejson.dumps(v, separators=(',', ':'))
def hashable(key):
if isinstance(key, list):
key = tuple(key)
return key
class ImBus(osv.Model):
_name = 'bus.bus'
_columns = {
'id' : fields.integer('Id'),
'create_date' : fields.datetime('Create date'),
'channel' : fields.char('Channel'),
'message' : fields.char('Message'),
}
def gc(self, cr, uid):
timeout_ago = datetime.datetime.utcnow()-datetime.timedelta(seconds=TIMEOUT*2)
domain = [('create_date', '<', timeout_ago.strftime(DEFAULT_SERVER_DATETIME_FORMAT))]
ids = self.search(cr, openerp.SUPERUSER_ID, domain)
self.unlink(cr, openerp.SUPERUSER_ID, ids)
def sendmany(self, cr, uid, notifications):
channels = set()
for channel, message in notifications:
channels.add(channel)
values = {
"channel" : json_dump(channel),
"message" : json_dump(message)
}
self.pool['bus.bus'].create(cr, openerp.SUPERUSER_ID, values)
cr.commit()
if random.random() < 0.01:
self.gc(cr, uid)
if channels:
with openerp.sql_db.db_connect('postgres').cursor() as cr2:
cr2.execute("notify imbus, %s", (json_dump(list(channels)),))
def sendone(self, cr, uid, channel, message):
self.sendmany(cr, uid, [[channel, message]])
def poll(self, cr, uid, channels, last=0):
# first poll return the notification in the 'buffer'
if last == 0:
timeout_ago = datetime.datetime.utcnow()-datetime.timedelta(seconds=TIMEOUT)
domain = [('create_date', '>', timeout_ago.strftime(DEFAULT_SERVER_DATETIME_FORMAT))]
else:
# else returns the unread notifications
domain = [('id','>',last)]
channels = [json_dump(c) for c in channels]
domain.append(('channel','in',channels))
notifications = self.search_read(cr, openerp.SUPERUSER_ID, domain)
return [{"id":notif["id"], "channel": simplejson.loads(notif["channel"]), "message":simplejson.loads(notif["message"])} for notif in notifications]
class ImDispatch(object):
def __init__(self):
self.channels = {}
def poll(self, dbname, channels, last, timeout=TIMEOUT):
# Dont hang ctrl-c for a poll request, we need to bypass private
# attribute access because we dont know before starting the thread that
# it will handle a longpolling request
if not openerp.evented:
current = threading.current_thread()
current._Thread__daemonic = True
# rename the thread to avoid tests waiting for a longpolling
current.setName("openerp.longpolling.request.%s" % current.ident)
registry = openerp.registry(dbname)
# immediatly returns if past notifications exist
with registry.cursor() as cr:
notifications = registry['bus.bus'].poll(cr, openerp.SUPERUSER_ID, channels, last)
# or wait for future ones
if not notifications:
event = self.Event()
for c in channels:
self.channels.setdefault(hashable(c), []).append(event)
try:
event.wait(timeout=timeout)
with registry.cursor() as cr:
notifications = registry['bus.bus'].poll(cr, openerp.SUPERUSER_ID, channels, last)
except Exception:
# timeout
pass
return notifications
def loop(self):
""" Dispatch postgres notifications to the relevant polling threads/greenlets """
_logger.info("Bus.loop listen imbus on db postgres")
with openerp.sql_db.db_connect('postgres').cursor() as cr:
conn = cr._cnx
cr.execute("listen imbus")
cr.commit();
while True:
if select.select([conn], [], [], TIMEOUT) == ([],[],[]):
pass
else:
conn.poll()
channels = []
while conn.notifies:
channels.extend(json.loads(conn.notifies.pop().payload))
# dispatch to local threads/greenlets
events = set()
for c in channels:
events.update(self.channels.pop(hashable(c),[]))
for e in events:
e.set()
def run(self):
while True:
try:
self.loop()
except Exception, e:
_logger.exception("Bus.loop error, sleep and retry")
time.sleep(TIMEOUT)
def start(self):
if openerp.evented:
# gevent mode
import gevent
self.Event = gevent.event.Event
gevent.spawn(self.run)
elif openerp.multi_process:
# disabled in prefork mode
return
else:
# threaded mode
self.Event = threading.Event
t = threading.Thread(name="%s.Bus" % __name__, target=self.run)
t.daemon = True
t.start()
return self
dispatch = ImDispatch().start()
#----------------------------------------------------------
# Controller
#----------------------------------------------------------
class Controller(openerp.http.Controller):
""" Examples:
openerp.jsonRpc('/longpolling/poll','call',{"channels":["c1"],last:0}).then(function(r){console.log(r)});
openerp.jsonRpc('/longpolling/send','call',{"channel":"c1","message":"m1"});
openerp.jsonRpc('/longpolling/send','call',{"channel":"c2","message":"m2"});
"""
@openerp.http.route('/longpolling/send', type="json", auth="public")
def send(self, channel, message):
if not isinstance(channel, basestring):
raise Exception("bus.Bus only string channels are allowed.")
registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.context
return registry['bus.bus'].sendone(cr, uid, channel, message)
# override to add channels
def _poll(self, dbname, channels, last, options):
request.cr.close()
request._cr = None
return dispatch.poll(dbname, channels, last)
@openerp.http.route('/longpolling/poll', type="json", auth="public")
def poll(self, channels, last, options=None):
if options is None:
options = {}
if not dispatch:
raise Exception("bus.Bus unavailable")
if [c for c in channels if not isinstance(c, basestring)]:
print channels
raise Exception("bus.Bus only string channels are allowed.")
return self._poll(request.db, channels, last, options)
# vim:et:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
646,
2022,
199,
646,
2050,
199,
646,
3504,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
646,
13804,
199,
646,
5166,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
9923,
492,
6186,
63,
6613,
63,
12488,
63,
4807,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
8899,
275,
5238,
199,
199,
30346,
199,
3,
18573,
199,
30346,
199,
318,
2022,
63,
2724,
8,
86,
304,
272,
372,
13804,
14,
4180,
8,
86,
12,
17658,
2687,
23324,
7596,
1333,
199,
199,
318,
21197,
8,
498,
304,
272,
340,
1228,
8,
498,
12,
769,
304,
267,
790,
275,
2008,
8,
498,
9,
272,
372,
790,
199,
199,
533,
473,
77,
12106,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
5610,
14,
5610,
7,
272,
485,
3406,
275,
469,
267,
283,
344,
7,
520,
1504,
14,
4115,
360,
1304,
659,
267,
283,
981,
63,
602,
7,
520,
1504,
14,
2083,
360,
2499,
1434,
659,
267,
283,
2775,
7,
520,
1504,
14,
1560,
360,
5358,
659,
267,
283,
1188,
7,
520,
1504,
14,
1560,
360,
2209,
659,
272,
789,
339,
347,
9486,
8,
277,
12,
2467,
12,
1747,
304,
267,
2653,
63,
14315,
275,
2197,
14,
2083,
14,
10779,
22251,
2083,
14,
7473,
8,
4515,
29,
8899,
10,
18,
9,
267,
2881,
275,
4274,
981,
63,
602,
297,
30243,
2653,
63,
14315,
14,
6205,
8,
3472,
63,
6613,
63,
12488,
63,
4807,
10524,
267,
2762,
221,
275,
291,
14,
1733,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2881,
9,
267,
291,
14,
7162,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2762,
9,
339,
347,
3222,
3479,
8,
277,
12,
2467,
12,
1747,
12,
13116,
304,
267,
9245,
275,
663,
342,
267,
367,
3623,
12,
1245,
315,
13116,
26,
288,
9245,
14,
525,
8,
2775,
9,
288,
1338,
275,
469,
355,
298,
2775,
2,
520,
2022,
63,
2724,
8,
2775,
395,
355,
298,
1188,
2,
520,
2022,
63,
2724,
8,
1188,
9,
288,
789,
288,
291,
14,
2293,
459,
5610,
14,
5610,
2278,
981,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
1338,
9,
288,
2467,
14,
3543,
342,
288,
340,
2196,
14,
2355,
342,
665,
378,
14,
614,
26,
355,
291,
14,
9493,
8,
1556,
12,
1747,
9,
267,
340,
9245,
26,
288,
543,
5166,
14,
3009,
63,
697,
14,
697,
63,
2242,
360,
10675,
1959,
3937,
342,
465,
2467,
18,
26,
355,
2467,
18,
14,
2526,
480,
6814,
3416,
5610,
12,
450,
83,
401,
334,
1001,
63,
2724,
8,
513,
8,
6324,
1826,
430,
339,
347,
3222,
368,
8,
277,
12,
2467,
12,
1747,
12,
3623,
12,
1245,
304,
267,
291,
14,
2254,
3479,
8,
1556,
12,
1747,
12,
3474,
2775,
12,
1245,
3934,
339,
347,
11271,
8,
277,
12,
2467,
12,
1747,
12,
9245,
12,
2061,
29,
16,
304,
267,
327,
1642,
11271,
372,
314,
6955,
315,
314,
283,
2738,
7,
267,
340,
2061,
508,
378,
26,
288,
2653,
63,
14315,
275,
2197,
14,
2083,
14,
10779,
22251,
2083,
14,
7473,
8,
4515,
29,
8899,
9,
288,
2881,
275,
4274,
981,
63,
602,
297,
26120,
2653,
63,
14315,
14,
6205,
8,
3472,
63,
6613,
63,
12488,
63,
4807,
10524,
267,
587,
26,
288,
327,
587,
2529,
314,
625,
739,
13116,
288,
2881,
275,
4274,
344,
1673,
4206,
2019,
1874,
267,
9245,
275,
359,
1001,
63,
2724,
8,
67,
9,
367,
286,
315,
9245,
61,
267,
2881,
14,
740,
4725,
2775,
1673,
262,
297,
6324,
430,
267,
13116,
275,
291,
14,
1733,
63,
739,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2881,
9,
267,
372,
16870,
344,
582,
27795,
905,
344,
2255,
298,
2775,
582,
13804,
14,
3640,
8,
27795,
905,
2775,
10252,
298,
1188,
582,
4129,
1001,
14,
3640,
8,
27795,
905,
1188,
3135,
93,
367,
32081,
315,
13116,
61,
199,
199,
533,
473,
77,
20628,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6324,
275,
1052,
339,
347,
11271,
8,
277,
12,
21842,
12,
9245,
12,
2061,
12,
2653,
29,
8899,
304,
267,
327,
577,
1888,
30084,
15427,
13,
67,
367,
282,
11271,
1056,
12,
781,
1929,
370,
21115,
5726,
267,
327,
2225,
2879,
2952,
781,
21542,
5715,
2544,
6617,
314,
2462,
626,
267,
327,
652,
911,
2429,
282,
1846,
17154,
1056,
267,
340,
440,
5166,
14,
12056,
471,
26,
288,
1453,
275,
5796,
14,
1818,
63,
2671,
342,
288,
1453,
423,
4436,
363,
10824,
530,
275,
715,
288,
327,
11441,
314,
2462,
370,
5126,
2295,
10923,
367,
282,
1846,
17154,
288,
1453,
14,
18347,
480,
11267,
14,
2809,
17154,
14,
1069,
4111,
83,
2,
450,
1453,
14,
5425,
9,
398,
7086,
275,
5166,
14,
5189,
8,
13238,
9,
398,
327,
3416,
3700,
292,
590,
2529,
340,
13541,
13116,
2187,
267,
543,
7086,
14,
3937,
342,
465,
2467,
26,
288,
13116,
275,
7086,
459,
5610,
14,
5610,
2278,
6843,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
9245,
12,
2061,
9,
267,
327,
503,
3618,
367,
6466,
7869,
267,
340,
440,
13116,
26,
288,
1566,
275,
291,
14,
2390,
342,
288,
367,
286,
315,
9245,
26,
355,
291,
14,
6324,
14,
5486,
8,
24596,
8,
67,
395,
15364,
740,
8,
1430,
9,
288,
862,
26,
355,
1566,
14,
2573,
8,
2593,
29,
2593,
9,
355,
543,
7086,
14,
3937,
342,
465,
2467,
26,
490,
13116,
275,
7086,
459,
5610,
14,
5610,
2278,
6843,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
9245,
12,
2061,
9,
288,
871,
2186,
26,
355,
327,
2653,
355,
986,
267,
372,
13116,
339,
347,
4438,
8,
277,
304,
267,
408,
28626,
19533,
13116,
370,
314,
12082,
12353,
7183,
15,
7731,
16537,
408,
267,
485,
2921,
14,
815,
480,
12106,
14,
3813,
6938,
3416,
5610,
641,
1592,
19533,
531,
267,
543,
5166,
14,
3009,
63,
697,
14,
697,
63,
2242,
360,
10675,
1959,
3937,
342,
465,
2467,
26,
288,
2557,
275,
2467,
423,
6413,
88,
288,
2467,
14,
2526,
480,
5859,
3416,
5610,
531,
288,
2467,
14,
3543,
7303,
288,
1830
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
646,
2022,
199,
646,
2050,
199,
646,
3504,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
646,
13804,
199,
646,
5166,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
9923,
492,
6186,
63,
6613,
63,
12488,
63,
4807,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
8899,
275,
5238,
199,
199,
30346,
199,
3,
18573,
199,
30346,
199,
318,
2022,
63,
2724,
8,
86,
304,
272,
372,
13804,
14,
4180,
8,
86,
12,
17658,
2687,
23324,
7596,
1333,
199,
199,
318,
21197,
8,
498,
304,
272,
340,
1228,
8,
498,
12,
769,
304,
267,
790,
275,
2008,
8,
498,
9,
272,
372,
790,
199,
199,
533,
473,
77,
12106,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
5610,
14,
5610,
7,
272,
485,
3406,
275,
469,
267,
283,
344,
7,
520,
1504,
14,
4115,
360,
1304,
659,
267,
283,
981,
63,
602,
7,
520,
1504,
14,
2083,
360,
2499,
1434,
659,
267,
283,
2775,
7,
520,
1504,
14,
1560,
360,
5358,
659,
267,
283,
1188,
7,
520,
1504,
14,
1560,
360,
2209,
659,
272,
789,
339,
347,
9486,
8,
277,
12,
2467,
12,
1747,
304,
267,
2653,
63,
14315,
275,
2197,
14,
2083,
14,
10779,
22251,
2083,
14,
7473,
8,
4515,
29,
8899,
10,
18,
9,
267,
2881,
275,
4274,
981,
63,
602,
297,
30243,
2653,
63,
14315,
14,
6205,
8,
3472,
63,
6613,
63,
12488,
63,
4807,
10524,
267,
2762,
221,
275,
291,
14,
1733,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2881,
9,
267,
291,
14,
7162,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2762,
9,
339,
347,
3222,
3479,
8,
277,
12,
2467,
12,
1747,
12,
13116,
304,
267,
9245,
275,
663,
342,
267,
367,
3623,
12,
1245,
315,
13116,
26,
288,
9245,
14,
525,
8,
2775,
9,
288,
1338,
275,
469,
355,
298,
2775,
2,
520,
2022,
63,
2724,
8,
2775,
395,
355,
298,
1188,
2,
520,
2022,
63,
2724,
8,
1188,
9,
288,
789,
288,
291,
14,
2293,
459,
5610,
14,
5610,
2278,
981,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
1338,
9,
288,
2467,
14,
3543,
342,
288,
340,
2196,
14,
2355,
342,
665,
378,
14,
614,
26,
355,
291,
14,
9493,
8,
1556,
12,
1747,
9,
267,
340,
9245,
26,
288,
543,
5166,
14,
3009,
63,
697,
14,
697,
63,
2242,
360,
10675,
1959,
3937,
342,
465,
2467,
18,
26,
355,
2467,
18,
14,
2526,
480,
6814,
3416,
5610,
12,
450,
83,
401,
334,
1001,
63,
2724,
8,
513,
8,
6324,
1826,
430,
339,
347,
3222,
368,
8,
277,
12,
2467,
12,
1747,
12,
3623,
12,
1245,
304,
267,
291,
14,
2254,
3479,
8,
1556,
12,
1747,
12,
3474,
2775,
12,
1245,
3934,
339,
347,
11271,
8,
277,
12,
2467,
12,
1747,
12,
9245,
12,
2061,
29,
16,
304,
267,
327,
1642,
11271,
372,
314,
6955,
315,
314,
283,
2738,
7,
267,
340,
2061,
508,
378,
26,
288,
2653,
63,
14315,
275,
2197,
14,
2083,
14,
10779,
22251,
2083,
14,
7473,
8,
4515,
29,
8899,
9,
288,
2881,
275,
4274,
981,
63,
602,
297,
26120,
2653,
63,
14315,
14,
6205,
8,
3472,
63,
6613,
63,
12488,
63,
4807,
10524,
267,
587,
26,
288,
327,
587,
2529,
314,
625,
739,
13116,
288,
2881,
275,
4274,
344,
1673,
4206,
2019,
1874,
267,
9245,
275,
359,
1001,
63,
2724,
8,
67,
9,
367,
286,
315,
9245,
61,
267,
2881,
14,
740,
4725,
2775,
1673,
262,
297,
6324,
430,
267,
13116,
275,
291,
14,
1733,
63,
739,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
2881,
9,
267,
372,
16870,
344,
582,
27795,
905,
344,
2255,
298,
2775,
582,
13804,
14,
3640,
8,
27795,
905,
2775,
10252,
298,
1188,
582,
4129,
1001,
14,
3640,
8,
27795,
905,
1188,
3135,
93,
367,
32081,
315,
13116,
61,
199,
199,
533,
473,
77,
20628,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6324,
275,
1052,
339,
347,
11271,
8,
277,
12,
21842,
12,
9245,
12,
2061,
12,
2653,
29,
8899,
304,
267,
327,
577,
1888,
30084,
15427,
13,
67,
367,
282,
11271,
1056,
12,
781,
1929,
370,
21115,
5726,
267,
327,
2225,
2879,
2952,
781,
21542,
5715,
2544,
6617,
314,
2462,
626,
267,
327,
652,
911,
2429,
282,
1846,
17154,
1056,
267,
340,
440,
5166,
14,
12056,
471,
26,
288,
1453,
275,
5796,
14,
1818,
63,
2671,
342,
288,
1453,
423,
4436,
363,
10824,
530,
275,
715,
288,
327,
11441,
314,
2462,
370,
5126,
2295,
10923,
367,
282,
1846,
17154,
288,
1453,
14,
18347,
480,
11267,
14,
2809,
17154,
14,
1069,
4111,
83,
2,
450,
1453,
14,
5425,
9,
398,
7086,
275,
5166,
14,
5189,
8,
13238,
9,
398,
327,
3416,
3700,
292,
590,
2529,
340,
13541,
13116,
2187,
267,
543,
7086,
14,
3937,
342,
465,
2467,
26,
288,
13116,
275,
7086,
459,
5610,
14,
5610,
2278,
6843,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
9245,
12,
2061,
9,
267,
327,
503,
3618,
367,
6466,
7869,
267,
340,
440,
13116,
26,
288,
1566,
275,
291,
14,
2390,
342,
288,
367,
286,
315,
9245,
26,
355,
291,
14,
6324,
14,
5486,
8,
24596,
8,
67,
395,
15364,
740,
8,
1430,
9,
288,
862,
26,
355,
1566,
14,
2573,
8,
2593,
29,
2593,
9,
355,
543,
7086,
14,
3937,
342,
465,
2467,
26,
490,
13116,
275,
7086,
459,
5610,
14,
5610,
2278,
6843,
8,
1556,
12,
5166,
14,
20710,
63,
998,
12,
9245,
12,
2061,
9,
288,
871,
2186,
26,
355,
327,
2653,
355,
986,
267,
372,
13116,
339,
347,
4438,
8,
277,
304,
267,
408,
28626,
19533,
13116,
370,
314,
12082,
12353,
7183,
15,
7731,
16537,
408,
267,
485,
2921,
14,
815,
480,
12106,
14,
3813,
6938,
3416,
5610,
641,
1592,
19533,
531,
267,
543,
5166,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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
] |
tinloaf/home-assistant
|
homeassistant/components/camera/usps.py
|
5
|
2585
|
"""
Support for a camera made up of usps mail images.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/camera.usps/
"""
from datetime import timedelta
import logging
from homeassistant.components.camera import Camera
from homeassistant.components.usps import DATA_USPS
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['usps']
SCAN_INTERVAL = timedelta(seconds=10)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up USPS mail camera."""
if discovery_info is None:
return
usps = hass.data[DATA_USPS]
add_entities([USPSCamera(usps)])
class USPSCamera(Camera):
"""Representation of the images available from USPS."""
def __init__(self, usps):
"""Initialize the USPS camera images."""
super().__init__()
self._usps = usps
self._name = self._usps.name
self._session = self._usps.session
self._mail_img = []
self._last_mail = None
self._mail_index = 0
self._mail_count = 0
self._timer = None
def camera_image(self):
"""Update the camera's image if it has changed."""
self._usps.update()
try:
self._mail_count = len(self._usps.mail)
except TypeError:
# No mail
return None
if self._usps.mail != self._last_mail:
# Mail items must have changed
self._mail_img = []
if len(self._usps.mail) >= 1:
self._last_mail = self._usps.mail
for article in self._usps.mail:
_LOGGER.debug("Fetching article image: %s", article)
img = self._session.get(article['image']).content
self._mail_img.append(img)
try:
return self._mail_img[self._mail_index]
except IndexError:
return None
@property
def name(self):
"""Return the name of this camera."""
return '{} mail'.format(self._name)
@property
def model(self):
"""Return date of mail as model."""
try:
return 'Date: {}'.format(str(self._usps.mail[0]['date']))
except IndexError:
return None
@property
def should_poll(self):
"""Update the mail image index periodically."""
return True
def update(self):
"""Update mail image index."""
if self._mail_index < (self._mail_count - 1):
self._mail_index += 1
else:
self._mail_index = 0
|
apache-2.0
|
[
624,
199,
11532,
367,
282,
15177,
6326,
1536,
402,
399,
681,
83,
6016,
5935,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
3931,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
11928,
14,
527,
1190,
15,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
199,
504,
8846,
14,
4608,
14,
11928,
492,
445,
7122,
199,
504,
8846,
14,
4608,
14,
527,
1190,
492,
7126,
63,
1668,
5067,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
25743,
9415,
2563,
275,
788,
527,
1190,
418,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
709,
9,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
19635,
5067,
6016,
15177,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
399,
681,
83,
275,
6298,
14,
576,
59,
3998,
63,
1668,
5067,
61,
272,
1050,
63,
8327,
779,
1668,
5067,
18425,
8,
527,
1190,
3948,
421,
199,
533,
19635,
5067,
18425,
8,
18425,
304,
272,
408,
20609,
402,
314,
5935,
2808,
687,
19635,
5067,
1041,
339,
347,
636,
826,
721,
277,
12,
399,
681,
83,
304,
267,
408,
9345,
314,
19635,
5067,
15177,
5935,
1041,
267,
1613,
11027,
826,
4533,
398,
291,
423,
527,
1190,
275,
399,
681,
83,
267,
291,
423,
354,
275,
291,
423,
527,
1190,
14,
354,
267,
291,
423,
1730,
275,
291,
423,
527,
1190,
14,
1730,
398,
291,
423,
1198,
63,
4060,
275,
942,
267,
291,
423,
2019,
63,
1198,
275,
488,
267,
291,
423,
1198,
63,
1080,
275,
378,
267,
291,
423,
1198,
63,
835,
275,
378,
398,
291,
423,
7414,
275,
488,
339,
347,
15177,
63,
1569,
8,
277,
304,
267,
408,
4152,
314,
15177,
1159,
1834,
340,
652,
965,
2896,
1041,
267,
291,
423,
527,
1190,
14,
873,
342,
267,
862,
26,
288,
291,
423,
1198,
63,
835,
275,
822,
8,
277,
423,
527,
1190,
14,
1198,
9,
267,
871,
3146,
26,
288,
327,
3091,
6016,
288,
372,
488,
398,
340,
291,
423,
527,
1190,
14,
1198,
1137,
291,
423,
2019,
63,
1198,
26,
288,
327,
18027,
2974,
1471,
1172,
2896,
288,
291,
423,
1198,
63,
4060,
275,
942,
288,
340,
822,
8,
277,
423,
527,
1190,
14,
1198,
9,
2356,
413,
26,
355,
291,
423,
2019,
63,
1198,
275,
291,
423,
527,
1190,
14,
1198,
355,
367,
9772,
315,
291,
423,
527,
1190,
14,
1198,
26,
490,
485,
10186,
14,
1757,
480,
11135,
316,
9772,
1834,
26,
450,
83,
401,
9772,
9,
490,
6050,
275,
291,
423,
1730,
14,
362,
8,
6934,
459,
1569,
13227,
1317,
490,
291,
423,
1198,
63,
4060,
14,
740,
8,
4060,
9,
398,
862,
26,
288,
372,
291,
423,
1198,
63,
4060,
59,
277,
423,
1198,
63,
1080,
61,
267,
871,
7888,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
642,
15177,
1041,
267,
372,
9005,
6016,
1370,
908,
8,
277,
423,
354,
9,
339,
768,
1829,
272,
347,
1402,
8,
277,
304,
267,
408,
1767,
1434,
402,
6016,
465,
1402,
1041,
267,
862,
26,
288,
372,
283,
2506,
26,
9499,
908,
8,
495,
8,
277,
423,
527,
1190,
14,
1198,
59,
16,
2733,
602,
5156,
267,
871,
7888,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
1077,
63,
6843,
8,
277,
304,
267,
408,
4152,
314,
6016,
1834,
1478,
18745,
1183,
1041,
267,
372,
715,
339,
347,
1678,
8,
277,
304,
267,
408,
4152,
6016,
1834,
1478,
1041,
267,
340,
291,
423,
1198,
63,
1080,
665,
334,
277,
423,
1198,
63,
835,
446,
413,
304,
288,
291,
423,
1198,
63,
1080,
847,
413,
267,
587,
26,
288,
291,
423,
1198,
63,
1080,
275,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
11532,
367,
282,
15177,
6326,
1536,
402,
399,
681,
83,
6016,
5935,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
3931,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
11928,
14,
527,
1190,
15,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
199,
504,
8846,
14,
4608,
14,
11928,
492,
445,
7122,
199,
504,
8846,
14,
4608,
14,
527,
1190,
492,
7126,
63,
1668,
5067,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
25743,
9415,
2563,
275,
788,
527,
1190,
418,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
709,
9,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
19635,
5067,
6016,
15177,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
399,
681,
83,
275,
6298,
14,
576,
59,
3998,
63,
1668,
5067,
61,
272,
1050,
63,
8327,
779,
1668,
5067,
18425,
8,
527,
1190,
3948,
421,
199,
533,
19635,
5067,
18425,
8,
18425,
304,
272,
408,
20609,
402,
314,
5935,
2808,
687,
19635,
5067,
1041,
339,
347,
636,
826,
721,
277,
12,
399,
681,
83,
304,
267,
408,
9345,
314,
19635,
5067,
15177,
5935,
1041,
267,
1613,
11027,
826,
4533,
398,
291,
423,
527,
1190,
275,
399,
681,
83,
267,
291,
423,
354,
275,
291,
423,
527,
1190,
14,
354,
267,
291,
423,
1730,
275,
291,
423,
527,
1190,
14,
1730,
398,
291,
423,
1198,
63,
4060,
275,
942,
267,
291,
423,
2019,
63,
1198,
275,
488,
267,
291,
423,
1198,
63,
1080,
275,
378,
267,
291,
423,
1198,
63,
835,
275,
378,
398,
291,
423,
7414,
275,
488,
339,
347,
15177,
63,
1569,
8,
277,
304,
267,
408,
4152,
314,
15177,
1159,
1834,
340,
652,
965,
2896,
1041,
267,
291,
423,
527,
1190,
14,
873,
342,
267,
862,
26,
288,
291,
423,
1198,
63,
835,
275,
822,
8,
277,
423,
527,
1190,
14,
1198,
9,
267,
871,
3146,
26,
288,
327,
3091,
6016,
288,
372,
488,
398,
340,
291,
423,
527,
1190,
14,
1198,
1137,
291,
423,
2019,
63,
1198,
26,
288,
327,
18027,
2974,
1471,
1172,
2896,
288,
291,
423,
1198,
63,
4060,
275,
942,
288,
340,
822,
8,
277,
423,
527,
1190,
14,
1198,
9,
2356,
413,
26,
355,
291,
423,
2019,
63,
1198,
275,
291,
423,
527,
1190,
14,
1198,
355,
367,
9772,
315,
291,
423,
527,
1190,
14,
1198,
26,
490,
485,
10186,
14,
1757,
480,
11135,
316,
9772,
1834,
26,
450,
83,
401,
9772,
9,
490,
6050,
275,
291,
423,
1730,
14,
362,
8,
6934,
459,
1569,
13227,
1317,
490,
291,
423,
1198,
63,
4060,
14,
740,
8,
4060,
9,
398,
862,
26,
288,
372,
291,
423,
1198,
63,
4060,
59,
277,
423,
1198,
63,
1080,
61,
267,
871,
7888,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
642,
15177,
1041,
267,
372,
9005,
6016,
1370,
908,
8,
277,
423,
354,
9,
339,
768,
1829,
272,
347,
1402,
8,
277,
304,
267,
408,
1767,
1434,
402,
6016,
465,
1402,
1041,
267,
862,
26,
288,
372,
283,
2506,
26,
9499,
908,
8,
495,
8,
277,
423,
527,
1190,
14,
1198,
59,
16,
2733,
602,
5156,
267,
871,
7888,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
1077,
63,
6843,
8,
277,
304,
267,
408,
4152,
314,
6016,
1834,
1478,
18745,
1183,
1041,
267,
372,
715,
339,
347,
1678,
8,
277,
304,
267,
408,
4152,
6016,
1834,
1478,
1041,
267,
340,
291,
423,
1198,
63,
1080,
665,
334,
277,
423,
1198,
63,
835,
446,
413,
304,
288,
291,
423,
1198,
63,
1080,
847,
413,
267,
587,
26,
288,
291,
423,
1198,
63,
1080,
275,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
kuiwei/kuiwei
|
common/lib/xmodule/xmodule/lti_module.py
|
7
|
31868
|
"""
Learning Tools Interoperability (LTI) module.
Resources
---------
Theoretical background and detailed specifications of LTI can be found on:
http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html
This module is based on the version 1.1.1 of the LTI specifications by the
IMS Global authority. For authentication, it uses OAuth1.
When responding back to the LTI tool provider, we must issue a correct
response. Types of responses and their message payload is available at:
Table A1.2 Interpretation of the 'CodeMajor/severity' matrix.
http://www.imsglobal.org/gws/gwsv1p0/imsgws_wsdlBindv1p0.html
A resource to test the LTI protocol (PHP realization):
http://www.imsglobal.org/developers/LTI/test/v1p1/lms.php
We have also begun to add support for LTI 1.2/2.0. We will keep this
docstring in synch with what support is available. The first LTI 2.0
feature to be supported is the REST API results service, see specification
at
http://www.imsglobal.org/lti/ltiv2p0/uml/purl.imsglobal.org/vocab/lis/v2/outcomes/Result/service.html
What is supported:
------------------
1.) Display of simple LTI in iframe or a new window.
2.) Multiple LTI components on a single page.
3.) The use of multiple LTI providers per course.
4.) Use of advanced LTI component that provides back a grade.
A) LTI 1.1.1 XML endpoint
a.) The LTI provider sends back a grade to a specified URL.
b.) Currently only action "update" is supported. "Read", and "delete"
actions initially weren't required.
B) LTI 2.0 Result Service JSON REST endpoint
(http://www.imsglobal.org/lti/ltiv2p0/uml/purl.imsglobal.org/vocab/lis/v2/outcomes/Result/service.html)
a.) Discovery of all such LTI http endpoints for a course. External tools GET from this discovery
endpoint and receive URLs for interacting with individual grading units.
(see lms/djangoapps/courseware/views.py:get_course_lti_endpoints)
b.) GET, PUT and DELETE in LTI Result JSON binding
(http://www.imsglobal.org/lti/ltiv2p0/mediatype/application/vnd/ims/lis/v2/result+json/index.html)
for a provider to synchronize grades into edx-platform. Reading, Setting, and Deleteing
Numeric grades between 0 and 1 and text + basic HTML feedback comments are supported, via
GET / PUT / DELETE HTTP methods respectively
"""
import logging
import oauthlib.oauth1
from oauthlib.oauth1.rfc5849 import signature
import hashlib
import base64
import urllib
import textwrap
import bleach
from lxml import etree
from webob import Response
import mock
from xml.sax.saxutils import escape
from xmodule.editing_module import MetadataOnlyEditingDescriptor
from xmodule.raw_module import EmptyDataRawDescriptor
from xmodule.x_module import XModule, module_attr
from xmodule.course_module import CourseDescriptor
from xmodule.lti_2_util import LTI20ModuleMixin, LTIError
from pkg_resources import resource_string
from xblock.core import String, Scope, List, XBlock
from xblock.fields import Boolean, Float
log = logging.getLogger(__name__)
# Make '_' a no-op so we can scrape strings
_ = lambda text: text
DOCS_ANCHOR_TAG = (
"<a target='_blank'"
"href='http://edx.readthedocs.org/projects/ca/en/latest/exercises_tools/lti_component.html'>"
"the edX LTI documentation</a>"
)
class LTIFields(object):
"""
Fields to define and obtain LTI tool from provider are set here,
except credentials, which should be set in course settings::
`lti_id` is id to connect tool with credentials in course settings. It should not contain :: (double semicolon)
`launch_url` is launch URL of tool.
`custom_parameters` are additional parameters to navigate to proper book and book page.
For example, for Vitalsource provider, `launch_url` should be
*https://bc-staging.vitalsource.com/books/book*,
and to get to proper book and book page, you should set custom parameters as::
vbid=put_book_id_here
book_location=page/put_page_number_here
Default non-empty URL for `launch_url` is needed due to oauthlib demand (URL scheme should be presented)::
https://github.com/idan/oauthlib/blob/master/oauthlib/oauth1/rfc5849/signature.py#L136
"""
display_name = String(
display_name=_("Display Name"),
help=_(
"Enter the name that students see for this component. "
"Analytics reports may also use the display name to identify this component."
),
scope=Scope.settings,
default="LTI",
)
lti_id = String(
display_name=_("LTI ID"),
help=_(
"Enter the LTI ID for the external LTI provider. "
"This value must be the same LTI ID that you entered in the "
"LTI Passports setting on the Advanced Settings page."
"<br />See " + DOCS_ANCHOR_TAG + " for more details on this setting."
),
default='',
scope=Scope.settings
)
launch_url = String(
display_name=_("LTI URL"),
help=_(
"Enter the URL of the external tool that this component launches. "
"This setting is only used when Hide External Tool is set to False."
"<br />See " + DOCS_ANCHOR_TAG + " for more details on this setting."
),
default='http://www.example.com',
scope=Scope.settings)
custom_parameters = List(
display_name=_("Custom Parameters"),
help=_(
"Add the key/value pair for any custom parameters, such as the page your e-book should open to or "
"the background color for this component."
"<br />See " + DOCS_ANCHOR_TAG + " for more details on this setting."
),
scope=Scope.settings)
open_in_a_new_page = Boolean(
display_name=_("Open in New Page"),
help=_(
"Select True if you want students to click a link that opens the LTI tool in a new window. "
"Select False if you want the LTI content to open in an IFrame in the current page. "
"This setting is only used when Hide External Tool is set to False. "
),
default=True,
scope=Scope.settings
)
has_score = Boolean(
display_name=_("Scored"),
help=_(
"Select True if this component will receive a numerical score from the external LTI system."
),
default=False,
scope=Scope.settings
)
weight = Float(
display_name=_("Weight"),
help=_(
"Enter the number of points possible for this component. "
"The default value is 1.0. "
"This setting is only used when Scored is set to True."
),
default=1.0,
scope=Scope.settings,
values={"min": 0},
)
module_score = Float(
help=_("The score kept in the xblock KVS -- duplicate of the published score in django DB"),
default=None,
scope=Scope.user_state
)
score_comment = String(
help=_("Comment as returned from grader, LTI2.0 spec"),
default="",
scope=Scope.user_state
)
hide_launch = Boolean(
display_name=_("Hide External Tool"),
help=_(
"Select True if you want to use this component as a placeholder for syncing with an external grading "
"system rather than launch an external tool. "
"This setting hides the Launch button and any IFrames for this component."
),
default=False,
scope=Scope.settings
)
class LTIModule(LTIFields, LTI20ModuleMixin, XModule):
"""
Module provides LTI integration to course.
Except usual Xmodule structure it proceeds with OAuth signing.
How it works::
1. Get credentials from course settings.
2. There is minimal set of parameters need to be signed (presented for Vitalsource)::
user_id
oauth_callback
lis_outcome_service_url
lis_result_sourcedid
launch_presentation_return_url
lti_message_type
lti_version
roles
*+ all custom parameters*
These parameters should be encoded and signed by *OAuth1* together with
`launch_url` and *POST* request type.
3. Signing proceeds with client key/secret pair obtained from course settings.
That pair should be obtained from LTI provider and set into course settings by course author.
After that signature and other OAuth data are generated.
OAuth data which is generated after signing is usual::
oauth_callback
oauth_nonce
oauth_consumer_key
oauth_signature_method
oauth_timestamp
oauth_version
4. All that data is passed to form and sent to LTI provider server by browser via
autosubmit via JavaScript.
Form example::
<form
action="${launch_url}"
name="ltiLaunchForm-${element_id}"
class="ltiLaunchForm"
method="post"
target="ltiLaunchFrame-${element_id}"
encType="application/x-www-form-urlencoded"
>
<input name="launch_presentation_return_url" value="" />
<input name="lis_outcome_service_url" value="" />
<input name="lis_result_sourcedid" value="" />
<input name="lti_message_type" value="basic-lti-launch-request" />
<input name="lti_version" value="LTI-1p0" />
<input name="oauth_callback" value="about:blank" />
<input name="oauth_consumer_key" value="${oauth_consumer_key}" />
<input name="oauth_nonce" value="${oauth_nonce}" />
<input name="oauth_signature_method" value="HMAC-SHA1" />
<input name="oauth_timestamp" value="${oauth_timestamp}" />
<input name="oauth_version" value="1.0" />
<input name="user_id" value="${user_id}" />
<input name="role" value="student" />
<input name="oauth_signature" value="${oauth_signature}" />
<input name="custom_1" value="${custom_param_1_value}" />
<input name="custom_2" value="${custom_param_2_value}" />
<input name="custom_..." value="${custom_param_..._value}" />
<input type="submit" value="Press to Launch" />
</form>
5. LTI provider has same secret key and it signs data string via *OAuth1* and compares signatures.
If signatures are correct, LTI provider redirects iframe source to LTI tool web page,
and LTI tool is rendered to iframe inside course.
Otherwise error message from LTI provider is generated.
"""
css = {'scss': [resource_string(__name__, 'css/lti/lti.scss')]}
def get_input_fields(self):
# LTI provides a list of default parameters that might be passed as
# part of the POST data. These parameters should not be prefixed.
# Likewise, The creator of an LTI link can add custom key/value parameters
# to a launch which are to be included with the launch of the LTI link.
# In this case, we will automatically add `custom_` prefix before this parameters.
# See http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html#_Toc316828520
PARAMETERS = [
"lti_message_type",
"lti_version",
"resource_link_title",
"resource_link_description",
"user_image",
"lis_person_name_given",
"lis_person_name_family",
"lis_person_name_full",
"lis_person_contact_email_primary",
"lis_person_sourcedid",
"role_scope_mentor",
"context_type",
"context_title",
"context_label",
"launch_presentation_locale",
"launch_presentation_document_target",
"launch_presentation_css_url",
"launch_presentation_width",
"launch_presentation_height",
"launch_presentation_return_url",
"tool_consumer_info_product_family_code",
"tool_consumer_info_version",
"tool_consumer_instance_guid",
"tool_consumer_instance_name",
"tool_consumer_instance_description",
"tool_consumer_instance_url",
"tool_consumer_instance_contact_email",
]
client_key, client_secret = self.get_client_key_secret()
# parsing custom parameters to dict
custom_parameters = {}
for custom_parameter in self.custom_parameters:
try:
param_name, param_value = [p.strip() for p in custom_parameter.split('=', 1)]
except ValueError:
_ = self.runtime.service(self, "i18n").ugettext
msg = _('Could not parse custom parameter: {custom_parameter}. Should be "x=y" string.').format(
custom_parameter="{0!r}".format(custom_parameter)
)
raise LTIError(msg)
# LTI specs: 'custom_' should be prepended before each custom parameter, as pointed in link above.
if param_name not in PARAMETERS:
param_name = 'custom_' + param_name
custom_parameters[unicode(param_name)] = unicode(param_value)
return self.oauth_params(
custom_parameters,
client_key,
client_secret,
)
def get_context(self):
"""
Returns a context.
"""
# use bleach defaults. see https://github.com/jsocol/bleach/blob/master/bleach/__init__.py
# ALLOWED_TAGS are
# ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code', 'em', 'i', 'li', 'ol', 'strong', 'ul']
#
# ALLOWED_ATTRIBUTES are
# 'a': ['href', 'title'],
# 'abbr': ['title'],
# 'acronym': ['title'],
#
# This lets all plaintext through.
sanitized_comment = bleach.clean(self.score_comment)
return {
'input_fields': self.get_input_fields(),
# These parameters do not participate in OAuth signing.
'launch_url': self.launch_url.strip(),
'element_id': self.location.html_id(),
'element_class': self.category,
'open_in_a_new_page': self.open_in_a_new_page,
'display_name': self.display_name,
'form_url': self.runtime.handler_url(self, 'preview_handler').rstrip('/?'),
'hide_launch': self.hide_launch,
'has_score': self.has_score,
'weight': self.weight,
'module_score': self.module_score,
'comment': sanitized_comment,
}
def get_html(self):
"""
Renders parameters to template.
"""
return self.system.render_template('lti.html', self.get_context())
@XBlock.handler
def preview_handler(self, _, __):
"""
This is called to get context with new oauth params to iframe.
"""
template = self.system.render_template('lti_form.html', self.get_context())
return Response(template, content_type='text/html')
def get_user_id(self):
user_id = self.runtime.anonymous_student_id
assert user_id is not None
return unicode(urllib.quote(user_id))
def get_outcome_service_url(self, service_name="grade_handler"):
"""
Return URL for storing grades.
To test LTI on sandbox we must use http scheme.
While testing locally and on Jenkins, mock_lti_server use http.referer
to obtain scheme, so it is ok to have http(s) anyway.
The scheme logic is handled in lms/lib/xblock/runtime.py
"""
return self.runtime.handler_url(self, service_name, thirdparty=True).rstrip('/?')
def get_resource_link_id(self):
"""
This is an opaque unique identifier that the TC guarantees will be unique
within the TC for every placement of the link.
If the tool / activity is placed multiple times in the same context,
each of those placements will be distinct.
This value will also change if the item is exported from one system or
context and imported into another system or context.
This parameter is required.
Example: u'edx.org-i4x-2-3-lti-31de800015cf4afb973356dbe81496df'
Hostname, edx.org,
makes resource_link_id change on import to another system.
Last part of location, location.name - 31de800015cf4afb973356dbe81496df,
is random hash, updated by course_id,
this makes resource_link_id unique inside single course.
First part of location is tag-org-course-category, i4x-2-3-lti.
Location.name itself does not change on import to another course,
but org and course_id change.
So together with org and course_id in a form of
i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
makes resource_link_id to be unique among courses inside same system.
"""
return unicode(urllib.quote("{}-{}".format(self.system.hostname, self.location.html_id())))
def get_lis_result_sourcedid(self):
"""
This field contains an identifier that indicates the LIS Result Identifier (if any)
associated with this launch. This field identifies a unique row and column within the
TC gradebook. This field is unique for every combination of context_id / resource_link_id / user_id.
This value may change for a particular resource_link_id / user_id from one launch to the next.
The TP should only retain the most recent value for this field for a particular resource_link_id / user_id.
This field is generally optional, but is required for grading.
"""
return "{context}:{resource_link}:{user_id}".format(
context=urllib.quote(self.context_id),
resource_link=self.get_resource_link_id(),
user_id=self.get_user_id()
)
def get_course(self):
"""
Return course by course id.
"""
return self.descriptor.runtime.modulestore.get_course(self.course_id)
@property
def context_id(self):
"""
Return context_id.
context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
that contains the link being launched.
"""
return self.course_id.to_deprecated_string()
@property
def role(self):
"""
Get system user role and convert it to LTI role.
"""
roles = {
'student': u'Student',
'staff': u'Administrator',
'instructor': u'Instructor',
}
return roles.get(self.system.get_user_role(), u'Student')
def oauth_params(self, custom_parameters, client_key, client_secret):
"""
Signs request and returns signature and OAuth parameters.
`custom_paramters` is dict of parsed `custom_parameter` field
`client_key` and `client_secret` are LTI tool credentials.
Also *anonymous student id* is passed to template and therefore to LTI provider.
"""
client = oauthlib.oauth1.Client(
client_key=unicode(client_key),
client_secret=unicode(client_secret)
)
# Must have parameters for correct signing from LTI:
body = {
u'user_id': self.get_user_id(),
u'oauth_callback': u'about:blank',
u'launch_presentation_return_url': '',
u'lti_message_type': u'basic-lti-launch-request',
u'lti_version': 'LTI-1p0',
u'roles': self.role,
# Parameters required for grading:
u'resource_link_id': self.get_resource_link_id(),
u'lis_result_sourcedid': self.get_lis_result_sourcedid(),
u'context_id': self.context_id,
}
if self.has_score:
body.update({
u'lis_outcome_service_url': self.get_outcome_service_url()
})
# Appending custom parameter for signing.
body.update(custom_parameters)
headers = {
# This is needed for body encoding:
'Content-Type': 'application/x-www-form-urlencoded',
}
try:
__, headers, __ = client.sign(
unicode(self.launch_url.strip()),
http_method=u'POST',
body=body,
headers=headers)
except ValueError: # Scheme not in url.
# https://github.com/idan/oauthlib/blob/master/oauthlib/oauth1/rfc5849/signature.py#L136
# Stubbing headers for now:
headers = {
u'Content-Type': u'application/x-www-form-urlencoded',
u'Authorization': u'OAuth oauth_nonce="80966668944732164491378916897", \
oauth_timestamp="1378916897", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", \
oauth_consumer_key="", oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"'}
params = headers['Authorization']
# Parse headers to pass to template as part of context:
params = dict([param.strip().replace('"', '').split('=') for param in params.split(',')])
params[u'oauth_nonce'] = params[u'OAuth oauth_nonce']
del params[u'OAuth oauth_nonce']
# oauthlib encodes signature with
# 'Content-Type': 'application/x-www-form-urlencoded'
# so '='' becomes '%3D'.
# We send form via browser, so browser will encode it again,
# So we need to decode signature back:
params[u'oauth_signature'] = urllib.unquote(params[u'oauth_signature']).decode('utf8')
# Add LTI parameters to OAuth parameters for sending in form.
params.update(body)
return params
def max_score(self):
return self.weight if self.has_score else None
@XBlock.handler
def grade_handler(self, request, suffix): # pylint: disable=unused-argument
"""
This is called by courseware.module_render, to handle an AJAX call.
Used only for grading. Returns XML response.
Example of request body from LTI provider::
<?xml version = "1.0" encoding = "UTF-8"?>
<imsx_POXEnvelopeRequest xmlns = "some_link (may be not required)">
<imsx_POXHeader>
<imsx_POXRequestHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>528243ba5241b</imsx_messageIdentifier>
</imsx_POXRequestHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>
<replaceResultRequest>
<resultRecord>
<sourcedGUID>
<sourcedId>feb-123-456-2929::28883</sourcedId>
</sourcedGUID>
<result>
<resultScore>
<language>en-us</language>
<textString>0.4</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>
Example of correct/incorrect answer XML body:: see response_xml_template.
"""
response_xml_template = textwrap.dedent("""\
<?xml version="1.0" encoding="UTF-8"?>
<imsx_POXEnvelopeResponse xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<imsx_POXHeader>
<imsx_POXResponseHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>{imsx_messageIdentifier}</imsx_messageIdentifier>
<imsx_statusInfo>
<imsx_codeMajor>{imsx_codeMajor}</imsx_codeMajor>
<imsx_severity>status</imsx_severity>
<imsx_description>{imsx_description}</imsx_description>
<imsx_messageRefIdentifier>
</imsx_messageRefIdentifier>
</imsx_statusInfo>
</imsx_POXResponseHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>{response}</imsx_POXBody>
</imsx_POXEnvelopeResponse>
""")
# Returns when `action` is unsupported.
# Supported actions:
# - replaceResultRequest.
unsupported_values = {
'imsx_codeMajor': 'unsupported',
'imsx_description': 'Target does not support the requested operation.',
'imsx_messageIdentifier': 'unknown',
'response': ''
}
# Returns if:
# - score is out of range;
# - can't parse response from TP;
# - can't verify OAuth signing or OAuth signing is incorrect.
failure_values = {
'imsx_codeMajor': 'failure',
'imsx_description': 'The request has failed.',
'imsx_messageIdentifier': 'unknown',
'response': ''
}
try:
imsx_messageIdentifier, sourcedId, score, action = self.parse_grade_xml_body(request.body)
except Exception as e:
error_message = "Request body XML parsing error: " + escape(e.message)
log.debug("[LTI]: " + error_message)
failure_values['imsx_description'] = error_message
return Response(response_xml_template.format(**failure_values), content_type="application/xml")
# Verify OAuth signing.
try:
self.verify_oauth_body_sign(request)
except (ValueError, LTIError) as e:
failure_values['imsx_messageIdentifier'] = escape(imsx_messageIdentifier)
error_message = "OAuth verification error: " + escape(e.message)
failure_values['imsx_description'] = error_message
log.debug("[LTI]: " + error_message)
return Response(response_xml_template.format(**failure_values), content_type="application/xml")
real_user = self.system.get_real_user(urllib.unquote(sourcedId.split(':')[-1]))
if not real_user: # that means we can't save to database, as we do not have real user id.
failure_values['imsx_messageIdentifier'] = escape(imsx_messageIdentifier)
failure_values['imsx_description'] = "User not found."
return Response(response_xml_template.format(**failure_values), content_type="application/xml")
if action == 'replaceResultRequest':
self.set_user_module_score(real_user, score, self.max_score())
values = {
'imsx_codeMajor': 'success',
'imsx_description': 'Score for {sourced_id} is now {score}'.format(sourced_id=sourcedId, score=score),
'imsx_messageIdentifier': escape(imsx_messageIdentifier),
'response': '<replaceResultResponse/>'
}
log.debug("[LTI]: Grade is saved.")
return Response(response_xml_template.format(**values), content_type="application/xml")
unsupported_values['imsx_messageIdentifier'] = escape(imsx_messageIdentifier)
log.debug("[LTI]: Incorrect action.")
return Response(response_xml_template.format(**unsupported_values), content_type='application/xml')
@classmethod
def parse_grade_xml_body(cls, body):
"""
Parses XML from request.body and returns parsed data
XML body should contain nsmap with namespace, that is specified in LTI specs.
Returns tuple: imsx_messageIdentifier, sourcedId, score, action
Raises Exception if can't parse.
"""
lti_spec_namespace = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"
namespaces = {'def': lti_spec_namespace}
data = body.strip().encode('utf-8')
parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')
root = etree.fromstring(data, parser=parser)
imsx_messageIdentifier = root.xpath("//def:imsx_messageIdentifier", namespaces=namespaces)[0].text or ''
sourcedId = root.xpath("//def:sourcedId", namespaces=namespaces)[0].text
score = root.xpath("//def:textString", namespaces=namespaces)[0].text
action = root.xpath("//def:imsx_POXBody", namespaces=namespaces)[0].getchildren()[0].tag.replace('{'+lti_spec_namespace+'}', '')
# Raise exception if score is not float or not in range 0.0-1.0 regarding spec.
score = float(score)
if not 0 <= score <= 1:
raise LTIError('score value outside the permitted range of 0-1.')
return imsx_messageIdentifier, sourcedId, score, action
def verify_oauth_body_sign(self, request, content_type='application/x-www-form-urlencoded'):
"""
Verify grade request from LTI provider using OAuth body signing.
Uses http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html::
This specification extends the OAuth signature to include integrity checks on HTTP request bodies
with content types other than application/x-www-form-urlencoded.
Arguments:
request: DjangoWebobRequest.
Raises:
LTIError if request is incorrect.
"""
client_key, client_secret = self.get_client_key_secret()
headers = {
'Authorization': unicode(request.headers.get('Authorization')),
'Content-Type': content_type,
}
sha1 = hashlib.sha1()
sha1.update(request.body)
oauth_body_hash = base64.b64encode(sha1.digest())
oauth_params = signature.collect_parameters(headers=headers, exclude_oauth_signature=False)
oauth_headers = dict(oauth_params)
oauth_signature = oauth_headers.pop('oauth_signature')
mock_request = mock.Mock(
uri=unicode(urllib.unquote(request.url)),
http_method=unicode(request.method),
params=oauth_headers.items(),
signature=oauth_signature
)
if oauth_body_hash != oauth_headers.get('oauth_body_hash'):
raise LTIError("OAuth body hash verification is failed.")
if not signature.verify_hmac_sha1(mock_request, client_secret):
raise LTIError("OAuth signature verification is failed.")
def get_client_key_secret(self):
"""
Obtains client_key and client_secret credentials from current course.
"""
course = self.get_course()
for lti_passport in course.lti_passports:
try:
lti_id, key, secret = [i.strip() for i in lti_passport.split(':')]
except ValueError:
_ = self.runtime.service(self, "i18n").ugettext
msg = _('Could not parse LTI passport: {lti_passport}. Should be "id:key:secret" string.').format(
lti_passport='{0!r}'.format(lti_passport)
)
raise LTIError(msg)
if lti_id == self.lti_id.strip():
return key, secret
return '', ''
class LTIDescriptor(LTIFields, MetadataOnlyEditingDescriptor, EmptyDataRawDescriptor):
"""
Descriptor for LTI Xmodule.
"""
module_class = LTIModule
grade_handler = module_attr('grade_handler')
preview_handler = module_attr('preview_handler')
lti_2_0_result_rest_handler = module_attr('lti_2_0_result_rest_handler')
clear_user_module_score = module_attr('clear_user_module_score')
get_outcome_service_url = module_attr('get_outcome_service_url')
|
agpl-3.0
|
[
624,
199,
25519,
23228,
8883,
9198,
3616,
334,
44,
13247,
9,
859,
14,
421,
199,
13745,
199,
9960,
199,
199,
1918,
720,
3294,
8020,
436,
16212,
28754,
402,
491,
13247,
883,
506,
1911,
641,
26,
339,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
44,
13247,
15,
86,
17,
80,
17,
80,
17,
15,
21934,
26246,
86,
17,
80,
17,
80,
17,
14,
1360,
199,
199,
2765,
859,
365,
4079,
641,
314,
1015,
413,
14,
17,
14,
17,
402,
314,
491,
13247,
28754,
701,
314,
199,
1469,
51,
13641,
18330,
14,
2104,
6299,
12,
652,
4440,
11715,
17,
14,
199,
199,
11423,
9163,
1098,
1771,
370,
314,
491,
13247,
4744,
5022,
12,
781,
1471,
4976,
282,
3211,
199,
1310,
14,
18851,
402,
9320,
436,
3932,
1245,
4886,
365,
2808,
737,
26,
339,
6957,
437,
17,
14,
18,
6551,
25133,
425,
402,
314,
283,
3034,
21657,
15,
20394,
7,
3634,
14,
272,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
71,
3569,
15,
8392,
2772,
17,
80,
16,
15,
73,
1328,
3569,
63,
21452,
8198,
86,
17,
80,
16,
14,
1360,
199,
199,
33,
2073,
370,
511,
314,
491,
13247,
4113,
334,
31300,
3363,
2072,
304,
339,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
23826,
15,
44,
13247,
15,
396,
15,
86,
17,
80,
17,
15,
15807,
14,
8624,
199,
199,
6004,
1172,
2597,
506,
17924,
370,
1050,
2291,
367,
491,
13247,
413,
14,
18,
15,
18,
14,
16,
14,
221,
2136,
911,
4215,
642,
199,
12485,
315,
308,
5654,
543,
4052,
2291,
365,
2808,
14,
221,
710,
1642,
491,
13247,
499,
14,
16,
199,
4445,
370,
506,
3748,
365,
314,
14880,
3261,
2058,
2435,
12,
1937,
8929,
199,
292,
199,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
26297,
15,
80,
633,
14,
73,
1328,
1498,
14,
1308,
15,
9953,
15,
14392,
15,
86,
18,
15,
17502,
83,
15,
2889,
15,
1364,
14,
1360,
199,
199,
21015,
365,
3748,
26,
199,
777,
306,
199,
199,
17,
4959,
12175,
402,
3486,
491,
13247,
315,
340,
1186,
503,
282,
892,
4353,
14,
199,
18,
4959,
14326,
491,
13247,
7323,
641,
282,
2849,
2034,
14,
199,
19,
4959,
710,
675,
402,
3663,
491,
13247,
18032,
1126,
2518,
14,
199,
20,
4959,
3645,
402,
19472,
491,
13247,
3931,
626,
6571,
1771,
282,
16183,
14,
272,
437,
9,
491,
13247,
413,
14,
17,
14,
17,
4692,
6037,
267,
282,
4959,
710,
491,
13247,
5022,
16178,
1771,
282,
16183,
370,
282,
2013,
2851,
14,
267,
330,
4959,
13550,
1454,
1595,
298,
873,
2,
365,
3748,
14,
298,
3284,
401,
436,
298,
1807,
2,
288,
5445,
22801,
781,
828,
1133,
1415,
14,
272,
699,
9,
491,
13247,
499,
14,
16,
10695,
7591,
4840,
14880,
6037,
2126,
334,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
26297,
15,
80,
633,
14,
73,
1328,
1498,
14,
1308,
15,
9953,
15,
14392,
15,
86,
18,
15,
17502,
83,
15,
2889,
15,
1364,
14,
1360,
9,
267,
282,
4959,
5289,
6913,
402,
1006,
4066,
491,
13247,
1455,
16173,
367,
282,
2518,
14,
221,
18802,
7249,
9576,
687,
642,
13172,
288,
6037,
436,
9128,
10867,
367,
17232,
316,
543,
8212,
22815,
6204,
14,
288,
334,
3239,
21577,
15,
16432,
15,
17744,
15,
4196,
14,
647,
26,
362,
63,
1972,
63,
21934,
63,
14461,
9,
267,
330,
4959,
9576,
12,
18337,
436,
15137,
315,
491,
13247,
10695,
4840,
11696,
288,
334,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
3700,
8588,
15,
3578,
15,
26379,
15,
11171,
15,
14392,
15,
86,
18,
15,
1099,
11,
1001,
15,
1080,
14,
1360,
9,
288,
367,
282,
5022,
370,
31021,
1999,
3424,
1901,
22435,
13,
3246,
14,
221,
799,
5384,
12,
13510,
12,
436,
8496,
316,
288,
19378,
1999,
3424,
3382,
378,
436,
413,
436,
1318,
435,
5678,
4163,
17145,
6786,
787,
3748,
12,
4799,
288,
9576,
1182,
18337,
1182,
15137,
3101,
3102,
17342,
199,
624,
199,
199,
646,
2050,
199,
646,
9725,
773,
14,
6126,
17,
199,
504,
9725,
773,
14,
6126,
17,
14,
8973,
12248,
25,
492,
4955,
199,
646,
8337,
199,
646,
1300,
772,
199,
646,
4011,
199,
646,
13390,
199,
646,
29603,
1225,
199,
504,
14490,
492,
7559,
199,
504,
14568,
492,
7232,
199,
646,
1683,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
199,
504,
9872,
14,
27057,
63,
578,
492,
16160,
5903,
20957,
1337,
4311,
199,
504,
9872,
14,
1773,
63,
578,
492,
9630,
1451,
7963,
4311,
199,
504,
9872,
14,
88,
63,
578,
492,
25656,
12,
859,
63,
962,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
21934,
63,
18,
63,
1974,
492,
491,
13247,
1165,
2377,
4256,
12,
491,
13247,
547,
199,
504,
5496,
63,
4435,
492,
2073,
63,
875,
199,
504,
12971,
14,
1018,
492,
2624,
12,
20488,
12,
3820,
12,
15398,
199,
504,
12971,
14,
955,
492,
9411,
12,
11140,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
4155,
14135,
282,
949,
13,
411,
880,
781,
883,
10328,
321,
3326,
199,
63,
275,
2400,
1318,
26,
1318,
199,
199,
30072,
63,
20139,
726,
63,
6967,
275,
334,
272,
3886,
65,
1347,
17574,
2500,
4065,
272,
298,
6399,
534,
1014,
921,
8268,
14,
25085,
14,
1308,
15,
6776,
15,
696,
15,
287,
15,
7410,
15,
5273,
559,
874,
63,
2537,
15,
21934,
63,
3173,
14,
1360,
7,
4335,
272,
298,
1589,
3988,
56,
491,
13247,
3794,
1108,
65,
4335,
199,
9,
421,
199,
533,
491,
13247,
7304,
8,
785,
304,
272,
408,
272,
16424,
370,
5627,
436,
3332,
491,
13247,
4744,
687,
5022,
787,
663,
2348,
12,
272,
871,
6235,
12,
1314,
1077,
506,
663,
315,
2518,
2202,
447,
339,
658,
21934,
63,
344,
64,
365,
1305,
370,
4907,
4744,
543,
6235,
315,
2518,
2202,
14,
2779,
1077,
440,
1395,
3800,
334,
3157,
18734,
12167,
9,
272,
658,
9850,
63,
633,
64,
365,
10623,
2851,
402,
4744,
14,
272,
658,
4229,
63,
3214,
64,
787,
4722,
2633,
370,
20850,
370
] |
[
199,
25519,
23228,
8883,
9198,
3616,
334,
44,
13247,
9,
859,
14,
421,
199,
13745,
199,
9960,
199,
199,
1918,
720,
3294,
8020,
436,
16212,
28754,
402,
491,
13247,
883,
506,
1911,
641,
26,
339,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
44,
13247,
15,
86,
17,
80,
17,
80,
17,
15,
21934,
26246,
86,
17,
80,
17,
80,
17,
14,
1360,
199,
199,
2765,
859,
365,
4079,
641,
314,
1015,
413,
14,
17,
14,
17,
402,
314,
491,
13247,
28754,
701,
314,
199,
1469,
51,
13641,
18330,
14,
2104,
6299,
12,
652,
4440,
11715,
17,
14,
199,
199,
11423,
9163,
1098,
1771,
370,
314,
491,
13247,
4744,
5022,
12,
781,
1471,
4976,
282,
3211,
199,
1310,
14,
18851,
402,
9320,
436,
3932,
1245,
4886,
365,
2808,
737,
26,
339,
6957,
437,
17,
14,
18,
6551,
25133,
425,
402,
314,
283,
3034,
21657,
15,
20394,
7,
3634,
14,
272,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
71,
3569,
15,
8392,
2772,
17,
80,
16,
15,
73,
1328,
3569,
63,
21452,
8198,
86,
17,
80,
16,
14,
1360,
199,
199,
33,
2073,
370,
511,
314,
491,
13247,
4113,
334,
31300,
3363,
2072,
304,
339,
1455,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
23826,
15,
44,
13247,
15,
396,
15,
86,
17,
80,
17,
15,
15807,
14,
8624,
199,
199,
6004,
1172,
2597,
506,
17924,
370,
1050,
2291,
367,
491,
13247,
413,
14,
18,
15,
18,
14,
16,
14,
221,
2136,
911,
4215,
642,
199,
12485,
315,
308,
5654,
543,
4052,
2291,
365,
2808,
14,
221,
710,
1642,
491,
13247,
499,
14,
16,
199,
4445,
370,
506,
3748,
365,
314,
14880,
3261,
2058,
2435,
12,
1937,
8929,
199,
292,
199,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
26297,
15,
80,
633,
14,
73,
1328,
1498,
14,
1308,
15,
9953,
15,
14392,
15,
86,
18,
15,
17502,
83,
15,
2889,
15,
1364,
14,
1360,
199,
199,
21015,
365,
3748,
26,
199,
777,
306,
199,
199,
17,
4959,
12175,
402,
3486,
491,
13247,
315,
340,
1186,
503,
282,
892,
4353,
14,
199,
18,
4959,
14326,
491,
13247,
7323,
641,
282,
2849,
2034,
14,
199,
19,
4959,
710,
675,
402,
3663,
491,
13247,
18032,
1126,
2518,
14,
199,
20,
4959,
3645,
402,
19472,
491,
13247,
3931,
626,
6571,
1771,
282,
16183,
14,
272,
437,
9,
491,
13247,
413,
14,
17,
14,
17,
4692,
6037,
267,
282,
4959,
710,
491,
13247,
5022,
16178,
1771,
282,
16183,
370,
282,
2013,
2851,
14,
267,
330,
4959,
13550,
1454,
1595,
298,
873,
2,
365,
3748,
14,
298,
3284,
401,
436,
298,
1807,
2,
288,
5445,
22801,
781,
828,
1133,
1415,
14,
272,
699,
9,
491,
13247,
499,
14,
16,
10695,
7591,
4840,
14880,
6037,
2126,
334,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
26297,
15,
80,
633,
14,
73,
1328,
1498,
14,
1308,
15,
9953,
15,
14392,
15,
86,
18,
15,
17502,
83,
15,
2889,
15,
1364,
14,
1360,
9,
267,
282,
4959,
5289,
6913,
402,
1006,
4066,
491,
13247,
1455,
16173,
367,
282,
2518,
14,
221,
18802,
7249,
9576,
687,
642,
13172,
288,
6037,
436,
9128,
10867,
367,
17232,
316,
543,
8212,
22815,
6204,
14,
288,
334,
3239,
21577,
15,
16432,
15,
17744,
15,
4196,
14,
647,
26,
362,
63,
1972,
63,
21934,
63,
14461,
9,
267,
330,
4959,
9576,
12,
18337,
436,
15137,
315,
491,
13247,
10695,
4840,
11696,
288,
334,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
21934,
15,
21934,
86,
18,
80,
16,
15,
3700,
8588,
15,
3578,
15,
26379,
15,
11171,
15,
14392,
15,
86,
18,
15,
1099,
11,
1001,
15,
1080,
14,
1360,
9,
288,
367,
282,
5022,
370,
31021,
1999,
3424,
1901,
22435,
13,
3246,
14,
221,
799,
5384,
12,
13510,
12,
436,
8496,
316,
288,
19378,
1999,
3424,
3382,
378,
436,
413,
436,
1318,
435,
5678,
4163,
17145,
6786,
787,
3748,
12,
4799,
288,
9576,
1182,
18337,
1182,
15137,
3101,
3102,
17342,
199,
624,
199,
199,
646,
2050,
199,
646,
9725,
773,
14,
6126,
17,
199,
504,
9725,
773,
14,
6126,
17,
14,
8973,
12248,
25,
492,
4955,
199,
646,
8337,
199,
646,
1300,
772,
199,
646,
4011,
199,
646,
13390,
199,
646,
29603,
1225,
199,
504,
14490,
492,
7559,
199,
504,
14568,
492,
7232,
199,
646,
1683,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
199,
504,
9872,
14,
27057,
63,
578,
492,
16160,
5903,
20957,
1337,
4311,
199,
504,
9872,
14,
1773,
63,
578,
492,
9630,
1451,
7963,
4311,
199,
504,
9872,
14,
88,
63,
578,
492,
25656,
12,
859,
63,
962,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
21934,
63,
18,
63,
1974,
492,
491,
13247,
1165,
2377,
4256,
12,
491,
13247,
547,
199,
504,
5496,
63,
4435,
492,
2073,
63,
875,
199,
504,
12971,
14,
1018,
492,
2624,
12,
20488,
12,
3820,
12,
15398,
199,
504,
12971,
14,
955,
492,
9411,
12,
11140,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
4155,
14135,
282,
949,
13,
411,
880,
781,
883,
10328,
321,
3326,
199,
63,
275,
2400,
1318,
26,
1318,
199,
199,
30072,
63,
20139,
726,
63,
6967,
275,
334,
272,
3886,
65,
1347,
17574,
2500,
4065,
272,
298,
6399,
534,
1014,
921,
8268,
14,
25085,
14,
1308,
15,
6776,
15,
696,
15,
287,
15,
7410,
15,
5273,
559,
874,
63,
2537,
15,
21934,
63,
3173,
14,
1360,
7,
4335,
272,
298,
1589,
3988,
56,
491,
13247,
3794,
1108,
65,
4335,
199,
9,
421,
199,
533,
491,
13247,
7304,
8,
785,
304,
272,
408,
272,
16424,
370,
5627,
436,
3332,
491,
13247,
4744,
687,
5022,
787,
663,
2348,
12,
272,
871,
6235,
12,
1314,
1077,
506,
663,
315,
2518,
2202,
447,
339,
658,
21934,
63,
344,
64,
365,
1305,
370,
4907,
4744,
543,
6235,
315,
2518,
2202,
14,
2779,
1077,
440,
1395,
3800,
334,
3157,
18734,
12167,
9,
272,
658,
9850,
63,
633,
64,
365,
10623,
2851,
402,
4744,
14,
272,
658,
4229,
63,
3214,
64,
787,
4722,
2633,
370,
20850,
370,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
imtapps/django-imt-fork
|
django/db/models/loading.py
|
104
|
10633
|
"Utilities for loading models and the modules that contain them."
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.utils._os import upath
from django.utils import six
import imp
import sys
import os
__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
'load_app', 'app_cache_ready')
class AppCache(object):
"""
A cache that stores installed applications and their models. Used to
provide reverse-relations and for app introspection (e.g. admin).
"""
# Use the Borg pattern to share state between all instances. Details at
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531.
__shared_state = dict(
# Keys of app_store are the model modules for each application.
app_store=SortedDict(),
# Mapping of installed app_labels to model modules for that app.
app_labels={},
# Mapping of app_labels to a dictionary of model names to model code.
# May contain apps that are not installed.
app_models=SortedDict(),
# Mapping of app_labels to errors raised when trying to import the app.
app_errors={},
# -- Everything below here is only used when populating the cache --
loaded=False,
handled={},
postponed=[],
nesting_level=0,
_get_models_cache={},
)
def __init__(self):
self.__dict__ = self.__shared_state
def _populate(self):
"""
Fill in all the cache information. This method is threadsafe, in the
sense that every caller will see the same state upon return, and if the
cache is already initialised, it does no work.
"""
if self.loaded:
return
# Note that we want to use the import lock here - the app loading is
# in many cases initiated implicitly by importing, and thus it is
# possible to end up in deadlock when one thread initiates loading
# without holding the importer lock and another thread then tries to
# import something which also launches the app loading. For details of
# this situation see #18251.
imp.acquire_lock()
try:
if self.loaded:
return
for app_name in settings.INSTALLED_APPS:
if app_name in self.handled:
continue
self.load_app(app_name, True)
if not self.nesting_level:
for app_name in self.postponed:
self.load_app(app_name)
self.loaded = True
finally:
imp.release_lock()
def _label_for(self, app_mod):
"""
Return app_label for given models module.
"""
return app_mod.__name__.split('.')[-2]
def load_app(self, app_name, can_postpone=False):
"""
Loads the app with the provided fully qualified name, and returns the
model module.
"""
self.handled[app_name] = None
self.nesting_level += 1
app_module = import_module(app_name)
try:
models = import_module('.models', app_name)
except ImportError:
self.nesting_level -= 1
# If the app doesn't have a models module, we can just ignore the
# ImportError and return no models for it.
if not module_has_submodule(app_module, 'models'):
return None
# But if the app does have a models module, we need to figure out
# whether to suppress or propagate the error. If can_postpone is
# True then it may be that the package is still being imported by
# Python and the models module isn't available yet. So we add the
# app to the postponed list and we'll try it again after all the
# recursion has finished (in populate). If can_postpone is False
# then it's time to raise the ImportError.
else:
if can_postpone:
self.postponed.append(app_name)
return None
else:
raise
self.nesting_level -= 1
if models not in self.app_store:
self.app_store[models] = len(self.app_store)
self.app_labels[self._label_for(models)] = models
return models
def app_cache_ready(self):
"""
Returns true if the model cache is fully populated.
Useful for code that wants to cache the results of get_models() for
themselves once it is safe to do so.
"""
return self.loaded
def get_apps(self):
"Returns a list of all installed modules that contain models."
self._populate()
# Ensure the returned list is always in the same order (with new apps
# added at the end). This avoids unstable ordering on the admin app
# list page, for example.
apps = [(v, k) for k, v in self.app_store.items()]
apps.sort()
return [elt[1] for elt in apps]
def get_app(self, app_label, emptyOK=False):
"""
Returns the module containing the models for the given app_label. If
the app has no models in it and 'emptyOK' is True, returns None.
"""
self._populate()
imp.acquire_lock()
try:
for app_name in settings.INSTALLED_APPS:
if app_label == app_name.split('.')[-1]:
mod = self.load_app(app_name, False)
if mod is None:
if emptyOK:
return None
raise ImproperlyConfigured("App with label %s is missing a models.py module." % app_label)
else:
return mod
raise ImproperlyConfigured("App with label %s could not be found" % app_label)
finally:
imp.release_lock()
def get_app_errors(self):
"Returns the map of known problems with the INSTALLED_APPS."
self._populate()
return self.app_errors
def get_models(self, app_mod=None,
include_auto_created=False, include_deferred=False,
only_installed=True, include_swapped=False):
"""
Given a module containing models, returns a list of the models.
Otherwise returns a list of all installed models.
By default, auto-created models (i.e., m2m models without an
explicit intermediate table) are not included. However, if you
specify include_auto_created=True, they will be.
By default, models created to satisfy deferred attribute
queries are *not* included in the list of models. However, if
you specify include_deferred, they will be.
By default, models that aren't part of installed apps will *not*
be included in the list of models. However, if you specify
only_installed=False, they will be.
By default, models that have been swapped out will *not* be
included in the list of models. However, if you specify
include_swapped, they will be.
"""
cache_key = (app_mod, include_auto_created, include_deferred, only_installed, include_swapped)
try:
return self._get_models_cache[cache_key]
except KeyError:
pass
self._populate()
if app_mod:
if app_mod in self.app_store:
app_list = [self.app_models.get(self._label_for(app_mod),
SortedDict())]
else:
app_list = []
else:
if only_installed:
app_list = [self.app_models.get(app_label, SortedDict())
for app_label in six.iterkeys(self.app_labels)]
else:
app_list = six.itervalues(self.app_models)
model_list = []
for app in app_list:
model_list.extend(
model for model in app.values()
if ((not model._deferred or include_deferred) and
(not model._meta.auto_created or include_auto_created) and
(not model._meta.swapped or include_swapped))
)
self._get_models_cache[cache_key] = model_list
return model_list
def get_model(self, app_label, model_name,
seed_cache=True, only_installed=True):
"""
Returns the model matching the given app_label and case-insensitive
model_name.
Returns None if no model is found.
"""
if seed_cache:
self._populate()
if only_installed and app_label not in self.app_labels:
return None
return self.app_models.get(app_label, SortedDict()).get(model_name.lower())
def register_models(self, app_label, *models):
"""
Register a set of models as belonging to an app.
"""
for model in models:
# Store as 'name: model' pair in a dictionary
# in the app_models dictionary
model_name = model._meta.object_name.lower()
model_dict = self.app_models.setdefault(app_label, SortedDict())
if model_name in model_dict:
# The same model may be imported via different paths (e.g.
# appname.models and project.appname.models). We use the source
# filename as a means to detect identity.
fname1 = os.path.abspath(upath(sys.modules[model.__module__].__file__))
fname2 = os.path.abspath(upath(sys.modules[model_dict[model_name].__module__].__file__))
# Since the filename extension could be .py the first time and
# .pyc or .pyo the second time, ignore the extension when
# comparing.
if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
continue
model_dict[model_name] = model
self._get_models_cache.clear()
cache = AppCache()
# These methods were always module level, so are kept that way for backwards
# compatibility.
get_apps = cache.get_apps
get_app = cache.get_app
get_app_errors = cache.get_app_errors
get_models = cache.get_models
get_model = cache.get_model
register_models = cache.register_models
load_app = cache.load_app
app_cache_ready = cache.app_cache_ready
|
bsd-3-clause
|
[
2,
22905,
367,
8697,
1709,
436,
314,
4621,
626,
1395,
3062,
2122,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
859,
63,
1989,
63,
16229,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
646,
1742,
199,
646,
984,
199,
646,
747,
199,
199,
363,
452,
363,
275,
661,
362,
63,
5181,
297,
283,
362,
63,
571,
297,
283,
362,
63,
992,
297,
283,
362,
63,
1238,
297,
283,
2683,
63,
992,
297,
267,
283,
912,
63,
571,
297,
283,
571,
63,
1637,
63,
2179,
358,
421,
199,
533,
4693,
4437,
8,
785,
304,
272,
408,
272,
437,
2581,
626,
14086,
4903,
13103,
436,
3932,
1709,
14,
8051,
370,
272,
5647,
3837,
13,
15741,
436,
367,
1145,
1109,
14254,
334,
69,
14,
71,
14,
4628,
680,
272,
408,
272,
327,
3645,
314,
699,
1308,
3851,
370,
8663,
1174,
3382,
1006,
4454,
14,
15621,
737,
272,
327,
1455,
921,
305,
4812,
14,
32595,
14,
957,
15,
1179,
9060,
15,
967,
32632,
15,
4718,
15,
25879,
15,
16373,
2192,
14,
272,
636,
5555,
63,
929,
275,
1211,
8,
267,
327,
17276,
402,
1145,
63,
1617,
787,
314,
1402,
4621,
367,
1924,
4223,
14,
267,
1145,
63,
1617,
29,
22861,
2141,
1062,
398,
327,
12340,
402,
4903,
1145,
63,
3512,
370,
1402,
4621,
367,
626,
1145,
14,
267,
1145,
63,
3512,
10324,
398,
327,
12340,
402,
1145,
63,
3512,
370,
282,
2600,
402,
1402,
1561,
370,
1402,
1233,
14,
267,
327,
10162,
1395,
8686,
626,
787,
440,
4903,
14,
267,
1145,
63,
992,
29,
22861,
2141,
1062,
398,
327,
12340,
402,
1145,
63,
3512,
370,
2552,
4915,
1380,
9936,
370,
492,
314,
1145,
14,
267,
1145,
63,
2550,
10324,
398,
327,
1553,
18414,
2127,
5084,
2348,
365,
1454,
1202,
1380,
4560,
20529,
314,
2581,
1553,
267,
6511,
29,
797,
12,
267,
8860,
10324,
267,
2963,
80,
28918,
6034,
267,
19500,
63,
1896,
29,
16,
12,
267,
485,
362,
63,
992,
63,
1637,
10324,
272,
776,
339,
347,
636,
826,
721,
277,
304,
267,
291,
855,
807,
363,
275,
291,
855,
5555,
63,
929,
339,
347,
485,
13817,
8,
277,
304,
267,
408,
267,
24797,
315,
1006,
314,
2581,
2556,
14,
961,
1083,
365,
2462,
3489,
12,
315,
314,
267,
12249,
626,
4036,
8025,
911,
1937,
314,
2011,
1174,
12188,
372,
12,
436,
340,
314,
267,
2581,
365,
2575,
2536,
9096,
12,
652,
1630,
949,
1736,
14,
267,
408,
267,
340,
291,
14,
4591,
26,
288,
372,
267,
327,
3390,
626,
781,
2934,
370,
675,
314,
492,
4650,
2348,
446,
314,
1145,
8697,
365,
267,
327,
315,
5002,
5560,
11023,
972,
19796,
701,
16306,
12,
436,
12850,
652,
365,
267,
327,
3962,
370,
1284,
1536,
315,
12314,
831,
1380,
1373,
2462,
11023,
2335,
8697,
267,
327,
1928,
17573,
314,
13479,
4650,
436,
4573,
2462,
2066,
11275,
370,
267,
327,
492,
6020,
1314,
2597,
10623,
397,
314,
1145,
8697,
14,
2104,
2436,
402,
267,
327,
642,
25781,
1937,
327,
1085,
12140,
14,
267,
1742,
14,
8174,
63,
831,
342,
267,
862,
26,
288,
340,
291,
14,
4591,
26,
355,
372,
288,
367,
1145,
63,
354,
315,
2202,
14,
15942,
63,
14219,
26,
355,
340,
1145,
63,
354,
315,
291,
14,
11217,
26,
490,
1980,
355,
291,
14,
912,
63,
571,
8,
571,
63,
354,
12,
715,
9,
288,
340,
440,
291,
14,
15272,
316,
63,
1896,
26,
355,
367,
1145,
63,
354,
315,
291,
14,
1932,
80,
28918,
26,
490,
291,
14,
912,
63,
571,
8,
571,
63,
354,
9,
355,
291,
14,
4591,
275,
715,
267,
3753,
26,
288,
1742,
14,
3221,
63,
831,
342,
339,
347,
485,
1302,
63,
509,
8,
277,
12,
1145,
63,
1494,
304,
267,
408,
267,
1432,
1145,
63,
1302,
367,
1627,
1709,
859,
14,
398,
408,
267,
372,
1145,
63,
1494,
855,
354,
4343,
1294,
29084,
18,
61,
339,
347,
2248,
63,
571,
8,
277,
12,
1145,
63,
354,
12,
883,
63,
1932,
80,
368,
29,
797,
304,
267,
408,
267,
30367,
314,
1145,
543,
314,
2741,
9999,
12313,
536,
12,
436,
2529,
314,
267,
1402,
859,
14,
267,
408,
267,
291,
14,
11217,
59,
571,
63,
354,
61,
275,
488,
267,
291,
14,
15272,
316,
63,
1896,
847,
413,
267,
1145,
63,
578,
275,
492,
63,
578,
8,
571,
63,
354,
9,
267,
862,
26,
288,
1709,
275,
492,
63,
578,
5175,
992,
297,
1145,
63,
354,
9,
267,
871,
3545,
26,
288,
291,
14,
15272,
316,
63,
1896,
4862,
413,
288,
327,
982,
314,
1145,
3181,
1133,
1172,
282,
1709,
859,
12,
781,
883,
2951,
3686,
314,
288,
327,
3545,
436,
372,
949,
1709,
367,
652,
14,
288,
340,
440,
859,
63,
1989,
63,
16229,
8,
571,
63,
578,
12,
283,
992,
735,
355,
372,
488,
288,
327,
11017,
340,
314,
1145,
1630,
1172,
282,
1709,
859,
12,
781,
1929,
370,
9658,
734,
288,
327,
3775,
370,
15678,
503,
19843,
314,
1125,
14,
982,
883,
63,
1932,
80,
368,
365,
288,
327,
715,
2066,
652,
1443,
506,
626,
314,
2559,
365,
5139,
3769,
8439,
701,
288,
327,
2018,
436,
314,
1709,
859,
5712,
1133,
2808,
5966,
14,
2002,
781,
1050,
314,
288,
327,
1145,
370,
314,
2963,
80,
28918,
769,
436,
781,
7171,
862,
652,
4020,
2410,
1006,
314,
288,
327,
16189,
965,
9158,
334,
262,
13904,
680,
982,
883,
63,
1932,
80,
368,
365,
756,
288,
327,
2066,
652,
1159,
900,
370,
746,
314,
3545,
14,
288,
587,
26,
355,
340,
883,
63,
1932,
80,
368,
26,
490,
291,
14,
1932,
80,
28918,
14,
740,
8,
571,
63,
354,
9,
490,
372,
488,
355,
587,
26,
490,
746,
398,
291,
14,
15272,
316,
63,
1896,
4862,
413,
267,
340,
1709,
440,
315,
291,
14,
571,
63,
1617,
26,
288,
291,
14,
571,
63,
1617,
59,
992,
61,
275,
822,
8,
277,
14,
571,
63,
1617,
9,
288,
291,
14,
571,
63,
3512,
59,
277,
423,
1302,
63,
509,
8
] |
[
22905,
367,
8697,
1709,
436,
314,
4621,
626,
1395,
3062,
2122,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
859,
63,
1989,
63,
16229,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
646,
1742,
199,
646,
984,
199,
646,
747,
199,
199,
363,
452,
363,
275,
661,
362,
63,
5181,
297,
283,
362,
63,
571,
297,
283,
362,
63,
992,
297,
283,
362,
63,
1238,
297,
283,
2683,
63,
992,
297,
267,
283,
912,
63,
571,
297,
283,
571,
63,
1637,
63,
2179,
358,
421,
199,
533,
4693,
4437,
8,
785,
304,
272,
408,
272,
437,
2581,
626,
14086,
4903,
13103,
436,
3932,
1709,
14,
8051,
370,
272,
5647,
3837,
13,
15741,
436,
367,
1145,
1109,
14254,
334,
69,
14,
71,
14,
4628,
680,
272,
408,
272,
327,
3645,
314,
699,
1308,
3851,
370,
8663,
1174,
3382,
1006,
4454,
14,
15621,
737,
272,
327,
1455,
921,
305,
4812,
14,
32595,
14,
957,
15,
1179,
9060,
15,
967,
32632,
15,
4718,
15,
25879,
15,
16373,
2192,
14,
272,
636,
5555,
63,
929,
275,
1211,
8,
267,
327,
17276,
402,
1145,
63,
1617,
787,
314,
1402,
4621,
367,
1924,
4223,
14,
267,
1145,
63,
1617,
29,
22861,
2141,
1062,
398,
327,
12340,
402,
4903,
1145,
63,
3512,
370,
1402,
4621,
367,
626,
1145,
14,
267,
1145,
63,
3512,
10324,
398,
327,
12340,
402,
1145,
63,
3512,
370,
282,
2600,
402,
1402,
1561,
370,
1402,
1233,
14,
267,
327,
10162,
1395,
8686,
626,
787,
440,
4903,
14,
267,
1145,
63,
992,
29,
22861,
2141,
1062,
398,
327,
12340,
402,
1145,
63,
3512,
370,
2552,
4915,
1380,
9936,
370,
492,
314,
1145,
14,
267,
1145,
63,
2550,
10324,
398,
327,
1553,
18414,
2127,
5084,
2348,
365,
1454,
1202,
1380,
4560,
20529,
314,
2581,
1553,
267,
6511,
29,
797,
12,
267,
8860,
10324,
267,
2963,
80,
28918,
6034,
267,
19500,
63,
1896,
29,
16,
12,
267,
485,
362,
63,
992,
63,
1637,
10324,
272,
776,
339,
347,
636,
826,
721,
277,
304,
267,
291,
855,
807,
363,
275,
291,
855,
5555,
63,
929,
339,
347,
485,
13817,
8,
277,
304,
267,
408,
267,
24797,
315,
1006,
314,
2581,
2556,
14,
961,
1083,
365,
2462,
3489,
12,
315,
314,
267,
12249,
626,
4036,
8025,
911,
1937,
314,
2011,
1174,
12188,
372,
12,
436,
340,
314,
267,
2581,
365,
2575,
2536,
9096,
12,
652,
1630,
949,
1736,
14,
267,
408,
267,
340,
291,
14,
4591,
26,
288,
372,
267,
327,
3390,
626,
781,
2934,
370,
675,
314,
492,
4650,
2348,
446,
314,
1145,
8697,
365,
267,
327,
315,
5002,
5560,
11023,
972,
19796,
701,
16306,
12,
436,
12850,
652,
365,
267,
327,
3962,
370,
1284,
1536,
315,
12314,
831,
1380,
1373,
2462,
11023,
2335,
8697,
267,
327,
1928,
17573,
314,
13479,
4650,
436,
4573,
2462,
2066,
11275,
370,
267,
327,
492,
6020,
1314,
2597,
10623,
397,
314,
1145,
8697,
14,
2104,
2436,
402,
267,
327,
642,
25781,
1937,
327,
1085,
12140,
14,
267,
1742,
14,
8174,
63,
831,
342,
267,
862,
26,
288,
340,
291,
14,
4591,
26,
355,
372,
288,
367,
1145,
63,
354,
315,
2202,
14,
15942,
63,
14219,
26,
355,
340,
1145,
63,
354,
315,
291,
14,
11217,
26,
490,
1980,
355,
291,
14,
912,
63,
571,
8,
571,
63,
354,
12,
715,
9,
288,
340,
440,
291,
14,
15272,
316,
63,
1896,
26,
355,
367,
1145,
63,
354,
315,
291,
14,
1932,
80,
28918,
26,
490,
291,
14,
912,
63,
571,
8,
571,
63,
354,
9,
355,
291,
14,
4591,
275,
715,
267,
3753,
26,
288,
1742,
14,
3221,
63,
831,
342,
339,
347,
485,
1302,
63,
509,
8,
277,
12,
1145,
63,
1494,
304,
267,
408,
267,
1432,
1145,
63,
1302,
367,
1627,
1709,
859,
14,
398,
408,
267,
372,
1145,
63,
1494,
855,
354,
4343,
1294,
29084,
18,
61,
339,
347,
2248,
63,
571,
8,
277,
12,
1145,
63,
354,
12,
883,
63,
1932,
80,
368,
29,
797,
304,
267,
408,
267,
30367,
314,
1145,
543,
314,
2741,
9999,
12313,
536,
12,
436,
2529,
314,
267,
1402,
859,
14,
267,
408,
267,
291,
14,
11217,
59,
571,
63,
354,
61,
275,
488,
267,
291,
14,
15272,
316,
63,
1896,
847,
413,
267,
1145,
63,
578,
275,
492,
63,
578,
8,
571,
63,
354,
9,
267,
862,
26,
288,
1709,
275,
492,
63,
578,
5175,
992,
297,
1145,
63,
354,
9,
267,
871,
3545,
26,
288,
291,
14,
15272,
316,
63,
1896,
4862,
413,
288,
327,
982,
314,
1145,
3181,
1133,
1172,
282,
1709,
859,
12,
781,
883,
2951,
3686,
314,
288,
327,
3545,
436,
372,
949,
1709,
367,
652,
14,
288,
340,
440,
859,
63,
1989,
63,
16229,
8,
571,
63,
578,
12,
283,
992,
735,
355,
372,
488,
288,
327,
11017,
340,
314,
1145,
1630,
1172,
282,
1709,
859,
12,
781,
1929,
370,
9658,
734,
288,
327,
3775,
370,
15678,
503,
19843,
314,
1125,
14,
982,
883,
63,
1932,
80,
368,
365,
288,
327,
715,
2066,
652,
1443,
506,
626,
314,
2559,
365,
5139,
3769,
8439,
701,
288,
327,
2018,
436,
314,
1709,
859,
5712,
1133,
2808,
5966,
14,
2002,
781,
1050,
314,
288,
327,
1145,
370,
314,
2963,
80,
28918,
769,
436,
781,
7171,
862,
652,
4020,
2410,
1006,
314,
288,
327,
16189,
965,
9158,
334,
262,
13904,
680,
982,
883,
63,
1932,
80,
368,
365,
756,
288,
327,
2066,
652,
1159,
900,
370,
746,
314,
3545,
14,
288,
587,
26,
355,
340,
883,
63,
1932,
80,
368,
26,
490,
291,
14,
1932,
80,
28918,
14,
740,
8,
571,
63,
354,
9,
490,
372,
488,
355,
587,
26,
490,
746,
398,
291,
14,
15272,
316,
63,
1896,
4862,
413,
267,
340,
1709,
440,
315,
291,
14,
571,
63,
1617,
26,
288,
291,
14,
571,
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,
1,
1
] |
bjolivot/ansible
|
lib/ansible/modules/source_control/git.py
|
7
|
42160
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2012, 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: git
author:
- "Ansible Core Team"
- "Michael DeHaan"
version_added: "0.0.1"
short_description: Deploy software (or files) from git checkouts
description:
- Manage I(git) checkouts of repositories to deploy files or software.
options:
repo:
required: true
aliases: [ name ]
description:
- git, SSH, or HTTP(S) protocol address of the git repository.
dest:
required: true
description:
- Absolute path of where the repository should be checked out to.
This parameter is required, unless C(clone) is set to C(no)
This change was made in version 1.8.3. Prior to this version,
the C(dest) parameter was always required.
version:
required: false
default: "HEAD"
description:
- What version of the repository to check out. This can be the
the literal string C(HEAD), a branch name, a tag name.
It can also be a I(SHA-1) hash, in which case C(refspec) needs
to be specified if the given revision is not already available.
accept_hostkey:
required: false
default: "no"
choices: [ "yes", "no" ]
version_added: "1.5"
description:
- if C(yes), adds the hostkey for the repo url if not already
added. If ssh_opts contains "-o StrictHostKeyChecking=no",
this parameter is ignored.
ssh_opts:
required: false
default: None
version_added: "1.5"
description:
- Creates a wrapper script and exports the path as GIT_SSH
which git then automatically uses to override ssh arguments.
An example value could be "-o StrictHostKeyChecking=no"
key_file:
required: false
default: None
version_added: "1.5"
description:
- Specify an optional private key file to use for the checkout.
reference:
required: false
default: null
version_added: "1.4"
description:
- Reference repository (see "git clone --reference ...")
remote:
required: false
default: "origin"
description:
- Name of the remote.
refspec:
required: false
default: null
version_added: "1.9"
description:
- Add an additional refspec to be fetched.
If version is set to a I(SHA-1) not reachable from any branch
or tag, this option may be necessary to specify the ref containing
the I(SHA-1).
Uses the same syntax as the 'git fetch' command.
An example value could be "refs/meta/config".
force:
required: false
default: "no"
choices: [ "yes", "no" ]
version_added: "0.7"
description:
- If C(yes), any modified files in the working
repository will be discarded. Prior to 0.7, this was always
'yes' and could not be disabled. Prior to 1.9, the default was
`yes`
depth:
required: false
default: null
version_added: "1.2"
description:
- Create a shallow clone with a history truncated to the specified
number or revisions. The minimum possible value is C(1), otherwise
ignored. Needs I(git>=1.9.1) to work correctly.
clone:
required: false
default: "yes"
choices: [ "yes", "no" ]
version_added: "1.9"
description:
- If C(no), do not clone the repository if it does not exist locally
update:
required: false
default: "yes"
choices: [ "yes", "no" ]
version_added: "1.2"
description:
- If C(no), do not retrieve new revisions from the origin repository
executable:
required: false
default: null
version_added: "1.4"
description:
- Path to git executable to use. If not supplied,
the normal mechanism for resolving binary paths will be used.
bare:
required: false
default: "no"
choices: [ "yes", "no" ]
version_added: "1.4"
description:
- if C(yes), repository will be created as a bare repo, otherwise
it will be a standard repo with a workspace.
umask:
required: false
default: null
version_added: "2.2"
description:
- The umask to set before doing any checkouts, or any other
repository maintenance.
recursive:
required: false
default: "yes"
choices: [ "yes", "no" ]
version_added: "1.6"
description:
- if C(no), repository will be cloned without the --recursive
option, skipping sub-modules.
track_submodules:
required: false
default: "no"
choices: ["yes", "no"]
version_added: "1.8"
description:
- if C(yes), submodules will track the latest commit on their
master branch (or other branch specified in .gitmodules). If
C(no), submodules will be kept at the revision specified by the
main project. This is equivalent to specifying the --remote flag
to git submodule update.
verify_commit:
required: false
default: "no"
choices: ["yes", "no"]
version_added: "2.0"
description:
- if C(yes), when cloning or checking out a C(version) verify the
signature of a GPG signed commit. This requires C(git) version>=2.1.0
to be installed. The commit MUST be signed and the public key MUST
be trusted in the GPG trustdb.
requirements:
- git>=1.7.1 (the command line tool)
notes:
- "If the task seems to be hanging, first verify remote host is in C(known_hosts).
SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt,
one solution is to use the option accept_hostkey. Another solution is to
add the remote host public key in C(/etc/ssh/ssh_known_hosts) before calling
the git module, with the following command: ssh-keyscan -H remote_host.com >> /etc/ssh/ssh_known_hosts."
'''
EXAMPLES = '''
# Example git checkout from Ansible Playbooks
- git:
repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout
version: release-0.22
# Example read-write git checkout from github
- git:
repo: ssh://git@github.com/mylogin/hello.git
dest: /home/mylogin/hello
# Example just ensuring the repo checkout exists
- git:
repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout
update: no
# Example just get information about the repository whether or not it has
# already been cloned locally.
- git:
repo: 'https://foosball.example.org/path/to/repo.git'
dest: /srv/checkout
clone: no
update: no
# Example checkout a github repo and use refspec to fetch all pull requests
- git:
repo: https://github.com/ansible/ansible-examples.git
dest: /src/ansible-examples
refspec: '+refs/pull/*:refs/heads/*'
'''
RETURN = '''
after:
description: last commit revision of the repository retrived during the update
returned: success
type: string
sample: 4c020102a9cd6fe908c9a4a326a38f972f63a903
before:
description: commit revision before the repository was updated, "null" for new repository
returned: success
type: string
sample: 67c04ebe40a003bda0efb34eacfb93b0cafdf628
remote_url_changed:
description: Contains True or False whether or not the remote URL was changed.
returned: success
type: boolean
sample: True
warnings:
description: List of warnings if requested features were not available due to a too old git version.
returned: error
type: string
sample: Your git version is too old to fully support the depth argument. Falling back to full checkouts.
'''
import os
import re
import shlex
import stat
import sys
import tempfile
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule, get_module_path
from ansible.module_utils.known_hosts import add_git_host_key
from ansible.module_utils.six import b, string_types
from ansible.module_utils._text import to_native
def head_splitter(headfile, remote, module=None, fail_on_error=False):
'''Extract the head reference'''
# https://github.com/ansible/ansible-modules-core/pull/907
res = None
if os.path.exists(headfile):
rawdata = None
try:
f = open(headfile, 'r')
rawdata = f.readline()
f.close()
except:
if fail_on_error and module:
module.fail_json(msg="Unable to read %s" % headfile)
if rawdata:
try:
rawdata = rawdata.replace('refs/remotes/%s' % remote, '', 1)
refparts = rawdata.split(' ')
newref = refparts[-1]
nrefparts = newref.split('/',2)
res = nrefparts[-1].rstrip('\n')
except:
if fail_on_error and module:
module.fail_json(msg="Unable to split head from '%s'" % rawdata)
return res
def unfrackgitpath(path):
if path is None:
return None
# copied from ansible.utils.path
return os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(path))))
def get_submodule_update_params(module, git_path, cwd):
#or: git submodule [--quiet] update [--init] [-N|--no-fetch]
#[-f|--force] [--rebase] [--reference <repository>] [--merge]
#[--recursive] [--] [<path>...]
params = []
# run a bad submodule command to get valid params
cmd = "%s submodule update --help" % (git_path)
rc, stdout, stderr = module.run_command(cmd, cwd=cwd)
lines = stderr.split('\n')
update_line = None
for line in lines:
if 'git submodule [--quiet] update ' in line:
update_line = line
if update_line:
update_line = update_line.replace('[','')
update_line = update_line.replace(']','')
update_line = update_line.replace('|',' ')
parts = shlex.split(update_line)
for part in parts:
if part.startswith('--'):
part = part.replace('--', '')
params.append(part)
return params
def write_ssh_wrapper():
module_dir = get_module_path()
try:
# make sure we have full permission to the module_dir, which
# may not be the case if we're sudo'ing to a non-root user
if os.access(module_dir, os.W_OK|os.R_OK|os.X_OK):
fd, wrapper_path = tempfile.mkstemp(prefix=module_dir + '/')
else:
raise OSError
except (IOError, OSError):
fd, wrapper_path = tempfile.mkstemp()
fh = os.fdopen(fd, 'w+b')
template = b("""#!/bin/sh
if [ -z "$GIT_SSH_OPTS" ]; then
BASEOPTS=""
else
BASEOPTS=$GIT_SSH_OPTS
fi
if [ -z "$GIT_KEY" ]; then
ssh $BASEOPTS "$@"
else
ssh -i "$GIT_KEY" -o IdentitiesOnly=yes $BASEOPTS "$@"
fi
""")
fh.write(template)
fh.close()
st = os.stat(wrapper_path)
os.chmod(wrapper_path, st.st_mode | stat.S_IEXEC)
return wrapper_path
def set_git_ssh(ssh_wrapper, key_file, ssh_opts):
if os.environ.get("GIT_SSH"):
del os.environ["GIT_SSH"]
os.environ["GIT_SSH"] = ssh_wrapper
if os.environ.get("GIT_KEY"):
del os.environ["GIT_KEY"]
if key_file:
os.environ["GIT_KEY"] = key_file
if os.environ.get("GIT_SSH_OPTS"):
del os.environ["GIT_SSH_OPTS"]
if ssh_opts:
os.environ["GIT_SSH_OPTS"] = ssh_opts
def get_version(module, git_path, dest, ref="HEAD"):
''' samples the version of the git repo '''
cmd = "%s rev-parse %s" % (git_path, ref)
rc, stdout, stderr = module.run_command(cmd, cwd=dest)
sha = to_native(stdout).rstrip('\n')
return sha
def get_submodule_versions(git_path, module, dest, version='HEAD'):
cmd = [git_path, 'submodule', 'foreach', git_path, 'rev-parse', version]
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg='Unable to determine hashes of submodules', stdout=out, stderr=err, rc=rc)
submodules = {}
subm_name = None
for line in out.splitlines():
if line.startswith("Entering '"):
subm_name = line[10:-1]
elif len(line.strip()) == 40:
if subm_name is None:
module.fail_json()
submodules[subm_name] = line.strip()
subm_name = None
else:
module.fail_json(msg='Unable to parse submodule hash line: %s' % line.strip())
if subm_name is not None:
module.fail_json(msg='Unable to find hash for submodule: %s' % subm_name)
return submodules
def clone(git_path, module, repo, dest, remote, depth, version, bare,
reference, refspec, verify_commit):
''' makes a new git repo if it does not already exist '''
dest_dirname = os.path.dirname(dest)
try:
os.makedirs(dest_dirname)
except:
pass
cmd = [ git_path, 'clone' ]
if bare:
cmd.append('--bare')
else:
cmd.extend([ '--origin', remote ])
if depth:
if version == 'HEAD' or refspec:
cmd.extend([ '--depth', str(depth) ])
elif is_remote_branch(git_path, module, dest, repo, version) \
or is_remote_tag(git_path, module, dest, repo, version):
cmd.extend([ '--depth', str(depth) ])
cmd.extend(['--branch', version])
else:
# only use depth if the remote object is branch or tag (i.e. fetchable)
module.warn("Ignoring depth argument. "
"Shallow clones are only available for "
"HEAD, branches, tags or in combination with refspec.")
if reference:
cmd.extend([ '--reference', str(reference) ])
cmd.extend([ repo, dest ])
module.run_command(cmd, check_rc=True, cwd=dest_dirname)
if bare:
if remote != 'origin':
module.run_command([git_path, 'remote', 'add', remote, repo], check_rc=True, cwd=dest)
if refspec:
cmd = [git_path, 'fetch']
if depth:
cmd.extend([ '--depth', str(depth) ])
cmd.extend([remote, refspec])
module.run_command(cmd, check_rc=True, cwd=dest)
if verify_commit:
verify_commit_sign(git_path, module, dest, version)
def has_local_mods(module, git_path, dest, bare):
if bare:
return False
cmd = "%s status --porcelain" % (git_path)
rc, stdout, stderr = module.run_command(cmd, cwd=dest)
lines = stdout.splitlines()
lines = list(filter(lambda c: not re.search('^\\?\\?.*$', c), lines))
return len(lines) > 0
def reset(git_path, module, dest):
'''
Resets the index and working tree to HEAD.
Discards any changes to tracked files in working
tree since that commit.
'''
cmd = "%s reset --hard HEAD" % (git_path,)
return module.run_command(cmd, check_rc=True, cwd=dest)
def get_diff(module, git_path, dest, repo, remote, depth, bare, before, after):
''' Return the difference between 2 versions '''
if before is None:
return { 'prepared': '>> Newly checked out %s' % after }
elif before != after:
# Ensure we have the object we are referring to during git diff !
git_version_used = git_version(git_path, module)
fetch(git_path, module, repo, dest, after, remote, depth, bare, '', git_version_used)
cmd = '%s diff %s %s' % (git_path, before, after)
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc == 0 and out:
return { 'prepared': out }
elif rc == 0:
return { 'prepared': '>> No visual differences between %s and %s' % (before, after) }
elif err:
return { 'prepared': '>> Failed to get proper diff between %s and %s:\n>> %s' % (before, after, err) }
else:
return { 'prepared': '>> Failed to get proper diff between %s and %s' % (before, after) }
return {}
def get_remote_head(git_path, module, dest, version, remote, bare):
cloning = False
cwd = None
tag = False
if remote == module.params['repo']:
cloning = True
else:
cwd = dest
if version == 'HEAD':
if cloning:
# cloning the repo, just get the remote's HEAD version
cmd = '%s ls-remote %s -h HEAD' % (git_path, remote)
else:
head_branch = get_head_branch(git_path, module, dest, remote, bare)
cmd = '%s ls-remote %s -h refs/heads/%s' % (git_path, remote, head_branch)
elif is_remote_branch(git_path, module, dest, remote, version):
cmd = '%s ls-remote %s -h refs/heads/%s' % (git_path, remote, version)
elif is_remote_tag(git_path, module, dest, remote, version):
tag = True
cmd = '%s ls-remote %s -t refs/tags/%s*' % (git_path, remote, version)
else:
# appears to be a sha1. return as-is since it appears
# cannot check for a specific sha1 on remote
return version
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=cwd)
if len(out) < 1:
module.fail_json(msg="Could not determine remote revision for %s" % version, stdout=out, stderr=err, rc=rc)
out = to_native(out)
if tag:
# Find the dereferenced tag if this is an annotated tag.
for tag in out.split('\n'):
if tag.endswith(version + '^{}'):
out = tag
break
elif tag.endswith(version):
out = tag
rev = out.split()[0]
return rev
def is_remote_tag(git_path, module, dest, remote, version):
cmd = '%s ls-remote %s -t refs/tags/%s' % (git_path, remote, version)
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
if to_native(version, errors='surrogate_or_strict') in out:
return True
else:
return False
def get_branches(git_path, module, dest):
branches = []
cmd = '%s branch --no-color -a' % (git_path,)
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg="Could not determine branch data - received %s" % out, stdout=out, stderr=err)
for line in out.split('\n'):
if line.strip():
branches.append(line.strip())
return branches
def get_tags(git_path, module, dest):
tags = []
cmd = '%s tag' % (git_path,)
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg="Could not determine tag data - received %s" % out, stdout=out, stderr=err)
for line in to_native(out).split('\n'):
if line.strip():
tags.append(line.strip())
return tags
def is_remote_branch(git_path, module, dest, remote, version):
cmd = '%s ls-remote %s -h refs/heads/%s' % (git_path, remote, version)
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
if to_native(version, errors='surrogate_or_strict') in out:
return True
else:
return False
def is_local_branch(git_path, module, dest, branch):
branches = get_branches(git_path, module, dest)
lbranch = '%s' % branch
if lbranch in branches:
return True
elif '* %s' % branch in branches:
return True
else:
return False
def is_not_a_branch(git_path, module, dest):
branches = get_branches(git_path, module, dest)
for branch in branches:
if branch.startswith('* ') and ('no branch' in branch or 'detached from' in branch):
return True
return False
def get_head_branch(git_path, module, dest, remote, bare=False):
'''
Determine what branch HEAD is associated with. This is partly
taken from lib/ansible/utils/__init__.py. It finds the correct
path to .git/HEAD and reads from that file the branch that HEAD is
associated with. In the case of a detached HEAD, this will look
up the branch in .git/refs/remotes/<remote>/HEAD.
'''
if bare:
repo_path = dest
else:
repo_path = os.path.join(dest, '.git')
# Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
if os.path.isfile(repo_path):
try:
git_conf = open(repo_path, 'rb')
for line in git_conf:
config_val = line.split(b(':'), 1)
if config_val[0].strip() == b('gitdir'):
gitdir = to_native(config_val[1].strip(), errors='surrogate_or_strict')
break
else:
# No repo path found
return ''
# There is a possibility the .git file to have an absolute path.
if os.path.isabs(gitdir):
repo_path = gitdir
else:
repo_path = os.path.join(repo_path.split('.git')[0], gitdir)
except (IOError, AttributeError):
# No repo path found
return ''
# Read .git/HEAD for the name of the branch.
# If we're in a detached HEAD state, look up the branch associated with
# the remote HEAD in .git/refs/remotes/<remote>/HEAD
headfile = os.path.join(repo_path, "HEAD")
if is_not_a_branch(git_path, module, dest):
headfile = os.path.join(repo_path, 'refs', 'remotes', remote, 'HEAD')
branch = head_splitter(headfile, remote, module=module, fail_on_error=True)
return branch
def get_remote_url(git_path, module, dest, remote):
'''Return URL of remote source for repo.'''
command = [git_path, 'ls-remote', '--get-url', remote]
(rc, out, err) = module.run_command(command, cwd=dest)
if rc != 0:
# There was an issue getting remote URL, most likely
# command is not available in this version of Git.
return None
return to_native(out).rstrip('\n')
def set_remote_url(git_path, module, repo, dest, remote):
''' updates repo from remote sources '''
# Return if remote URL isn't changing.
remote_url = get_remote_url(git_path, module, dest, remote)
if remote_url == repo or unfrackgitpath(remote_url) == unfrackgitpath(repo):
return False
command = [git_path, 'remote', 'set-url', remote, repo]
(rc, out, err) = module.run_command(command, cwd=dest)
if rc != 0:
label = "set a new url %s for %s" % (repo, remote)
module.fail_json(msg="Failed to %s: %s %s" % (label, out, err))
# Return False if remote_url is None to maintain previous behavior
# for Git versions prior to 1.7.5 that lack required functionality.
return remote_url is not None
def fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used):
''' updates repo from remote sources '''
set_remote_url(git_path, module, repo, dest, remote)
commands = []
fetch_str = 'download remote objects and refs'
fetch_cmd = [git_path, 'fetch']
refspecs = []
if depth:
# try to find the minimal set of refs we need to fetch to get a
# successful checkout
currenthead = get_head_branch(git_path, module, dest, remote)
if refspec:
refspecs.append(refspec)
elif version == 'HEAD':
refspecs.append(currenthead)
elif is_remote_branch(git_path, module, dest, repo, version):
if currenthead != version:
# this workaround is only needed for older git versions
# 1.8.3 is broken, 1.9.x works
# ensure that remote branch is available as both local and remote ref
refspecs.append('+refs/heads/%s:refs/heads/%s' % (version, version))
refspecs.append('+refs/heads/%s:refs/remotes/%s/%s' % (version, remote, version))
else:
refspecs.append(version)
elif is_remote_tag(git_path, module, dest, repo, version):
refspecs.append('+refs/tags/'+version+':refs/tags/'+version)
if refspecs:
# if refspecs is empty, i.e. version is neither heads nor tags
# assume it is a version hash
# fall back to a full clone, otherwise we might not be able to checkout
# version
fetch_cmd.extend(['--depth', str(depth)])
if not depth or not refspecs:
# don't try to be minimalistic but do a full clone
# also do this if depth is given, but version is something that can't be fetched directly
if bare:
refspecs = ['+refs/heads/*:refs/heads/*', '+refs/tags/*:refs/tags/*']
else:
# ensure all tags are fetched
if git_version_used >= LooseVersion('1.9'):
fetch_cmd.append('--tags')
else:
# old git versions have a bug in --tags that prevents updating existing tags
commands.append((fetch_str, fetch_cmd + [remote]))
refspecs = ['+refs/tags/*:refs/tags/*']
if refspec:
refspecs.append(refspec)
fetch_cmd.extend([remote])
commands.append((fetch_str, fetch_cmd + refspecs))
for (label,command) in commands:
(rc,out,err) = module.run_command(command, cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to %s: %s %s" % (label, out, err), cmd=command)
def submodules_fetch(git_path, module, remote, track_submodules, dest):
changed = False
if not os.path.exists(os.path.join(dest, '.gitmodules')):
# no submodules
return changed
gitmodules_file = open(os.path.join(dest, '.gitmodules'), 'r')
for line in gitmodules_file:
# Check for new submodules
if not changed and line.strip().startswith('path'):
path = line.split('=', 1)[1].strip()
# Check that dest/path/.git exists
if not os.path.exists(os.path.join(dest, path, '.git')):
changed = True
# add the submodule repo's hostkey
if line.strip().startswith('url'):
repo = line.split('=', 1)[1].strip()
if module.params['ssh_opts'] is not None:
if "-o StrictHostKeyChecking=no" not in module.params['ssh_opts']:
add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey'])
else:
add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey'])
# Check for updates to existing modules
if not changed:
# Fetch updates
begin = get_submodule_versions(git_path, module, dest)
cmd = [git_path, 'submodule', 'foreach', git_path, 'fetch']
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to fetch submodules: %s" % out + err)
if track_submodules:
# Compare against submodule HEAD
### FIXME: determine this from .gitmodules
version = 'master'
after = get_submodule_versions(git_path, module, dest, '%s/%s'
% (remote, version))
if begin != after:
changed = True
else:
# Compare against the superproject's expectation
cmd = [git_path, 'submodule', 'status']
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
if rc != 0:
module.fail_json(msg='Failed to retrieve submodule status: %s' % out + err)
for line in out.splitlines():
if line[0] != ' ':
changed = True
break
return changed
def submodule_update(git_path, module, dest, track_submodules, force=False):
''' init and update any submodules '''
# get the valid submodule params
params = get_submodule_update_params(module, git_path, dest)
# skip submodule commands if .gitmodules is not present
if not os.path.exists(os.path.join(dest, '.gitmodules')):
return (0, '', '')
cmd = [ git_path, 'submodule', 'sync' ]
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
if 'remote' in params and track_submodules:
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ,'--remote' ]
else:
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ]
if force:
cmd.append('--force')
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to init/update submodules: %s" % out + err)
return (rc, out, err)
def set_remote_branch(git_path, module, dest, remote, version, depth):
"""set refs for the remote branch version
This assumes the branch does not yet exist locally and is therefore also not checked out.
Can't use git remote set-branches, as it is not available in git 1.7.1 (centos6)
"""
branchref = "+refs/heads/%s:refs/heads/%s" % (version, version)
branchref += ' +refs/heads/%s:refs/remotes/%s/%s' % (version, remote, version)
cmd = "%s fetch --depth=%s %s %s" % (git_path, depth, remote, branchref)
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to fetch branch from remote: %s" % version, stdout=out, stderr=err, rc=rc)
def switch_version(git_path, module, dest, remote, version, verify_commit, depth):
cmd = ''
if version == 'HEAD':
branch = get_head_branch(git_path, module, dest, remote)
(rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, branch), cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to checkout branch %s" % branch,
stdout=out, stderr=err, rc=rc)
cmd = "%s reset --hard %s --" % (git_path, remote)
else:
# FIXME check for local_branch first, should have been fetched already
if is_remote_branch(git_path, module, dest, remote, version):
if depth and not is_local_branch(git_path, module, dest, version):
# git clone --depth implies --single-branch, which makes
# the checkout fail if the version changes
# fetch the remote branch, to be able to check it out next
set_remote_branch(git_path, module, dest, remote, version, depth)
if not is_local_branch(git_path, module, dest, version):
cmd = "%s checkout --track -b %s %s/%s" % (git_path, version, remote, version)
else:
(rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, version), cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to checkout branch %s" % version,
stdout=out, stderr=err, rc=rc)
cmd = "%s reset --hard %s/%s" % (git_path, remote, version)
else:
cmd = "%s checkout --force %s" % (git_path, version)
(rc, out1, err1) = module.run_command(cmd, cwd=dest)
if rc != 0:
if version != 'HEAD':
module.fail_json(msg="Failed to checkout %s" % (version),
stdout=out1, stderr=err1, rc=rc, cmd=cmd)
else:
module.fail_json(msg="Failed to checkout branch %s" % (branch),
stdout=out1, stderr=err1, rc=rc, cmd=cmd)
if verify_commit:
verify_commit_sign(git_path, module, dest, version)
return (rc, out1, err1)
def verify_commit_sign(git_path, module, dest, version):
if version in get_tags(git_path, module, dest):
git_sub = "verify-tag"
else:
git_sub = "verify-commit"
cmd = "%s %s %s" % (git_path, git_sub, version)
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg='Failed to verify GPG signature of commit/tag "%s"' % version, stdout=out, stderr=err, rc=rc)
return (rc, out, err)
def git_version(git_path, module):
"""return the installed version of git"""
cmd = "%s --version" % git_path
(rc, out, err) = module.run_command(cmd)
if rc != 0:
# one could fail_json here, but the version info is not that important, so let's try to fail only on actual git commands
return None
rematch = re.search('git version (.*)$', to_native(out))
if not rematch:
return None
return LooseVersion(rematch.groups()[0])
# ===========================================
def main():
module = AnsibleModule(
argument_spec = dict(
dest=dict(type='path'),
repo=dict(required=True, aliases=['name']),
version=dict(default='HEAD'),
remote=dict(default='origin'),
refspec=dict(default=None),
reference=dict(default=None),
force=dict(default='no', type='bool'),
depth=dict(default=None, type='int'),
clone=dict(default='yes', type='bool'),
update=dict(default='yes', type='bool'),
verify_commit=dict(default='no', type='bool'),
accept_hostkey=dict(default='no', type='bool'),
key_file=dict(default=None, type='path', required=False),
ssh_opts=dict(default=None, required=False),
executable=dict(default=None, type='path'),
bare=dict(default='no', type='bool'),
recursive=dict(default='yes', type='bool'),
track_submodules=dict(default='no', type='bool'),
umask=dict(default=None, type='raw'),
),
supports_check_mode=True
)
dest = module.params['dest']
repo = module.params['repo']
version = module.params['version']
remote = module.params['remote']
refspec = module.params['refspec']
force = module.params['force']
depth = module.params['depth']
update = module.params['update']
allow_clone = module.params['clone']
bare = module.params['bare']
verify_commit = module.params['verify_commit']
reference = module.params['reference']
git_path = module.params['executable'] or module.get_bin_path('git', True)
key_file = module.params['key_file']
ssh_opts = module.params['ssh_opts']
umask = module.params['umask']
result = dict(changed = False, warnings=list())
# evaluate and set the umask before doing anything else
if umask is not None:
if not isinstance(umask, string_types):
module.fail_json(msg="umask must be defined as a quoted octal integer")
try:
umask = int(umask, 8)
except:
module.fail_json(msg="umask must be an octal integer",
details=str(sys.exc_info()[1]))
os.umask(umask)
# Certain features such as depth require a file:/// protocol for path based urls
# so force a protocol here ...
if repo.startswith('/'):
repo = 'file://' + repo
# We screenscrape a huge amount of git commands so use C locale anytime we
# call run_command()
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
gitconfig = None
if not dest and allow_clone:
module.fail_json(msg="the destination directory must be specified unless clone=no")
elif dest:
dest = os.path.abspath(dest)
if bare:
gitconfig = os.path.join(dest, 'config')
else:
gitconfig = os.path.join(dest, '.git', 'config')
# create a wrapper script and export
# GIT_SSH=<path> as an environment variable
# for git to use the wrapper script
ssh_wrapper = None
if key_file or ssh_opts:
ssh_wrapper = write_ssh_wrapper()
set_git_ssh(ssh_wrapper, key_file, ssh_opts)
module.add_cleanup_file(path=ssh_wrapper)
# add the git repo's hostkey
if module.params['ssh_opts'] is not None:
if "-o StrictHostKeyChecking=no" not in module.params['ssh_opts']:
add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey'])
else:
add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey'])
git_version_used = git_version(git_path, module)
if depth is not None and git_version_used < LooseVersion('1.9.1'):
result['warnings'].append("Your git version is too old to fully support the depth argument. Falling back to full checkouts.")
depth = None
recursive = module.params['recursive']
track_submodules = module.params['track_submodules']
result.update(before=None)
local_mods = False
need_fetch = True
if (dest and not os.path.exists(gitconfig)) or (not dest and not allow_clone):
# if there is no git configuration, do a clone operation unless:
# * the user requested no clone (they just want info)
# * we're doing a check mode test
# In those cases we do an ls-remote
if module.check_mode or not allow_clone:
remote_head = get_remote_head(git_path, module, dest, version, repo, bare)
result.update(changed=True, after=remote_head)
if module._diff:
diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
if diff:
result['diff'] = diff
module.exit_json(**result)
# there's no git config, so clone
clone(git_path, module, repo, dest, remote, depth, version, bare, reference, refspec, verify_commit)
need_fetch = False
elif not update:
# Just return having found a repo already in the dest path
# this does no checking that the repo is the actual repo
# requested.
result['before'] = get_version(module, git_path, dest)
result.update(after=result['before'])
module.exit_json(**result)
else:
# else do a pull
local_mods = has_local_mods(module, git_path, dest, bare)
result['before'] = get_version(module, git_path, dest)
if local_mods:
# failure should happen regardless of check mode
if not force:
module.fail_json(msg="Local modifications exist in repository (force=no).", **result)
# if force and in non-check mode, do a reset
if not module.check_mode:
reset(git_path, module, dest)
result.update(changed=True, msg='Local modifications exist.')
# exit if already at desired sha version
if module.check_mode:
remote_url = get_remote_url(git_path, module, dest, remote)
remote_url_changed = remote_url and remote_url != repo and unfrackgitpath(remote_url) != unfrackgitpath(repo)
else:
remote_url_changed = set_remote_url(git_path, module, repo, dest, remote)
result.update(remote_url_changed=remote_url_changed)
if module.check_mode:
remote_head = get_remote_head(git_path, module, dest, version, remote, bare)
result.update(changed=(result['before'] != remote_head or remote_url_changed), after=remote_head)
# FIXME: This diff should fail since the new remote_head is not fetched yet?!
if module._diff:
diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
if diff:
result['diff'] = diff
module.exit_json(**result)
else:
fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used)
result['after'] = get_version(module, git_path, dest)
# switch to version specified regardless of whether
# we got new revisions from the repository
if not bare:
switch_version(git_path, module, dest, remote, version, verify_commit, depth)
# Deal with submodules
submodules_updated = False
if recursive and not bare:
submodules_updated = submodules_fetch(git_path, module, remote, track_submodules, dest)
if submodules_updated:
result.update(submodules_changed=submodules_updated)
if module.check_mode:
result.update(changed=True, after=remote_head)
module.exit_json(**result)
# Switch to version specified
submodule_update(git_path, module, dest, track_submodules, force=force)
# determine if we changed anything
result['after'] = get_version(module, git_path, dest)
if result['before'] != result['after'] or local_mods or submodules_updated or remote_url_changed:
result.update(changed=True)
if module._diff:
diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
if diff:
result['diff'] = diff
# cleanup the wrapper script
if ssh_wrapper:
try:
os.remove(ssh_wrapper)
except OSError:
# No need to fail if the file already doesn't exist
pass
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6029,
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,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
6135,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
2,
199,
1023,
63,
3270,
26,
298,
16,
14,
16,
14,
17,
2,
199,
3612,
63,
1802,
26,
21588,
3374,
2032,
334,
269,
1584,
9,
687,
6135,
15243,
83,
199,
1802,
26,
272,
446,
14944,
473,
8,
3187,
9,
15243,
83,
402,
23737,
370,
12287,
1584,
503,
2032,
14,
199,
1419,
26,
272,
3831,
26,
267,
1415,
26,
2549,
267,
5481,
26,
359,
536,
1622,
267,
1369,
26,
288,
446,
6135,
12,
12027,
12,
503,
3101,
8,
51,
9,
4113,
2287,
402,
314,
6135,
7611,
14,
272,
2053,
26,
267,
1415,
26,
2549,
267,
1369,
26,
288,
446,
24964,
931,
402,
2382,
314,
7611,
1077,
506,
7923,
734,
370,
14,
1598,
961,
2725,
365,
1415,
12,
7444,
445,
8,
6311,
9,
365,
663,
370,
445,
8,
889,
9,
1598,
961,
1570,
1990,
6326,
315,
1015,
413,
14,
24,
14,
19,
14,
8538,
269,
370,
642,
1015,
12,
1598,
314,
445,
8,
2614,
9,
2725,
1990,
3544,
1415,
14,
272,
1015,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
5211,
2,
267,
1369,
26,
288,
446,
14791,
1015,
402,
314,
7611,
370,
1104,
734,
14,
221,
961,
883,
506,
314,
1598,
314,
8785,
1059,
445,
8,
5211,
395,
282,
5246,
536,
12,
282,
1947,
536,
14,
1598,
2779,
883,
2597,
506,
282,
473,
8,
8461,
13,
17,
9,
2631,
12,
315,
1314,
1930,
445,
8,
1121,
1650,
9,
4839,
1598,
370,
506,
2013,
340,
314,
1627,
6974,
365,
440,
2575,
2808,
14,
272,
4729,
63,
1102,
498,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
340,
445,
8,
5066,
395,
9584,
314,
1591,
498,
367,
314,
3831,
1166,
340,
440,
2575,
1598,
3483,
14,
982,
8635,
63,
3291,
3509,
3905,
79,
23052,
4965,
1197,
14740,
29,
889,
401,
1598,
642,
2725,
365,
5525,
14,
272,
8635,
63,
3291,
26,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
10560,
282,
4975,
2884,
436,
22609,
314,
931,
465,
598,
649,
63,
13716,
1598,
1314,
6135,
2066,
5847,
4440,
370,
4278,
8635,
2368,
14,
1598,
1626,
2893,
574,
4293,
506,
3905,
79,
23052,
4965,
1197,
14740,
29,
889,
2,
272,
790,
63,
493,
26,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
13327,
376,
2716,
5726,
790,
570,
370,
675,
367,
314,
15243,
14,
272,
3659,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
20,
2,
267,
1369,
26,
288,
446,
10944,
7611,
334,
3239,
298,
3187,
7289,
1553,
4443,
2263,
531,
272,
3982,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
6493,
2,
267,
1369,
26,
288,
446,
2812,
402,
314,
3982,
14,
272,
2984,
1650,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
25,
2,
267,
1369,
26,
288,
446,
2654,
376,
4722,
2984,
1650,
370,
506,
19251,
14,
1598,
982,
1015,
365,
663,
370,
282,
473,
8,
8461,
13,
17,
9,
440,
29542,
687,
1263,
5246,
1598,
503,
1947,
12,
642,
945,
1443,
506,
5784,
370,
4165,
314,
2984,
3035,
1598,
314,
473,
8,
8461,
13,
17,
680,
1598,
14911,
314,
2011,
6302,
465,
314,
283,
3187,
5267,
7,
1414,
14,
1598,
1626,
2893,
574,
4293,
506,
298,
7655,
15,
2024,
15,
888,
1674,
272,
3542,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1015,
63,
3270,
26,
298,
16,
14,
23,
2,
267,
1369,
26,
288,
446,
982,
445,
8,
5066,
395,
1263,
6042,
1584,
315,
314,
6449,
1598,
7611,
911,
506,
22002,
14,
221,
8538,
269,
370,
378,
14,
23,
12,
642,
1990,
3544,
1598,
283,
5066,
7,
436,
4293,
440,
506,
6980,
14,
221,
8538,
269,
370,
413,
14,
25,
12,
314,
849,
1990,
1598,
658,
5066,
64,
272,
5818,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
18,
2,
267,
1369,
26,
288,
446,
2790,
282,
23834,
7289,
543,
282,
7994,
17661,
370,
314,
2013,
1598,
1329,
503,
22164,
14,
710,
7481,
3962,
574,
365,
445,
8,
17,
395,
4257,
1598,
5525,
14,
29613,
473,
8,
3187,
8119,
17,
14,
25,
14,
17,
9,
370,
1736,
6657,
14,
272,
7289,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
5066,
2,
267,
3415,
26,
359,
298,
5066
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6029,
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,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
6135,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
2,
199,
1023,
63,
3270,
26,
298,
16,
14,
16,
14,
17,
2,
199,
3612,
63,
1802,
26,
21588,
3374,
2032,
334,
269,
1584,
9,
687,
6135,
15243,
83,
199,
1802,
26,
272,
446,
14944,
473,
8,
3187,
9,
15243,
83,
402,
23737,
370,
12287,
1584,
503,
2032,
14,
199,
1419,
26,
272,
3831,
26,
267,
1415,
26,
2549,
267,
5481,
26,
359,
536,
1622,
267,
1369,
26,
288,
446,
6135,
12,
12027,
12,
503,
3101,
8,
51,
9,
4113,
2287,
402,
314,
6135,
7611,
14,
272,
2053,
26,
267,
1415,
26,
2549,
267,
1369,
26,
288,
446,
24964,
931,
402,
2382,
314,
7611,
1077,
506,
7923,
734,
370,
14,
1598,
961,
2725,
365,
1415,
12,
7444,
445,
8,
6311,
9,
365,
663,
370,
445,
8,
889,
9,
1598,
961,
1570,
1990,
6326,
315,
1015,
413,
14,
24,
14,
19,
14,
8538,
269,
370,
642,
1015,
12,
1598,
314,
445,
8,
2614,
9,
2725,
1990,
3544,
1415,
14,
272,
1015,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
5211,
2,
267,
1369,
26,
288,
446,
14791,
1015,
402,
314,
7611,
370,
1104,
734,
14,
221,
961,
883,
506,
314,
1598,
314,
8785,
1059,
445,
8,
5211,
395,
282,
5246,
536,
12,
282,
1947,
536,
14,
1598,
2779,
883,
2597,
506,
282,
473,
8,
8461,
13,
17,
9,
2631,
12,
315,
1314,
1930,
445,
8,
1121,
1650,
9,
4839,
1598,
370,
506,
2013,
340,
314,
1627,
6974,
365,
440,
2575,
2808,
14,
272,
4729,
63,
1102,
498,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
340,
445,
8,
5066,
395,
9584,
314,
1591,
498,
367,
314,
3831,
1166,
340,
440,
2575,
1598,
3483,
14,
982,
8635,
63,
3291,
3509,
3905,
79,
23052,
4965,
1197,
14740,
29,
889,
401,
1598,
642,
2725,
365,
5525,
14,
272,
8635,
63,
3291,
26,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
10560,
282,
4975,
2884,
436,
22609,
314,
931,
465,
598,
649,
63,
13716,
1598,
1314,
6135,
2066,
5847,
4440,
370,
4278,
8635,
2368,
14,
1598,
1626,
2893,
574,
4293,
506,
3905,
79,
23052,
4965,
1197,
14740,
29,
889,
2,
272,
790,
63,
493,
26,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
267,
1369,
26,
288,
446,
13327,
376,
2716,
5726,
790,
570,
370,
675,
367,
314,
15243,
14,
272,
3659,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
20,
2,
267,
1369,
26,
288,
446,
10944,
7611,
334,
3239,
298,
3187,
7289,
1553,
4443,
2263,
531,
272,
3982,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
6493,
2,
267,
1369,
26,
288,
446,
2812,
402,
314,
3982,
14,
272,
2984,
1650,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
25,
2,
267,
1369,
26,
288,
446,
2654,
376,
4722,
2984,
1650,
370,
506,
19251,
14,
1598,
982,
1015,
365,
663,
370,
282,
473,
8,
8461,
13,
17,
9,
440,
29542,
687,
1263,
5246,
1598,
503,
1947,
12,
642,
945,
1443,
506,
5784,
370,
4165,
314,
2984,
3035,
1598,
314,
473,
8,
8461,
13,
17,
680,
1598,
14911,
314,
2011,
6302,
465,
314,
283,
3187,
5267,
7,
1414,
14,
1598,
1626,
2893,
574,
4293,
506,
298,
7655,
15,
2024,
15,
888,
1674,
272,
3542,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1015,
63,
3270,
26,
298,
16,
14,
23,
2,
267,
1369,
26,
288,
446,
982,
445,
8,
5066,
395,
1263,
6042,
1584,
315,
314,
6449,
1598,
7611,
911,
506,
22002,
14,
221,
8538,
269,
370,
378,
14,
23,
12,
642,
1990,
3544,
1598,
283,
5066,
7,
436,
4293,
440,
506,
6980,
14,
221,
8538,
269,
370,
413,
14,
25,
12,
314,
849,
1990,
1598,
658,
5066,
64,
272,
5818,
26,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
1015,
63,
3270,
26,
298,
17,
14,
18,
2,
267,
1369,
26,
288,
446,
2790,
282,
23834,
7289,
543,
282,
7994,
17661,
370,
314,
2013,
1598,
1329,
503,
22164,
14,
710,
7481,
3962,
574,
365,
445,
8,
17,
395,
4257,
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
] |
jmesteve/asterisk
|
openerp/addons/web/static/lib/py.js/doc/conf.py
|
543
|
7829
|
# -*- coding: utf-8 -*-
#
# py.js documentation build configuration file, created by
# sphinx-quickstart on Sun Sep 9 19:36:23 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.todo']
# 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'py.js'
copyright = u'2012, Xavier Morel'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.6'
# The full version, including alpha/beta/rc tags.
release = '0.6'
# 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 = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# Default sphinx domain
default_domain = 'js'
# 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'
# default code-block highlighting
highlight_language = 'javascript'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'pyjsdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'pyjs.tex', u'py.js Documentation',
u'Xavier Morel', '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', 'pyjs', u'py.js Documentation',
[u'Xavier Morel'], 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', 'pyjs', u'py.js Documentation',
u'Xavier Morel', 'pyjs', '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'
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1134,
14,
3596,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
428,
1545,
221,
1749,
5851,
26,
1344,
26,
1789,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
11396,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
647,
14,
3596,
7,
199,
7307,
275,
399,
7,
7409,
12,
1323,
7194,
281,
16917,
76,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
22,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
22,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
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,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
3758,
15882,
2881,
199,
885,
63,
2261,
275,
283,
3596,
7,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
3,
849,
1233,
13,
1457,
22437,
199,
14337,
63,
3671,
275,
283,
9554,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1134,
14,
3596,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
428,
1545,
221,
1749,
5851,
26,
1344,
26,
1789,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
11396,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
647,
14,
3596,
7,
199,
7307,
275,
399,
7,
7409,
12,
1323,
7194,
281,
16917,
76,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
22,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
22,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
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,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
3758,
15882,
2881,
199,
885,
63,
2261,
275,
283,
3596,
7,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
3,
849,
1233,
13,
1457,
22437,
199,
14337,
63,
3671,
275,
283,
9554,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pombredanne/rekall
|
rekall-core/rekall/plugins/windows/registry/getservicesids.py
|
6
|
2660
|
# Rekall Memory Forensics
# Copyright (C) 2011 Volatile Systems
# Copyright (C) 2011 Jamie Levy (Gleeda) <jamie.levy@gmail.com>
# Copyright 2013 Google Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
@author: Jamie Levy (Gleeda)
@license: GNU General Public License 2.0 or later
@contact: jamie.levy@gmail.com
@organization: Volatile Systems
"""
from rekall import utils
from rekall.plugins.windows.registry import registry
import hashlib
import struct
class GetServiceSids(registry.RegistryPlugin):
"""Get the names of services in the Registry and return Calculated SID"""
__name = "getservicesids"
def createservicesid(self, service_name):
"""Calculate the Service SID."""
# We depend on service name to be a unicode string here.
service_name = utils.SmartUnicode(service_name)
sha = hashlib.sha1(service_name.encode("utf-16-le").upper()).digest()
return 'S-1-5-80-' + '-'.join(
[str(n) for n in struct.unpack("<IIIII", sha)])
def get_service_sids(self):
# Search for the current_control_set in all hives.
for hive_offset in self.hive_offsets:
reg = registry.RegistryHive(
hive_offset=hive_offset, session=self.session)
current_control_set = reg.CurrentControlSet()
# There is no CurrentControlSet in this hive.
if not current_control_set:
continue
# Enumerate the services.
for subkey in current_control_set.open_subkey("services").subkeys():
sid = self.createservicesid(subkey.Name)
yield sid, subkey.Name
def render(self, renderer):
"""output to Service SIDs as a dictionary for future use."""
renderer.table_header([("SID", "sid", "<70"),
("Service Name", "name", "")])
for sid, service in self.get_service_sids():
renderer.table_row(sid, service)
|
gpl-2.0
|
[
3,
799,
22360,
15825,
21684,
78,
17378,
199,
3,
1898,
334,
35,
9,
7760,
16171,
23590,
15285,
199,
3,
1898,
334,
35,
9,
7760,
1603,
455,
1873,
491,
6857,
89,
334,
39,
274,
379,
65,
9,
665,
16997,
1873,
14,
6972,
89,
32,
6799,
14,
957,
30,
199,
3,
1898,
6171,
4475,
3277,
14,
2900,
5924,
5702,
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,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
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,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
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,
3,
199,
199,
624,
199,
32,
2502,
26,
755,
1603,
455,
1873,
491,
6857,
89,
334,
39,
274,
379,
65,
9,
199,
32,
1682,
26,
420,
1664,
1696,
1684,
844,
499,
14,
16,
503,
2945,
199,
32,
7811,
26,
420,
1335,
455,
1873,
14,
6972,
89,
32,
6799,
14,
957,
199,
32,
9071,
26,
16171,
23590,
15285,
199,
624,
199,
199,
504,
295,
22360,
492,
3778,
199,
504,
295,
22360,
14,
5265,
14,
8258,
14,
5189,
492,
7086,
199,
199,
646,
8337,
199,
646,
2702,
421,
199,
533,
2372,
3167,
51,
1580,
8,
5189,
14,
10899,
5061,
304,
272,
408,
1002,
314,
1561,
402,
8500,
315,
314,
20738,
436,
372,
19821,
972,
428,
998,
624,
339,
636,
354,
275,
298,
362,
1364,
338,
795,
2,
339,
347,
1218,
1364,
4148,
8,
277,
12,
2435,
63,
354,
304,
267,
408,
14860,
314,
7591,
428,
998,
1041,
398,
327,
2136,
11687,
641,
2435,
536,
370,
506,
282,
2649,
1059,
2348,
14,
267,
2435,
63,
354,
275,
3778,
14,
29111,
7087,
8,
1364,
63,
354,
9,
398,
7793,
275,
8337,
14,
4835,
17,
8,
1364,
63,
354,
14,
2143,
480,
1624,
13,
975,
13,
274,
3471,
4142,
8801,
5671,
342,
267,
372,
283,
51,
13,
17,
13,
21,
13,
1257,
15668,
435,
2475,
1370,
904,
8,
288,
359,
495,
8,
78,
9,
367,
302,
315,
2702,
14,
5301,
6757,
8921,
30807,
401,
7793,
3948,
339,
347,
664,
63,
1364,
63,
338,
795,
8,
277,
304,
267,
327,
8730,
367,
314,
1453,
63,
2785,
63,
409,
315,
1006,
394,
7602,
14,
267,
367,
29134,
63,
2743,
315,
291,
14,
17230,
63,
14253,
26,
288,
1295,
275,
7086,
14,
10899,
30232,
8,
355,
29134,
63,
2743,
29,
17230,
63,
2743,
12,
2351,
29,
277,
14,
1730,
9,
953,
1453,
63,
2785,
63,
409,
275,
1295,
14,
5639,
3717,
1084,
342,
953,
327,
6006,
365,
949,
9338,
3717,
1084,
315,
642,
29134,
14,
288,
340,
440,
1453,
63,
2785,
63,
409,
26,
355,
1980,
953,
327,
3447,
940,
1866,
314,
8500,
14,
288,
367,
1007,
498,
315,
1453,
63,
2785,
63,
409,
14,
1490,
63,
954,
498,
480,
5950,
3471,
954,
1612,
837,
355,
15764,
275,
291,
14,
981,
1364,
4148,
8,
954,
498,
14,
985,
9,
2234,
1995,
15764,
12,
1007,
498,
14,
985,
339,
347,
3795,
8,
277,
12,
11889,
304,
267,
408,
1199,
370,
7591,
428,
12818,
465,
282,
2600,
367,
6466,
675,
1041,
267,
11889,
14,
1224,
63,
1291,
27187,
19514,
401,
298,
4148,
401,
3886,
2760,
1288,
3044,
1689,
3167,
2812,
401,
298,
354,
401,
6899,
566,
398,
367,
15764,
12,
2435,
315,
291,
14,
362,
63,
1364,
63,
338,
795,
837,
288,
11889,
14,
1224,
63,
1143,
8,
4148,
12,
2435,
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
] |
[
799,
22360,
15825,
21684,
78,
17378,
199,
3,
1898,
334,
35,
9,
7760,
16171,
23590,
15285,
199,
3,
1898,
334,
35,
9,
7760,
1603,
455,
1873,
491,
6857,
89,
334,
39,
274,
379,
65,
9,
665,
16997,
1873,
14,
6972,
89,
32,
6799,
14,
957,
30,
199,
3,
1898,
6171,
4475,
3277,
14,
2900,
5924,
5702,
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,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
199,
3,
2195,
945,
9,
1263,
2945,
1015,
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,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
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,
3,
199,
199,
624,
199,
32,
2502,
26,
755,
1603,
455,
1873,
491,
6857,
89,
334,
39,
274,
379,
65,
9,
199,
32,
1682,
26,
420,
1664,
1696,
1684,
844,
499,
14,
16,
503,
2945,
199,
32,
7811,
26,
420,
1335,
455,
1873,
14,
6972,
89,
32,
6799,
14,
957,
199,
32,
9071,
26,
16171,
23590,
15285,
199,
624,
199,
199,
504,
295,
22360,
492,
3778,
199,
504,
295,
22360,
14,
5265,
14,
8258,
14,
5189,
492,
7086,
199,
199,
646,
8337,
199,
646,
2702,
421,
199,
533,
2372,
3167,
51,
1580,
8,
5189,
14,
10899,
5061,
304,
272,
408,
1002,
314,
1561,
402,
8500,
315,
314,
20738,
436,
372,
19821,
972,
428,
998,
624,
339,
636,
354,
275,
298,
362,
1364,
338,
795,
2,
339,
347,
1218,
1364,
4148,
8,
277,
12,
2435,
63,
354,
304,
267,
408,
14860,
314,
7591,
428,
998,
1041,
398,
327,
2136,
11687,
641,
2435,
536,
370,
506,
282,
2649,
1059,
2348,
14,
267,
2435,
63,
354,
275,
3778,
14,
29111,
7087,
8,
1364,
63,
354,
9,
398,
7793,
275,
8337,
14,
4835,
17,
8,
1364,
63,
354,
14,
2143,
480,
1624,
13,
975,
13,
274,
3471,
4142,
8801,
5671,
342,
267,
372,
283,
51,
13,
17,
13,
21,
13,
1257,
15668,
435,
2475,
1370,
904,
8,
288,
359,
495,
8,
78,
9,
367,
302,
315,
2702,
14,
5301,
6757,
8921,
30807,
401,
7793,
3948,
339,
347,
664,
63,
1364,
63,
338,
795,
8,
277,
304,
267,
327,
8730,
367,
314,
1453,
63,
2785,
63,
409,
315,
1006,
394,
7602,
14,
267,
367,
29134,
63,
2743,
315,
291,
14,
17230,
63,
14253,
26,
288,
1295,
275,
7086,
14,
10899,
30232,
8,
355,
29134,
63,
2743,
29,
17230,
63,
2743,
12,
2351,
29,
277,
14,
1730,
9,
953,
1453,
63,
2785,
63,
409,
275,
1295,
14,
5639,
3717,
1084,
342,
953,
327,
6006,
365,
949,
9338,
3717,
1084,
315,
642,
29134,
14,
288,
340,
440,
1453,
63,
2785,
63,
409,
26,
355,
1980,
953,
327,
3447,
940,
1866,
314,
8500,
14,
288,
367,
1007,
498,
315,
1453,
63,
2785,
63,
409,
14,
1490,
63,
954,
498,
480,
5950,
3471,
954,
1612,
837,
355,
15764,
275,
291,
14,
981,
1364,
4148,
8,
954,
498,
14,
985,
9,
2234,
1995,
15764,
12,
1007,
498,
14,
985,
339,
347,
3795,
8,
277,
12,
11889,
304,
267,
408,
1199,
370,
7591,
428,
12818,
465,
282,
2600,
367,
6466,
675,
1041,
267,
11889,
14,
1224,
63,
1291,
27187,
19514,
401,
298,
4148,
401,
3886,
2760,
1288,
3044,
1689,
3167,
2812,
401,
298,
354,
401,
6899,
566,
398,
367,
15764,
12,
2435,
315,
291,
14,
362,
63,
1364,
63,
338,
795,
837,
288,
11889,
14,
1224,
63,
1143,
8,
4148,
12,
2435,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andreadelrio/bedrock
|
bedrock/grants/grants_db.py
|
43
|
39061
|
# -*- coding: utf-8 -*-
from collections import namedtuple
Grant = namedtuple('Grant', 'url, grantee, location, title, type, total_support, '
'year, description, break_down, urls')
GRANTS = [
Grant(
u'dream-yard',
u'DreamYard Project',
u'United States',
u'Hive Fashion DreamYard Summer Intensive',
u'learning-webmaking',
u'$8,250',
2012,
u'<p> Mozilla provided a grant to <a href="http://www.dreamyard.com/">'
u'DreamYard Arts Center</a> in the Bronx, NY, in conjunction with '
u'<a href="http://explorecreateshare.org/2012/07/20/'
u'next-seasons-hottest-trend-hive-fashion/">Hive Fashion</a>, '
u'to support a DIY Fashion intensive for teens in August 2012.</p>',
u'',
u'',
),
Grant(
u'compumentor',
u'Compumentor',
u'United States',
u'2007 TechSoup Netsquared Conference',
u'free-culture-community',
u'$2,000',
2007,
u'<p>Mozilla contributed to the 2007 TechSoup <a href="http://www.netsquared.org">'
u'Netsquared Conference</a> Innovation Fund to support innovative software applications '
u'created by and for non-profit organizations.</p>',
u'',
u'',
),
Grant(
u'codethink',
u'Codethink Ltd.',
u'United Kingdom',
u'Accessibility Research',
u'open-source-technology',
u'$4,427',
2007,
u'<p>Mozilla made a grant to <a href="http://www.codethink.co.uk/">Codethink Ltd.</a> '
u'to do a feasibility study for migrating the AT-SPI accessibility '
u'interface to use D-Bus.</p>',
u'',
u'',
),
Grant(
u'charles-chen',
u'Charles Chen',
u'United States',
u'Fire Vox',
u'open-source-technology',
u'$11,976',
2007,
u'<p>Mozilla supported the work of Charles Chen to implement ARIA widgets in the '
u'<a href="http://www.accessfirefox.org/Fire_Vox.php">Fire Vox</a> open source '
u'screen reader extension for Firefox.</p>',
u'',
u'',
),
Grant(
u'ariel-rios',
u'Ariel Rios',
u'United States',
u'GNOME Accessibility',
u'open-source-technology',
u'$12,471',
2007,
u'<p>Mozilla supported the work of Ariel Rios to implement the AT-SPI Collection '
u'interface for better Firefox accessibility on Linux.</p>',
u'',
u'',
),
Grant(
u'aapd',
u'American Association of People with Disabilities',
u'United States',
u'AAPD',
u'free-culture-community',
u'$1,000',
2007,
u'<p>Mozilla sponsored the <a href="http://www.aapd.com/">AAPD</a> Leadership Gala '
u'and related activities.</p>',
u'',
u'',
),
Grant(
u'peoples-production-house',
u'People’s Production House',
u'United States',
u'World’s Fair 2.0 Design Intensive Incubator',
u'learning-webmaking',
u'$14,500',
2012,
u'<p>This grant to the <a href="http://peoplesproductionhouse.org/">'
u'People’s Production House</a> supported the implementation of three '
u'design workshops for youth in conjunction with World’s Fair 2.0, a '
u'cell-phone based journalism scavenger hunt that investigates the borough '
u'of Queens’ history - past and present. The final Design Intensive '
u'took place during Maker Faire, and involved youth in the installation of '
u'their work at the New York Hall of Science.</p>',
u'',
u'',
),
Grant(
u'participatory-culture-foundation',
u'Participatory Culture Foundation',
u'United States',
u'NewsHour Open Election 2012',
u'free-culture-community',
u'$266,530.42',
2012,
u'<p>As part of the NewsHour Open Election 2012 project, supported by the '
u'Corporation for Public Broadcasting, and in partnership with PBS NewsHour and '
u'Mozilla, the <a href="http://pculture.org/">Participatory Culture Foundation</a> '
u'has received support to develop crowd-sourcing technologies to enable citizen '
u'volunteers to translate and caption 2012 election coverage into dozens of languages, '
u'as well as for the deaf and hard-of-hearing. These technologies will make election '
u'news, speeches and debates more accessible for diverse audiences, helping to increase '
u'their understanding of, and engagement in, the political process.</p>',
u'',
u'',
),
Grant(
u'global-kids-inc',
u'Global Kids Inc.',
u'United States',
u'PenPal News',
u'learning-webmaking',
u'$15,000',
2012,
u'<p> Mozilla provided a grant to <a href="http://www.globalkids.org/">'
u'Global Kids Inc.</a>, in conjunction with Hive NYC, for the development of '
u'PenPal News software. PenPal News is a web app that uses news as a '
u'conversation-starter to connect middle and high school-aged youth '
u'domestically and internationally.</p>',
u'',
u'',
),
Grant(
u'public_knowledge',
u'Public Knowledge',
u'United States',
u'Public Knowledge',
u'user-sovereignty',
u'$5,000',
2012,
u'<p><a href="http://www.publicknowledge.org/">Public Knowledge</a> preserves the '
u'openness of the Internet and the public’s access to knowledge, promotes creativity '
u'through balanced copyright, and upholds and protects the rights of consumers to use '
u'innovative technology lawfully.</p>',
u'',
u'',
),
Grant(
u'institute_of_play',
u'Institute of Play',
u'United States',
u'Hive Activity Delivery Mechanism',
u'learning-webmaking',
u'$12,604',
2012,
u'<p>This grant to the <a href="http://www.instituteofplay.org/">Institute of Play</a> '
u'provided support for the Hive Activity Delivery Mechanism Project, which seeks to '
u'develop a sharing model for Hive-developed learning activities that represents the '
u'collaboration, experimentation and youth-focus that typifies the '
u'Hive and its members.</p>',
u'',
u'',
),
Grant(
u'cbc',
u'CBC Radio Canada',
u'Canada',
u'Marshall McLuhan Project',
u'free-culture-community',
u'$10,000',
2011,
u'<p>This grant was given to the <a href="http://www.cbc.ca">'
u'Canadian Broadcasting Corporation</a> to support the creation of on-line '
u'content to engage Canadians in the celebration of the 100th anniversary of '
u'the birth of Marshall McLuhan.</p>',
u'',
u'',
),
Grant(
u'big-blue-button',
u'Blindside Networks',
u'Canada',
u'BigBlueButton',
u'open-source-technology',
u'$11,000',
2011,
u'<p><a href="http://www.blindsidenetworks.com/">Blindside Networks</a> '
u'is a company dedicated to helping universities, colleges, and commercial '
u'companies deliver a high-quality learning experience to remote students. '
u'The goal of the BigBlueButton open source project is to enable remote students '
u'to have a high-quality learning experience. This grant supported converting '
u'BigBlueButton 0.8-beta to use popcorn.js, the HTML5 media framework designed '
u'for synchronized playback of media.</p>',
u'',
u'',
),
Grant(
u'depaul-university',
u'DePaul University',
u'United States',
u'Digital Youth Mentor',
u'learning-webmaking',
u'$25,000',
2011,
u'<p>This grant was made to <a href="http://www.depaul.edu">DePaul University</a> '
u'to support the employment of a Digital Youth Mentor.</p>',
u'',
u'',
),
Grant(
u'new-youth-city',
u'New Youth City Learning Network',
u'United States',
u'Hackasaurus',
u'learning-webmaking',
u'$25,000',
2011,
u'<p>This grant to the <a href="http://dmlcentral.net/projects/3658">'
u'New Youth City Learning Network</a> at the Social Science Research Centre '
u'supported the development of Hackasaurus. Hackasaurus is a set of tools that '
u'are under development to help teenagers closely review, remix and redesign '
u'the Web. Hackasaurus was prototyped with youth over the course of several '
u'workshops and jam days in New York and Chicago.</p>',
u'',
u'',
),
Grant(
u'henrik-moltke',
u'Henrik Moltke',
u'Germany',
u'Hyperaudio',
u'free-culture-community',
u'$10,000',
2011,
u'<p>This grant supported the development of a compelling concept and implementation '
u'plan for the <a href="http://www.hyperaudio.org/">Hyperaudio</a> project.</p>',
u'',
u'',
),
Grant(
u'bay-area-video-coalition',
u'Bay Area Video Coalition',
u'United States',
u'Zero Divide/Mozilla Youth Media Project',
u'open-source-technology',
u'$88,500',
2012,
u'<p>The <a href="http://www.bavc.org/">Bay Area Video Coalition (BAVC)</a> '
u'was an implementation partner in the Mozilla Foundation/Zero Divide youth '
u'media project in 2011. They worked together to test software prototypes for '
u'Butter, a user interface for WebMadeMovies; to instruct and lead youth '
u'participants to create 3-4 web-native productions with these tools; and to '
u'create a modular, openly-licensed curriculum to make it easier for people to '
u'create HTML5/open video projects of their own.</p><p>In 2012, Mozilla provided '
u'a grant to BAVC to support the <a href="http://bavc.org/creative_code">'
u'Open Source track at BAVC’s Digital Pathways</a>, as part of a broader partnership '
u'between BAVC and Mozilla to encourage next-generation integrated '
u'learning and career skills.</p>',
{
u'2011': ['Amount: $73,500'],
u'2012': ['Amount: $15,000']
},
u'',
),
Grant(
u'universal-subtitles',
u'Universal Subtitles',
u'United States',
u'Universal Subtitles',
u'free-culture-community',
u'$100,000',
2011,
u'<p>In 2011, Mozilla provided a grant to support the development of '
u'<a href="http://www.universalsubtitles.org">Universal Subtitles</a> '
u'(now known as Amara). Amara gives individuals, communities, and larger '
u'organizations the power to overcome accessibility and language barriers '
u'for online video. The tools are free and open source and make the work of '
u'subtitling and translating video simpler, more appealing, and, most of all, '
u'more collaborative.</p>',
u'',
u'',
),
Grant(
u'adaptive-technology-resource-centre',
u'Adaptive Technology Resource Centre',
u'Canada',
u'Adaptive Technology Resource Centre',
u'open-source-technology',
u'$10,000',
2006,
u'<p>This grant was made to the Adaptive Technology Resource Centre at '
u'the University of Toronto (now the <a href="http://idrc.ocad.ca/">'
u'Inclusive Design Research Centre</a> at the Ontario College of Art and Design). '
u'It enabled the development of an accessible Thunderbird user interface as well as '
u'its adoption through evangelism, mentoring, community-building, and technical '
u'leadership, with a focus on working with the jQuery community to implement ARIA '
u'support in this popular toolkit.</p>',
u'',
u'',
),
Grant(
u'benetech',
u'Benetech',
u'United States',
u'Benetech DAISY Reader for Firefox',
u'free-culture-community',
u'$50,000',
2009,
u'<p>Mozilla provided funding over two years to <a href="http://www.benetech.org/">'
u'Benetech</a>, a corporation dedicated to leveraging technology innovation and '
u'business expertise to solve unmet social needs. This funding supports the development '
u'of an open source, browser-based DAISY reader that enables people with print '
u'disabilities to read accessible text using Firefox.</p>',
{
u'2008': ['Amount: $25,000'],
u'2009': ['Amount: $25,000']
},
u'',
),
Grant(
u'nvda',
u'NV Access',
u'Australia',
u'NVDA Screen Reader',
u'open-source-technology',
u'$135,000',
2010,
u'<p>Mozilla made grants to <a href="http://www.nvaccess.org/">NV Access</a> '
u'from 2007 to 2010 to support the development of '
u'<a href="http://www.nvda-project.org/">NonVisual Desktop Access (NVDA)</a>, '
u'a free and open source screen reader for the Microsoft Windows operating system. '
u'Providing feedback via synthetic speech and Braille, it enables blind or vision '
u'impaired people to access computers running Windows for no more '
u'cost than a sighted person.</p>',
{
u'2007': ['Initial Support: $10,000', 'Support for full time work of James Teh: $80,000'],
u'2009': ['Expanding work: $25,000'],
u'2010': ['Growing influence: $20,000']
},
[
u'http://www.nvda-project.org/blog/'
u'Mozilla_Foundation_grant_allows_for_employment_of_NVDA_full-time_developer',
u'http://www.nvda-project.org/blog/First_Work_on_Web_Access_Grant',
u'http://www.nvda-project.org/blog/NewMozillaGrantFurthersNVDA',
u'http://www.nvda-project.org/blog/NVDAPresentationAtCSUN2009'
]
),
Grant(
u'firebug-accessibility',
u'University of Illinois Urbana-Champaign & The Paciello Group ',
u'United States',
u'Firebug Accessibility',
u'open-source-technology',
u'$120,009',
2010,
u'<p>This grant provided funds to the <a href="http://illinois.edu/">'
u'University of Illinois Urbana-Champaign</a> and '
u'<a href="http://www.paciellogroup.com/">The Paciello Group</a> in 2009 '
u'and 2010 for their joint work on Firebug accessibility. The goal was to '
u'mainstream accessibility for web applications by building accessibility '
u'testing functions and associated test cases into '
u'<a href="http://getfirebug.com/">Firebug</a>, a popular tool used by many '
u'web developers.</p>',
{
u'2009': ['Phase One: $25,000', 'Phase Two: $25,000', 'Phase Three: $25,000'],
u'2010': ['Phase Four: $25,000', 'Phase Five: $20,009']
},
u'',
),
Grant(
u'vquence',
u'Vquence',
u'Australia',
u'Vquence',
u'open-source-technology',
u'$75,000',
2010,
u'<p>In the spring of 2008 Mozilla became concerned about the lack of '
u'support for deaf and blind Firefox users. Mozilla identified '
u'<a href="http://www.gingertech.net/">Dr. Silvia Pfeiffer</a> and her '
u'company Vquence as the best resource for creating a plan for open '
u'video accessibility. By providing grants in 2008, 2009 and 2010, '
u'Mozilla supported the technology that implemented Firefox video '
u'accessibility features, such as text subtitles for the hearing-impaired '
u'and audio descriptions for blind users.</p>',
{
u'2008': ['Amount: $25,000'],
u'2009': ['Amount: $25,000'],
u'2010': ['Amount: $25,000']
},
[
u'http://frankhecker.com/2009/06/30/new-mozilla-accessibility-projects/',
]
),
Grant(
u'web4all',
u'World Wide Web Consortium',
u'UK',
u'Web4All Conference',
u'free-culture-community',
u'$4,000',
2010,
u'<p>Mozilla has sponsored the <a href="http://www.w4a.info/">Web4All Conference</a> '
u'for several years, and has also sponsored several speakers to be able to attend. '
u'The Web4All Conference is an annual cross-disciplinary gathering focused on '
u'Scientific Enquiry, Research, Development and Engineering. Views bridge academia, '
u'commerce and industry, and arguments encompassing a range of beliefs across the '
u'design-accessibility spectrum are presented.</p>',
{
u'2007': ['Amount: $1,000'],
u'2008': ['Amount: $1,000'],
u'2009': ['Amount: $1,000'],
u'2010': ['Amount: $1,000'],
},
u'',
),
Grant(
u'creative-commons',
u'Creative Commons',
u'United States',
u'Creative Commons Pledge',
u'free-culture-community',
u'$300,000',
2010,
u'<p>In December 2007, Mozilla decided to participate in '
u'<a href="http://creativecommons.org/">Creative Commons</a> "5x5 Challenge." '
u'Beginning in 2008, Mozilla pledged $100,000 per year for five years to support '
u'open licensing on the web, developing hybrid organizations, and maturing the '
u'concept of the web as an ecology of shared ideas.</p>',
{
u'2008': ['Amount: $100,000'],
u'2009': ['Amount: $100,000'],
u'2010': ['Amount: $100,000'],
},
u'',
),
Grant(
u'foms',
u'Annodex Association',
u'Australia',
u'Foundations of Open Media Software Workshop',
u'free-culture-community',
u'$15,000',
2009,
u'<p>These grants provided sponsorship for the 2007, 2008 and 2009 '
u'<a href="http://www.foms-workshop.org">Foundations of Open Media Software (FOMS)</a> '
u'workshop in Hobart, Australia. The bulk of these funds were used to cover the travel '
u'expenses of key participants who otherwise would have been unable to attend. '
u'This meeting hosts important discussions on open codecs, HTML specifications, '
u'browsers and hands-on work towards specifications for video in browsers.</p>',
{
u'2007': ['Amount: $5,000'],
u'2008': ['Amount: $5,000'],
u'2009': ['Amount: $5,000']
},
u'',
),
Grant(
u'free-culture-conference',
u'Berkeley Center for Law and Technology',
u'United States',
u'Free Culture Conference',
u'free-culture-community',
u'$5,000',
2008,
u'<p>This grant provided sponsorship for the Free Culture Conference put '
u'on by the <a href="http://www.law.berkeley.edu/bclt.htm">'
u'Berkeley Center for Law and Technology</a>, held October 11 and 12, 2008 '
u'in Berkeley, California. The Free Culture Conference is a yearly touchstone '
u'event for the advancement of free cultures, where members are free to '
u'participate without artificial limits.</p>',
u'',
u'',
),
Grant(
u'fscons',
u'FFKP',
u'Sweden',
u'Free Society Conference and Nordic Summit',
u'free-culture-community',
u'$1,300',
2009,
u'<p>This grant provided sponsorship for the third '
u'<a href="https://fscons.org/2009/">Free Society Conference and '
u'Nordic Summit (FSCONS)</a> held November 13-15, 2009, in Goteborg, Sweden. '
u'FSCONS is jointly organized by Free Software Foundation Europe, '
u'Creative Commons and Wikipedia Sverige.</p>',
u'',
u'',
),
Grant(
u'free-software-foundation',
u'Free Software Foundation',
u'United States',
u'LinuxBIOS Support',
u'free-culture-community',
u'$10,000',
2007,
u'<p>In 2007, Mozilla provided $10,000 to support the LinuxBIOS-related '
u'activities of the <a href="http://www.fsf.org/">Free Software Foundation</a>. '
u'This grant went toward software development, infrastructure and communications. '
u'The Free Software Foundation ported coreboot to the alix.2c3 board, a board '
u'useful in building routers, firewalls, and wifi access points.</p>',
u'',
u'',
),
Grant(
u'gnome',
u'GNOME',
u'United States',
u'GNOME Accessibility',
u'open-source-technology',
u'$48,000',
2010,
u'<p>Mozilla offered grants in support of '
u'<a href="http://projects.gnome.org/outreach/a11y/">GNOME’s Outreach '
u'Program for Accessibility</a>. The <a href="http://www.gnome.org/">'
u'GNOME Foundation</a> sponsors the GNOME project to provide a free desktop '
u'environment for Linux systems. Mozilla and GNOME have been longtime '
u'collaborators on open source and accessibility issues.</p><p>See the '
u'<a href="reports/gnome-haeger-report/">grant final report</a> for more details.</p>',
{
u'2007': ['General Accessibility Support: $10,000'],
u'2008': ['Orca rich document browsing extension: $8,000'],
u'2009': ['GNOME Outreach Program: Accessibility: $10,000', 'CSUN Accessibility Conference: $10,000'],
u'2010': ['General Accessibility Support: $10,000']
},
[
u'https://blog.mozilla.org/blog/2010/02/04/mozilla-gnome-accessibility/',
]
),
Grant(
u'ifosslr',
u'International Free and Open Source Software Law Review (IFOSSLR)',
u'Europe',
u'IFOSSLR Launch',
u'user-sovereignty',
u'$10,000',
2009,
u'<p>This grant funded the launch of the <a href="http://www.ifosslr.org/">'
u'International Free and Open Source Software Law Review (IFOSSLR)</a>, a '
u'collaborative legal publication aiming to increase knowledge and understanding '
u'among lawyers about Free and Open Source Software issues. Topics included copyright, '
u'licence implementation, licence interpretation, software patents, open standards, '
u'case law and statutory changes.</p>',
u'',
u'',
),
Grant(
u'mozdev',
u'MozDev',
u'United States',
u'MozDev Support',
u'open-source-technology',
u'$90,000',
2008,
u'<p>Mozilla supported the <a href="http://www.mozdev.org/about.html">'
u'MozDev Community Organization</a> by providing general funds to support '
u'MozDev’s operations. MozDev is a software development community dedicated '
u'to making quality applications and extensions freely available to all computer '
u'users. Its goal is to help establish Mozilla as a viable application development '
u'platform. Since 2006, Mozilla grants have funded the majority of MozDev’s budget. '
u'This support gives back to the community that contributes so much to establishing '
u'Mozilla as a viable application development platform and the community that builds '
u'quality applications and extensions.</p>',
{
u'2006': ['Amount: $30,000'],
u'2007': ['Amount: $30,000'],
u'2008': ['Amount: $30,000']
},
u'',
),
Grant(
u'nonprofit-software-development-summit',
u'Aspiration',
u'United States',
u'Nonprofit Software Development Summit',
u'free-culture-community',
u'$5,000',
2009,
u'<p>This grant supported the <a href="http://www.aspirationtech.org/events/devsummit09">'
u'Nonprofit Software Development Summit</a>, held November 18-20, 2009 in Oakland. '
u'This was the third annual convening of people and organizations developing software '
u'tools, web applications and other technology to support nonprofits and social '
u'justice causes. <a href="http://www.aspirationtech.org/">Aspiration</a>, '
u'the conference organizer, is a non-profit organization that connects nonprofits '
u'with software solutions that help them better carry out their work.</p>',
u'',
u'',
),
Grant(
u'open-source-software-institute',
u'Open Source Software Institute',
u'United States',
u'OCSP Stapling',
u'open-source-technology',
u'$30,000',
2007,
u'<p>This grant to the <a href="http://www.oss-institute.org/">'
u'Open Source Software Institute</a>, in cooperation with the NSS '
u'development team and Mozilla developers, investigated the problem of '
u'providing OCSP stapling support for Apache and other open source '
u'SSL/TLS-enabled server software incorporating the OpenSSL library. '
u'The Open Source Software Institute (OSSI) was identified as having '
u'extensive experience with OpenSSL, and was the lead organization '
u'responsible for getting US government FIPS 140-2 validation of OpenSSL.</p>',
u'',
u'',
),
Grant(
u'open-video-alliance',
u'Open Video Alliance',
u'United States',
u'Open Video Alliance',
u'free-culture-community',
u'$30,000',
2009,
u'<p>Mozilla offered support to <a href="http://openvideoalliance.org/">'
u'Open Video Alliance</a> activities in support of the open video movement. '
u'Open Video Alliance is a coalition of organizations and individuals committed '
u'to the idea that the power of the moving image should belong to everyone. '
u'This grant funded various efforts in the open video movement, such as the '
u'operations of openvideoalliance.org, the branding of open video products, '
u'outreach to the public media, fundraising and video production.</p>',
u'',
u'',
),
Grant(
u'perl-foundation',
u'Perl Foundation',
u'United States',
u'Perl6 Support',
u'open-source-technology',
u'$10,000',
2007,
u'<p>Mozilla provided a grant to the <a href="http://www.perlfoundation.org/">'
u'Perl Foundation</a>, a non-profit dedicated to the advancement of the Perl '
u'programming language through open discussion, collaboration, design and code. '
u'This grant supported the development of Perl 6.</p>',
u'',
u'',
),
Grant(
u'personal-democracy-forum',
u'Personal Democracy Forum',
u'United States',
u'Personal Democracy Forum',
u'user-sovereignty',
u'$15,000',
2009,
u'<p>For two years Mozilla sponsored the <a href="http://personaldemocracy.com/'
u'pdf-conference/personal-democracy-forum-conference">Personal Democracy Forum</a>, '
u'a forum for discussion on how politics and technology intersect. Each year top '
u'opinion-makers, political practitioners, technologists and journalists come '
u'together to network, exchange ideas and explore how technology and the internet '
u'are changing politics, democracy and society.</p>',
{
u'2008': ['Amount: $10,000'],
u'2009': ['Amount: $5,000']
},
u'',
),
Grant(
u'software-freedom-conservancy',
u'Software Freedom Conservancy',
u'United States',
u'Software Freedom Conservancy',
u'free-culture-community',
u'$30,000',
2012,
u'<p>Mozilla provided funding to help the '
u'<a href="http://conservancy.softwarefreedom.org/">Software Freedom Conservancy</a> '
u'serve additional open source projects and work more closely with peer projects. '
u'As from 2008, Mozilla\'s funding helped the Conservancy to provide administrative, '
u'financial management, coordination and logistical services to twenty FLOSS '
u'(Free, Libre and Open Source Software) projects including Foresight Linux, '
u'Sugar Labs, jQuery, Amarok, Darcs, OpenInkpot, and K-3D.</p>',
{
u'2008': ['Amount: $10,000'],
u'2009': ['Amount: $10,000'],
u'2012': ['Amount: $10,000']
},
u'',
),
Grant(
u'seneca',
u'Seneca College',
u'Canada',
u'Seneca College',
u'learning-webmaking',
u'$327,860',
2011,
u'<p>Since 2005, <a href="http://www.senecac.on.ca/">Seneca College</a> '
u'in Toronto has worked closely with the Mozilla community to create a set '
u'of Mozilla-specific courses, engage hundreds of students directly in Mozilla '
u'development projects, and host and record dozens of Mozilla events and talks. '
u'Seneca’s faculty and students are key contributors to the Mozilla project, '
u'and have gained significant experience bootstrapping new contributors into the '
u'Mozilla technology and culture. Seneca College of Applied Arts and Technology is a '
u'community college for applied arts and technology in Toronto, Ontario. </p>',
{
u'2006': ['Amount: $50,000'],
u'2007': ['Amount: $100,000'],
u'2009': ['Amount: $80,910'],
u'2011': ['Amount: $96,950']
},
u'',
),
Grant(
u'leigh-school',
u'Leigh School',
u'New Zealand',
u'Leigh School',
u'learning-webmaking',
u'$2,500',
2009,
u'<p>This grant is supporting ICT components for courses and the purchase of '
u'equipment and software to support the ICT components of courses at '
u'<a href="http://www.leigh.school.nz/">Leigh School</a>, a primary school in '
u'New Zealand dedicated to a broad curriculum that includes computers and technology.</p>',
u'',
u'',
),
Grant(
u'peer2peer-university',
u'Phillip Schmidt (P2PU)',
u'United States',
u'Peer2Peer University',
u'learning-webmaking',
u'$25,500',
2011,
u'<p>Mozilla issued a grant to Phillip Schmidt in 2009 '
u'(<a href="http://www.p2pu.org/">P2PU</a>) to enable the creation of '
u'an online course called <a href="https://wiki.mozilla.org/Education/EduCourse">'
u'Open|Web|Content|Education</a>, where educators learned about open content licensing, '
u'open web technologies and open teaching methods. In 2011, Mozilla provided a '
u'grant to P2PU to support <a href="https://p2pu.org/en/schools/school-of-webcraft/sets/'
u'webmaking-101/">Webmaking 101</a> and the <a href="https://p2pu.org/en/groups/schools/'
u'school-of-webcraft/">School of Webcraft</a> community coordination.</p><p>P2PU combines '
u'open educational resources, structured courses, and recognition of knowledge and '
u'learning to offer high-quality low-cost education opportunities. It is run and '
u'governed by volunteers.</p>',
{
u'2009': ['Open|Web|Content|Education: $2,500'],
u'2011': ['Webmaking 101 - Project Management & School of Webcraft - Community Coordination: $23,000']
},
u'',
),
Grant(
u'ushaidi-chile',
u'Ushahidi',
u'United States and Chile',
u'Ushahidi Chile',
u'free-culture-community',
u'$10,000',
2010,
u'<p>In a crisis environment, maintaining lines of communication is critically important. '
u'<a href="http://www.ushahidi.com/">Ushahidi</a> developed an open source platform that '
u'enables citizen reporting in crisis situations. A deadly earthquake struck Chile on '
u'February 27, 2010, cutting off many vulnerable people from traditional sources of '
u'information. Mozilla awarded a grant to enable Ushahidi volunteers to train Chilean '
u'civilians and government officials to utilize the Ushahidi platform during the relief '
u'effort.</p><p>See the <a href="reports/ushahidi-chile-report/">final grant report</a> '
u'for more details.</p>',
u'',
[
u'http://blog.ushahidi.com/index.php/2010/03/15/mozilla-foundation-supports-ushahidi-chile/',
]
),
Grant(
u'atlan',
u'Atlan Laboratories',
u'United States',
u'FIPS 140-2 Validation',
u'open-source-technology',
u'$25,000',
2008,
u'<p>This grant to Atlan Labs, along with funding from Red Hat and Sun Microsystems, '
u'supported FIPS 140-2 validation for the latest version of Network Security Services '
u'(NSS). Federal Information Processing Standards Publications (FIPS PUBS) '
u'140-1 and 140-2 are US government standards for implementations of cryptographic '
u'modules - that is, hardware or software that encrypts and decrypts data or '
u'performs other cryptographic operations. Atlan Labs was a a cybersecurity '
u'product testing firm based in McLean, Virginia that provided Federal Information '
u'Processing Standard (FIPS) 140-2 and 201 validations. Atlan was acquired by '
u'<a href="http://www.saic.com/infosec/testing-accreditation/">SAIC</a> in July 2009.</p>',
u'',
u'',
),
Grant(
u'automated-calendar-testing',
u'Merike Sell',
u'Estonia',
u'Calendar Automated Testing',
u'open-source-technology',
u'$4,500',
2009,
u'<p>This grant is funding the development of calendar automated testing for the '
u'Mozilla calendar code. This was originally an idea presented at the 2009 '
u'Google Summer of Code, and Mozilla Calendar developers became interested in '
u'funding technology that would enable automated testing. Merike Sell is an active '
u'member of the Mozilla developer and localization communites who live in Estonia.</p>',
u'',
u'',
),
Grant(
u'w3c-validator',
u'World Wide Web Consortium',
u'International',
u'W3C Validator',
u'open-source-technology',
u'$15,000',
2009,
u'<p>The Mozilla Foundation is a member of the <a href="http://www.w3.org/">'
u'World Wide Web Consortium</a>, and various Mozilla people represent Mozilla in '
u'W3C working groups and other W3C contexts. This grant was issued beyond Mozilla’s '
u'existing W3C membership dues, and funded work on '
u'<a href="http://jigsaw.w3.org/css-validator/">W3C CSS Validator</a> by giving to '
u'ERCIM, the W3C’s donation program.</p>',
u'',
u'',
),
Grant(
u'jambu',
u'Jambu',
u'United States',
u'Jambu',
u'open-source-technology',
u'$25,000',
2007,
u'<p><a href="www.oatsoft.org/Software/jambu">Jambu</a> is a pointer and switch '
u'project that improves accessibility for people with physical disabilities. '
u'This grant supported the improvement of switch access to Firefox on Windows, '
u'with the greater goal of providing transparent alternative input access to computers. '
u'Users served by this project may include adults who have experienced a debilitating '
u'accident or stroke, people with congential physical disabilities, children with '
u'multiple disabilities, and those with learning difficulties or limited education '
u'who often need to learn to use a switch through specialist educational programs.</p>',
{
u'2006': ['Phase 1: $15,000'],
u'2007': ['Phase 2: $10,000'],
},
u'',
),
Grant(
u'nu',
u'Northeastern University',
u'United States',
u'Graduate-level work of PhD students at Northeastern University',
u'open-source-technology',
u'$283,085',
2010,
u'<p>Since 2009 Mozilla has supported the graduate-level work of PhD students at '
u'<a href="http://www.ccs.neu.edu/">Northeastern University</a>, developing new tools '
u'for the standardization, streamlining, and testing of JavaScript. In 2009 Mozilla '
u'contributed $99,115 to the research efforts of '
u'<a href="http://www.ccs.neu.edu/home/samth/">Sam Tobin-Hochstadt</a>. In 2010 '
u'Mozilla made two gifts: one of $107,596 to further support Mr. Tobin-Hochstadt’s '
u'research and another gift of $76,374 to <a href="http://www.ccs.neu.edu/home/dimvar/">'
u'Demetrios Vardoulakis</a>.</p>',
{
u'2009': ['PhD Research of Sam Tobin-Hochstadt: $99,115'],
u'2010': ['PhD research of Sam Tobin-Hochstadt and Demetrios Vardoulakis: $107,596 and $76,374']
},
u'',
),
Grant(
u'owasp',
u'OWASP',
u'United States',
u'The Open Web Application Security Project',
u'open-source-technology',
u'$15,000',
2010,
u'<p>This grant supports the <a href="http://www.owasp.org/index.php/Main_Page">'
u'Open Web Application Security Project</a>, which focuses on improving the security '
u'of application software. OWASP\'s mission is to make application security visible, '
u'so that people and organizations can make informed decisions about true '
u'application security risks.</p>',
u'',
u'',
),
Grant(
u'webaim',
u'WebAIM',
u'United States',
u'WebAIM',
u'open-source-technology',
u'$15,000',
2006,
u'<p>In 2006, Mozilla provided a grant to <a href="http://webaim.org/">WebAIM</a>, '
u'an accessibility organization based at Utah State University, to develop XUL '
u'accessibility guidelines and an accompanying evaluation tool. WebAIM has provided '
u'comprehensive web accessibility solutions since 1999. These years of experience '
u'have made WebAIM one of the leading providers of web accessibility expertise '
u'internationally. WebAIM is a non-profit organization within the Center for '
u'Persons with Disabilities at Utah State University.</p>',
u'',
u'',
),
]
|
mpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
5055,
492,
12863,
199,
199,
39,
17633,
275,
12863,
360,
39,
17633,
297,
283,
633,
12,
9202,
15557,
12,
2909,
12,
2538,
12,
730,
12,
3141,
63,
4058,
12,
283,
1169,
283,
3403,
12,
1369,
12,
2059,
63,
2110,
12,
8187,
358,
199,
199,
3975,
1441,
51,
275,
359,
272,
598,
17633,
8,
267,
399,
5121,
1091,
13,
89,
1005,
297,
267,
399,
7,
36,
1091,
57,
1005,
7290,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
30232,
481,
29059,
577,
1091,
57,
1005,
12094,
2626,
1010,
724,
3398,
297,
267,
399,
7,
10546,
13,
2520,
391,
17443,
297,
267,
399,
7,
4,
24,
12,
7991,
297,
267,
6029,
12,
267,
399,
7601,
80,
30,
17728,
2741,
282,
16085,
370,
665,
65,
4369,
628,
1014,
921,
1544,
14,
68,
1091,
89,
1005,
14,
957,
15,
15603,
267,
399,
7,
36,
1091,
57,
1005,
1952,
1086,
24699,
1108,
65,
30,
315,
314,
699,
2641,
88,
12,
653,
57,
12,
315,
22888,
543,
283,
267,
399,
7601,
65,
4369,
628,
1014,
921,
16971,
264,
981,
6251,
14,
1308,
15,
7409,
15,
1780,
15,
1165,
4805,
267,
399,
7,
2184,
13,
12605,
83,
13,
8885,
396,
13,
84,
16479,
13,
17230,
13,
70,
29059,
26049,
30232,
481,
29059,
1108,
65,
6244,
283,
267,
399,
1133,
79,
2291,
282,
5266,
57,
481,
29059,
315,
724,
3398,
367,
1565,
8764,
315,
25298,
833,
6029,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
863,
760,
269,
297,
267,
399,
7,
2404,
760,
269,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
9488,
5773,
335,
12341,
5365,
12973,
1448,
1769,
297,
267,
399,
7,
4624,
13,
67,
427,
608,
13,
9387,
297,
267,
399,
7,
4,
18,
12,
1493,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
406,
24855,
370,
314,
10219,
5773,
335,
12341,
665,
65,
4369,
628,
1014,
921,
1544,
14,
846,
12973,
14,
1308,
15603,
267,
399,
7,
2480,
12973,
1448,
1769,
1108,
65,
30,
1010,
889,
4255,
481,
725,
370,
2291,
315,
30442,
1905,
2032,
13103,
283,
267,
399,
7,
3966,
701,
436,
367,
2222,
13,
496,
3269,
20765,
12270,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
600,
29727,
297,
267,
399,
7,
3034,
29727,
12126,
3130,
267,
399,
7,
1358,
5703,
1804,
316,
4556,
297,
267,
399,
7,
1945,
823,
4783,
26993,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
20,
12,
27358,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
6326,
282,
16085,
370,
665,
65,
4369,
628,
1014,
921,
1544,
14,
600,
29727,
14,
331,
14,
3210,
26049,
3034,
29727,
12126,
9758,
65,
30,
283,
267,
399,
1133,
79,
886,
282,
1964,
305,
29524,
25932,
367,
3952,
10417,
314,
15059,
13,
20495,
1066,
823,
4783,
283,
267,
399,
7,
3266,
370,
675,
577,
13,
12106,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
1560,
2978,
13,
24604,
297,
267,
399,
7,
1610,
2978,
2799,
287,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
13081,
812,
19131,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
845,
12,
25,
2114,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
3748,
314,
1736,
402,
6659,
2978,
2799,
287,
370,
5669,
4160,
13033,
11114,
315,
314,
283,
267,
399,
7601,
65,
4369,
628,
1014,
921,
1544,
14,
2732,
15394,
14,
1308,
15,
13081,
63,
54,
19131,
14,
8624,
1743,
13081,
812,
19131,
1108,
65,
30,
1551,
1350,
283,
267,
399,
1159,
4463,
7002,
3329,
367,
24584,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
759,
352,
13,
322,
736,
297,
267,
399,
7,
26291,
352,
820,
9207,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
39,
2826,
3635,
4473,
823,
4783,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
713,
12,
26012,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
3748,
314,
1736,
402,
31153,
352,
820,
9207,
370,
5669,
314,
15059,
13,
20495,
18003,
283,
267,
399,
7,
3266,
367,
8034,
24584,
1066,
823,
4783,
641,
10130,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
65,
439,
68,
297,
267,
399,
7,
33,
278,
28775,
24207,
425,
402,
11379,
7939,
543,
5289,
5807,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
33,
1282,
36,
297,
267,
399,
7,
4624,
13,
67,
427,
608,
13,
9387,
297,
267,
399,
7,
4,
17,
12,
1493,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
308,
678,
1152,
581,
314,
665,
65,
4369,
628,
1014,
921,
1544,
14,
65,
439,
68,
14,
957,
26049,
33,
1282,
36,
1108,
65,
30,
7005,
669,
3319,
598,
14774,
283,
267,
399,
7,
460,
4048,
30744,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
321,
411,
2978,
13,
10777,
13,
6740,
297,
267,
399,
7,
8070,
7939,
21045,
83,
24114,
869,
7130,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
15943,
21045,
83,
481,
8387,
499,
14,
16,
29410,
1010,
724,
3398,
3277,
456,
707,
297,
267,
399,
7,
10546,
13,
2520,
391,
17443,
297,
267,
399,
7,
4,
1079,
12,
5783,
297,
267,
6029,
12,
267,
399,
7601,
80,
30,
2765,
16085,
370,
314,
665,
65,
4369,
628,
1014,
921,
321,
411,
2978,
10777,
6740,
14,
1308,
15,
15603,
267,
399,
7,
8070,
7939,
21045,
83,
24114,
869,
7130,
1108,
65,
30,
3748,
314,
4514,
402,
7795,
283,
267,
399,
5121,
69,
1037,
1736,
609,
1483,
367,
612,
79,
762,
315,
22888,
543,
13064,
21045,
83,
481,
8387,
499,
14,
16,
12,
282,
283,
267,
399,
7,
3890,
13,
9339,
4079,
9605,
19185,
12328,
1856,
836,
394,
638,
626,
315,
27174,
2335,
314,
330
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
5055,
492,
12863,
199,
199,
39,
17633,
275,
12863,
360,
39,
17633,
297,
283,
633,
12,
9202,
15557,
12,
2909,
12,
2538,
12,
730,
12,
3141,
63,
4058,
12,
283,
1169,
283,
3403,
12,
1369,
12,
2059,
63,
2110,
12,
8187,
358,
199,
199,
3975,
1441,
51,
275,
359,
272,
598,
17633,
8,
267,
399,
5121,
1091,
13,
89,
1005,
297,
267,
399,
7,
36,
1091,
57,
1005,
7290,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
30232,
481,
29059,
577,
1091,
57,
1005,
12094,
2626,
1010,
724,
3398,
297,
267,
399,
7,
10546,
13,
2520,
391,
17443,
297,
267,
399,
7,
4,
24,
12,
7991,
297,
267,
6029,
12,
267,
399,
7601,
80,
30,
17728,
2741,
282,
16085,
370,
665,
65,
4369,
628,
1014,
921,
1544,
14,
68,
1091,
89,
1005,
14,
957,
15,
15603,
267,
399,
7,
36,
1091,
57,
1005,
1952,
1086,
24699,
1108,
65,
30,
315,
314,
699,
2641,
88,
12,
653,
57,
12,
315,
22888,
543,
283,
267,
399,
7601,
65,
4369,
628,
1014,
921,
16971,
264,
981,
6251,
14,
1308,
15,
7409,
15,
1780,
15,
1165,
4805,
267,
399,
7,
2184,
13,
12605,
83,
13,
8885,
396,
13,
84,
16479,
13,
17230,
13,
70,
29059,
26049,
30232,
481,
29059,
1108,
65,
6244,
283,
267,
399,
1133,
79,
2291,
282,
5266,
57,
481,
29059,
315,
724,
3398,
367,
1565,
8764,
315,
25298,
833,
6029,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
863,
760,
269,
297,
267,
399,
7,
2404,
760,
269,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
9488,
5773,
335,
12341,
5365,
12973,
1448,
1769,
297,
267,
399,
7,
4624,
13,
67,
427,
608,
13,
9387,
297,
267,
399,
7,
4,
18,
12,
1493,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
406,
24855,
370,
314,
10219,
5773,
335,
12341,
665,
65,
4369,
628,
1014,
921,
1544,
14,
846,
12973,
14,
1308,
15603,
267,
399,
7,
2480,
12973,
1448,
1769,
1108,
65,
30,
1010,
889,
4255,
481,
725,
370,
2291,
315,
30442,
1905,
2032,
13103,
283,
267,
399,
7,
3966,
701,
436,
367,
2222,
13,
496,
3269,
20765,
12270,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
600,
29727,
297,
267,
399,
7,
3034,
29727,
12126,
3130,
267,
399,
7,
1358,
5703,
1804,
316,
4556,
297,
267,
399,
7,
1945,
823,
4783,
26993,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
20,
12,
27358,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
6326,
282,
16085,
370,
665,
65,
4369,
628,
1014,
921,
1544,
14,
600,
29727,
14,
331,
14,
3210,
26049,
3034,
29727,
12126,
9758,
65,
30,
283,
267,
399,
1133,
79,
886,
282,
1964,
305,
29524,
25932,
367,
3952,
10417,
314,
15059,
13,
20495,
1066,
823,
4783,
283,
267,
399,
7,
3266,
370,
675,
577,
13,
12106,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
1560,
2978,
13,
24604,
297,
267,
399,
7,
1610,
2978,
2799,
287,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
13081,
812,
19131,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
845,
12,
25,
2114,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
3748,
314,
1736,
402,
6659,
2978,
2799,
287,
370,
5669,
4160,
13033,
11114,
315,
314,
283,
267,
399,
7601,
65,
4369,
628,
1014,
921,
1544,
14,
2732,
15394,
14,
1308,
15,
13081,
63,
54,
19131,
14,
8624,
1743,
13081,
812,
19131,
1108,
65,
30,
1551,
1350,
283,
267,
399,
1159,
4463,
7002,
3329,
367,
24584,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
759,
352,
13,
322,
736,
297,
267,
399,
7,
26291,
352,
820,
9207,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
39,
2826,
3635,
4473,
823,
4783,
297,
267,
399,
7,
1490,
13,
1365,
13,
266,
24731,
297,
267,
399,
7,
4,
713,
12,
26012,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
3748,
314,
1736,
402,
31153,
352,
820,
9207,
370,
5669,
314,
15059,
13,
20495,
18003,
283,
267,
399,
7,
3266,
367,
8034,
24584,
1066,
823,
4783,
641,
10130,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
65,
439,
68,
297,
267,
399,
7,
33,
278,
28775,
24207,
425,
402,
11379,
7939,
543,
5289,
5807,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
33,
1282,
36,
297,
267,
399,
7,
4624,
13,
67,
427,
608,
13,
9387,
297,
267,
399,
7,
4,
17,
12,
1493,
297,
267,
10219,
12,
267,
399,
7601,
80,
30,
22285,
308,
678,
1152,
581,
314,
665,
65,
4369,
628,
1014,
921,
1544,
14,
65,
439,
68,
14,
957,
26049,
33,
1282,
36,
1108,
65,
30,
7005,
669,
3319,
598,
14774,
283,
267,
399,
7,
460,
4048,
30744,
9758,
80,
4206,
267,
399,
6448,
267,
399,
6448,
272,
2318,
272,
598,
17633,
8,
267,
399,
7,
321,
411,
2978,
13,
10777,
13,
6740,
297,
267,
399,
7,
8070,
7939,
21045,
83,
24114,
869,
7130,
297,
267,
399,
7,
1358,
5703,
24230,
297,
267,
399,
7,
15943,
21045,
83,
481,
8387,
499,
14,
16,
29410,
1010,
724,
3398,
3277,
456,
707,
297,
267,
399,
7,
10546,
13,
2520,
391,
17443,
297,
267,
399,
7,
4,
1079,
12,
5783,
297,
267,
6029,
12,
267,
399,
7601,
80,
30,
2765,
16085,
370,
314,
665,
65,
4369,
628,
1014,
921,
321,
411,
2978,
10777,
6740,
14,
1308,
15,
15603,
267,
399,
7,
8070,
7939,
21045,
83,
24114,
869,
7130,
1108,
65,
30,
3748,
314,
4514,
402,
7795,
283,
267,
399,
5121,
69,
1037,
1736,
609,
1483,
367,
612,
79,
762,
315,
22888,
543,
13064,
21045,
83,
481,
8387,
499,
14,
16,
12,
282,
283,
267,
399,
7,
3890,
13,
9339,
4079,
9605,
19185,
12328,
1856,
836,
394,
638,
626,
315,
27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,
1,
1,
1,
1,
1,
1
] |
MER-GROUP/intellij-community
|
python/helpers/pydev/third_party/pep8/lib2to3/lib2to3/fixes/fix_exitfunc.py
|
291
|
2505
|
"""
Convert use of sys.exitfunc to use the atexit module.
"""
# Author: Benjamin Peterson
from lib2to3 import pytree, fixer_base
from lib2to3.fixer_util import Name, Attr, Call, Comma, Newline, syms
class FixExitfunc(fixer_base.BaseFix):
keep_line_order = True
BM_compatible = True
PATTERN = """
(
sys_import=import_name<'import'
('sys'
|
dotted_as_names< (any ',')* 'sys' (',' any)* >
)
>
|
expr_stmt<
power< 'sys' trailer< '.' 'exitfunc' > >
'=' func=any >
)
"""
def __init__(self, *args):
super(FixExitfunc, self).__init__(*args)
def start_tree(self, tree, filename):
super(FixExitfunc, self).start_tree(tree, filename)
self.sys_import = None
def transform(self, node, results):
# First, find a the sys import. We'll just hope it's global scope.
if "sys_import" in results:
if self.sys_import is None:
self.sys_import = results["sys_import"]
return
func = results["func"].clone()
func.prefix = u""
register = pytree.Node(syms.power,
Attr(Name(u"atexit"), Name(u"register"))
)
call = Call(register, [func], node.prefix)
node.replace(call)
if self.sys_import is None:
# That's interesting.
self.warning(node, "Can't find sys import; Please add an atexit "
"import at the top of your file.")
return
# Now add an atexit import after the sys import.
names = self.sys_import.children[1]
if names.type == syms.dotted_as_names:
names.append_child(Comma())
names.append_child(Name(u"atexit", u" "))
else:
containing_stmt = self.sys_import.parent
position = containing_stmt.children.index(self.sys_import)
stmt_container = containing_stmt.parent
new_import = pytree.Node(syms.import_name,
[Name(u"import"), Name(u"atexit", u" ")]
)
new = pytree.Node(syms.simple_stmt, [new_import])
containing_stmt.insert_child(position + 1, Newline())
containing_stmt.insert_child(position + 2, new)
|
apache-2.0
|
[
624,
199,
7306,
675,
402,
984,
14,
2224,
1532,
370,
675,
314,
19840,
859,
14,
199,
624,
199,
199,
3,
6529,
26,
26844,
16997,
262,
22912,
834,
199,
199,
504,
1973,
18,
475,
19,
492,
23353,
12,
24739,
63,
1095,
199,
504,
1973,
18,
475,
19,
14,
25973,
63,
1974,
492,
2812,
12,
20516,
12,
6523,
12,
5429,
391,
12,
7053,
604,
12,
25308,
421,
199,
533,
14811,
6699,
1532,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
272,
4215,
63,
604,
63,
1648,
275,
715,
272,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
1598,
334,
2116,
984,
63,
646,
29,
646,
63,
354,
28,
7,
646,
7,
1993,
661,
1274,
7,
1993,
1204,
1993,
18947,
63,
305,
63,
1247,
28,
334,
1629,
1656,
358,
10,
283,
1274,
7,
334,
1673,
1263,
3342,
690,
1993,
776,
2116,
690,
1598,
1204,
2116,
5348,
63,
9649,
28,
1993,
7074,
28,
283,
1274,
7,
17357,
28,
7815,
283,
2224,
1532,
7,
690,
690,
2116,
14051,
2562,
29,
1629,
690,
1598,
776,
1598,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
1613,
8,
11985,
6699,
1532,
12,
291,
2843,
826,
9308,
589,
9,
339,
347,
1343,
63,
2350,
8,
277,
12,
3123,
12,
1788,
304,
267,
1613,
8,
11985,
6699,
1532,
12,
291,
680,
928,
63,
2350,
8,
2350,
12,
1788,
9,
267,
291,
14,
1274,
63,
646,
275,
488,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
327,
7758,
12,
2342,
282,
314,
984,
492,
14,
2136,
7171,
2951,
3661,
652,
1159,
2288,
4194,
14,
267,
340,
298,
1274,
63,
646,
2,
315,
2058,
26,
288,
340,
291,
14,
1274,
63,
646,
365,
488,
26,
355,
291,
14,
1274,
63,
646,
275,
2058,
905,
1274,
63,
646,
937,
288,
372,
398,
2562,
275,
2058,
905,
1532,
4140,
6311,
342,
267,
2562,
14,
1861,
275,
399,
341,
267,
2274,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
3044,
20516,
8,
985,
8,
85,
2,
24026,
390,
1288,
2812,
8,
85,
2,
2683,
2237,
3044,
776,
267,
1240,
275,
6523,
8,
2683,
12,
359,
1532,
467,
1031,
14,
1861,
9,
267,
1031,
14,
1814,
8,
1250,
9,
398,
340,
291,
14,
1274,
63,
646,
365,
488,
26,
288,
327,
10314,
1159,
19604,
14,
288,
291,
14,
3764,
8,
932,
12,
298,
6049,
1133,
2342,
984,
492,
27,
7754,
1050,
376,
19840,
298,
2490,
298,
646,
737,
314,
2746,
402,
2195,
570,
2685,
288,
372,
398,
327,
7356,
1050,
376,
19840,
492,
2410,
314,
984,
492,
14,
267,
1561,
275,
291,
14,
1274,
63,
646,
14,
3223,
59,
17,
61,
267,
340,
1561,
14,
466,
508,
25308,
14,
19404,
63,
305,
63,
1247,
26,
288,
1561,
14,
740,
63,
1739,
8,
25732,
1012,
288,
1561,
14,
740,
63,
1739,
8,
985,
8,
85,
2,
24026,
390,
401,
399,
2,
26725,
267,
587,
26,
288,
3035,
63,
9649,
275,
291,
14,
1274,
63,
646,
14,
1708,
288,
3421,
275,
3035,
63,
9649,
14,
3223,
14,
1080,
8,
277,
14,
1274,
63,
646,
9,
288,
12284,
63,
3600,
275,
3035,
63,
9649,
14,
1708,
288,
892,
63,
646,
275,
23353,
14,
1716,
8,
13807,
14,
646,
63,
354,
12,
2892,
359,
985,
8,
85,
2,
646,
1288,
2812,
8,
85,
2,
24026,
390,
401,
399,
2,
298,
1874,
2892,
776,
288,
892,
275,
23353,
14,
1716,
8,
13807,
14,
4129,
63,
9649,
12,
359,
1222,
63,
646,
566,
288,
3035,
63,
9649,
14,
3176,
63,
1739,
8,
3124,
435,
413,
12,
7053,
604,
1012,
288,
3035,
63,
9649,
14,
3176,
63,
1739,
8,
3124,
435,
499,
12,
892,
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
] |
[
199,
7306,
675,
402,
984,
14,
2224,
1532,
370,
675,
314,
19840,
859,
14,
199,
624,
199,
199,
3,
6529,
26,
26844,
16997,
262,
22912,
834,
199,
199,
504,
1973,
18,
475,
19,
492,
23353,
12,
24739,
63,
1095,
199,
504,
1973,
18,
475,
19,
14,
25973,
63,
1974,
492,
2812,
12,
20516,
12,
6523,
12,
5429,
391,
12,
7053,
604,
12,
25308,
421,
199,
533,
14811,
6699,
1532,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
272,
4215,
63,
604,
63,
1648,
275,
715,
272,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
1598,
334,
2116,
984,
63,
646,
29,
646,
63,
354,
28,
7,
646,
7,
1993,
661,
1274,
7,
1993,
1204,
1993,
18947,
63,
305,
63,
1247,
28,
334,
1629,
1656,
358,
10,
283,
1274,
7,
334,
1673,
1263,
3342,
690,
1993,
776,
2116,
690,
1598,
1204,
2116,
5348,
63,
9649,
28,
1993,
7074,
28,
283,
1274,
7,
17357,
28,
7815,
283,
2224,
1532,
7,
690,
690,
2116,
14051,
2562,
29,
1629,
690,
1598,
776,
1598,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
1613,
8,
11985,
6699,
1532,
12,
291,
2843,
826,
9308,
589,
9,
339,
347,
1343,
63,
2350,
8,
277,
12,
3123,
12,
1788,
304,
267,
1613,
8,
11985,
6699,
1532,
12,
291,
680,
928,
63,
2350,
8,
2350,
12,
1788,
9,
267,
291,
14,
1274,
63,
646,
275,
488,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
327,
7758,
12,
2342,
282,
314,
984,
492,
14,
2136,
7171,
2951,
3661,
652,
1159,
2288,
4194,
14,
267,
340,
298,
1274,
63,
646,
2,
315,
2058,
26,
288,
340,
291,
14,
1274,
63,
646,
365,
488,
26,
355,
291,
14,
1274,
63,
646,
275,
2058,
905,
1274,
63,
646,
937,
288,
372,
398,
2562,
275,
2058,
905,
1532,
4140,
6311,
342,
267,
2562,
14,
1861,
275,
399,
341,
267,
2274,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
3044,
20516,
8,
985,
8,
85,
2,
24026,
390,
1288,
2812,
8,
85,
2,
2683,
2237,
3044,
776,
267,
1240,
275,
6523,
8,
2683,
12,
359,
1532,
467,
1031,
14,
1861,
9,
267,
1031,
14,
1814,
8,
1250,
9,
398,
340,
291,
14,
1274,
63,
646,
365,
488,
26,
288,
327,
10314,
1159,
19604,
14,
288,
291,
14,
3764,
8,
932,
12,
298,
6049,
1133,
2342,
984,
492,
27,
7754,
1050,
376,
19840,
298,
2490,
298,
646,
737,
314,
2746,
402,
2195,
570,
2685,
288,
372,
398,
327,
7356,
1050,
376,
19840,
492,
2410,
314,
984,
492,
14,
267,
1561,
275,
291,
14,
1274,
63,
646,
14,
3223,
59,
17,
61,
267,
340,
1561,
14,
466,
508,
25308,
14,
19404,
63,
305,
63,
1247,
26,
288,
1561,
14,
740,
63,
1739,
8,
25732,
1012,
288,
1561,
14,
740,
63,
1739,
8,
985,
8,
85,
2,
24026,
390,
401,
399,
2,
26725,
267,
587,
26,
288,
3035,
63,
9649,
275,
291,
14,
1274,
63,
646,
14,
1708,
288,
3421,
275,
3035,
63,
9649,
14,
3223,
14,
1080,
8,
277,
14,
1274,
63,
646,
9,
288,
12284,
63,
3600,
275,
3035,
63,
9649,
14,
1708,
288,
892,
63,
646,
275,
23353,
14,
1716,
8,
13807,
14,
646,
63,
354,
12,
2892,
359,
985,
8,
85,
2,
646,
1288,
2812,
8,
85,
2,
24026,
390,
401,
399,
2,
298,
1874,
2892,
776,
288,
892,
275,
23353,
14,
1716,
8,
13807,
14,
4129,
63,
9649,
12,
359,
1222,
63,
646,
566,
288,
3035,
63,
9649,
14,
3176,
63,
1739,
8,
3124,
435,
413,
12,
7053,
604,
1012,
288,
3035,
63,
9649,
14,
3176,
63,
1739,
8,
3124,
435,
499,
12,
892,
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,
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
] |
Nite69/Axis
|
share/qt/extract_strings_qt.py
|
1294
|
1784
|
#!/usr/bin/python
'''
Extract _("...") strings for translation and convert to Qt4 stringdefs so that
they can be picked up by Qt linguist.
'''
from subprocess import Popen, PIPE
import glob
OUT_CPP="src/qt/bitcoinstrings.cpp"
EMPTY=['""']
def parse_po(text):
"""
Parse 'po' format produced by xgettext.
Return a list of (msgid,msgstr) tuples.
"""
messages = []
msgid = []
msgstr = []
in_msgid = False
in_msgstr = False
for line in text.split('\n'):
line = line.rstrip('\r')
if line.startswith('msgid '):
if in_msgstr:
messages.append((msgid, msgstr))
in_msgstr = False
# message start
in_msgid = True
msgid = [line[6:]]
elif line.startswith('msgstr '):
in_msgid = False
in_msgstr = True
msgstr = [line[7:]]
elif line.startswith('"'):
if in_msgid:
msgid.append(line)
if in_msgstr:
msgstr.append(line)
if in_msgstr:
messages.append((msgid, msgstr))
return messages
files = glob.glob('src/*.cpp') + glob.glob('src/*.h')
# xgettext -n --keyword=_ $FILES
child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
(out, err) = child.communicate()
messages = parse_po(out)
f = open(OUT_CPP, 'w')
f.write("""#include <QtGlobal>
// Automatically generated by extract_strings.py
#ifdef __GNUC__
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
""")
f.write('static const char UNUSED *bitcoin_strings[] = {')
for (msgid, msgstr) in messages:
if msgid != EMPTY:
f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))
f.write('};')
f.close()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
2344,
199,
12147,
3824,
12594,
3326,
367,
7761,
436,
3957,
370,
3959,
20,
1059,
8710,
880,
626,
199,
29002,
883,
506,
29438,
1536,
701,
3959,
634,
14659,
631,
14,
199,
2344,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
5739,
199,
199,
1877,
63,
14533,
628,
2164,
15,
8440,
15,
22816,
5465,
14,
5910,
2,
199,
13993,
2968,
341,
418,
199,
199,
318,
2198,
63,
555,
8,
505,
304,
272,
408,
272,
6077,
283,
555,
7,
1475,
13584,
701,
671,
5152,
14,
272,
1432,
282,
769,
402,
334,
15245,
12,
23367,
9,
6346,
14,
272,
408,
272,
3788,
275,
942,
272,
17879,
275,
942,
272,
1499,
495,
275,
942,
272,
315,
63,
15245,
275,
756,
272,
315,
63,
23367,
275,
756,
339,
367,
1004,
315,
1318,
14,
1294,
2258,
78,
735,
267,
1004,
275,
1004,
14,
6735,
2258,
82,
358,
267,
340,
1004,
14,
2460,
360,
15245,
18927,
288,
340,
315,
63,
23367,
26,
355,
3788,
14,
740,
1332,
15245,
12,
1499,
495,
430,
355,
315,
63,
23367,
275,
756,
288,
327,
1245,
1343,
288,
315,
63,
15245,
275,
715,
7846,
17879,
275,
359,
604,
59,
22,
21316,
267,
916,
1004,
14,
2460,
360,
23367,
18927,
288,
315,
63,
15245,
275,
756,
288,
315,
63,
23367,
275,
715,
288,
1499,
495,
275,
359,
604,
59,
23,
21316,
267,
916,
1004,
14,
2460,
14088,
735,
288,
340,
315,
63,
15245,
26,
355,
17879,
14,
740,
8,
604,
9,
288,
340,
315,
63,
23367,
26,
355,
1499,
495,
14,
740,
8,
604,
9,
339,
340,
315,
63,
23367,
26,
267,
3788,
14,
740,
1332,
15245,
12,
1499,
495,
430,
339,
372,
3788,
199,
199,
1725,
275,
5739,
14,
6463,
360,
2164,
20362,
5910,
358,
435,
5739,
14,
6463,
360,
2164,
20362,
72,
358,
9948,
199,
3,
671,
5152,
446,
78,
1553,
6691,
3699,
2672,
9472,
199,
1739,
275,
13995,
2941,
88,
5152,
28280,
1199,
4022,
21810,
78,
28280,
6691,
3699,
418,
435,
1584,
12,
3839,
29,
6089,
9,
199,
8,
548,
12,
2329,
9,
275,
1982,
14,
10664,
342,
199,
199,
3431,
275,
2198,
63,
555,
8,
548,
9,
9948,
199,
70,
275,
1551,
8,
1877,
63,
14533,
12,
283,
87,
358,
199,
70,
14,
952,
4852,
3,
2613,
665,
4238,
7025,
30,
199,
501,
9195,
17174,
4046,
701,
5536,
63,
5465,
14,
647,
199,
3,
27737,
636,
17732,
35,
363,
199,
3,
4640,
738,
27726,
636,
3215,
721,
8,
8618,
430,
199,
3,
2836,
199,
3,
4640,
738,
27726,
199,
3,
13739,
199,
6141,
199,
70,
14,
952,
360,
1986,
950,
1495,
738,
27726,
627,
22816,
63,
5465,
8607,
275,
469,
358,
199,
509,
334,
15245,
12,
1499,
495,
9,
315,
3788,
26,
272,
340,
17879,
1137,
16589,
26,
267,
289,
14,
952,
360,
19229,
63,
26376,
1951,
63,
2826,
1938,
480,
22816,
13,
1018,
401,
450,
83,
26323,
78,
7,
450,
17485,
78,
1370,
904,
8,
15245,
1724,
199,
70,
14,
952,
360,
93,
10784,
199,
70,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2344,
199,
12147,
3824,
12594,
3326,
367,
7761,
436,
3957,
370,
3959,
20,
1059,
8710,
880,
626,
199,
29002,
883,
506,
29438,
1536,
701,
3959,
634,
14659,
631,
14,
199,
2344,
199,
504,
3873,
492,
13995,
12,
22773,
199,
646,
5739,
199,
199,
1877,
63,
14533,
628,
2164,
15,
8440,
15,
22816,
5465,
14,
5910,
2,
199,
13993,
2968,
341,
418,
199,
199,
318,
2198,
63,
555,
8,
505,
304,
272,
408,
272,
6077,
283,
555,
7,
1475,
13584,
701,
671,
5152,
14,
272,
1432,
282,
769,
402,
334,
15245,
12,
23367,
9,
6346,
14,
272,
408,
272,
3788,
275,
942,
272,
17879,
275,
942,
272,
1499,
495,
275,
942,
272,
315,
63,
15245,
275,
756,
272,
315,
63,
23367,
275,
756,
339,
367,
1004,
315,
1318,
14,
1294,
2258,
78,
735,
267,
1004,
275,
1004,
14,
6735,
2258,
82,
358,
267,
340,
1004,
14,
2460,
360,
15245,
18927,
288,
340,
315,
63,
23367,
26,
355,
3788,
14,
740,
1332,
15245,
12,
1499,
495,
430,
355,
315,
63,
23367,
275,
756,
288,
327,
1245,
1343,
288,
315,
63,
15245,
275,
715,
7846,
17879,
275,
359,
604,
59,
22,
21316,
267,
916,
1004,
14,
2460,
360,
23367,
18927,
288,
315,
63,
15245,
275,
756,
288,
315,
63,
23367,
275,
715,
288,
1499,
495,
275,
359,
604,
59,
23,
21316,
267,
916,
1004,
14,
2460,
14088,
735,
288,
340,
315,
63,
15245,
26,
355,
17879,
14,
740,
8,
604,
9,
288,
340,
315,
63,
23367,
26,
355,
1499,
495,
14,
740,
8,
604,
9,
339,
340,
315,
63,
23367,
26,
267,
3788,
14,
740,
1332,
15245,
12,
1499,
495,
430,
339,
372,
3788,
199,
199,
1725,
275,
5739,
14,
6463,
360,
2164,
20362,
5910,
358,
435,
5739,
14,
6463,
360,
2164,
20362,
72,
358,
9948,
199,
3,
671,
5152,
446,
78,
1553,
6691,
3699,
2672,
9472,
199,
1739,
275,
13995,
2941,
88,
5152,
28280,
1199,
4022,
21810,
78,
28280,
6691,
3699,
418,
435,
1584,
12,
3839,
29,
6089,
9,
199,
8,
548,
12,
2329,
9,
275,
1982,
14,
10664,
342,
199,
199,
3431,
275,
2198,
63,
555,
8,
548,
9,
9948,
199,
70,
275,
1551,
8,
1877,
63,
14533,
12,
283,
87,
358,
199,
70,
14,
952,
4852,
3,
2613,
665,
4238,
7025,
30,
199,
501,
9195,
17174,
4046,
701,
5536,
63,
5465,
14,
647,
199,
3,
27737,
636,
17732,
35,
363,
199,
3,
4640,
738,
27726,
636,
3215,
721,
8,
8618,
430,
199,
3,
2836,
199,
3,
4640,
738,
27726,
199,
3,
13739,
199,
6141,
199,
70,
14,
952,
360,
1986,
950,
1495,
738,
27726,
627,
22816,
63,
5465,
8607,
275,
469,
358,
199,
509,
334,
15245,
12,
1499,
495,
9,
315,
3788,
26,
272,
340,
17879,
1137,
16589,
26,
267,
289,
14,
952,
360,
19229,
63,
26376,
1951,
63,
2826,
1938,
480,
22816,
13,
1018,
401,
450,
83,
26323,
78,
7,
450,
17485,
78,
1370,
904,
8,
15245,
1724,
199,
70,
14,
952,
360,
93,
10784,
199,
70,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
rnikiforova/GuruTubeProject
|
GuruTube/libraries/django/middleware/transaction.py
|
113
|
2641
|
import warnings
from django.core.exceptions import MiddlewareNotUsed
from django.db import connection, transaction
class TransactionMiddleware(object):
"""
Transaction middleware. If this is enabled, each view function will be run
with commit_on_response activated - that way a save() doesn't do a direct
commit, the commit is done when a successful response is created. If an
exception happens, the database is rolled back.
"""
def __init__(self):
warnings.warn(
"TransactionMiddleware is deprecated in favor of ATOMIC_REQUESTS.",
PendingDeprecationWarning, stacklevel=2)
if connection.settings_dict['ATOMIC_REQUESTS']:
raise MiddlewareNotUsed
def process_request(self, request):
"""Enters transaction management"""
transaction.enter_transaction_management()
def process_exception(self, request, exception):
"""Rolls back the database and leaves transaction management"""
if transaction.is_dirty():
# This rollback might fail because of network failure for example.
# If rollback isn't possible it is impossible to clean the
# connection's state. So leave the connection in dirty state and
# let request_finished signal deal with cleaning the connection.
transaction.rollback()
transaction.leave_transaction_management()
def process_response(self, request, response):
"""Commits and leaves transaction management."""
if not transaction.get_autocommit():
if transaction.is_dirty():
# Note: it is possible that the commit fails. If the reason is
# closed connection or some similar reason, then there is
# little hope to proceed nicely. However, in some cases (
# deferred foreign key checks for exampl) it is still possible
# to rollback().
try:
transaction.commit()
except Exception:
# If the rollback fails, the transaction state will be
# messed up. It doesn't matter, the connection will be set
# to clean state after the request finishes. And, we can't
# clean the state here properly even if we wanted to, the
# connection is in transaction but we can't rollback...
transaction.rollback()
transaction.leave_transaction_management()
raise
transaction.leave_transaction_management()
return response
|
bsd-3-clause
|
[
646,
3598,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
603,
3551,
1763,
9167,
199,
504,
1639,
14,
697,
492,
1950,
12,
6008,
199,
199,
533,
18244,
6608,
8,
785,
304,
272,
408,
272,
18244,
10816,
14,
982,
642,
365,
5223,
12,
1924,
2455,
805,
911,
506,
1255,
272,
543,
5532,
63,
265,
63,
1310,
22225,
446,
626,
4340,
282,
3354,
342,
3181,
1133,
886,
282,
4125,
272,
5532,
12,
314,
5532,
365,
4224,
1380,
282,
9512,
1177,
365,
2737,
14,
982,
376,
272,
1919,
10986,
12,
314,
3050,
365,
20182,
1146,
1771,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
3598,
14,
4050,
8,
288,
298,
10161,
6608,
365,
5906,
315,
17914,
402,
437,
2566,
17233,
63,
6780,
51,
4765,
288,
29216,
15561,
12,
13232,
29,
18,
9,
267,
340,
1950,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
2565,
288,
746,
603,
3551,
1763,
9167,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
408,
1327,
878,
6008,
10041,
624,
267,
6008,
14,
4200,
63,
5945,
63,
8110,
342,
339,
347,
2112,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
408,
50,
393,
478,
1771,
314,
3050,
436,
16733,
6008,
10041,
624,
267,
340,
6008,
14,
374,
63,
8799,
837,
288,
327,
961,
16475,
5594,
2449,
2952,
402,
2784,
5988,
367,
2893,
14,
288,
327,
982,
16475,
5712,
1133,
3962,
652,
365,
26847,
370,
3633,
314,
288,
327,
1950,
1159,
1174,
14,
2002,
10137,
314,
1950,
315,
14650,
1174,
436,
288,
327,
4691,
1056,
63,
8669,
4673,
7962,
543,
29579,
314,
1950,
14,
288,
6008,
14,
10437,
342,
267,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
408,
5150,
1405,
436,
16733,
6008,
10041,
1041,
267,
340,
440,
6008,
14,
362,
63,
17881,
837,
288,
340,
6008,
14,
374,
63,
8799,
837,
355,
327,
3390,
26,
652,
365,
3962,
626,
314,
5532,
6918,
14,
982,
314,
4499,
365,
355,
327,
6876,
1950,
503,
2005,
8545,
4499,
12,
2066,
2337,
365,
355,
327,
12050,
3661,
370,
20320,
14213,
590,
14,
9738,
12,
315,
2005,
5560,
334,
355,
327,
12309,
11608,
790,
5920,
367,
444,
65,
2421,
9,
652,
365,
5139,
3962,
355,
327,
370,
16475,
1252,
355,
862,
26,
490,
6008,
14,
3543,
342,
355,
871,
2186,
26,
490,
327,
982,
314,
16475,
6918,
12,
314,
6008,
1174,
911,
506,
490,
327,
26560,
939,
1536,
14,
2779,
3181,
1133,
17247,
12,
314,
1950,
911,
506,
663,
490,
327,
370,
3633,
1174,
2410,
314,
1056,
9578,
397,
14,
6061,
12,
781,
883,
1133,
490,
327,
3633,
314,
1174,
2348,
7684,
2755,
340,
781,
13632,
370,
12,
314,
490,
327,
1950,
365,
315,
6008,
1325,
781,
883,
1133,
16475,
1396,
490,
6008,
14,
10437,
342,
490,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
490,
746,
288,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
267,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3598,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
603,
3551,
1763,
9167,
199,
504,
1639,
14,
697,
492,
1950,
12,
6008,
199,
199,
533,
18244,
6608,
8,
785,
304,
272,
408,
272,
18244,
10816,
14,
982,
642,
365,
5223,
12,
1924,
2455,
805,
911,
506,
1255,
272,
543,
5532,
63,
265,
63,
1310,
22225,
446,
626,
4340,
282,
3354,
342,
3181,
1133,
886,
282,
4125,
272,
5532,
12,
314,
5532,
365,
4224,
1380,
282,
9512,
1177,
365,
2737,
14,
982,
376,
272,
1919,
10986,
12,
314,
3050,
365,
20182,
1146,
1771,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
3598,
14,
4050,
8,
288,
298,
10161,
6608,
365,
5906,
315,
17914,
402,
437,
2566,
17233,
63,
6780,
51,
4765,
288,
29216,
15561,
12,
13232,
29,
18,
9,
267,
340,
1950,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
2565,
288,
746,
603,
3551,
1763,
9167,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
408,
1327,
878,
6008,
10041,
624,
267,
6008,
14,
4200,
63,
5945,
63,
8110,
342,
339,
347,
2112,
63,
1971,
8,
277,
12,
1056,
12,
1919,
304,
267,
408,
50,
393,
478,
1771,
314,
3050,
436,
16733,
6008,
10041,
624,
267,
340,
6008,
14,
374,
63,
8799,
837,
288,
327,
961,
16475,
5594,
2449,
2952,
402,
2784,
5988,
367,
2893,
14,
288,
327,
982,
16475,
5712,
1133,
3962,
652,
365,
26847,
370,
3633,
314,
288,
327,
1950,
1159,
1174,
14,
2002,
10137,
314,
1950,
315,
14650,
1174,
436,
288,
327,
4691,
1056,
63,
8669,
4673,
7962,
543,
29579,
314,
1950,
14,
288,
6008,
14,
10437,
342,
267,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
408,
5150,
1405,
436,
16733,
6008,
10041,
1041,
267,
340,
440,
6008,
14,
362,
63,
17881,
837,
288,
340,
6008,
14,
374,
63,
8799,
837,
355,
327,
3390,
26,
652,
365,
3962,
626,
314,
5532,
6918,
14,
982,
314,
4499,
365,
355,
327,
6876,
1950,
503,
2005,
8545,
4499,
12,
2066,
2337,
365,
355,
327,
12050,
3661,
370,
20320,
14213,
590,
14,
9738,
12,
315,
2005,
5560,
334,
355,
327,
12309,
11608,
790,
5920,
367,
444,
65,
2421,
9,
652,
365,
5139,
3962,
355,
327,
370,
16475,
1252,
355,
862,
26,
490,
6008,
14,
3543,
342,
355,
871,
2186,
26,
490,
327,
982,
314,
16475,
6918,
12,
314,
6008,
1174,
911,
506,
490,
327,
26560,
939,
1536,
14,
2779,
3181,
1133,
17247,
12,
314,
1950,
911,
506,
663,
490,
327,
370,
3633,
1174,
2410,
314,
1056,
9578,
397,
14,
6061,
12,
781,
883,
1133,
490,
327,
3633,
314,
1174,
2348,
7684,
2755,
340,
781,
13632,
370,
12,
314,
490,
327,
1950,
365,
315,
6008,
1325,
781,
883,
1133,
16475,
1396,
490,
6008,
14,
10437,
342,
490,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
490,
746,
288,
6008,
14,
12422,
63,
5945,
63,
8110,
342,
267,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
MoisesTedeschi/python
|
Scripts-Python/Modulos-Diversos/deteccao-de-faces-com-python-e-opencv/Lib/site-packages/pip/_vendor/chardet/utf8prober.py
|
290
|
2766
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is mozilla.org 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 #########################
from .charsetprober import CharSetProber
from .enums import ProbingState, MachineState
from .codingstatemachine import CodingStateMachine
from .mbcssm import UTF8_SM_MODEL
class UTF8Prober(CharSetProber):
ONE_CHAR_PROB = 0.5
def __init__(self):
super(UTF8Prober, self).__init__()
self.coding_sm = CodingStateMachine(UTF8_SM_MODEL)
self._num_mb_chars = None
self.reset()
def reset(self):
super(UTF8Prober, self).reset()
self.coding_sm.reset()
self._num_mb_chars = 0
@property
def charset_name(self):
return "utf-8"
@property
def language(self):
return ""
def feed(self, byte_str):
for c in byte_str:
coding_state = self.coding_sm.next_state(c)
if coding_state == MachineState.ERROR:
self._state = ProbingState.NOT_ME
break
elif coding_state == MachineState.ITS_ME:
self._state = ProbingState.FOUND_IT
break
elif coding_state == MachineState.START:
if self.coding_sm.get_current_charlen() >= 2:
self._num_mb_chars += 1
if self.state == ProbingState.DETECTING:
if self.get_confidence() > self.SHORTCUT_THRESHOLD:
self._state = ProbingState.FOUND_IT
return self.state
def get_confidence(self):
unlike = 0.99
if self._num_mb_chars < 6:
unlike *= self.ONE_CHAR_PROB ** self._num_mb_chars
return 1.0 - unlike
else:
return unlike
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
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,
504,
1275,
6043,
19903,
492,
31727,
199,
504,
1275,
19921,
492,
2165,
10911,
2223,
12,
18722,
2223,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
887,
3919,
77,
492,
9094,
24,
63,
4029,
63,
11429,
4388,
199,
533,
9094,
24,
8029,
8,
15159,
304,
272,
13051,
63,
5901,
63,
30533,
275,
378,
14,
21,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6610,
24,
8029,
12,
291,
2843,
826,
4533,
267,
291,
14,
1523,
63,
3300,
275,
30539,
8,
6610,
24,
63,
4029,
63,
11429,
9,
267,
291,
423,
1507,
63,
887,
63,
6574,
275,
488,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
1613,
8,
6610,
24,
8029,
12,
291,
680,
3958,
342,
267,
291,
14,
1523,
63,
3300,
14,
3958,
342,
267,
291,
423,
1507,
63,
887,
63,
6574,
275,
378,
339,
768,
1829,
272,
347,
5960,
63,
354,
8,
277,
304,
267,
372,
298,
1624,
13,
24,
2,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
3087,
339,
347,
4733,
8,
277,
12,
3696,
63,
495,
304,
267,
367,
286,
315,
3696,
63,
495,
26,
288,
2803,
63,
929,
275,
291,
14,
1523,
63,
3300,
14,
2184,
63,
929,
8,
67,
9,
288,
340,
2803,
63,
929,
508,
18722,
2223,
14,
3170,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
4609,
63,
3635,
355,
2059,
288,
916,
2803,
63,
929,
508,
18722,
2223,
14,
5930,
63,
3635,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
13945,
63,
649,
355,
2059,
288,
916,
2803,
63,
929,
508,
18722,
2223,
14,
7363,
26,
355,
340,
291,
14,
1523,
63,
3300,
14,
362,
63,
1818,
63,
1560,
552,
342,
2356,
499,
26,
490,
291,
423,
1507,
63,
887,
63,
6574,
847,
413,
398,
340,
291,
14,
929,
508,
2165,
10911,
2223,
14,
17442,
3582,
1206,
26,
288,
340,
291,
14,
362,
63,
13969,
342,
690,
291,
14,
13003,
24678,
63,
19307,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
13945,
63,
649,
398,
372,
291,
14,
929,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
29750,
275,
378,
14,
1020,
267,
340,
291,
423,
1507,
63,
887,
63,
6574,
665,
1227,
26,
288,
29750,
9000,
291,
14,
4817,
63,
5901,
63,
30533,
1011,
291,
423,
1507,
63,
887,
63,
6574,
288,
372,
413,
14,
16,
446,
29750,
267,
587,
26,
288,
372,
29750,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1303,
6956,
14,
1308,
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,
504,
1275,
6043,
19903,
492,
31727,
199,
504,
1275,
19921,
492,
2165,
10911,
2223,
12,
18722,
2223,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
887,
3919,
77,
492,
9094,
24,
63,
4029,
63,
11429,
4388,
199,
533,
9094,
24,
8029,
8,
15159,
304,
272,
13051,
63,
5901,
63,
30533,
275,
378,
14,
21,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6610,
24,
8029,
12,
291,
2843,
826,
4533,
267,
291,
14,
1523,
63,
3300,
275,
30539,
8,
6610,
24,
63,
4029,
63,
11429,
9,
267,
291,
423,
1507,
63,
887,
63,
6574,
275,
488,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
1613,
8,
6610,
24,
8029,
12,
291,
680,
3958,
342,
267,
291,
14,
1523,
63,
3300,
14,
3958,
342,
267,
291,
423,
1507,
63,
887,
63,
6574,
275,
378,
339,
768,
1829,
272,
347,
5960,
63,
354,
8,
277,
304,
267,
372,
298,
1624,
13,
24,
2,
339,
768,
1829,
272,
347,
2637,
8,
277,
304,
267,
372,
3087,
339,
347,
4733,
8,
277,
12,
3696,
63,
495,
304,
267,
367,
286,
315,
3696,
63,
495,
26,
288,
2803,
63,
929,
275,
291,
14,
1523,
63,
3300,
14,
2184,
63,
929,
8,
67,
9,
288,
340,
2803,
63,
929,
508,
18722,
2223,
14,
3170,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
4609,
63,
3635,
355,
2059,
288,
916,
2803,
63,
929,
508,
18722,
2223,
14,
5930,
63,
3635,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
13945,
63,
649,
355,
2059,
288,
916,
2803,
63,
929,
508,
18722,
2223,
14,
7363,
26,
355,
340,
291,
14,
1523,
63,
3300,
14,
362,
63,
1818,
63,
1560,
552,
342,
2356,
499,
26,
490,
291,
423,
1507,
63,
887,
63,
6574,
847,
413,
398,
340,
291,
14,
929,
508,
2165,
10911,
2223,
14,
17442,
3582,
1206,
26,
288,
340,
291,
14,
362,
63,
13969,
342,
690,
291,
14,
13003,
24678,
63,
19307,
26,
355,
291,
423,
929,
275,
2165,
10911,
2223,
14,
13945,
63,
649,
398,
372,
291,
14,
929,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
29750,
275,
378,
14,
1020,
267,
340,
291,
423,
1507,
63,
887,
63,
6574,
665,
1227,
26,
288,
29750,
9000,
291,
14,
4817,
63,
5901,
63,
30533,
1011,
291,
423,
1507,
63,
887,
63,
6574,
288,
372,
413,
14,
16,
446,
29750,
267,
587,
26,
288,
372,
29750,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dbinetti/barberscore-django
|
project/apps/bhs/management/commands/update_membercenter.py
|
3
|
6525
|
# Standard Library
import datetime
import logging
import requests
# Django
from django.core.management.base import BaseCommand
from django.utils import timezone
from django.contrib.auth import get_user_model
from django.apps import apps
from django.conf import settings
from apps.bhs.tasks import update_person_from_membercenter
from apps.bhs.tasks import update_group_from_membercenter
from apps.bhs.tasks import update_group_owners_from_membercenter
# First-Party
User = get_user_model()
Person = apps.get_model('bhs.person')
Group = apps.get_model('bhs.group')
log = logging.getLogger('updater')
class Command(BaseCommand):
help = "Command to sync with Member Center database."
def add_arguments(self, parser):
parser.add_argument(
'--days',
type=int,
dest='days',
nargs='?',
const=1,
help='Number of days to update.',
)
parser.add_argument(
'--hours',
type=int,
dest='hours',
nargs='?',
const=1,
help='Number of hours to update.',
)
parser.add_argument(
'--minutes',
type=int,
dest='minutes',
nargs='?',
const=1,
help='Number of hours to update.',
)
def handle(self, *args, **options):
# Set Cursor
if options['days']:
cursor = timezone.now() - datetime.timedelta(days=options['days'], hours=1)
elif options['hours']:
cursor = timezone.now() - datetime.timedelta(hours=options['hours'], minutes=5)
elif options['minutes']:
cursor = timezone.now() - datetime.timedelta(minutes=options['minutes'], seconds=5)
else:
cursor = None
# Sync Persons
self.stdout.write("Fetching Persons from Member Center...")
endpoint, _, token = settings.MEMBERCENTER_URL.partition('@')
url = "{0}/bhs/person".format(endpoint)
headers = {
'Authorization': 'Token {0}'.format(token)
}
page = 1
params = {
'filter[status]': Person.STATUS.active,
'filter[modified__gt]': cursor,
'page[number]': page,
}
response = requests.get(
url,
headers=headers,
params=params,
)
response.raise_for_status()
response_json = response.json()
t = response_json['meta']['pagination']['count']
if t:
i = 0
pages = response_json['meta']['pagination']['pages']
while page <= pages:
response = requests.get(
url,
headers=headers,
params=params,
)
response.raise_for_status()
response_json = response.json()
items = response_json['data']
for item in items:
i += 1
self.stdout.flush()
self.stdout.write("Updating {0} of {1} Persons...".format(i, t), ending='\r')
update_person_from_membercenter.delay(item)
page += 1
params['page[number]'] = page
self.stdout.write("")
self.stdout.write("Updated {0} Persons.".format(t))
# Sync Groups
self.stdout.write("Fetching Groups from Member Center...")
endpoint, _, token = settings.MEMBERCENTER_URL.partition('@')
url = "{0}/bhs/group".format(endpoint)
headers = {
'Authorization': 'Token {0}'.format(token)
}
page = 1
params = {
'filter[status]': Group.STATUS.active,
'filter[kind__gt]': 30,
'filter[modified__gt]': cursor,
'page[number]': page,
}
response = requests.get(
url,
headers=headers,
params=params,
)
response.raise_for_status()
response_json = response.json()
t = response_json['meta']['pagination']['count']
if t:
i = 0
pages = response_json['meta']['pagination']['pages']
while page <= pages:
response = requests.get(
url,
headers=headers,
params=params,
)
response.raise_for_status()
response_json = response.json()
items = response_json['data']
for item in items:
i += 1
self.stdout.flush()
self.stdout.write("Updating {0} of {1} Groups...".format(i, t), ending='\r')
update_group_from_membercenter.delay(item)
page += 1
params['page[number]'] = page
self.stdout.write("")
self.stdout.write("Updated {0} Groups.".format(t))
# Sync Roles
# self.stdout.write("Fetching Officers from Member Center...")
# endpoint, _, token = settings.MEMBERCENTER_URL.partition('@')
# url = "{0}/bhs/officer".format(endpoint)
# headers = {
# 'Authorization': 'Token {0}'.format(token)
# }
# page = 1
# params = {
# 'group__status': Group.STATUS.active,
# 'group__kind__gt': 30,
# 'modified__gt': cursor,
# 'page': page,
# }
# response = requests.get(
# url,
# headers=headers,
# params=params,
# ).json()
# t = response['meta']['pagination']['count']
# if t:
# i = 0
# pages = response['meta']['pagination']['pages']
# while page <= pages:
# response = requests.get(
# url,
# headers=headers,
# params=params,
# ).json()
# items = response['data']
# for item in items:
# i += 1
# self.stdout.flush()
# self.stdout.write("Updating {0} of {1} Roles...".format(i, t), ending='\r')
# update_group_owners_from_membercenter.delay(item)
# page += 1
# params['page[number]'] = page
# self.stdout.write("")
# self.stdout.write("Updated {0} Officers.".format(t))
self.stdout.write("Complete.")
|
bsd-2-clause
|
[
199,
3,
9739,
11243,
199,
646,
2197,
199,
646,
2050,
199,
646,
4145,
199,
3,
5634,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
5484,
63,
504,
63,
1114,
4218,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
923,
63,
504,
63,
1114,
4218,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
923,
63,
27169,
63,
504,
63,
1114,
4218,
199,
199,
3,
7758,
13,
25233,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
7344,
275,
8686,
14,
362,
63,
1238,
360,
66,
4213,
14,
5484,
358,
199,
2448,
275,
8686,
14,
362,
63,
1238,
360,
66,
4213,
14,
923,
358,
199,
199,
793,
275,
2050,
14,
5572,
360,
29645,
358,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
298,
3110,
370,
7604,
543,
14409,
24699,
3050,
2122,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
4899,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
4899,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
7609,
370,
1678,
3130,
267,
776,
398,
1798,
14,
525,
63,
2094,
8,
288,
2850,
8419,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
8419,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
10857,
370,
1678,
3130,
267,
776,
398,
1798,
14,
525,
63,
2094,
8,
288,
2850,
10430,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
10430,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
10857,
370,
1678,
3130,
267,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
327,
2494,
20385,
267,
340,
1511,
459,
4899,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
4899,
29,
1419,
459,
4899,
995,
10857,
29,
17,
9,
267,
916,
1511,
459,
8419,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
8419,
29,
1419,
459,
8419,
995,
9395,
29,
21,
9,
267,
916,
1511,
459,
10430,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
10430,
29,
1419,
459,
10430,
995,
4696,
29,
21,
9,
267,
587,
26,
288,
3920,
275,
488,
398,
327,
22407,
8028,
83,
267,
291,
14,
2703,
14,
952,
480,
11135,
316,
8028,
83,
687,
14409,
24699,
12594,
267,
6037,
12,
5501,
1526,
275,
2202,
14,
26682,
17611,
63,
2632,
14,
5312,
16591,
358,
267,
1166,
275,
5310,
16,
5995,
66,
4213,
15,
5484,
1674,
908,
8,
6520,
9,
267,
2323,
275,
469,
288,
283,
11626,
356,
283,
3264,
469,
16,
5285,
908,
8,
1418,
9,
267,
789,
267,
2034,
275,
413,
267,
1862,
275,
469,
288,
283,
1541,
59,
1205,
61,
356,
8028,
14,
6305,
14,
2682,
12,
288,
283,
1541,
59,
5540,
363,
3308,
61,
356,
3920,
12,
288,
283,
1606,
59,
1955,
61,
356,
2034,
12,
267,
789,
267,
1177,
275,
4145,
14,
362,
8,
288,
1166,
12,
288,
2323,
29,
2139,
12,
288,
1862,
29,
1162,
12,
267,
776,
267,
1177,
14,
3730,
63,
509,
63,
1205,
342,
267,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
267,
307,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
835,
418,
267,
340,
307,
26,
288,
284,
275,
378,
288,
6497,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
5856,
418,
288,
1830,
2034,
2695,
6497,
26,
355,
1177,
275,
4145,
14,
362,
8,
490,
1166,
12,
490,
2323,
29,
2139,
12,
490,
1862,
29,
1162,
12,
355,
776,
355,
1177,
14,
3730,
63,
509,
63,
1205,
342,
355,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
355,
2974,
275,
1177,
63,
1001,
459,
576,
418,
355,
367,
1242,
315,
2974,
26,
490,
284,
847,
413,
490,
291,
14,
2703,
14,
4939,
342,
490,
291,
14,
2703,
14,
952,
480,
24993,
469,
16,
93,
402,
469,
17,
93,
8028,
83,
1396,
1674,
908,
8,
73,
12,
307,
395,
13401,
17115,
82,
358,
490,
1678,
63,
5484,
63,
504,
63,
1114,
4218,
14,
5814,
8,
1053,
9,
355,
2034,
847,
413,
355,
1862,
459,
1606,
59,
1955,
61,
418,
275,
2034,
288,
291,
14,
2703,
14,
952,
10804,
267,
291,
14,
2703,
14,
952,
480,
19920,
469,
16,
93,
8028,
83,
15848,
908,
8,
84,
430,
398,
327,
22407,
25031,
267,
291,
14,
2703,
14,
952,
480,
11135,
316,
25031,
687,
14409,
24699,
12594,
267,
6037,
12,
5501,
1526,
275,
2202,
14,
26682,
17611,
63,
2632,
14,
5312,
16591,
358,
267,
1166,
275,
5310,
16,
5995,
66,
4213,
15,
923,
1674,
908,
8,
6520,
9,
267,
2323,
275,
469,
288,
283,
11626,
356,
283,
3264,
469,
16,
5285,
908,
8,
1418,
9,
267,
789,
267,
2034,
275,
413,
267,
1862,
275,
469,
288,
283,
1541,
59,
1205,
61,
356,
5611,
14,
6305,
14,
2682,
12,
288,
283,
1541,
59,
5091,
363,
3308,
61,
356,
4233,
12,
288,
283,
1541,
59,
5540,
363,
3308,
61,
356,
3920,
12,
288,
283,
1606,
59,
1955,
61,
356,
2034,
12,
267,
789,
267,
1177,
275,
4145,
14,
362,
8,
288,
1166,
12,
288,
2323,
29,
2139,
12,
288,
1862,
29,
1162,
12,
267,
776,
267,
1177,
14,
3730,
63,
509,
63,
1205,
342,
267,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
267,
307,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
835,
418,
267,
340,
307,
26,
288,
284,
275,
378,
288,
6497,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
5856,
418,
288,
1830,
2034,
2695,
6497,
26,
355,
1177,
275,
4145,
14,
362,
8,
490,
1166,
12,
490,
2323,
29,
2139,
12,
490,
1862,
29,
1162,
12,
355,
776,
355,
1177,
14,
3730,
63,
509,
63,
1205,
342,
355,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
355,
2974,
275,
1177,
63,
1001,
459,
576,
418,
355,
367,
1242,
315,
2974,
26,
490,
284
] |
[
3,
9739,
11243,
199,
646,
2197,
199,
646,
2050,
199,
646,
4145,
199,
3,
5634,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
5484,
63,
504,
63,
1114,
4218,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
923,
63,
504,
63,
1114,
4218,
199,
504,
8686,
14,
66,
4213,
14,
5054,
492,
1678,
63,
923,
63,
27169,
63,
504,
63,
1114,
4218,
199,
199,
3,
7758,
13,
25233,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
7344,
275,
8686,
14,
362,
63,
1238,
360,
66,
4213,
14,
5484,
358,
199,
2448,
275,
8686,
14,
362,
63,
1238,
360,
66,
4213,
14,
923,
358,
199,
199,
793,
275,
2050,
14,
5572,
360,
29645,
358,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
298,
3110,
370,
7604,
543,
14409,
24699,
3050,
2122,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
4899,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
4899,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
7609,
370,
1678,
3130,
267,
776,
398,
1798,
14,
525,
63,
2094,
8,
288,
2850,
8419,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
8419,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
10857,
370,
1678,
3130,
267,
776,
398,
1798,
14,
525,
63,
2094,
8,
288,
2850,
10430,
297,
288,
730,
29,
442,
12,
288,
2053,
534,
10430,
297,
288,
9237,
31468,
288,
950,
29,
17,
12,
288,
1720,
534,
3259,
402,
10857,
370,
1678,
3130,
267,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
327,
2494,
20385,
267,
340,
1511,
459,
4899,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
4899,
29,
1419,
459,
4899,
995,
10857,
29,
17,
9,
267,
916,
1511,
459,
8419,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
8419,
29,
1419,
459,
8419,
995,
9395,
29,
21,
9,
267,
916,
1511,
459,
10430,
2565,
288,
3920,
275,
7137,
14,
2131,
342,
446,
2197,
14,
7473,
8,
10430,
29,
1419,
459,
10430,
995,
4696,
29,
21,
9,
267,
587,
26,
288,
3920,
275,
488,
398,
327,
22407,
8028,
83,
267,
291,
14,
2703,
14,
952,
480,
11135,
316,
8028,
83,
687,
14409,
24699,
12594,
267,
6037,
12,
5501,
1526,
275,
2202,
14,
26682,
17611,
63,
2632,
14,
5312,
16591,
358,
267,
1166,
275,
5310,
16,
5995,
66,
4213,
15,
5484,
1674,
908,
8,
6520,
9,
267,
2323,
275,
469,
288,
283,
11626,
356,
283,
3264,
469,
16,
5285,
908,
8,
1418,
9,
267,
789,
267,
2034,
275,
413,
267,
1862,
275,
469,
288,
283,
1541,
59,
1205,
61,
356,
8028,
14,
6305,
14,
2682,
12,
288,
283,
1541,
59,
5540,
363,
3308,
61,
356,
3920,
12,
288,
283,
1606,
59,
1955,
61,
356,
2034,
12,
267,
789,
267,
1177,
275,
4145,
14,
362,
8,
288,
1166,
12,
288,
2323,
29,
2139,
12,
288,
1862,
29,
1162,
12,
267,
776,
267,
1177,
14,
3730,
63,
509,
63,
1205,
342,
267,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
267,
307,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
835,
418,
267,
340,
307,
26,
288,
284,
275,
378,
288,
6497,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
5856,
418,
288,
1830,
2034,
2695,
6497,
26,
355,
1177,
275,
4145,
14,
362,
8,
490,
1166,
12,
490,
2323,
29,
2139,
12,
490,
1862,
29,
1162,
12,
355,
776,
355,
1177,
14,
3730,
63,
509,
63,
1205,
342,
355,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
355,
2974,
275,
1177,
63,
1001,
459,
576,
418,
355,
367,
1242,
315,
2974,
26,
490,
284,
847,
413,
490,
291,
14,
2703,
14,
4939,
342,
490,
291,
14,
2703,
14,
952,
480,
24993,
469,
16,
93,
402,
469,
17,
93,
8028,
83,
1396,
1674,
908,
8,
73,
12,
307,
395,
13401,
17115,
82,
358,
490,
1678,
63,
5484,
63,
504,
63,
1114,
4218,
14,
5814,
8,
1053,
9,
355,
2034,
847,
413,
355,
1862,
459,
1606,
59,
1955,
61,
418,
275,
2034,
288,
291,
14,
2703,
14,
952,
10804,
267,
291,
14,
2703,
14,
952,
480,
19920,
469,
16,
93,
8028,
83,
15848,
908,
8,
84,
430,
398,
327,
22407,
25031,
267,
291,
14,
2703,
14,
952,
480,
11135,
316,
25031,
687,
14409,
24699,
12594,
267,
6037,
12,
5501,
1526,
275,
2202,
14,
26682,
17611,
63,
2632,
14,
5312,
16591,
358,
267,
1166,
275,
5310,
16,
5995,
66,
4213,
15,
923,
1674,
908,
8,
6520,
9,
267,
2323,
275,
469,
288,
283,
11626,
356,
283,
3264,
469,
16,
5285,
908,
8,
1418,
9,
267,
789,
267,
2034,
275,
413,
267,
1862,
275,
469,
288,
283,
1541,
59,
1205,
61,
356,
5611,
14,
6305,
14,
2682,
12,
288,
283,
1541,
59,
5091,
363,
3308,
61,
356,
4233,
12,
288,
283,
1541,
59,
5540,
363,
3308,
61,
356,
3920,
12,
288,
283,
1606,
59,
1955,
61,
356,
2034,
12,
267,
789,
267,
1177,
275,
4145,
14,
362,
8,
288,
1166,
12,
288,
2323,
29,
2139,
12,
288,
1862,
29,
1162,
12,
267,
776,
267,
1177,
14,
3730,
63,
509,
63,
1205,
342,
267,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
267,
307,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
835,
418,
267,
340,
307,
26,
288,
284,
275,
378,
288,
6497,
275,
1177,
63,
1001,
459,
2024,
2545,
22793,
2545,
5856,
418,
288,
1830,
2034,
2695,
6497,
26,
355,
1177,
275,
4145,
14,
362,
8,
490,
1166,
12,
490,
2323,
29,
2139,
12,
490,
1862,
29,
1162,
12,
355,
776,
355,
1177,
14,
3730,
63,
509,
63,
1205,
342,
355,
1177,
63,
1001,
275,
1177,
14,
1001,
342,
355,
2974,
275,
1177,
63,
1001,
459,
576,
418,
355,
367,
1242,
315,
2974,
26,
490,
284,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cookbrite/flyingcloud
|
examples/flask-web-app/salt/app/application/flask_example_app/app.py
|
1
|
3120
|
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
import logging
import os
from StringIO import StringIO
from logging.handlers import RotatingFileHandler
import cv2
from PIL import Image
from flask import Flask, make_response, request, send_from_directory, jsonify, render_template, send_file
app = Flask(__name__, static_url_path='')
app.config.update(
DEBUG=True,
)
# Generate a secret random key for the session
app.secret_key = os.urandom(24)
@app.route('/')
def index(name=None):
return render_template('index.html', name=name)
@app.route('/canny')
def canny():
# adapted from https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html#canny
img = cv2.imread('static/img/ship.jpg', 0)
edges = cv2.Canny(img, 100, 200)
im = Image.fromarray(edges)
img2 = StringIO()
im.save(img2, format="png")
img2.seek(0)
return send_file(img2, mimetype='image/png')
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.errorhandler(403)
def not_authorized():
message = {
'status': 403,
'message': 'Not authorized: ' + request.url,
}
response = jsonify(message)
response.status_code = 403
return response
@app.errorhandler(404)
def not_found(error=None):
message = {
'status': 404,
'message': 'Not Found: ' + request.url,
}
response = jsonify(message)
response.status_code = 404
return response
@app.route('/static/<path:path>')
def send_web(path):
return send_from_directory('static', path)
@app.errorhandler(500)
def internal_error(exception):
app.logger.error(exception)
return render_template('500.html'), 500
@app.errorhandler(400)
def internal_error(exception):
app.logger.exception("Error: %s", exception)
return render_template('400.html'), 500
def configure_logging():
namespace = {}
namespace['base_dir'] = os.path.abspath(os.path.dirname(__file__))
namespace['logfile'] = os.path.join(namespace['base_dir'], "flask-example.log")
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
rotating_file_handler = RotatingFileHandler(namespace['logfile'], maxBytes=10000, backupCount=20)
rotating_file_handler.setLevel(logging.DEBUG)
console_stream_handler = logging.StreamHandler()
console_stream_handler.setLevel(logging.DEBUG if namespace.get('debug') else logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_stream_handler.setFormatter(formatter)
rotating_file_handler.setFormatter(formatter)
logger.addHandler(console_stream_handler)
logger.addHandler(rotating_file_handler)
return logger, rotating_file_handler, console_stream_handler
if __name__ == '__main__':
logger, file_handler, stream_handler = configure_logging()
app.logger.addHandler(file_handler)
app.logger.addHandler(stream_handler)
app.run(
host="0.0.0.0",
port=int("8001"),
)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
870,
63,
1593,
199,
199,
646,
2050,
199,
646,
747,
199,
504,
5228,
492,
5228,
199,
504,
2050,
14,
5586,
492,
20423,
1958,
21982,
199,
199,
646,
6277,
18,
199,
504,
14937,
492,
6047,
199,
504,
7209,
492,
16704,
12,
1852,
63,
1310,
12,
1056,
12,
3222,
63,
504,
63,
3619,
12,
23819,
12,
3795,
63,
1160,
12,
3222,
63,
493,
199,
199,
571,
275,
16704,
3460,
354,
3108,
2955,
63,
633,
63,
515,
13275,
199,
571,
14,
888,
14,
873,
8,
267,
10990,
29,
549,
12,
199,
9,
199,
199,
3,
7958,
282,
7565,
2196,
790,
367,
314,
2351,
199,
571,
14,
4731,
63,
498,
275,
747,
14,
22776,
8,
1194,
9,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
8,
354,
29,
403,
304,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
297,
536,
29,
354,
9,
421,
199,
32,
571,
14,
4449,
2336,
67,
1189,
89,
358,
199,
318,
883,
9745,
837,
272,
327,
26266,
687,
4178,
921,
1490,
5107,
13,
1548,
13,
84,
337,
293,
2551,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
647,
63,
23561,
83,
15,
647,
63,
4060,
4687,
15,
647,
63,
67,
1189,
89,
15,
647,
63,
67,
1189,
89,
14,
1360,
3,
67,
1189,
89,
272,
6050,
275,
6277,
18,
14,
1017,
739,
360,
1986,
15,
4060,
15,
3319,
14,
8476,
297,
378,
9,
272,
8207,
275,
6277,
18,
14,
35,
1189,
89,
8,
4060,
12,
2948,
12,
1926,
9,
272,
3416,
275,
6047,
14,
504,
1144,
8,
6929,
9,
272,
6050,
18,
275,
5228,
342,
272,
3416,
14,
2117,
8,
4060,
18,
12,
1475,
628,
4524,
531,
272,
6050,
18,
14,
5507,
8,
16,
9,
272,
372,
3222,
63,
493,
8,
4060,
18,
12,
12200,
534,
1569,
15,
4524,
358,
421,
199,
318,
4370,
63,
493,
8,
1501,
304,
272,
372,
7815,
315,
1788,
436,
971,
1779,
1788,
14,
13490,
14078,
413,
2788,
17,
61,
315,
27805,
1149,
63,
18451,
421,
199,
32,
571,
14,
705,
2232,
8,
13353,
9,
199,
318,
440,
63,
11497,
837,
272,
1245,
275,
469,
267,
283,
1205,
356,
13269,
12,
267,
283,
1188,
356,
283,
1763,
18788,
26,
283,
435,
1056,
14,
633,
12,
272,
789,
272,
1177,
275,
23819,
8,
1188,
9,
272,
1177,
14,
1205,
63,
600,
275,
13269,
272,
372,
1177,
421,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
440,
63,
4214,
8,
705,
29,
403,
304,
272,
1245,
275,
469,
267,
283,
1205,
356,
7901,
12,
267,
283,
1188,
356,
283,
1763,
2643,
26,
283,
435,
1056,
14,
633,
12,
272,
789,
272,
1177,
275,
23819,
8,
1188,
9,
272,
1177,
14,
1205,
63,
600,
275,
7901,
272,
372,
1177,
421,
199,
32,
571,
14,
4449,
2336,
1986,
8316,
515,
26,
515,
5971,
199,
318,
3222,
63,
2520,
8,
515,
304,
272,
372,
3222,
63,
504,
63,
3619,
360,
1986,
297,
931,
9,
421,
199,
32,
571,
14,
705,
2232,
8,
5783,
9,
199,
318,
5007,
63,
705,
8,
1971,
304,
272,
1145,
14,
2921,
14,
705,
8,
1971,
9,
272,
372,
3795,
63,
1160,
360,
5783,
14,
1360,
659,
6891,
421,
199,
32,
571,
14,
705,
2232,
8,
5303,
9,
199,
318,
5007,
63,
705,
8,
1971,
304,
272,
1145,
14,
2921,
14,
1971,
480,
547,
26,
450,
83,
401,
1919,
9,
272,
372,
3795,
63,
1160,
360,
5303,
14,
1360,
659,
6891,
421,
199,
318,
7908,
63,
4806,
837,
272,
3231,
275,
1052,
272,
3231,
459,
1095,
63,
694,
418,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
3231,
459,
12804,
418,
275,
747,
14,
515,
14,
904,
8,
3251,
459,
1095,
63,
694,
995,
298,
15720,
13,
2694,
14,
793,
531,
272,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
272,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
272,
7513,
1958,
63,
493,
63,
2232,
275,
20423,
1958,
21982,
8,
3251,
459,
12804,
995,
1390,
5571,
29,
9943,
12,
6902,
2353,
29,
1165,
9,
272,
7513,
1958,
63,
493,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
272,
8559,
63,
1745,
63,
2232,
275,
2050,
14,
22482,
342,
272,
8559,
63,
1745,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
340,
3231,
14,
362,
360,
1757,
358,
587,
2050,
14,
4531,
9,
272,
9698,
275,
2050,
14,
7772,
24713,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
272,
8559,
63,
1745,
63,
2232,
14,
26076,
8,
8911,
9,
272,
7513,
1958,
63,
493,
63,
2232,
14,
26076,
8,
8911,
9,
272,
2512,
14,
18826,
8,
6614,
63,
1745,
63,
2232,
9,
272,
2512,
14,
18826,
8,
4571,
1958,
63,
493,
63,
2232,
9,
272,
372,
2512,
12,
7513,
1958,
63,
493,
63,
2232,
12,
8559,
63,
1745,
63,
2232,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2512,
12,
570,
63,
2232,
12,
2547,
63,
2232,
275,
7908,
63,
4806,
342,
272,
1145,
14,
2921,
14,
18826,
8,
493,
63,
2232,
9,
272,
1145,
14,
2921,
14,
18826,
8,
1745,
63,
2232,
9,
272,
1145,
14,
1065,
8,
288,
1591,
628,
16,
14,
16,
14,
16,
14,
16,
401,
288,
1844,
29,
442,
480,
24,
4587,
1288,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
870,
63,
1593,
199,
199,
646,
2050,
199,
646,
747,
199,
504,
5228,
492,
5228,
199,
504,
2050,
14,
5586,
492,
20423,
1958,
21982,
199,
199,
646,
6277,
18,
199,
504,
14937,
492,
6047,
199,
504,
7209,
492,
16704,
12,
1852,
63,
1310,
12,
1056,
12,
3222,
63,
504,
63,
3619,
12,
23819,
12,
3795,
63,
1160,
12,
3222,
63,
493,
199,
199,
571,
275,
16704,
3460,
354,
3108,
2955,
63,
633,
63,
515,
13275,
199,
571,
14,
888,
14,
873,
8,
267,
10990,
29,
549,
12,
199,
9,
199,
199,
3,
7958,
282,
7565,
2196,
790,
367,
314,
2351,
199,
571,
14,
4731,
63,
498,
275,
747,
14,
22776,
8,
1194,
9,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
8,
354,
29,
403,
304,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
297,
536,
29,
354,
9,
421,
199,
32,
571,
14,
4449,
2336,
67,
1189,
89,
358,
199,
318,
883,
9745,
837,
272,
327,
26266,
687,
4178,
921,
1490,
5107,
13,
1548,
13,
84,
337,
293,
2551,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
647,
63,
23561,
83,
15,
647,
63,
4060,
4687,
15,
647,
63,
67,
1189,
89,
15,
647,
63,
67,
1189,
89,
14,
1360,
3,
67,
1189,
89,
272,
6050,
275,
6277,
18,
14,
1017,
739,
360,
1986,
15,
4060,
15,
3319,
14,
8476,
297,
378,
9,
272,
8207,
275,
6277,
18,
14,
35,
1189,
89,
8,
4060,
12,
2948,
12,
1926,
9,
272,
3416,
275,
6047,
14,
504,
1144,
8,
6929,
9,
272,
6050,
18,
275,
5228,
342,
272,
3416,
14,
2117,
8,
4060,
18,
12,
1475,
628,
4524,
531,
272,
6050,
18,
14,
5507,
8,
16,
9,
272,
372,
3222,
63,
493,
8,
4060,
18,
12,
12200,
534,
1569,
15,
4524,
358,
421,
199,
318,
4370,
63,
493,
8,
1501,
304,
272,
372,
7815,
315,
1788,
436,
971,
1779,
1788,
14,
13490,
14078,
413,
2788,
17,
61,
315,
27805,
1149,
63,
18451,
421,
199,
32,
571,
14,
705,
2232,
8,
13353,
9,
199,
318,
440,
63,
11497,
837,
272,
1245,
275,
469,
267,
283,
1205,
356,
13269,
12,
267,
283,
1188,
356,
283,
1763,
18788,
26,
283,
435,
1056,
14,
633,
12,
272,
789,
272,
1177,
275,
23819,
8,
1188,
9,
272,
1177,
14,
1205,
63,
600,
275,
13269,
272,
372,
1177,
421,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
440,
63,
4214,
8,
705,
29,
403,
304,
272,
1245,
275,
469,
267,
283,
1205,
356,
7901,
12,
267,
283,
1188,
356,
283,
1763,
2643,
26,
283,
435,
1056,
14,
633,
12,
272,
789,
272,
1177,
275,
23819,
8,
1188,
9,
272,
1177,
14,
1205,
63,
600,
275,
7901,
272,
372,
1177,
421,
199,
32,
571,
14,
4449,
2336,
1986,
8316,
515,
26,
515,
5971,
199,
318,
3222,
63,
2520,
8,
515,
304,
272,
372,
3222,
63,
504,
63,
3619,
360,
1986,
297,
931,
9,
421,
199,
32,
571,
14,
705,
2232,
8,
5783,
9,
199,
318,
5007,
63,
705,
8,
1971,
304,
272,
1145,
14,
2921,
14,
705,
8,
1971,
9,
272,
372,
3795,
63,
1160,
360,
5783,
14,
1360,
659,
6891,
421,
199,
32,
571,
14,
705,
2232,
8,
5303,
9,
199,
318,
5007,
63,
705,
8,
1971,
304,
272,
1145,
14,
2921,
14,
1971,
480,
547,
26,
450,
83,
401,
1919,
9,
272,
372,
3795,
63,
1160,
360,
5303,
14,
1360,
659,
6891,
421,
199,
318,
7908,
63,
4806,
837,
272,
3231,
275,
1052,
272,
3231,
459,
1095,
63,
694,
418,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
3231,
459,
12804,
418,
275,
747,
14,
515,
14,
904,
8,
3251,
459,
1095,
63,
694,
995,
298,
15720,
13,
2694,
14,
793,
531,
272,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
272,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
272,
7513,
1958,
63,
493,
63,
2232,
275,
20423,
1958,
21982,
8,
3251,
459,
12804,
995,
1390,
5571,
29,
9943,
12,
6902,
2353,
29,
1165,
9,
272,
7513,
1958,
63,
493,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
272,
8559,
63,
1745,
63,
2232,
275,
2050,
14,
22482,
342,
272,
8559,
63,
1745,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
340,
3231,
14,
362,
360,
1757,
358,
587,
2050,
14,
4531,
9,
272,
9698,
275,
2050,
14,
7772,
24713,
18331,
9,
83,
446,
2818,
354,
9,
83,
446,
2818,
20056,
9,
83,
446,
2818,
1188,
9,
83,
358,
272,
8559,
63,
1745,
63,
2232,
14,
26076,
8,
8911,
9,
272,
7513,
1958,
63,
493,
63,
2232,
14,
26076,
8,
8911,
9,
272,
2512,
14,
18826,
8,
6614,
63,
1745,
63,
2232,
9,
272,
2512,
14,
18826,
8,
4571,
1958,
63,
493,
63,
2232,
9,
272,
372,
2512,
12,
7513,
1958,
63,
493,
63,
2232,
12,
8559,
63,
1745,
63,
2232,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2512,
12,
570,
63,
2232,
12,
2547,
63,
2232,
275,
7908,
63,
4806,
342,
272,
1145,
14,
2921,
14,
18826,
8,
493,
63,
2232,
9,
272,
1145,
14,
2921,
14,
18826,
8,
1745,
63,
2232,
9,
272,
1145,
14,
1065,
8,
288,
1591,
628,
16,
14,
16,
14,
16,
14,
16,
401,
288,
1844,
29,
442,
480,
24,
4587,
1288,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
grayjay/aenea
|
client/test/test_proxy_actions.py
|
7
|
5890
|
# This file is part of Aenea
#
# Aenea is free software: you can redistribute it and/or modify it under
# the terms of version 3 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# Aenea 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 Aenea. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (2014) Alex Roper
# Alex Roper <alex@aroper.net>
import unittest
import mock
from aenea.proxy_actions import *
class TestActions(unittest.TestCase):
@mock.patch('aenea.communications.server')
def test_key(self, comm):
ProxyKey('H').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'H', 'count': 1, 'modifiers': []})])
ProxyKey('H, e').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'H', 'count': 1, 'modifiers': []}),
('key_press', (), {'key': 'e', 'count': 1, 'modifiers': []})])
ProxyKey('Super_R').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'count': 1, 'modifiers': [], 'key': 'Super_R'})])
ProxyKey('c-home').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'count': 1, 'modifiers': ['control'], 'key': 'home'})])
ProxyKey('c-home:2').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'home', 'count': 2, 'modifiers': ['control']})])
ProxyKey('c-home:2/5').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'home', 'count': 2, 'modifiers': ['control']}),
('pause', (), {'amount': 0.05})])
ProxyKey('c-home/1:2/5').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'home', 'count': 2, 'count_delay': 0.01, 'modifiers': ['control']}),
('pause', (), {'amount': 0.05})])
ProxyKey('home').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'home', 'count': 1, 'modifiers': []})])
ProxyKey('home:2').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'home', 'count': 2, 'modifiers': []})])
ProxyKey('home:0').execute()
comm.execute_batch.assert_called_with([])
@mock.patch('aenea.communications.server')
def test_key_multiple_modifiers(self, comm):
ProxyKey('scawh-H').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'H', 'count': 1, 'modifiers': ['shift', 'control', 'alt', 'super', 'hyper']})])
@mock.patch('aenea.communications.server')
def test_key_manual(self, comm):
ProxyKey('a:up').execute()
comm.execute_batch.assert_called_with([('key_press', (), {'key': 'a', 'direction': 'up', 'modifiers': []})])
@mock.patch('aenea.communications.server')
def test_text(self, comm):
ProxyText('Hello world!').execute()
comm.write_text.assert_called_with(text='Hello world!')
@mock.patch('aenea.communications.server')
def test_mouse_move(self, comm):
ProxyMouse('[3, 5]').execute()
comm.execute_batch.assert_called_with([('move_mouse', (), {'x': 3.0, 'y': 5.0, 'proportional': False, 'reference': 'absolute'})])
ProxyMouse('<7 9>').execute()
comm.execute_batch.assert_called_with([('move_mouse', (), {'x': 7.0, 'y': 9.0, 'proportional': False, 'reference': 'relative'})])
ProxyMouse('(3, 5)').execute()
comm.execute_batch.assert_called_with([('move_mouse', (), {'x': 3.0, 'y': 5.0, 'proportional': False, 'reference': 'relative_active'})])
ProxyMouse(','.join(['[3 5]'] * 3)).execute()
comm.execute_batch.assert_called_with([('move_mouse', (), {'x': 3.0, 'y': 5.0, 'proportional': False, 'reference': 'absolute'}),
('move_mouse', (), {'x': 3.0, 'y': 5.0, 'proportional': False, 'reference': 'absolute'}),
('move_mouse', (), {'x': 3.0, 'y': 5.0, 'proportional': False, 'reference': 'absolute'})])
@mock.patch('aenea.communications.server')
def test_mouse_click(self, comm):
ProxyMouse('left').execute()
comm.execute_batch.assert_called_with([('click_mouse', (), {'button': 'left', 'count': 1, 'count_delay': None, 'direction': 'click'})])
ProxyMouse('right').execute()
comm.execute_batch.assert_called_with([('click_mouse', (), {'button': 'right', 'count': 1, 'count_delay': None, 'direction': 'click'})])
ProxyMouse('wheelup:5').execute()
comm.execute_batch.assert_called_with([('click_mouse', (), {'button': 'wheelup', 'count': 5, 'count_delay': None, 'direction': 'click'})])
ProxyMouse('wheeldown:5/9').execute()
comm.execute_batch.assert_called_with([('click_mouse', (), {'button': 'wheeldown', 'count': 5, 'direction': 'click', 'count_delay': 0.09})])
@mock.patch('aenea.communications.server')
def test_drag(self, comm):
ProxyMouse('middle:up/5').execute()
comm.execute_batch.assert_called_with([('click_mouse', (), {'button': 'middle', 'direction': 'up', 'count_delay': 0.05, 'count': 1})])
@mock.patch('aenea.communications.server')
def test_phantom_click(self, comm):
ProxyMousePhantomClick('(78, 114), left').execute()
comm.execute_batch.assert_called_with([('move_mouse', (), {'y': 114.0, 'x': 78.0, 'phantom': 'left', 'reference': 'relative_active', 'proportional': False})])
if __name__ == '__main__':
unittest.main()
|
lgpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
437,
287,
4489,
199,
3,
199,
3,
437,
287,
4489,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
1015,
650,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
437,
287,
4489,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
199,
3,
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,
437,
287,
4489,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1898,
334,
7280,
9,
22986,
820,
2262,
199,
3,
22986,
820,
2262,
665,
24421,
32,
285,
2262,
14,
846,
30,
199,
199,
646,
2882,
199,
646,
1683,
199,
199,
504,
282,
287,
4489,
14,
3280,
63,
3723,
492,
627,
421,
199,
533,
1379,
9303,
8,
2796,
14,
1746,
304,
272,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
40,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
40,
12,
325,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
8688,
6901,
661,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
69,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
11823,
63,
50,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
835,
356,
413,
12,
283,
17431,
356,
990,
283,
498,
356,
283,
11823,
63,
50,
3071,
566,
398,
12373,
1197,
360,
67,
13,
4219,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
835,
356,
413,
12,
283,
17431,
356,
788,
2785,
995,
283,
498,
356,
283,
4219,
3071,
566,
398,
12373,
1197,
360,
67,
13,
4219,
26,
18,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
788,
2785,
13678,
566,
398,
12373,
1197,
360,
67,
13,
4219,
26,
18,
15,
21,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
788,
2785,
418,
8688,
6901,
661,
11241,
297,
11969,
791,
4606,
356,
378,
14,
1717,
1552,
566,
398,
12373,
1197,
360,
67,
13,
4219,
15,
17,
26,
18,
15,
21,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
835,
63,
5814,
356,
378,
14,
614,
12,
283,
17431,
356,
788,
2785,
418,
8688,
6901,
661,
11241,
297,
11969,
791,
4606,
356,
378,
14,
1717,
1552,
566,
398,
12373,
1197,
360,
4219,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
4219,
26,
18,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
4219,
26,
16,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
4157,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
63,
6048,
63,
17431,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
7101,
2191,
13,
40,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
788,
4723,
297,
283,
2785,
297,
283,
4478,
297,
283,
4792,
297,
283,
9547,
13678,
566,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
63,
9285,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
65,
26,
384,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
65,
297,
283,
6874,
356,
283,
384,
297,
283,
17431,
356,
942,
1552,
566,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
505,
8,
277,
12,
1923,
304,
267,
12373,
1872,
360,
6257,
6701,
1,
1959,
2526,
342,
267,
1923,
14,
952,
63,
505,
14,
479,
63,
3527,
63,
1045,
8,
505,
534,
6257,
6701,
10916,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
10544,
63,
1185,
8,
277,
12,
1923,
304,
267,
12373,
17141,
11894,
19,
12,
959,
61,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
1185,
63,
10544,
297,
11969,
791,
88,
356,
650,
14,
16,
12,
283,
89,
356,
959,
14,
16,
12,
283,
4469,
15029,
279,
356,
756,
12,
283,
4443,
356,
283,
6116,
3071
] |
[
961,
570,
365,
1777,
402,
437,
287,
4489,
199,
3,
199,
3,
437,
287,
4489,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
1015,
650,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
437,
287,
4489,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
6401,
1696,
1684,
199,
3,
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,
437,
287,
4489,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1898,
334,
7280,
9,
22986,
820,
2262,
199,
3,
22986,
820,
2262,
665,
24421,
32,
285,
2262,
14,
846,
30,
199,
199,
646,
2882,
199,
646,
1683,
199,
199,
504,
282,
287,
4489,
14,
3280,
63,
3723,
492,
627,
421,
199,
533,
1379,
9303,
8,
2796,
14,
1746,
304,
272,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
40,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
40,
12,
325,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
8688,
6901,
661,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
69,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
11823,
63,
50,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
835,
356,
413,
12,
283,
17431,
356,
990,
283,
498,
356,
283,
11823,
63,
50,
3071,
566,
398,
12373,
1197,
360,
67,
13,
4219,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
835,
356,
413,
12,
283,
17431,
356,
788,
2785,
995,
283,
498,
356,
283,
4219,
3071,
566,
398,
12373,
1197,
360,
67,
13,
4219,
26,
18,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
788,
2785,
13678,
566,
398,
12373,
1197,
360,
67,
13,
4219,
26,
18,
15,
21,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
788,
2785,
418,
8688,
6901,
661,
11241,
297,
11969,
791,
4606,
356,
378,
14,
1717,
1552,
566,
398,
12373,
1197,
360,
67,
13,
4219,
15,
17,
26,
18,
15,
21,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
835,
63,
5814,
356,
378,
14,
614,
12,
283,
17431,
356,
788,
2785,
418,
8688,
6901,
661,
11241,
297,
11969,
791,
4606,
356,
378,
14,
1717,
1552,
566,
398,
12373,
1197,
360,
4219,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
4219,
26,
18,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
4219,
297,
283,
835,
356,
499,
12,
283,
17431,
356,
942,
1552,
566,
398,
12373,
1197,
360,
4219,
26,
16,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
4157,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
63,
6048,
63,
17431,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
7101,
2191,
13,
40,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
40,
297,
283,
835,
356,
413,
12,
283,
17431,
356,
788,
4723,
297,
283,
2785,
297,
283,
4478,
297,
283,
4792,
297,
283,
9547,
13678,
566,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
498,
63,
9285,
8,
277,
12,
1923,
304,
267,
12373,
1197,
360,
65,
26,
384,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
498,
63,
2915,
297,
11969,
791,
498,
356,
283,
65,
297,
283,
6874,
356,
283,
384,
297,
283,
17431,
356,
942,
1552,
566,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
505,
8,
277,
12,
1923,
304,
267,
12373,
1872,
360,
6257,
6701,
1,
1959,
2526,
342,
267,
1923,
14,
952,
63,
505,
14,
479,
63,
3527,
63,
1045,
8,
505,
534,
6257,
6701,
10916,
339,
768,
1805,
14,
2068,
360,
65,
287,
4489,
14,
9203,
1298,
14,
1000,
358,
272,
347,
511,
63,
10544,
63,
1185,
8,
277,
12,
1923,
304,
267,
12373,
17141,
11894,
19,
12,
959,
61,
1959,
2526,
342,
267,
1923,
14,
2526,
63,
2912,
14,
479,
63,
3527,
63,
1045,
8318,
1185,
63,
10544,
297,
11969,
791,
88,
356,
650,
14,
16,
12,
283,
89,
356,
959,
14,
16,
12,
283,
4469,
15029,
279,
356,
756,
12,
283,
4443,
356,
283,
6116,
3071,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Ninjakow/TrueSkill
|
lib/numpy/f2py/tests/test_array_from_pyobj.py
|
82
|
22124
|
from __future__ import division, absolute_import, print_function
import unittest
import os
import sys
import copy
from numpy import (
array, alltrue, ndarray, zeros, dtype, intp, clongdouble
)
from numpy.testing import (
run_module_suite, assert_, assert_equal, SkipTest
)
from numpy.core.multiarray import typeinfo
import util
wrap = None
def setup():
"""
Build the required testing extension module
"""
global wrap
# Check compiler availability first
if not util.has_c_compiler():
raise SkipTest("No C compiler available")
if wrap is None:
config_code = """
config.add_extension('test_array_from_pyobj_ext',
sources=['wrapmodule.c', 'fortranobject.c'],
define_macros=[])
"""
d = os.path.dirname(__file__)
src = [os.path.join(d, 'src', 'array_from_pyobj', 'wrapmodule.c'),
os.path.join(d, '..', 'src', 'fortranobject.c'),
os.path.join(d, '..', 'src', 'fortranobject.h')]
wrap = util.build_module_distutils(src, config_code,
'test_array_from_pyobj_ext')
def flags_info(arr):
flags = wrap.array_attrs(arr)[6]
return flags2names(flags)
def flags2names(flags):
info = []
for flagname in ['CONTIGUOUS', 'FORTRAN', 'OWNDATA', 'ENSURECOPY',
'ENSUREARRAY', 'ALIGNED', 'NOTSWAPPED', 'WRITEABLE',
'UPDATEIFCOPY', 'BEHAVED', 'BEHAVED_RO',
'CARRAY', 'FARRAY'
]:
if abs(flags) & getattr(wrap, flagname, 0):
info.append(flagname)
return info
class Intent(object):
def __init__(self, intent_list=[]):
self.intent_list = intent_list[:]
flags = 0
for i in intent_list:
if i == 'optional':
flags |= wrap.F2PY_OPTIONAL
else:
flags |= getattr(wrap, 'F2PY_INTENT_' + i.upper())
self.flags = flags
def __getattr__(self, name):
name = name.lower()
if name == 'in_':
name = 'in'
return self.__class__(self.intent_list + [name])
def __str__(self):
return 'intent(%s)' % (','.join(self.intent_list))
def __repr__(self):
return 'Intent(%r)' % (self.intent_list)
def is_intent(self, *names):
for name in names:
if name not in self.intent_list:
return False
return True
def is_intent_exact(self, *names):
return len(self.intent_list) == len(names) and self.is_intent(*names)
intent = Intent()
_type_names = ['BOOL', 'BYTE', 'UBYTE', 'SHORT', 'USHORT', 'INT', 'UINT',
'LONG', 'ULONG', 'LONGLONG', 'ULONGLONG',
'FLOAT', 'DOUBLE', 'CFLOAT']
_cast_dict = {'BOOL': ['BOOL']}
_cast_dict['BYTE'] = _cast_dict['BOOL'] + ['BYTE']
_cast_dict['UBYTE'] = _cast_dict['BOOL'] + ['UBYTE']
_cast_dict['BYTE'] = ['BYTE']
_cast_dict['UBYTE'] = ['UBYTE']
_cast_dict['SHORT'] = _cast_dict['BYTE'] + ['UBYTE', 'SHORT']
_cast_dict['USHORT'] = _cast_dict['UBYTE'] + ['BYTE', 'USHORT']
_cast_dict['INT'] = _cast_dict['SHORT'] + ['USHORT', 'INT']
_cast_dict['UINT'] = _cast_dict['USHORT'] + ['SHORT', 'UINT']
_cast_dict['LONG'] = _cast_dict['INT'] + ['LONG']
_cast_dict['ULONG'] = _cast_dict['UINT'] + ['ULONG']
_cast_dict['LONGLONG'] = _cast_dict['LONG'] + ['LONGLONG']
_cast_dict['ULONGLONG'] = _cast_dict['ULONG'] + ['ULONGLONG']
_cast_dict['FLOAT'] = _cast_dict['SHORT'] + ['USHORT', 'FLOAT']
_cast_dict['DOUBLE'] = _cast_dict['INT'] + ['UINT', 'FLOAT', 'DOUBLE']
_cast_dict['CFLOAT'] = _cast_dict['FLOAT'] + ['CFLOAT']
# 32 bit system malloc typically does not provide the alignment required by
# 16 byte long double types this means the inout intent cannot be satisfied
# and several tests fail as the alignment flag can be randomly true or fals
# when numpy gains an aligned allocator the tests could be enabled again
if ((intp().dtype.itemsize != 4 or clongdouble().dtype.alignment <= 8) and
sys.platform != 'win32'):
_type_names.extend(['LONGDOUBLE', 'CDOUBLE', 'CLONGDOUBLE'])
_cast_dict['LONGDOUBLE'] = _cast_dict['LONG'] + \
['ULONG', 'FLOAT', 'DOUBLE', 'LONGDOUBLE']
_cast_dict['CLONGDOUBLE'] = _cast_dict['LONGDOUBLE'] + \
['CFLOAT', 'CDOUBLE', 'CLONGDOUBLE']
_cast_dict['CDOUBLE'] = _cast_dict['DOUBLE'] + ['CFLOAT', 'CDOUBLE']
class Type(object):
_type_cache = {}
def __new__(cls, name):
if isinstance(name, dtype):
dtype0 = name
name = None
for n, i in typeinfo.items():
if isinstance(i, tuple) and dtype0.type is i[-1]:
name = n
break
obj = cls._type_cache.get(name.upper(), None)
if obj is not None:
return obj
obj = object.__new__(cls)
obj._init(name)
cls._type_cache[name.upper()] = obj
return obj
def _init(self, name):
self.NAME = name.upper()
self.type_num = getattr(wrap, 'NPY_' + self.NAME)
assert_equal(self.type_num, typeinfo[self.NAME][1])
self.dtype = typeinfo[self.NAME][-1]
self.elsize = typeinfo[self.NAME][2] / 8
self.dtypechar = typeinfo[self.NAME][0]
def cast_types(self):
return [self.__class__(_m) for _m in _cast_dict[self.NAME]]
def all_types(self):
return [self.__class__(_m) for _m in _type_names]
def smaller_types(self):
bits = typeinfo[self.NAME][3]
types = []
for name in _type_names:
if typeinfo[name][3] < bits:
types.append(Type(name))
return types
def equal_types(self):
bits = typeinfo[self.NAME][3]
types = []
for name in _type_names:
if name == self.NAME:
continue
if typeinfo[name][3] == bits:
types.append(Type(name))
return types
def larger_types(self):
bits = typeinfo[self.NAME][3]
types = []
for name in _type_names:
if typeinfo[name][3] > bits:
types.append(Type(name))
return types
class Array(object):
def __init__(self, typ, dims, intent, obj):
self.type = typ
self.dims = dims
self.intent = intent
self.obj_copy = copy.deepcopy(obj)
self.obj = obj
# arr.dtypechar may be different from typ.dtypechar
self.arr = wrap.call(typ.type_num, dims, intent.flags, obj)
assert_(isinstance(self.arr, ndarray), repr(type(self.arr)))
self.arr_attr = wrap.array_attrs(self.arr)
if len(dims) > 1:
if self.intent.is_intent('c'):
assert_(intent.flags & wrap.F2PY_INTENT_C)
assert_(not self.arr.flags['FORTRAN'],
repr((self.arr.flags, getattr(obj, 'flags', None))))
assert_(self.arr.flags['CONTIGUOUS'])
assert_(not self.arr_attr[6] & wrap.FORTRAN)
else:
assert_(not intent.flags & wrap.F2PY_INTENT_C)
assert_(self.arr.flags['FORTRAN'])
assert_(not self.arr.flags['CONTIGUOUS'])
assert_(self.arr_attr[6] & wrap.FORTRAN)
if obj is None:
self.pyarr = None
self.pyarr_attr = None
return
if intent.is_intent('cache'):
assert_(isinstance(obj, ndarray), repr(type(obj)))
self.pyarr = array(obj).reshape(*dims).copy()
else:
self.pyarr = array(array(obj, dtype=typ.dtypechar).reshape(*dims),
order=self.intent.is_intent('c') and 'C' or 'F')
assert_(self.pyarr.dtype == typ,
repr((self.pyarr.dtype, typ)))
assert_(self.pyarr.flags['OWNDATA'], (obj, intent))
self.pyarr_attr = wrap.array_attrs(self.pyarr)
if len(dims) > 1:
if self.intent.is_intent('c'):
assert_(not self.pyarr.flags['FORTRAN'])
assert_(self.pyarr.flags['CONTIGUOUS'])
assert_(not self.pyarr_attr[6] & wrap.FORTRAN)
else:
assert_(self.pyarr.flags['FORTRAN'])
assert_(not self.pyarr.flags['CONTIGUOUS'])
assert_(self.pyarr_attr[6] & wrap.FORTRAN)
assert_(self.arr_attr[1] == self.pyarr_attr[1]) # nd
assert_(self.arr_attr[2] == self.pyarr_attr[2]) # dimensions
if self.arr_attr[1] <= 1:
assert_(self.arr_attr[3] == self.pyarr_attr[3],
repr((self.arr_attr[3], self.pyarr_attr[3],
self.arr.tobytes(), self.pyarr.tobytes()))) # strides
assert_(self.arr_attr[5][-2:] == self.pyarr_attr[5][-2:],
repr((self.arr_attr[5], self.pyarr_attr[5]))) # descr
assert_(self.arr_attr[6] == self.pyarr_attr[6],
repr((self.arr_attr[6], self.pyarr_attr[6],
flags2names(0 * self.arr_attr[6] - self.pyarr_attr[6]),
flags2names(self.arr_attr[6]), intent))) # flags
if intent.is_intent('cache'):
assert_(self.arr_attr[5][3] >= self.type.elsize,
repr((self.arr_attr[5][3], self.type.elsize)))
else:
assert_(self.arr_attr[5][3] == self.type.elsize,
repr((self.arr_attr[5][3], self.type.elsize)))
assert_(self.arr_equal(self.pyarr, self.arr))
if isinstance(self.obj, ndarray):
if typ.elsize == Type(obj.dtype).elsize:
if not intent.is_intent('copy') and self.arr_attr[1] <= 1:
assert_(self.has_shared_memory())
def arr_equal(self, arr1, arr2):
if arr1.shape != arr2.shape:
return False
s = arr1 == arr2
return alltrue(s.flatten())
def __str__(self):
return str(self.arr)
def has_shared_memory(self):
"""Check that created array shares data with input array.
"""
if self.obj is self.arr:
return True
if not isinstance(self.obj, ndarray):
return False
obj_attr = wrap.array_attrs(self.obj)
return obj_attr[0] == self.arr_attr[0]
class test_intent(unittest.TestCase):
def test_in_out(self):
assert_equal(str(intent.in_.out), 'intent(in,out)')
assert_(intent.in_.c.is_intent('c'))
assert_(not intent.in_.c.is_intent_exact('c'))
assert_(intent.in_.c.is_intent_exact('c', 'in'))
assert_(intent.in_.c.is_intent_exact('in', 'c'))
assert_(not intent.in_.is_intent('c'))
class _test_shared_memory:
num2seq = [1, 2]
num23seq = [[1, 2, 3], [4, 5, 6]]
def test_in_from_2seq(self):
a = self.array([2], intent.in_, self.num2seq)
assert_(not a.has_shared_memory())
def test_in_from_2casttype(self):
for t in self.type.cast_types():
obj = array(self.num2seq, dtype=t.dtype)
a = self.array([len(self.num2seq)], intent.in_, obj)
if t.elsize == self.type.elsize:
assert_(
a.has_shared_memory(), repr((self.type.dtype, t.dtype)))
else:
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_inout_2seq(self):
obj = array(self.num2seq, dtype=self.type.dtype)
a = self.array([len(self.num2seq)], intent.inout, obj)
assert_(a.has_shared_memory())
try:
a = self.array([2], intent.in_.inout, self.num2seq)
except TypeError as msg:
if not str(msg).startswith('failed to initialize intent'
'(inout|inplace|cache) array'):
raise
else:
raise SystemError('intent(inout) should have failed on sequence')
def test_f_inout_23seq(self):
obj = array(self.num23seq, dtype=self.type.dtype, order='F')
shape = (len(self.num23seq), len(self.num23seq[0]))
a = self.array(shape, intent.in_.inout, obj)
assert_(a.has_shared_memory())
obj = array(self.num23seq, dtype=self.type.dtype, order='C')
shape = (len(self.num23seq), len(self.num23seq[0]))
try:
a = self.array(shape, intent.in_.inout, obj)
except ValueError as msg:
if not str(msg).startswith('failed to initialize intent'
'(inout) array'):
raise
else:
raise SystemError(
'intent(inout) should have failed on improper array')
def test_c_inout_23seq(self):
obj = array(self.num23seq, dtype=self.type.dtype)
shape = (len(self.num23seq), len(self.num23seq[0]))
a = self.array(shape, intent.in_.c.inout, obj)
assert_(a.has_shared_memory())
def test_in_copy_from_2casttype(self):
for t in self.type.cast_types():
obj = array(self.num2seq, dtype=t.dtype)
a = self.array([len(self.num2seq)], intent.in_.copy, obj)
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_c_in_from_23seq(self):
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_, self.num23seq)
assert_(not a.has_shared_memory())
def test_in_from_23casttype(self):
for t in self.type.cast_types():
obj = array(self.num23seq, dtype=t.dtype)
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_, obj)
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_f_in_from_23casttype(self):
for t in self.type.cast_types():
obj = array(self.num23seq, dtype=t.dtype, order='F')
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_, obj)
if t.elsize == self.type.elsize:
assert_(a.has_shared_memory(), repr(t.dtype))
else:
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_c_in_from_23casttype(self):
for t in self.type.cast_types():
obj = array(self.num23seq, dtype=t.dtype)
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_.c, obj)
if t.elsize == self.type.elsize:
assert_(a.has_shared_memory(), repr(t.dtype))
else:
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_f_copy_in_from_23casttype(self):
for t in self.type.cast_types():
obj = array(self.num23seq, dtype=t.dtype, order='F')
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_.copy, obj)
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_c_copy_in_from_23casttype(self):
for t in self.type.cast_types():
obj = array(self.num23seq, dtype=t.dtype)
a = self.array([len(self.num23seq), len(self.num23seq[0])],
intent.in_.c.copy, obj)
assert_(not a.has_shared_memory(), repr(t.dtype))
def test_in_cache_from_2casttype(self):
for t in self.type.all_types():
if t.elsize != self.type.elsize:
continue
obj = array(self.num2seq, dtype=t.dtype)
shape = (len(self.num2seq),)
a = self.array(shape, intent.in_.c.cache, obj)
assert_(a.has_shared_memory(), repr(t.dtype))
a = self.array(shape, intent.in_.cache, obj)
assert_(a.has_shared_memory(), repr(t.dtype))
obj = array(self.num2seq, dtype=t.dtype, order='F')
a = self.array(shape, intent.in_.c.cache, obj)
assert_(a.has_shared_memory(), repr(t.dtype))
a = self.array(shape, intent.in_.cache, obj)
assert_(a.has_shared_memory(), repr(t.dtype))
try:
a = self.array(shape, intent.in_.cache, obj[::-1])
except ValueError as msg:
if not str(msg).startswith('failed to initialize'
' intent(cache) array'):
raise
else:
raise SystemError(
'intent(cache) should have failed on multisegmented array')
def test_in_cache_from_2casttype_failure(self):
for t in self.type.all_types():
if t.elsize >= self.type.elsize:
continue
obj = array(self.num2seq, dtype=t.dtype)
shape = (len(self.num2seq),)
try:
self.array(shape, intent.in_.cache, obj) # Should succeed
except ValueError as msg:
if not str(msg).startswith('failed to initialize'
' intent(cache) array'):
raise
else:
raise SystemError(
'intent(cache) should have failed on smaller array')
def test_cache_hidden(self):
shape = (2,)
a = self.array(shape, intent.cache.hide, None)
assert_(a.arr.shape == shape)
shape = (2, 3)
a = self.array(shape, intent.cache.hide, None)
assert_(a.arr.shape == shape)
shape = (-1, 3)
try:
a = self.array(shape, intent.cache.hide, None)
except ValueError as msg:
if not str(msg).startswith('failed to create intent'
'(cache|hide)|optional array'):
raise
else:
raise SystemError(
'intent(cache) should have failed on undefined dimensions')
def test_hidden(self):
shape = (2,)
a = self.array(shape, intent.hide, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
shape = (2, 3)
a = self.array(shape, intent.hide, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
assert_(a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS'])
shape = (2, 3)
a = self.array(shape, intent.c.hide, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
assert_(not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS'])
shape = (-1, 3)
try:
a = self.array(shape, intent.hide, None)
except ValueError as msg:
if not str(msg).startswith('failed to create intent'
'(cache|hide)|optional array'):
raise
else:
raise SystemError('intent(hide) should have failed'
' on undefined dimensions')
def test_optional_none(self):
shape = (2,)
a = self.array(shape, intent.optional, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
shape = (2, 3)
a = self.array(shape, intent.optional, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
assert_(a.arr.flags['FORTRAN'] and not a.arr.flags['CONTIGUOUS'])
shape = (2, 3)
a = self.array(shape, intent.c.optional, None)
assert_(a.arr.shape == shape)
assert_(a.arr_equal(a.arr, zeros(shape, dtype=self.type.dtype)))
assert_(not a.arr.flags['FORTRAN'] and a.arr.flags['CONTIGUOUS'])
def test_optional_from_2seq(self):
obj = self.num2seq
shape = (len(obj),)
a = self.array(shape, intent.optional, obj)
assert_(a.arr.shape == shape)
assert_(not a.has_shared_memory())
def test_optional_from_23seq(self):
obj = self.num23seq
shape = (len(obj), len(obj[0]))
a = self.array(shape, intent.optional, obj)
assert_(a.arr.shape == shape)
assert_(not a.has_shared_memory())
a = self.array(shape, intent.optional.c, obj)
assert_(a.arr.shape == shape)
assert_(not a.has_shared_memory())
def test_inplace(self):
obj = array(self.num23seq, dtype=self.type.dtype)
assert_(not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS'])
shape = obj.shape
a = self.array(shape, intent.inplace, obj)
assert_(obj[1][2] == a.arr[1][2], repr((obj, a.arr)))
a.arr[1][2] = 54
assert_(obj[1][2] == a.arr[1][2] ==
array(54, dtype=self.type.dtype), repr((obj, a.arr)))
assert_(a.arr is obj)
assert_(obj.flags['FORTRAN']) # obj attributes are changed inplace!
assert_(not obj.flags['CONTIGUOUS'])
def test_inplace_from_casttype(self):
for t in self.type.cast_types():
if t is self.type:
continue
obj = array(self.num23seq, dtype=t.dtype)
assert_(obj.dtype.type == t.dtype)
assert_(obj.dtype.type is not self.type.dtype)
assert_(not obj.flags['FORTRAN'] and obj.flags['CONTIGUOUS'])
shape = obj.shape
a = self.array(shape, intent.inplace, obj)
assert_(obj[1][2] == a.arr[1][2], repr((obj, a.arr)))
a.arr[1][2] = 54
assert_(obj[1][2] == a.arr[1][2] ==
array(54, dtype=self.type.dtype), repr((obj, a.arr)))
assert_(a.arr is obj)
assert_(obj.flags['FORTRAN']) # obj attributes changed inplace!
assert_(not obj.flags['CONTIGUOUS'])
assert_(obj.dtype.type is self.type.dtype) # obj changed inplace!
for t in _type_names:
exec('''\
class test_%s_gen(unittest.TestCase,
_test_shared_memory
):
def setUp(self):
self.type = Type(%r)
array = lambda self,dims,intent,obj: Array(Type(%r),dims,intent,obj)
''' % (t, t, t))
if __name__ == "__main__":
setup()
run_module_suite()
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
1331,
199,
199,
504,
2680,
492,
334,
272,
1625,
12,
1006,
2052,
12,
6800,
12,
10136,
12,
2152,
12,
315,
683,
12,
824,
951,
3157,
199,
9,
199,
504,
2680,
14,
4776,
492,
334,
272,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
18795,
199,
9,
199,
504,
2680,
14,
1018,
14,
23698,
492,
730,
815,
199,
646,
4884,
199,
199,
3823,
275,
488,
421,
199,
318,
3272,
837,
272,
408,
272,
6516,
314,
1415,
5343,
3329,
859,
339,
408,
272,
2288,
4816,
339,
327,
2670,
6365,
14962,
1642,
272,
340,
440,
4884,
14,
1989,
63,
67,
63,
5772,
837,
267,
746,
18795,
480,
1944,
445,
6365,
2808,
531,
339,
340,
4816,
365,
488,
26,
267,
1101,
63,
600,
275,
408,
267,
1101,
14,
525,
63,
3435,
360,
396,
63,
1144,
63,
504,
63,
29797,
63,
832,
297,
2490,
5274,
2968,
3823,
578,
14,
67,
297,
283,
18496,
785,
14,
67,
995,
2490,
5627,
63,
16358,
14285,
267,
408,
267,
366,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
267,
2928,
275,
359,
736,
14,
515,
14,
904,
8,
68,
12,
283,
2164,
297,
283,
1144,
63,
504,
63,
29797,
297,
283,
3823,
578,
14,
67,
659,
2049,
747,
14,
515,
14,
904,
8,
68,
12,
19155,
283,
2164,
297,
283,
18496,
785,
14,
67,
659,
2049,
747,
14,
515,
14,
904,
8,
68,
12,
19155,
283,
2164,
297,
283,
18496,
785,
14,
72,
5440,
267,
4816,
275,
4884,
14,
1506,
63,
578,
63,
13350,
8,
2164,
12,
1101,
63,
600,
12,
5644,
283,
396,
63,
1144,
63,
504,
63,
29797,
63,
832,
358,
421,
199,
318,
3285,
63,
815,
8,
5250,
304,
272,
3285,
275,
4816,
14,
1144,
63,
3288,
8,
5250,
2788,
22,
61,
272,
372,
3285,
18,
1247,
8,
2469,
9,
421,
199,
318,
3285,
18,
1247,
8,
2469,
304,
272,
2256,
275,
942,
272,
367,
3305,
354,
315,
788,
5801,
1277,
32504,
297,
283,
2707,
17433,
297,
283,
47,
3705,
3998,
297,
283,
8456,
3942,
16188,
297,
2151,
283,
8456,
3942,
12322,
297,
283,
15255,
1149,
297,
283,
4609,
8745,
7121,
1149,
297,
283,
10387,
2617,
297,
2151,
283,
10383,
4656,
16188,
297,
283,
6773,
40,
6087,
1149,
297,
283,
6773,
40,
6087,
1149,
63,
1092,
297,
2151,
283,
35,
12322,
297,
283,
38,
12322,
7,
2151,
16246,
267,
340,
2853,
8,
2469,
9,
1253,
2519,
8,
3823,
12,
3305,
354,
12,
378,
304,
288,
2256,
14,
740,
8,
4173,
354,
9,
272,
372,
2256,
421,
199,
533,
1010,
767,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
21020,
63,
513,
17894,
267,
291,
14,
17456,
63,
513,
275,
21020,
63,
513,
5873,
267,
3285,
275,
378,
267,
367,
284,
315,
21020,
63,
513,
26,
288,
340,
284,
508,
283,
4144,
356,
355,
3285,
8901,
4816,
14,
38,
18,
4521,
63,
21008,
288,
587,
26,
355,
3285,
8901,
2519,
8,
3823,
12,
283,
38,
18,
4521,
63,
2919,
1309,
8650,
435,
284,
14,
4142,
1012,
267,
291,
14,
2469,
275,
3285,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
536,
275,
536,
14,
2325,
342,
267,
340,
536,
508,
283,
262,
63,
356,
288,
536,
275,
283,
262,
7,
267,
372,
291,
855,
533,
721,
277,
14,
17456,
63,
513,
435,
359,
354,
566,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
17456,
4042,
83,
3171,
450,
334,
26409,
904,
8,
277,
14,
17456,
63,
513,
430,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
607,
767,
4042,
82,
3171,
450,
334,
277,
14,
17456,
63,
513,
9,
339,
347,
365,
63,
17456,
8,
277,
12,
627,
1247,
304,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
17456,
63,
513,
26,
355,
372,
756,
267,
372,
715,
339,
347,
365,
63,
17456,
63,
7327,
8,
277,
12,
627,
1247,
304,
267,
372,
822,
8,
277,
14,
17456,
63,
513,
9,
508,
822,
8,
1247,
9,
436,
291,
14,
374,
63,
17456,
2031,
1247,
9,
199,
199,
17456,
275,
1010,
767,
342,
199,
199,
63,
466,
63,
1247,
275,
788,
16026,
297,
283,
19714,
297,
283,
2533,
57,
3727,
297,
283,
13003,
297,
283,
14527,
2596,
297,
283,
2919,
297,
283,
17459,
297,
2049,
283,
12375,
297,
283,
1293,
7770,
297,
283,
44,
615,
2226,
7770,
297,
283,
1293,
615,
2226,
7770,
297,
2049,
283,
11783,
297,
283,
14989,
297,
283,
5487,
10440,
418,
199,
199,
63,
2931,
63,
807,
275,
791,
16026,
356,
788,
16026,
12074,
199,
63,
2931,
63,
807,
459,
19714,
418,
275,
485,
2931,
63,
807,
459,
16026,
418,
435,
788,
19714,
418,
199,
63,
2931,
63,
807,
459,
2533,
57,
3727,
418,
275,
485,
2931,
63,
807,
459,
16026,
418,
435,
788,
2533,
57,
3727,
418,
199,
63,
2931,
63,
807,
459,
19714,
418,
275,
788,
19714,
418,
199,
63,
2931,
63,
807,
459,
2533,
57,
3727,
418,
275,
788,
2533,
57,
3727,
418,
199,
63,
2931,
63,
807,
459,
13003,
418,
275,
485,
2931,
63,
807,
459,
19714,
418,
435,
788,
2533,
57,
3727,
297,
283,
13003,
418,
199,
63,
2931,
63,
807,
459,
14527,
2596,
418,
275,
485,
2931,
63,
807,
459,
2533,
57,
3727,
418,
435,
788,
19714,
297,
283,
14527,
2596,
418,
199,
63,
2931,
63,
807,
459,
2919,
418,
275,
485,
2931,
63,
807,
459,
13003,
418,
435,
788,
14527,
2596,
297,
283,
2919,
418,
199,
63,
2931,
63,
807,
459,
17459,
418,
275,
485,
2931,
63,
807,
459,
14527,
2596,
418,
435,
788,
13003,
297,
283,
17459,
418,
199,
199,
63,
2931,
63,
807,
459,
12375,
418,
275,
485,
2931,
63,
807,
459,
2919,
418,
435,
788,
12375,
418,
199,
63,
2931,
63,
807,
459,
1293,
7770,
418,
275,
485,
2931,
63,
807,
459,
17459,
418,
435,
788,
1293,
7770,
418,
199,
199,
63,
2931,
63,
807,
459,
44,
615,
2226,
7770,
418,
275,
485,
2931,
63,
807,
459,
12375,
418,
435,
788,
44,
615,
2226,
7770,
418,
199,
63,
2931,
63,
807,
459,
1293,
615
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
1331,
199,
199,
504,
2680,
492,
334,
272,
1625,
12,
1006,
2052,
12,
6800,
12,
10136,
12,
2152,
12,
315,
683,
12,
824,
951,
3157,
199,
9,
199,
504,
2680,
14,
4776,
492,
334,
272,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
18795,
199,
9,
199,
504,
2680,
14,
1018,
14,
23698,
492,
730,
815,
199,
646,
4884,
199,
199,
3823,
275,
488,
421,
199,
318,
3272,
837,
272,
408,
272,
6516,
314,
1415,
5343,
3329,
859,
339,
408,
272,
2288,
4816,
339,
327,
2670,
6365,
14962,
1642,
272,
340,
440,
4884,
14,
1989,
63,
67,
63,
5772,
837,
267,
746,
18795,
480,
1944,
445,
6365,
2808,
531,
339,
340,
4816,
365,
488,
26,
267,
1101,
63,
600,
275,
408,
267,
1101,
14,
525,
63,
3435,
360,
396,
63,
1144,
63,
504,
63,
29797,
63,
832,
297,
2490,
5274,
2968,
3823,
578,
14,
67,
297,
283,
18496,
785,
14,
67,
995,
2490,
5627,
63,
16358,
14285,
267,
408,
267,
366,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
267,
2928,
275,
359,
736,
14,
515,
14,
904,
8,
68,
12,
283,
2164,
297,
283,
1144,
63,
504,
63,
29797,
297,
283,
3823,
578,
14,
67,
659,
2049,
747,
14,
515,
14,
904,
8,
68,
12,
19155,
283,
2164,
297,
283,
18496,
785,
14,
67,
659,
2049,
747,
14,
515,
14,
904,
8,
68,
12,
19155,
283,
2164,
297,
283,
18496,
785,
14,
72,
5440,
267,
4816,
275,
4884,
14,
1506,
63,
578,
63,
13350,
8,
2164,
12,
1101,
63,
600,
12,
5644,
283,
396,
63,
1144,
63,
504,
63,
29797,
63,
832,
358,
421,
199,
318,
3285,
63,
815,
8,
5250,
304,
272,
3285,
275,
4816,
14,
1144,
63,
3288,
8,
5250,
2788,
22,
61,
272,
372,
3285,
18,
1247,
8,
2469,
9,
421,
199,
318,
3285,
18,
1247,
8,
2469,
304,
272,
2256,
275,
942,
272,
367,
3305,
354,
315,
788,
5801,
1277,
32504,
297,
283,
2707,
17433,
297,
283,
47,
3705,
3998,
297,
283,
8456,
3942,
16188,
297,
2151,
283,
8456,
3942,
12322,
297,
283,
15255,
1149,
297,
283,
4609,
8745,
7121,
1149,
297,
283,
10387,
2617,
297,
2151,
283,
10383,
4656,
16188,
297,
283,
6773,
40,
6087,
1149,
297,
283,
6773,
40,
6087,
1149,
63,
1092,
297,
2151,
283,
35,
12322,
297,
283,
38,
12322,
7,
2151,
16246,
267,
340,
2853,
8,
2469,
9,
1253,
2519,
8,
3823,
12,
3305,
354,
12,
378,
304,
288,
2256,
14,
740,
8,
4173,
354,
9,
272,
372,
2256,
421,
199,
533,
1010,
767,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
21020,
63,
513,
17894,
267,
291,
14,
17456,
63,
513,
275,
21020,
63,
513,
5873,
267,
3285,
275,
378,
267,
367,
284,
315,
21020,
63,
513,
26,
288,
340,
284,
508,
283,
4144,
356,
355,
3285,
8901,
4816,
14,
38,
18,
4521,
63,
21008,
288,
587,
26,
355,
3285,
8901,
2519,
8,
3823,
12,
283,
38,
18,
4521,
63,
2919,
1309,
8650,
435,
284,
14,
4142,
1012,
267,
291,
14,
2469,
275,
3285,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
536,
275,
536,
14,
2325,
342,
267,
340,
536,
508,
283,
262,
63,
356,
288,
536,
275,
283,
262,
7,
267,
372,
291,
855,
533,
721,
277,
14,
17456,
63,
513,
435,
359,
354,
566,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
17456,
4042,
83,
3171,
450,
334,
26409,
904,
8,
277,
14,
17456,
63,
513,
430,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
607,
767,
4042,
82,
3171,
450,
334,
277,
14,
17456,
63,
513,
9,
339,
347,
365,
63,
17456,
8,
277,
12,
627,
1247,
304,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
17456,
63,
513,
26,
355,
372,
756,
267,
372,
715,
339,
347,
365,
63,
17456,
63,
7327,
8,
277,
12,
627,
1247,
304,
267,
372,
822,
8,
277,
14,
17456,
63,
513,
9,
508,
822,
8,
1247,
9,
436,
291,
14,
374,
63,
17456,
2031,
1247,
9,
199,
199,
17456,
275,
1010,
767,
342,
199,
199,
63,
466,
63,
1247,
275,
788,
16026,
297,
283,
19714,
297,
283,
2533,
57,
3727,
297,
283,
13003,
297,
283,
14527,
2596,
297,
283,
2919,
297,
283,
17459,
297,
2049,
283,
12375,
297,
283,
1293,
7770,
297,
283,
44,
615,
2226,
7770,
297,
283,
1293,
615,
2226,
7770,
297,
2049,
283,
11783,
297,
283,
14989,
297,
283,
5487,
10440,
418,
199,
199,
63,
2931,
63,
807,
275,
791,
16026,
356,
788,
16026,
12074,
199,
63,
2931,
63,
807,
459,
19714,
418,
275,
485,
2931,
63,
807,
459,
16026,
418,
435,
788,
19714,
418,
199,
63,
2931,
63,
807,
459,
2533,
57,
3727,
418,
275,
485,
2931,
63,
807,
459,
16026,
418,
435,
788,
2533,
57,
3727,
418,
199,
63,
2931,
63,
807,
459,
19714,
418,
275,
788,
19714,
418,
199,
63,
2931,
63,
807,
459,
2533,
57,
3727,
418,
275,
788,
2533,
57,
3727,
418,
199,
63,
2931,
63,
807,
459,
13003,
418,
275,
485,
2931,
63,
807,
459,
19714,
418,
435,
788,
2533,
57,
3727,
297,
283,
13003,
418,
199,
63,
2931,
63,
807,
459,
14527,
2596,
418,
275,
485,
2931,
63,
807,
459,
2533,
57,
3727,
418,
435,
788,
19714,
297,
283,
14527,
2596,
418,
199,
63,
2931,
63,
807,
459,
2919,
418,
275,
485,
2931,
63,
807,
459,
13003,
418,
435,
788,
14527,
2596,
297,
283,
2919,
418,
199,
63,
2931,
63,
807,
459,
17459,
418,
275,
485,
2931,
63,
807,
459,
14527,
2596,
418,
435,
788,
13003,
297,
283,
17459,
418,
199,
199,
63,
2931,
63,
807,
459,
12375,
418,
275,
485,
2931,
63,
807,
459,
2919,
418,
435,
788,
12375,
418,
199,
63,
2931,
63,
807,
459,
1293,
7770,
418,
275,
485,
2931,
63,
807,
459,
17459,
418,
435,
788,
1293,
7770,
418,
199,
199,
63,
2931,
63,
807,
459,
44,
615,
2226,
7770,
418,
275,
485,
2931,
63,
807,
459,
12375,
418,
435,
788,
44,
615,
2226,
7770,
418,
199,
63,
2931,
63,
807,
459,
1293,
615,
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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print_function, unicode_literals
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow, QMessageBox, QFileDialog, QGridLayout, QHBoxLayout, \
QVBoxLayout, QGroupBox, QCheckBox, QPushButton, QAction
from PatchEdit import *
from collections import OrderedDict
import copy
class PatchGUI(QMainWindow):
def __init__(self):
self.app = QApplication(sys.argv)
super(PatchGUI, self).__init__()
self.file_dic = OrderedDict()
self.orig_patch_obj_dic = OrderedDict()
self.patch_obj_dic = OrderedDict()
self.cb_dic = OrderedDict()
self.vBox_list = []
self.apply_button = None
self.disable_all_button = None
self.defaults_button = None
self.choose_files()
def choose_files(self):
fn_list, file_type = QFileDialog.getOpenFileNames(caption='Open File', filter='Kobo Patch (*.patch)')
if fn_list:
fd = {fn: None for fn in fn_list}
self.file_dic, error = read_patch_files(fd)
if error:
QMessageBox.critical(self, 'Read Error!', error)
else:
for (fn, patch_text) in iterDic(self.file_dic):
self.orig_patch_obj_dic[fn] = gen_patch_obj_list(fn, patch_text)
self.initialize()
else:
self.close()
def initialize(self):
self.patch_obj_dic = copy.deepcopy(self.orig_patch_obj_dic)
cont_index = 0
vBox = QVBoxLayout(self)
for (fn, patch_obj_list) in iterDic(self.patch_obj_dic):
self.cb_dic[fn] = []
gb = QGroupBox(fn)
cb_grid = QGridLayout(self)
# Create and add checkboxes to appropriate LabelFrame
for (cb_index, obj) in enumerate(patch_obj_list):
# Create checkbox variable and checkbox label for display
cb_name = ''
if obj.group:
cb_name = obj.name + '\n(' + obj.group + ')'
else:
cb_name = obj.name
# Create and add checkboxes to the LabelFrame, using the grid geometry manager
self.cb_dic[fn].append(QCheckBox(cb_name))
# Set initial state of checkboxes
if 'yes' in obj.status:
self.cb_dic[fn][cb_index].setCheckState(Qt.Checked)
else:
self.cb_dic[fn][cb_index].setCheckState(Qt.Unchecked)
self.cb_dic[fn][cb_index].stateChanged.connect(self.toggle_check)
self.cb_dic[fn][cb_index].setToolTip(self.patch_obj_dic[fn][cb_index].help_text)
grid_pos = calc_grid_pos(cb_index, cols=3)
cb_grid.addWidget(self.cb_dic[fn][cb_index], grid_pos[0], grid_pos[1])
gb.setLayout(cb_grid)
vBox.addWidget(gb)
cont_index += 1
self.apply_button = QPushButton('Apply Changes')
self.apply_button.clicked.connect(self.app_chgs)
self.disable_all_button = QPushButton("Disable All")
self.disable_all_button.clicked.connect(self.disable_all_patches)
self.defaults_button = QPushButton('Restore Settings')
self.defaults_button.clicked.connect(self.restore_defaults)
button_box = QHBoxLayout()
button_box.addStretch()
button_box.addWidget(self.apply_button)
button_box.addWidget(self.disable_all_button)
button_box.addWidget(self.defaults_button)
button_box.addStretch()
vBox.addLayout(button_box)
self.setCentralWidget(QWidget(self))
self.centralWidget().setLayout(vBox)
self.setWindowTitle('Kobo Patch GUI')
self.show()
sys.exit(self.app.exec_())
def disable_all_patches(self):
"""
Does what it says on the tin :p
Deselects all checkboxes and sets each objects status to 'no'
:return:
"""
for chk_list in self.cb_dic.values():
for cb in chk_list:
cb.setCheckState(Qt.Unchecked)
for (fn, patch_obj_list) in iterDic(self.patch_obj_dic):
for patch_obj in patch_obj_list:
patch_obj.status = '`no`'
def restore_defaults(self):
"""
Restores the state of the patch objects and checkboxes back to their original state of when the file was loaded
:return:
"""
self.patch_obj_dic = copy.deepcopy(self.orig_patch_obj_dic)
for (cb_list, patch_obj_list) in zip(self.cb_dic.values(), self.patch_obj_dic.values()):
for (cb, patch_obj) in zip(cb_list, patch_obj_list):
if 'yes' in patch_obj.status:
cb.setCheckState(Qt.Checked)
else:
cb.setCheckState(Qt.Unchecked)
def toggle_check(self, event):
cb = self.sender()
name = cb.text()
for patch_list in self.patch_obj_dic.values():
for obj in patch_list:
if obj.name in name:
if cb.isChecked():
obj.status = '`yes`'
else:
obj.status = '`no`'
def app_chgs(self, event):
ask_confirm = QMessageBox.question(self, 'Are you sure?', 'Are you sure you wish to write the changes to the '
'patch files?', QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if ask_confirm == QMessageBox.Yes:
success, error_title, error_msg = apply_changes(self.patch_obj_dic, self.file_dic)
if not success:
QMessageBox.critical(self, error_title, error_msg)
else:
QMessageBox.information(self, 'Sussess!', 'The files were successfully written.')
def edit(self):
pass
if __name__ == '__main__':
pg = PatchGUI()
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
984,
199,
504,
14084,
21,
14,
10901,
492,
3959,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3339,
12,
29469,
12,
1413,
16031,
12,
25159,
12,
1413,
25213,
12,
1413,
7900,
4798,
12,
1413,
40,
18536,
12,
971,
272,
1413,
54,
18536,
12,
1413,
2448,
3532,
12,
1413,
20530,
12,
1413,
20083,
12,
1413,
3310,
199,
504,
19292,
4685,
492,
627,
199,
504,
5055,
492,
8773,
199,
646,
1331,
199,
199,
533,
19292,
14438,
8,
49,
16031,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
571,
275,
29469,
8,
1274,
14,
3020,
9,
267,
1613,
8,
11173,
14438,
12,
291,
2843,
826,
4533,
267,
291,
14,
493,
63,
5000,
275,
8773,
342,
267,
291,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
275,
8773,
342,
267,
291,
14,
2068,
63,
1113,
63,
5000,
275,
8773,
342,
267,
291,
14,
2894,
63,
5000,
275,
8773,
342,
267,
291,
14,
86,
3532,
63,
513,
275,
942,
267,
291,
14,
4998,
63,
3887,
275,
488,
267,
291,
14,
5993,
63,
452,
63,
3887,
275,
488,
267,
291,
14,
4322,
63,
3887,
275,
488,
398,
291,
14,
16143,
63,
1725,
342,
339,
347,
11496,
63,
1725,
8,
277,
304,
267,
4325,
63,
513,
12,
570,
63,
466,
275,
1413,
25213,
14,
362,
4299,
1173,
5866,
8,
13410,
534,
4299,
3814,
297,
2457,
534,
31305,
656,
19292,
334,
4856,
2068,
5942,
267,
340,
4325,
63,
513,
26,
288,
6111,
275,
469,
2324,
26,
488,
367,
4325,
315,
4325,
63,
513,
93,
288,
291,
14,
493,
63,
5000,
12,
1125,
275,
1586,
63,
2068,
63,
1725,
8,
2592,
9,
288,
340,
1125,
26,
355,
25159,
14,
13138,
8,
277,
12,
283,
3284,
4520,
12389,
1125,
9,
288,
587,
26,
355,
367,
334,
2324,
12,
3371,
63,
505,
9,
315,
2740,
36,
530,
8,
277,
14,
493,
63,
5000,
304,
490,
291,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
59,
2324,
61,
275,
3805,
63,
2068,
63,
1113,
63,
513,
8,
2324,
12,
3371,
63,
505,
9,
355,
291,
14,
8489,
342,
267,
587,
26,
288,
291,
14,
1600,
342,
339,
347,
8265,
8,
277,
304,
267,
291,
14,
2068,
63,
1113,
63,
5000,
275,
1331,
14,
8293,
8,
277,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
9,
267,
13770,
63,
1080,
275,
378,
267,
373,
3532,
275,
1413,
54,
18536,
8,
277,
9,
267,
367,
334,
2324,
12,
3371,
63,
1113,
63,
513,
9,
315,
2740,
36,
530,
8,
277,
14,
2068,
63,
1113,
63,
5000,
304,
288,
291,
14,
2894,
63,
5000,
59,
2324,
61,
275,
942,
288,
25411,
275,
1413,
2448,
3532,
8,
2324,
9,
288,
7434,
63,
3825,
275,
1413,
7900,
4798,
8,
277,
9,
288,
327,
2790,
436,
1050,
1104,
12922,
370,
5827,
10354,
3160,
288,
367,
334,
2894,
63,
1080,
12,
1559,
9,
315,
3874,
8,
2068,
63,
1113,
63,
513,
304,
355,
327,
2790,
24190,
1750,
436,
24190,
1768,
367,
2929,
355,
7434,
63,
354,
275,
2125,
355,
340,
1559,
14,
923,
26,
490,
7434,
63,
354,
275,
1559,
14,
354,
435,
1557,
78,
360,
435,
1559,
14,
923,
435,
16107,
355,
587,
26,
490,
7434,
63,
354,
275,
1559,
14,
354,
2234,
327,
2790,
436,
1050,
1104,
12922,
370,
314,
10354,
3160,
12,
1808,
314,
6068,
3400,
5256,
355,
291,
14,
2894,
63,
5000,
59,
2324,
1055,
740,
8,
49,
20530,
8,
2894,
63,
354,
430,
355,
327,
2494,
2536,
1174,
402,
1104,
12922,
355,
340,
283,
5066,
7,
315,
1559,
14,
1205,
26,
490,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
409,
1799,
2223,
8,
4238,
14,
14627,
9,
355,
587,
26,
490,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
409,
1799,
2223,
8,
4238,
14,
1358,
10718,
9,
2234,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
929,
6970,
14,
2242,
8,
277,
14,
13396,
63,
1074,
9,
355,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
29892,
8,
277,
14,
2068,
63,
1113,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
3437,
63,
505,
9,
355,
6068,
63,
1712,
275,
12831,
63,
3825,
63,
1712,
8,
2894,
63,
1080,
12,
8850,
29,
19,
9,
2234,
7434,
63,
3825,
14,
9475,
8,
277,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
467,
6068,
63,
1712,
59,
16,
467,
6068,
63,
1712,
59,
17,
566,
953,
25411,
14,
409,
4798,
8,
2894,
63,
3825,
9,
288,
373,
3532,
14,
9475,
8,
4908,
9,
953,
13770,
63,
1080,
847,
413,
398,
291,
14,
4998,
63,
3887,
275,
1413,
20083,
360,
16581,
18784,
358,
267,
291,
14,
4998,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
571,
63,
335,
458,
9,
267,
291,
14,
5993,
63,
452,
63,
3887,
275,
1413,
20083,
480,
13707,
2900,
531,
267,
291,
14,
5993,
63,
452,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
5993,
63,
452,
63,
11350,
9,
267,
291,
14,
4322,
63,
3887,
275,
1413,
20083,
360,
21012,
13303,
358,
267,
291,
14,
4322,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
8011,
63,
4322,
9,
398,
5528,
63,
1977,
275,
1413,
40,
18536,
342,
267,
5528,
63,
1977,
14,
525,
21537,
342,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
4998,
63,
3887,
9,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
5993,
63,
452,
63,
3887,
9,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
4322,
63,
3887,
9,
267,
5528,
63,
1977,
14,
525,
21537,
342,
267,
373,
3532,
14,
30571,
8,
3887,
63,
1977,
9,
398,
291,
14,
409,
25290,
3339,
8,
23894,
8,
277,
430,
267,
291,
14,
16067,
3339,
1252,
409,
4798,
8,
86,
3532,
9,
267,
291,
14,
30601,
360,
31305,
656,
19292,
17160,
358,
267,
291,
14,
2384,
342,
267,
984,
14,
2224,
8,
277,
14,
571,
14,
1628,
63,
1012,
339,
347,
3507,
63,
452,
63,
11350,
8,
277,
304,
267,
408,
267,
12078,
4052,
652,
20065,
641,
314,
307,
262,
520,
80,
267
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
984,
199,
504,
14084,
21,
14,
10901,
492,
3959,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3339,
12,
29469,
12,
1413,
16031,
12,
25159,
12,
1413,
25213,
12,
1413,
7900,
4798,
12,
1413,
40,
18536,
12,
971,
272,
1413,
54,
18536,
12,
1413,
2448,
3532,
12,
1413,
20530,
12,
1413,
20083,
12,
1413,
3310,
199,
504,
19292,
4685,
492,
627,
199,
504,
5055,
492,
8773,
199,
646,
1331,
199,
199,
533,
19292,
14438,
8,
49,
16031,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
571,
275,
29469,
8,
1274,
14,
3020,
9,
267,
1613,
8,
11173,
14438,
12,
291,
2843,
826,
4533,
267,
291,
14,
493,
63,
5000,
275,
8773,
342,
267,
291,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
275,
8773,
342,
267,
291,
14,
2068,
63,
1113,
63,
5000,
275,
8773,
342,
267,
291,
14,
2894,
63,
5000,
275,
8773,
342,
267,
291,
14,
86,
3532,
63,
513,
275,
942,
267,
291,
14,
4998,
63,
3887,
275,
488,
267,
291,
14,
5993,
63,
452,
63,
3887,
275,
488,
267,
291,
14,
4322,
63,
3887,
275,
488,
398,
291,
14,
16143,
63,
1725,
342,
339,
347,
11496,
63,
1725,
8,
277,
304,
267,
4325,
63,
513,
12,
570,
63,
466,
275,
1413,
25213,
14,
362,
4299,
1173,
5866,
8,
13410,
534,
4299,
3814,
297,
2457,
534,
31305,
656,
19292,
334,
4856,
2068,
5942,
267,
340,
4325,
63,
513,
26,
288,
6111,
275,
469,
2324,
26,
488,
367,
4325,
315,
4325,
63,
513,
93,
288,
291,
14,
493,
63,
5000,
12,
1125,
275,
1586,
63,
2068,
63,
1725,
8,
2592,
9,
288,
340,
1125,
26,
355,
25159,
14,
13138,
8,
277,
12,
283,
3284,
4520,
12389,
1125,
9,
288,
587,
26,
355,
367,
334,
2324,
12,
3371,
63,
505,
9,
315,
2740,
36,
530,
8,
277,
14,
493,
63,
5000,
304,
490,
291,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
59,
2324,
61,
275,
3805,
63,
2068,
63,
1113,
63,
513,
8,
2324,
12,
3371,
63,
505,
9,
355,
291,
14,
8489,
342,
267,
587,
26,
288,
291,
14,
1600,
342,
339,
347,
8265,
8,
277,
304,
267,
291,
14,
2068,
63,
1113,
63,
5000,
275,
1331,
14,
8293,
8,
277,
14,
2981,
63,
2068,
63,
1113,
63,
5000,
9,
267,
13770,
63,
1080,
275,
378,
267,
373,
3532,
275,
1413,
54,
18536,
8,
277,
9,
267,
367,
334,
2324,
12,
3371,
63,
1113,
63,
513,
9,
315,
2740,
36,
530,
8,
277,
14,
2068,
63,
1113,
63,
5000,
304,
288,
291,
14,
2894,
63,
5000,
59,
2324,
61,
275,
942,
288,
25411,
275,
1413,
2448,
3532,
8,
2324,
9,
288,
7434,
63,
3825,
275,
1413,
7900,
4798,
8,
277,
9,
288,
327,
2790,
436,
1050,
1104,
12922,
370,
5827,
10354,
3160,
288,
367,
334,
2894,
63,
1080,
12,
1559,
9,
315,
3874,
8,
2068,
63,
1113,
63,
513,
304,
355,
327,
2790,
24190,
1750,
436,
24190,
1768,
367,
2929,
355,
7434,
63,
354,
275,
2125,
355,
340,
1559,
14,
923,
26,
490,
7434,
63,
354,
275,
1559,
14,
354,
435,
1557,
78,
360,
435,
1559,
14,
923,
435,
16107,
355,
587,
26,
490,
7434,
63,
354,
275,
1559,
14,
354,
2234,
327,
2790,
436,
1050,
1104,
12922,
370,
314,
10354,
3160,
12,
1808,
314,
6068,
3400,
5256,
355,
291,
14,
2894,
63,
5000,
59,
2324,
1055,
740,
8,
49,
20530,
8,
2894,
63,
354,
430,
355,
327,
2494,
2536,
1174,
402,
1104,
12922,
355,
340,
283,
5066,
7,
315,
1559,
14,
1205,
26,
490,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
409,
1799,
2223,
8,
4238,
14,
14627,
9,
355,
587,
26,
490,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
409,
1799,
2223,
8,
4238,
14,
1358,
10718,
9,
2234,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
929,
6970,
14,
2242,
8,
277,
14,
13396,
63,
1074,
9,
355,
291,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
29892,
8,
277,
14,
2068,
63,
1113,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
1055,
3437,
63,
505,
9,
355,
6068,
63,
1712,
275,
12831,
63,
3825,
63,
1712,
8,
2894,
63,
1080,
12,
8850,
29,
19,
9,
2234,
7434,
63,
3825,
14,
9475,
8,
277,
14,
2894,
63,
5000,
59,
2324,
1527,
2894,
63,
1080,
467,
6068,
63,
1712,
59,
16,
467,
6068,
63,
1712,
59,
17,
566,
953,
25411,
14,
409,
4798,
8,
2894,
63,
3825,
9,
288,
373,
3532,
14,
9475,
8,
4908,
9,
953,
13770,
63,
1080,
847,
413,
398,
291,
14,
4998,
63,
3887,
275,
1413,
20083,
360,
16581,
18784,
358,
267,
291,
14,
4998,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
571,
63,
335,
458,
9,
267,
291,
14,
5993,
63,
452,
63,
3887,
275,
1413,
20083,
480,
13707,
2900,
531,
267,
291,
14,
5993,
63,
452,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
5993,
63,
452,
63,
11350,
9,
267,
291,
14,
4322,
63,
3887,
275,
1413,
20083,
360,
21012,
13303,
358,
267,
291,
14,
4322,
63,
3887,
14,
11276,
14,
2242,
8,
277,
14,
8011,
63,
4322,
9,
398,
5528,
63,
1977,
275,
1413,
40,
18536,
342,
267,
5528,
63,
1977,
14,
525,
21537,
342,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
4998,
63,
3887,
9,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
5993,
63,
452,
63,
3887,
9,
267,
5528,
63,
1977,
14,
9475,
8,
277,
14,
4322,
63,
3887,
9,
267,
5528,
63,
1977,
14,
525,
21537,
342,
267,
373,
3532,
14,
30571,
8,
3887,
63,
1977,
9,
398,
291,
14,
409,
25290,
3339,
8,
23894,
8,
277,
430,
267,
291,
14,
16067,
3339,
1252,
409,
4798,
8,
86,
3532,
9,
267,
291,
14,
30601,
360,
31305,
656,
19292,
17160,
358,
267,
291,
14,
2384,
342,
267,
984,
14,
2224,
8,
277,
14,
571,
14,
1628,
63,
1012,
339,
347,
3507,
63,
452,
63,
11350,
8,
277,
304,
267,
408,
267,
12078,
4052,
652,
20065,
641,
314,
307,
262,
520,
80,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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~
Extra db.Model property classes.
:copyright: 2011 by tipfy.org.
:license: BSD, see LICENSE.txt for more details.
"""
import hashlib
import pickle
import decimal
from google.appengine.ext import db
from tipfy.utils import json_decode, json_encode, slugify
try:
# This is optional, only required by TimezoneProperty.
from pytz.gae import pytz
except ImportError, e:
pass
class EtagProperty(db.Property):
"""Automatically creates an ETag based on the value of another property.
Note: the ETag is only set or updated after the entity is saved.
Example::
from google.appengine.ext import db
from tipfy.appengine.db import EtagProperty
class StaticContent(db.Model):
data = db.BlobProperty()
etag = EtagProperty(data)
This class derives from `aetycoon <http://github.com/Arachnid/aetycoon>`_.
"""
def __init__(self, prop, *args, **kwargs):
self.prop = prop
super(EtagProperty, self).__init__(*args, **kwargs)
def get_value_for_datastore(self, model_instance):
v = self.prop.__get__(model_instance, type(model_instance))
if not v:
return None
if isinstance(v, unicode):
v = v.encode('utf-8')
return hashlib.sha1(v).hexdigest()
class KeyProperty(db.Property):
"""A property that stores a key, without automatically dereferencing it.
Example usage:
>>> class SampleModel(db.Model):
... sample_key = KeyProperty()
>>> model = SampleModel()
>>> model.sample_key = db.Key.from_path("Foo", "bar")
>>> model.put() # doctest: +ELLIPSIS
datastore_types.Key.from_path(u'SampleModel', ...)
>>> model.sample_key # doctest: +ELLIPSIS
datastore_types.Key.from_path(u'Foo', u'bar', ...)
Adapted from aetycoon: http://github.com/Arachnid/aetycoon/
Added possibility to set it using a db.Model instance.
"""
def validate(self, value):
"""Validate the value.
Args:
value: The value to validate.
Returns:
A valid key.
"""
if isinstance(value, basestring):
value = db.Key(value)
elif isinstance(value, db.Model):
if not value.has_key():
raise db.BadValueError('%s instance must have a complete key to '
'be stored.' % value.__class__.kind())
value = value.key()
if value is not None:
if not isinstance(value, db.Key):
raise TypeError('Property %s must be an instance of db.Key'
% self.name)
return super(KeyProperty, self).validate(value)
class JsonProperty(db.Property):
"""Stores a value automatically encoding to JSON on set and decoding
on get.
"""
data_type = db.Text
def get_value_for_datastore(self, model_instance):
"""Encodes the value to JSON."""
value = super(JsonProperty, self).get_value_for_datastore(
model_instance)
if value is not None:
return db.Text(json_encode(value, separators=(',', ':')))
def make_value_from_datastore(self, value):
"""Decodes the value from JSON."""
if value is not None:
return json_decode(value)
def validate(self, value):
if value is not None and not isinstance(value, (dict, list, tuple)):
raise db.BadValueError('Property %s must be a dict, list or '
'tuple.' % self.name)
return value
class PickleProperty(db.Property):
"""A property for storing complex objects in the datastore in pickled form.
Example::
>>> class PickleModel(db.Model):
... data = PickleProperty()
>>> model = PickleModel()
>>> model.data = {"foo": "bar"}
>>> model.data
{'foo': 'bar'}
>>> model.put() # doctest: +ELLIPSIS
datastore_types.Key.from_path(u'PickleModel', ...)
>>> model2 = PickleModel.all().get()
>>> model2.data
{'foo': 'bar'}
This class derives from `aetycoon <http://github.com/Arachnid/aetycoon>`_.
"""
data_type = db.Blob
def get_value_for_datastore(self, model_instance):
value = self.__get__(model_instance, model_instance.__class__)
value = self.validate(value)
if value is not None:
return db.Blob(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))
def make_value_from_datastore(self, value):
if value is not None:
return pickle.loads(str(value))
class SlugProperty(db.Property):
"""Automatically creates a slug (a lowercase string with words separated by
dashes) based on the value of another property.
Note: the slug is only set or updated after the entity is saved. Example::
from google.appengine.ext import db
from tipfy.appengine.db import SlugProperty
class BlogPost(db.Model):
title = db.StringProperty()
slug = SlugProperty(title)
This class derives from `aetycoon <http://github.com/Arachnid/aetycoon>`_.
"""
def __init__(self, prop, max_length=None, *args, **kwargs):
self.prop = prop
self.max_length = max_length
super(SlugProperty, self).__init__(*args, **kwargs)
def get_value_for_datastore(self, model_instance):
v = self.prop.__get__(model_instance, type(model_instance))
if not v:
return self.default
return slugify(v, max_length=self.max_length, default=self.default)
class TimezoneProperty(db.Property):
"""Stores a timezone value."""
data_type = str
def get_value_for_datastore(self, model_instance):
value = super(TimezoneProperty, self).get_value_for_datastore(
model_instance)
value = self.validate(value)
return value.zone
def make_value_from_datastore(self, value):
return pytz.timezone(value)
def validate(self, value):
value = super(TimezoneProperty, self).validate(value)
if value is None or hasattr(value, 'zone'):
return value
elif isinstance(value, basestring):
return pytz.timezone(value)
raise db.BadValueError("Property %s must be a pytz timezone or string."
% self.name)
class DecimalProperty(db.Property):
"""Stores a decimal value."""
data_type = decimal.Decimal
def get_value_for_datastore(self, model_instance):
return str(super(DecimalProperty, self).get_value_for_datastore(
model_instance))
def make_value_from_datastore(self, value):
return decimal.Decimal(value)
def validate(self, value):
value = super(DecimalProperty, self).validate(value)
if value is None or isinstance(value, decimal.Decimal):
return value
elif isinstance(value, basestring):
return decimal.Decimal(value)
raise db.BadValueError("Property %s must be a Decimal or string"
% self.name)
|
unlicense
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
19201,
1399,
14,
15358,
14,
697,
14,
3282,
272,
18294,
22935,
94,
339,
11177,
1592,
14,
1685,
3324,
3992,
14,
339,
520,
7307,
26,
7760,
701,
19201,
1399,
14,
1308,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
14,
2424,
367,
1655,
2436,
14,
199,
624,
199,
646,
8337,
199,
646,
5927,
199,
646,
6107,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
199,
504,
19201,
1399,
14,
1208,
492,
2022,
63,
2708,
12,
2022,
63,
2143,
12,
29864,
199,
199,
893,
26,
272,
327,
961,
365,
2716,
12,
1454,
1415,
701,
4703,
2619,
3697,
14,
272,
687,
15444,
14,
71,
3624,
492,
15444,
199,
2590,
3545,
12,
325,
26,
272,
986,
421,
199,
533,
662,
1450,
3697,
8,
697,
14,
3697,
304,
272,
408,
3358,
17174,
8491,
376,
662,
1931,
4079,
641,
314,
574,
402,
4573,
3324,
14,
339,
3390,
26,
314,
662,
1931,
365,
1454,
663,
503,
4588,
2410,
314,
4642,
365,
6290,
14,
272,
5679,
447,
398,
687,
6233,
14,
15358,
14,
832,
492,
1592,
267,
687,
19201,
1399,
14,
15358,
14,
697,
492,
662,
1450,
3697,
398,
1021,
13599,
2714,
8,
697,
14,
1685,
304,
288,
666,
275,
1592,
14,
16799,
3697,
342,
288,
13677,
275,
662,
1450,
3697,
8,
576,
9,
339,
961,
1021,
5405,
2310,
687,
658,
3624,
369,
331,
265,
665,
1014,
921,
5031,
14,
957,
15,
33,
345,
11019,
344,
15,
3624,
369,
331,
265,
8637,
3754,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5931,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
4469,
275,
5931,
267,
1613,
8,
37,
1450,
3697,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
585,
63,
509,
63,
11450,
8,
277,
12,
1402,
63,
842,
304,
267,
373,
275,
291,
14,
4469,
855,
362,
721,
1238,
63,
842,
12,
730,
8,
1238,
63,
842,
430,
267,
340,
440,
373,
26,
288,
372,
488,
398,
340,
1228,
8,
86,
12,
2649,
304,
288,
373,
275,
373,
14,
2143,
360,
1624,
13,
24,
358,
398,
372,
8337,
14,
4835,
17,
8,
86,
680,
11453,
342,
421,
199,
533,
2606,
3697,
8,
697,
14,
3697,
304,
272,
408,
33,
3324,
626,
14086,
282,
790,
12,
1928,
5847,
477,
264,
21532,
652,
14,
339,
5679,
4503,
26,
339,
1306,
1021,
15227,
1685,
8,
697,
14,
1685,
304,
272,
2263,
257,
2690,
63,
498,
275,
2606,
3697,
342,
339,
1306,
1402,
275,
15227,
1685,
342,
272,
1306,
1402,
14,
3271,
63,
498,
275,
1592,
14,
1197,
14,
504,
63,
515,
480,
5686,
401,
298,
1700,
531,
272,
1306,
1402,
14,
524,
342,
327,
8868,
26,
435,
21677,
272,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
8176,
1685,
297,
19172,
339,
1306,
1402,
14,
3271,
63,
498,
327,
8868,
26,
435,
21677,
272,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
5686,
297,
399,
7,
1700,
297,
19172,
339,
4431,
18309,
687,
16951,
369,
331,
265,
26,
1455,
921,
5031,
14,
957,
15,
33,
345,
11019,
344,
15,
3624,
369,
331,
265,
15,
272,
16230,
31077,
370,
663,
652,
1808,
282,
1592,
14,
1685,
1256,
14,
272,
408,
272,
347,
4107,
8,
277,
12,
574,
304,
267,
408,
12584,
314,
574,
14,
398,
3033,
26,
881,
574,
26,
710,
574,
370,
4107,
14,
267,
1803,
26,
881,
437,
1686,
790,
14,
267,
408,
267,
340,
1228,
8,
585,
12,
7116,
304,
288,
574,
275,
1592,
14,
1197,
8,
585,
9,
267,
916,
1228,
8,
585,
12,
1592,
14,
1685,
304,
288,
340,
440,
574,
14,
1989,
63,
498,
837,
355,
746,
1592,
14,
5725,
3393,
3508,
83,
1256,
1471,
1172,
282,
4890,
790,
370,
283,
490,
283,
1235,
5489,
3530,
450,
574,
855,
533,
4343,
5091,
1012,
953,
574,
275,
574,
14,
498,
342,
398,
340,
574,
365,
440,
488,
26,
288,
340,
440,
1228,
8,
585,
12,
1592,
14,
1197,
304,
355,
746,
3146,
360,
3697,
450,
83,
1471,
506,
376,
1256,
402,
1592,
14,
1197,
7,
490,
450,
291,
14,
354,
9,
398,
372,
1613,
8,
1197,
3697,
12,
291,
680,
3502,
8,
585,
9,
421,
199,
533,
14587,
3697,
8,
697,
14,
3697,
304,
272,
408,
4759,
470,
282,
574,
5847,
2644,
370,
4840,
641,
663,
436,
15952,
272,
641,
664,
14,
272,
408,
272,
666,
63,
466,
275,
1592,
14,
1872,
339,
347,
664,
63,
585,
63,
509,
63,
11450,
8,
277,
12,
1402,
63,
842,
304,
267,
408,
1327,
6021,
314,
574,
370,
4840,
1041,
267,
574,
275,
1613,
8,
9653,
3697,
12,
291,
680,
362,
63,
585,
63,
509,
63,
11450,
8,
288,
1402,
63,
842,
9,
267,
340,
574,
365,
440,
488,
26,
288,
372,
1592,
14,
1872,
8,
1001,
63,
2143,
8,
585,
12,
17658,
2687,
23324,
7596,
7058,
339,
347,
1852,
63,
585,
63,
504,
63,
11450,
8,
277,
12,
574,
304,
267,
408,
872,
6021,
314,
574,
687,
4840,
1041,
267,
340,
574,
365,
440,
488,
26,
288,
372,
2022,
63,
2708,
8,
585,
9,
339,
347,
4107,
8,
277,
12,
574,
304,
267,
340,
574,
365,
440,
488,
436,
440,
1228,
8,
585,
12,
334,
807,
12,
769,
12,
2008,
2298,
288,
746,
1592,
14,
5725,
3393,
360,
3697,
450,
83,
1471,
506,
282,
1211,
12,
769,
503,
283,
355,
283,
2960,
3530,
450,
291,
14,
354,
9,
398,
372,
574,
421,
199,
533,
31732,
3697,
8,
697,
14,
3697,
304,
272,
408,
33,
3324,
367,
16915,
6114,
2251,
315,
314,
12007,
315,
18731,
1824,
14,
272,
5679,
447,
398,
1306,
1021,
31732,
1685,
8,
697,
14,
1685,
304,
267,
2263,
666,
275,
31732,
3697,
342,
267,
1306,
1402,
275,
31732,
1685,
342,
267,
1306,
1402,
14,
576,
275,
2420,
1421,
582,
298,
1700,
3570,
267,
1306,
1402,
14,
576,
267,
791,
1421,
356,
283,
1700,
936,
267,
1306,
1402,
14,
524,
342,
327,
8868,
26,
435,
21677,
267,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
12755,
1685,
297,
19172,
267,
1306,
1402,
18,
275,
31732,
1685,
14,
452,
1252,
362,
342,
267,
1306,
1402,
18
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
19201,
1399,
14,
15358,
14,
697,
14,
3282,
272,
18294,
22935,
94,
339,
11177,
1592,
14,
1685,
3324,
3992,
14,
339,
520,
7307,
26,
7760,
701,
19201,
1399,
14,
1308,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
14,
2424,
367,
1655,
2436,
14,
199,
624,
199,
646,
8337,
199,
646,
5927,
199,
646,
6107,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
199,
504,
19201,
1399,
14,
1208,
492,
2022,
63,
2708,
12,
2022,
63,
2143,
12,
29864,
199,
199,
893,
26,
272,
327,
961,
365,
2716,
12,
1454,
1415,
701,
4703,
2619,
3697,
14,
272,
687,
15444,
14,
71,
3624,
492,
15444,
199,
2590,
3545,
12,
325,
26,
272,
986,
421,
199,
533,
662,
1450,
3697,
8,
697,
14,
3697,
304,
272,
408,
3358,
17174,
8491,
376,
662,
1931,
4079,
641,
314,
574,
402,
4573,
3324,
14,
339,
3390,
26,
314,
662,
1931,
365,
1454,
663,
503,
4588,
2410,
314,
4642,
365,
6290,
14,
272,
5679,
447,
398,
687,
6233,
14,
15358,
14,
832,
492,
1592,
267,
687,
19201,
1399,
14,
15358,
14,
697,
492,
662,
1450,
3697,
398,
1021,
13599,
2714,
8,
697,
14,
1685,
304,
288,
666,
275,
1592,
14,
16799,
3697,
342,
288,
13677,
275,
662,
1450,
3697,
8,
576,
9,
339,
961,
1021,
5405,
2310,
687,
658,
3624,
369,
331,
265,
665,
1014,
921,
5031,
14,
957,
15,
33,
345,
11019,
344,
15,
3624,
369,
331,
265,
8637,
3754,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5931,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
4469,
275,
5931,
267,
1613,
8,
37,
1450,
3697,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
585,
63,
509,
63,
11450,
8,
277,
12,
1402,
63,
842,
304,
267,
373,
275,
291,
14,
4469,
855,
362,
721,
1238,
63,
842,
12,
730,
8,
1238,
63,
842,
430,
267,
340,
440,
373,
26,
288,
372,
488,
398,
340,
1228,
8,
86,
12,
2649,
304,
288,
373,
275,
373,
14,
2143,
360,
1624,
13,
24,
358,
398,
372,
8337,
14,
4835,
17,
8,
86,
680,
11453,
342,
421,
199,
533,
2606,
3697,
8,
697,
14,
3697,
304,
272,
408,
33,
3324,
626,
14086,
282,
790,
12,
1928,
5847,
477,
264,
21532,
652,
14,
339,
5679,
4503,
26,
339,
1306,
1021,
15227,
1685,
8,
697,
14,
1685,
304,
272,
2263,
257,
2690,
63,
498,
275,
2606,
3697,
342,
339,
1306,
1402,
275,
15227,
1685,
342,
272,
1306,
1402,
14,
3271,
63,
498,
275,
1592,
14,
1197,
14,
504,
63,
515,
480,
5686,
401,
298,
1700,
531,
272,
1306,
1402,
14,
524,
342,
327,
8868,
26,
435,
21677,
272,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
8176,
1685,
297,
19172,
339,
1306,
1402,
14,
3271,
63,
498,
327,
8868,
26,
435,
21677,
272,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
5686,
297,
399,
7,
1700,
297,
19172,
339,
4431,
18309,
687,
16951,
369,
331,
265,
26,
1455,
921,
5031,
14,
957,
15,
33,
345,
11019,
344,
15,
3624,
369,
331,
265,
15,
272,
16230,
31077,
370,
663,
652,
1808,
282,
1592,
14,
1685,
1256,
14,
272,
408,
272,
347,
4107,
8,
277,
12,
574,
304,
267,
408,
12584,
314,
574,
14,
398,
3033,
26,
881,
574,
26,
710,
574,
370,
4107,
14,
267,
1803,
26,
881,
437,
1686,
790,
14,
267,
408,
267,
340,
1228,
8,
585,
12,
7116,
304,
288,
574,
275,
1592,
14,
1197,
8,
585,
9,
267,
916,
1228,
8,
585,
12,
1592,
14,
1685,
304,
288,
340,
440,
574,
14,
1989,
63,
498,
837,
355,
746,
1592,
14,
5725,
3393,
3508,
83,
1256,
1471,
1172,
282,
4890,
790,
370,
283,
490,
283,
1235,
5489,
3530,
450,
574,
855,
533,
4343,
5091,
1012,
953,
574,
275,
574,
14,
498,
342,
398,
340,
574,
365,
440,
488,
26,
288,
340,
440,
1228,
8,
585,
12,
1592,
14,
1197,
304,
355,
746,
3146,
360,
3697,
450,
83,
1471,
506,
376,
1256,
402,
1592,
14,
1197,
7,
490,
450,
291,
14,
354,
9,
398,
372,
1613,
8,
1197,
3697,
12,
291,
680,
3502,
8,
585,
9,
421,
199,
533,
14587,
3697,
8,
697,
14,
3697,
304,
272,
408,
4759,
470,
282,
574,
5847,
2644,
370,
4840,
641,
663,
436,
15952,
272,
641,
664,
14,
272,
408,
272,
666,
63,
466,
275,
1592,
14,
1872,
339,
347,
664,
63,
585,
63,
509,
63,
11450,
8,
277,
12,
1402,
63,
842,
304,
267,
408,
1327,
6021,
314,
574,
370,
4840,
1041,
267,
574,
275,
1613,
8,
9653,
3697,
12,
291,
680,
362,
63,
585,
63,
509,
63,
11450,
8,
288,
1402,
63,
842,
9,
267,
340,
574,
365,
440,
488,
26,
288,
372,
1592,
14,
1872,
8,
1001,
63,
2143,
8,
585,
12,
17658,
2687,
23324,
7596,
7058,
339,
347,
1852,
63,
585,
63,
504,
63,
11450,
8,
277,
12,
574,
304,
267,
408,
872,
6021,
314,
574,
687,
4840,
1041,
267,
340,
574,
365,
440,
488,
26,
288,
372,
2022,
63,
2708,
8,
585,
9,
339,
347,
4107,
8,
277,
12,
574,
304,
267,
340,
574,
365,
440,
488,
436,
440,
1228,
8,
585,
12,
334,
807,
12,
769,
12,
2008,
2298,
288,
746,
1592,
14,
5725,
3393,
360,
3697,
450,
83,
1471,
506,
282,
1211,
12,
769,
503,
283,
355,
283,
2960,
3530,
450,
291,
14,
354,
9,
398,
372,
574,
421,
199,
533,
31732,
3697,
8,
697,
14,
3697,
304,
272,
408,
33,
3324,
367,
16915,
6114,
2251,
315,
314,
12007,
315,
18731,
1824,
14,
272,
5679,
447,
398,
1306,
1021,
31732,
1685,
8,
697,
14,
1685,
304,
267,
2263,
666,
275,
31732,
3697,
342,
267,
1306,
1402,
275,
31732,
1685,
342,
267,
1306,
1402,
14,
576,
275,
2420,
1421,
582,
298,
1700,
3570,
267,
1306,
1402,
14,
576,
267,
791,
1421,
356,
283,
1700,
936,
267,
1306,
1402,
14,
524,
342,
327,
8868,
26,
435,
21677,
267,
12007,
63,
1313,
14,
1197,
14,
504,
63,
515,
8,
85,
7,
12755,
1685,
297,
19172,
267,
1306,
1402,
18,
275,
31732,
1685,
14,
452,
1252,
362,
342,
267,
1306,
1402,
18,
0
] |
[
1,
1,
1,
1,
1,
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eup
|
backend/venv/lib/python2.7/site-packages/tekton/gae/middleware/json_middleware.py
|
9
|
1065
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import json
from tekton.gae.middleware import Middleware
from tekton.gae.middleware.response import ResponseBase
class JsonResponse(ResponseBase):
def __init__(self, context, secure_prefix=")]}',\n"):
super(JsonResponse, self).__init__(context)
self.secure_prefix = secure_prefix
def to_json(self):
return self.secure_prefix + json.dumps(self.context)
class JsonUnsecureResponse(JsonResponse):
def __init__(self, context, secure_prefix=''):
super(JsonUnsecureResponse, self).__init__(context, secure_prefix)
class JsonResponseMiddleware(Middleware):
def set_up(self):
fcn_response = self.dependencies['_fcn_response']
if isinstance(fcn_response, JsonResponse):
resp = self.handler.response
resp.headers[str('Content-Type')] = str('application/json')
resp.write(fcn_response.to_json())
return True # after response, there is no need to look for more middlewares
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
2022,
199,
504,
1565,
75,
1860,
14,
71,
3624,
14,
5754,
492,
603,
3551,
199,
504,
1565,
75,
1860,
14,
71,
3624,
14,
5754,
14,
1310,
492,
7232,
1563,
421,
199,
533,
21072,
8,
2364,
1563,
304,
272,
347,
636,
826,
721,
277,
12,
1067,
12,
11153,
63,
1861,
29,
11323,
7293,
60,
78,
2349,
267,
1613,
8,
9653,
2364,
12,
291,
2843,
826,
721,
1100,
9,
267,
291,
14,
7817,
63,
1861,
275,
11153,
63,
1861,
339,
347,
370,
63,
1001,
8,
277,
304,
267,
372,
291,
14,
7817,
63,
1861,
435,
2022,
14,
4180,
8,
277,
14,
1100,
9,
421,
199,
533,
14587,
1358,
7817,
2364,
8,
9653,
2364,
304,
272,
347,
636,
826,
721,
277,
12,
1067,
12,
11153,
63,
1861,
9280,
267,
1613,
8,
9653,
1358,
7817,
2364,
12,
291,
2843,
826,
721,
1100,
12,
11153,
63,
1861,
9,
421,
199,
533,
21072,
6608,
8,
6608,
304,
272,
347,
663,
63,
384,
8,
277,
304,
267,
289,
6413,
63,
1310,
275,
291,
14,
5714,
8680,
26554,
63,
1310,
418,
267,
340,
1228,
8,
26554,
63,
1310,
12,
21072,
304,
288,
3085,
275,
291,
14,
2232,
14,
1310,
288,
3085,
14,
2139,
59,
495,
360,
2714,
13,
804,
5440,
275,
620,
360,
3578,
15,
1001,
358,
288,
3085,
14,
952,
8,
26554,
63,
1310,
14,
475,
63,
1001,
1012,
288,
372,
715,
221,
327,
2410,
1177,
12,
2337,
365,
949,
1929,
370,
3648,
367,
1655,
12180,
758,
470,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
2022,
199,
504,
1565,
75,
1860,
14,
71,
3624,
14,
5754,
492,
603,
3551,
199,
504,
1565,
75,
1860,
14,
71,
3624,
14,
5754,
14,
1310,
492,
7232,
1563,
421,
199,
533,
21072,
8,
2364,
1563,
304,
272,
347,
636,
826,
721,
277,
12,
1067,
12,
11153,
63,
1861,
29,
11323,
7293,
60,
78,
2349,
267,
1613,
8,
9653,
2364,
12,
291,
2843,
826,
721,
1100,
9,
267,
291,
14,
7817,
63,
1861,
275,
11153,
63,
1861,
339,
347,
370,
63,
1001,
8,
277,
304,
267,
372,
291,
14,
7817,
63,
1861,
435,
2022,
14,
4180,
8,
277,
14,
1100,
9,
421,
199,
533,
14587,
1358,
7817,
2364,
8,
9653,
2364,
304,
272,
347,
636,
826,
721,
277,
12,
1067,
12,
11153,
63,
1861,
9280,
267,
1613,
8,
9653,
1358,
7817,
2364,
12,
291,
2843,
826,
721,
1100,
12,
11153,
63,
1861,
9,
421,
199,
533,
21072,
6608,
8,
6608,
304,
272,
347,
663,
63,
384,
8,
277,
304,
267,
289,
6413,
63,
1310,
275,
291,
14,
5714,
8680,
26554,
63,
1310,
418,
267,
340,
1228,
8,
26554,
63,
1310,
12,
21072,
304,
288,
3085,
275,
291,
14,
2232,
14,
1310,
288,
3085,
14,
2139,
59,
495,
360,
2714,
13,
804,
5440,
275,
620,
360,
3578,
15,
1001,
358,
288,
3085,
14,
952,
8,
26554,
63,
1310,
14,
475,
63,
1001,
1012,
288,
372,
715,
221,
327,
2410,
1177,
12,
2337,
365,
949,
1929,
370,
3648,
367,
1655,
12180,
758,
470,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
uclouvain/OSIS-Louvain
|
features/steps/4_offer_create.py
|
1
|
4004
|
# ############################################################################
# OSIS stands for Open Student Information System. It's an application
# designed to manage the core business of higher education institutions,
# such as universities, faculties, institutes and professional schools.
# The core business involves the administration of students, teachers,
# courses, programs and so on.
#
# Copyright (C) 2015-2019 Université catholique de Louvain (http://www.uclouvain.be)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of this license - GNU General Public License - is available
# at the root of the source code of this program. If not,
# see http://www.gnu.org/licenses/.
# ############################################################################
from behave import *
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from features.steps.utils.pages import SearchEducationGroupPage
use_step_matcher("parse")
@given("Aller sur la page Catalogue de formations / Formation")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
url = '/educationgroups/'
context.current_page = SearchEducationGroupPage(driver=context.browser, base_url=context.get_url(url)).open()
context.test.assertEqual(context.browser.current_url, context.get_url(url))
@step("Cliquer sur « Nouvelle Formation »")
def step_impl(context):
context.current_page.new_training.click()
@step("Cliquer sur « Oui, je confirme »")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
context.current_page = context.current_page.confirm_modal.click()
@step("Cliquer sur l'onglet Diplômes/Certificats")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
context.current_page.tab_diploma.click()
@step("Si une modal d'avertissement s'affiche, cliquer sur « oui »")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
try:
context.current_page.find_element(By.CSS_SELECTOR,
'#confirm-modal > div > div > div.modal-footer > button.btn.btn-warning'
).click()
except NoSuchElementException:
pass
@then("Vérifier que la formation {acronym} à bien été créée de {start_year} à {end_year}")
def step_impl(context, acronym, start_year, end_year):
"""
:type context: behave.runner.Context
"""
for i in range(int(start_year), int(end_year) + 1):
string_to_check = "{} ({}-".format(acronym, i)
context.test.assertIn(string_to_check, context.current_page.success_messages.text)
@step("Cliquer sur « Nouvelle Mini-Formation »")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
context.current_page.new_mini_training.click()
@when("Ouvrir l'arbre")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
context.current_page.toggle_tree.click()
@then("Vérifier que le(s) enfant(s) de {code} sont bien {children}")
def step_impl(context, code, children):
"""
:type context: behave.runner.Context
:type code: str
:type children: str
"""
context.current_page.open_first_node_tree.click()
expected_children = children.split(',')
children_in_tree = context.current_page.get_name_first_children()
for i, child in enumerate(expected_children):
context.test.assertIn(child, children_in_tree[i])
|
agpl-3.0
|
[
3,
23441,
381,
199,
3,
221,
4403,
1311,
410,
5915,
367,
3232,
17246,
17064,
6187,
14,
2779,
1159,
376,
4223,
199,
3,
221,
19829,
370,
9635,
314,
6170,
26440,
402,
10948,
3988,
30500,
2727,
390,
8653,
12,
199,
3,
221,
4066,
465,
625,
4380,
338,
1417,
12,
21625,
1141,
397,
12,
2727,
390,
3862,
436,
22398,
28661,
308,
2239,
1446,
14,
199,
3,
221,
710,
6170,
26440,
25613,
2310,
314,
4628,
4633,
402,
18557,
12,
1565,
1225,
1192,
12,
199,
3,
221,
13588,
12,
18572,
436,
880,
641,
14,
199,
3,
199,
3,
221,
1898,
334,
35,
9,
6900,
13,
14982,
1910,
4380,
2221,
5741,
286,
1619,
23711,
544,
477,
491,
810,
86,
1581,
334,
1014,
921,
1544,
14,
947,
320,
9154,
1581,
14,
1235,
9,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
437,
1331,
402,
642,
4190,
446,
1664,
1696,
1684,
844,
446,
365,
2808,
199,
3,
221,
737,
314,
1738,
402,
314,
1350,
1233,
402,
642,
2240,
14,
221,
982,
440,
12,
199,
3,
221,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
23441,
381,
199,
504,
24062,
492,
627,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
199,
504,
4534,
14,
5895,
14,
1208,
14,
5856,
492,
8730,
37,
5905,
425,
2448,
3276,
199,
199,
1180,
63,
2926,
63,
16135,
480,
1122,
531,
421,
199,
32,
11809,
480,
2439,
1435,
6296,
1127,
2034,
22881,
310,
477,
367,
21953,
1182,
2104,
1615,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1166,
275,
1994,
379,
30500,
2634,
4805,
272,
1067,
14,
1818,
63,
1606,
275,
8730,
37,
5905,
425,
2448,
3276,
8,
3090,
29,
1100,
14,
5750,
12,
1300,
63,
633,
29,
1100,
14,
362,
63,
633,
8,
633,
4992,
1490,
342,
272,
1067,
14,
396,
14,
629,
8,
1100,
14,
5750,
14,
1818,
63,
633,
12,
1067,
14,
362,
63,
633,
8,
633,
430,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
653,
810,
1090,
274,
2104,
1615,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
1067,
14,
1818,
63,
1606,
14,
1222,
63,
7588,
14,
4891,
342,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
593,
1907,
12,
1335,
69,
406,
1795,
278,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
275,
1067,
14,
1818,
63,
1606,
14,
9548,
63,
17713,
14,
4891,
342,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
634,
7,
951,
2723,
577,
711,
76,
128,
113,
6415,
15,
7851,
22563,
1956,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
2902,
63,
21846,
320,
391,
14,
4891,
342,
421,
199,
32,
2926,
480,
18934,
625,
69,
21698,
366,
7,
65,
12101,
28780,
434,
308,
7,
27054,
595,
12,
5053,
16891,
6296,
22405,
105,
312,
1907,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
862,
26,
267,
1067,
14,
1818,
63,
1606,
14,
1623,
63,
2108,
8,
2175,
14,
14391,
63,
25691,
12,
5101,
3943,
9548,
13,
17713,
690,
9073,
690,
9073,
690,
9073,
14,
17713,
13,
12781,
690,
5528,
14,
9633,
14,
9633,
13,
3764,
7,
5101,
7092,
4891,
342,
272,
871,
23798,
2162,
1726,
26,
267,
986,
421,
199,
32,
12726,
480,
54,
5741,
322,
3895,
17414,
1127,
367,
1615,
469,
645,
2641,
12828,
93,
26031,
12111,
287,
26785,
84,
5741,
2467,
5741,
5741,
69,
477,
469,
928,
63,
3403,
93,
26031,
469,
500,
63,
3403,
15412,
199,
318,
3650,
63,
5472,
8,
1100,
12,
1066,
2641,
12828,
12,
1343,
63,
3403,
12,
1284,
63,
3403,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
367,
284,
315,
1425,
8,
442,
8,
928,
63,
3403,
395,
1109,
8,
500,
63,
3403,
9,
435,
413,
304,
267,
1059,
63,
475,
63,
1074,
275,
11491,
334,
2440,
13,
1674,
908,
8,
645,
2641,
12828,
12,
284,
9,
267,
1067,
14,
396,
14,
4080,
8,
875,
63,
475,
63,
1074,
12,
1067,
14,
1818,
63,
1606,
14,
3742,
63,
3431,
14,
505,
9,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
653,
810,
1090,
274,
24954,
13,
1858,
1615,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
1222,
63,
18000,
63,
7588,
14,
4891,
342,
421,
199,
32,
6526,
480,
47,
9154,
322,
82,
634,
7,
285,
10205,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
13396,
63,
2350,
14,
4891,
342,
421,
199,
32,
12726,
480,
54,
5741,
322,
3895,
17414,
1026,
8,
83,
9,
655,
70,
867,
8,
83,
9,
477,
469,
600,
93,
308,
1888,
12111,
287,
469,
3223,
15412,
199,
318,
3650,
63,
5472,
8,
1100,
12,
1233,
12,
4978,
304,
272,
408,
272,
520
] |
[
23441,
381,
199,
3,
221,
4403,
1311,
410,
5915,
367,
3232,
17246,
17064,
6187,
14,
2779,
1159,
376,
4223,
199,
3,
221,
19829,
370,
9635,
314,
6170,
26440,
402,
10948,
3988,
30500,
2727,
390,
8653,
12,
199,
3,
221,
4066,
465,
625,
4380,
338,
1417,
12,
21625,
1141,
397,
12,
2727,
390,
3862,
436,
22398,
28661,
308,
2239,
1446,
14,
199,
3,
221,
710,
6170,
26440,
25613,
2310,
314,
4628,
4633,
402,
18557,
12,
1565,
1225,
1192,
12,
199,
3,
221,
13588,
12,
18572,
436,
880,
641,
14,
199,
3,
199,
3,
221,
1898,
334,
35,
9,
6900,
13,
14982,
1910,
4380,
2221,
5741,
286,
1619,
23711,
544,
477,
491,
810,
86,
1581,
334,
1014,
921,
1544,
14,
947,
320,
9154,
1581,
14,
1235,
9,
199,
3,
199,
3,
221,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
437,
1331,
402,
642,
4190,
446,
1664,
1696,
1684,
844,
446,
365,
2808,
199,
3,
221,
737,
314,
1738,
402,
314,
1350,
1233,
402,
642,
2240,
14,
221,
982,
440,
12,
199,
3,
221,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
23441,
381,
199,
504,
24062,
492,
627,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
199,
504,
4534,
14,
5895,
14,
1208,
14,
5856,
492,
8730,
37,
5905,
425,
2448,
3276,
199,
199,
1180,
63,
2926,
63,
16135,
480,
1122,
531,
421,
199,
32,
11809,
480,
2439,
1435,
6296,
1127,
2034,
22881,
310,
477,
367,
21953,
1182,
2104,
1615,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1166,
275,
1994,
379,
30500,
2634,
4805,
272,
1067,
14,
1818,
63,
1606,
275,
8730,
37,
5905,
425,
2448,
3276,
8,
3090,
29,
1100,
14,
5750,
12,
1300,
63,
633,
29,
1100,
14,
362,
63,
633,
8,
633,
4992,
1490,
342,
272,
1067,
14,
396,
14,
629,
8,
1100,
14,
5750,
14,
1818,
63,
633,
12,
1067,
14,
362,
63,
633,
8,
633,
430,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
653,
810,
1090,
274,
2104,
1615,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
1067,
14,
1818,
63,
1606,
14,
1222,
63,
7588,
14,
4891,
342,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
593,
1907,
12,
1335,
69,
406,
1795,
278,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
275,
1067,
14,
1818,
63,
1606,
14,
9548,
63,
17713,
14,
4891,
342,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
634,
7,
951,
2723,
577,
711,
76,
128,
113,
6415,
15,
7851,
22563,
1956,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
2902,
63,
21846,
320,
391,
14,
4891,
342,
421,
199,
32,
2926,
480,
18934,
625,
69,
21698,
366,
7,
65,
12101,
28780,
434,
308,
7,
27054,
595,
12,
5053,
16891,
6296,
22405,
105,
312,
1907,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
862,
26,
267,
1067,
14,
1818,
63,
1606,
14,
1623,
63,
2108,
8,
2175,
14,
14391,
63,
25691,
12,
5101,
3943,
9548,
13,
17713,
690,
9073,
690,
9073,
690,
9073,
14,
17713,
13,
12781,
690,
5528,
14,
9633,
14,
9633,
13,
3764,
7,
5101,
7092,
4891,
342,
272,
871,
23798,
2162,
1726,
26,
267,
986,
421,
199,
32,
12726,
480,
54,
5741,
322,
3895,
17414,
1127,
367,
1615,
469,
645,
2641,
12828,
93,
26031,
12111,
287,
26785,
84,
5741,
2467,
5741,
5741,
69,
477,
469,
928,
63,
3403,
93,
26031,
469,
500,
63,
3403,
15412,
199,
318,
3650,
63,
5472,
8,
1100,
12,
1066,
2641,
12828,
12,
1343,
63,
3403,
12,
1284,
63,
3403,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
367,
284,
315,
1425,
8,
442,
8,
928,
63,
3403,
395,
1109,
8,
500,
63,
3403,
9,
435,
413,
304,
267,
1059,
63,
475,
63,
1074,
275,
11491,
334,
2440,
13,
1674,
908,
8,
645,
2641,
12828,
12,
284,
9,
267,
1067,
14,
396,
14,
4080,
8,
875,
63,
475,
63,
1074,
12,
1067,
14,
1818,
63,
1606,
14,
3742,
63,
3431,
14,
505,
9,
421,
199,
32,
2926,
480,
20653,
16891,
6296,
22405,
105,
653,
810,
1090,
274,
24954,
13,
1858,
1615,
22405,
120,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
1222,
63,
18000,
63,
7588,
14,
4891,
342,
421,
199,
32,
6526,
480,
47,
9154,
322,
82,
634,
7,
285,
10205,
531,
199,
318,
3650,
63,
5472,
8,
1100,
304,
272,
408,
272,
520,
466,
1067,
26,
24062,
14,
5933,
14,
2998,
272,
408,
272,
1067,
14,
1818,
63,
1606,
14,
13396,
63,
2350,
14,
4891,
342,
421,
199,
32,
12726,
480,
54,
5741,
322,
3895,
17414,
1026,
8,
83,
9,
655,
70,
867,
8,
83,
9,
477,
469,
600,
93,
308,
1888,
12111,
287,
469,
3223,
15412,
199,
318,
3650,
63,
5472,
8,
1100,
12,
1233,
12,
4978,
304,
272,
408,
272,
520,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ksrajkumar/openerp-6.1
|
openerp/addons/base/res/report/__init__.py
|
79
|
1201
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#from report import report_sxw
#report_sxw.report_sxw('report.partner.list', 'res.partner', 'addons/base/res/partner/report/partner_list.rml')
# 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,
8664,
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,
3,
504,
3622,
492,
3622,
63,
20851,
199,
3,
3070,
63,
20851,
14,
3070,
63,
20851,
360,
3070,
14,
3899,
14,
513,
297,
283,
470,
14,
3899,
297,
283,
10788,
15,
1095,
15,
470,
15,
3899,
15,
3070,
15,
3899,
63,
513,
14,
16300,
358,
4388,
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
] |
[
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,
8664,
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,
3,
504,
3622,
492,
3622,
63,
20851,
199,
3,
3070,
63,
20851,
14,
3070,
63,
20851,
360,
3070,
14,
3899,
14,
513,
297,
283,
470,
14,
3899,
297,
283,
10788,
15,
1095,
15,
470,
15,
3899,
15,
3070,
15,
3899,
63,
513,
14,
16300,
358,
4388,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bhuvanshankar/userinfuser
|
serverside/dao/accounts_dao.py
|
12
|
5968
|
# Copyright (C) 2011, CloudCaptive
#
# 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/>.
#
'''
Created on Feb 14, 2011
psuedo DAO methods
@author: shan
'''
from serverside.constants import ACCOUNT_STATUS
from serverside.entities import memcache_db
from serverside.entities.accounts import Accounts
from serverside.entities.widgets import TrophyCase, Points, Rank, Notifier, \
Leaderboard, Milestones
from serverside import constants
from serverside.tools import utils
from serverside.dao import users_dao
import hashlib
import logging
import uuid
def create_account(email,
password,
enable=False,
account_type="bronze",
payment_type="free"):
"""
Creates an account with all the other needed dependencies properly initialized.
"""
"""
Required:
email = db.EmailProperty(required=True)
password = db.StringProperty(required=True);
isEnabled = db.StringProperty(required=True, choices=ACCOUNT_STATUS.RANGE_OF_VALUES)
accountType = db.StringProperty(required=True, choices=set(ACCOUNT_TYPES))
paymentType = db.StringProperty(required=True,choices=set(PAYMENT_TYPES))
cookieKey = db.StringProperty(required=True)
apiKey = db.StringProperty(required=True)
trophyWidget = db.ReferenceProperty(required=True, reference_class=TrophyCase)
pointsWidget = db.ReferenceProperty(required=True, reference_class=Points)
rankWidget = db.ReferenceProperty(required=True, reference_class=Rank)
"""
new_trophy_case = TrophyCase(key_name=email)
memcache_db.save_entity(new_trophy_case, email)
new_rank = Rank(key_name=email)
memcache_db.save_entity(new_rank, email)
new_points = Points(key_name=email)
memcache_db.save_entity(new_points, email)
new_notifier = Notifier(key_name=email)
memcache_db.save_entity(new_notifier, email)
new_leader = Leaderboard(key_name=email)
memcache_db.save_entity(new_leader, email)
new_milestones = Milestones(key_name=email)
memcache_db.save_entity(new_milestones, email)
""" Generate an API key """
api_key = str(uuid.uuid4())
""" Hash the password """
hashed_password = hashlib.sha1(password).hexdigest()
enable_account = ACCOUNT_STATUS.PENDING_CREATE
if enable:
enable_account = ACCOUNT_STATUS.ENABLED
newacc = Accounts(key_name = email,
email = email,
password = hashed_password,
isEnabled = enable_account,
accountType = account_type,
paymentType = payment_type,
apiKey = api_key,
cookieKey = "xxxxxxxxxxxxxx",
trophyWidget = new_trophy_case,
pointsWidget = new_points,
rankWidget = new_rank,
notifierWidget = new_notifier,
leaderWidget = new_leader,
milestoneWidget = new_milestones)
try:
memcache_db.save_entity(newacc, email)
except:
logging.error("Failed to create account")
users_dao.create_new_user(email, constants.ANONYMOUS_USER)
return newacc
def authenticate_web_account(account_id, password):
entity = memcache_db.get_entity(account_id, "Accounts")
if entity != None and entity.password == hashlib.sha1(password).hexdigest() and entity.isEnabled == ACCOUNT_STATUS.ENABLED:
return entity
else:
return None
def change_account_password(email, new_password):
""" Change value in data store, also do hashing """
values = {"password" : hashlib.sha1(new_password).hexdigest()}
try:
memcache_db.update_fields(email, "Accounts", values)
return True
except:
logging.info("Password change failed.")
return False
def reset_password(email):
"""
Generates a random password for the account, and saves into account.
Returns the new password.
Returns None if account lookup/update fails
"""
account_entity = memcache_db.get_entity(email, "Accounts")
ret = None
if account_entity:
random_str = utils.generate_random_string(8)
if change_account_password(email, random_str):
ret = random_str
else:
logging.info("Unable to change password.")
else:
logging.info("Password cannot be reset, account was not located.")
return ret
def authorize_api(account_id, api_key):
"""
return the account on success, non on failure
"""
acc = None
try:
acc = memcache_db.get_entity(account_id, "Accounts")
except:
logging.error("Error getting account with key %s"%account_id)
return None
if not acc:
logging.error("Permission error with null account")
return None
if acc.apiKey != api_key or not acc.isEnabled:
logging.error("Permission error with %s account with %s api key versus %s"\
%(account_id, api_key, acc.apiKey))
return None
return acc
def delete_account(acc_key):
memcache_db.delete_entity_with_key(acc_key, "Leaderboard")
memcache_db.delete_entity_with_key(acc_key, "TrophyCase")
memcache_db.delete_entity_with_key(acc_key, "Points")
memcache_db.delete_entity_with_key(acc_key, "Rank")
return memcache_db.delete_entity_with_key(acc_key, "Accounts")
def save(acc_ref):
memcache_db.save_entity(acc_ref, acc_ref.key().name())
def get(acc_key):
return memcache_db.get_entity(acc_key, "Accounts")
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
7760,
12,
8142,
9155,
857,
199,
3,
221,
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,
221,
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,
221,
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,
2344,
199,
10502,
641,
21141,
4329,
12,
7760,
199,
199,
1190,
310,
1117,
577,
23320,
3102,
199,
199,
32,
2502,
26,
1033,
290,
199,
2344,
199,
504,
1654,
2441,
14,
5559,
492,
6570,
8760,
63,
6305,
199,
504,
1654,
2441,
14,
8327,
492,
21598,
63,
697,
199,
504,
1654,
2441,
14,
8327,
14,
8370,
492,
4473,
6851,
199,
504,
1654,
2441,
14,
8327,
14,
8583,
492,
377,
293,
6581,
1538,
12,
32598,
12,
31536,
12,
3091,
11612,
12,
971,
523,
7005,
669,
3576,
12,
603,
24156,
199,
504,
1654,
2441,
492,
5262,
221,
199,
504,
1654,
2441,
14,
2537,
492,
3778,
199,
504,
1654,
2441,
14,
20431,
492,
4390,
63,
20431,
199,
646,
8337,
199,
646,
2050,
199,
646,
5377,
421,
199,
318,
1218,
63,
2048,
8,
2123,
12,
718,
2505,
12,
718,
4756,
29,
797,
12,
673,
2933,
63,
466,
628,
66,
2641,
806,
401,
673,
11628,
63,
466,
628,
4624,
2349,
523,
408,
523,
10560,
376,
2933,
543,
1006,
314,
1163,
4346,
5124,
7684,
10038,
14,
523,
408,
2043,
12244,
408,
523,
11105,
26,
523,
3031,
275,
1592,
14,
7035,
3697,
8,
2427,
29,
549,
9,
523,
2505,
275,
1592,
14,
31821,
8,
2427,
29,
549,
2736,
523,
365,
6589,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
3415,
29,
18928,
63,
6305,
14,
15167,
63,
3359,
63,
15514,
9,
523,
2933,
804,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
3415,
29,
409,
8,
18928,
63,
7893,
430,
16421,
11628,
804,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
4577,
29,
409,
8,
17698,
4479,
63,
7893,
430,
523,
5494,
1197,
275,
1592,
14,
31821,
8,
2427,
29,
549,
9,
523,
2986,
1197,
275,
1592,
14,
31821,
8,
2427,
29,
549,
9,
523,
22621,
6581,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
52,
293,
6581,
1538,
9,
523,
4501,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
10225,
9,
523,
6915,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
19486,
9,
523,
408,
12244,
892,
63,
1374,
6581,
63,
2546,
275,
377,
293,
6581,
1538,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
1374,
6581,
63,
2546,
12,
3031,
9,
819,
892,
63,
4648,
275,
31536,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
4648,
12,
3031,
9,
819,
892,
63,
3438,
275,
32598,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
3438,
12,
3031,
9,
819,
892,
63,
18031,
275,
3091,
11612,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
18031,
12,
3031,
9,
523,
523,
892,
63,
18498,
275,
7005,
669,
3576,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
18498,
12,
3031,
9,
12244,
892,
63,
77,
24156,
275,
603,
24156,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
77,
24156,
12,
3031,
9,
12244,
408,
7958,
376,
3261,
790,
408,
523,
2986,
63,
498,
275,
620,
8,
2580,
14,
2580,
20,
1012,
12244,
408,
16101,
314,
2505,
408,
523,
19871,
63,
2060,
275,
8337,
14,
4835,
17,
8,
2060,
680,
11453,
342,
12244,
4756,
63,
2048,
275,
6570,
8760,
63,
6305,
14,
21243,
63,
8366,
523,
340,
4756,
26,
272,
4756,
63,
2048,
275,
6570,
8760,
63,
6305,
14,
15704,
12244,
892,
5470,
275,
4473,
6851,
8,
498,
63,
354,
275,
3031,
12,
1993,
3031,
275,
3031,
12,
1993,
2505,
275,
19871,
63,
2060,
12,
1993,
365,
6589,
275,
4756,
63,
2048,
12,
1993,
2933,
804,
275,
2933,
63,
466,
12,
1993,
11628,
804,
275,
11628,
63,
466,
12,
1993,
2986,
1197,
275,
2986,
63,
498,
12,
1993,
5494,
1197,
275,
298,
9505,
5336,
2154,
401,
1993,
22621,
6581,
3339,
275,
892,
63,
1374,
6581,
63,
2546,
12,
1993,
4501,
3339,
275,
892,
63,
3438,
12,
1993,
6915,
3339,
275,
892,
63,
4648,
12,
1993,
30154,
3339,
275,
892,
63,
18031,
12,
1993,
23092,
3339,
275,
892,
63,
18498,
12,
1993,
333,
18072,
3339,
275,
892,
63,
77,
24156,
9,
12244,
862,
26,
272,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
5470,
12,
3031,
9,
523,
871,
26,
272,
2050,
14,
705,
480,
4276,
370,
1218,
2933,
531,
523,
523,
4390,
63,
20431,
14,
981,
63,
1222,
63,
751,
8,
2123,
12,
5262,
14,
879,
32537,
2679,
1668,
63,
3791,
9,
523,
523,
372,
892,
5470,
421,
199,
318,
12895,
63,
2520,
63,
2048,
8,
2048,
63,
344,
12,
2505,
304,
523,
4642,
275,
21598,
63,
697,
14,
362,
63,
4502,
8,
2048,
63,
344,
12,
298,
30682,
531,
523,
340,
4642,
1137,
488,
436,
4642,
14,
2060,
508,
8337,
14,
4835,
17,
8,
2060,
680,
11453,
342,
436,
4642,
14,
374,
6589,
508,
6570,
8760,
63,
6305,
14,
15704,
26,
272,
372,
4642,
523,
587,
26,
272,
372,
488,
2043,
2043,
199
] |
[
1898,
334,
35,
9,
7760,
12,
8142,
9155,
857,
199,
3,
221,
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,
221,
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,
221,
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,
2344,
199,
10502,
641,
21141,
4329,
12,
7760,
199,
199,
1190,
310,
1117,
577,
23320,
3102,
199,
199,
32,
2502,
26,
1033,
290,
199,
2344,
199,
504,
1654,
2441,
14,
5559,
492,
6570,
8760,
63,
6305,
199,
504,
1654,
2441,
14,
8327,
492,
21598,
63,
697,
199,
504,
1654,
2441,
14,
8327,
14,
8370,
492,
4473,
6851,
199,
504,
1654,
2441,
14,
8327,
14,
8583,
492,
377,
293,
6581,
1538,
12,
32598,
12,
31536,
12,
3091,
11612,
12,
971,
523,
7005,
669,
3576,
12,
603,
24156,
199,
504,
1654,
2441,
492,
5262,
221,
199,
504,
1654,
2441,
14,
2537,
492,
3778,
199,
504,
1654,
2441,
14,
20431,
492,
4390,
63,
20431,
199,
646,
8337,
199,
646,
2050,
199,
646,
5377,
421,
199,
318,
1218,
63,
2048,
8,
2123,
12,
718,
2505,
12,
718,
4756,
29,
797,
12,
673,
2933,
63,
466,
628,
66,
2641,
806,
401,
673,
11628,
63,
466,
628,
4624,
2349,
523,
408,
523,
10560,
376,
2933,
543,
1006,
314,
1163,
4346,
5124,
7684,
10038,
14,
523,
408,
2043,
12244,
408,
523,
11105,
26,
523,
3031,
275,
1592,
14,
7035,
3697,
8,
2427,
29,
549,
9,
523,
2505,
275,
1592,
14,
31821,
8,
2427,
29,
549,
2736,
523,
365,
6589,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
3415,
29,
18928,
63,
6305,
14,
15167,
63,
3359,
63,
15514,
9,
523,
2933,
804,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
3415,
29,
409,
8,
18928,
63,
7893,
430,
16421,
11628,
804,
275,
1592,
14,
31821,
8,
2427,
29,
549,
12,
4577,
29,
409,
8,
17698,
4479,
63,
7893,
430,
523,
5494,
1197,
275,
1592,
14,
31821,
8,
2427,
29,
549,
9,
523,
2986,
1197,
275,
1592,
14,
31821,
8,
2427,
29,
549,
9,
523,
22621,
6581,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
52,
293,
6581,
1538,
9,
523,
4501,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
10225,
9,
523,
6915,
3339,
275,
1592,
14,
5083,
3697,
8,
2427,
29,
549,
12,
3659,
63,
533,
29,
19486,
9,
523,
408,
12244,
892,
63,
1374,
6581,
63,
2546,
275,
377,
293,
6581,
1538,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
1374,
6581,
63,
2546,
12,
3031,
9,
819,
892,
63,
4648,
275,
31536,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
4648,
12,
3031,
9,
819,
892,
63,
3438,
275,
32598,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
3438,
12,
3031,
9,
819,
892,
63,
18031,
275,
3091,
11612,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
18031,
12,
3031,
9,
523,
523,
892,
63,
18498,
275,
7005,
669,
3576,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
18498,
12,
3031,
9,
12244,
892,
63,
77,
24156,
275,
603,
24156,
8,
498,
63,
354,
29,
2123,
9,
523,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
63,
77,
24156,
12,
3031,
9,
12244,
408,
7958,
376,
3261,
790,
408,
523,
2986,
63,
498,
275,
620,
8,
2580,
14,
2580,
20,
1012,
12244,
408,
16101,
314,
2505,
408,
523,
19871,
63,
2060,
275,
8337,
14,
4835,
17,
8,
2060,
680,
11453,
342,
12244,
4756,
63,
2048,
275,
6570,
8760,
63,
6305,
14,
21243,
63,
8366,
523,
340,
4756,
26,
272,
4756,
63,
2048,
275,
6570,
8760,
63,
6305,
14,
15704,
12244,
892,
5470,
275,
4473,
6851,
8,
498,
63,
354,
275,
3031,
12,
1993,
3031,
275,
3031,
12,
1993,
2505,
275,
19871,
63,
2060,
12,
1993,
365,
6589,
275,
4756,
63,
2048,
12,
1993,
2933,
804,
275,
2933,
63,
466,
12,
1993,
11628,
804,
275,
11628,
63,
466,
12,
1993,
2986,
1197,
275,
2986,
63,
498,
12,
1993,
5494,
1197,
275,
298,
9505,
5336,
2154,
401,
1993,
22621,
6581,
3339,
275,
892,
63,
1374,
6581,
63,
2546,
12,
1993,
4501,
3339,
275,
892,
63,
3438,
12,
1993,
6915,
3339,
275,
892,
63,
4648,
12,
1993,
30154,
3339,
275,
892,
63,
18031,
12,
1993,
23092,
3339,
275,
892,
63,
18498,
12,
1993,
333,
18072,
3339,
275,
892,
63,
77,
24156,
9,
12244,
862,
26,
272,
21598,
63,
697,
14,
2117,
63,
4502,
8,
1222,
5470,
12,
3031,
9,
523,
871,
26,
272,
2050,
14,
705,
480,
4276,
370,
1218,
2933,
531,
523,
523,
4390,
63,
20431,
14,
981,
63,
1222,
63,
751,
8,
2123,
12,
5262,
14,
879,
32537,
2679,
1668,
63,
3791,
9,
523,
523,
372,
892,
5470,
421,
199,
318,
12895,
63,
2520,
63,
2048,
8,
2048,
63,
344,
12,
2505,
304,
523,
4642,
275,
21598,
63,
697,
14,
362,
63,
4502,
8,
2048,
63,
344,
12,
298,
30682,
531,
523,
340,
4642,
1137,
488,
436,
4642,
14,
2060,
508,
8337,
14,
4835,
17,
8,
2060,
680,
11453,
342,
436,
4642,
14,
374,
6589,
508,
6570,
8760,
63,
6305,
14,
15704,
26,
272,
372,
4642,
523,
587,
26,
272,
372,
488,
2043,
2043,
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,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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
] |
40223227/2015cdbg6w0622-40223227-
|
static/Brython3.1.1-20150328-091302/Lib/decimal.py
|
623
|
230510
|
# Copyright (c) 2004 Python Software Foundation.
# All rights reserved.
# Written by Eric Price <eprice at tjhsst.edu>
# and Facundo Batista <facundo at taniquetil.com.ar>
# and Raymond Hettinger <python at rcn.com>
# and Aahz <aahz at pobox.com>
# and Tim Peters
# This module should be kept in sync with the latest updates of the
# IBM specification as it evolves. Those updates will be treated
# as bug fixes (deviation from the spec is a compatibility, usability
# bug) and will be backported. At this point the spec is stabilizing
# and the updates are becoming fewer, smaller, and less significant.
"""
This is an implementation of decimal floating point arithmetic based on
the General Decimal Arithmetic Specification:
http://speleotrove.com/decimal/decarith.html
and IEEE standard 854-1987:
http://en.wikipedia.org/wiki/IEEE_854-1987
Decimal floating point has finite precision with arbitrarily large bounds.
The purpose of this module is to support arithmetic using familiar
"schoolhouse" rules and to avoid some of the tricky representation
issues associated with binary floating point. The package is especially
useful for financial applications or for contexts where users have
expectations that are at odds with binary floating point (for instance,
in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
of 0.0; Decimal('1.00') % Decimal('0.1') returns the expected
Decimal('0.00')).
Here are some examples of using the decimal module:
>>> from decimal import *
>>> setcontext(ExtendedContext)
>>> Decimal(0)
Decimal('0')
>>> Decimal('1')
Decimal('1')
>>> Decimal('-.0123')
Decimal('-0.0123')
>>> Decimal(123456)
Decimal('123456')
>>> Decimal('123.45e12345678')
Decimal('1.2345E+12345680')
>>> Decimal('1.33') + Decimal('1.27')
Decimal('2.60')
>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
Decimal('-2.20')
>>> dig = Decimal(1)
>>> print(dig / Decimal(3))
0.333333333
>>> getcontext().prec = 18
>>> print(dig / Decimal(3))
0.333333333333333333
>>> print(dig.sqrt())
1
>>> print(Decimal(3).sqrt())
1.73205080756887729
>>> print(Decimal(3) ** 123)
4.85192780976896427E+58
>>> inf = Decimal(1) / Decimal(0)
>>> print(inf)
Infinity
>>> neginf = Decimal(-1) / Decimal(0)
>>> print(neginf)
-Infinity
>>> print(neginf + inf)
NaN
>>> print(neginf * inf)
-Infinity
>>> print(dig / 0)
Infinity
>>> getcontext().traps[DivisionByZero] = 1
>>> print(dig / 0)
Traceback (most recent call last):
...
...
...
decimal.DivisionByZero: x / 0
>>> c = Context()
>>> c.traps[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> c.divide(Decimal(0), Decimal(0))
Decimal('NaN')
>>> c.traps[InvalidOperation] = 1
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> print(c.divide(Decimal(0), Decimal(0)))
Traceback (most recent call last):
...
...
...
decimal.InvalidOperation: 0 / 0
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> c.traps[InvalidOperation] = 0
>>> print(c.divide(Decimal(0), Decimal(0)))
NaN
>>> print(c.flags[InvalidOperation])
1
>>>
"""
__all__ = [
# Two major classes
'Decimal', 'Context',
# Contexts
'DefaultContext', 'BasicContext', 'ExtendedContext',
# Exceptions
'DecimalException', 'Clamped', 'InvalidOperation', 'DivisionByZero',
'Inexact', 'Rounded', 'Subnormal', 'Overflow', 'Underflow',
'FloatOperation',
# Constants for use in setting up contexts
'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN', 'ROUND_05UP',
# Functions for manipulating contexts
'setcontext', 'getcontext', 'localcontext',
# Limits for the C version for compatibility
'MAX_PREC', 'MAX_EMAX', 'MIN_EMIN', 'MIN_ETINY',
# C version: compile time choice that enables the thread local context
'HAVE_THREADS'
]
__version__ = '1.70' # Highest version of the spec this complies with
# See http://speleotrove.com/decimal/
import copy as _copy
import math as _math
import numbers as _numbers
import sys
try:
from collections import namedtuple as _namedtuple
DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
except ImportError:
DecimalTuple = lambda *args: args
# Rounding
ROUND_DOWN = 'ROUND_DOWN'
ROUND_HALF_UP = 'ROUND_HALF_UP'
ROUND_HALF_EVEN = 'ROUND_HALF_EVEN'
ROUND_CEILING = 'ROUND_CEILING'
ROUND_FLOOR = 'ROUND_FLOOR'
ROUND_UP = 'ROUND_UP'
ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
ROUND_05UP = 'ROUND_05UP'
# Compatibility with the C version
HAVE_THREADS = True
if sys.maxsize == 2**63-1:
MAX_PREC = 999999999999999999
MAX_EMAX = 999999999999999999
MIN_EMIN = -999999999999999999
else:
MAX_PREC = 425000000
MAX_EMAX = 425000000
MIN_EMIN = -425000000
MIN_ETINY = MIN_EMIN - (MAX_PREC-1)
# Errors
class DecimalException(ArithmeticError):
"""Base exception class.
Used exceptions derive from this.
If an exception derives from another exception besides this (such as
Underflow (Inexact, Rounded, Subnormal) that indicates that it is only
called if the others are present. This isn't actually used for
anything, though.
handle -- Called when context._raise_error is called and the
trap_enabler is not set. First argument is self, second is the
context. More arguments can be given, those being after
the explanation in _raise_error (For example,
context._raise_error(NewError, '(-x)!', self._sign) would
call NewError().handle(context, self._sign).)
To define a new exception, it should be sufficient to have it derive
from DecimalException.
"""
def handle(self, context, *args):
pass
class Clamped(DecimalException):
"""Exponent of a 0 changed to fit bounds.
This occurs and signals clamped if the exponent of a result has been
altered in order to fit the constraints of a specific concrete
representation. This may occur when the exponent of a zero result would
be outside the bounds of a representation, or when a large normal
number would have an encoded exponent that cannot be represented. In
this latter case, the exponent is reduced to fit and the corresponding
number of zero digits are appended to the coefficient ("fold-down").
"""
#brython fixme
pass
class InvalidOperation(DecimalException):
"""An invalid operation was performed.
Various bad things cause this:
Something creates a signaling NaN
-INF + INF
0 * (+-)INF
(+-)INF / (+-)INF
x % 0
(+-)INF % x
x._rescale( non-integer )
sqrt(-x) , x > 0
0 ** 0
x ** (non-integer)
x ** (+-)INF
An operand is invalid
The result of the operation after these is a quiet positive NaN,
except when the cause is a signaling NaN, in which case the result is
also a quiet NaN, but with the original sign, and an optional
diagnostic information.
"""
def handle(self, context, *args):
if args:
ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True)
return ans._fix_nan(context)
return _NaN
class ConversionSyntax(InvalidOperation):
"""Trying to convert badly formed string.
This occurs and signals invalid-operation if an string is being
converted to a number and it does not conform to the numeric string
syntax. The result is [0,qNaN].
"""
def handle(self, context, *args):
return _NaN
class DivisionByZero(DecimalException, ZeroDivisionError):
"""Division by 0.
This occurs and signals division-by-zero if division of a finite number
by zero was attempted (during a divide-integer or divide operation, or a
power operation with negative right-hand operand), and the dividend was
not zero.
The result of the operation is [sign,inf], where sign is the exclusive
or of the signs of the operands for divide, or is 1 for an odd power of
-0, for power.
"""
def handle(self, context, sign, *args):
return _SignedInfinity[sign]
class DivisionImpossible(InvalidOperation):
"""Cannot perform the division adequately.
This occurs and signals invalid-operation if the integer result of a
divide-integer or remainder operation had too many digits (would be
longer than precision). The result is [0,qNaN].
"""
def handle(self, context, *args):
return _NaN
class DivisionUndefined(InvalidOperation, ZeroDivisionError):
"""Undefined result of division.
This occurs and signals invalid-operation if division by zero was
attempted (during a divide-integer, divide, or remainder operation), and
the dividend is also zero. The result is [0,qNaN].
"""
def handle(self, context, *args):
return _NaN
class Inexact(DecimalException):
"""Had to round, losing information.
This occurs and signals inexact whenever the result of an operation is
not exact (that is, it needed to be rounded and any discarded digits
were non-zero), or if an overflow or underflow condition occurs. The
result in all cases is unchanged.
The inexact signal may be tested (or trapped) to determine if a given
operation (or sequence of operations) was inexact.
"""
#brython fix me
pass
class InvalidContext(InvalidOperation):
"""Invalid context. Unknown rounding, for example.
This occurs and signals invalid-operation if an invalid context was
detected during an operation. This can occur if contexts are not checked
on creation and either the precision exceeds the capability of the
underlying concrete representation or an unknown or unsupported rounding
was specified. These aspects of the context need only be checked when
the values are required to be used. The result is [0,qNaN].
"""
def handle(self, context, *args):
return _NaN
class Rounded(DecimalException):
"""Number got rounded (not necessarily changed during rounding).
This occurs and signals rounded whenever the result of an operation is
rounded (that is, some zero or non-zero digits were discarded from the
coefficient), or if an overflow or underflow condition occurs. The
result in all cases is unchanged.
The rounded signal may be tested (or trapped) to determine if a given
operation (or sequence of operations) caused a loss of precision.
"""
#brython fix me
pass
class Subnormal(DecimalException):
"""Exponent < Emin before rounding.
This occurs and signals subnormal whenever the result of a conversion or
operation is subnormal (that is, its adjusted exponent is less than
Emin, before any rounding). The result in all cases is unchanged.
The subnormal signal may be tested (or trapped) to determine if a given
or operation (or sequence of operations) yielded a subnormal result.
"""
#brython fix me
pass
class Overflow(Inexact, Rounded):
"""Numerical overflow.
This occurs and signals overflow if the adjusted exponent of a result
(from a conversion or from an operation that is not an attempt to divide
by zero), after rounding, would be greater than the largest value that
can be handled by the implementation (the value Emax).
The result depends on the rounding mode:
For round-half-up and round-half-even (and for round-half-down and
round-up, if implemented), the result of the operation is [sign,inf],
where sign is the sign of the intermediate result. For round-down, the
result is the largest finite number that can be represented in the
current precision, with the sign of the intermediate result. For
round-ceiling, the result is the same as for round-down if the sign of
the intermediate result is 1, or is [0,inf] otherwise. For round-floor,
the result is the same as for round-down if the sign of the intermediate
result is 0, or is [1,inf] otherwise. In all cases, Inexact and Rounded
will also be raised.
"""
def handle(self, context, sign, *args):
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
ROUND_HALF_DOWN, ROUND_UP):
return _SignedInfinity[sign]
if sign == 0:
if context.rounding == ROUND_CEILING:
return _SignedInfinity[sign]
return _dec_from_triple(sign, '9'*context.prec,
context.Emax-context.prec+1)
if sign == 1:
if context.rounding == ROUND_FLOOR:
return _SignedInfinity[sign]
return _dec_from_triple(sign, '9'*context.prec,
context.Emax-context.prec+1)
class Underflow(Inexact, Rounded, Subnormal):
"""Numerical underflow with result rounded to 0.
This occurs and signals underflow if a result is inexact and the
adjusted exponent of the result would be smaller (more negative) than
the smallest value that can be handled by the implementation (the value
Emin). That is, the result is both inexact and subnormal.
The result after an underflow will be a subnormal number rounded, if
necessary, so that its exponent is not less than Etiny. This may result
in 0 with the sign of the intermediate result and an exponent of Etiny.
In all cases, Inexact, Rounded, and Subnormal will also be raised.
"""
#brython fix me
pass
class FloatOperation(DecimalException, TypeError):
"""Enable stricter semantics for mixing floats and Decimals.
If the signal is not trapped (default), mixing floats and Decimals is
permitted in the Decimal() constructor, context.create_decimal() and
all comparison operators. Both conversion and comparisons are exact.
Any occurrence of a mixed operation is silently recorded by setting
FloatOperation in the context flags. Explicit conversions with
Decimal.from_float() or context.create_decimal_from_float() do not
set the flag.
Otherwise (the signal is trapped), only equality comparisons and explicit
conversions are silent. All other mixed operations raise FloatOperation.
"""
#brython fix me
pass
# List of public traps and flags
_signals = [Clamped, DivisionByZero, Inexact, Overflow, Rounded,
Underflow, InvalidOperation, Subnormal, FloatOperation]
# Map conditions (per the spec) to signals
_condition_map = {ConversionSyntax:InvalidOperation,
DivisionImpossible:InvalidOperation,
DivisionUndefined:InvalidOperation,
InvalidContext:InvalidOperation}
# Valid rounding modes
_rounding_modes = (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_CEILING,
ROUND_FLOOR, ROUND_UP, ROUND_HALF_DOWN, ROUND_05UP)
##### Context Functions ##################################################
# The getcontext() and setcontext() function manage access to a thread-local
# current context. Py2.4 offers direct support for thread locals. If that
# is not available, use threading.current_thread() which is slower but will
# work for older Pythons. If threads are not part of the build, create a
# mock threading object with threading.local() returning the module namespace.
try:
import threading
except ImportError:
# Python was compiled without threads; create a mock object instead
class MockThreading(object):
def local(self, sys=sys):
return sys.modules[__name__]
threading = MockThreading()
del MockThreading
try:
threading.local
except AttributeError:
# To fix reloading, force it to create a new context
# Old contexts have different exceptions in their dicts, making problems.
if hasattr(threading.current_thread(), '__decimal_context__'):
del threading.current_thread().__decimal_context__
def setcontext(context):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
threading.current_thread().__decimal_context__ = context
def getcontext():
"""Returns this thread's context.
If this thread does not yet have a context, returns
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
"""
try:
return threading.current_thread().__decimal_context__
except AttributeError:
context = Context()
threading.current_thread().__decimal_context__ = context
return context
else:
local = threading.local()
if hasattr(local, '__decimal_context__'):
del local.__decimal_context__
def getcontext(_local=local):
"""Returns this thread's context.
If this thread does not yet have a context, returns
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
"""
try:
return _local.__decimal_context__
except AttributeError:
context = Context()
_local.__decimal_context__ = context
return context
def setcontext(context, _local=local):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
_local.__decimal_context__ = context
del threading, local # Don't contaminate the namespace
def localcontext(ctx=None):
"""Return a context manager for a copy of the supplied context
Uses a copy of the current context if no context is specified
The returned context manager creates a local decimal context
in a with statement:
def sin(x):
with localcontext() as ctx:
ctx.prec += 2
# Rest of sin calculation algorithm
# uses a precision 2 greater than normal
return +s # Convert result to normal precision
def sin(x):
with localcontext(ExtendedContext):
# Rest of sin calculation algorithm
# uses the Extended Context from the
# General Decimal Arithmetic Specification
return +s # Convert result to normal context
>>> setcontext(DefaultContext)
>>> print(getcontext().prec)
28
>>> with localcontext():
... ctx = getcontext()
... ctx.prec += 2
... print(ctx.prec)
...
30
>>> with localcontext(ExtendedContext):
... print(getcontext().prec)
...
9
>>> print(getcontext().prec)
28
"""
if ctx is None: ctx = getcontext()
return _ContextManager(ctx)
##### Decimal class #######################################################
# Do not subclass Decimal from numbers.Real and do not register it as such
# (because Decimals are not interoperable with floats). See the notes in
# numbers.py for more detail.
class Decimal(object):
"""Floating point class for decimal arithmetic."""
__slots__ = ('_exp','_int','_sign', '_is_special')
# Generally, the value of the Decimal instance is given by
# (-1)**_sign * _int * 10**_exp
# Special values are signified by _is_special == True
# We're immutable, so use __new__ not __init__
def __new__(cls, value="0", context=None):
"""Create a decimal point instance.
>>> Decimal('3.14') # string input
Decimal('3.14')
>>> Decimal((0, (3, 1, 4), -2)) # tuple (sign, digit_tuple, exponent)
Decimal('3.14')
>>> Decimal(314) # int
Decimal('314')
>>> Decimal(Decimal(314)) # another decimal instance
Decimal('314')
>>> Decimal(' 3.14 \\n') # leading and trailing whitespace okay
Decimal('3.14')
"""
# Note that the coefficient, self._int, is actually stored as
# a string rather than as a tuple of digits. This speeds up
# the "digits to integer" and "integer to digits" conversions
# that are used in almost every arithmetic operation on
# Decimals. This is an internal detail: the as_tuple function
# and the Decimal constructor still deal with tuples of
# digits.
self = object.__new__(cls)
# From a string
# REs insist on real strings, so we can too.
if isinstance(value, str):
value=value.strip().lower()
if value.startswith("-"):
self._sign = 1
value=value[1:]
else:
self._sign = 0
if value in ('', 'nan'):
self._is_special = True
self._int = ''
#if m.group('signal'): #figure out what a signaling NaN is later
# self._exp = 'N'
#else:
# self._exp = 'n'
self._exp='n'
return self
if value in ('inf', 'infinity'):
self._int = '0'
self._exp = 'F'
self._is_special = True
return self
import _jsre as re
_m=re.match("^\d*\.?\d*(e\+?\d*)?$", value)
if not _m:
self._is_special = True
self._int = ''
self._exp='n'
return self
if '.' in value:
intpart, fracpart=value.split('.')
if 'e' in fracpart:
fracpart, exp=fracpart.split('e')
exp=int(exp)
else:
exp=0
#self._int = str(int(intpart+fracpart))
self._int = intpart+fracpart
self._exp = exp - len(fracpart)
self._is_special = False
return self
else:
#is this a pure int?
self._is_special = False
if 'e' in value:
self._int, _exp=value.split('e')
self._exp=int(_exp)
#print(self._int, self._exp)
else:
self._int = value
self._exp = 0
return self
#m = _parser(value.strip())
#if m is None:
if context is None:
context = getcontext()
return context._raise_error(ConversionSyntax,
"Invalid literal for Decimal: %r" % value)
#if m.group('sign') == "-":
# self._sign = 1
#else:
# self._sign = 0
#intpart = m.group('int')
#if intpart is not None:
# # finite number
# fracpart = m.group('frac') or ''
# exp = int(m.group('exp') or '0')
# self._int = str(int(intpart+fracpart))
# self._exp = exp - len(fracpart)
# self._is_special = False
#else:
# diag = m.group('diag')
# if diag is not None:
# # NaN
# self._int = str(int(diag or '0')).lstrip('0')
# if m.group('signal'):
# self._exp = 'N'
# else:
# self._exp = 'n'
# else:
# # infinity
# self._int = '0'
# self._exp = 'F'
# self._is_special = True
#return self
# From an integer
if isinstance(value, int):
if value >= 0:
self._sign = 0
else:
self._sign = 1
self._exp = 0
self._int = str(abs(value))
self._is_special = False
return self
# From another decimal
if isinstance(value, Decimal):
self._exp = value._exp
self._sign = value._sign
self._int = value._int
self._is_special = value._is_special
return self
# From an internal working value
if isinstance(value, _WorkRep):
self._sign = value.sign
self._int = str(value.int)
self._exp = int(value.exp)
self._is_special = False
return self
# tuple/list conversion (possibly from as_tuple())
if isinstance(value, (list,tuple)):
if len(value) != 3:
raise ValueError('Invalid tuple size in creation of Decimal '
'from list or tuple. The list or tuple '
'should have exactly three elements.')
# process sign. The isinstance test rejects floats
if not (isinstance(value[0], int) and value[0] in (0,1)):
raise ValueError("Invalid sign. The first value in the tuple "
"should be an integer; either 0 for a "
"positive number or 1 for a negative number.")
self._sign = value[0]
if value[2] == 'F':
# infinity: value[1] is ignored
self._int = '0'
self._exp = value[2]
self._is_special = True
else:
# process and validate the digits in value[1]
digits = []
for digit in value[1]:
if isinstance(digit, int) and 0 <= digit <= 9:
# skip leading zeros
if digits or digit != 0:
digits.append(digit)
else:
raise ValueError("The second value in the tuple must "
"be composed of integers in the range "
"0 through 9.")
if value[2] in ('n', 'N'):
# NaN: digits form the diagnostic
self._int = ''.join(map(str, digits))
self._exp = value[2]
self._is_special = True
elif isinstance(value[2], int):
# finite number: digits give the coefficient
self._int = ''.join(map(str, digits or [0]))
self._exp = value[2]
self._is_special = False
else:
raise ValueError("The third value in the tuple must "
"be an integer, or one of the "
"strings 'F', 'n', 'N'.")
return self
if isinstance(value, float):
if context is None:
context = getcontext()
context._raise_error(FloatOperation,
"strict semantics for mixing floats and Decimals are "
"enabled")
value = Decimal.from_float(value)
self._exp = value._exp
self._sign = value._sign
self._int = value._int
self._is_special = value._is_special
return self
raise TypeError("Cannot convert %r to Decimal" % value)
# @classmethod, but @decorator is not valid Python 2.3 syntax, so
# don't use it (see notes on Py2.3 compatibility at top of file)
def from_float(cls, f):
"""Converts a float to a decimal number, exactly.
Note that Decimal.from_float(0.1) is not the same as Decimal('0.1').
Since 0.1 is not exactly representable in binary floating point, the
value is stored as the nearest representable value which is
0x1.999999999999ap-4. The exact equivalent of the value in decimal
is 0.1000000000000000055511151231257827021181583404541015625.
>>> Decimal.from_float(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> Decimal.from_float(float('nan'))
Decimal('NaN')
>>> Decimal.from_float(float('inf'))
Decimal('Infinity')
>>> Decimal.from_float(-float('inf'))
Decimal('-Infinity')
>>> Decimal.from_float(-0.0)
Decimal('-0')
"""
if isinstance(f, int): # handle integer inputs
return cls(f)
if not isinstance(f, float):
raise TypeError("argument must be int or float.")
if _math.isinf(f) or _math.isnan(f):
return cls(repr(f))
if _math.copysign(1.0, f) == 1.0:
sign = 0
else:
sign = 1
n, d = abs(f).as_integer_ratio()
k = d.bit_length() - 1
result = _dec_from_triple(sign, str(n*5**k), -k)
if cls is Decimal:
return result
else:
return cls(result)
from_float = classmethod(from_float)
def _isnan(self):
"""Returns whether the number is not actually one.
0 if a number
1 if NaN
2 if sNaN
"""
if self._is_special:
exp = self._exp
if exp == 'n':
return 1
elif exp == 'N':
return 2
return 0
def _isinfinity(self):
"""Returns whether the number is infinite
0 if finite or not a number
1 if +INF
-1 if -INF
"""
if self._exp == 'F':
if self._sign:
return -1
return 1
return 0
def _check_nans(self, other=None, context=None):
"""Returns whether the number is not actually one.
if self, other are sNaN, signal
if self, other are NaN return nan
return 0
Done before operations.
"""
self_is_nan = self._isnan()
if other is None:
other_is_nan = False
else:
other_is_nan = other._isnan()
if self_is_nan or other_is_nan:
if context is None:
context = getcontext()
if self_is_nan == 2:
return context._raise_error(InvalidOperation, 'sNaN',
self)
if other_is_nan == 2:
return context._raise_error(InvalidOperation, 'sNaN',
other)
if self_is_nan:
return self._fix_nan(context)
return other._fix_nan(context)
return 0
def _compare_check_nans(self, other, context):
"""Version of _check_nans used for the signaling comparisons
compare_signal, __le__, __lt__, __ge__, __gt__.
Signal InvalidOperation if either self or other is a (quiet
or signaling) NaN. Signaling NaNs take precedence over quiet
NaNs.
Return 0 if neither operand is a NaN.
"""
if context is None:
context = getcontext()
if self._is_special or other._is_special:
if self.is_snan():
return context._raise_error(InvalidOperation,
'comparison involving sNaN',
self)
elif other.is_snan():
return context._raise_error(InvalidOperation,
'comparison involving sNaN',
other)
elif self.is_qnan():
return context._raise_error(InvalidOperation,
'comparison involving NaN',
self)
elif other.is_qnan():
return context._raise_error(InvalidOperation,
'comparison involving NaN',
other)
return 0
def __bool__(self):
"""Return True if self is nonzero; otherwise return False.
NaNs and infinities are considered nonzero.
"""
return self._is_special or self._int != '0'
def _cmp(self, other):
"""Compare the two non-NaN decimal instances self and other.
Returns -1 if self < other, 0 if self == other and 1
if self > other. This routine is for internal use only."""
if self._is_special or other._is_special:
self_inf = self._isinfinity()
other_inf = other._isinfinity()
if self_inf == other_inf:
return 0
elif self_inf < other_inf:
return -1
else:
return 1
# check for zeros; Decimal('0') == Decimal('-0')
if not self:
if not other:
return 0
else:
return -((-1)**other._sign)
if not other:
return (-1)**self._sign
# If different signs, neg one is less
if other._sign < self._sign:
return -1
if self._sign < other._sign:
return 1
self_adjusted = self.adjusted()
other_adjusted = other.adjusted()
if self_adjusted == other_adjusted:
self_padded = self._int + '0'*(self._exp - other._exp)
other_padded = other._int + '0'*(other._exp - self._exp)
if self_padded == other_padded:
return 0
elif self_padded < other_padded:
return -(-1)**self._sign
else:
return (-1)**self._sign
elif self_adjusted > other_adjusted:
return (-1)**self._sign
else: # self_adjusted < other_adjusted
return -((-1)**self._sign)
# Note: The Decimal standard doesn't cover rich comparisons for
# Decimals. In particular, the specification is silent on the
# subject of what should happen for a comparison involving a NaN.
# We take the following approach:
#
# == comparisons involving a quiet NaN always return False
# != comparisons involving a quiet NaN always return True
# == or != comparisons involving a signaling NaN signal
# InvalidOperation, and return False or True as above if the
# InvalidOperation is not trapped.
# <, >, <= and >= comparisons involving a (quiet or signaling)
# NaN signal InvalidOperation, and return False if the
# InvalidOperation is not trapped.
#
# This behavior is designed to conform as closely as possible to
# that specified by IEEE 754.
def __eq__(self, other, context=None):
self, other = _convert_for_comparison(self, other, equality_op=True)
if other is NotImplemented:
return other
if self._check_nans(other, context):
return False
return self._cmp(other) == 0
def __ne__(self, other, context=None):
self, other = _convert_for_comparison(self, other, equality_op=True)
if other is NotImplemented:
return other
if self._check_nans(other, context):
return True
return self._cmp(other) != 0
def __lt__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
return False
return self._cmp(other) < 0
def __le__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
return False
return self._cmp(other) <= 0
def __gt__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
return False
return self._cmp(other) > 0
def __ge__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
return False
return self._cmp(other) >= 0
def compare(self, other, context=None):
"""Compares one to another.
-1 => a < b
0 => a = b
1 => a > b
NaN => one is NaN
Like __cmp__, but returns Decimal instances.
"""
other = _convert_other(other, raiseit=True)
# Compare(NaN, NaN) = NaN
if (self._is_special or other and other._is_special):
ans = self._check_nans(other, context)
if ans:
return ans
return Decimal(self._cmp(other))
def __hash__(self):
"""x.__hash__() <==> hash(x)"""
# In order to make sure that the hash of a Decimal instance
# agrees with the hash of a numerically equal integer, float
# or Fraction, we follow the rules for numeric hashes outlined
# in the documentation. (See library docs, 'Built-in Types').
if self._is_special:
if self.is_snan():
raise TypeError('Cannot hash a signaling NaN value.')
elif self.is_nan():
return _PyHASH_NAN
else:
if self._sign:
return -_PyHASH_INF
else:
return _PyHASH_INF
if self._exp >= 0:
exp_hash = pow(10, self._exp, _PyHASH_MODULUS)
else:
exp_hash = pow(_PyHASH_10INV, -self._exp, _PyHASH_MODULUS)
hash_ = int(self._int) * exp_hash % _PyHASH_MODULUS
ans = hash_ if self >= 0 else -hash_
return -2 if ans == -1 else ans
def as_tuple(self):
"""Represents the number as a triple tuple.
To show the internals exactly as they are.
"""
return DecimalTuple(self._sign, tuple(map(int, self._int)), self._exp)
def __repr__(self):
"""Represents the number as an instance of Decimal."""
# Invariant: eval(repr(d)) == d
return "Decimal('%s')" % str(self)
def __str__(self, eng=False, context=None):
"""Return string representation of the number in scientific notation.
Captures all of the information in the underlying representation.
"""
sign = ['', '-'][self._sign]
if self._is_special:
if self._exp == 'F':
return sign + 'Infinity'
elif self._exp == 'n':
return sign + 'NaN' + self._int
else: # self._exp == 'N'
return sign + 'sNaN' + self._int
# number of digits of self._int to left of decimal point
leftdigits = self._exp + len(self._int)
# dotplace is number of digits of self._int to the left of the
# decimal point in the mantissa of the output string (that is,
# after adjusting the exponent)
if self._exp <= 0 and leftdigits > -6:
# no exponent required
dotplace = leftdigits
elif not eng:
# usual scientific notation: 1 digit on left of the point
dotplace = 1
elif self._int == '0':
# engineering notation, zero
dotplace = (leftdigits + 1) % 3 - 1
else:
# engineering notation, nonzero
dotplace = (leftdigits - 1) % 3 + 1
if dotplace <= 0:
intpart = '0'
fracpart = '.' + '0'*(-dotplace) + self._int
elif dotplace >= len(self._int):
intpart = self._int+'0'*(dotplace-len(self._int))
fracpart = ''
else:
intpart = self._int[:dotplace]
fracpart = '.' + self._int[dotplace:]
if leftdigits == dotplace:
exp = ''
else:
if context is None:
context = getcontext()
exp = ['e', 'E'][context.capitals] + "%+d" % (leftdigits-dotplace)
return sign + intpart + fracpart + exp
def to_eng_string(self, context=None):
"""Convert to engineering-type string.
Engineering notation has an exponent which is a multiple of 3, so there
are up to 3 digits left of the decimal place.
Same rules for when in exponential and when as a value as in __str__.
"""
return self.__str__(eng=True, context=context)
def __neg__(self, context=None):
"""Returns a copy with the sign switched.
Rounds, if it has reason.
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if context is None:
context = getcontext()
if not self and context.rounding != ROUND_FLOOR:
# -Decimal('0') is Decimal('0'), not Decimal('-0'), except
# in ROUND_FLOOR rounding mode.
ans = self.copy_abs()
else:
ans = self.copy_negate()
return ans._fix(context)
def __pos__(self, context=None):
"""Returns a copy, unless it is a sNaN.
Rounds the number (if more then precision digits)
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if context is None:
context = getcontext()
if not self and context.rounding != ROUND_FLOOR:
# + (-0) = 0, except in ROUND_FLOOR rounding mode.
ans = self.copy_abs()
else:
ans = Decimal(self)
return ans._fix(context)
def __abs__(self, round=True, context=None):
"""Returns the absolute value of self.
If the keyword argument 'round' is false, do not round. The
expression self.__abs__(round=False) is equivalent to
self.copy_abs().
"""
if not round:
return self.copy_abs()
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if self._sign:
ans = self.__neg__(context=context)
else:
ans = self.__pos__(context=context)
return ans
def __add__(self, other, context=None):
"""Returns self + other.
-INF + INF (or the reverse) cause InvalidOperation errors.
"""
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
return ans
if self._isinfinity():
# If both INF, same sign => same as both, opposite => error.
if self._sign != other._sign and other._isinfinity():
return context._raise_error(InvalidOperation, '-INF + INF')
return Decimal(self)
if other._isinfinity():
return Decimal(other) # Can't both be infinity here
exp = min(self._exp, other._exp)
negativezero = 0
if context.rounding == ROUND_FLOOR and self._sign != other._sign:
# If the answer is 0, the sign should be negative, in this case.
negativezero = 1
if not self and not other:
sign = min(self._sign, other._sign)
if negativezero:
sign = 1
ans = _dec_from_triple(sign, '0', exp)
ans = ans._fix(context)
return ans
if not self:
exp = max(exp, other._exp - context.prec-1)
ans = other._rescale(exp, context.rounding)
ans = ans._fix(context)
return ans
if not other:
exp = max(exp, self._exp - context.prec-1)
ans = self._rescale(exp, context.rounding)
ans = ans._fix(context)
return ans
op1 = _WorkRep(self)
op2 = _WorkRep(other)
op1, op2 = _normalize(op1, op2, context.prec)
result = _WorkRep()
if op1.sign != op2.sign:
# Equal and opposite
if op1.int == op2.int:
ans = _dec_from_triple(negativezero, '0', exp)
ans = ans._fix(context)
return ans
if op1.int < op2.int:
op1, op2 = op2, op1
# OK, now abs(op1) > abs(op2)
if op1.sign == 1:
result.sign = 1
op1.sign, op2.sign = op2.sign, op1.sign
else:
result.sign = 0
# So we know the sign, and op1 > 0.
elif op1.sign == 1:
result.sign = 1
op1.sign, op2.sign = (0, 0)
else:
result.sign = 0
# Now, op1 > abs(op2) > 0
if op2.sign == 0:
result.int = op1.int + op2.int
else:
result.int = op1.int - op2.int
result.exp = op1.exp
ans = Decimal(result)
ans = ans._fix(context)
return ans
__radd__ = __add__
def __sub__(self, other, context=None):
"""Return self - other"""
other = _convert_other(other)
if other is NotImplemented:
return other
if self._is_special or other._is_special:
ans = self._check_nans(other, context=context)
if ans:
return ans
# self - other is computed as self + other.copy_negate()
return self.__add__(other.copy_negate(), context=context)
def __rsub__(self, other, context=None):
"""Return other - self"""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__sub__(self, context=context)
def __mul__(self, other, context=None):
"""Return self * other.
(+-) INF * 0 (or its reverse) raise InvalidOperation.
"""
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
resultsign = self._sign ^ other._sign
if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
return ans
if self._isinfinity():
if not other:
return context._raise_error(InvalidOperation, '(+-)INF * 0')
return _SignedInfinity[resultsign]
if other._isinfinity():
if not self:
return context._raise_error(InvalidOperation, '0 * (+-)INF')
return _SignedInfinity[resultsign]
resultexp = self._exp + other._exp
# Special case for multiplying by zero
if not self or not other:
ans = _dec_from_triple(resultsign, '0', resultexp)
# Fixing in case the exponent is out of bounds
ans = ans._fix(context)
return ans
# Special case for multiplying by power of 10
if self._int == '1':
ans = _dec_from_triple(resultsign, other._int, resultexp)
ans = ans._fix(context)
return ans
if other._int == '1':
ans = _dec_from_triple(resultsign, self._int, resultexp)
ans = ans._fix(context)
return ans
op1 = _WorkRep(self)
op2 = _WorkRep(other)
ans = _dec_from_triple(resultsign, str(op1.int * op2.int), resultexp)
ans = ans._fix(context)
return ans
__rmul__ = __mul__
def __truediv__(self, other, context=None):
"""Return self / other."""
other = _convert_other(other)
if other is NotImplemented:
return NotImplemented
if context is None:
context = getcontext()
sign = self._sign ^ other._sign
if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
return ans
if self._isinfinity() and other._isinfinity():
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
if self._isinfinity():
return _SignedInfinity[sign]
if other._isinfinity():
context._raise_error(Clamped, 'Division by infinity')
return _dec_from_triple(sign, '0', context.Etiny())
# Special cases for zeroes
if not other:
if not self:
return context._raise_error(DivisionUndefined, '0 / 0')
return context._raise_error(DivisionByZero, 'x / 0', sign)
if not self:
exp = self._exp - other._exp
coeff = 0
else:
# OK, so neither = 0, INF or NaN
shift = len(other._int) - len(self._int) + context.prec + 1
exp = self._exp - other._exp - shift
op1 = _WorkRep(self)
op2 = _WorkRep(other)
if shift >= 0:
coeff, remainder = divmod(op1.int * 10**shift, op2.int)
else:
coeff, remainder = divmod(op1.int, op2.int * 10**-shift)
if remainder:
# result is not exact; adjust to ensure correct rounding
if coeff % 5 == 0:
coeff += 1
else:
# result is exact; get as close to ideal exponent as possible
ideal_exp = self._exp - other._exp
while exp < ideal_exp and coeff % 10 == 0:
coeff //= 10
exp += 1
ans = _dec_from_triple(sign, str(coeff), exp)
return ans._fix(context)
def _divide(self, other, context):
"""Return (self // other, self % other), to context.prec precision.
Assumes that neither self nor other is a NaN, that self is not
infinite and that other is nonzero.
"""
sign = self._sign ^ other._sign
if other._isinfinity():
ideal_exp = self._exp
else:
ideal_exp = min(self._exp, other._exp)
expdiff = self.adjusted() - other.adjusted()
if not self or other._isinfinity() or expdiff <= -2:
return (_dec_from_triple(sign, '0', 0),
self._rescale(ideal_exp, context.rounding))
if expdiff <= context.prec:
op1 = _WorkRep(self)
op2 = _WorkRep(other)
if op1.exp >= op2.exp:
op1.int *= 10**(op1.exp - op2.exp)
else:
op2.int *= 10**(op2.exp - op1.exp)
q, r = divmod(op1.int, op2.int)
if q < 10**context.prec:
return (_dec_from_triple(sign, str(q), 0),
_dec_from_triple(self._sign, str(r), ideal_exp))
# Here the quotient is too large to be representable
ans = context._raise_error(DivisionImpossible,
'quotient too large in //, % or divmod')
return ans, ans
def __rtruediv__(self, other, context=None):
"""Swaps self/other and returns __truediv__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__truediv__(self, context=context)
def __divmod__(self, other, context=None):
"""
Return (self // other, self % other)
"""
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
ans = self._check_nans(other, context)
if ans:
return (ans, ans)
sign = self._sign ^ other._sign
if self._isinfinity():
if other._isinfinity():
ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
return ans, ans
else:
return (_SignedInfinity[sign],
context._raise_error(InvalidOperation, 'INF % x'))
if not other:
if not self:
ans = context._raise_error(DivisionUndefined, 'divmod(0, 0)')
return ans, ans
else:
return (context._raise_error(DivisionByZero, 'x // 0', sign),
context._raise_error(InvalidOperation, 'x % 0'))
quotient, remainder = self._divide(other, context)
remainder = remainder._fix(context)
return quotient, remainder
def __rdivmod__(self, other, context=None):
"""Swaps self/other and returns __divmod__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__divmod__(self, context=context)
def __mod__(self, other, context=None):
"""
self % other
"""
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
ans = self._check_nans(other, context)
if ans:
return ans
if self._isinfinity():
return context._raise_error(InvalidOperation, 'INF % x')
elif not other:
if self:
return context._raise_error(InvalidOperation, 'x % 0')
else:
return context._raise_error(DivisionUndefined, '0 % 0')
remainder = self._divide(other, context)[1]
remainder = remainder._fix(context)
return remainder
def __rmod__(self, other, context=None):
"""Swaps self/other and returns __mod__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__mod__(self, context=context)
def remainder_near(self, other, context=None):
"""
Remainder nearest to 0- abs(remainder-near) <= other/2
"""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
ans = self._check_nans(other, context)
if ans:
return ans
# self == +/-infinity -> InvalidOperation
if self._isinfinity():
return context._raise_error(InvalidOperation,
'remainder_near(infinity, x)')
# other == 0 -> either InvalidOperation or DivisionUndefined
if not other:
if self:
return context._raise_error(InvalidOperation,
'remainder_near(x, 0)')
else:
return context._raise_error(DivisionUndefined,
'remainder_near(0, 0)')
# other = +/-infinity -> remainder = self
if other._isinfinity():
ans = Decimal(self)
return ans._fix(context)
# self = 0 -> remainder = self, with ideal exponent
ideal_exponent = min(self._exp, other._exp)
if not self:
ans = _dec_from_triple(self._sign, '0', ideal_exponent)
return ans._fix(context)
# catch most cases of large or small quotient
expdiff = self.adjusted() - other.adjusted()
if expdiff >= context.prec + 1:
# expdiff >= prec+1 => abs(self/other) > 10**prec
return context._raise_error(DivisionImpossible)
if expdiff <= -2:
# expdiff <= -2 => abs(self/other) < 0.1
ans = self._rescale(ideal_exponent, context.rounding)
return ans._fix(context)
# adjust both arguments to have the same exponent, then divide
op1 = _WorkRep(self)
op2 = _WorkRep(other)
if op1.exp >= op2.exp:
op1.int *= 10**(op1.exp - op2.exp)
else:
op2.int *= 10**(op2.exp - op1.exp)
q, r = divmod(op1.int, op2.int)
# remainder is r*10**ideal_exponent; other is +/-op2.int *
# 10**ideal_exponent. Apply correction to ensure that
# abs(remainder) <= abs(other)/2
if 2*r + (q&1) > op2.int:
r -= op2.int
q += 1
if q >= 10**context.prec:
return context._raise_error(DivisionImpossible)
# result has same sign as self unless r is negative
sign = self._sign
if r < 0:
sign = 1-sign
r = -r
ans = _dec_from_triple(sign, str(r), ideal_exponent)
return ans._fix(context)
def __floordiv__(self, other, context=None):
"""self // other"""
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
ans = self._check_nans(other, context)
if ans:
return ans
if self._isinfinity():
if other._isinfinity():
return context._raise_error(InvalidOperation, 'INF // INF')
else:
return _SignedInfinity[self._sign ^ other._sign]
if not other:
if self:
return context._raise_error(DivisionByZero, 'x // 0',
self._sign ^ other._sign)
else:
return context._raise_error(DivisionUndefined, '0 // 0')
return self._divide(other, context)[0]
def __rfloordiv__(self, other, context=None):
"""Swaps self/other and returns __floordiv__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__floordiv__(self, context=context)
def __float__(self):
"""Float representation."""
if self._isnan():
if self.is_snan():
raise ValueError("Cannot convert signaling NaN to float")
s = "-nan" if self._sign else "nan"
else:
s = str(self)
return float(s)
def __int__(self):
"""Converts self to an int, truncating if necessary."""
if self._is_special:
if self._isnan():
raise ValueError("Cannot convert NaN to integer")
elif self._isinfinity():
raise OverflowError("Cannot convert infinity to integer")
s = (-1)**self._sign
if self._exp >= 0:
return s*int(self._int)*10**self._exp
else:
return s*int(self._int[:self._exp] or '0')
__trunc__ = __int__
def real(self):
return self
real = property(real)
def imag(self):
return Decimal(0)
imag = property(imag)
def conjugate(self):
return self
def __complex__(self):
return complex(float(self))
def _fix_nan(self, context):
"""Decapitate the payload of a NaN to fit the context"""
payload = self._int
# maximum length of payload is precision if clamp=0,
# precision-1 if clamp=1.
max_payload_len = context.prec - context.clamp
if len(payload) > max_payload_len:
payload = payload[len(payload)-max_payload_len:].lstrip('0')
return _dec_from_triple(self._sign, payload, self._exp, True)
return Decimal(self)
def _fix(self, context):
"""Round if it is necessary to keep self within prec precision.
Rounds and fixes the exponent. Does not raise on a sNaN.
Arguments:
self - Decimal instance
context - context used.
"""
if self._is_special:
if self._isnan():
# decapitate payload if necessary
return self._fix_nan(context)
else:
# self is +/-Infinity; return unaltered
return Decimal(self)
# if self is zero then exponent should be between Etiny and
# Emax if clamp==0, and between Etiny and Etop if clamp==1.
Etiny = context.Etiny()
Etop = context.Etop()
if not self:
exp_max = [context.Emax, Etop][context.clamp]
new_exp = min(max(self._exp, Etiny), exp_max)
if new_exp != self._exp:
context._raise_error(Clamped)
return _dec_from_triple(self._sign, '0', new_exp)
else:
return Decimal(self)
# exp_min is the smallest allowable exponent of the result,
# equal to max(self.adjusted()-context.prec+1, Etiny)
exp_min = len(self._int) + self._exp - context.prec
if exp_min > Etop:
# overflow: exp_min > Etop iff self.adjusted() > Emax
ans = context._raise_error(Overflow, 'above Emax', self._sign)
context._raise_error(Inexact)
context._raise_error(Rounded)
return ans
self_is_subnormal = exp_min < Etiny
if self_is_subnormal:
exp_min = Etiny
# round if self has too many digits
if self._exp < exp_min:
digits = len(self._int) + self._exp - exp_min
if digits < 0:
self = _dec_from_triple(self._sign, '1', exp_min-1)
digits = 0
rounding_method = self._pick_rounding_function[context.rounding]
changed = rounding_method(self, digits)
coeff = self._int[:digits] or '0'
if changed > 0:
coeff = str(int(coeff)+1)
if len(coeff) > context.prec:
coeff = coeff[:-1]
exp_min += 1
# check whether the rounding pushed the exponent out of range
if exp_min > Etop:
ans = context._raise_error(Overflow, 'above Emax', self._sign)
else:
ans = _dec_from_triple(self._sign, coeff, exp_min)
# raise the appropriate signals, taking care to respect
# the precedence described in the specification
if changed and self_is_subnormal:
context._raise_error(Underflow)
if self_is_subnormal:
context._raise_error(Subnormal)
if changed:
context._raise_error(Inexact)
context._raise_error(Rounded)
if not ans:
# raise Clamped on underflow to 0
context._raise_error(Clamped)
return ans
if self_is_subnormal:
context._raise_error(Subnormal)
# fold down if clamp == 1 and self has too few digits
if context.clamp == 1 and self._exp > Etop:
context._raise_error(Clamped)
self_padded = self._int + '0'*(self._exp - Etop)
return _dec_from_triple(self._sign, self_padded, Etop)
# here self was representable to begin with; return unchanged
return Decimal(self)
# for each of the rounding functions below:
# self is a finite, nonzero Decimal
# prec is an integer satisfying 0 <= prec < len(self._int)
#
# each function returns either -1, 0, or 1, as follows:
# 1 indicates that self should be rounded up (away from zero)
# 0 indicates that self should be truncated, and that all the
# digits to be truncated are zeros (so the value is unchanged)
# -1 indicates that there are nonzero digits to be truncated
def _round_down(self, prec):
"""Also known as round-towards-0, truncate."""
if _all_zeros(self._int, prec):
return 0
else:
return -1
def _round_up(self, prec):
"""Rounds away from 0."""
return -self._round_down(prec)
def _round_half_up(self, prec):
"""Rounds 5 up (away from 0)"""
if self._int[prec] in '56789':
return 1
elif _all_zeros(self._int, prec):
return 0
else:
return -1
def _round_half_down(self, prec):
"""Round 5 down"""
if _exact_half(self._int, prec):
return -1
else:
return self._round_half_up(prec)
def _round_half_even(self, prec):
"""Round 5 to even, rest to nearest."""
if _exact_half(self._int, prec) and \
(prec == 0 or self._int[prec-1] in '02468'):
return -1
else:
return self._round_half_up(prec)
def _round_ceiling(self, prec):
"""Rounds up (not away from 0 if negative.)"""
if self._sign:
return self._round_down(prec)
else:
return -self._round_down(prec)
def _round_floor(self, prec):
"""Rounds down (not towards 0 if negative)"""
if not self._sign:
return self._round_down(prec)
else:
return -self._round_down(prec)
def _round_05up(self, prec):
"""Round down unless digit prec-1 is 0 or 5."""
if prec and self._int[prec-1] not in '05':
return self._round_down(prec)
else:
return -self._round_down(prec)
_pick_rounding_function = dict(
ROUND_DOWN = _round_down,
ROUND_UP = _round_up,
ROUND_HALF_UP = _round_half_up,
ROUND_HALF_DOWN = _round_half_down,
ROUND_HALF_EVEN = _round_half_even,
ROUND_CEILING = _round_ceiling,
ROUND_FLOOR = _round_floor,
ROUND_05UP = _round_05up,
)
def __round__(self, n=None):
"""Round self to the nearest integer, or to a given precision.
If only one argument is supplied, round a finite Decimal
instance self to the nearest integer. If self is infinite or
a NaN then a Python exception is raised. If self is finite
and lies exactly halfway between two integers then it is
rounded to the integer with even last digit.
>>> round(Decimal('123.456'))
123
>>> round(Decimal('-456.789'))
-457
>>> round(Decimal('-3.0'))
-3
>>> round(Decimal('2.5'))
2
>>> round(Decimal('3.5'))
4
>>> round(Decimal('Inf'))
Traceback (most recent call last):
...
OverflowError: cannot round an infinity
>>> round(Decimal('NaN'))
Traceback (most recent call last):
...
ValueError: cannot round a NaN
If a second argument n is supplied, self is rounded to n
decimal places using the rounding mode for the current
context.
For an integer n, round(self, -n) is exactly equivalent to
self.quantize(Decimal('1En')).
>>> round(Decimal('123.456'), 0)
Decimal('123')
>>> round(Decimal('123.456'), 2)
Decimal('123.46')
>>> round(Decimal('123.456'), -2)
Decimal('1E+2')
>>> round(Decimal('-Infinity'), 37)
Decimal('NaN')
>>> round(Decimal('sNaN123'), 0)
Decimal('NaN123')
"""
if n is not None:
# two-argument form: use the equivalent quantize call
if not isinstance(n, int):
raise TypeError('Second argument to round should be integral')
exp = _dec_from_triple(0, '1', -n)
return self.quantize(exp)
# one-argument form
if self._is_special:
if self.is_nan():
raise ValueError("cannot round a NaN")
else:
raise OverflowError("cannot round an infinity")
return int(self._rescale(0, ROUND_HALF_EVEN))
def __floor__(self):
"""Return the floor of self, as an integer.
For a finite Decimal instance self, return the greatest
integer n such that n <= self. If self is infinite or a NaN
then a Python exception is raised.
"""
if self._is_special:
if self.is_nan():
raise ValueError("cannot round a NaN")
else:
raise OverflowError("cannot round an infinity")
return int(self._rescale(0, ROUND_FLOOR))
def __ceil__(self):
"""Return the ceiling of self, as an integer.
For a finite Decimal instance self, return the least integer n
such that n >= self. If self is infinite or a NaN then a
Python exception is raised.
"""
if self._is_special:
if self.is_nan():
raise ValueError("cannot round a NaN")
else:
raise OverflowError("cannot round an infinity")
return int(self._rescale(0, ROUND_CEILING))
def fma(self, other, third, context=None):
"""Fused multiply-add.
Returns self*other+third with no rounding of the intermediate
product self*other.
self and other are multiplied together, with no rounding of
the result. The third operand is then added to the result,
and a single final rounding is performed.
"""
other = _convert_other(other, raiseit=True)
third = _convert_other(third, raiseit=True)
# compute product; raise InvalidOperation if either operand is
# a signaling NaN or if the product is zero times infinity.
if self._is_special or other._is_special:
if context is None:
context = getcontext()
if self._exp == 'N':
return context._raise_error(InvalidOperation, 'sNaN', self)
if other._exp == 'N':
return context._raise_error(InvalidOperation, 'sNaN', other)
if self._exp == 'n':
product = self
elif other._exp == 'n':
product = other
elif self._exp == 'F':
if not other:
return context._raise_error(InvalidOperation,
'INF * 0 in fma')
product = _SignedInfinity[self._sign ^ other._sign]
elif other._exp == 'F':
if not self:
return context._raise_error(InvalidOperation,
'0 * INF in fma')
product = _SignedInfinity[self._sign ^ other._sign]
else:
product = _dec_from_triple(self._sign ^ other._sign,
str(int(self._int) * int(other._int)),
self._exp + other._exp)
return product.__add__(third, context)
def _power_modulo(self, other, modulo, context=None):
"""Three argument version of __pow__"""
other = _convert_other(other)
if other is NotImplemented:
return other
modulo = _convert_other(modulo)
if modulo is NotImplemented:
return modulo
if context is None:
context = getcontext()
# deal with NaNs: if there are any sNaNs then first one wins,
# (i.e. behaviour for NaNs is identical to that of fma)
self_is_nan = self._isnan()
other_is_nan = other._isnan()
modulo_is_nan = modulo._isnan()
if self_is_nan or other_is_nan or modulo_is_nan:
if self_is_nan == 2:
return context._raise_error(InvalidOperation, 'sNaN',
self)
if other_is_nan == 2:
return context._raise_error(InvalidOperation, 'sNaN',
other)
if modulo_is_nan == 2:
return context._raise_error(InvalidOperation, 'sNaN',
modulo)
if self_is_nan:
return self._fix_nan(context)
if other_is_nan:
return other._fix_nan(context)
return modulo._fix_nan(context)
# check inputs: we apply same restrictions as Python's pow()
if not (self._isinteger() and
other._isinteger() and
modulo._isinteger()):
return context._raise_error(InvalidOperation,
'pow() 3rd argument not allowed '
'unless all arguments are integers')
if other < 0:
return context._raise_error(InvalidOperation,
'pow() 2nd argument cannot be '
'negative when 3rd argument specified')
if not modulo:
return context._raise_error(InvalidOperation,
'pow() 3rd argument cannot be 0')
# additional restriction for decimal: the modulus must be less
# than 10**prec in absolute value
if modulo.adjusted() >= context.prec:
return context._raise_error(InvalidOperation,
'insufficient precision: pow() 3rd '
'argument must not have more than '
'precision digits')
# define 0**0 == NaN, for consistency with two-argument pow
# (even though it hurts!)
if not other and not self:
return context._raise_error(InvalidOperation,
'at least one of pow() 1st argument '
'and 2nd argument must be nonzero ;'
'0**0 is not defined')
# compute sign of result
if other._iseven():
sign = 0
else:
sign = self._sign
# convert modulo to a Python integer, and self and other to
# Decimal integers (i.e. force their exponents to be >= 0)
modulo = abs(int(modulo))
base = _WorkRep(self.to_integral_value())
exponent = _WorkRep(other.to_integral_value())
# compute result using integer pow()
base = (base.int % modulo * pow(10, base.exp, modulo)) % modulo
for i in range(exponent.exp):
base = pow(base, 10, modulo)
base = pow(base, exponent.int, modulo)
return _dec_from_triple(sign, str(base), 0)
def _power_exact(self, other, p):
"""Attempt to compute self**other exactly.
Given Decimals self and other and an integer p, attempt to
compute an exact result for the power self**other, with p
digits of precision. Return None if self**other is not
exactly representable in p digits.
Assumes that elimination of special cases has already been
performed: self and other must both be nonspecial; self must
be positive and not numerically equal to 1; other must be
nonzero. For efficiency, other._exp should not be too large,
so that 10**abs(other._exp) is a feasible calculation."""
# In the comments below, we write x for the value of self and y for the
# value of other. Write x = xc*10**xe and abs(y) = yc*10**ye, with xc
# and yc positive integers not divisible by 10.
# The main purpose of this method is to identify the *failure*
# of x**y to be exactly representable with as little effort as
# possible. So we look for cheap and easy tests that
# eliminate the possibility of x**y being exact. Only if all
# these tests are passed do we go on to actually compute x**y.
# Here's the main idea. Express y as a rational number m/n, with m and
# n relatively prime and n>0. Then for x**y to be exactly
# representable (at *any* precision), xc must be the nth power of a
# positive integer and xe must be divisible by n. If y is negative
# then additionally xc must be a power of either 2 or 5, hence a power
# of 2**n or 5**n.
#
# There's a limit to how small |y| can be: if y=m/n as above
# then:
#
# (1) if xc != 1 then for the result to be representable we
# need xc**(1/n) >= 2, and hence also xc**|y| >= 2. So
# if |y| <= 1/nbits(xc) then xc < 2**nbits(xc) <=
# 2**(1/|y|), hence xc**|y| < 2 and the result is not
# representable.
#
# (2) if xe != 0, |xe|*(1/n) >= 1, so |xe|*|y| >= 1. Hence if
# |y| < 1/|xe| then the result is not representable.
#
# Note that since x is not equal to 1, at least one of (1) and
# (2) must apply. Now |y| < 1/nbits(xc) iff |yc|*nbits(xc) <
# 10**-ye iff len(str(|yc|*nbits(xc)) <= -ye.
#
# There's also a limit to how large y can be, at least if it's
# positive: the normalized result will have coefficient xc**y,
# so if it's representable then xc**y < 10**p, and y <
# p/log10(xc). Hence if y*log10(xc) >= p then the result is
# not exactly representable.
# if len(str(abs(yc*xe)) <= -ye then abs(yc*xe) < 10**-ye,
# so |y| < 1/xe and the result is not representable.
# Similarly, len(str(abs(yc)*xc_bits)) <= -ye implies |y|
# < 1/nbits(xc).
x = _WorkRep(self)
xc, xe = x.int, x.exp
while xc % 10 == 0:
xc //= 10
xe += 1
y = _WorkRep(other)
yc, ye = y.int, y.exp
while yc % 10 == 0:
yc //= 10
ye += 1
# case where xc == 1: result is 10**(xe*y), with xe*y
# required to be an integer
if xc == 1:
xe *= yc
# result is now 10**(xe * 10**ye); xe * 10**ye must be integral
while xe % 10 == 0:
xe //= 10
ye += 1
if ye < 0:
return None
exponent = xe * 10**ye
if y.sign == 1:
exponent = -exponent
# if other is a nonnegative integer, use ideal exponent
if other._isinteger() and other._sign == 0:
ideal_exponent = self._exp*int(other)
zeros = min(exponent-ideal_exponent, p-1)
else:
zeros = 0
return _dec_from_triple(0, '1' + '0'*zeros, exponent-zeros)
# case where y is negative: xc must be either a power
# of 2 or a power of 5.
if y.sign == 1:
last_digit = xc % 10
if last_digit in (2,4,6,8):
# quick test for power of 2
if xc & -xc != xc:
return None
# now xc is a power of 2; e is its exponent
e = _nbits(xc)-1
# We now have:
#
# x = 2**e * 10**xe, e > 0, and y < 0.
#
# The exact result is:
#
# x**y = 5**(-e*y) * 10**(e*y + xe*y)
#
# provided that both e*y and xe*y are integers. Note that if
# 5**(-e*y) >= 10**p, then the result can't be expressed
# exactly with p digits of precision.
#
# Using the above, we can guard against large values of ye.
# 93/65 is an upper bound for log(10)/log(5), so if
#
# ye >= len(str(93*p//65))
#
# then
#
# -e*y >= -y >= 10**ye > 93*p/65 > p*log(10)/log(5),
#
# so 5**(-e*y) >= 10**p, and the coefficient of the result
# can't be expressed in p digits.
# emax >= largest e such that 5**e < 10**p.
emax = p*93//65
if ye >= len(str(emax)):
return None
# Find -e*y and -xe*y; both must be integers
e = _decimal_lshift_exact(e * yc, ye)
xe = _decimal_lshift_exact(xe * yc, ye)
if e is None or xe is None:
return None
if e > emax:
return None
xc = 5**e
elif last_digit == 5:
# e >= log_5(xc) if xc is a power of 5; we have
# equality all the way up to xc=5**2658
e = _nbits(xc)*28//65
xc, remainder = divmod(5**e, xc)
if remainder:
return None
while xc % 5 == 0:
xc //= 5
e -= 1
# Guard against large values of ye, using the same logic as in
# the 'xc is a power of 2' branch. 10/3 is an upper bound for
# log(10)/log(2).
emax = p*10//3
if ye >= len(str(emax)):
return None
e = _decimal_lshift_exact(e * yc, ye)
xe = _decimal_lshift_exact(xe * yc, ye)
if e is None or xe is None:
return None
if e > emax:
return None
xc = 2**e
else:
return None
if xc >= 10**p:
return None
xe = -e-xe
return _dec_from_triple(0, str(xc), xe)
# now y is positive; find m and n such that y = m/n
if ye >= 0:
m, n = yc*10**ye, 1
else:
if xe != 0 and len(str(abs(yc*xe))) <= -ye:
return None
xc_bits = _nbits(xc)
if xc != 1 and len(str(abs(yc)*xc_bits)) <= -ye:
return None
m, n = yc, 10**(-ye)
while m % 2 == n % 2 == 0:
m //= 2
n //= 2
while m % 5 == n % 5 == 0:
m //= 5
n //= 5
# compute nth root of xc*10**xe
if n > 1:
# if 1 < xc < 2**n then xc isn't an nth power
if xc != 1 and xc_bits <= n:
return None
xe, rem = divmod(xe, n)
if rem != 0:
return None
# compute nth root of xc using Newton's method
a = 1 << -(-_nbits(xc)//n) # initial estimate
while True:
q, r = divmod(xc, a**(n-1))
if a <= q:
break
else:
a = (a*(n-1) + q)//n
if not (a == q and r == 0):
return None
xc = a
# now xc*10**xe is the nth root of the original xc*10**xe
# compute mth power of xc*10**xe
# if m > p*100//_log10_lb(xc) then m > p/log10(xc), hence xc**m >
# 10**p and the result is not representable.
if xc > 1 and m > p*100//_log10_lb(xc):
return None
xc = xc**m
xe *= m
if xc > 10**p:
return None
# by this point the result *is* exactly representable
# adjust the exponent to get as close as possible to the ideal
# exponent, if necessary
str_xc = str(xc)
if other._isinteger() and other._sign == 0:
ideal_exponent = self._exp*int(other)
zeros = min(xe-ideal_exponent, p-len(str_xc))
else:
zeros = 0
return _dec_from_triple(0, str_xc+'0'*zeros, xe-zeros)
def __pow__(self, other, modulo=None, context=None):
"""Return self ** other [ % modulo].
With two arguments, compute self**other.
With three arguments, compute (self**other) % modulo. For the
three argument form, the following restrictions on the
arguments hold:
- all three arguments must be integral
- other must be nonnegative
- either self or other (or both) must be nonzero
- modulo must be nonzero and must have at most p digits,
where p is the context precision.
If any of these restrictions is violated the InvalidOperation
flag is raised.
The result of pow(self, other, modulo) is identical to the
result that would be obtained by computing (self**other) %
modulo with unbounded precision, but is computed more
efficiently. It is always exact.
"""
if modulo is not None:
return self._power_modulo(other, modulo, context)
other = _convert_other(other)
if other is NotImplemented:
return other
if context is None:
context = getcontext()
# either argument is a NaN => result is NaN
ans = self._check_nans(other, context)
if ans:
return ans
# 0**0 = NaN (!), x**0 = 1 for nonzero x (including +/-Infinity)
if not other:
if not self:
return context._raise_error(InvalidOperation, '0 ** 0')
else:
return _One
# result has sign 1 iff self._sign is 1 and other is an odd integer
result_sign = 0
if self._sign == 1:
if other._isinteger():
if not other._iseven():
result_sign = 1
else:
# -ve**noninteger = NaN
# (-0)**noninteger = 0**noninteger
if self:
return context._raise_error(InvalidOperation,
'x ** y with x negative and y not an integer')
# negate self, without doing any unwanted rounding
self = self.copy_negate()
# 0**(+ve or Inf)= 0; 0**(-ve or -Inf) = Infinity
if not self:
if other._sign == 0:
return _dec_from_triple(result_sign, '0', 0)
else:
return _SignedInfinity[result_sign]
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
if self._isinfinity():
if other._sign == 0:
return _SignedInfinity[result_sign]
else:
return _dec_from_triple(result_sign, '0', 0)
# 1**other = 1, but the choice of exponent and the flags
# depend on the exponent of self, and on whether other is a
# positive integer, a negative integer, or neither
if self == _One:
if other._isinteger():
# exp = max(self._exp*max(int(other), 0),
# 1-context.prec) but evaluating int(other) directly
# is dangerous until we know other is small (other
# could be 1e999999999)
if other._sign == 1:
multiplier = 0
elif other > context.prec:
multiplier = context.prec
else:
multiplier = int(other)
exp = self._exp * multiplier
if exp < 1-context.prec:
exp = 1-context.prec
context._raise_error(Rounded)
else:
context._raise_error(Inexact)
context._raise_error(Rounded)
exp = 1-context.prec
return _dec_from_triple(result_sign, '1'+'0'*-exp, exp)
# compute adjusted exponent of self
self_adj = self.adjusted()
# self ** infinity is infinity if self > 1, 0 if self < 1
# self ** -infinity is infinity if self < 1, 0 if self > 1
if other._isinfinity():
if (other._sign == 0) == (self_adj < 0):
return _dec_from_triple(result_sign, '0', 0)
else:
return _SignedInfinity[result_sign]
# from here on, the result always goes through the call
# to _fix at the end of this function.
ans = None
exact = False
# crude test to catch cases of extreme overflow/underflow. If
# log10(self)*other >= 10**bound and bound >= len(str(Emax))
# then 10**bound >= 10**len(str(Emax)) >= Emax+1 and hence
# self**other >= 10**(Emax+1), so overflow occurs. The test
# for underflow is similar.
bound = self._log10_exp_bound() + other.adjusted()
if (self_adj >= 0) == (other._sign == 0):
# self > 1 and other +ve, or self < 1 and other -ve
# possibility of overflow
if bound >= len(str(context.Emax)):
ans = _dec_from_triple(result_sign, '1', context.Emax+1)
else:
# self > 1 and other -ve, or self < 1 and other +ve
# possibility of underflow to 0
Etiny = context.Etiny()
if bound >= len(str(-Etiny)):
ans = _dec_from_triple(result_sign, '1', Etiny-1)
# try for an exact result with precision +1
if ans is None:
ans = self._power_exact(other, context.prec + 1)
if ans is not None:
if result_sign == 1:
ans = _dec_from_triple(1, ans._int, ans._exp)
exact = True
# usual case: inexact result, x**y computed directly as exp(y*log(x))
if ans is None:
p = context.prec
x = _WorkRep(self)
xc, xe = x.int, x.exp
y = _WorkRep(other)
yc, ye = y.int, y.exp
if y.sign == 1:
yc = -yc
# compute correctly rounded result: start with precision +3,
# then increase precision until result is unambiguously roundable
extra = 3
while True:
coeff, exp = _dpower(xc, xe, yc, ye, p+extra)
if coeff % (5*10**(len(str(coeff))-p-1)):
break
extra += 3
ans = _dec_from_triple(result_sign, str(coeff), exp)
# unlike exp, ln and log10, the power function respects the
# rounding mode; no need to switch to ROUND_HALF_EVEN here
# There's a difficulty here when 'other' is not an integer and
# the result is exact. In this case, the specification
# requires that the Inexact flag be raised (in spite of
# exactness), but since the result is exact _fix won't do this
# for us. (Correspondingly, the Underflow signal should also
# be raised for subnormal results.) We can't directly raise
# these signals either before or after calling _fix, since
# that would violate the precedence for signals. So we wrap
# the ._fix call in a temporary context, and reraise
# afterwards.
if exact and not other._isinteger():
# pad with zeros up to length context.prec+1 if necessary; this
# ensures that the Rounded signal will be raised.
if len(ans._int) <= context.prec:
expdiff = context.prec + 1 - len(ans._int)
ans = _dec_from_triple(ans._sign, ans._int+'0'*expdiff,
ans._exp-expdiff)
# create a copy of the current context, with cleared flags/traps
newcontext = context.copy()
newcontext.clear_flags()
for exception in _signals:
newcontext.traps[exception] = 0
# round in the new context
ans = ans._fix(newcontext)
# raise Inexact, and if necessary, Underflow
newcontext._raise_error(Inexact)
if newcontext.flags[Subnormal]:
newcontext._raise_error(Underflow)
# propagate signals to the original context; _fix could
# have raised any of Overflow, Underflow, Subnormal,
# Inexact, Rounded, Clamped. Overflow needs the correct
# arguments. Note that the order of the exceptions is
# important here.
if newcontext.flags[Overflow]:
context._raise_error(Overflow, 'above Emax', ans._sign)
for exception in Underflow, Subnormal, Inexact, Rounded, Clamped:
if newcontext.flags[exception]:
context._raise_error(exception)
else:
ans = ans._fix(context)
return ans
def __rpow__(self, other, context=None):
"""Swaps self/other and returns __pow__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__pow__(self, context=context)
def normalize(self, context=None):
"""Normalize- strip trailing 0s, change anything equal to 0 to 0e0"""
if context is None:
context = getcontext()
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
dup = self._fix(context)
if dup._isinfinity():
return dup
if not dup:
return _dec_from_triple(dup._sign, '0', 0)
exp_max = [context.Emax, context.Etop()][context.clamp]
end = len(dup._int)
exp = dup._exp
while dup._int[end-1] == '0' and exp < exp_max:
exp += 1
end -= 1
return _dec_from_triple(dup._sign, dup._int[:end], exp)
def quantize(self, exp, rounding=None, context=None, watchexp=True):
"""Quantize self so its exponent is the same as that of exp.
Similar to self._rescale(exp._exp) but with error checking.
"""
exp = _convert_other(exp, raiseit=True)
if context is None:
context = getcontext()
if rounding is None:
rounding = context.rounding
if self._is_special or exp._is_special:
ans = self._check_nans(exp, context)
if ans:
return ans
if exp._isinfinity() or self._isinfinity():
if exp._isinfinity() and self._isinfinity():
return Decimal(self) # if both are inf, it is OK
return context._raise_error(InvalidOperation,
'quantize with one INF')
# if we're not watching exponents, do a simple rescale
if not watchexp:
ans = self._rescale(exp._exp, rounding)
# raise Inexact and Rounded where appropriate
if ans._exp > self._exp:
context._raise_error(Rounded)
if ans != self:
context._raise_error(Inexact)
return ans
# exp._exp should be between Etiny and Emax
if not (context.Etiny() <= exp._exp <= context.Emax):
return context._raise_error(InvalidOperation,
'target exponent out of bounds in quantize')
if not self:
ans = _dec_from_triple(self._sign, '0', exp._exp)
return ans._fix(context)
self_adjusted = self.adjusted()
if self_adjusted > context.Emax:
return context._raise_error(InvalidOperation,
'exponent of quantize result too large for current context')
if self_adjusted - exp._exp + 1 > context.prec:
return context._raise_error(InvalidOperation,
'quantize result has too many digits for current context')
ans = self._rescale(exp._exp, rounding)
if ans.adjusted() > context.Emax:
return context._raise_error(InvalidOperation,
'exponent of quantize result too large for current context')
if len(ans._int) > context.prec:
return context._raise_error(InvalidOperation,
'quantize result has too many digits for current context')
# raise appropriate flags
if ans and ans.adjusted() < context.Emin:
context._raise_error(Subnormal)
if ans._exp > self._exp:
if ans != self:
context._raise_error(Inexact)
context._raise_error(Rounded)
# call to fix takes care of any necessary folddown, and
# signals Clamped if necessary
ans = ans._fix(context)
return ans
def same_quantum(self, other, context=None):
"""Return True if self and other have the same exponent; otherwise
return False.
If either operand is a special value, the following rules are used:
* return True if both operands are infinities
* return True if both operands are NaNs
* otherwise, return False.
"""
other = _convert_other(other, raiseit=True)
if self._is_special or other._is_special:
return (self.is_nan() and other.is_nan() or
self.is_infinite() and other.is_infinite())
return self._exp == other._exp
def _rescale(self, exp, rounding):
"""Rescale self so that the exponent is exp, either by padding with zeros
or by truncating digits, using the given rounding mode.
Specials are returned without change. This operation is
quiet: it raises no flags, and uses no information from the
context.
exp = exp to scale to (an integer)
rounding = rounding mode
"""
if self._is_special:
return Decimal(self)
if not self:
return _dec_from_triple(self._sign, '0', exp)
if self._exp >= exp:
# pad answer with zeros if necessary
return _dec_from_triple(self._sign,
self._int + '0'*(self._exp - exp), exp)
# too many digits; round and lose data. If self.adjusted() <
# exp-1, replace self by 10**(exp-1) before rounding
digits = len(self._int) + self._exp - exp
if digits < 0:
self = _dec_from_triple(self._sign, '1', exp-1)
digits = 0
this_function = self._pick_rounding_function[rounding]
changed = this_function(self, digits)
coeff = self._int[:digits] or '0'
if changed == 1:
coeff = str(int(coeff)+1)
return _dec_from_triple(self._sign, coeff, exp)
def _round(self, places, rounding):
"""Round a nonzero, nonspecial Decimal to a fixed number of
significant figures, using the given rounding mode.
Infinities, NaNs and zeros are returned unaltered.
This operation is quiet: it raises no flags, and uses no
information from the context.
"""
if places <= 0:
raise ValueError("argument should be at least 1 in _round")
if self._is_special or not self:
return Decimal(self)
ans = self._rescale(self.adjusted()+1-places, rounding)
# it can happen that the rescale alters the adjusted exponent;
# for example when rounding 99.97 to 3 significant figures.
# When this happens we end up with an extra 0 at the end of
# the number; a second rescale fixes this.
if ans.adjusted() != self.adjusted():
ans = ans._rescale(ans.adjusted()+1-places, rounding)
return ans
def to_integral_exact(self, rounding=None, context=None):
"""Rounds to a nearby integer.
If no rounding mode is specified, take the rounding mode from
the context. This method raises the Rounded and Inexact flags
when appropriate.
See also: to_integral_value, which does exactly the same as
this method except that it doesn't raise Inexact or Rounded.
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
return Decimal(self)
if self._exp >= 0:
return Decimal(self)
if not self:
return _dec_from_triple(self._sign, '0', 0)
if context is None:
context = getcontext()
if rounding is None:
rounding = context.rounding
ans = self._rescale(0, rounding)
if ans != self:
context._raise_error(Inexact)
context._raise_error(Rounded)
return ans
def to_integral_value(self, rounding=None, context=None):
"""Rounds to the nearest integer, without raising inexact, rounded."""
if context is None:
context = getcontext()
if rounding is None:
rounding = context.rounding
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
return Decimal(self)
if self._exp >= 0:
return Decimal(self)
else:
return self._rescale(0, rounding)
# the method name changed, but we provide also the old one, for compatibility
to_integral = to_integral_value
def sqrt(self, context=None):
"""Return the square root of self."""
if context is None:
context = getcontext()
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if self._isinfinity() and self._sign == 0:
return Decimal(self)
if not self:
# exponent = self._exp // 2. sqrt(-0) = -0
ans = _dec_from_triple(self._sign, '0', self._exp // 2)
return ans._fix(context)
if self._sign == 1:
return context._raise_error(InvalidOperation, 'sqrt(-x), x > 0')
# At this point self represents a positive number. Let p be
# the desired precision and express self in the form c*100**e
# with c a positive real number and e an integer, c and e
# being chosen so that 100**(p-1) <= c < 100**p. Then the
# (exact) square root of self is sqrt(c)*10**e, and 10**(p-1)
# <= sqrt(c) < 10**p, so the closest representable Decimal at
# precision p is n*10**e where n = round_half_even(sqrt(c)),
# the closest integer to sqrt(c) with the even integer chosen
# in the case of a tie.
#
# To ensure correct rounding in all cases, we use the
# following trick: we compute the square root to an extra
# place (precision p+1 instead of precision p), rounding down.
# Then, if the result is inexact and its last digit is 0 or 5,
# we increase the last digit to 1 or 6 respectively; if it's
# exact we leave the last digit alone. Now the final round to
# p places (or fewer in the case of underflow) will round
# correctly and raise the appropriate flags.
# use an extra digit of precision
prec = context.prec+1
# write argument in the form c*100**e where e = self._exp//2
# is the 'ideal' exponent, to be used if the square root is
# exactly representable. l is the number of 'digits' of c in
# base 100, so that 100**(l-1) <= c < 100**l.
op = _WorkRep(self)
e = op.exp >> 1
if op.exp & 1:
c = op.int * 10
l = (len(self._int) >> 1) + 1
else:
c = op.int
l = len(self._int)+1 >> 1
# rescale so that c has exactly prec base 100 'digits'
shift = prec-l
if shift >= 0:
c *= 100**shift
exact = True
else:
c, remainder = divmod(c, 100**-shift)
exact = not remainder
e -= shift
# find n = floor(sqrt(c)) using Newton's method
n = 10**prec
while True:
q = c//n
if n <= q:
break
else:
n = n + q >> 1
exact = exact and n*n == c
if exact:
# result is exact; rescale to use ideal exponent e
if shift >= 0:
# assert n % 10**shift == 0
n //= 10**shift
else:
n *= 10**-shift
e += shift
else:
# result is not exact; fix last digit as described above
if n % 5 == 0:
n += 1
ans = _dec_from_triple(0, str(n), e)
# round, and fit to current context
context = context._shallow_copy()
rounding = context._set_rounding(ROUND_HALF_EVEN)
ans = ans._fix(context)
context.rounding = rounding
return ans
def max(self, other, context=None):
"""Returns the larger value.
Like max(self, other) except if one is not a number, returns
NaN (and signals if one is sNaN). Also rounds.
"""
other = _convert_other(other, raiseit=True)
if context is None:
context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
# number is always returned
sn = self._isnan()
on = other._isnan()
if sn or on:
if on == 1 and sn == 0:
return self._fix(context)
if sn == 1 and on == 0:
return other._fix(context)
return self._check_nans(other, context)
c = self._cmp(other)
if c == 0:
# If both operands are finite and equal in numerical value
# then an ordering is applied:
#
# If the signs differ then max returns the operand with the
# positive sign and min returns the operand with the negative sign
#
# If the signs are the same then the exponent is used to select
# the result. This is exactly the ordering used in compare_total.
c = self.compare_total(other)
if c == -1:
ans = other
else:
ans = self
return ans._fix(context)
def min(self, other, context=None):
"""Returns the smaller value.
Like min(self, other) except if one is not a number, returns
NaN (and signals if one is sNaN). Also rounds.
"""
other = _convert_other(other, raiseit=True)
if context is None:
context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
# number is always returned
sn = self._isnan()
on = other._isnan()
if sn or on:
if on == 1 and sn == 0:
return self._fix(context)
if sn == 1 and on == 0:
return other._fix(context)
return self._check_nans(other, context)
c = self._cmp(other)
if c == 0:
c = self.compare_total(other)
if c == -1:
ans = self
else:
ans = other
return ans._fix(context)
def _isinteger(self):
"""Returns whether self is an integer"""
if self._is_special:
return False
if self._exp >= 0:
return True
rest = self._int[self._exp:]
return rest == '0'*len(rest)
def _iseven(self):
"""Returns True if self is even. Assumes self is an integer."""
if not self or self._exp > 0:
return True
return self._int[-1+self._exp] in '02468'
def adjusted(self):
"""Return the adjusted exponent of self"""
try:
return self._exp + len(self._int) - 1
# If NaN or Infinity, self._exp is string
except TypeError:
return 0
def canonical(self):
"""Returns the same Decimal object.
As we do not have different encodings for the same number, the
received object already is in its canonical form.
"""
return self
def compare_signal(self, other, context=None):
"""Compares self to the other operand numerically.
It's pretty much like compare(), but all NaNs signal, with signaling
NaNs taking precedence over quiet NaNs.
"""
other = _convert_other(other, raiseit = True)
ans = self._compare_check_nans(other, context)
if ans:
return ans
return self.compare(other, context=context)
def compare_total(self, other, context=None):
"""Compares self to other using the abstract representations.
This is not like the standard compare, which use their numerical
value. Note that a total ordering is defined for all possible abstract
representations.
"""
other = _convert_other(other, raiseit=True)
# if one is negative and the other is positive, it's easy
if self._sign and not other._sign:
return _NegativeOne
if not self._sign and other._sign:
return _One
sign = self._sign
# let's handle both NaN types
self_nan = self._isnan()
other_nan = other._isnan()
if self_nan or other_nan:
if self_nan == other_nan:
# compare payloads as though they're integers
self_key = len(self._int), self._int
other_key = len(other._int), other._int
if self_key < other_key:
if sign:
return _One
else:
return _NegativeOne
if self_key > other_key:
if sign:
return _NegativeOne
else:
return _One
return _Zero
if sign:
if self_nan == 1:
return _NegativeOne
if other_nan == 1:
return _One
if self_nan == 2:
return _NegativeOne
if other_nan == 2:
return _One
else:
if self_nan == 1:
return _One
if other_nan == 1:
return _NegativeOne
if self_nan == 2:
return _One
if other_nan == 2:
return _NegativeOne
if self < other:
return _NegativeOne
if self > other:
return _One
if self._exp < other._exp:
if sign:
return _One
else:
return _NegativeOne
if self._exp > other._exp:
if sign:
return _NegativeOne
else:
return _One
return _Zero
def compare_total_mag(self, other, context=None):
"""Compares self to other using abstract repr., ignoring sign.
Like compare_total, but with operand's sign ignored and assumed to be 0.
"""
other = _convert_other(other, raiseit=True)
s = self.copy_abs()
o = other.copy_abs()
return s.compare_total(o)
def copy_abs(self):
"""Returns a copy with the sign set to 0. """
return _dec_from_triple(0, self._int, self._exp, self._is_special)
def copy_negate(self):
"""Returns a copy with the sign inverted."""
if self._sign:
return _dec_from_triple(0, self._int, self._exp, self._is_special)
else:
return _dec_from_triple(1, self._int, self._exp, self._is_special)
def copy_sign(self, other, context=None):
"""Returns self with the sign of other."""
other = _convert_other(other, raiseit=True)
return _dec_from_triple(other._sign, self._int,
self._exp, self._is_special)
def exp(self, context=None):
"""Returns e ** self."""
if context is None:
context = getcontext()
# exp(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
return ans
# exp(-Infinity) = 0
if self._isinfinity() == -1:
return _Zero
# exp(0) = 1
if not self:
return _One
# exp(Infinity) = Infinity
if self._isinfinity() == 1:
return Decimal(self)
# the result is now guaranteed to be inexact (the true
# mathematical result is transcendental). There's no need to
# raise Rounded and Inexact here---they'll always be raised as
# a result of the call to _fix.
p = context.prec
adj = self.adjusted()
# we only need to do any computation for quite a small range
# of adjusted exponents---for example, -29 <= adj <= 10 for
# the default context. For smaller exponent the result is
# indistinguishable from 1 at the given precision, while for
# larger exponent the result either overflows or underflows.
if self._sign == 0 and adj > len(str((context.Emax+1)*3)):
# overflow
ans = _dec_from_triple(0, '1', context.Emax+1)
elif self._sign == 1 and adj > len(str((-context.Etiny()+1)*3)):
# underflow to 0
ans = _dec_from_triple(0, '1', context.Etiny()-1)
elif self._sign == 0 and adj < -p:
# p+1 digits; final round will raise correct flags
ans = _dec_from_triple(0, '1' + '0'*(p-1) + '1', -p)
elif self._sign == 1 and adj < -p-1:
# p+1 digits; final round will raise correct flags
ans = _dec_from_triple(0, '9'*(p+1), -p-1)
# general case
else:
op = _WorkRep(self)
c, e = op.int, op.exp
if op.sign == 1:
c = -c
# compute correctly rounded result: increase precision by
# 3 digits at a time until we get an unambiguously
# roundable result
extra = 3
while True:
coeff, exp = _dexp(c, e, p+extra)
if coeff % (5*10**(len(str(coeff))-p-1)):
break
extra += 3
ans = _dec_from_triple(0, str(coeff), exp)
# at this stage, ans should round correctly with *any*
# rounding mode, not just with ROUND_HALF_EVEN
context = context._shallow_copy()
rounding = context._set_rounding(ROUND_HALF_EVEN)
ans = ans._fix(context)
context.rounding = rounding
return ans
def is_canonical(self):
"""Return True if self is canonical; otherwise return False.
Currently, the encoding of a Decimal instance is always
canonical, so this method returns True for any Decimal.
"""
return True
def is_finite(self):
"""Return True if self is finite; otherwise return False.
A Decimal instance is considered finite if it is neither
infinite nor a NaN.
"""
return not self._is_special
def is_infinite(self):
"""Return True if self is infinite; otherwise return False."""
return self._exp == 'F'
def is_nan(self):
"""Return True if self is a qNaN or sNaN; otherwise return False."""
return self._exp in ('n', 'N')
def is_normal(self, context=None):
"""Return True if self is a normal number; otherwise return False."""
if self._is_special or not self:
return False
if context is None:
context = getcontext()
return context.Emin <= self.adjusted()
def is_qnan(self):
"""Return True if self is a quiet NaN; otherwise return False."""
return self._exp == 'n'
def is_signed(self):
"""Return True if self is negative; otherwise return False."""
return self._sign == 1
def is_snan(self):
"""Return True if self is a signaling NaN; otherwise return False."""
return self._exp == 'N'
def is_subnormal(self, context=None):
"""Return True if self is subnormal; otherwise return False."""
if self._is_special or not self:
return False
if context is None:
context = getcontext()
return self.adjusted() < context.Emin
def is_zero(self):
"""Return True if self is a zero; otherwise return False."""
return not self._is_special and self._int == '0'
def _ln_exp_bound(self):
"""Compute a lower bound for the adjusted exponent of self.ln().
In other words, compute r such that self.ln() >= 10**r. Assumes
that self is finite and positive and that self != 1.
"""
# for 0.1 <= x <= 10 we use the inequalities 1-1/x <= ln(x) <= x-1
adj = self._exp + len(self._int) - 1
if adj >= 1:
# argument >= 10; we use 23/10 = 2.3 as a lower bound for ln(10)
return len(str(adj*23//10)) - 1
if adj <= -2:
# argument <= 0.1
return len(str((-1-adj)*23//10)) - 1
op = _WorkRep(self)
c, e = op.int, op.exp
if adj == 0:
# 1 < self < 10
num = str(c-10**-e)
den = str(c)
return len(num) - len(den) - (num < den)
# adj == -1, 0.1 <= self < 1
return e + len(str(10**-e - c)) - 1
def ln(self, context=None):
"""Returns the natural (base e) logarithm of self."""
if context is None:
context = getcontext()
# ln(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
return ans
# ln(0.0) == -Infinity
if not self:
return _NegativeInfinity
# ln(Infinity) = Infinity
if self._isinfinity() == 1:
return _Infinity
# ln(1.0) == 0.0
if self == _One:
return _Zero
# ln(negative) raises InvalidOperation
if self._sign == 1:
return context._raise_error(InvalidOperation,
'ln of a negative value')
# result is irrational, so necessarily inexact
op = _WorkRep(self)
c, e = op.int, op.exp
p = context.prec
# correctly rounded result: repeatedly increase precision by 3
# until we get an unambiguously roundable result
places = p - self._ln_exp_bound() + 2 # at least p+3 places
while True:
coeff = _dlog(c, e, places)
# assert len(str(abs(coeff)))-p >= 1
if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
break
places += 3
ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places)
context = context._shallow_copy()
rounding = context._set_rounding(ROUND_HALF_EVEN)
ans = ans._fix(context)
context.rounding = rounding
return ans
def _log10_exp_bound(self):
"""Compute a lower bound for the adjusted exponent of self.log10().
In other words, find r such that self.log10() >= 10**r.
Assumes that self is finite and positive and that self != 1.
"""
# For x >= 10 or x < 0.1 we only need a bound on the integer
# part of log10(self), and this comes directly from the
# exponent of x. For 0.1 <= x <= 10 we use the inequalities
# 1-1/x <= log(x) <= x-1. If x > 1 we have |log10(x)| >
# (1-1/x)/2.31 > 0. If x < 1 then |log10(x)| > (1-x)/2.31 > 0
adj = self._exp + len(self._int) - 1
if adj >= 1:
# self >= 10
return len(str(adj))-1
if adj <= -2:
# self < 0.1
return len(str(-1-adj))-1
op = _WorkRep(self)
c, e = op.int, op.exp
if adj == 0:
# 1 < self < 10
num = str(c-10**-e)
den = str(231*c)
return len(num) - len(den) - (num < den) + 2
# adj == -1, 0.1 <= self < 1
num = str(10**-e-c)
return len(num) + e - (num < "231") - 1
def log10(self, context=None):
"""Returns the base 10 logarithm of self."""
if context is None:
context = getcontext()
# log10(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
return ans
# log10(0.0) == -Infinity
if not self:
return _NegativeInfinity
# log10(Infinity) = Infinity
if self._isinfinity() == 1:
return _Infinity
# log10(negative or -Infinity) raises InvalidOperation
if self._sign == 1:
return context._raise_error(InvalidOperation,
'log10 of a negative value')
# log10(10**n) = n
if self._int[0] == '1' and self._int[1:] == '0'*(len(self._int) - 1):
# answer may need rounding
ans = Decimal(self._exp + len(self._int) - 1)
else:
# result is irrational, so necessarily inexact
op = _WorkRep(self)
c, e = op.int, op.exp
p = context.prec
# correctly rounded result: repeatedly increase precision
# until result is unambiguously roundable
places = p-self._log10_exp_bound()+2
while True:
coeff = _dlog10(c, e, places)
# assert len(str(abs(coeff)))-p >= 1
if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
break
places += 3
ans = _dec_from_triple(int(coeff<0), str(abs(coeff)), -places)
context = context._shallow_copy()
rounding = context._set_rounding(ROUND_HALF_EVEN)
ans = ans._fix(context)
context.rounding = rounding
return ans
def logb(self, context=None):
""" Returns the exponent of the magnitude of self's MSD.
The result is the integer which is the exponent of the magnitude
of the most significant digit of self (as though it were truncated
to a single digit while maintaining the value of that digit and
without limiting the resulting exponent).
"""
# logb(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
return ans
if context is None:
context = getcontext()
# logb(+/-Inf) = +Inf
if self._isinfinity():
return _Infinity
# logb(0) = -Inf, DivisionByZero
if not self:
return context._raise_error(DivisionByZero, 'logb(0)', 1)
# otherwise, simply return the adjusted exponent of self, as a
# Decimal. Note that no attempt is made to fit the result
# into the current context.
ans = Decimal(self.adjusted())
return ans._fix(context)
def _islogical(self):
"""Return True if self is a logical operand.
For being logical, it must be a finite number with a sign of 0,
an exponent of 0, and a coefficient whose digits must all be
either 0 or 1.
"""
if self._sign != 0 or self._exp != 0:
return False
for dig in self._int:
if dig not in '01':
return False
return True
def _fill_logical(self, context, opa, opb):
dif = context.prec - len(opa)
if dif > 0:
opa = '0'*dif + opa
elif dif < 0:
opa = opa[-context.prec:]
dif = context.prec - len(opb)
if dif > 0:
opb = '0'*dif + opb
elif dif < 0:
opb = opb[-context.prec:]
return opa, opb
def logical_and(self, other, context=None):
"""Applies an 'and' operation between self and other's digits."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
# fill to context.prec
(opa, opb) = self._fill_logical(context, self._int, other._int)
# make the operation, and clean starting zeroes
result = "".join([str(int(a)&int(b)) for a,b in zip(opa,opb)])
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
def logical_invert(self, context=None):
"""Invert all its digits."""
if context is None:
context = getcontext()
return self.logical_xor(_dec_from_triple(0,'1'*context.prec,0),
context)
def logical_or(self, other, context=None):
"""Applies an 'or' operation between self and other's digits."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
# fill to context.prec
(opa, opb) = self._fill_logical(context, self._int, other._int)
# make the operation, and clean starting zeroes
result = "".join([str(int(a)|int(b)) for a,b in zip(opa,opb)])
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
def logical_xor(self, other, context=None):
"""Applies an 'xor' operation between self and other's digits."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
if not self._islogical() or not other._islogical():
return context._raise_error(InvalidOperation)
# fill to context.prec
(opa, opb) = self._fill_logical(context, self._int, other._int)
# make the operation, and clean starting zeroes
result = "".join([str(int(a)^int(b)) for a,b in zip(opa,opb)])
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
def max_mag(self, other, context=None):
"""Compares the values numerically with their sign ignored."""
other = _convert_other(other, raiseit=True)
if context is None:
context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
# number is always returned
sn = self._isnan()
on = other._isnan()
if sn or on:
if on == 1 and sn == 0:
return self._fix(context)
if sn == 1 and on == 0:
return other._fix(context)
return self._check_nans(other, context)
c = self.copy_abs()._cmp(other.copy_abs())
if c == 0:
c = self.compare_total(other)
if c == -1:
ans = other
else:
ans = self
return ans._fix(context)
def min_mag(self, other, context=None):
"""Compares the values numerically with their sign ignored."""
other = _convert_other(other, raiseit=True)
if context is None:
context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
# number is always returned
sn = self._isnan()
on = other._isnan()
if sn or on:
if on == 1 and sn == 0:
return self._fix(context)
if sn == 1 and on == 0:
return other._fix(context)
return self._check_nans(other, context)
c = self.copy_abs()._cmp(other.copy_abs())
if c == 0:
c = self.compare_total(other)
if c == -1:
ans = self
else:
ans = other
return ans._fix(context)
def next_minus(self, context=None):
"""Returns the largest representable number smaller than itself."""
if context is None:
context = getcontext()
ans = self._check_nans(context=context)
if ans:
return ans
if self._isinfinity() == -1:
return _NegativeInfinity
if self._isinfinity() == 1:
return _dec_from_triple(0, '9'*context.prec, context.Etop())
context = context.copy()
context._set_rounding(ROUND_FLOOR)
context._ignore_all_flags()
new_self = self._fix(context)
if new_self != self:
return new_self
return self.__sub__(_dec_from_triple(0, '1', context.Etiny()-1),
context)
def next_plus(self, context=None):
"""Returns the smallest representable number larger than itself."""
if context is None:
context = getcontext()
ans = self._check_nans(context=context)
if ans:
return ans
if self._isinfinity() == 1:
return _Infinity
if self._isinfinity() == -1:
return _dec_from_triple(1, '9'*context.prec, context.Etop())
context = context.copy()
context._set_rounding(ROUND_CEILING)
context._ignore_all_flags()
new_self = self._fix(context)
if new_self != self:
return new_self
return self.__add__(_dec_from_triple(0, '1', context.Etiny()-1),
context)
def next_toward(self, other, context=None):
"""Returns the number closest to self, in the direction towards other.
The result is the closest representable number to self
(excluding self) that is in the direction towards other,
unless both have the same value. If the two operands are
numerically equal, then the result is a copy of self with the
sign set to be the same as the sign of other.
"""
other = _convert_other(other, raiseit=True)
if context is None:
context = getcontext()
ans = self._check_nans(other, context)
if ans:
return ans
comparison = self._cmp(other)
if comparison == 0:
return self.copy_sign(other)
if comparison == -1:
ans = self.next_plus(context)
else: # comparison == 1
ans = self.next_minus(context)
# decide which flags to raise using value of ans
if ans._isinfinity():
context._raise_error(Overflow,
'Infinite result from next_toward',
ans._sign)
context._raise_error(Inexact)
context._raise_error(Rounded)
elif ans.adjusted() < context.Emin:
context._raise_error(Underflow)
context._raise_error(Subnormal)
context._raise_error(Inexact)
context._raise_error(Rounded)
# if precision == 1 then we don't raise Clamped for a
# result 0E-Etiny.
if not ans:
context._raise_error(Clamped)
return ans
def number_class(self, context=None):
"""Returns an indication of the class of self.
The class is one of the following strings:
sNaN
NaN
-Infinity
-Normal
-Subnormal
-Zero
+Zero
+Subnormal
+Normal
+Infinity
"""
if self.is_snan():
return "sNaN"
if self.is_qnan():
return "NaN"
inf = self._isinfinity()
if inf == 1:
return "+Infinity"
if inf == -1:
return "-Infinity"
if self.is_zero():
if self._sign:
return "-Zero"
else:
return "+Zero"
if context is None:
context = getcontext()
if self.is_subnormal(context=context):
if self._sign:
return "-Subnormal"
else:
return "+Subnormal"
# just a normal, regular, boring number, :)
if self._sign:
return "-Normal"
else:
return "+Normal"
def radix(self):
"""Just returns 10, as this is Decimal, :)"""
return Decimal(10)
def rotate(self, other, context=None):
"""Returns a rotated copy of self, value-of-other times."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
ans = self._check_nans(other, context)
if ans:
return ans
if other._exp != 0:
return context._raise_error(InvalidOperation)
if not (-context.prec <= int(other) <= context.prec):
return context._raise_error(InvalidOperation)
if self._isinfinity():
return Decimal(self)
# get values, pad if necessary
torot = int(other)
rotdig = self._int
topad = context.prec - len(rotdig)
if topad > 0:
rotdig = '0'*topad + rotdig
elif topad < 0:
rotdig = rotdig[-topad:]
# let's rotate!
rotated = rotdig[torot:] + rotdig[:torot]
return _dec_from_triple(self._sign,
rotated.lstrip('0') or '0', self._exp)
def scaleb(self, other, context=None):
"""Returns self operand after adding the second value to its exp."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
ans = self._check_nans(other, context)
if ans:
return ans
if other._exp != 0:
return context._raise_error(InvalidOperation)
liminf = -2 * (context.Emax + context.prec)
limsup = 2 * (context.Emax + context.prec)
if not (liminf <= int(other) <= limsup):
return context._raise_error(InvalidOperation)
if self._isinfinity():
return Decimal(self)
d = _dec_from_triple(self._sign, self._int, self._exp + int(other))
d = d._fix(context)
return d
def shift(self, other, context=None):
"""Returns a shifted copy of self, value-of-other times."""
if context is None:
context = getcontext()
other = _convert_other(other, raiseit=True)
ans = self._check_nans(other, context)
if ans:
return ans
if other._exp != 0:
return context._raise_error(InvalidOperation)
if not (-context.prec <= int(other) <= context.prec):
return context._raise_error(InvalidOperation)
if self._isinfinity():
return Decimal(self)
# get values, pad if necessary
torot = int(other)
rotdig = self._int
topad = context.prec - len(rotdig)
if topad > 0:
rotdig = '0'*topad + rotdig
elif topad < 0:
rotdig = rotdig[-topad:]
# let's shift!
if torot < 0:
shifted = rotdig[:torot]
else:
shifted = rotdig + '0'*torot
shifted = shifted[-context.prec:]
return _dec_from_triple(self._sign,
shifted.lstrip('0') or '0', self._exp)
# Support for pickling, copy, and deepcopy
def __reduce__(self):
return (self.__class__, (str(self),))
def __copy__(self):
if type(self) is Decimal:
return self # I'm immutable; therefore I am my own clone
return self.__class__(str(self))
def __deepcopy__(self, memo):
if type(self) is Decimal:
return self # My components are also immutable
return self.__class__(str(self))
# PEP 3101 support. the _localeconv keyword argument should be
# considered private: it's provided for ease of testing only.
def __format__(self, specifier, context=None, _localeconv=None):
"""Format a Decimal instance according to the given specifier.
The specifier should be a standard format specifier, with the
form described in PEP 3101. Formatting types 'e', 'E', 'f',
'F', 'g', 'G', 'n' and '%' are supported. If the formatting
type is omitted it defaults to 'g' or 'G', depending on the
value of context.capitals.
"""
# Note: PEP 3101 says that if the type is not present then
# there should be at least one digit after the decimal point.
# We take the liberty of ignoring this requirement for
# Decimal---it's presumably there to make sure that
# format(float, '') behaves similarly to str(float).
if context is None:
context = getcontext()
spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
# special values don't care about the type or precision
if self._is_special:
sign = _format_sign(self._sign, spec)
body = str(self.copy_abs())
return _format_align(sign, body, spec)
# a type of None defaults to 'g' or 'G', depending on context
if spec['type'] is None:
spec['type'] = ['g', 'G'][context.capitals]
# if type is '%', adjust exponent of self accordingly
if spec['type'] == '%':
self = _dec_from_triple(self._sign, self._int, self._exp+2)
# round if necessary, taking rounding mode from the context
rounding = context.rounding
precision = spec['precision']
if precision is not None:
if spec['type'] in 'eE':
self = self._round(precision+1, rounding)
elif spec['type'] in 'fF%':
self = self._rescale(-precision, rounding)
elif spec['type'] in 'gG' and len(self._int) > precision:
self = self._round(precision, rounding)
# special case: zeros with a positive exponent can't be
# represented in fixed point; rescale them to 0e0.
if not self and self._exp > 0 and spec['type'] in 'fF%':
self = self._rescale(0, rounding)
# figure out placement of the decimal point
leftdigits = self._exp + len(self._int)
if spec['type'] in 'eE':
if not self and precision is not None:
dotplace = 1 - precision
else:
dotplace = 1
elif spec['type'] in 'fF%':
dotplace = leftdigits
elif spec['type'] in 'gG':
if self._exp <= 0 and leftdigits > -6:
dotplace = leftdigits
else:
dotplace = 1
# find digits before and after decimal point, and get exponent
if dotplace < 0:
intpart = '0'
fracpart = '0'*(-dotplace) + self._int
elif dotplace > len(self._int):
intpart = self._int + '0'*(dotplace-len(self._int))
fracpart = ''
else:
intpart = self._int[:dotplace] or '0'
fracpart = self._int[dotplace:]
exp = leftdigits-dotplace
# done with the decimal-specific stuff; hand over the rest
# of the formatting to the _format_number function
return _format_number(self._sign, intpart, fracpart, exp, spec)
def _dec_from_triple(sign, coefficient, exponent, special=False):
"""Create a decimal instance directly, without any validation,
normalization (e.g. removal of leading zeros) or argument
conversion.
This function is for *internal use only*.
"""
self = object.__new__(Decimal)
self._sign = sign
self._int = coefficient
self._exp = exponent
self._is_special = special
return self
# Register Decimal as a kind of Number (an abstract base class).
# However, do not register it as Real (because Decimals are not
# interoperable with floats).
_numbers.Number.register(Decimal)
##### Context class #######################################################
class _ContextManager(object):
"""Context manager class to support localcontext().
Sets a copy of the supplied context in __enter__() and restores
the previous decimal context in __exit__()
"""
def __init__(self, new_context):
self.new_context = new_context.copy()
def __enter__(self):
self.saved_context = getcontext()
setcontext(self.new_context)
return self.new_context
def __exit__(self, t, v, tb):
setcontext(self.saved_context)
class Context(object):
"""Contains the context for a Decimal instance.
Contains:
prec - precision (for use in rounding, division, square roots..)
rounding - rounding type (how you round)
traps - If traps[exception] = 1, then the exception is
raised when it is caused. Otherwise, a value is
substituted in.
flags - When an exception is caused, flags[exception] is set.
(Whether or not the trap_enabler is set)
Should be reset by user of Decimal instance.
Emin - Minimum exponent
Emax - Maximum exponent
capitals - If 1, 1*10^1 is printed as 1E+1.
If 0, printed as 1e1
clamp - If 1, change exponents if too high (Default 0)
"""
def __init__(self, prec=None, rounding=None, Emin=None, Emax=None,
capitals=None, clamp=None, flags=None, traps=None,
_ignored_flags=None):
# Set defaults; for everything except flags and _ignored_flags,
# inherit from DefaultContext.
try:
dc = DefaultContext
except NameError:
pass
self.prec = prec if prec is not None else dc.prec
self.rounding = rounding if rounding is not None else dc.rounding
self.Emin = Emin if Emin is not None else dc.Emin
self.Emax = Emax if Emax is not None else dc.Emax
self.capitals = capitals if capitals is not None else dc.capitals
self.clamp = clamp if clamp is not None else dc.clamp
if _ignored_flags is None:
self._ignored_flags = []
else:
self._ignored_flags = _ignored_flags
if traps is None:
self.traps = dc.traps.copy()
elif not isinstance(traps, dict):
self.traps = dict((s, int(s in traps)) for s in _signals + traps)
else:
self.traps = traps
if flags is None:
self.flags = dict.fromkeys(_signals, 0)
elif not isinstance(flags, dict):
self.flags = dict((s, int(s in flags)) for s in _signals + flags)
else:
self.flags = flags
def _set_integer_check(self, name, value, vmin, vmax):
if not isinstance(value, int):
raise TypeError("%s must be an integer" % name)
if vmin == '-inf':
if value > vmax:
raise ValueError("%s must be in [%s, %d]. got: %s" % (name, vmin, vmax, value))
elif vmax == 'inf':
if value < vmin:
raise ValueError("%s must be in [%d, %s]. got: %s" % (name, vmin, vmax, value))
else:
if value < vmin or value > vmax:
raise ValueError("%s must be in [%d, %d]. got %s" % (name, vmin, vmax, value))
return object.__setattr__(self, name, value)
def _set_signal_dict(self, name, d):
if not isinstance(d, dict):
raise TypeError("%s must be a signal dict" % d)
for key in d:
if not key in _signals:
raise KeyError("%s is not a valid signal dict" % d)
for key in _signals:
if not key in d:
raise KeyError("%s is not a valid signal dict" % d)
return object.__setattr__(self, name, d)
def __setattr__(self, name, value):
if name == 'prec':
return self._set_integer_check(name, value, 1, 'inf')
elif name == 'Emin':
return self._set_integer_check(name, value, '-inf', 0)
elif name == 'Emax':
return self._set_integer_check(name, value, 0, 'inf')
elif name == 'capitals':
return self._set_integer_check(name, value, 0, 1)
elif name == 'clamp':
return self._set_integer_check(name, value, 0, 1)
elif name == 'rounding':
if not value in _rounding_modes:
# raise TypeError even for strings to have consistency
# among various implementations.
raise TypeError("%s: invalid rounding mode" % value)
return object.__setattr__(self, name, value)
elif name == 'flags' or name == 'traps':
return self._set_signal_dict(name, value)
elif name == '_ignored_flags':
return object.__setattr__(self, name, value)
else:
raise AttributeError(
"'decimal.Context' object has no attribute '%s'" % name)
def __delattr__(self, name):
raise AttributeError("%s cannot be deleted" % name)
# Support for pickling, copy, and deepcopy
def __reduce__(self):
flags = [sig for sig, v in self.flags.items() if v]
traps = [sig for sig, v in self.traps.items() if v]
return (self.__class__,
(self.prec, self.rounding, self.Emin, self.Emax,
self.capitals, self.clamp, flags, traps))
def __repr__(self):
"""Show the current context."""
s = []
s.append('Context(prec=%(prec)d, rounding=%(rounding)s, '
'Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, '
'clamp=%(clamp)d'
% vars(self))
names = [f.__name__ for f, v in self.flags.items() if v]
s.append('flags=[' + ', '.join(names) + ']')
names = [t.__name__ for t, v in self.traps.items() if v]
s.append('traps=[' + ', '.join(names) + ']')
return ', '.join(s) + ')'
def clear_flags(self):
"""Reset all flags to zero"""
for flag in self.flags:
self.flags[flag] = 0
def clear_traps(self):
"""Reset all traps to zero"""
for flag in self.traps:
self.traps[flag] = 0
def _shallow_copy(self):
"""Returns a shallow copy from self."""
nc = Context(self.prec, self.rounding, self.Emin, self.Emax,
self.capitals, self.clamp, self.flags, self.traps,
self._ignored_flags)
return nc
def copy(self):
"""Returns a deep copy from self."""
nc = Context(self.prec, self.rounding, self.Emin, self.Emax,
self.capitals, self.clamp,
self.flags.copy(), self.traps.copy(),
self._ignored_flags)
return nc
__copy__ = copy
def _raise_error(self, condition, explanation = None, *args):
"""Handles an error
If the flag is in _ignored_flags, returns the default response.
Otherwise, it sets the flag, then, if the corresponding
trap_enabler is set, it reraises the exception. Otherwise, it returns
the default value after setting the flag.
"""
error = _condition_map.get(condition, condition)
if error in self._ignored_flags:
# Don't touch the flag
return error().handle(self, *args)
self.flags[error] = 1
if not self.traps[error]:
# The errors define how to handle themselves.
return condition().handle(self, *args)
# Errors should only be risked on copies of the context
# self._ignored_flags = []
raise error(explanation)
def _ignore_all_flags(self):
"""Ignore all flags, if they are raised"""
return self._ignore_flags(*_signals)
def _ignore_flags(self, *flags):
"""Ignore the flags, if they are raised"""
# Do not mutate-- This way, copies of a context leave the original
# alone.
self._ignored_flags = (self._ignored_flags + list(flags))
return list(flags)
def _regard_flags(self, *flags):
"""Stop ignoring the flags, if they are raised"""
if flags and isinstance(flags[0], (tuple,list)):
flags = flags[0]
for flag in flags:
self._ignored_flags.remove(flag)
# We inherit object.__hash__, so we must deny this explicitly
__hash__ = None
def Etiny(self):
"""Returns Etiny (= Emin - prec + 1)"""
return int(self.Emin - self.prec + 1)
def Etop(self):
"""Returns maximum exponent (= Emax - prec + 1)"""
return int(self.Emax - self.prec + 1)
def _set_rounding(self, type):
"""Sets the rounding type.
Sets the rounding type, and returns the current (previous)
rounding type. Often used like:
context = context.copy()
# so you don't change the calling context
# if an error occurs in the middle.
rounding = context._set_rounding(ROUND_UP)
val = self.__sub__(other, context=context)
context._set_rounding(rounding)
This will make it round up for that operation.
"""
rounding = self.rounding
self.rounding= type
return rounding
def create_decimal(self, num='0'):
"""Creates a new Decimal instance but using self as context.
This method implements the to-number operation of the
IBM Decimal specification."""
if isinstance(num, str) and num != num.strip():
return self._raise_error(ConversionSyntax,
"no trailing or leading whitespace is "
"permitted.")
d = Decimal(num, context=self)
if d._isnan() and len(d._int) > self.prec - self.clamp:
return self._raise_error(ConversionSyntax,
"diagnostic info too long in NaN")
return d._fix(self)
def create_decimal_from_float(self, f):
"""Creates a new Decimal instance from a float but rounding using self
as the context.
>>> context = Context(prec=5, rounding=ROUND_DOWN)
>>> context.create_decimal_from_float(3.1415926535897932)
Decimal('3.1415')
>>> context = Context(prec=5, traps=[Inexact])
>>> context.create_decimal_from_float(3.1415926535897932)
Traceback (most recent call last):
...
decimal.Inexact: None
"""
d = Decimal.from_float(f) # An exact conversion
return d._fix(self) # Apply the context rounding
# Methods
def abs(self, a):
"""Returns the absolute value of the operand.
If the operand is negative, the result is the same as using the minus
operation on the operand. Otherwise, the result is the same as using
the plus operation on the operand.
>>> ExtendedContext.abs(Decimal('2.1'))
Decimal('2.1')
>>> ExtendedContext.abs(Decimal('-100'))
Decimal('100')
>>> ExtendedContext.abs(Decimal('101.5'))
Decimal('101.5')
>>> ExtendedContext.abs(Decimal('-101.5'))
Decimal('101.5')
>>> ExtendedContext.abs(-1)
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return a.__abs__(context=self)
def add(self, a, b):
"""Return the sum of the two operands.
>>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
Decimal('19.00')
>>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
Decimal('1.02E+4')
>>> ExtendedContext.add(1, Decimal(2))
Decimal('3')
>>> ExtendedContext.add(Decimal(8), 5)
Decimal('13')
>>> ExtendedContext.add(5, 5)
Decimal('10')
"""
a = _convert_other(a, raiseit=True)
r = a.__add__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def _apply(self, a):
return str(a._fix(self))
def canonical(self, a):
"""Returns the same Decimal object.
As we do not have different encodings for the same number, the
received object already is in its canonical form.
>>> ExtendedContext.canonical(Decimal('2.50'))
Decimal('2.50')
"""
if not isinstance(a, Decimal):
raise TypeError("canonical requires a Decimal as an argument.")
return a.canonical()
def compare(self, a, b):
"""Compares values numerically.
If the signs of the operands differ, a value representing each operand
('-1' if the operand is less than zero, '0' if the operand is zero or
negative zero, or '1' if the operand is greater than zero) is used in
place of that operand for the comparison instead of the actual
operand.
The comparison is then effected by subtracting the second operand from
the first and then returning a value according to the result of the
subtraction: '-1' if the result is less than zero, '0' if the result is
zero or negative zero, or '1' if the result is greater than zero.
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
Decimal('-1')
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
Decimal('0')
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
Decimal('0')
>>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
Decimal('1')
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
Decimal('1')
>>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
Decimal('-1')
>>> ExtendedContext.compare(1, 2)
Decimal('-1')
>>> ExtendedContext.compare(Decimal(1), 2)
Decimal('-1')
>>> ExtendedContext.compare(1, Decimal(2))
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.compare(b, context=self)
def compare_signal(self, a, b):
"""Compares the values of the two operands numerically.
It's pretty much like compare(), but all NaNs signal, with signaling
NaNs taking precedence over quiet NaNs.
>>> c = ExtendedContext
>>> c.compare_signal(Decimal('2.1'), Decimal('3'))
Decimal('-1')
>>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
Decimal('0')
>>> c.flags[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
Decimal('NaN')
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
Decimal('NaN')
>>> print(c.flags[InvalidOperation])
1
>>> c.compare_signal(-1, 2)
Decimal('-1')
>>> c.compare_signal(Decimal(-1), 2)
Decimal('-1')
>>> c.compare_signal(-1, Decimal(2))
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.compare_signal(b, context=self)
def compare_total(self, a, b):
"""Compares two operands using their abstract representation.
This is not like the standard compare, which use their numerical
value. Note that a total ordering is defined for all possible abstract
representations.
>>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
Decimal('-1')
>>> ExtendedContext.compare_total(Decimal('-127'), Decimal('12'))
Decimal('-1')
>>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
Decimal('-1')
>>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
Decimal('0')
>>> ExtendedContext.compare_total(Decimal('12.3'), Decimal('12.300'))
Decimal('1')
>>> ExtendedContext.compare_total(Decimal('12.3'), Decimal('NaN'))
Decimal('-1')
>>> ExtendedContext.compare_total(1, 2)
Decimal('-1')
>>> ExtendedContext.compare_total(Decimal(1), 2)
Decimal('-1')
>>> ExtendedContext.compare_total(1, Decimal(2))
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.compare_total(b)
def compare_total_mag(self, a, b):
"""Compares two operands using their abstract representation ignoring sign.
Like compare_total, but with operand's sign ignored and assumed to be 0.
"""
a = _convert_other(a, raiseit=True)
return a.compare_total_mag(b)
def copy_abs(self, a):
"""Returns a copy of the operand with the sign set to 0.
>>> ExtendedContext.copy_abs(Decimal('2.1'))
Decimal('2.1')
>>> ExtendedContext.copy_abs(Decimal('-100'))
Decimal('100')
>>> ExtendedContext.copy_abs(-1)
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return a.copy_abs()
def copy_decimal(self, a):
"""Returns a copy of the decimal object.
>>> ExtendedContext.copy_decimal(Decimal('2.1'))
Decimal('2.1')
>>> ExtendedContext.copy_decimal(Decimal('-1.00'))
Decimal('-1.00')
>>> ExtendedContext.copy_decimal(1)
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return Decimal(a)
def copy_negate(self, a):
"""Returns a copy of the operand with the sign inverted.
>>> ExtendedContext.copy_negate(Decimal('101.5'))
Decimal('-101.5')
>>> ExtendedContext.copy_negate(Decimal('-101.5'))
Decimal('101.5')
>>> ExtendedContext.copy_negate(1)
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.copy_negate()
def copy_sign(self, a, b):
"""Copies the second operand's sign to the first one.
In detail, it returns a copy of the first operand with the sign
equal to the sign of the second operand.
>>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
Decimal('1.50')
>>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
Decimal('1.50')
>>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
Decimal('-1.50')
>>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
Decimal('-1.50')
>>> ExtendedContext.copy_sign(1, -2)
Decimal('-1')
>>> ExtendedContext.copy_sign(Decimal(1), -2)
Decimal('-1')
>>> ExtendedContext.copy_sign(1, Decimal(-2))
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.copy_sign(b)
def divide(self, a, b):
"""Decimal division in a specified context.
>>> ExtendedContext.divide(Decimal('1'), Decimal('3'))
Decimal('0.333333333')
>>> ExtendedContext.divide(Decimal('2'), Decimal('3'))
Decimal('0.666666667')
>>> ExtendedContext.divide(Decimal('5'), Decimal('2'))
Decimal('2.5')
>>> ExtendedContext.divide(Decimal('1'), Decimal('10'))
Decimal('0.1')
>>> ExtendedContext.divide(Decimal('12'), Decimal('12'))
Decimal('1')
>>> ExtendedContext.divide(Decimal('8.00'), Decimal('2'))
Decimal('4.00')
>>> ExtendedContext.divide(Decimal('2.400'), Decimal('2.0'))
Decimal('1.20')
>>> ExtendedContext.divide(Decimal('1000'), Decimal('100'))
Decimal('10')
>>> ExtendedContext.divide(Decimal('1000'), Decimal('1'))
Decimal('1000')
>>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
Decimal('1.20E+6')
>>> ExtendedContext.divide(5, 5)
Decimal('1')
>>> ExtendedContext.divide(Decimal(5), 5)
Decimal('1')
>>> ExtendedContext.divide(5, Decimal(5))
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
r = a.__truediv__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def divide_int(self, a, b):
"""Divides two numbers and returns the integer part of the result.
>>> ExtendedContext.divide_int(Decimal('2'), Decimal('3'))
Decimal('0')
>>> ExtendedContext.divide_int(Decimal('10'), Decimal('3'))
Decimal('3')
>>> ExtendedContext.divide_int(Decimal('1'), Decimal('0.3'))
Decimal('3')
>>> ExtendedContext.divide_int(10, 3)
Decimal('3')
>>> ExtendedContext.divide_int(Decimal(10), 3)
Decimal('3')
>>> ExtendedContext.divide_int(10, Decimal(3))
Decimal('3')
"""
a = _convert_other(a, raiseit=True)
r = a.__floordiv__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def divmod(self, a, b):
"""Return (a // b, a % b).
>>> ExtendedContext.divmod(Decimal(8), Decimal(3))
(Decimal('2'), Decimal('2'))
>>> ExtendedContext.divmod(Decimal(8), Decimal(4))
(Decimal('2'), Decimal('0'))
>>> ExtendedContext.divmod(8, 4)
(Decimal('2'), Decimal('0'))
>>> ExtendedContext.divmod(Decimal(8), 4)
(Decimal('2'), Decimal('0'))
>>> ExtendedContext.divmod(8, Decimal(4))
(Decimal('2'), Decimal('0'))
"""
a = _convert_other(a, raiseit=True)
r = a.__divmod__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def exp(self, a):
"""Returns e ** a.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.exp(Decimal('-Infinity'))
Decimal('0')
>>> c.exp(Decimal('-1'))
Decimal('0.367879441')
>>> c.exp(Decimal('0'))
Decimal('1')
>>> c.exp(Decimal('1'))
Decimal('2.71828183')
>>> c.exp(Decimal('0.693147181'))
Decimal('2.00000000')
>>> c.exp(Decimal('+Infinity'))
Decimal('Infinity')
>>> c.exp(10)
Decimal('22026.4658')
"""
a =_convert_other(a, raiseit=True)
return a.exp(context=self)
def fma(self, a, b, c):
"""Returns a multiplied by b, plus c.
The first two operands are multiplied together, using multiply,
the third operand is then added to the result of that
multiplication, using add, all with only one final rounding.
>>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7'))
Decimal('22')
>>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7'))
Decimal('-8')
>>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578'))
Decimal('1.38435736E+12')
>>> ExtendedContext.fma(1, 3, 4)
Decimal('7')
>>> ExtendedContext.fma(1, Decimal(3), 4)
Decimal('7')
>>> ExtendedContext.fma(1, 3, Decimal(4))
Decimal('7')
"""
a = _convert_other(a, raiseit=True)
return a.fma(b, c, context=self)
def is_canonical(self, a):
"""Return True if the operand is canonical; otherwise return False.
Currently, the encoding of a Decimal instance is always
canonical, so this method returns True for any Decimal.
>>> ExtendedContext.is_canonical(Decimal('2.50'))
True
"""
if not isinstance(a, Decimal):
raise TypeError("is_canonical requires a Decimal as an argument.")
return a.is_canonical()
def is_finite(self, a):
"""Return True if the operand is finite; otherwise return False.
A Decimal instance is considered finite if it is neither
infinite nor a NaN.
>>> ExtendedContext.is_finite(Decimal('2.50'))
True
>>> ExtendedContext.is_finite(Decimal('-0.3'))
True
>>> ExtendedContext.is_finite(Decimal('0'))
True
>>> ExtendedContext.is_finite(Decimal('Inf'))
False
>>> ExtendedContext.is_finite(Decimal('NaN'))
False
>>> ExtendedContext.is_finite(1)
True
"""
a = _convert_other(a, raiseit=True)
return a.is_finite()
def is_infinite(self, a):
"""Return True if the operand is infinite; otherwise return False.
>>> ExtendedContext.is_infinite(Decimal('2.50'))
False
>>> ExtendedContext.is_infinite(Decimal('-Inf'))
True
>>> ExtendedContext.is_infinite(Decimal('NaN'))
False
>>> ExtendedContext.is_infinite(1)
False
"""
a = _convert_other(a, raiseit=True)
return a.is_infinite()
def is_nan(self, a):
"""Return True if the operand is a qNaN or sNaN;
otherwise return False.
>>> ExtendedContext.is_nan(Decimal('2.50'))
False
>>> ExtendedContext.is_nan(Decimal('NaN'))
True
>>> ExtendedContext.is_nan(Decimal('-sNaN'))
True
>>> ExtendedContext.is_nan(1)
False
"""
a = _convert_other(a, raiseit=True)
return a.is_nan()
def is_normal(self, a):
"""Return True if the operand is a normal number;
otherwise return False.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.is_normal(Decimal('2.50'))
True
>>> c.is_normal(Decimal('0.1E-999'))
False
>>> c.is_normal(Decimal('0.00'))
False
>>> c.is_normal(Decimal('-Inf'))
False
>>> c.is_normal(Decimal('NaN'))
False
>>> c.is_normal(1)
True
"""
a = _convert_other(a, raiseit=True)
return a.is_normal(context=self)
def is_qnan(self, a):
"""Return True if the operand is a quiet NaN; otherwise return False.
>>> ExtendedContext.is_qnan(Decimal('2.50'))
False
>>> ExtendedContext.is_qnan(Decimal('NaN'))
True
>>> ExtendedContext.is_qnan(Decimal('sNaN'))
False
>>> ExtendedContext.is_qnan(1)
False
"""
a = _convert_other(a, raiseit=True)
return a.is_qnan()
def is_signed(self, a):
"""Return True if the operand is negative; otherwise return False.
>>> ExtendedContext.is_signed(Decimal('2.50'))
False
>>> ExtendedContext.is_signed(Decimal('-12'))
True
>>> ExtendedContext.is_signed(Decimal('-0'))
True
>>> ExtendedContext.is_signed(8)
False
>>> ExtendedContext.is_signed(-8)
True
"""
a = _convert_other(a, raiseit=True)
return a.is_signed()
def is_snan(self, a):
"""Return True if the operand is a signaling NaN;
otherwise return False.
>>> ExtendedContext.is_snan(Decimal('2.50'))
False
>>> ExtendedContext.is_snan(Decimal('NaN'))
False
>>> ExtendedContext.is_snan(Decimal('sNaN'))
True
>>> ExtendedContext.is_snan(1)
False
"""
a = _convert_other(a, raiseit=True)
return a.is_snan()
def is_subnormal(self, a):
"""Return True if the operand is subnormal; otherwise return False.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.is_subnormal(Decimal('2.50'))
False
>>> c.is_subnormal(Decimal('0.1E-999'))
True
>>> c.is_subnormal(Decimal('0.00'))
False
>>> c.is_subnormal(Decimal('-Inf'))
False
>>> c.is_subnormal(Decimal('NaN'))
False
>>> c.is_subnormal(1)
False
"""
a = _convert_other(a, raiseit=True)
return a.is_subnormal(context=self)
def is_zero(self, a):
"""Return True if the operand is a zero; otherwise return False.
>>> ExtendedContext.is_zero(Decimal('0'))
True
>>> ExtendedContext.is_zero(Decimal('2.50'))
False
>>> ExtendedContext.is_zero(Decimal('-0E+2'))
True
>>> ExtendedContext.is_zero(1)
False
>>> ExtendedContext.is_zero(0)
True
"""
a = _convert_other(a, raiseit=True)
return a.is_zero()
def ln(self, a):
"""Returns the natural (base e) logarithm of the operand.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.ln(Decimal('0'))
Decimal('-Infinity')
>>> c.ln(Decimal('1.000'))
Decimal('0')
>>> c.ln(Decimal('2.71828183'))
Decimal('1.00000000')
>>> c.ln(Decimal('10'))
Decimal('2.30258509')
>>> c.ln(Decimal('+Infinity'))
Decimal('Infinity')
>>> c.ln(1)
Decimal('0')
"""
a = _convert_other(a, raiseit=True)
return a.ln(context=self)
def log10(self, a):
"""Returns the base 10 logarithm of the operand.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.log10(Decimal('0'))
Decimal('-Infinity')
>>> c.log10(Decimal('0.001'))
Decimal('-3')
>>> c.log10(Decimal('1.000'))
Decimal('0')
>>> c.log10(Decimal('2'))
Decimal('0.301029996')
>>> c.log10(Decimal('10'))
Decimal('1')
>>> c.log10(Decimal('70'))
Decimal('1.84509804')
>>> c.log10(Decimal('+Infinity'))
Decimal('Infinity')
>>> c.log10(0)
Decimal('-Infinity')
>>> c.log10(1)
Decimal('0')
"""
a = _convert_other(a, raiseit=True)
return a.log10(context=self)
def logb(self, a):
""" Returns the exponent of the magnitude of the operand's MSD.
The result is the integer which is the exponent of the magnitude
of the most significant digit of the operand (as though the
operand were truncated to a single digit while maintaining the
value of that digit and without limiting the resulting exponent).
>>> ExtendedContext.logb(Decimal('250'))
Decimal('2')
>>> ExtendedContext.logb(Decimal('2.50'))
Decimal('0')
>>> ExtendedContext.logb(Decimal('0.03'))
Decimal('-2')
>>> ExtendedContext.logb(Decimal('0'))
Decimal('-Infinity')
>>> ExtendedContext.logb(1)
Decimal('0')
>>> ExtendedContext.logb(10)
Decimal('1')
>>> ExtendedContext.logb(100)
Decimal('2')
"""
a = _convert_other(a, raiseit=True)
return a.logb(context=self)
def logical_and(self, a, b):
"""Applies the logical operation 'and' between each operand's digits.
The operands must be both logical numbers.
>>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
Decimal('0')
>>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
Decimal('0')
>>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
Decimal('0')
>>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
Decimal('1')
>>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
Decimal('1000')
>>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
Decimal('10')
>>> ExtendedContext.logical_and(110, 1101)
Decimal('100')
>>> ExtendedContext.logical_and(Decimal(110), 1101)
Decimal('100')
>>> ExtendedContext.logical_and(110, Decimal(1101))
Decimal('100')
"""
a = _convert_other(a, raiseit=True)
return a.logical_and(b, context=self)
def logical_invert(self, a):
"""Invert all the digits in the operand.
The operand must be a logical number.
>>> ExtendedContext.logical_invert(Decimal('0'))
Decimal('111111111')
>>> ExtendedContext.logical_invert(Decimal('1'))
Decimal('111111110')
>>> ExtendedContext.logical_invert(Decimal('111111111'))
Decimal('0')
>>> ExtendedContext.logical_invert(Decimal('101010101'))
Decimal('10101010')
>>> ExtendedContext.logical_invert(1101)
Decimal('111110010')
"""
a = _convert_other(a, raiseit=True)
return a.logical_invert(context=self)
def logical_or(self, a, b):
"""Applies the logical operation 'or' between each operand's digits.
The operands must be both logical numbers.
>>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
Decimal('0')
>>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
Decimal('1')
>>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
Decimal('1')
>>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
Decimal('1')
>>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
Decimal('1110')
>>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
Decimal('1110')
>>> ExtendedContext.logical_or(110, 1101)
Decimal('1111')
>>> ExtendedContext.logical_or(Decimal(110), 1101)
Decimal('1111')
>>> ExtendedContext.logical_or(110, Decimal(1101))
Decimal('1111')
"""
a = _convert_other(a, raiseit=True)
return a.logical_or(b, context=self)
def logical_xor(self, a, b):
"""Applies the logical operation 'xor' between each operand's digits.
The operands must be both logical numbers.
>>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
Decimal('0')
>>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
Decimal('1')
>>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
Decimal('1')
>>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
Decimal('0')
>>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
Decimal('110')
>>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
Decimal('1101')
>>> ExtendedContext.logical_xor(110, 1101)
Decimal('1011')
>>> ExtendedContext.logical_xor(Decimal(110), 1101)
Decimal('1011')
>>> ExtendedContext.logical_xor(110, Decimal(1101))
Decimal('1011')
"""
a = _convert_other(a, raiseit=True)
return a.logical_xor(b, context=self)
def max(self, a, b):
"""max compares two values numerically and returns the maximum.
If either operand is a NaN then the general rules apply.
Otherwise, the operands are compared as though by the compare
operation. If they are numerically equal then the left-hand operand
is chosen as the result. Otherwise the maximum (closer to positive
infinity) of the two operands is chosen as the result.
>>> ExtendedContext.max(Decimal('3'), Decimal('2'))
Decimal('3')
>>> ExtendedContext.max(Decimal('-10'), Decimal('3'))
Decimal('3')
>>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
Decimal('1')
>>> ExtendedContext.max(Decimal('7'), Decimal('NaN'))
Decimal('7')
>>> ExtendedContext.max(1, 2)
Decimal('2')
>>> ExtendedContext.max(Decimal(1), 2)
Decimal('2')
>>> ExtendedContext.max(1, Decimal(2))
Decimal('2')
"""
a = _convert_other(a, raiseit=True)
return a.max(b, context=self)
def max_mag(self, a, b):
"""Compares the values numerically with their sign ignored.
>>> ExtendedContext.max_mag(Decimal('7'), Decimal('NaN'))
Decimal('7')
>>> ExtendedContext.max_mag(Decimal('7'), Decimal('-10'))
Decimal('-10')
>>> ExtendedContext.max_mag(1, -2)
Decimal('-2')
>>> ExtendedContext.max_mag(Decimal(1), -2)
Decimal('-2')
>>> ExtendedContext.max_mag(1, Decimal(-2))
Decimal('-2')
"""
a = _convert_other(a, raiseit=True)
return a.max_mag(b, context=self)
def min(self, a, b):
"""min compares two values numerically and returns the minimum.
If either operand is a NaN then the general rules apply.
Otherwise, the operands are compared as though by the compare
operation. If they are numerically equal then the left-hand operand
is chosen as the result. Otherwise the minimum (closer to negative
infinity) of the two operands is chosen as the result.
>>> ExtendedContext.min(Decimal('3'), Decimal('2'))
Decimal('2')
>>> ExtendedContext.min(Decimal('-10'), Decimal('3'))
Decimal('-10')
>>> ExtendedContext.min(Decimal('1.0'), Decimal('1'))
Decimal('1.0')
>>> ExtendedContext.min(Decimal('7'), Decimal('NaN'))
Decimal('7')
>>> ExtendedContext.min(1, 2)
Decimal('1')
>>> ExtendedContext.min(Decimal(1), 2)
Decimal('1')
>>> ExtendedContext.min(1, Decimal(29))
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return a.min(b, context=self)
def min_mag(self, a, b):
"""Compares the values numerically with their sign ignored.
>>> ExtendedContext.min_mag(Decimal('3'), Decimal('-2'))
Decimal('-2')
>>> ExtendedContext.min_mag(Decimal('-3'), Decimal('NaN'))
Decimal('-3')
>>> ExtendedContext.min_mag(1, -2)
Decimal('1')
>>> ExtendedContext.min_mag(Decimal(1), -2)
Decimal('1')
>>> ExtendedContext.min_mag(1, Decimal(-2))
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return a.min_mag(b, context=self)
def minus(self, a):
"""Minus corresponds to unary prefix minus in Python.
The operation is evaluated using the same rules as subtract; the
operation minus(a) is calculated as subtract('0', a) where the '0'
has the same exponent as the operand.
>>> ExtendedContext.minus(Decimal('1.3'))
Decimal('-1.3')
>>> ExtendedContext.minus(Decimal('-1.3'))
Decimal('1.3')
>>> ExtendedContext.minus(1)
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.__neg__(context=self)
def multiply(self, a, b):
"""multiply multiplies two operands.
If either operand is a special value then the general rules apply.
Otherwise, the operands are multiplied together
('long multiplication'), resulting in a number which may be as long as
the sum of the lengths of the two operands.
>>> ExtendedContext.multiply(Decimal('1.20'), Decimal('3'))
Decimal('3.60')
>>> ExtendedContext.multiply(Decimal('7'), Decimal('3'))
Decimal('21')
>>> ExtendedContext.multiply(Decimal('0.9'), Decimal('0.8'))
Decimal('0.72')
>>> ExtendedContext.multiply(Decimal('0.9'), Decimal('-0'))
Decimal('-0.0')
>>> ExtendedContext.multiply(Decimal('654321'), Decimal('654321'))
Decimal('4.28135971E+11')
>>> ExtendedContext.multiply(7, 7)
Decimal('49')
>>> ExtendedContext.multiply(Decimal(7), 7)
Decimal('49')
>>> ExtendedContext.multiply(7, Decimal(7))
Decimal('49')
"""
a = _convert_other(a, raiseit=True)
r = a.__mul__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def next_minus(self, a):
"""Returns the largest representable number smaller than a.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> ExtendedContext.next_minus(Decimal('1'))
Decimal('0.999999999')
>>> c.next_minus(Decimal('1E-1007'))
Decimal('0E-1007')
>>> ExtendedContext.next_minus(Decimal('-1.00000003'))
Decimal('-1.00000004')
>>> c.next_minus(Decimal('Infinity'))
Decimal('9.99999999E+999')
>>> c.next_minus(1)
Decimal('0.999999999')
"""
a = _convert_other(a, raiseit=True)
return a.next_minus(context=self)
def next_plus(self, a):
"""Returns the smallest representable number larger than a.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> ExtendedContext.next_plus(Decimal('1'))
Decimal('1.00000001')
>>> c.next_plus(Decimal('-1E-1007'))
Decimal('-0E-1007')
>>> ExtendedContext.next_plus(Decimal('-1.00000003'))
Decimal('-1.00000002')
>>> c.next_plus(Decimal('-Infinity'))
Decimal('-9.99999999E+999')
>>> c.next_plus(1)
Decimal('1.00000001')
"""
a = _convert_other(a, raiseit=True)
return a.next_plus(context=self)
def next_toward(self, a, b):
"""Returns the number closest to a, in direction towards b.
The result is the closest representable number from the first
operand (but not the first operand) that is in the direction
towards the second operand, unless the operands have the same
value.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.next_toward(Decimal('1'), Decimal('2'))
Decimal('1.00000001')
>>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
Decimal('-0E-1007')
>>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
Decimal('-1.00000002')
>>> c.next_toward(Decimal('1'), Decimal('0'))
Decimal('0.999999999')
>>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
Decimal('0E-1007')
>>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
Decimal('-1.00000004')
>>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
Decimal('-0.00')
>>> c.next_toward(0, 1)
Decimal('1E-1007')
>>> c.next_toward(Decimal(0), 1)
Decimal('1E-1007')
>>> c.next_toward(0, Decimal(1))
Decimal('1E-1007')
"""
a = _convert_other(a, raiseit=True)
return a.next_toward(b, context=self)
def normalize(self, a):
"""normalize reduces an operand to its simplest form.
Essentially a plus operation with all trailing zeros removed from the
result.
>>> ExtendedContext.normalize(Decimal('2.1'))
Decimal('2.1')
>>> ExtendedContext.normalize(Decimal('-2.0'))
Decimal('-2')
>>> ExtendedContext.normalize(Decimal('1.200'))
Decimal('1.2')
>>> ExtendedContext.normalize(Decimal('-120'))
Decimal('-1.2E+2')
>>> ExtendedContext.normalize(Decimal('120.00'))
Decimal('1.2E+2')
>>> ExtendedContext.normalize(Decimal('0.00'))
Decimal('0')
>>> ExtendedContext.normalize(6)
Decimal('6')
"""
a = _convert_other(a, raiseit=True)
return a.normalize(context=self)
def number_class(self, a):
"""Returns an indication of the class of the operand.
The class is one of the following strings:
-sNaN
-NaN
-Infinity
-Normal
-Subnormal
-Zero
+Zero
+Subnormal
+Normal
+Infinity
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.number_class(Decimal('Infinity'))
'+Infinity'
>>> c.number_class(Decimal('1E-10'))
'+Normal'
>>> c.number_class(Decimal('2.50'))
'+Normal'
>>> c.number_class(Decimal('0.1E-999'))
'+Subnormal'
>>> c.number_class(Decimal('0'))
'+Zero'
>>> c.number_class(Decimal('-0'))
'-Zero'
>>> c.number_class(Decimal('-0.1E-999'))
'-Subnormal'
>>> c.number_class(Decimal('-1E-10'))
'-Normal'
>>> c.number_class(Decimal('-2.50'))
'-Normal'
>>> c.number_class(Decimal('-Infinity'))
'-Infinity'
>>> c.number_class(Decimal('NaN'))
'NaN'
>>> c.number_class(Decimal('-NaN'))
'NaN'
>>> c.number_class(Decimal('sNaN'))
'sNaN'
>>> c.number_class(123)
'+Normal'
"""
a = _convert_other(a, raiseit=True)
return a.number_class(context=self)
def plus(self, a):
"""Plus corresponds to unary prefix plus in Python.
The operation is evaluated using the same rules as add; the
operation plus(a) is calculated as add('0', a) where the '0'
has the same exponent as the operand.
>>> ExtendedContext.plus(Decimal('1.3'))
Decimal('1.3')
>>> ExtendedContext.plus(Decimal('-1.3'))
Decimal('-1.3')
>>> ExtendedContext.plus(-1)
Decimal('-1')
"""
a = _convert_other(a, raiseit=True)
return a.__pos__(context=self)
def power(self, a, b, modulo=None):
"""Raises a to the power of b, to modulo if given.
With two arguments, compute a**b. If a is negative then b
must be integral. The result will be inexact unless b is
integral and the result is finite and can be expressed exactly
in 'precision' digits.
With three arguments, compute (a**b) % modulo. For the
three argument form, the following restrictions on the
arguments hold:
- all three arguments must be integral
- b must be nonnegative
- at least one of a or b must be nonzero
- modulo must be nonzero and have at most 'precision' digits
The result of pow(a, b, modulo) is identical to the result
that would be obtained by computing (a**b) % modulo with
unbounded precision, but is computed more efficiently. It is
always exact.
>>> c = ExtendedContext.copy()
>>> c.Emin = -999
>>> c.Emax = 999
>>> c.power(Decimal('2'), Decimal('3'))
Decimal('8')
>>> c.power(Decimal('-2'), Decimal('3'))
Decimal('-8')
>>> c.power(Decimal('2'), Decimal('-3'))
Decimal('0.125')
>>> c.power(Decimal('1.7'), Decimal('8'))
Decimal('69.7575744')
>>> c.power(Decimal('10'), Decimal('0.301029996'))
Decimal('2.00000000')
>>> c.power(Decimal('Infinity'), Decimal('-1'))
Decimal('0')
>>> c.power(Decimal('Infinity'), Decimal('0'))
Decimal('1')
>>> c.power(Decimal('Infinity'), Decimal('1'))
Decimal('Infinity')
>>> c.power(Decimal('-Infinity'), Decimal('-1'))
Decimal('-0')
>>> c.power(Decimal('-Infinity'), Decimal('0'))
Decimal('1')
>>> c.power(Decimal('-Infinity'), Decimal('1'))
Decimal('-Infinity')
>>> c.power(Decimal('-Infinity'), Decimal('2'))
Decimal('Infinity')
>>> c.power(Decimal('0'), Decimal('0'))
Decimal('NaN')
>>> c.power(Decimal('3'), Decimal('7'), Decimal('16'))
Decimal('11')
>>> c.power(Decimal('-3'), Decimal('7'), Decimal('16'))
Decimal('-11')
>>> c.power(Decimal('-3'), Decimal('8'), Decimal('16'))
Decimal('1')
>>> c.power(Decimal('3'), Decimal('7'), Decimal('-16'))
Decimal('11')
>>> c.power(Decimal('23E12345'), Decimal('67E189'), Decimal('123456789'))
Decimal('11729830')
>>> c.power(Decimal('-0'), Decimal('17'), Decimal('1729'))
Decimal('-0')
>>> c.power(Decimal('-23'), Decimal('0'), Decimal('65537'))
Decimal('1')
>>> ExtendedContext.power(7, 7)
Decimal('823543')
>>> ExtendedContext.power(Decimal(7), 7)
Decimal('823543')
>>> ExtendedContext.power(7, Decimal(7), 2)
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
r = a.__pow__(b, modulo, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def quantize(self, a, b):
"""Returns a value equal to 'a' (rounded), having the exponent of 'b'.
The coefficient of the result is derived from that of the left-hand
operand. It may be rounded using the current rounding setting (if the
exponent is being increased), multiplied by a positive power of ten (if
the exponent is being decreased), or is unchanged (if the exponent is
already equal to that of the right-hand operand).
Unlike other operations, if the length of the coefficient after the
quantize operation would be greater than precision then an Invalid
operation condition is raised. This guarantees that, unless there is
an error condition, the exponent of the result of a quantize is always
equal to that of the right-hand operand.
Also unlike other operations, quantize will never raise Underflow, even
if the result is subnormal and inexact.
>>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001'))
Decimal('2.170')
>>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01'))
Decimal('2.17')
>>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1'))
Decimal('2.2')
>>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0'))
Decimal('2')
>>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1'))
Decimal('0E+1')
>>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity'))
Decimal('-Infinity')
>>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity'))
Decimal('NaN')
>>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1'))
Decimal('-0')
>>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5'))
Decimal('-0E+5')
>>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2'))
Decimal('NaN')
>>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2'))
Decimal('NaN')
>>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1'))
Decimal('217.0')
>>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0'))
Decimal('217')
>>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1'))
Decimal('2.2E+2')
>>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2'))
Decimal('2E+2')
>>> ExtendedContext.quantize(1, 2)
Decimal('1')
>>> ExtendedContext.quantize(Decimal(1), 2)
Decimal('1')
>>> ExtendedContext.quantize(1, Decimal(2))
Decimal('1')
"""
a = _convert_other(a, raiseit=True)
return a.quantize(b, context=self)
def radix(self):
"""Just returns 10, as this is Decimal, :)
>>> ExtendedContext.radix()
Decimal('10')
"""
return Decimal(10)
def remainder(self, a, b):
"""Returns the remainder from integer division.
The result is the residue of the dividend after the operation of
calculating integer division as described for divide-integer, rounded
to precision digits if necessary. The sign of the result, if
non-zero, is the same as that of the original dividend.
This operation will fail under the same conditions as integer division
(that is, if integer division on the same two operands would fail, the
remainder cannot be calculated).
>>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3'))
Decimal('2.1')
>>> ExtendedContext.remainder(Decimal('10'), Decimal('3'))
Decimal('1')
>>> ExtendedContext.remainder(Decimal('-10'), Decimal('3'))
Decimal('-1')
>>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1'))
Decimal('0.2')
>>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3'))
Decimal('0.1')
>>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3'))
Decimal('1.0')
>>> ExtendedContext.remainder(22, 6)
Decimal('4')
>>> ExtendedContext.remainder(Decimal(22), 6)
Decimal('4')
>>> ExtendedContext.remainder(22, Decimal(6))
Decimal('4')
"""
a = _convert_other(a, raiseit=True)
r = a.__mod__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def remainder_near(self, a, b):
"""Returns to be "a - b * n", where n is the integer nearest the exact
value of "x / b" (if two integers are equally near then the even one
is chosen). If the result is equal to 0 then its sign will be the
sign of a.
This operation will fail under the same conditions as integer division
(that is, if integer division on the same two operands would fail, the
remainder cannot be calculated).
>>> ExtendedContext.remainder_near(Decimal('2.1'), Decimal('3'))
Decimal('-0.9')
>>> ExtendedContext.remainder_near(Decimal('10'), Decimal('6'))
Decimal('-2')
>>> ExtendedContext.remainder_near(Decimal('10'), Decimal('3'))
Decimal('1')
>>> ExtendedContext.remainder_near(Decimal('-10'), Decimal('3'))
Decimal('-1')
>>> ExtendedContext.remainder_near(Decimal('10.2'), Decimal('1'))
Decimal('0.2')
>>> ExtendedContext.remainder_near(Decimal('10'), Decimal('0.3'))
Decimal('0.1')
>>> ExtendedContext.remainder_near(Decimal('3.6'), Decimal('1.3'))
Decimal('-0.3')
>>> ExtendedContext.remainder_near(3, 11)
Decimal('3')
>>> ExtendedContext.remainder_near(Decimal(3), 11)
Decimal('3')
>>> ExtendedContext.remainder_near(3, Decimal(11))
Decimal('3')
"""
a = _convert_other(a, raiseit=True)
return a.remainder_near(b, context=self)
def rotate(self, a, b):
"""Returns a rotated copy of a, b times.
The coefficient of the result is a rotated copy of the digits in
the coefficient of the first operand. The number of places of
rotation is taken from the absolute value of the second operand,
with the rotation being to the left if the second operand is
positive or to the right otherwise.
>>> ExtendedContext.rotate(Decimal('34'), Decimal('8'))
Decimal('400000003')
>>> ExtendedContext.rotate(Decimal('12'), Decimal('9'))
Decimal('12')
>>> ExtendedContext.rotate(Decimal('123456789'), Decimal('-2'))
Decimal('891234567')
>>> ExtendedContext.rotate(Decimal('123456789'), Decimal('0'))
Decimal('123456789')
>>> ExtendedContext.rotate(Decimal('123456789'), Decimal('+2'))
Decimal('345678912')
>>> ExtendedContext.rotate(1333333, 1)
Decimal('13333330')
>>> ExtendedContext.rotate(Decimal(1333333), 1)
Decimal('13333330')
>>> ExtendedContext.rotate(1333333, Decimal(1))
Decimal('13333330')
"""
a = _convert_other(a, raiseit=True)
return a.rotate(b, context=self)
def same_quantum(self, a, b):
"""Returns True if the two operands have the same exponent.
The result is never affected by either the sign or the coefficient of
either operand.
>>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('0.001'))
False
>>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('0.01'))
True
>>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('1'))
False
>>> ExtendedContext.same_quantum(Decimal('Inf'), Decimal('-Inf'))
True
>>> ExtendedContext.same_quantum(10000, -1)
True
>>> ExtendedContext.same_quantum(Decimal(10000), -1)
True
>>> ExtendedContext.same_quantum(10000, Decimal(-1))
True
"""
a = _convert_other(a, raiseit=True)
return a.same_quantum(b)
def scaleb (self, a, b):
"""Returns the first operand after adding the second value its exp.
>>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('-2'))
Decimal('0.0750')
>>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('0'))
Decimal('7.50')
>>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('3'))
Decimal('7.50E+3')
>>> ExtendedContext.scaleb(1, 4)
Decimal('1E+4')
>>> ExtendedContext.scaleb(Decimal(1), 4)
Decimal('1E+4')
>>> ExtendedContext.scaleb(1, Decimal(4))
Decimal('1E+4')
"""
a = _convert_other(a, raiseit=True)
return a.scaleb(b, context=self)
def shift(self, a, b):
"""Returns a shifted copy of a, b times.
The coefficient of the result is a shifted copy of the digits
in the coefficient of the first operand. The number of places
to shift is taken from the absolute value of the second operand,
with the shift being to the left if the second operand is
positive or to the right otherwise. Digits shifted into the
coefficient are zeros.
>>> ExtendedContext.shift(Decimal('34'), Decimal('8'))
Decimal('400000000')
>>> ExtendedContext.shift(Decimal('12'), Decimal('9'))
Decimal('0')
>>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2'))
Decimal('1234567')
>>> ExtendedContext.shift(Decimal('123456789'), Decimal('0'))
Decimal('123456789')
>>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2'))
Decimal('345678900')
>>> ExtendedContext.shift(88888888, 2)
Decimal('888888800')
>>> ExtendedContext.shift(Decimal(88888888), 2)
Decimal('888888800')
>>> ExtendedContext.shift(88888888, Decimal(2))
Decimal('888888800')
"""
a = _convert_other(a, raiseit=True)
return a.shift(b, context=self)
def sqrt(self, a):
"""Square root of a non-negative number to context precision.
If the result must be inexact, it is rounded using the round-half-even
algorithm.
>>> ExtendedContext.sqrt(Decimal('0'))
Decimal('0')
>>> ExtendedContext.sqrt(Decimal('-0'))
Decimal('-0')
>>> ExtendedContext.sqrt(Decimal('0.39'))
Decimal('0.624499800')
>>> ExtendedContext.sqrt(Decimal('100'))
Decimal('10')
>>> ExtendedContext.sqrt(Decimal('1'))
Decimal('1')
>>> ExtendedContext.sqrt(Decimal('1.0'))
Decimal('1.0')
>>> ExtendedContext.sqrt(Decimal('1.00'))
Decimal('1.0')
>>> ExtendedContext.sqrt(Decimal('7'))
Decimal('2.64575131')
>>> ExtendedContext.sqrt(Decimal('10'))
Decimal('3.16227766')
>>> ExtendedContext.sqrt(2)
Decimal('1.41421356')
>>> ExtendedContext.prec
9
"""
a = _convert_other(a, raiseit=True)
return a.sqrt(context=self)
def subtract(self, a, b):
"""Return the difference between the two operands.
>>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.07'))
Decimal('0.23')
>>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.30'))
Decimal('0.00')
>>> ExtendedContext.subtract(Decimal('1.3'), Decimal('2.07'))
Decimal('-0.77')
>>> ExtendedContext.subtract(8, 5)
Decimal('3')
>>> ExtendedContext.subtract(Decimal(8), 5)
Decimal('3')
>>> ExtendedContext.subtract(8, Decimal(5))
Decimal('3')
"""
a = _convert_other(a, raiseit=True)
r = a.__sub__(b, context=self)
if r is NotImplemented:
raise TypeError("Unable to convert %s to Decimal" % b)
else:
return r
def to_eng_string(self, a):
"""Converts a number to a string, using scientific notation.
The operation is not affected by the context.
"""
a = _convert_other(a, raiseit=True)
return a.to_eng_string(context=self)
def to_sci_string(self, a):
"""Converts a number to a string, using scientific notation.
The operation is not affected by the context.
"""
a = _convert_other(a, raiseit=True)
return a.__str__(context=self)
def to_integral_exact(self, a):
"""Rounds to an integer.
When the operand has a negative exponent, the result is the same
as using the quantize() operation using the given operand as the
left-hand-operand, 1E+0 as the right-hand-operand, and the precision
of the operand as the precision setting; Inexact and Rounded flags
are allowed in this operation. The rounding mode is taken from the
context.
>>> ExtendedContext.to_integral_exact(Decimal('2.1'))
Decimal('2')
>>> ExtendedContext.to_integral_exact(Decimal('100'))
Decimal('100')
>>> ExtendedContext.to_integral_exact(Decimal('100.0'))
Decimal('100')
>>> ExtendedContext.to_integral_exact(Decimal('101.5'))
Decimal('102')
>>> ExtendedContext.to_integral_exact(Decimal('-101.5'))
Decimal('-102')
>>> ExtendedContext.to_integral_exact(Decimal('10E+5'))
Decimal('1.0E+6')
>>> ExtendedContext.to_integral_exact(Decimal('7.89E+77'))
Decimal('7.89E+77')
>>> ExtendedContext.to_integral_exact(Decimal('-Inf'))
Decimal('-Infinity')
"""
a = _convert_other(a, raiseit=True)
return a.to_integral_exact(context=self)
def to_integral_value(self, a):
"""Rounds to an integer.
When the operand has a negative exponent, the result is the same
as using the quantize() operation using the given operand as the
left-hand-operand, 1E+0 as the right-hand-operand, and the precision
of the operand as the precision setting, except that no flags will
be set. The rounding mode is taken from the context.
>>> ExtendedContext.to_integral_value(Decimal('2.1'))
Decimal('2')
>>> ExtendedContext.to_integral_value(Decimal('100'))
Decimal('100')
>>> ExtendedContext.to_integral_value(Decimal('100.0'))
Decimal('100')
>>> ExtendedContext.to_integral_value(Decimal('101.5'))
Decimal('102')
>>> ExtendedContext.to_integral_value(Decimal('-101.5'))
Decimal('-102')
>>> ExtendedContext.to_integral_value(Decimal('10E+5'))
Decimal('1.0E+6')
>>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
Decimal('7.89E+77')
>>> ExtendedContext.to_integral_value(Decimal('-Inf'))
Decimal('-Infinity')
"""
a = _convert_other(a, raiseit=True)
return a.to_integral_value(context=self)
# the method name changed, but we provide also the old one, for compatibility
to_integral = to_integral_value
class _WorkRep(object):
__slots__ = ('sign','int','exp')
# sign: 0 or 1
# int: int
# exp: None, int, or string
def __init__(self, value=None):
if value is None:
self.sign = None
self.int = 0
self.exp = None
elif isinstance(value, Decimal):
self.sign = value._sign
self.int = int(value._int)
self.exp = value._exp
else:
# assert isinstance(value, tuple)
self.sign = value[0]
self.int = value[1]
self.exp = value[2]
def __repr__(self):
return "(%r, %r, %r)" % (self.sign, self.int, self.exp)
__str__ = __repr__
def _normalize(op1, op2, prec = 0):
"""Normalizes op1, op2 to have the same exp and length of coefficient.
Done during addition.
"""
if op1.exp < op2.exp:
tmp = op2
other = op1
else:
tmp = op1
other = op2
# Let exp = min(tmp.exp - 1, tmp.adjusted() - precision - 1).
# Then adding 10**exp to tmp has the same effect (after rounding)
# as adding any positive quantity smaller than 10**exp; similarly
# for subtraction. So if other is smaller than 10**exp we replace
# it with 10**exp. This avoids tmp.exp - other.exp getting too large.
tmp_len = len(str(tmp.int))
other_len = len(str(other.int))
exp = tmp.exp + min(-1, tmp_len - prec - 2)
if other_len + other.exp - 1 < exp:
other.int = 1
other.exp = exp
tmp.int *= 10 ** (tmp.exp - other.exp)
tmp.exp = other.exp
return op1, op2
##### Integer arithmetic functions used by ln, log10, exp and __pow__ #####
_nbits = int.bit_length
def _decimal_lshift_exact(n, e):
""" Given integers n and e, return n * 10**e if it's an integer, else None.
The computation is designed to avoid computing large powers of 10
unnecessarily.
>>> _decimal_lshift_exact(3, 4)
30000
>>> _decimal_lshift_exact(300, -999999999) # returns None
"""
if n == 0:
return 0
elif e >= 0:
return n * 10**e
else:
# val_n = largest power of 10 dividing n.
str_n = str(abs(n))
val_n = len(str_n) - len(str_n.rstrip('0'))
return None if val_n < -e else n // 10**-e
def _sqrt_nearest(n, a):
"""Closest integer to the square root of the positive integer n. a is
an initial approximation to the square root. Any positive integer
will do for a, but the closer a is to the square root of n the
faster convergence will be.
"""
if n <= 0 or a <= 0:
raise ValueError("Both arguments to _sqrt_nearest should be positive.")
b=0
while a != b:
b, a = a, a--n//a>>1
return a
def _rshift_nearest(x, shift):
"""Given an integer x and a nonnegative integer shift, return closest
integer to x / 2**shift; use round-to-even in case of a tie.
"""
b, q = 1 << shift, x >> shift
return q + (2*(x & (b-1)) + (q&1) > b)
def _div_nearest(a, b):
"""Closest integer to a/b, a and b positive integers; rounds to even
in the case of a tie.
"""
q, r = divmod(a, b)
return q + (2*r + (q&1) > b)
def _ilog(x, M, L = 8):
"""Integer approximation to M*log(x/M), with absolute error boundable
in terms only of x/M.
Given positive integers x and M, return an integer approximation to
M * log(x/M). For L = 8 and 0.1 <= x/M <= 10 the difference
between the approximation and the exact result is at most 22. For
L = 8 and 1.0 <= x/M <= 10.0 the difference is at most 15. In
both cases these are upper bounds on the error; it will usually be
much smaller."""
# The basic algorithm is the following: let log1p be the function
# log1p(x) = log(1+x). Then log(x/M) = log1p((x-M)/M). We use
# the reduction
#
# log1p(y) = 2*log1p(y/(1+sqrt(1+y)))
#
# repeatedly until the argument to log1p is small (< 2**-L in
# absolute value). For small y we can use the Taylor series
# expansion
#
# log1p(y) ~ y - y**2/2 + y**3/3 - ... - (-y)**T/T
#
# truncating at T such that y**T is small enough. The whole
# computation is carried out in a form of fixed-point arithmetic,
# with a real number z being represented by an integer
# approximation to z*M. To avoid loss of precision, the y below
# is actually an integer approximation to 2**R*y*M, where R is the
# number of reductions performed so far.
y = x-M
# argument reduction; R = number of reductions performed
R = 0
while (R <= L and abs(y) << L-R >= M or
R > L and abs(y) >> R-L >= M):
y = _div_nearest((M*y) << 1,
M + _sqrt_nearest(M*(M+_rshift_nearest(y, R)), M))
R += 1
# Taylor series with T terms
T = -int(-10*len(str(M))//(3*L))
yshift = _rshift_nearest(y, R)
w = _div_nearest(M, T)
for k in range(T-1, 0, -1):
w = _div_nearest(M, k) - _div_nearest(yshift*w, M)
return _div_nearest(w*y, M)
def _dlog10(c, e, p):
"""Given integers c, e and p with c > 0, p >= 0, compute an integer
approximation to 10**p * log10(c*10**e), with an absolute error of
at most 1. Assumes that c*10**e is not exactly 1."""
# increase precision by 2; compensate for this by dividing
# final result by 100
p += 2
# write c*10**e as d*10**f with either:
# f >= 0 and 1 <= d <= 10, or
# f <= 0 and 0.1 <= d <= 1.
# Thus for c*10**e close to 1, f = 0
l = len(str(c))
f = e+l - (e+l >= 1)
if p > 0:
M = 10**p
k = e+p-f
if k >= 0:
c *= 10**k
else:
c = _div_nearest(c, 10**-k)
log_d = _ilog(c, M) # error < 5 + 22 = 27
log_10 = _log10_digits(p) # error < 1
log_d = _div_nearest(log_d*M, log_10)
log_tenpower = f*M # exact
else:
log_d = 0 # error < 2.31
log_tenpower = _div_nearest(f, 10**-p) # error < 0.5
return _div_nearest(log_tenpower+log_d, 100)
def _dlog(c, e, p):
"""Given integers c, e and p with c > 0, compute an integer
approximation to 10**p * log(c*10**e), with an absolute error of
at most 1. Assumes that c*10**e is not exactly 1."""
# Increase precision by 2. The precision increase is compensated
# for at the end with a division by 100.
p += 2
# rewrite c*10**e as d*10**f with either f >= 0 and 1 <= d <= 10,
# or f <= 0 and 0.1 <= d <= 1. Then we can compute 10**p * log(c*10**e)
# as 10**p * log(d) + 10**p*f * log(10).
l = len(str(c))
f = e+l - (e+l >= 1)
# compute approximation to 10**p*log(d), with error < 27
if p > 0:
k = e+p-f
if k >= 0:
c *= 10**k
else:
c = _div_nearest(c, 10**-k) # error of <= 0.5 in c
# _ilog magnifies existing error in c by a factor of at most 10
log_d = _ilog(c, 10**p) # error < 5 + 22 = 27
else:
# p <= 0: just approximate the whole thing by 0; error < 2.31
log_d = 0
# compute approximation to f*10**p*log(10), with error < 11.
if f:
extra = len(str(abs(f)))-1
if p + extra >= 0:
# error in f * _log10_digits(p+extra) < |f| * 1 = |f|
# after division, error < |f|/10**extra + 0.5 < 10 + 0.5 < 11
f_log_ten = _div_nearest(f*_log10_digits(p+extra), 10**extra)
else:
f_log_ten = 0
else:
f_log_ten = 0
# error in sum < 11+27 = 38; error after division < 0.38 + 0.5 < 1
return _div_nearest(f_log_ten + log_d, 100)
class _Log10Memoize(object):
"""Class to compute, store, and allow retrieval of, digits of the
constant log(10) = 2.302585.... This constant is needed by
Decimal.ln, Decimal.log10, Decimal.exp and Decimal.__pow__."""
def __init__(self):
self.digits = "23025850929940456840179914546843642076011014886"
def getdigits(self, p):
"""Given an integer p >= 0, return floor(10**p)*log(10).
For example, self.getdigits(3) returns 2302.
"""
# digits are stored as a string, for quick conversion to
# integer in the case that we've already computed enough
# digits; the stored digits should always be correct
# (truncated, not rounded to nearest).
if p < 0:
raise ValueError("p should be nonnegative")
if p >= len(self.digits):
# compute p+3, p+6, p+9, ... digits; continue until at
# least one of the extra digits is nonzero
extra = 3
while True:
# compute p+extra digits, correct to within 1ulp
M = 10**(p+extra+2)
digits = str(_div_nearest(_ilog(10*M, M), 100))
if digits[-extra:] != '0'*extra:
break
extra += 3
# keep all reliable digits so far; remove trailing zeros
# and next nonzero digit
self.digits = digits.rstrip('0')[:-1]
return int(self.digits[:p+1])
_log10_digits = _Log10Memoize().getdigits
def _iexp(x, M, L=8):
"""Given integers x and M, M > 0, such that x/M is small in absolute
value, compute an integer approximation to M*exp(x/M). For 0 <=
x/M <= 2.4, the absolute error in the result is bounded by 60 (and
is usually much smaller)."""
# Algorithm: to compute exp(z) for a real number z, first divide z
# by a suitable power R of 2 so that |z/2**R| < 2**-L. Then
# compute expm1(z/2**R) = exp(z/2**R) - 1 using the usual Taylor
# series
#
# expm1(x) = x + x**2/2! + x**3/3! + ...
#
# Now use the identity
#
# expm1(2x) = expm1(x)*(expm1(x)+2)
#
# R times to compute the sequence expm1(z/2**R),
# expm1(z/2**(R-1)), ... , exp(z/2), exp(z).
# Find R such that x/2**R/M <= 2**-L
R = _nbits((x<<L)//M)
# Taylor series. (2**L)**T > M
T = -int(-10*len(str(M))//(3*L))
y = _div_nearest(x, T)
Mshift = M<<R
for i in range(T-1, 0, -1):
y = _div_nearest(x*(Mshift + y), Mshift * i)
# Expansion
for k in range(R-1, -1, -1):
Mshift = M<<(k+2)
y = _div_nearest(y*(y+Mshift), Mshift)
return M+y
def _dexp(c, e, p):
"""Compute an approximation to exp(c*10**e), with p decimal places of
precision.
Returns integers d, f such that:
10**(p-1) <= d <= 10**p, and
(d-1)*10**f < exp(c*10**e) < (d+1)*10**f
In other words, d*10**f is an approximation to exp(c*10**e) with p
digits of precision, and with an error in d of at most 1. This is
almost, but not quite, the same as the error being < 1ulp: when d
= 10**(p-1) the error could be up to 10 ulp."""
# we'll call iexp with M = 10**(p+2), giving p+3 digits of precision
p += 2
# compute log(10) with extra precision = adjusted exponent of c*10**e
extra = max(0, e + len(str(c)) - 1)
q = p + extra
# compute quotient c*10**e/(log(10)) = c*10**(e+q)/(log(10)*10**q),
# rounding down
shift = e+q
if shift >= 0:
cshift = c*10**shift
else:
cshift = c//10**-shift
quot, rem = divmod(cshift, _log10_digits(q))
# reduce remainder back to original precision
rem = _div_nearest(rem, 10**extra)
# error in result of _iexp < 120; error after division < 0.62
return _div_nearest(_iexp(rem, 10**p), 1000), quot - p + 3
def _dpower(xc, xe, yc, ye, p):
"""Given integers xc, xe, yc and ye representing Decimals x = xc*10**xe and
y = yc*10**ye, compute x**y. Returns a pair of integers (c, e) such that:
10**(p-1) <= c <= 10**p, and
(c-1)*10**e < x**y < (c+1)*10**e
in other words, c*10**e is an approximation to x**y with p digits
of precision, and with an error in c of at most 1. (This is
almost, but not quite, the same as the error being < 1ulp: when c
== 10**(p-1) we can only guarantee error < 10ulp.)
We assume that: x is positive and not equal to 1, and y is nonzero.
"""
# Find b such that 10**(b-1) <= |y| <= 10**b
b = len(str(abs(yc))) + ye
# log(x) = lxc*10**(-p-b-1), to p+b+1 places after the decimal point
lxc = _dlog(xc, xe, p+b+1)
# compute product y*log(x) = yc*lxc*10**(-p-b-1+ye) = pc*10**(-p-1)
shift = ye-b
if shift >= 0:
pc = lxc*yc*10**shift
else:
pc = _div_nearest(lxc*yc, 10**-shift)
if pc == 0:
# we prefer a result that isn't exactly 1; this makes it
# easier to compute a correctly rounded result in __pow__
if ((len(str(xc)) + xe >= 1) == (yc > 0)): # if x**y > 1:
coeff, exp = 10**(p-1)+1, 1-p
else:
coeff, exp = 10**p-1, -p
else:
coeff, exp = _dexp(pc, -(p+1), p+1)
coeff = _div_nearest(coeff, 10)
exp += 1
return coeff, exp
def _log10_lb(c, correction = {
'1': 100, '2': 70, '3': 53, '4': 40, '5': 31,
'6': 23, '7': 16, '8': 10, '9': 5}):
"""Compute a lower bound for 100*log10(c) for a positive integer c."""
if c <= 0:
raise ValueError("The argument to _log10_lb should be nonnegative.")
str_c = str(c)
return 100*len(str_c) - correction[str_c[0]]
##### Helper Functions ####################################################
def _convert_other(other, raiseit=False, allow_float=False):
"""Convert other to Decimal.
Verifies that it's ok to use in an implicit construction.
If allow_float is true, allow conversion from float; this
is used in the comparison methods (__eq__ and friends).
"""
if isinstance(other, Decimal):
return other
if isinstance(other, int):
return Decimal(other)
if allow_float and isinstance(other, float):
return Decimal.from_float(other)
if raiseit:
raise TypeError("Unable to convert %s to Decimal" % other)
return NotImplemented
def _convert_for_comparison(self, other, equality_op=False):
"""Given a Decimal instance self and a Python object other, return
a pair (s, o) of Decimal instances such that "s op o" is
equivalent to "self op other" for any of the 6 comparison
operators "op".
"""
if isinstance(other, Decimal):
return self, other
# Comparison with a Rational instance (also includes integers):
# self op n/d <=> self*d op n (for n and d integers, d positive).
# A NaN or infinity can be left unchanged without affecting the
# comparison result.
if isinstance(other, _numbers.Rational):
if not self._is_special:
self = _dec_from_triple(self._sign,
str(int(self._int) * other.denominator),
self._exp)
return self, Decimal(other.numerator)
# Comparisons with float and complex types. == and != comparisons
# with complex numbers should succeed, returning either True or False
# as appropriate. Other comparisons return NotImplemented.
if equality_op and isinstance(other, _numbers.Complex) and other.imag == 0:
other = other.real
if isinstance(other, float):
context = getcontext()
if equality_op:
context.flags[FloatOperation] = 1
else:
context._raise_error(FloatOperation,
"strict semantics for mixing floats and Decimals are enabled")
return self, Decimal.from_float(other)
return NotImplemented, NotImplemented
##### Setup Specific Contexts ############################################
# The default context prototype used by Context()
# Is mutable, so that new contexts can have different default values
DefaultContext = Context(
prec=17, rounding=ROUND_HALF_EVEN,
traps=[DivisionByZero, Overflow, InvalidOperation],
flags=[],
Emax=308,
Emin=-324,
capitals=1,
clamp=0
)
# Pre-made alternate contexts offered by the specification
# Don't change these; the user should be able to select these
# contexts and be able to reproduce results from other implementations
# of the spec.
BasicContext = Context(
prec=9, rounding=ROUND_HALF_UP,
traps=[DivisionByZero, Overflow, InvalidOperation, Clamped, Underflow],
flags=[],
)
ExtendedContext = Context(
prec=9, rounding=ROUND_HALF_EVEN,
traps=[],
flags=[],
)
##### crud for parsing strings #############################################
#
# Regular expression used for parsing numeric strings. Additional
# comments:
#
# 1. Uncomment the two '\s*' lines to allow leading and/or trailing
# whitespace. But note that the specification disallows whitespace in
# a numeric string.
#
# 2. For finite numbers (not infinities and NaNs) the body of the
# number between the optional sign and the optional exponent must have
# at least one decimal digit, possibly after the decimal point. The
# lookahead expression '(?=\d|\.\d)' checks this.
#import re
#_parser = re.compile(r""" # A numeric string consists of:
# \s*
# (?P<sign>[-+])? # an optional sign, followed by either...
# (
# (?=\d|\.\d) # ...a number (with at least one digit)
# (?P<int>\d*) # having a (possibly empty) integer part
# (\.(?P<frac>\d*))? # followed by an optional fractional part
# (E(?P<exp>[-+]?\d+))? # followed by an optional exponent, or...
# |
# Inf(inity)? # ...an infinity, or...
# |
# (?P<signal>s)? # ...an (optionally signaling)
# NaN # NaN
# (?P<diag>\d*) # with (possibly empty) diagnostic info.
# )
# \s*
# \Z
#""", re.VERBOSE | re.IGNORECASE).match
import _jsre as re
_all_zeros = re.compile('0*$').match
_exact_half = re.compile('50*$').match
##### PEP3101 support functions ##############################################
# The functions in this section have little to do with the Decimal
# class, and could potentially be reused or adapted for other pure
# Python numeric classes that want to implement __format__
#
# A format specifier for Decimal looks like:
#
# [[fill]align][sign][#][0][minimumwidth][,][.precision][type]
#_parse_format_specifier_regex = re.compile(r"""\A
#(?:
# (?P<fill>.)?
# (?P<align>[<>=^])
#)?
#(?P<sign>[-+ ])?
#(?P<alt>\#)?
#(?P<zeropad>0)?
#(?P<minimumwidth>(?!0)\d+)?
#(?P<thousands_sep>,)?
#(?:\.(?P<precision>0|(?!0)\d+))?
#(?P<type>[eEfFgGn%])?
#\Z
#""", re.VERBOSE|re.DOTALL)
del re
# The locale module is only needed for the 'n' format specifier. The
# rest of the PEP 3101 code functions quite happily without it, so we
# don't care too much if locale isn't present.
try:
import locale as _locale
except ImportError:
pass
def _parse_format_specifier(format_spec, _localeconv=None):
"""Parse and validate a format specifier.
Turns a standard numeric format specifier into a dict, with the
following entries:
fill: fill character to pad field to minimum width
align: alignment type, either '<', '>', '=' or '^'
sign: either '+', '-' or ' '
minimumwidth: nonnegative integer giving minimum width
zeropad: boolean, indicating whether to pad with zeros
thousands_sep: string to use as thousands separator, or ''
grouping: grouping for thousands separators, in format
used by localeconv
decimal_point: string to use for decimal point
precision: nonnegative integer giving precision, or None
type: one of the characters 'eEfFgG%', or None
"""
m = _parse_format_specifier_regex.match(format_spec)
if m is None:
raise ValueError("Invalid format specifier: " + format_spec)
# get the dictionary
format_dict = m.groupdict()
# zeropad; defaults for fill and alignment. If zero padding
# is requested, the fill and align fields should be absent.
fill = format_dict['fill']
align = format_dict['align']
format_dict['zeropad'] = (format_dict['zeropad'] is not None)
if format_dict['zeropad']:
if fill is not None:
raise ValueError("Fill character conflicts with '0'"
" in format specifier: " + format_spec)
if align is not None:
raise ValueError("Alignment conflicts with '0' in "
"format specifier: " + format_spec)
format_dict['fill'] = fill or ' '
# PEP 3101 originally specified that the default alignment should
# be left; it was later agreed that right-aligned makes more sense
# for numeric types. See http://bugs.python.org/issue6857.
format_dict['align'] = align or '>'
# default sign handling: '-' for negative, '' for positive
if format_dict['sign'] is None:
format_dict['sign'] = '-'
# minimumwidth defaults to 0; precision remains None if not given
format_dict['minimumwidth'] = int(format_dict['minimumwidth'] or '0')
if format_dict['precision'] is not None:
format_dict['precision'] = int(format_dict['precision'])
# if format type is 'g' or 'G' then a precision of 0 makes little
# sense; convert it to 1. Same if format type is unspecified.
if format_dict['precision'] == 0:
if format_dict['type'] is None or format_dict['type'] in 'gGn':
format_dict['precision'] = 1
# determine thousands separator, grouping, and decimal separator, and
# add appropriate entries to format_dict
if format_dict['type'] == 'n':
# apart from separators, 'n' behaves just like 'g'
format_dict['type'] = 'g'
if _localeconv is None:
_localeconv = _locale.localeconv()
if format_dict['thousands_sep'] is not None:
raise ValueError("Explicit thousands separator conflicts with "
"'n' type in format specifier: " + format_spec)
format_dict['thousands_sep'] = _localeconv['thousands_sep']
format_dict['grouping'] = _localeconv['grouping']
format_dict['decimal_point'] = _localeconv['decimal_point']
else:
if format_dict['thousands_sep'] is None:
format_dict['thousands_sep'] = ''
format_dict['grouping'] = [3, 0]
format_dict['decimal_point'] = '.'
return format_dict
def _format_align(sign, body, spec):
"""Given an unpadded, non-aligned numeric string 'body' and sign
string 'sign', add padding and alignment conforming to the given
format specifier dictionary 'spec' (as produced by
parse_format_specifier).
"""
# how much extra space do we have to play with?
minimumwidth = spec['minimumwidth']
fill = spec['fill']
padding = fill*(minimumwidth - len(sign) - len(body))
align = spec['align']
if align == '<':
result = sign + body + padding
elif align == '>':
result = padding + sign + body
elif align == '=':
result = sign + padding + body
elif align == '^':
half = len(padding)//2
result = padding[:half] + sign + body + padding[half:]
else:
raise ValueError('Unrecognised alignment field')
return result
def _group_lengths(grouping):
"""Convert a localeconv-style grouping into a (possibly infinite)
iterable of integers representing group lengths.
"""
# The result from localeconv()['grouping'], and the input to this
# function, should be a list of integers in one of the
# following three forms:
#
# (1) an empty list, or
# (2) nonempty list of positive integers + [0]
# (3) list of positive integers + [locale.CHAR_MAX], or
from itertools import chain, repeat
if not grouping:
return []
elif grouping[-1] == 0 and len(grouping) >= 2:
return chain(grouping[:-1], repeat(grouping[-2]))
elif grouping[-1] == _locale.CHAR_MAX:
return grouping[:-1]
else:
raise ValueError('unrecognised format for grouping')
def _insert_thousands_sep(digits, spec, min_width=1):
"""Insert thousands separators into a digit string.
spec is a dictionary whose keys should include 'thousands_sep' and
'grouping'; typically it's the result of parsing the format
specifier using _parse_format_specifier.
The min_width keyword argument gives the minimum length of the
result, which will be padded on the left with zeros if necessary.
If necessary, the zero padding adds an extra '0' on the left to
avoid a leading thousands separator. For example, inserting
commas every three digits in '123456', with min_width=8, gives
'0,123,456', even though that has length 9.
"""
sep = spec['thousands_sep']
grouping = spec['grouping']
groups = []
for l in _group_lengths(grouping):
if l <= 0:
raise ValueError("group length should be positive")
# max(..., 1) forces at least 1 digit to the left of a separator
l = min(max(len(digits), min_width, 1), l)
groups.append('0'*(l - len(digits)) + digits[-l:])
digits = digits[:-l]
min_width -= l
if not digits and min_width <= 0:
break
min_width -= len(sep)
else:
l = max(len(digits), min_width, 1)
groups.append('0'*(l - len(digits)) + digits[-l:])
return sep.join(reversed(groups))
def _format_sign(is_negative, spec):
"""Determine sign character."""
if is_negative:
return '-'
elif spec['sign'] in ' +':
return spec['sign']
else:
return ''
def _format_number(is_negative, intpart, fracpart, exp, spec):
"""Format a number, given the following data:
is_negative: true if the number is negative, else false
intpart: string of digits that must appear before the decimal point
fracpart: string of digits that must come after the point
exp: exponent, as an integer
spec: dictionary resulting from parsing the format specifier
This function uses the information in spec to:
insert separators (decimal separator and thousands separators)
format the sign
format the exponent
add trailing '%' for the '%' type
zero-pad if necessary
fill and align if necessary
"""
sign = _format_sign(is_negative, spec)
if fracpart or spec['alt']:
fracpart = spec['decimal_point'] + fracpart
if exp != 0 or spec['type'] in 'eE':
echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']]
fracpart += "{0}{1:+}".format(echar, exp)
if spec['type'] == '%':
fracpart += '%'
if spec['zeropad']:
min_width = spec['minimumwidth'] - len(fracpart) - len(sign)
else:
min_width = 0
intpart = _insert_thousands_sep(intpart, spec, min_width)
return _format_align(sign, intpart+fracpart, spec)
##### Useful Constants (internal use only) ################################
# Reusable defaults
_Infinity = Decimal('Inf')
_NegativeInfinity = Decimal('-Inf')
_NaN = Decimal('NaN')
_Zero = Decimal(0)
_One = Decimal(1)
_NegativeOne = Decimal(-1)
# _SignedInfinity[sign] is infinity w/ that sign
_SignedInfinity = (_Infinity, _NegativeInfinity)
# Constants related to the hash implementation; hash(x) is based
# on the reduction of x modulo _PyHASH_MODULUS
_PyHASH_MODULUS = sys.hash_info.modulus
# hash values to use for positive and negative infinities, and nans
_PyHASH_INF = sys.hash_info.inf
_PyHASH_NAN = sys.hash_info.nan
# _PyHASH_10INV is the inverse of 10 modulo the prime _PyHASH_MODULUS
_PyHASH_10INV = pow(10, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
del sys
try:
import _decimal
except ImportError:
pass
else:
s1 = set(dir())
s2 = set(dir(_decimal))
for name in s1 - s2:
del globals()[name]
del s1, s2, name
from _decimal import *
if __name__ == '__main__':
import doctest, decimal
doctest.testmod(decimal)
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
8353,
2018,
2290,
2752,
14,
199,
3,
2900,
4481,
4644,
14,
199,
199,
3,
27694,
701,
662,
1567,
20276,
665,
69,
4777,
737,
307,
74,
4213,
270,
14,
8654,
30,
199,
3,
259,
436,
481,
645,
11833,
699,
2159,
1207,
665,
12668,
11833,
737,
20162,
2029,
2270,
14,
957,
14,
285,
30,
199,
3,
259,
436,
30703,
2106,
68,
869,
386,
1337,
281,
665,
1548,
737,
4819,
78,
14,
957,
30,
199,
3,
259,
436,
437,
11326,
90,
665,
2158,
19552,
737,
1115,
1977,
14,
957,
30,
199,
3,
259,
436,
26244,
11379,
878,
199,
199,
3,
961,
859,
1077,
506,
16204,
315,
7604,
543,
314,
8839,
7029,
402,
314,
199,
3,
26202,
8929,
465,
652,
325,
5650,
2310,
14,
221,
18049,
261,
7029,
911,
506,
10184,
199,
3,
465,
6519,
25079,
334,
271,
12337,
687,
314,
3158,
365,
282,
7163,
12,
2739,
3616,
199,
3,
6519,
9,
436,
911,
506,
1771,
2315,
14,
221,
2854,
642,
2376,
314,
3158,
365,
410,
25007,
20135,
199,
3,
436,
314,
7029,
787,
506,
7909,
27392,
12,
12700,
12,
436,
6656,
16474,
14,
199,
199,
624,
199,
2765,
365,
376,
4514,
402,
6107,
8402,
2376,
24166,
4079,
641,
199,
1589,
1696,
6345,
31153,
18764,
5367,
3477,
26,
339,
1455,
921,
12325,
274,
357,
11750,
14,
957,
15,
6355,
15,
271,
7007,
448,
14,
1360,
199,
199,
460,
473,
29146,
4465,
1695,
1477,
13,
30828,
26,
339,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
32692,
63,
31505,
13,
30828,
199,
199,
6745,
8402,
2376,
965,
21837,
7151,
543,
601,
2075,
82,
11406,
7031,
10461,
14,
199,
199,
1918,
12016,
402,
642,
859,
365,
370,
2291,
24166,
1808,
21450,
1638,
285,
199,
2,
23194,
6740,
2,
4713,
436,
370,
5126,
2005,
402,
314,
32553,
6025,
199,
10115,
4568,
543,
3366,
8402,
2376,
14,
221,
710,
2559,
365,
24002,
199,
1180,
1893,
367,
2583,
24409,
13103,
503,
367,
18191,
2382,
4390,
1172,
199,
15752,
626,
787,
737,
16699,
83,
543,
3366,
8402,
2376,
334,
509,
1256,
12,
199,
262,
3366,
8402,
2376,
12,
413,
14,
383,
450,
378,
14,
17,
10557,
378,
14,
16,
13453,
20036,
2720,
3140,
199,
1618,
378,
14,
16,
27,
6345,
360,
17,
14,
383,
358,
450,
6345,
360,
16,
14,
17,
358,
2529,
314,
1420,
199,
6745,
360,
16,
14,
383,
11103,
199,
199,
21741,
787,
2005,
7251,
402,
1808,
314,
6107,
859,
26,
199,
199,
6071,
687,
6107,
492,
627,
199,
6071,
663,
1100,
8,
14107,
2998,
9,
199,
6071,
6345,
8,
16,
9,
199,
6745,
360,
16,
358,
199,
6071,
6345,
360,
17,
358,
199,
6745,
360,
17,
358,
199,
6071,
6345,
3654,
14,
29555,
358,
199,
6745,
3654,
16,
14,
29555,
358,
199,
6071,
6345,
8,
19060,
9,
199,
6745,
360,
19060,
358,
199,
6071,
6345,
360,
4288,
14,
2322,
69,
19542,
358,
199,
6745,
360,
17,
14,
5533,
21,
37,
11,
19060,
1257,
358,
199,
6071,
6345,
360,
17,
14,
1153,
358,
435,
6345,
360,
17,
14,
1465,
358,
199,
6745,
360,
18,
14,
2259,
358,
199,
6071,
6345,
360,
713,
14,
1082,
358,
435,
6345,
360,
19,
14,
1555,
358,
446,
6345,
360,
1085,
14,
2953,
358,
199,
6745,
3654,
18,
14,
1165,
358,
199,
6071,
31190,
275,
6345,
8,
17,
9,
199,
6071,
870,
8,
18367,
1182,
6345,
8,
19,
430,
199,
16,
14,
15093,
19,
199,
6071,
664,
1100,
1252,
9218,
275,
6155,
199,
6071,
870,
8,
18367,
1182,
6345,
8,
19,
430,
199,
16,
14,
15093,
15093,
1153,
199,
6071,
870,
8,
18367,
14,
5079,
1012,
199,
17,
199,
6071,
870,
8,
6745,
8,
19,
680,
5079,
1012,
199,
17,
14,
23,
12122,
1400,
11369,
1367,
1299,
1138,
1398,
199,
6071,
870,
8,
6745,
8,
19,
9,
1011,
11869,
9,
199,
20,
14,
2426,
1167,
1465,
11782,
2114,
1407,
772,
1465,
37,
11,
2010,
199,
6071,
10739,
275,
6345,
8,
17,
9,
1182,
6345,
8,
16,
9,
199,
6071,
870,
8,
4904,
9,
199,
14660,
199,
6071,
1279,
903,
70,
275,
6345,
2801,
17,
9,
1182,
6345,
8,
16,
9,
199,
6071,
870,
8,
685,
903,
70,
9,
199,
13,
14660,
199,
6071,
870,
8,
685,
903,
70,
435,
10739,
9,
199,
14300,
199,
6071,
870,
8,
685,
903,
70,
627,
10739,
9,
199,
13,
14660,
199,
6071,
870,
8,
18367,
1182,
378,
9,
199,
14660,
199,
6071,
664,
1100,
1252,
1239,
1190,
59,
16979,
2175,
8681,
61,
275,
413,
199,
6071,
870,
8,
18367,
1182,
378,
9,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
523,
2263,
523,
2263,
523,
2263,
199,
6355,
14,
16979,
2175,
8681,
26,
671,
1182,
378,
199,
6071,
286,
275,
9470,
342,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
16,
199,
6071,
286,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
430,
199,
6745,
360,
14300,
358,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
413,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
286,
14,
2469,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
16,
199,
6071,
870,
8,
67,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
1724,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
523,
2263,
523,
2263,
523,
2263,
199,
6355,
14,
27355,
26,
378,
1182,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
286,
14,
2469,
59,
27355,
61,
275,
378,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
1724,
199,
14300,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
199,
624,
199,
199,
363,
452,
363,
275,
359,
272,
327,
16853,
12160,
3992,
272,
283,
6745,
297,
283,
2998,
297,
339,
327,
9470,
83,
272,
283,
2698,
2998,
297,
283,
6845,
2998,
297,
283,
14107,
2998,
297,
339,
327,
24873,
272,
283,
6745,
1726,
297,
283,
12086,
311,
379,
297,
283,
27355,
297,
283,
16979,
2175,
8681,
297,
272,
283
] |
[
1898,
334,
67,
9,
8353,
2018,
2290,
2752,
14,
199,
3,
2900,
4481,
4644,
14,
199,
199,
3,
27694,
701,
662,
1567,
20276,
665,
69,
4777,
737,
307,
74,
4213,
270,
14,
8654,
30,
199,
3,
259,
436,
481,
645,
11833,
699,
2159,
1207,
665,
12668,
11833,
737,
20162,
2029,
2270,
14,
957,
14,
285,
30,
199,
3,
259,
436,
30703,
2106,
68,
869,
386,
1337,
281,
665,
1548,
737,
4819,
78,
14,
957,
30,
199,
3,
259,
436,
437,
11326,
90,
665,
2158,
19552,
737,
1115,
1977,
14,
957,
30,
199,
3,
259,
436,
26244,
11379,
878,
199,
199,
3,
961,
859,
1077,
506,
16204,
315,
7604,
543,
314,
8839,
7029,
402,
314,
199,
3,
26202,
8929,
465,
652,
325,
5650,
2310,
14,
221,
18049,
261,
7029,
911,
506,
10184,
199,
3,
465,
6519,
25079,
334,
271,
12337,
687,
314,
3158,
365,
282,
7163,
12,
2739,
3616,
199,
3,
6519,
9,
436,
911,
506,
1771,
2315,
14,
221,
2854,
642,
2376,
314,
3158,
365,
410,
25007,
20135,
199,
3,
436,
314,
7029,
787,
506,
7909,
27392,
12,
12700,
12,
436,
6656,
16474,
14,
199,
199,
624,
199,
2765,
365,
376,
4514,
402,
6107,
8402,
2376,
24166,
4079,
641,
199,
1589,
1696,
6345,
31153,
18764,
5367,
3477,
26,
339,
1455,
921,
12325,
274,
357,
11750,
14,
957,
15,
6355,
15,
271,
7007,
448,
14,
1360,
199,
199,
460,
473,
29146,
4465,
1695,
1477,
13,
30828,
26,
339,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
32692,
63,
31505,
13,
30828,
199,
199,
6745,
8402,
2376,
965,
21837,
7151,
543,
601,
2075,
82,
11406,
7031,
10461,
14,
199,
199,
1918,
12016,
402,
642,
859,
365,
370,
2291,
24166,
1808,
21450,
1638,
285,
199,
2,
23194,
6740,
2,
4713,
436,
370,
5126,
2005,
402,
314,
32553,
6025,
199,
10115,
4568,
543,
3366,
8402,
2376,
14,
221,
710,
2559,
365,
24002,
199,
1180,
1893,
367,
2583,
24409,
13103,
503,
367,
18191,
2382,
4390,
1172,
199,
15752,
626,
787,
737,
16699,
83,
543,
3366,
8402,
2376,
334,
509,
1256,
12,
199,
262,
3366,
8402,
2376,
12,
413,
14,
383,
450,
378,
14,
17,
10557,
378,
14,
16,
13453,
20036,
2720,
3140,
199,
1618,
378,
14,
16,
27,
6345,
360,
17,
14,
383,
358,
450,
6345,
360,
16,
14,
17,
358,
2529,
314,
1420,
199,
6745,
360,
16,
14,
383,
11103,
199,
199,
21741,
787,
2005,
7251,
402,
1808,
314,
6107,
859,
26,
199,
199,
6071,
687,
6107,
492,
627,
199,
6071,
663,
1100,
8,
14107,
2998,
9,
199,
6071,
6345,
8,
16,
9,
199,
6745,
360,
16,
358,
199,
6071,
6345,
360,
17,
358,
199,
6745,
360,
17,
358,
199,
6071,
6345,
3654,
14,
29555,
358,
199,
6745,
3654,
16,
14,
29555,
358,
199,
6071,
6345,
8,
19060,
9,
199,
6745,
360,
19060,
358,
199,
6071,
6345,
360,
4288,
14,
2322,
69,
19542,
358,
199,
6745,
360,
17,
14,
5533,
21,
37,
11,
19060,
1257,
358,
199,
6071,
6345,
360,
17,
14,
1153,
358,
435,
6345,
360,
17,
14,
1465,
358,
199,
6745,
360,
18,
14,
2259,
358,
199,
6071,
6345,
360,
713,
14,
1082,
358,
435,
6345,
360,
19,
14,
1555,
358,
446,
6345,
360,
1085,
14,
2953,
358,
199,
6745,
3654,
18,
14,
1165,
358,
199,
6071,
31190,
275,
6345,
8,
17,
9,
199,
6071,
870,
8,
18367,
1182,
6345,
8,
19,
430,
199,
16,
14,
15093,
19,
199,
6071,
664,
1100,
1252,
9218,
275,
6155,
199,
6071,
870,
8,
18367,
1182,
6345,
8,
19,
430,
199,
16,
14,
15093,
15093,
1153,
199,
6071,
870,
8,
18367,
14,
5079,
1012,
199,
17,
199,
6071,
870,
8,
6745,
8,
19,
680,
5079,
1012,
199,
17,
14,
23,
12122,
1400,
11369,
1367,
1299,
1138,
1398,
199,
6071,
870,
8,
6745,
8,
19,
9,
1011,
11869,
9,
199,
20,
14,
2426,
1167,
1465,
11782,
2114,
1407,
772,
1465,
37,
11,
2010,
199,
6071,
10739,
275,
6345,
8,
17,
9,
1182,
6345,
8,
16,
9,
199,
6071,
870,
8,
4904,
9,
199,
14660,
199,
6071,
1279,
903,
70,
275,
6345,
2801,
17,
9,
1182,
6345,
8,
16,
9,
199,
6071,
870,
8,
685,
903,
70,
9,
199,
13,
14660,
199,
6071,
870,
8,
685,
903,
70,
435,
10739,
9,
199,
14300,
199,
6071,
870,
8,
685,
903,
70,
627,
10739,
9,
199,
13,
14660,
199,
6071,
870,
8,
18367,
1182,
378,
9,
199,
14660,
199,
6071,
664,
1100,
1252,
1239,
1190,
59,
16979,
2175,
8681,
61,
275,
413,
199,
6071,
870,
8,
18367,
1182,
378,
9,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
523,
2263,
523,
2263,
523,
2263,
199,
6355,
14,
16979,
2175,
8681,
26,
671,
1182,
378,
199,
6071,
286,
275,
9470,
342,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
16,
199,
6071,
286,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
430,
199,
6745,
360,
14300,
358,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
413,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
286,
14,
2469,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
16,
199,
6071,
870,
8,
67,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
1724,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
523,
2263,
523,
2263,
523,
2263,
199,
6355,
14,
27355,
26,
378,
1182,
378,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
286,
14,
2469,
59,
27355,
61,
275,
378,
199,
6071,
286,
14,
1239,
1190,
59,
27355,
61,
275,
378,
199,
6071,
870,
8,
67,
14,
16081,
8,
6745,
8,
16,
395,
6345,
8,
16,
1724,
199,
14300,
199,
6071,
870,
8,
67,
14,
2469,
59,
27355,
566,
199,
17,
199,
6071,
199,
624,
199,
199,
363,
452,
363,
275,
359,
272,
327,
16853,
12160,
3992,
272,
283,
6745,
297,
283,
2998,
297,
339,
327,
9470,
83,
272,
283,
2698,
2998,
297,
283,
6845,
2998,
297,
283,
14107,
2998,
297,
339,
327,
24873,
272,
283,
6745,
1726,
297,
283,
12086,
311,
379,
297,
283,
27355,
297,
283,
16979,
2175,
8681,
297,
272,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
GameTechDev/PresentMon
|
Tests/googletest/googletest/scripts/common.py
|
1180
|
2919
|
# Copyright 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.
"""Shared utilities for writing scripts for Google Test/Mock."""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
# Matches the line from 'svn info .' output that describes what SVN
# path the current local directory corresponds to. For example, in
# a googletest SVN workspace's trunk/test directory, the output will be:
#
# URL: https://googletest.googlecode.com/svn/trunk/test
_SVN_INFO_URL_RE = re.compile(r'^URL: https://(\w+)\.googlecode\.com/svn(.*)')
def GetCommandOutput(command):
"""Runs the shell command and returns its stdout as a list of lines."""
f = os.popen(command, 'r')
lines = [line.strip() for line in f.readlines()]
f.close()
return lines
def GetSvnInfo():
"""Returns the project name and the current SVN workspace's root path."""
for line in GetCommandOutput('svn info .'):
m = _SVN_INFO_URL_RE.match(line)
if m:
project = m.group(1) # googletest or googlemock
rel_path = m.group(2)
root = os.path.realpath(rel_path.count('/') * '../')
return project, root
return None, None
def GetSvnTrunk():
"""Returns the current SVN workspace's trunk root path."""
_, root = GetSvnInfo()
return root + '/trunk' if root else None
def IsInGTestSvn():
project, _ = GetSvnInfo()
return project == 'googletest'
def IsInGMockSvn():
project, _ = GetSvnInfo()
return project == 'googlemock'
|
mit
|
[
3,
1898,
6171,
4475,
3277,
14,
2900,
5924,
5702,
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,
624,
12197,
15841,
367,
3575,
10554,
367,
4475,
1379,
15,
3346,
1041,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
421,
199,
646,
747,
199,
646,
295,
421,
199,
3,
21682,
314,
1004,
687,
283,
6836,
2256,
1275,
7,
1072,
626,
23369,
4052,
24639,
199,
3,
931,
314,
1453,
2257,
2082,
13718,
370,
14,
221,
2104,
2893,
12,
315,
199,
3,
282,
31141,
24639,
14466,
1159,
24764,
15,
396,
2082,
12,
314,
1072,
911,
506,
26,
199,
3,
199,
3,
2851,
26,
4178,
921,
3098,
396,
14,
31864,
14,
957,
15,
6836,
15,
13409,
15,
396,
199,
63,
31222,
63,
4531,
63,
2632,
63,
907,
275,
295,
14,
2014,
8,
82,
4289,
2632,
26,
4178,
921,
2961,
87,
13439,
14,
31864,
4537,
957,
15,
6836,
19276,
5942,
421,
199,
318,
2372,
3110,
2959,
8,
1531,
304,
523,
408,
16291,
314,
5218,
1414,
436,
2529,
2399,
3839,
465,
282,
769,
402,
2385,
1041,
819,
289,
275,
747,
14,
12207,
8,
1531,
12,
283,
82,
358,
523,
2385,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
289,
14,
9684,
5106,
523,
289,
14,
1600,
342,
523,
372,
2385,
421,
199,
318,
2372,
51,
6002,
2354,
837,
523,
408,
3407,
314,
2199,
536,
436,
314,
1453,
24639,
14466,
1159,
1738,
931,
1041,
819,
367,
1004,
315,
2372,
3110,
2959,
360,
6836,
2256,
1275,
735,
272,
333,
275,
485,
31222,
63,
4531,
63,
2632,
63,
907,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
489,
2199,
275,
333,
14,
923,
8,
17,
9,
221,
327,
31141,
503,
6233,
1805,
489,
4668,
63,
515,
275,
333,
14,
923,
8,
18,
9,
489,
1738,
275,
747,
14,
515,
14,
11091,
8,
3369,
63,
515,
14,
835,
7825,
627,
20644,
358,
489,
372,
2199,
12,
1738,
819,
372,
488,
12,
488,
421,
199,
318,
2372,
51,
6002,
20460,
75,
837,
523,
408,
3407,
314,
1453,
24639,
14466,
1159,
24764,
1738,
931,
1041,
819,
5501,
1738,
275,
2372,
51,
6002,
2354,
342,
523,
372,
1738,
435,
1994,
13409,
7,
340,
1738,
587,
488,
421,
199,
318,
6596,
607,
39,
774,
51,
6002,
837,
523,
2199,
12,
485,
275,
2372,
51,
6002,
2354,
342,
523,
372,
2199,
508,
283,
3098,
396,
7,
421,
199,
318,
6596,
607,
39,
3346,
51,
6002,
837,
523,
2199,
12,
485,
275,
2372,
51,
6002,
2354,
342,
523,
372,
2199,
508,
283,
3098,
1805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
4475,
3277,
14,
2900,
5924,
5702,
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,
624,
12197,
15841,
367,
3575,
10554,
367,
4475,
1379,
15,
3346,
1041,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
421,
199,
646,
747,
199,
646,
295,
421,
199,
3,
21682,
314,
1004,
687,
283,
6836,
2256,
1275,
7,
1072,
626,
23369,
4052,
24639,
199,
3,
931,
314,
1453,
2257,
2082,
13718,
370,
14,
221,
2104,
2893,
12,
315,
199,
3,
282,
31141,
24639,
14466,
1159,
24764,
15,
396,
2082,
12,
314,
1072,
911,
506,
26,
199,
3,
199,
3,
2851,
26,
4178,
921,
3098,
396,
14,
31864,
14,
957,
15,
6836,
15,
13409,
15,
396,
199,
63,
31222,
63,
4531,
63,
2632,
63,
907,
275,
295,
14,
2014,
8,
82,
4289,
2632,
26,
4178,
921,
2961,
87,
13439,
14,
31864,
4537,
957,
15,
6836,
19276,
5942,
421,
199,
318,
2372,
3110,
2959,
8,
1531,
304,
523,
408,
16291,
314,
5218,
1414,
436,
2529,
2399,
3839,
465,
282,
769,
402,
2385,
1041,
819,
289,
275,
747,
14,
12207,
8,
1531,
12,
283,
82,
358,
523,
2385,
275,
359,
604,
14,
1913,
342,
367,
1004,
315,
289,
14,
9684,
5106,
523,
289,
14,
1600,
342,
523,
372,
2385,
421,
199,
318,
2372,
51,
6002,
2354,
837,
523,
408,
3407,
314,
2199,
536,
436,
314,
1453,
24639,
14466,
1159,
1738,
931,
1041,
819,
367,
1004,
315,
2372,
3110,
2959,
360,
6836,
2256,
1275,
735,
272,
333,
275,
485,
31222,
63,
4531,
63,
2632,
63,
907,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
489,
2199,
275,
333,
14,
923,
8,
17,
9,
221,
327,
31141,
503,
6233,
1805,
489,
4668,
63,
515,
275,
333,
14,
923,
8,
18,
9,
489,
1738,
275,
747,
14,
515,
14,
11091,
8,
3369,
63,
515,
14,
835,
7825,
627,
20644,
358,
489,
372,
2199,
12,
1738,
819,
372,
488,
12,
488,
421,
199,
318,
2372,
51,
6002,
20460,
75,
837,
523,
408,
3407,
314,
1453,
24639,
14466,
1159,
24764,
1738,
931,
1041,
819,
5501,
1738,
275,
2372,
51,
6002,
2354,
342,
523,
372,
1738,
435,
1994,
13409,
7,
340,
1738,
587,
488,
421,
199,
318,
6596,
607,
39,
774,
51,
6002,
837,
523,
2199,
12,
485,
275,
2372,
51,
6002,
2354,
342,
523,
372,
2199,
508,
283,
3098,
396,
7,
421,
199,
318,
6596,
607,
39,
3346,
51,
6002,
837,
523,
2199,
12,
485,
275,
2372,
51,
6002,
2354,
342,
523,
372,
2199,
508,
283,
3098,
1805,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dmitriy0611/django
|
tests/admin_views/custom_has_permission_admin.py
|
380
|
1089
|
"""
A custom AdminSite for AdminViewPermissionsTest.test_login_has_permission().
"""
from __future__ import unicode_literals
from django.contrib import admin
from django.contrib.auth import get_permission_codename
from django.contrib.auth.forms import AuthenticationForm
from . import admin as base_admin, models
PERMISSION_NAME = 'admin_views.%s' % get_permission_codename('change', models.Article._meta)
class PermissionAdminAuthenticationForm(AuthenticationForm):
def confirm_login_allowed(self, user):
from django import forms
if not user.is_active or not (user.is_staff or user.has_perm(PERMISSION_NAME)):
raise forms.ValidationError('permission denied')
class HasPermissionAdmin(admin.AdminSite):
login_form = PermissionAdminAuthenticationForm
def has_permission(self, request):
return (
request.user.is_active and
(request.user.is_staff or request.user.has_perm(PERMISSION_NAME))
)
site = HasPermissionAdmin(name="has_permission_admin")
site.register(models.Article, base_admin.ArticleAdmin)
|
bsd-3-clause
|
[
624,
199,
33,
3537,
9516,
8972,
367,
9516,
2768,
17004,
774,
14,
396,
63,
2886,
63,
1989,
63,
5693,
1252,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
5693,
63,
11879,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
15995,
2821,
199,
199,
504,
1275,
492,
4628,
465,
1300,
63,
2113,
12,
1709,
199,
199,
4227,
22320,
63,
2339,
275,
283,
2113,
63,
4196,
4111,
83,
7,
450,
664,
63,
5693,
63,
11879,
360,
1461,
297,
1709,
14,
7221,
423,
2024,
9,
421,
199,
533,
8779,
4880,
10348,
2821,
8,
10348,
2821,
304,
272,
347,
12679,
63,
2886,
63,
6541,
8,
277,
12,
922,
304,
267,
687,
1639,
492,
4513,
267,
340,
440,
922,
14,
374,
63,
2682,
503,
440,
334,
751,
14,
374,
63,
7018,
503,
922,
14,
1989,
63,
8220,
8,
4227,
22320,
63,
2339,
2298,
288,
746,
4513,
14,
8172,
360,
5693,
23355,
358,
421,
199,
533,
13481,
7980,
4880,
8,
2113,
14,
4880,
8972,
304,
272,
4676,
63,
964,
275,
8779,
4880,
10348,
2821,
339,
347,
965,
63,
5693,
8,
277,
12,
1056,
304,
267,
372,
334,
288,
1056,
14,
751,
14,
374,
63,
2682,
436,
288,
334,
1069,
14,
751,
14,
374,
63,
7018,
503,
1056,
14,
751,
14,
1989,
63,
8220,
8,
4227,
22320,
63,
2339,
430,
267,
776,
421,
199,
2124,
275,
13481,
7980,
4880,
8,
354,
628,
1989,
63,
5693,
63,
2113,
531,
199,
2124,
14,
2683,
8,
992,
14,
7221,
12,
1300,
63,
2113,
14,
7221,
4880,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
33,
3537,
9516,
8972,
367,
9516,
2768,
17004,
774,
14,
396,
63,
2886,
63,
1989,
63,
5693,
1252,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
5693,
63,
11879,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
15995,
2821,
199,
199,
504,
1275,
492,
4628,
465,
1300,
63,
2113,
12,
1709,
199,
199,
4227,
22320,
63,
2339,
275,
283,
2113,
63,
4196,
4111,
83,
7,
450,
664,
63,
5693,
63,
11879,
360,
1461,
297,
1709,
14,
7221,
423,
2024,
9,
421,
199,
533,
8779,
4880,
10348,
2821,
8,
10348,
2821,
304,
272,
347,
12679,
63,
2886,
63,
6541,
8,
277,
12,
922,
304,
267,
687,
1639,
492,
4513,
267,
340,
440,
922,
14,
374,
63,
2682,
503,
440,
334,
751,
14,
374,
63,
7018,
503,
922,
14,
1989,
63,
8220,
8,
4227,
22320,
63,
2339,
2298,
288,
746,
4513,
14,
8172,
360,
5693,
23355,
358,
421,
199,
533,
13481,
7980,
4880,
8,
2113,
14,
4880,
8972,
304,
272,
4676,
63,
964,
275,
8779,
4880,
10348,
2821,
339,
347,
965,
63,
5693,
8,
277,
12,
1056,
304,
267,
372,
334,
288,
1056,
14,
751,
14,
374,
63,
2682,
436,
288,
334,
1069,
14,
751,
14,
374,
63,
7018,
503,
1056,
14,
751,
14,
1989,
63,
8220,
8,
4227,
22320,
63,
2339,
430,
267,
776,
421,
199,
2124,
275,
13481,
7980,
4880,
8,
354,
628,
1989,
63,
5693,
63,
2113,
531,
199,
2124,
14,
2683,
8,
992,
14,
7221,
12,
1300,
63,
2113,
14,
7221,
4880,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
import datetime
import json
import logging
from django.conf import settings
from xmodule.open_ended_grading_classes import peer_grading_service
from xmodule.open_ended_grading_classes.controller_query_service import ControllerQueryService
from courseware.access import has_access
from edxmako.shortcuts import render_to_string
from student.models import unique_id_for_user
from util.cache import cache
from .staff_grading_service import StaffGradingService
log = logging.getLogger(__name__)
NOTIFICATION_CACHE_TIME = 300
KEY_PREFIX = "open_ended_"
NOTIFICATION_TYPES = (
('student_needs_to_peer_grade', 'peer_grading', 'Peer Grading'),
('staff_needs_to_grade', 'staff_grading', 'Staff Grading'),
('new_student_grading_to_view', 'open_ended_problems', 'Problems you have submitted'),
('flagged_submissions_exist', 'open_ended_flagged_problems', 'Flagged Submissions')
)
def staff_grading_notifications(course, user):
staff_gs = StaffGradingService(settings.OPEN_ENDED_GRADING_INTERFACE)
pending_grading = False
img_path = ""
course_id = course.id
student_id = unique_id_for_user(user)
notification_type = "staff"
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
try:
notifications = json.loads(staff_gs.get_notifications(course_id))
if notifications['success']:
if notifications['staff_needs_to_grade']:
pending_grading = True
except:
#Non catastrophic error, so no real action
notifications = {}
#This is a dev_facing_error
log.info(
"Problem with getting notifications from staff grading service for course {0} user {1}.".format(course_id,
student_id))
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {'pending_grading': pending_grading, 'img_path': img_path, 'response': notifications}
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
def peer_grading_notifications(course, user):
peer_gs = peer_grading_service.PeerGradingService(settings.OPEN_ENDED_GRADING_INTERFACE, render_to_string)
pending_grading = False
img_path = ""
course_id = course.id
student_id = unique_id_for_user(user)
notification_type = "peer"
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
try:
notifications = json.loads(peer_gs.get_notifications(course_id, student_id))
if notifications['success']:
if notifications['student_needs_to_peer_grade']:
pending_grading = True
except:
#Non catastrophic error, so no real action
notifications = {}
#This is a dev_facing_error
log.info(
"Problem with getting notifications from peer grading service for course {0} user {1}.".format(course_id,
student_id))
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {'pending_grading': pending_grading, 'img_path': img_path, 'response': notifications}
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
def combined_notifications(course, user):
"""
Show notifications to a given user for a given course. Get notifications from the cache if possible,
or from the grading controller server if not.
@param course: The course object for which we are getting notifications
@param user: The user object for which we are getting notifications
@return: A dictionary with boolean pending_grading (true if there is pending grading), img_path (for notification
image), and response (actual response from grading controller server).
"""
#Set up return values so that we can return them for error cases
pending_grading = False
img_path = ""
notifications = {}
notification_dict = {'pending_grading': pending_grading, 'img_path': img_path, 'response': notifications}
#We don't want to show anonymous users anything.
if not user.is_authenticated():
return notification_dict
#Initialize controller query service using our mock system
controller_qs = ControllerQueryService(settings.OPEN_ENDED_GRADING_INTERFACE, render_to_string)
student_id = unique_id_for_user(user)
user_is_staff = bool(has_access(user, 'staff', course))
course_id = course.id
notification_type = "combined"
#See if we have a stored value in the cache
success, notification_dict = get_value_from_cache(student_id, course_id, notification_type)
if success:
return notification_dict
#Get the time of the last login of the user
last_login = user.last_login
last_time_viewed = last_login - datetime.timedelta(seconds=(NOTIFICATION_CACHE_TIME + 60))
try:
#Get the notifications from the grading controller
notifications = controller_qs.check_combined_notifications(
course.id,
student_id,
user_is_staff,
last_time_viewed,
)
if notifications.get('success'):
if (notifications.get('staff_needs_to_grade') or
notifications.get('student_needs_to_peer_grade')):
pending_grading = True
except:
#Non catastrophic error, so no real action
#This is a dev_facing_error
log.exception(
u"Problem with getting notifications from controller query service for course {0} user {1}.".format(
course_id, student_id))
if pending_grading:
img_path = "/static/images/grading_notification.png"
notification_dict = {'pending_grading': pending_grading, 'img_path': img_path, 'response': notifications}
#Store the notifications in the cache
set_value_in_cache(student_id, course_id, notification_type, notification_dict)
return notification_dict
def get_value_from_cache(student_id, course_id, notification_type):
key_name = create_key_name(student_id, course_id, notification_type)
success, value = _get_value_from_cache(key_name)
return success, value
def set_value_in_cache(student_id, course_id, notification_type, value):
key_name = create_key_name(student_id, course_id, notification_type)
_set_value_in_cache(key_name, value)
def create_key_name(student_id, course_id, notification_type):
key_name = u"{prefix}{type}_{course}_{student}".format(
prefix=KEY_PREFIX,
type=notification_type,
course=course_id,
student=student_id,
)
return key_name
def _get_value_from_cache(key_name):
value = cache.get(key_name)
success = False
if value is None:
return success, value
try:
value = json.loads(value)
success = True
except:
pass
return success, value
def _set_value_in_cache(key_name, value):
cache.set(key_name, json.dumps(value), NOTIFICATION_CACHE_TIME)
|
agpl-3.0
|
[
646,
2197,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
492,
9104,
63,
16050,
63,
1364,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
5538,
63,
1131,
63,
1364,
492,
16282,
3227,
3167,
199,
199,
504,
20736,
14,
2732,
492,
965,
63,
2732,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
875,
199,
504,
6474,
14,
992,
492,
3747,
63,
344,
63,
509,
63,
751,
199,
504,
4884,
14,
1637,
492,
2581,
199,
199,
504,
1275,
7018,
63,
16050,
63,
1364,
492,
25910,
5761,
1098,
3167,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
22839,
2594,
63,
8677,
63,
4961,
275,
9601,
199,
3078,
63,
6351,
275,
298,
1490,
63,
8960,
12172,
199,
199,
22839,
2594,
63,
7893,
275,
334,
272,
661,
5500,
63,
10065,
63,
475,
63,
7866,
63,
4523,
297,
283,
7866,
63,
16050,
297,
283,
12566,
10268,
1098,
659,
272,
661,
7018,
63,
10065,
63,
475,
63,
4523,
297,
283,
7018,
63,
16050,
297,
283,
18963,
10268,
1098,
659,
272,
661,
1222,
63,
5500,
63,
16050,
63,
475,
63,
1345,
297,
283,
1490,
63,
8960,
63,
22959,
297,
283,
919,
7561,
1265,
1172,
16930,
659,
272,
661,
4173,
3046,
63,
29752,
63,
4494,
297,
283,
1490,
63,
8960,
63,
4173,
3046,
63,
22959,
297,
283,
5318,
3046,
4804,
2554,
358,
199,
9,
421,
199,
318,
12622,
63,
16050,
63,
12782,
8,
1972,
12,
922,
304,
272,
12622,
63,
458,
275,
25910,
5761,
1098,
3167,
8,
1751,
14,
9935,
63,
25518,
63,
3975,
1554,
1206,
63,
17598,
9,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
2518,
63,
344,
275,
2518,
14,
344,
272,
6474,
63,
344,
275,
3747,
63,
344,
63,
509,
63,
751,
8,
751,
9,
272,
6955,
63,
466,
275,
298,
7018,
2,
339,
3182,
12,
6955,
63,
807,
275,
664,
63,
585,
63,
504,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
9,
272,
340,
3182,
26,
267,
372,
6955,
63,
807,
339,
862,
26,
267,
13116,
275,
2022,
14,
3640,
8,
7018,
63,
458,
14,
362,
63,
12782,
8,
1972,
63,
344,
430,
267,
340,
13116,
459,
3742,
2565,
288,
340,
13116,
459,
7018,
63,
10065,
63,
475,
63,
4523,
2565,
355,
9413,
63,
16050,
275,
715,
272,
871,
26,
267,
327,
6932,
286,
419,
24627,
838,
530,
1125,
12,
880,
949,
3363,
1595,
267,
13116,
275,
1052,
267,
327,
2765,
365,
282,
4866,
63,
32552,
63,
705,
267,
943,
14,
815,
8,
288,
298,
16467,
543,
10232,
13116,
687,
12622,
22815,
2435,
367,
2518,
469,
16,
93,
922,
469,
17,
5565,
1674,
908,
8,
1972,
63,
344,
12,
12268,
14960,
6474,
63,
344,
430,
339,
340,
9413,
63,
16050,
26,
267,
6050,
63,
515,
275,
3286,
1986,
15,
4782,
15,
16050,
63,
6761,
14,
4524,
2,
339,
6955,
63,
807,
275,
791,
6455,
63,
16050,
356,
9413,
63,
16050,
12,
283,
4060,
63,
515,
356,
6050,
63,
515,
12,
283,
1310,
356,
13116,
93,
339,
663,
63,
585,
63,
262,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
12,
6955,
63,
807,
9,
339,
372,
6955,
63,
807,
421,
199,
318,
9104,
63,
16050,
63,
12782,
8,
1972,
12,
922,
304,
272,
9104,
63,
458,
275,
9104,
63,
16050,
63,
1364,
14,
12566,
5761,
1098,
3167,
8,
1751,
14,
9935,
63,
25518,
63,
3975,
1554,
1206,
63,
17598,
12,
3795,
63,
475,
63,
875,
9,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
2518,
63,
344,
275,
2518,
14,
344,
272,
6474,
63,
344,
275,
3747,
63,
344,
63,
509,
63,
751,
8,
751,
9,
272,
6955,
63,
466,
275,
298,
7866,
2,
339,
3182,
12,
6955,
63,
807,
275,
664,
63,
585,
63,
504,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
9,
272,
340,
3182,
26,
267,
372,
6955,
63,
807,
339,
862,
26,
267,
13116,
275,
2022,
14,
3640,
8,
7866,
63,
458,
14,
362,
63,
12782,
8,
1972,
63,
344,
12,
6474,
63,
344,
430,
267,
340,
13116,
459,
3742,
2565,
288,
340,
13116,
459,
5500,
63,
10065,
63,
475,
63,
7866,
63,
4523,
2565,
355,
9413,
63,
16050,
275,
715,
272,
871,
26,
267,
327,
6932,
286,
419,
24627,
838,
530,
1125,
12,
880,
949,
3363,
1595,
267,
13116,
275,
1052,
267,
327,
2765,
365,
282,
4866,
63,
32552,
63,
705,
267,
943,
14,
815,
8,
288,
298,
16467,
543,
10232,
13116,
687,
9104,
22815,
2435,
367,
2518,
469,
16,
93,
922,
469,
17,
5565,
1674,
908,
8,
1972,
63,
344,
12,
12268,
13235,
6474,
63,
344,
430,
272,
340,
9413,
63,
16050,
26,
267,
6050,
63,
515,
275,
3286,
1986,
15,
4782,
15,
16050,
63,
6761,
14,
4524,
2,
339,
6955,
63,
807,
275,
791,
6455,
63,
16050,
356,
9413,
63,
16050,
12,
283,
4060,
63,
515,
356,
6050,
63,
515,
12,
283,
1310,
356,
13116,
93,
339,
663,
63,
585,
63,
262,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
12,
6955,
63,
807,
9,
339,
372,
6955,
63,
807,
421,
199,
318,
12149,
63,
12782,
8,
1972,
12,
922,
304,
272,
408,
272,
12968,
13116,
370,
282,
1627,
922,
367,
282,
1627,
2518,
14,
221,
2372,
13116,
687,
314,
2581,
340,
3962,
12,
272,
503,
687,
314,
22815,
7614,
1654,
340,
440,
14,
272,
768,
635,
2518,
26,
710,
2518,
909,
367,
1314,
781,
787,
10232,
13116,
272,
768,
635,
922,
26,
710,
922,
909,
367,
1314,
781,
787,
10232,
13116,
272,
768,
1107,
26,
437,
2600,
543,
5046,
9413,
63,
16050,
334,
2052,
340,
2337,
365,
9413,
22815,
395,
6050,
63,
515,
334,
509,
6955,
272,
1834,
395,
436,
1177,
334,
6514,
1177,
687,
22815,
7614,
1654,
680,
272,
408,
272,
327,
1084,
1536,
372,
1338,
880,
626,
781,
883,
372,
3062,
367,
1125,
5560,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
13116,
275,
1052,
272,
6955,
63
] |
[
2197,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
492,
9104,
63,
16050,
63,
1364,
199,
504,
9872,
14,
1490,
63,
8960,
63,
16050,
63,
2888,
14,
5538,
63,
1131,
63,
1364,
492,
16282,
3227,
3167,
199,
199,
504,
20736,
14,
2732,
492,
965,
63,
2732,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
875,
199,
504,
6474,
14,
992,
492,
3747,
63,
344,
63,
509,
63,
751,
199,
504,
4884,
14,
1637,
492,
2581,
199,
199,
504,
1275,
7018,
63,
16050,
63,
1364,
492,
25910,
5761,
1098,
3167,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
22839,
2594,
63,
8677,
63,
4961,
275,
9601,
199,
3078,
63,
6351,
275,
298,
1490,
63,
8960,
12172,
199,
199,
22839,
2594,
63,
7893,
275,
334,
272,
661,
5500,
63,
10065,
63,
475,
63,
7866,
63,
4523,
297,
283,
7866,
63,
16050,
297,
283,
12566,
10268,
1098,
659,
272,
661,
7018,
63,
10065,
63,
475,
63,
4523,
297,
283,
7018,
63,
16050,
297,
283,
18963,
10268,
1098,
659,
272,
661,
1222,
63,
5500,
63,
16050,
63,
475,
63,
1345,
297,
283,
1490,
63,
8960,
63,
22959,
297,
283,
919,
7561,
1265,
1172,
16930,
659,
272,
661,
4173,
3046,
63,
29752,
63,
4494,
297,
283,
1490,
63,
8960,
63,
4173,
3046,
63,
22959,
297,
283,
5318,
3046,
4804,
2554,
358,
199,
9,
421,
199,
318,
12622,
63,
16050,
63,
12782,
8,
1972,
12,
922,
304,
272,
12622,
63,
458,
275,
25910,
5761,
1098,
3167,
8,
1751,
14,
9935,
63,
25518,
63,
3975,
1554,
1206,
63,
17598,
9,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
2518,
63,
344,
275,
2518,
14,
344,
272,
6474,
63,
344,
275,
3747,
63,
344,
63,
509,
63,
751,
8,
751,
9,
272,
6955,
63,
466,
275,
298,
7018,
2,
339,
3182,
12,
6955,
63,
807,
275,
664,
63,
585,
63,
504,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
9,
272,
340,
3182,
26,
267,
372,
6955,
63,
807,
339,
862,
26,
267,
13116,
275,
2022,
14,
3640,
8,
7018,
63,
458,
14,
362,
63,
12782,
8,
1972,
63,
344,
430,
267,
340,
13116,
459,
3742,
2565,
288,
340,
13116,
459,
7018,
63,
10065,
63,
475,
63,
4523,
2565,
355,
9413,
63,
16050,
275,
715,
272,
871,
26,
267,
327,
6932,
286,
419,
24627,
838,
530,
1125,
12,
880,
949,
3363,
1595,
267,
13116,
275,
1052,
267,
327,
2765,
365,
282,
4866,
63,
32552,
63,
705,
267,
943,
14,
815,
8,
288,
298,
16467,
543,
10232,
13116,
687,
12622,
22815,
2435,
367,
2518,
469,
16,
93,
922,
469,
17,
5565,
1674,
908,
8,
1972,
63,
344,
12,
12268,
14960,
6474,
63,
344,
430,
339,
340,
9413,
63,
16050,
26,
267,
6050,
63,
515,
275,
3286,
1986,
15,
4782,
15,
16050,
63,
6761,
14,
4524,
2,
339,
6955,
63,
807,
275,
791,
6455,
63,
16050,
356,
9413,
63,
16050,
12,
283,
4060,
63,
515,
356,
6050,
63,
515,
12,
283,
1310,
356,
13116,
93,
339,
663,
63,
585,
63,
262,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
12,
6955,
63,
807,
9,
339,
372,
6955,
63,
807,
421,
199,
318,
9104,
63,
16050,
63,
12782,
8,
1972,
12,
922,
304,
272,
9104,
63,
458,
275,
9104,
63,
16050,
63,
1364,
14,
12566,
5761,
1098,
3167,
8,
1751,
14,
9935,
63,
25518,
63,
3975,
1554,
1206,
63,
17598,
12,
3795,
63,
475,
63,
875,
9,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
2518,
63,
344,
275,
2518,
14,
344,
272,
6474,
63,
344,
275,
3747,
63,
344,
63,
509,
63,
751,
8,
751,
9,
272,
6955,
63,
466,
275,
298,
7866,
2,
339,
3182,
12,
6955,
63,
807,
275,
664,
63,
585,
63,
504,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
9,
272,
340,
3182,
26,
267,
372,
6955,
63,
807,
339,
862,
26,
267,
13116,
275,
2022,
14,
3640,
8,
7866,
63,
458,
14,
362,
63,
12782,
8,
1972,
63,
344,
12,
6474,
63,
344,
430,
267,
340,
13116,
459,
3742,
2565,
288,
340,
13116,
459,
5500,
63,
10065,
63,
475,
63,
7866,
63,
4523,
2565,
355,
9413,
63,
16050,
275,
715,
272,
871,
26,
267,
327,
6932,
286,
419,
24627,
838,
530,
1125,
12,
880,
949,
3363,
1595,
267,
13116,
275,
1052,
267,
327,
2765,
365,
282,
4866,
63,
32552,
63,
705,
267,
943,
14,
815,
8,
288,
298,
16467,
543,
10232,
13116,
687,
9104,
22815,
2435,
367,
2518,
469,
16,
93,
922,
469,
17,
5565,
1674,
908,
8,
1972,
63,
344,
12,
12268,
13235,
6474,
63,
344,
430,
272,
340,
9413,
63,
16050,
26,
267,
6050,
63,
515,
275,
3286,
1986,
15,
4782,
15,
16050,
63,
6761,
14,
4524,
2,
339,
6955,
63,
807,
275,
791,
6455,
63,
16050,
356,
9413,
63,
16050,
12,
283,
4060,
63,
515,
356,
6050,
63,
515,
12,
283,
1310,
356,
13116,
93,
339,
663,
63,
585,
63,
262,
63,
1637,
8,
5500,
63,
344,
12,
2518,
63,
344,
12,
6955,
63,
466,
12,
6955,
63,
807,
9,
339,
372,
6955,
63,
807,
421,
199,
318,
12149,
63,
12782,
8,
1972,
12,
922,
304,
272,
408,
272,
12968,
13116,
370,
282,
1627,
922,
367,
282,
1627,
2518,
14,
221,
2372,
13116,
687,
314,
2581,
340,
3962,
12,
272,
503,
687,
314,
22815,
7614,
1654,
340,
440,
14,
272,
768,
635,
2518,
26,
710,
2518,
909,
367,
1314,
781,
787,
10232,
13116,
272,
768,
635,
922,
26,
710,
922,
909,
367,
1314,
781,
787,
10232,
13116,
272,
768,
1107,
26,
437,
2600,
543,
5046,
9413,
63,
16050,
334,
2052,
340,
2337,
365,
9413,
22815,
395,
6050,
63,
515,
334,
509,
6955,
272,
1834,
395,
436,
1177,
334,
6514,
1177,
687,
22815,
7614,
1654,
680,
272,
408,
272,
327,
1084,
1536,
372,
1338,
880,
626,
781,
883,
372,
3062,
367,
1125,
5560,
272,
9413,
63,
16050,
275,
756,
272,
6050,
63,
515,
275,
3087,
272,
13116,
275,
1052,
272,
6955,
63,
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
1,
1
] |
bitmazk/django-good-practice-examples
|
setup.py
|
1
|
1406
|
import os
from setuptools import setup, find_packages
import good_practice_examples as app
def read(fname):
try:
return open(os.path.join(os.path.dirname(__file__), fname)).read()
except IOError:
return ''
dependency_links = [
# needs this dev version for django 1.6 fixes
'https://github.com/KristianOellegaard/django-hvad/tarball/0e2101f15404eaf9611cd6cf843bfc424117b227', # NOQA
]
setup(
name="django-good-practice-examples",
version=app.__version__,
description=read('DESCRIPTION'),
long_description=read('README.rst'),
license='The MIT License',
platforms=['OS Independent'],
keywords='django, good, practice, examples, list, display',
author='Daniel Kaufhold',
author_email='daniel.kaufhold@bitmazk.com',
url="https://github.com/bitmazk/django-good-practice-examples",
packages=find_packages(),
include_package_data=True,
install_requires=[
'Django',
'South',
'django-libs',
'Pillow',
'djangocms_utils',
'django-countries',
'django-multilingual-news',
],
dependency_links=dependency_links,
tests_require=[
'fabric',
'factory_boy',
'django-nose',
'coverage',
'django-coverage',
'mock',
'flake8',
'ipdb',
],
test_suite='good_practice_examples.tests.runtests.runtests',
)
|
mit
|
[
646,
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
646,
6954,
63,
80,
6457,
3548,
63,
8589,
465,
1145,
421,
199,
318,
1586,
8,
5252,
304,
272,
862,
26,
267,
372,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
6748,
4992,
739,
342,
272,
871,
5925,
26,
267,
372,
2125,
421,
199,
8575,
63,
4614,
275,
359,
272,
327,
4839,
642,
4866,
1015,
367,
1639,
413,
14,
22,
25079,
272,
283,
2859,
921,
5031,
14,
957,
15,
43,
18824,
5653,
47,
352,
4170,
65,
1005,
15,
1176,
13,
22926,
350,
15,
18829,
15,
16,
69,
2025,
614,
70,
1046,
5188,
69,
2756,
2534,
845,
2866,
22,
2177,
14349,
66,
3003,
21089,
7362,
66,
11385,
297,
221,
327,
20432,
199,
61,
421,
199,
2758,
8,
272,
536,
628,
1176,
13,
8302,
13,
80,
6457,
3548,
13,
8589,
401,
272,
1015,
29,
571,
855,
1023,
3108,
272,
1369,
29,
739,
360,
17705,
659,
272,
1846,
63,
1802,
29,
739,
360,
18195,
14,
8332,
659,
272,
4190,
534,
1918,
10697,
844,
297,
272,
10677,
2968,
3100,
1010,
7106,
995,
272,
7681,
534,
1176,
12,
6954,
12,
24471,
12,
7251,
12,
769,
12,
2929,
297,
272,
4132,
534,
29336,
14769,
1804,
65,
1286,
12239,
297,
272,
4132,
63,
2123,
534,
24863,
14769,
14,
7351,
1286,
12239,
32,
2075,
391,
20344,
14,
957,
297,
272,
1166,
628,
2859,
921,
5031,
14,
957,
15,
2075,
391,
20344,
15,
1176,
13,
8302,
13,
80,
6457,
3548,
13,
8589,
401,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
1524,
267,
283,
9323,
297,
267,
283,
30534,
297,
267,
283,
1176,
13,
8450,
297,
267,
283,
48,
382,
674,
297,
267,
283,
12816,
679,
706,
63,
1208,
297,
267,
283,
1176,
13,
23598,
297,
267,
283,
1176,
13,
3029,
2983,
1061,
13,
13224,
297,
272,
2156,
272,
5936,
63,
4614,
29,
8575,
63,
4614,
12,
272,
2295,
63,
4365,
1524,
267,
283,
4991,
297,
267,
283,
3702,
63,
656,
89,
297,
267,
283,
1176,
13,
21085,
297,
267,
283,
10828,
297,
267,
283,
1176,
13,
10828,
297,
267,
283,
1805,
297,
267,
283,
14163,
415,
24,
297,
267,
283,
711,
697,
297,
272,
2156,
272,
511,
63,
5768,
534,
8302,
63,
80,
6457,
3548,
63,
8589,
14,
2219,
14,
1065,
2219,
14,
1065,
2219,
297,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
646,
6954,
63,
80,
6457,
3548,
63,
8589,
465,
1145,
421,
199,
318,
1586,
8,
5252,
304,
272,
862,
26,
267,
372,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
6748,
4992,
739,
342,
272,
871,
5925,
26,
267,
372,
2125,
421,
199,
8575,
63,
4614,
275,
359,
272,
327,
4839,
642,
4866,
1015,
367,
1639,
413,
14,
22,
25079,
272,
283,
2859,
921,
5031,
14,
957,
15,
43,
18824,
5653,
47,
352,
4170,
65,
1005,
15,
1176,
13,
22926,
350,
15,
18829,
15,
16,
69,
2025,
614,
70,
1046,
5188,
69,
2756,
2534,
845,
2866,
22,
2177,
14349,
66,
3003,
21089,
7362,
66,
11385,
297,
221,
327,
20432,
199,
61,
421,
199,
2758,
8,
272,
536,
628,
1176,
13,
8302,
13,
80,
6457,
3548,
13,
8589,
401,
272,
1015,
29,
571,
855,
1023,
3108,
272,
1369,
29,
739,
360,
17705,
659,
272,
1846,
63,
1802,
29,
739,
360,
18195,
14,
8332,
659,
272,
4190,
534,
1918,
10697,
844,
297,
272,
10677,
2968,
3100,
1010,
7106,
995,
272,
7681,
534,
1176,
12,
6954,
12,
24471,
12,
7251,
12,
769,
12,
2929,
297,
272,
4132,
534,
29336,
14769,
1804,
65,
1286,
12239,
297,
272,
4132,
63,
2123,
534,
24863,
14769,
14,
7351,
1286,
12239,
32,
2075,
391,
20344,
14,
957,
297,
272,
1166,
628,
2859,
921,
5031,
14,
957,
15,
2075,
391,
20344,
15,
1176,
13,
8302,
13,
80,
6457,
3548,
13,
8589,
401,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
1524,
267,
283,
9323,
297,
267,
283,
30534,
297,
267,
283,
1176,
13,
8450,
297,
267,
283,
48,
382,
674,
297,
267,
283,
12816,
679,
706,
63,
1208,
297,
267,
283,
1176,
13,
23598,
297,
267,
283,
1176,
13,
3029,
2983,
1061,
13,
13224,
297,
272,
2156,
272,
5936,
63,
4614,
29,
8575,
63,
4614,
12,
272,
2295,
63,
4365,
1524,
267,
283,
4991,
297,
267,
283,
3702,
63,
656,
89,
297,
267,
283,
1176,
13,
21085,
297,
267,
283,
10828,
297,
267,
283,
1176,
13,
10828,
297,
267,
283,
1805,
297,
267,
283,
14163,
415,
24,
297,
267,
283,
711,
697,
297,
272,
2156,
272,
511,
63,
5768,
534,
8302,
63,
80,
6457,
3548,
63,
8589,
14,
2219,
14,
1065,
2219,
14,
1065,
2219,
297,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
manisandro/QGIS
|
python/plugins/processing/algs/gdal/tri.py
|
4
|
4593
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
tri.py
---------------------
Date : October 2013
Copyright : (C) 2013 by Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Alexander Bruy'
__date__ = 'October 2013'
__copyright__ = '(C) 2013, Alexander Bruy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
from qgis.core import (QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterString,
QgsProcessingParameterBoolean,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
class tri(GdalAlgorithm):
INPUT = 'INPUT'
BAND = 'BAND'
COMPUTE_EDGES = 'COMPUTE_EDGES'
OPTIONS = 'OPTIONS'
OUTPUT = 'OUTPUT'
def __init__(self):
super().__init__()
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterBand(self.BAND,
self.tr('Band number'),
1,
parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterBoolean(self.COMPUTE_EDGES,
self.tr('Compute edges'),
defaultValue=False))
options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
optional=True)
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
options_param.setMetadata({
'widget_wrapper': {
'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
self.addParameter(options_param)
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Terrain Ruggedness Index')))
def name(self):
return 'triterrainruggednessindex'
def displayName(self):
return self.tr('Terrain Ruggedness Index (TRI)')
def group(self):
return self.tr('Raster analysis')
def groupId(self):
return 'rasteranalysis'
def commandName(self):
return 'gdaldem'
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['TRI']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
arguments.append(inLayer.source())
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)
arguments.append('-b')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
if self.parameterAsBoolean(parameters, self.COMPUTE_EDGES, context):
arguments.append('-compute_edges')
options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
3229,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
18365,
22459,
6171,
272,
1898,
3322,
520,
334,
35,
9,
6171,
701,
22986,
11438,
699,
6558,
89,
272,
11426,
4483,
520,
282,
3113,
11438,
6308,
330,
6558,
89,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
33,
3113,
11438,
699,
6558,
89,
7,
199,
363,
602,
363,
275,
283,
17584,
22459,
6171,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6171,
12,
22986,
11438,
699,
6558,
89,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
28559,
1726,
12,
2432,
23764,
10701,
12,
2432,
23764,
13284,
5003,
12,
2432,
23764,
11675,
12,
2432,
23764,
1558,
12,
2432,
23764,
4082,
12,
2432,
23764,
13284,
13151,
9,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
11057,
16,
61,
421,
199,
533,
3229,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
699,
3649,
275,
283,
23297,
7,
272,
16503,
4586,
63,
1149,
39,
654,
275,
283,
6790,
4586,
63,
1149,
39,
654,
7,
272,
23860,
275,
283,
8808,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
339,
347,
4205,
11570,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
13284,
5003,
8,
277,
14,
7321,
12,
291,
14,
454,
360,
3205,
4045,
7058,
267,
291,
14,
26895,
8,
28559,
4720,
11675,
8,
277,
14,
23297,
12,
9349,
291,
14,
454,
360,
11675,
1329,
659,
9349,
413,
12,
9349,
1676,
5003,
4720,
985,
29,
277,
14,
7321,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
6790,
4586,
63,
1149,
39,
654,
12,
9144,
291,
14,
454,
360,
8564,
8207,
659,
9144,
31617,
29,
797,
430,
398,
1511,
63,
635,
275,
23764,
1558,
8,
277,
14,
8808,
12,
9349,
291,
14,
454,
360,
8824,
7143,
1511,
659,
9349,
31617,
4581,
9349,
2716,
29,
549,
9,
267,
1511,
63,
635,
14,
409,
6381,
8,
1419,
63,
635,
14,
2469,
342,
1204,
23764,
10701,
14,
5318,
23613,
9,
267,
1511,
63,
635,
14,
409,
5142,
2561,
288,
283,
3440,
63,
5029,
356,
469,
355,
283,
533,
356,
283,
6338,
14,
31128,
14,
11600,
14,
1907,
14,
13284,
4558,
3339,
14,
13284,
4558,
32276,
936,
1552,
267,
291,
14,
26895,
8,
1419,
63,
635,
9,
398,
291,
14,
26895,
8,
28559,
4720,
13284,
13151,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
8600,
6322,
820,
1518,
3046,
4171,
5499,
7058,
339,
347,
536,
8,
277,
304,
267,
372,
283,
599,
351,
6322,
82,
1518,
3046,
4171,
1080,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
8600,
6322,
820,
1518,
3046,
4171,
5499,
334,
1766,
41,
5942,
339,
347,
1572,
8,
277,
304,
267,
372,
291,
14,
454,
360,
13284,
11284,
358,
339,
347,
1572,
1304,
8,
277,
304,
267,
372,
283,
20876,
10466,
7,
339,
347,
1414,
985,
8,
277,
304,
267,
372,
283,
11600,
23522,
7,
339,
347,
664,
9270,
14680,
8,
277,
12,
2633,
12,
1067,
12,
17145,
12,
14043,
29,
549,
304,
267,
2368,
275,
788,
1766,
41,
418,
267,
315,
5003,
275,
291,
14,
5329,
2822,
13284,
5003,
8,
3214,
12,
291,
14,
7321,
12,
1067,
9,
267,
340,
315,
5003,
365,
488,
26,
288,
746,
17214,
1726,
8,
277,
14,
3197,
13284,
547,
8,
3214,
12,
291,
14,
7321,
430,
398,
2368,
14,
740,
8,
262,
5003,
14,
1365,
1012,
267,
734,
275,
291,
14,
5329,
2822,
2959,
5003,
8,
3214,
12,
291,
14,
8414,
12,
1067,
9,
267,
291,
14,
409,
2959,
1110,
8,
277,
14,
8414,
12,
734,
9,
267,
2368,
14,
740,
8,
548,
9,
398,
2368,
14,
740,
3654,
66,
358,
267,
2368,
14,
740,
8,
495,
8,
277,
14,
5329,
2822,
3241,
8,
3214,
12,
291,
14,
23297,
12,
1067,
1724,
398,
340,
291,
14,
5329,
2822,
4082,
8,
3214,
12,
291,
14,
6790,
4586,
63,
1149,
39,
654,
12,
1067,
304,
288,
2368,
14,
740,
3654,
3357,
63,
6929,
358,
398,
1511,
275,
291,
14,
5329,
2822,
1558,
8,
3214,
12,
291,
14,
8808,
12,
1067,
9,
267,
340,
1511,
26,
288,
2368,
14,
2880,
8,
39,
12390,
7535,
14,
1122,
13921,
4558,
8,
1419,
430,
398,
372,
359,
277,
14,
1531,
985,
1062,
598,
12390,
7535,
14,
3765,
3325,
13005,
8,
4958,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
17623,
272,
3229,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
18365,
22459,
6171,
272,
1898,
3322,
520,
334,
35,
9,
6171,
701,
22986,
11438,
699,
6558,
89,
272,
11426,
4483,
520,
282,
3113,
11438,
6308,
330,
6558,
89,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
33,
3113,
11438,
699,
6558,
89,
7,
199,
363,
602,
363,
275,
283,
17584,
22459,
6171,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6171,
12,
22986,
11438,
699,
6558,
89,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
28559,
1726,
12,
2432,
23764,
10701,
12,
2432,
23764,
13284,
5003,
12,
2432,
23764,
11675,
12,
2432,
23764,
1558,
12,
2432,
23764,
4082,
12,
2432,
23764,
13284,
13151,
9,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
11057,
16,
61,
421,
199,
533,
3229,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
699,
3649,
275,
283,
23297,
7,
272,
16503,
4586,
63,
1149,
39,
654,
275,
283,
6790,
4586,
63,
1149,
39,
654,
7,
272,
23860,
275,
283,
8808,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
339,
347,
4205,
11570,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
13284,
5003,
8,
277,
14,
7321,
12,
291,
14,
454,
360,
3205,
4045,
7058,
267,
291,
14,
26895,
8,
28559,
4720,
11675,
8,
277,
14,
23297,
12,
9349,
291,
14,
454,
360,
11675,
1329,
659,
9349,
413,
12,
9349,
1676,
5003,
4720,
985,
29,
277,
14,
7321,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
6790,
4586,
63,
1149,
39,
654,
12,
9144,
291,
14,
454,
360,
8564,
8207,
659,
9144,
31617,
29,
797,
430,
398,
1511,
63,
635,
275,
23764,
1558,
8,
277,
14,
8808,
12,
9349,
291,
14,
454,
360,
8824,
7143,
1511,
659,
9349,
31617,
4581,
9349,
2716,
29,
549,
9,
267,
1511,
63,
635,
14,
409,
6381,
8,
1419,
63,
635,
14,
2469,
342,
1204,
23764,
10701,
14,
5318,
23613,
9,
267,
1511,
63,
635,
14,
409,
5142,
2561,
288,
283,
3440,
63,
5029,
356,
469,
355,
283,
533,
356,
283,
6338,
14,
31128,
14,
11600,
14,
1907,
14,
13284,
4558,
3339,
14,
13284,
4558,
32276,
936,
1552,
267,
291,
14,
26895,
8,
1419,
63,
635,
9,
398,
291,
14,
26895,
8,
28559,
4720,
13284,
13151,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
8600,
6322,
820,
1518,
3046,
4171,
5499,
7058,
339,
347,
536,
8,
277,
304,
267,
372,
283,
599,
351,
6322,
82,
1518,
3046,
4171,
1080,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
8600,
6322,
820,
1518,
3046,
4171,
5499,
334,
1766,
41,
5942,
339,
347,
1572,
8,
277,
304,
267,
372,
291,
14,
454,
360,
13284,
11284,
358,
339,
347,
1572,
1304,
8,
277,
304,
267,
372,
283,
20876,
10466,
7,
339,
347,
1414,
985,
8,
277,
304,
267,
372,
283,
11600,
23522,
7,
339,
347,
664,
9270,
14680,
8,
277,
12,
2633,
12,
1067,
12,
17145,
12,
14043,
29,
549,
304,
267,
2368,
275,
788,
1766,
41,
418,
267,
315,
5003,
275,
291,
14,
5329,
2822,
13284,
5003,
8,
3214,
12,
291,
14,
7321,
12,
1067,
9,
267,
340,
315,
5003,
365,
488,
26,
288,
746,
17214,
1726,
8,
277,
14,
3197,
13284,
547,
8,
3214,
12,
291,
14,
7321,
430,
398,
2368,
14,
740,
8,
262,
5003,
14,
1365,
1012,
267,
734,
275,
291,
14,
5329,
2822,
2959,
5003,
8,
3214,
12,
291,
14,
8414,
12,
1067,
9,
267,
291,
14,
409,
2959,
1110,
8,
277,
14,
8414,
12,
734,
9,
267,
2368,
14,
740,
8,
548,
9,
398,
2368,
14,
740,
3654,
66,
358,
267,
2368,
14,
740,
8,
495,
8,
277,
14,
5329,
2822,
3241,
8,
3214,
12,
291,
14,
23297,
12,
1067,
1724,
398,
340,
291,
14,
5329,
2822,
4082,
8,
3214,
12,
291,
14,
6790,
4586,
63,
1149,
39,
654,
12,
1067,
304,
288,
2368,
14,
740,
3654,
3357,
63,
6929,
358,
398,
1511,
275,
291,
14,
5329,
2822,
1558,
8,
3214,
12,
291,
14,
8808,
12,
1067,
9,
267,
340,
1511,
26,
288,
2368,
14,
2880,
8,
39,
12390,
7535,
14,
1122,
13921,
4558,
8,
1419,
430,
398,
372,
359,
277,
14,
1531,
985,
1062,
598,
12390,
7535,
14,
3765,
3325,
13005,
8,
4958,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ehashman/oh-mainline
|
vendor/packages/whoosh/src/whoosh/support/levenshtein.py
|
64
|
2379
|
"""
Contains functions implementing edit distance algorithms.
"""
from whoosh.compat import xrange
def levenshtein(seq1, seq2, limit=None):
"""Returns the Levenshtein edit distance between two strings.
"""
oneago = None
thisrow = range(1, len(seq2) + 1) + [0]
for x in xrange(len(seq1)):
# Python lists wrap around for negative indices, so put the
# leftmost column at the *end* of the list. This matches with
# the zero-indexed strings and saves extra calculation.
oneago, thisrow = thisrow, [0] * len(seq2) + [x + 1]
for y in xrange(len(seq2)):
delcost = oneago[y] + 1
addcost = thisrow[y - 1] + 1
subcost = oneago[y - 1] + (seq1[x] != seq2[y])
thisrow[y] = min(delcost, addcost, subcost)
if limit and x > limit and min(thisrow) > limit:
return limit + 1
return thisrow[len(seq2) - 1]
def damerau_levenshtein(seq1, seq2, limit=None):
"""Returns the Damerau-Levenshtein edit distance between two strings.
"""
oneago = None
thisrow = list(range(1, len(seq2) + 1)) + [0]
for x in xrange(len(seq1)):
# Python lists wrap around for negative indices, so put the
# leftmost column at the *end* of the list. This matches with
# the zero-indexed strings and saves extra calculation.
twoago, oneago, thisrow = oneago, thisrow, [0] * len(seq2) + [x + 1]
for y in xrange(len(seq2)):
delcost = oneago[y] + 1
addcost = thisrow[y - 1] + 1
subcost = oneago[y - 1] + (seq1[x] != seq2[y])
thisrow[y] = min(delcost, addcost, subcost)
# This block deals with transpositions
if (x > 0 and y > 0 and seq1[x] == seq2[y - 1]
and seq1[x - 1] == seq2[y] and seq1[x] != seq2[y]):
thisrow[y] = min(thisrow[y], twoago[y - 2] + 1)
if limit and x > limit and min(thisrow) > limit:
return limit + 1
return thisrow[len(seq2) - 1]
def relative(a, b):
"""Returns the relative distance between two strings, in the range
[0-1] where 1 means total equality.
"""
d = distance(a, b)
longer = float(max((len(a), len(b))))
shorter = float(min((len(a), len(b))))
r = ((longer - d) / longer) * (shorter / longer)
return r
distance = damerau_levenshtein
|
agpl-3.0
|
[
624,
199,
6906,
3423,
18234,
5283,
6033,
18036,
14,
199,
624,
199,
199,
504,
3963,
22267,
14,
5819,
492,
4945,
421,
199,
318,
1026,
1856,
609,
15859,
8,
3610,
17,
12,
5412,
18,
12,
2304,
29,
403,
304,
272,
408,
3407,
314,
7005,
1856,
609,
15859,
5283,
6033,
3382,
2877,
3326,
14,
272,
408,
339,
1373,
14315,
275,
488,
272,
642,
1143,
275,
1425,
8,
17,
12,
822,
8,
3610,
18,
9,
435,
413,
9,
435,
359,
16,
61,
272,
367,
671,
315,
4945,
8,
552,
8,
3610,
17,
2298,
267,
327,
2018,
5548,
4816,
6818,
367,
6946,
4918,
12,
880,
5324,
314,
267,
327,
29971,
2763,
737,
314,
627,
500,
10,
402,
314,
769,
14,
961,
4450,
543,
267,
327,
314,
4697,
13,
16821,
3326,
436,
23050,
2402,
15232,
14,
267,
1373,
14315,
12,
642,
1143,
275,
642,
1143,
12,
359,
16,
61,
627,
822,
8,
3610,
18,
9,
435,
359,
88,
435,
413,
61,
267,
367,
612,
315,
4945,
8,
552,
8,
3610,
18,
2298,
288,
2150,
6336,
275,
1373,
14315,
59,
89,
61,
435,
413,
288,
1050,
6336,
275,
642,
1143,
59,
89,
446,
413,
61,
435,
413,
288,
1007,
6336,
275,
1373,
14315,
59,
89,
446,
413,
61,
435,
334,
3610,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
566,
288,
642,
1143,
59,
89,
61,
275,
1748,
8,
2264,
6336,
12,
1050,
6336,
12,
1007,
6336,
9,
398,
340,
2304,
436,
671,
690,
2304,
436,
1748,
8,
3749,
1143,
9,
690,
2304,
26,
288,
372,
2304,
435,
413,
339,
372,
642,
1143,
59,
552,
8,
3610,
18,
9,
446,
413,
61,
421,
199,
318,
366,
7122,
85,
63,
274,
1856,
609,
15859,
8,
3610,
17,
12,
5412,
18,
12,
2304,
29,
403,
304,
272,
408,
3407,
314,
577,
7122,
85,
13,
2553,
1856,
609,
15859,
5283,
6033,
3382,
2877,
3326,
14,
272,
408,
339,
1373,
14315,
275,
488,
272,
642,
1143,
275,
769,
8,
1842,
8,
17,
12,
822,
8,
3610,
18,
9,
435,
413,
430,
435,
359,
16,
61,
272,
367,
671,
315,
4945,
8,
552,
8,
3610,
17,
2298,
267,
327,
2018,
5548,
4816,
6818,
367,
6946,
4918,
12,
880,
5324,
314,
267,
327,
29971,
2763,
737,
314,
627,
500,
10,
402,
314,
769,
14,
961,
4450,
543,
267,
327,
314,
4697,
13,
16821,
3326,
436,
23050,
2402,
15232,
14,
267,
2877,
14315,
12,
1373,
14315,
12,
642,
1143,
275,
1373,
14315,
12,
642,
1143,
12,
359,
16,
61,
627,
822,
8,
3610,
18,
9,
435,
359,
88,
435,
413,
61,
267,
367,
612,
315,
4945,
8,
552,
8,
3610,
18,
2298,
288,
2150,
6336,
275,
1373,
14315,
59,
89,
61,
435,
413,
288,
1050,
6336,
275,
642,
1143,
59,
89,
446,
413,
61,
435,
413,
288,
1007,
6336,
275,
1373,
14315,
59,
89,
446,
413,
61,
435,
334,
3610,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
566,
288,
642,
1143,
59,
89,
61,
275,
1748,
8,
2264,
6336,
12,
1050,
6336,
12,
1007,
6336,
9,
288,
327,
961,
1853,
477,
2551,
543,
1752,
12658,
288,
340,
334,
88,
690,
378,
436,
612,
690,
378,
436,
5412,
17,
59,
88,
61,
508,
5412,
18,
59,
89,
446,
413,
61,
355,
436,
5412,
17,
59,
88,
446,
413,
61,
508,
5412,
18,
59,
89,
61,
436,
5412,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
4682,
355,
642,
1143,
59,
89,
61,
275,
1748,
8,
3749,
1143,
59,
89,
467,
2877,
14315,
59,
89,
446,
499,
61,
435,
413,
9,
398,
340,
2304,
436,
671,
690,
2304,
436,
1748,
8,
3749,
1143,
9,
690,
2304,
26,
288,
372,
2304,
435,
413,
339,
372,
642,
1143,
59,
552,
8,
3610,
18,
9,
446,
413,
61,
421,
199,
318,
3847,
8,
65,
12,
330,
304,
272,
408,
3407,
314,
3847,
6033,
3382,
2877,
3326,
12,
315,
314,
1425,
272,
359,
16,
13,
17,
61,
2382,
413,
4910,
3141,
16612,
14,
272,
408,
339,
366,
275,
6033,
8,
65,
12,
330,
9,
272,
8088,
275,
2069,
8,
988,
1332,
552,
8,
65,
395,
822,
8,
66,
7845,
272,
18299,
275,
2069,
8,
827,
1332,
552,
8,
65,
395,
822,
8,
66,
7845,
272,
519,
275,
3666,
5298,
836,
446,
366,
9,
1182,
8088,
9,
627,
334,
609,
3968,
1182,
8088,
9,
272,
372,
519,
421,
199,
5590,
275,
366,
7122,
85,
63,
274,
1856,
609,
15859,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6906,
3423,
18234,
5283,
6033,
18036,
14,
199,
624,
199,
199,
504,
3963,
22267,
14,
5819,
492,
4945,
421,
199,
318,
1026,
1856,
609,
15859,
8,
3610,
17,
12,
5412,
18,
12,
2304,
29,
403,
304,
272,
408,
3407,
314,
7005,
1856,
609,
15859,
5283,
6033,
3382,
2877,
3326,
14,
272,
408,
339,
1373,
14315,
275,
488,
272,
642,
1143,
275,
1425,
8,
17,
12,
822,
8,
3610,
18,
9,
435,
413,
9,
435,
359,
16,
61,
272,
367,
671,
315,
4945,
8,
552,
8,
3610,
17,
2298,
267,
327,
2018,
5548,
4816,
6818,
367,
6946,
4918,
12,
880,
5324,
314,
267,
327,
29971,
2763,
737,
314,
627,
500,
10,
402,
314,
769,
14,
961,
4450,
543,
267,
327,
314,
4697,
13,
16821,
3326,
436,
23050,
2402,
15232,
14,
267,
1373,
14315,
12,
642,
1143,
275,
642,
1143,
12,
359,
16,
61,
627,
822,
8,
3610,
18,
9,
435,
359,
88,
435,
413,
61,
267,
367,
612,
315,
4945,
8,
552,
8,
3610,
18,
2298,
288,
2150,
6336,
275,
1373,
14315,
59,
89,
61,
435,
413,
288,
1050,
6336,
275,
642,
1143,
59,
89,
446,
413,
61,
435,
413,
288,
1007,
6336,
275,
1373,
14315,
59,
89,
446,
413,
61,
435,
334,
3610,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
566,
288,
642,
1143,
59,
89,
61,
275,
1748,
8,
2264,
6336,
12,
1050,
6336,
12,
1007,
6336,
9,
398,
340,
2304,
436,
671,
690,
2304,
436,
1748,
8,
3749,
1143,
9,
690,
2304,
26,
288,
372,
2304,
435,
413,
339,
372,
642,
1143,
59,
552,
8,
3610,
18,
9,
446,
413,
61,
421,
199,
318,
366,
7122,
85,
63,
274,
1856,
609,
15859,
8,
3610,
17,
12,
5412,
18,
12,
2304,
29,
403,
304,
272,
408,
3407,
314,
577,
7122,
85,
13,
2553,
1856,
609,
15859,
5283,
6033,
3382,
2877,
3326,
14,
272,
408,
339,
1373,
14315,
275,
488,
272,
642,
1143,
275,
769,
8,
1842,
8,
17,
12,
822,
8,
3610,
18,
9,
435,
413,
430,
435,
359,
16,
61,
272,
367,
671,
315,
4945,
8,
552,
8,
3610,
17,
2298,
267,
327,
2018,
5548,
4816,
6818,
367,
6946,
4918,
12,
880,
5324,
314,
267,
327,
29971,
2763,
737,
314,
627,
500,
10,
402,
314,
769,
14,
961,
4450,
543,
267,
327,
314,
4697,
13,
16821,
3326,
436,
23050,
2402,
15232,
14,
267,
2877,
14315,
12,
1373,
14315,
12,
642,
1143,
275,
1373,
14315,
12,
642,
1143,
12,
359,
16,
61,
627,
822,
8,
3610,
18,
9,
435,
359,
88,
435,
413,
61,
267,
367,
612,
315,
4945,
8,
552,
8,
3610,
18,
2298,
288,
2150,
6336,
275,
1373,
14315,
59,
89,
61,
435,
413,
288,
1050,
6336,
275,
642,
1143,
59,
89,
446,
413,
61,
435,
413,
288,
1007,
6336,
275,
1373,
14315,
59,
89,
446,
413,
61,
435,
334,
3610,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
566,
288,
642,
1143,
59,
89,
61,
275,
1748,
8,
2264,
6336,
12,
1050,
6336,
12,
1007,
6336,
9,
288,
327,
961,
1853,
477,
2551,
543,
1752,
12658,
288,
340,
334,
88,
690,
378,
436,
612,
690,
378,
436,
5412,
17,
59,
88,
61,
508,
5412,
18,
59,
89,
446,
413,
61,
355,
436,
5412,
17,
59,
88,
446,
413,
61,
508,
5412,
18,
59,
89,
61,
436,
5412,
17,
59,
88,
61,
1137,
5412,
18,
59,
89,
4682,
355,
642,
1143,
59,
89,
61,
275,
1748,
8,
3749,
1143,
59,
89,
467,
2877,
14315,
59,
89,
446,
499,
61,
435,
413,
9,
398,
340,
2304,
436,
671,
690,
2304,
436,
1748,
8,
3749,
1143,
9,
690,
2304,
26,
288,
372,
2304,
435,
413,
339,
372,
642,
1143,
59,
552,
8,
3610,
18,
9,
446,
413,
61,
421,
199,
318,
3847,
8,
65,
12,
330,
304,
272,
408,
3407,
314,
3847,
6033,
3382,
2877,
3326,
12,
315,
314,
1425,
272,
359,
16,
13,
17,
61,
2382,
413,
4910,
3141,
16612,
14,
272,
408,
339,
366,
275,
6033,
8,
65,
12,
330,
9,
272,
8088,
275,
2069,
8,
988,
1332,
552,
8,
65,
395,
822,
8,
66,
7845,
272,
18299,
275,
2069,
8,
827,
1332,
552,
8,
65,
395,
822,
8,
66,
7845,
272,
519,
275,
3666,
5298,
836,
446,
366,
9,
1182,
8088,
9,
627,
334,
609,
3968,
1182,
8088,
9,
272,
372,
519,
421,
199,
5590,
275,
366,
7122,
85,
63,
274,
1856,
609,
15859,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
FuzzyHobbit/letsencrypt
|
letsencrypt-nginx/letsencrypt_nginx/tests/util.py
|
11
|
3355
|
"""Common utilities for letsencrypt_nginx."""
import os
import pkg_resources
import unittest
import mock
import zope.component
from acme import jose
from letsencrypt import configuration
from letsencrypt.tests import test_util
from letsencrypt.plugins import common
from letsencrypt_nginx import constants
from letsencrypt_nginx import configurator
class NginxTest(unittest.TestCase): # pylint: disable=too-few-public-methods
def setUp(self):
super(NginxTest, self).setUp()
self.temp_dir, self.config_dir, self.work_dir = common.dir_setup(
"etc_nginx", "letsencrypt_nginx.tests")
self.ssl_options = common.setup_ssl_options(
self.config_dir, constants.MOD_SSL_CONF_SRC,
constants.MOD_SSL_CONF_DEST)
self.config_path = os.path.join(self.temp_dir, "etc_nginx")
self.rsa512jwk = jose.JWKRSA.load(test_util.load_vector(
"rsa512_key.pem"))
def get_data_filename(filename):
"""Gets the filename of a test data file."""
return pkg_resources.resource_filename(
"letsencrypt_nginx.tests", os.path.join(
"testdata", "etc_nginx", filename))
def get_nginx_configurator(
config_path, config_dir, work_dir, version=(1, 6, 2)):
"""Create an Nginx Configurator with the specified options."""
backups = os.path.join(work_dir, "backups")
with mock.patch("letsencrypt_nginx.configurator.le_util."
"exe_exists") as mock_exe_exists:
mock_exe_exists.return_value = True
config = configurator.NginxConfigurator(
config=mock.MagicMock(
nginx_server_root=config_path,
le_vhost_ext="-le-ssl.conf",
config_dir=config_dir,
work_dir=work_dir,
backup_dir=backups,
temp_checkpoint_dir=os.path.join(work_dir, "temp_checkpoints"),
in_progress_dir=os.path.join(backups, "IN_PROGRESS"),
server="https://acme-server.org:443/new",
tls_sni_01_port=5001,
),
name="nginx",
version=version)
config.prepare()
# Provide general config utility.
nsconfig = configuration.NamespaceConfig(config.config)
zope.component.provideUtility(nsconfig)
return config
def filter_comments(tree):
"""Filter comment nodes from parsed configurations."""
def traverse(tree):
"""Generator dropping comment nodes"""
for key, values in tree:
if isinstance(key, list):
yield [key, filter_comments(values)]
else:
if key != '#':
yield [key, values]
return list(traverse(tree))
def contains_at_depth(haystack, needle, n):
"""Is the needle in haystack at depth n?
Return true if the needle is present in one of the sub-iterables in haystack
at depth n. Haystack must be an iterable.
"""
# Specifically use hasattr rather than isinstance(..., collections.Iterable)
# because we want to include lists but reject strings.
if not hasattr(haystack, '__iter__'):
return False
if n == 0:
return needle in haystack
else:
for item in haystack:
if contains_at_depth(item, needle, n - 1):
return True
return False
|
apache-2.0
|
[
624,
7844,
15841,
367,
4691,
31561,
63,
25826,
1041,
199,
646,
747,
199,
646,
5496,
63,
4435,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
20110,
14,
3173,
199,
199,
504,
32433,
492,
5225,
261,
199,
199,
504,
4691,
31561,
492,
2897,
199,
199,
504,
4691,
31561,
14,
2219,
492,
511,
63,
1974,
199,
199,
504,
4691,
31561,
14,
5265,
492,
2863,
199,
199,
504,
4691,
31561,
63,
25826,
492,
5262,
199,
504,
4691,
31561,
63,
25826,
492,
1101,
17320,
421,
199,
533,
653,
19101,
774,
8,
2796,
14,
1746,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
46,
19101,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
808,
63,
694,
12,
291,
14,
888,
63,
694,
12,
291,
14,
800,
63,
694,
275,
2863,
14,
694,
63,
2758,
8,
288,
298,
6839,
63,
25826,
401,
298,
2723,
31561,
63,
25826,
14,
2219,
531,
398,
291,
14,
4266,
63,
1419,
275,
2863,
14,
2758,
63,
4266,
63,
1419,
8,
288,
291,
14,
888,
63,
694,
12,
5262,
14,
8816,
63,
5413,
63,
3103,
63,
12447,
12,
288,
5262,
14,
8816,
63,
5413,
63,
3103,
63,
19374,
9,
398,
291,
14,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
298,
6839,
63,
25826,
531,
398,
291,
14,
13487,
7736,
74,
14947,
275,
5225,
261,
14,
42,
31005,
12115,
14,
912,
8,
396,
63,
1974,
14,
912,
63,
4106,
8,
288,
298,
13487,
7736,
63,
498,
14,
13102,
2237,
421,
199,
318,
664,
63,
576,
63,
1501,
8,
1501,
304,
272,
408,
14426,
314,
1788,
402,
282,
511,
666,
570,
1041,
272,
372,
5496,
63,
4435,
14,
1927,
63,
1501,
8,
267,
298,
2723,
31561,
63,
25826,
14,
2219,
401,
747,
14,
515,
14,
904,
8,
288,
298,
18481,
401,
298,
6839,
63,
25826,
401,
1788,
430,
421,
199,
318,
664,
63,
25826,
63,
888,
17320,
8,
267,
1101,
63,
515,
12,
1101,
63,
694,
12,
1736,
63,
694,
12,
1015,
2687,
17,
12,
1227,
12,
499,
2298,
272,
408,
2499,
376,
653,
19101,
4094,
17320,
543,
314,
2013,
1511,
1041,
339,
6902,
83,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
27376,
531,
339,
543,
1683,
14,
2068,
480,
2723,
31561,
63,
25826,
14,
888,
17320,
14,
274,
63,
1974,
2122,
490,
298,
5803,
63,
2444,
531,
465,
1683,
63,
5803,
63,
2444,
26,
267,
1683,
63,
5803,
63,
2444,
14,
1107,
63,
585,
275,
715,
398,
1101,
275,
1101,
17320,
14,
46,
19101,
28051,
8,
288,
1101,
29,
1805,
14,
11988,
8,
355,
302,
19101,
63,
1000,
63,
1231,
29,
888,
63,
515,
12,
355,
1026,
63,
32071,
63,
832,
27295,
274,
13,
4266,
14,
2190,
401,
355,
1101,
63,
694,
29,
888,
63,
694,
12,
355,
1736,
63,
694,
29,
800,
63,
694,
12,
355,
6902,
63,
694,
29,
27376,
12,
355,
2388,
63,
10109,
63,
694,
29,
736,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
808,
63,
32475,
1288,
355,
315,
63,
5734,
63,
694,
29,
736,
14,
515,
14,
904,
8,
27376,
12,
298,
568,
63,
24547,
1288,
355,
1654,
628,
2859,
921,
18107,
13,
1000,
14,
1308,
26,
16284,
15,
1222,
401,
355,
15142,
63,
5167,
73,
63,
614,
63,
719,
29,
21,
4587,
12,
288,
2318,
288,
536,
628,
25826,
401,
288,
1015,
29,
1023,
9,
267,
1101,
14,
6726,
342,
339,
327,
22896,
8605,
1101,
11420,
14,
272,
700,
888,
275,
2897,
14,
8814,
2028,
8,
888,
14,
888,
9,
272,
20110,
14,
3173,
14,
20824,
17505,
8,
561,
888,
9,
339,
372,
1101,
421,
199,
318,
2457,
63,
6223,
8,
2350,
304,
272,
408,
4131,
3721,
3380,
687,
4565,
13422,
1041,
339,
347,
24749,
8,
2350,
304,
267,
408,
7599,
366,
20148,
3721,
3380,
624,
267,
367,
790,
12,
1338,
315,
3123,
26,
288,
340,
1228,
8,
498,
12,
769,
304,
355,
1995,
359,
498,
12,
2457,
63,
6223,
8,
1459,
1874,
288,
587,
26,
355,
340,
790,
1137,
32326,
490,
1995,
359,
498,
12,
1338,
61,
339,
372,
769,
8,
23650,
8,
2350,
430,
421,
199,
318,
3509,
63,
292,
63,
4631,
8,
72,
1187,
2340,
12,
1929,
274,
12,
302,
304,
272,
408,
1831,
314,
1929,
274,
315,
394,
1187,
2340,
737,
5818,
302,
31,
339,
1432,
2549,
340,
314,
1929,
274,
365,
3451,
315,
1373,
402,
314,
1007,
13,
8147,
83,
315,
394,
1187,
2340,
272,
737,
5818,
302,
14,
869,
1187,
2340,
1471,
506,
376,
6076,
14,
272,
408,
272,
327,
30836,
675,
2688,
7830,
2419,
1228,
8,
11577,
5055,
14,
20852,
9,
272,
327,
2952,
781,
2934,
370,
2387,
5548,
1325,
17100,
3326,
14,
272,
340,
440,
2688,
8,
72,
1187,
2340,
12,
2560,
1661,
12168,
267,
372,
756,
272,
340,
302,
508,
378,
26,
267,
372,
1929,
274,
315,
394,
1187,
2340,
272,
587,
26,
267,
367,
1242,
315,
394,
1187,
2340,
26,
288,
340,
3509,
63,
292,
63,
4631,
8,
1053,
12,
1929,
274,
12,
302,
446,
413,
304,
355,
372,
715,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7844,
15841,
367,
4691,
31561,
63,
25826,
1041,
199,
646,
747,
199,
646,
5496,
63,
4435,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
20110,
14,
3173,
199,
199,
504,
32433,
492,
5225,
261,
199,
199,
504,
4691,
31561,
492,
2897,
199,
199,
504,
4691,
31561,
14,
2219,
492,
511,
63,
1974,
199,
199,
504,
4691,
31561,
14,
5265,
492,
2863,
199,
199,
504,
4691,
31561,
63,
25826,
492,
5262,
199,
504,
4691,
31561,
63,
25826,
492,
1101,
17320,
421,
199,
533,
653,
19101,
774,
8,
2796,
14,
1746,
304,
221,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
46,
19101,
774,
12,
291,
680,
5996,
342,
398,
291,
14,
808,
63,
694,
12,
291,
14,
888,
63,
694,
12,
291,
14,
800,
63,
694,
275,
2863,
14,
694,
63,
2758,
8,
288,
298,
6839,
63,
25826,
401,
298,
2723,
31561,
63,
25826,
14,
2219,
531,
398,
291,
14,
4266,
63,
1419,
275,
2863,
14,
2758,
63,
4266,
63,
1419,
8,
288,
291,
14,
888,
63,
694,
12,
5262,
14,
8816,
63,
5413,
63,
3103,
63,
12447,
12,
288,
5262,
14,
8816,
63,
5413,
63,
3103,
63,
19374,
9,
398,
291,
14,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
298,
6839,
63,
25826,
531,
398,
291,
14,
13487,
7736,
74,
14947,
275,
5225,
261,
14,
42,
31005,
12115,
14,
912,
8,
396,
63,
1974,
14,
912,
63,
4106,
8,
288,
298,
13487,
7736,
63,
498,
14,
13102,
2237,
421,
199,
318,
664,
63,
576,
63,
1501,
8,
1501,
304,
272,
408,
14426,
314,
1788,
402,
282,
511,
666,
570,
1041,
272,
372,
5496,
63,
4435,
14,
1927,
63,
1501,
8,
267,
298,
2723,
31561,
63,
25826,
14,
2219,
401,
747,
14,
515,
14,
904,
8,
288,
298,
18481,
401,
298,
6839,
63,
25826,
401,
1788,
430,
421,
199,
318,
664,
63,
25826,
63,
888,
17320,
8,
267,
1101,
63,
515,
12,
1101,
63,
694,
12,
1736,
63,
694,
12,
1015,
2687,
17,
12,
1227,
12,
499,
2298,
272,
408,
2499,
376,
653,
19101,
4094,
17320,
543,
314,
2013,
1511,
1041,
339,
6902,
83,
275,
747,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
27376,
531,
339,
543,
1683,
14,
2068,
480,
2723,
31561,
63,
25826,
14,
888,
17320,
14,
274,
63,
1974,
2122,
490,
298,
5803,
63,
2444,
531,
465,
1683,
63,
5803,
63,
2444,
26,
267,
1683,
63,
5803,
63,
2444,
14,
1107,
63,
585,
275,
715,
398,
1101,
275,
1101,
17320,
14,
46,
19101,
28051,
8,
288,
1101,
29,
1805,
14,
11988,
8,
355,
302,
19101,
63,
1000,
63,
1231,
29,
888,
63,
515,
12,
355,
1026,
63,
32071,
63,
832,
27295,
274,
13,
4266,
14,
2190,
401,
355,
1101,
63,
694,
29,
888,
63,
694,
12,
355,
1736,
63,
694,
29,
800,
63,
694,
12,
355,
6902,
63,
694,
29,
27376,
12,
355,
2388,
63,
10109,
63,
694,
29,
736,
14,
515,
14,
904,
8,
800,
63,
694,
12,
298,
808,
63,
32475,
1288,
355,
315,
63,
5734,
63,
694,
29,
736,
14,
515,
14,
904,
8,
27376,
12,
298,
568,
63,
24547,
1288,
355,
1654,
628,
2859,
921,
18107,
13,
1000,
14,
1308,
26,
16284,
15,
1222,
401,
355,
15142,
63,
5167,
73,
63,
614,
63,
719,
29,
21,
4587,
12,
288,
2318,
288,
536,
628,
25826,
401,
288,
1015,
29,
1023,
9,
267,
1101,
14,
6726,
342,
339,
327,
22896,
8605,
1101,
11420,
14,
272,
700,
888,
275,
2897,
14,
8814,
2028,
8,
888,
14,
888,
9,
272,
20110,
14,
3173,
14,
20824,
17505,
8,
561,
888,
9,
339,
372,
1101,
421,
199,
318,
2457,
63,
6223,
8,
2350,
304,
272,
408,
4131,
3721,
3380,
687,
4565,
13422,
1041,
339,
347,
24749,
8,
2350,
304,
267,
408,
7599,
366,
20148,
3721,
3380,
624,
267,
367,
790,
12,
1338,
315,
3123,
26,
288,
340,
1228,
8,
498,
12,
769,
304,
355,
1995,
359,
498,
12,
2457,
63,
6223,
8,
1459,
1874,
288,
587,
26,
355,
340,
790,
1137,
32326,
490,
1995,
359,
498,
12,
1338,
61,
339,
372,
769,
8,
23650,
8,
2350,
430,
421,
199,
318,
3509,
63,
292,
63,
4631,
8,
72,
1187,
2340,
12,
1929,
274,
12,
302,
304,
272,
408,
1831,
314,
1929,
274,
315,
394,
1187,
2340,
737,
5818,
302,
31,
339,
1432,
2549,
340,
314,
1929,
274,
365,
3451,
315,
1373,
402,
314,
1007,
13,
8147,
83,
315,
394,
1187,
2340,
272,
737,
5818,
302,
14,
869,
1187,
2340,
1471,
506,
376,
6076,
14,
272,
408,
272,
327,
30836,
675,
2688,
7830,
2419,
1228,
8,
11577,
5055,
14,
20852,
9,
272,
327,
2952,
781,
2934,
370,
2387,
5548,
1325,
17100,
3326,
14,
272,
340,
440,
2688,
8,
72,
1187,
2340,
12,
2560,
1661,
12168,
267,
372,
756,
272,
340,
302,
508,
378,
26,
267,
372,
1929,
274,
315,
394,
1187,
2340,
272,
587,
26,
267,
367,
1242,
315,
394,
1187,
2340,
26,
288,
340,
3509,
63,
292,
63,
4631,
8,
1053,
12,
1929,
274,
12,
302,
446,
413,
304,
355,
372,
715,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
danielpalomino/gem5
|
src/arch/x86/isa/insts/simd128/integer/shift/__init__.py
|
91
|
2403
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# 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 the copyright holders 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.
#
# Authors: Gabe Black
categories = ["left_logical_shift",
"right_logical_shift",
"right_arithmetic_shift"]
microcode = '''
# 128 bit multimedia and scientific instructions
'''
for category in categories:
exec "import %s as cat" % category
microcode += cat.microcode
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
8906,
275,
2097,
3039,
63,
7954,
63,
4723,
401,
1598,
298,
1019,
63,
7954,
63,
4723,
401,
1598,
298,
1019,
63,
18327,
15307,
63,
4723,
937,
199,
199,
6453,
600,
275,
1449,
199,
3,
7960,
4546,
19207,
521,
2391,
436,
6276,
23509,
15794,
199,
2344,
199,
509,
4637,
315,
9695,
26,
272,
2146,
298,
646,
450,
83,
465,
6230,
2,
450,
4637,
272,
9967,
600,
847,
6230,
14,
6453,
600,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
8906,
275,
2097,
3039,
63,
7954,
63,
4723,
401,
1598,
298,
1019,
63,
7954,
63,
4723,
401,
1598,
298,
1019,
63,
18327,
15307,
63,
4723,
937,
199,
199,
6453,
600,
275,
1449,
199,
3,
7960,
4546,
19207,
521,
2391,
436,
6276,
23509,
15794,
199,
2344,
199,
509,
4637,
315,
9695,
26,
272,
2146,
298,
646,
450,
83,
465,
6230,
2,
450,
4637,
272,
9967,
600,
847,
6230,
14,
6453,
600,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
evanma92/routeh
|
flask/lib/python2.7/site-packages/pip/utils/build.py
|
899
|
1312
|
from __future__ import absolute_import
import os.path
import tempfile
from pip.utils import rmtree
class BuildDirectory(object):
def __init__(self, name=None, delete=None):
# If we were not given an explicit directory, and we were not given an
# explicit delete option, then we'll default to deleting.
if name is None and delete is None:
delete = True
if name is None:
# We realpath here because some systems have their default tmpdir
# symlinked to another directory. This tends to confuse build
# scripts, so we canonicalize the path by traversing potential
# symlinks here.
name = os.path.realpath(tempfile.mkdtemp(prefix="pip-build-"))
# If we were not given an explicit directory, and we were not given
# an explicit delete option, then we'll default to deleting.
if delete is None:
delete = True
self.name = name
self.delete = delete
def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)
def __enter__(self):
return self.name
def __exit__(self, exc, value, tb):
self.cleanup()
def cleanup(self):
if self.delete:
rmtree(self.name)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
747,
14,
515,
199,
646,
5549,
199,
199,
504,
7305,
14,
1208,
492,
20978,
421,
199,
533,
6516,
6231,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
12,
3145,
29,
403,
304,
267,
327,
982,
781,
4898,
440,
1627,
376,
5027,
2082,
12,
436,
781,
4898,
440,
1627,
376,
267,
327,
5027,
3145,
945,
12,
2066,
781,
7171,
849,
370,
13794,
14,
267,
340,
536,
365,
488,
436,
3145,
365,
488,
26,
288,
3145,
275,
715,
398,
340,
536,
365,
488,
26,
288,
327,
2136,
3363,
515,
2348,
2952,
2005,
10460,
1172,
3932,
849,
12885,
288,
327,
4678,
12751,
370,
4573,
2082,
14,
221,
961,
16685,
795,
370,
3743,
1180,
1900,
288,
327,
10554,
12,
880,
781,
11358,
794,
314,
931,
701,
1468,
422,
1044,
12330,
288,
327,
19891,
2348,
14,
288,
536,
275,
747,
14,
515,
14,
11091,
8,
17336,
14,
11983,
8,
1861,
628,
9983,
13,
1506,
13,
2237,
288,
327,
982,
781,
4898,
440,
1627,
376,
5027,
2082,
12,
436,
781,
4898,
440,
1627,
288,
327,
376,
5027,
3145,
945,
12,
2066,
781,
7171,
849,
370,
13794,
14,
288,
340,
3145,
365,
488,
26,
355,
3145,
275,
715,
398,
291,
14,
354,
275,
536,
267,
291,
14,
1807,
275,
3145,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
2440,
18776,
82,
93,
23167,
908,
8,
277,
855,
533,
4914,
354,
3108,
291,
14,
354,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
636,
2224,
721,
277,
12,
3178,
12,
574,
12,
7070,
304,
267,
291,
14,
7661,
342,
339,
347,
9058,
8,
277,
304,
267,
340,
291,
14,
1807,
26,
288,
20978,
8,
277,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
747,
14,
515,
199,
646,
5549,
199,
199,
504,
7305,
14,
1208,
492,
20978,
421,
199,
533,
6516,
6231,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
12,
3145,
29,
403,
304,
267,
327,
982,
781,
4898,
440,
1627,
376,
5027,
2082,
12,
436,
781,
4898,
440,
1627,
376,
267,
327,
5027,
3145,
945,
12,
2066,
781,
7171,
849,
370,
13794,
14,
267,
340,
536,
365,
488,
436,
3145,
365,
488,
26,
288,
3145,
275,
715,
398,
340,
536,
365,
488,
26,
288,
327,
2136,
3363,
515,
2348,
2952,
2005,
10460,
1172,
3932,
849,
12885,
288,
327,
4678,
12751,
370,
4573,
2082,
14,
221,
961,
16685,
795,
370,
3743,
1180,
1900,
288,
327,
10554,
12,
880,
781,
11358,
794,
314,
931,
701,
1468,
422,
1044,
12330,
288,
327,
19891,
2348,
14,
288,
536,
275,
747,
14,
515,
14,
11091,
8,
17336,
14,
11983,
8,
1861,
628,
9983,
13,
1506,
13,
2237,
288,
327,
982,
781,
4898,
440,
1627,
376,
5027,
2082,
12,
436,
781,
4898,
440,
1627,
288,
327,
376,
5027,
3145,
945,
12,
2066,
781,
7171,
849,
370,
13794,
14,
288,
340,
3145,
365,
488,
26,
355,
3145,
275,
715,
398,
291,
14,
354,
275,
536,
267,
291,
14,
1807,
275,
3145,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
2440,
18776,
82,
93,
23167,
908,
8,
277,
855,
533,
4914,
354,
3108,
291,
14,
354,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
636,
2224,
721,
277,
12,
3178,
12,
574,
12,
7070,
304,
267,
291,
14,
7661,
342,
339,
347,
9058,
8,
277,
304,
267,
340,
291,
14,
1807,
26,
288,
20978,
8,
277,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dr0pz0ne/sibble
|
lib/ansible/plugins/lookup/indexed_items.py
|
127
|
1237
|
# (c) 2012, 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/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, variables, **kwargs):
if not isinstance(terms, list):
raise AnsibleError("with_indexed_items expects a list")
items = self._flatten(terms)
return zip(range(len(items)), items)
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
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,
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,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
199,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
398,
340,
440,
1228,
8,
9187,
12,
769,
304,
288,
746,
13358,
480,
1045,
63,
16821,
63,
1744,
14292,
282,
769,
531,
398,
2974,
275,
291,
423,
8487,
8,
9187,
9,
267,
372,
3482,
8,
1842,
8,
552,
8,
1744,
1826,
2974,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
6029,
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,
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,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
199,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
12,
1011,
958,
304,
398,
340,
440,
1228,
8,
9187,
12,
769,
304,
288,
746,
13358,
480,
1045,
63,
16821,
63,
1744,
14292,
282,
769,
531,
398,
2974,
275,
291,
423,
8487,
8,
9187,
9,
267,
372,
3482,
8,
1842,
8,
552,
8,
1744,
1826,
2974,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
coded-by-hand/mass
|
env/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/commands/search.py
|
9
|
4078
|
import sys
import textwrap
import pkg_resources
import pip.download
from pip.basecommand import Command
from pip.util import get_terminal_size
from pip.log import logger
from pip.backwardcompat import xmlrpclib, reduce, cmp
from distutils.version import StrictVersion, LooseVersion
class SearchCommand(Command):
name = 'search'
usage = '%prog QUERY'
summary = 'Search PyPI'
def __init__(self):
super(SearchCommand, self).__init__()
self.parser.add_option(
'--index',
dest='index',
metavar='URL',
default='http://pypi.python.org/pypi',
help='Base URL of Python Package Index (default %default)')
def run(self, options, args):
if not args:
logger.warn('ERROR: Missing required argument (search query).')
return
query = args
index_url = options.index
pypi_hits = self.search(query, index_url)
hits = transform_hits(pypi_hits)
terminal_width = None
if sys.stdout.isatty():
terminal_width = get_terminal_size()[0]
print_results(hits, terminal_width=terminal_width)
def search(self, query, index_url):
pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport)
hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits
def transform_hits(hits):
"""
The list from pypi is really a list of versions. We want a list of
packages with the list of versions stored inline. This converts the
list from pypi into one we can use.
"""
packages = {}
for hit in hits:
name = hit['name']
summary = hit['summary']
version = hit['version']
score = hit['_pypi_ordering']
if name not in packages.keys():
packages[name] = {'name': name, 'summary': summary, 'versions': [version], 'score': score}
else:
packages[name]['versions'].append(version)
# if this is the highest version, replace summary and score
if version == highest_version(packages[name]['versions']):
packages[name]['summary'] = summary
packages[name]['score'] = score
# each record has a unique name now, so we will convert the dict into a list sorted by score
package_list = sorted(packages.values(), key=lambda x: x['score'], reverse=True)
return package_list
def print_results(hits, name_column_width=25, terminal_width=None):
installed_packages = [p.project_name for p in pkg_resources.working_set]
for hit in hits:
name = hit['name']
summary = hit['summary'] or ''
if terminal_width is not None:
# wrap and indent summary to fit terminal
summary = textwrap.wrap(summary, terminal_width - name_column_width - 5)
summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)
line = '%s - %s' % (name.ljust(name_column_width), summary)
try:
logger.notify(line)
if name in installed_packages:
dist = pkg_resources.get_distribution(name)
logger.indent += 2
try:
latest = highest_version(hit['versions'])
if dist.version == latest:
logger.notify('INSTALLED: %s (latest)' % dist.version)
else:
logger.notify('INSTALLED: %s' % dist.version)
logger.notify('LATEST: %s' % latest)
finally:
logger.indent -= 2
except UnicodeEncodeError:
pass
def compare_versions(version1, version2):
try:
return cmp(StrictVersion(version1), StrictVersion(version2))
# in case of abnormal version number, fall back to LooseVersion
except ValueError:
return cmp(LooseVersion(version1), LooseVersion(version2))
def highest_version(versions):
return reduce((lambda v1, v2: compare_versions(v1, v2) == 1 and v1 or v2), versions)
SearchCommand()
|
bsd-2-clause
|
[
646,
984,
199,
646,
13390,
199,
646,
5496,
63,
4435,
199,
646,
7305,
14,
4249,
199,
504,
7305,
14,
1095,
1531,
492,
5817,
199,
504,
7305,
14,
1974,
492,
664,
63,
12010,
63,
890,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
14,
15457,
5819,
492,
19122,
12,
7114,
12,
10467,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
12,
18462,
421,
199,
533,
8730,
3110,
8,
3110,
304,
272,
536,
275,
283,
1733,
7,
272,
4503,
275,
1543,
6595,
7813,
9418,
7,
272,
6212,
275,
283,
5278,
24330,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
5278,
3110,
12,
291,
2843,
826,
4533,
267,
291,
14,
2087,
14,
525,
63,
1422,
8,
288,
2850,
1080,
297,
288,
2053,
534,
1080,
297,
288,
8214,
534,
2632,
297,
288,
849,
534,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
297,
288,
1720,
534,
1563,
2851,
402,
2018,
15665,
5499,
334,
885,
450,
885,
5942,
339,
347,
1255,
8,
277,
12,
1511,
12,
1249,
304,
267,
340,
440,
1249,
26,
288,
2512,
14,
4050,
360,
3170,
26,
15626,
1415,
1423,
334,
1733,
1827,
28583,
288,
372,
267,
1827,
275,
1249,
267,
1478,
63,
633,
275,
1511,
14,
1080,
398,
1134,
1038,
63,
16595,
275,
291,
14,
1733,
8,
1131,
12,
1478,
63,
633,
9,
267,
19745,
275,
5793,
63,
16595,
8,
17343,
63,
16595,
9,
398,
11167,
63,
2063,
275,
488,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
11167,
63,
2063,
275,
664,
63,
12010,
63,
890,
3430,
16,
61,
398,
870,
63,
2604,
8,
16595,
12,
11167,
63,
2063,
29,
12010,
63,
2063,
9,
339,
347,
2754,
8,
277,
12,
1827,
12,
1478,
63,
633,
304,
267,
1134,
1038,
275,
19122,
14,
3120,
4936,
8,
1080,
63,
633,
12,
7305,
14,
4249,
14,
17596,
773,
63,
5545,
9,
267,
19745,
275,
1134,
1038,
14,
1733,
3252,
354,
356,
1827,
12,
283,
4705,
356,
1827,
1386,
283,
269,
358,
267,
372,
19745,
421,
199,
318,
5793,
63,
16595,
8,
16595,
304,
272,
408,
272,
710,
769,
687,
1134,
1038,
365,
7710,
282,
769,
402,
5459,
14,
2136,
2934,
282,
769,
402,
272,
6117,
543,
314,
769,
402,
5459,
5489,
8308,
14,
961,
15373,
314,
272,
769,
687,
1134,
1038,
1901,
1373,
781,
883,
675,
14,
272,
408,
272,
6117,
275,
1052,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
267,
1015,
275,
9793,
459,
1023,
418,
267,
5396,
275,
9793,
8680,
17343,
63,
7128,
418,
398,
340,
536,
440,
315,
6117,
14,
1612,
837,
288,
6117,
59,
354,
61,
275,
791,
354,
356,
536,
12,
283,
4705,
356,
6212,
12,
283,
6234,
356,
359,
1023,
467,
283,
3397,
356,
5396,
93,
267,
587,
26,
288,
6117,
59,
354,
2733,
6234,
2278,
740,
8,
1023,
9,
953,
327,
340,
642,
365,
314,
15356,
1015,
12,
3350,
6212,
436,
5396,
288,
340,
1015,
508,
15356,
63,
1023,
8,
5154,
59,
354,
2733,
6234,
9090,
355,
6117,
59,
354,
2733,
4705,
418,
275,
6212,
355,
6117,
59,
354,
2733,
3397,
418,
275,
5396,
339,
327,
1924,
2777,
965,
282,
3747,
536,
3063,
12,
880,
781,
911,
3957,
314,
1211,
1901,
282,
769,
3355,
701,
5396,
272,
2559,
63,
513,
275,
3355,
8,
5154,
14,
1459,
1062,
790,
29,
2734,
671,
26,
671,
459,
3397,
995,
3837,
29,
549,
9,
272,
372,
2559,
63,
513,
421,
199,
318,
870,
63,
2604,
8,
16595,
12,
536,
63,
2301,
63,
2063,
29,
821,
12,
11167,
63,
2063,
29,
403,
304,
272,
4903,
63,
5154,
275,
359,
80,
14,
1715,
63,
354,
367,
299,
315,
5496,
63,
4435,
14,
9818,
63,
409,
61,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
503,
2125,
267,
340,
11167,
63,
2063,
365,
440,
488,
26,
288,
327,
4816,
436,
4363,
6212,
370,
5542,
11167,
288,
6212,
275,
13390,
14,
3823,
8,
4705,
12,
11167,
63,
2063,
446,
536,
63,
2301,
63,
2063,
446,
959,
9,
288,
6212,
275,
17485,
78,
7,
435,
283,
283,
627,
334,
354,
63,
2301,
63,
2063,
435,
650,
4992,
904,
8,
4705,
9,
267,
1004,
275,
1543,
83,
446,
450,
83,
7,
450,
334,
354,
14,
19996,
8,
354,
63,
2301,
63,
2063,
395,
6212,
9,
267,
862,
26,
288,
2512,
14,
6814,
8,
604,
9,
288,
340,
536,
315,
4903,
63,
5154,
26,
355,
2917,
275,
5496,
63,
4435,
14,
362,
63,
4972,
8,
354,
9,
355,
2512,
14,
3724,
847,
499,
355,
862,
26,
490,
8839,
275,
15356,
63,
1023,
8,
12948,
459,
6234,
1105,
490,
340,
2917,
14,
1023,
508,
8839,
26,
717,
2512,
14,
6814,
360,
15942,
26,
450,
83,
334,
7410,
3171,
450,
2917,
14,
1023,
9,
490,
587,
26,
717,
2512,
14,
6814,
360,
15942,
26,
450,
83,
7,
450,
2917,
14,
1023,
9,
717,
2512,
14,
6814,
360,
20307,
1719,
26,
259,
450,
83,
7,
450,
8839,
9,
355,
3753,
26,
490,
2512,
14,
3724,
4862,
499,
267,
871,
24094,
26,
288,
986,
421,
199,
318,
6540,
63,
6234,
8,
1023,
17,
12,
1015,
18,
304,
272,
862,
26,
267,
372,
10467,
8,
18625,
3353,
8,
1023,
17,
395,
23052,
3353,
8,
1023,
18,
430,
272,
327,
315,
1930,
402,
2236,
3302,
1015,
1329,
12,
11264,
1771,
370,
18462,
272,
871,
1722,
26,
267,
372,
10467,
8,
44,
17851,
8,
1023,
17,
395,
18462,
8,
1023,
18,
430,
421,
199,
318,
15356,
63,
1023,
8,
6234,
304,
272,
372,
7114,
1332,
2734,
373,
17,
12,
373,
18,
26,
6540,
63,
6234,
8,
86,
17,
12,
373,
18,
9,
508,
413,
436,
373,
17,
503,
373,
18,
395,
5459,
9,
421,
199,
5278,
3110,
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
] |
[
984,
199,
646,
13390,
199,
646,
5496,
63,
4435,
199,
646,
7305,
14,
4249,
199,
504,
7305,
14,
1095,
1531,
492,
5817,
199,
504,
7305,
14,
1974,
492,
664,
63,
12010,
63,
890,
199,
504,
7305,
14,
793,
492,
2512,
199,
504,
7305,
14,
15457,
5819,
492,
19122,
12,
7114,
12,
10467,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
12,
18462,
421,
199,
533,
8730,
3110,
8,
3110,
304,
272,
536,
275,
283,
1733,
7,
272,
4503,
275,
1543,
6595,
7813,
9418,
7,
272,
6212,
275,
283,
5278,
24330,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
5278,
3110,
12,
291,
2843,
826,
4533,
267,
291,
14,
2087,
14,
525,
63,
1422,
8,
288,
2850,
1080,
297,
288,
2053,
534,
1080,
297,
288,
8214,
534,
2632,
297,
288,
849,
534,
1014,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
297,
288,
1720,
534,
1563,
2851,
402,
2018,
15665,
5499,
334,
885,
450,
885,
5942,
339,
347,
1255,
8,
277,
12,
1511,
12,
1249,
304,
267,
340,
440,
1249,
26,
288,
2512,
14,
4050,
360,
3170,
26,
15626,
1415,
1423,
334,
1733,
1827,
28583,
288,
372,
267,
1827,
275,
1249,
267,
1478,
63,
633,
275,
1511,
14,
1080,
398,
1134,
1038,
63,
16595,
275,
291,
14,
1733,
8,
1131,
12,
1478,
63,
633,
9,
267,
19745,
275,
5793,
63,
16595,
8,
17343,
63,
16595,
9,
398,
11167,
63,
2063,
275,
488,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
11167,
63,
2063,
275,
664,
63,
12010,
63,
890,
3430,
16,
61,
398,
870,
63,
2604,
8,
16595,
12,
11167,
63,
2063,
29,
12010,
63,
2063,
9,
339,
347,
2754,
8,
277,
12,
1827,
12,
1478,
63,
633,
304,
267,
1134,
1038,
275,
19122,
14,
3120,
4936,
8,
1080,
63,
633,
12,
7305,
14,
4249,
14,
17596,
773,
63,
5545,
9,
267,
19745,
275,
1134,
1038,
14,
1733,
3252,
354,
356,
1827,
12,
283,
4705,
356,
1827,
1386,
283,
269,
358,
267,
372,
19745,
421,
199,
318,
5793,
63,
16595,
8,
16595,
304,
272,
408,
272,
710,
769,
687,
1134,
1038,
365,
7710,
282,
769,
402,
5459,
14,
2136,
2934,
282,
769,
402,
272,
6117,
543,
314,
769,
402,
5459,
5489,
8308,
14,
961,
15373,
314,
272,
769,
687,
1134,
1038,
1901,
1373,
781,
883,
675,
14,
272,
408,
272,
6117,
275,
1052,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
267,
1015,
275,
9793,
459,
1023,
418,
267,
5396,
275,
9793,
8680,
17343,
63,
7128,
418,
398,
340,
536,
440,
315,
6117,
14,
1612,
837,
288,
6117,
59,
354,
61,
275,
791,
354,
356,
536,
12,
283,
4705,
356,
6212,
12,
283,
6234,
356,
359,
1023,
467,
283,
3397,
356,
5396,
93,
267,
587,
26,
288,
6117,
59,
354,
2733,
6234,
2278,
740,
8,
1023,
9,
953,
327,
340,
642,
365,
314,
15356,
1015,
12,
3350,
6212,
436,
5396,
288,
340,
1015,
508,
15356,
63,
1023,
8,
5154,
59,
354,
2733,
6234,
9090,
355,
6117,
59,
354,
2733,
4705,
418,
275,
6212,
355,
6117,
59,
354,
2733,
3397,
418,
275,
5396,
339,
327,
1924,
2777,
965,
282,
3747,
536,
3063,
12,
880,
781,
911,
3957,
314,
1211,
1901,
282,
769,
3355,
701,
5396,
272,
2559,
63,
513,
275,
3355,
8,
5154,
14,
1459,
1062,
790,
29,
2734,
671,
26,
671,
459,
3397,
995,
3837,
29,
549,
9,
272,
372,
2559,
63,
513,
421,
199,
318,
870,
63,
2604,
8,
16595,
12,
536,
63,
2301,
63,
2063,
29,
821,
12,
11167,
63,
2063,
29,
403,
304,
272,
4903,
63,
5154,
275,
359,
80,
14,
1715,
63,
354,
367,
299,
315,
5496,
63,
4435,
14,
9818,
63,
409,
61,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
503,
2125,
267,
340,
11167,
63,
2063,
365,
440,
488,
26,
288,
327,
4816,
436,
4363,
6212,
370,
5542,
11167,
288,
6212,
275,
13390,
14,
3823,
8,
4705,
12,
11167,
63,
2063,
446,
536,
63,
2301,
63,
2063,
446,
959,
9,
288,
6212,
275,
17485,
78,
7,
435,
283,
283,
627,
334,
354,
63,
2301,
63,
2063,
435,
650,
4992,
904,
8,
4705,
9,
267,
1004,
275,
1543,
83,
446,
450,
83,
7,
450,
334,
354,
14,
19996,
8,
354,
63,
2301,
63,
2063,
395,
6212,
9,
267,
862,
26,
288,
2512,
14,
6814,
8,
604,
9,
288,
340,
536,
315,
4903,
63,
5154,
26,
355,
2917,
275,
5496,
63,
4435,
14,
362,
63,
4972,
8,
354,
9,
355,
2512,
14,
3724,
847,
499,
355,
862,
26,
490,
8839,
275,
15356,
63,
1023,
8,
12948,
459,
6234,
1105,
490,
340,
2917,
14,
1023,
508,
8839,
26,
717,
2512,
14,
6814,
360,
15942,
26,
450,
83,
334,
7410,
3171,
450,
2917,
14,
1023,
9,
490,
587,
26,
717,
2512,
14,
6814,
360,
15942,
26,
450,
83,
7,
450,
2917,
14,
1023,
9,
717,
2512,
14,
6814,
360,
20307,
1719,
26,
259,
450,
83,
7,
450,
8839,
9,
355,
3753,
26,
490,
2512,
14,
3724,
4862,
499,
267,
871,
24094,
26,
288,
986,
421,
199,
318,
6540,
63,
6234,
8,
1023,
17,
12,
1015,
18,
304,
272,
862,
26,
267,
372,
10467,
8,
18625,
3353,
8,
1023,
17,
395,
23052,
3353,
8,
1023,
18,
430,
272,
327,
315,
1930,
402,
2236,
3302,
1015,
1329,
12,
11264,
1771,
370,
18462,
272,
871,
1722,
26,
267,
372,
10467,
8,
44,
17851,
8,
1023,
17,
395,
18462,
8,
1023,
18,
430,
421,
199,
318,
15356,
63,
1023,
8,
6234,
304,
272,
372,
7114,
1332,
2734,
373,
17,
12,
373,
18,
26,
6540,
63,
6234,
8,
86,
17,
12,
373,
18,
9,
508,
413,
436,
373,
17,
503,
373,
18,
395,
5459,
9,
421,
199,
5278,
3110,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mikf/gallery-dl
|
gallery_dl/extractor/fuskator.py
|
1
|
3698
|
# -*- coding: utf-8 -*-
# Copyright 2019 Mike Fährmann
#
# 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.
"""Extractors for https://fuskator.com/"""
from .common import GalleryExtractor, Extractor, Message
from .. import text
import time
class FuskatorGalleryExtractor(GalleryExtractor):
"""Extractor for image galleries on fuskator.com"""
category = "fuskator"
root = "https://fuskator.com"
pattern = r"(?:https?://)?fuskator\.com/(?:thumbs|expanded)/([^/?#]+)"
test = (
("https://fuskator.com/thumbs/d0GnIzXrSKU/", {
"pattern": r"https://i\d+.fuskator.com/large/d0GnIzXrSKU/.+\.jpg",
"count": 22,
"keyword": {
"gallery_id": 473023,
"gallery_hash": "d0GnIzXrSKU",
"title": "re:Shaved Brunette Babe Maria Ryabushkina with ",
"views": int,
"score": float,
"count": 22,
"tags": list,
},
}),
("https://fuskator.com/expanded/gXpKzjgIidA/index.html"),
)
def __init__(self, match):
self.gallery_hash = match.group(1)
url = "{}/thumbs/{}/".format(self.root, self.gallery_hash)
GalleryExtractor.__init__(self, match, url)
def metadata(self, page):
headers = {
"Referer" : self.gallery_url,
"X-Requested-With": "XMLHttpRequest",
}
auth = self.request(
self.root + "/ajax/auth.aspx", method="POST", headers=headers,
).text
params = {
"X-Auth": auth,
"hash" : self.gallery_hash,
"_" : int(time.time()),
}
self.data = data = self.request(
self.root + "/ajax/gal.aspx", params=params, headers=headers,
).json()
title = text.extract(page, "<title>", "</title>")[0].strip()
title, _, gallery_id = title.rpartition("#")
return {
"gallery_id" : text.parse_int(gallery_id),
"gallery_hash": self.gallery_hash,
"title" : text.unescape(title[:-15]),
"views" : data["hits"],
"score" : data["rating"],
"tags" : data["tags"].split(","),
"count" : len(data["images"]),
}
def images(self, page):
for image in self.data["images"]:
yield "https:" + image["imageUrl"], image
class FuskatorSearchExtractor(Extractor):
"""Extractor for search results on fuskator.com"""
category = "fuskator"
subcategory = "search"
root = "https://fuskator.com"
pattern = r"(?:https?://)?fuskator\.com(/(?:search|page)/.+)"
test = (
("https://fuskator.com/search/red_swimsuit/", {
"pattern": FuskatorGalleryExtractor.pattern,
"count": ">= 40",
}),
("https://fuskator.com/page/3/swimsuit/quality/"),
)
def __init__(self, match):
Extractor.__init__(self, match)
self.path = match.group(1)
def items(self):
url = self.root + self.path
data = {"_extractor": FuskatorGalleryExtractor}
while True:
page = self.request(url).text
for path in text.extract_iter(
page, 'class="pic_pad"><a href="', '"'):
yield Message.Queue, self.root + path, data
pages = text.extract(page, 'class="pages"><span>', '>>><')[0]
if not pages:
return
url = self.root + text.rextract(pages, 'href="', '"')[0]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
20312,
603,
7455,
481,
13733,
22276,
1189,
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,
199,
624,
11039,
83,
367,
4178,
921,
31958,
75,
707,
14,
957,
15,
624,
199,
199,
504,
1275,
2330,
492,
598,
17787,
11039,
12,
18925,
12,
6430,
199,
504,
2508,
492,
1318,
199,
646,
900,
421,
199,
533,
481,
527,
75,
707,
39,
17787,
11039,
8,
39,
17787,
11039,
304,
272,
408,
11039,
367,
1834,
486,
4598,
1996,
641,
289,
527,
75,
707,
14,
957,
624,
272,
4637,
275,
298,
31958,
75,
707,
2,
272,
1738,
275,
298,
2859,
921,
31958,
75,
707,
14,
957,
2,
272,
3851,
275,
519,
2,
5169,
2859,
14144,
5547,
31958,
75,
707,
4537,
957,
32576,
273,
23135,
92,
15645,
2447,
7059,
10197,
3,
2807,
2924,
272,
511,
275,
334,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
273,
23135,
15,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
10665,
469,
288,
298,
3401,
582,
519,
2,
2859,
921,
73,
60,
68,
26240,
31958,
75,
707,
14,
957,
15,
9629,
15,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
15,
6977,
4537,
8476,
401,
288,
298,
835,
582,
6928,
12,
288,
298,
6691,
582,
469,
355,
298,
25372,
63,
344,
582,
841,
2898,
16771,
12,
355,
298,
25372,
63,
2227,
582,
298,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
401,
355,
298,
1213,
582,
298,
264,
26,
2662,
4292,
699,
1065,
386,
266,
699,
7570,
603,
27957,
820,
89,
371,
2084,
75,
13765,
543,
3872,
355,
298,
4196,
582,
1109,
12,
355,
298,
3397,
582,
2069,
12,
355,
298,
835,
582,
6928,
12,
355,
298,
2969,
582,
769,
12,
288,
1660,
267,
9998,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
15645,
15,
71,
56,
80,
43,
90,
74,
71,
41,
344,
33,
15,
1080,
14,
1360,
1288,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1336,
304,
267,
291,
14,
25372,
63,
2227,
275,
1336,
14,
923,
8,
17,
9,
267,
1166,
275,
11491,
15,
273,
23135,
19655,
1674,
908,
8,
277,
14,
1231,
12,
291,
14,
25372,
63,
2227,
9,
267,
598,
17787,
11039,
855,
826,
721,
277,
12,
1336,
12,
1166,
9,
339,
347,
3341,
8,
277,
12,
2034,
304,
267,
2323,
275,
469,
288,
298,
28900,
2,
260,
520,
291,
14,
25372,
63,
633,
12,
288,
298,
56,
13,
17935,
13,
3007,
582,
298,
4317,
10441,
401,
267,
789,
267,
1790,
275,
291,
14,
1069,
8,
288,
291,
14,
1231,
435,
3286,
12774,
15,
1178,
14,
26146,
401,
1083,
628,
4030,
401,
2323,
29,
2139,
12,
267,
7092,
505,
398,
1862,
275,
469,
288,
298,
56,
13,
2817,
582,
1790,
12,
288,
298,
2227,
2,
221,
520,
291,
14,
25372,
63,
2227,
12,
288,
14220,
258,
520,
1109,
8,
521,
14,
521,
4000,
267,
789,
267,
291,
14,
576,
275,
666,
275,
291,
14,
1069,
8,
288,
291,
14,
1231,
435,
3286,
12774,
15,
27074,
14,
26146,
401,
1862,
29,
1162,
12,
2323,
29,
2139,
12,
267,
7092,
1001,
342,
398,
2538,
275,
1318,
14,
5005,
8,
1606,
12,
3886,
1213,
7166,
15683,
1213,
9579,
59,
16,
1055,
1913,
342,
267,
2538,
12,
5501,
486,
17787,
63,
344,
275,
2538,
14,
25817,
10064,
531,
398,
372,
469,
288,
298,
25372,
63,
344,
2,
221,
520,
1318,
14,
1122,
63,
442,
8,
25372,
63,
344,
395,
288,
298,
25372,
63,
2227,
582,
291,
14,
25372,
63,
2227,
12,
288,
298,
1213,
2,
755,
520,
1318,
14,
22726,
8,
1213,
4439,
1046,
2522,
288,
298,
4196,
2,
755,
520,
666,
905,
16595,
2255,
288,
298,
3397,
2,
755,
520,
666,
905,
10417,
2255,
288,
298,
2969,
2,
263,
520,
666,
905,
2969,
4140,
1294,
11854,
1288,
288,
298,
835,
2,
755,
520,
822,
8,
576,
905,
4782,
10252,
267,
789,
339,
347,
5935,
8,
277,
12,
2034,
304,
267,
367,
1834,
315,
291,
14,
576,
905,
4782,
6229,
288,
1995,
298,
2859,
5424,
435,
1834,
905,
1569,
6417,
2255,
1834,
421,
199,
533,
481,
527,
75,
707,
5278,
11039,
8,
11039,
304,
272,
408,
11039,
367,
2754,
2058,
641,
289,
527,
75,
707,
14,
957,
624,
272,
4637,
275,
298,
31958,
75,
707,
2,
272,
1007,
3710,
275,
298,
1733,
2,
272,
1738,
275,
298,
2859,
921,
31958,
75,
707,
14,
957,
2,
272,
3851,
275,
519,
2,
5169,
2859,
14144,
5547,
31958,
75,
707,
4537,
957,
29478,
5169,
1733,
92,
1606,
2447,
6977,
2924,
272,
511,
275,
334,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
1733,
15,
581,
63,
3519,
11171,
4993,
10665,
469,
288,
298,
3401,
582,
481,
527,
75,
707,
39,
17787,
11039,
14,
3401,
12,
288,
298,
835,
582,
298,
8119,
6335,
401,
267,
9998,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
1606,
15,
19,
15,
3519,
11171,
4993,
15,
9161,
15,
1288,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1336,
304,
267,
18925,
855,
826,
721,
277,
12,
1336,
9,
267,
291,
14,
515,
275,
1336,
14,
923,
8,
17,
9,
339,
347,
2974,
8,
277,
304,
267,
1166,
275,
291,
14,
1231,
435,
291,
14,
515,
267,
666,
275,
2420,
63,
22677,
582,
481,
527,
75,
707,
39,
17787,
11039,
93,
398,
1830,
715,
26,
288,
2034,
275,
291,
14,
1069,
8,
633,
680,
505,
288,
367,
931,
315,
1318,
14,
5005,
63,
1661,
8,
490,
2034,
12,
283,
533,
628,
12475,
63,
6226,
8186,
65,
4369,
628,
297,
5522,
735,
355,
1995,
6430,
14,
3737,
12,
291,
14,
1231,
435,
931,
12,
666,
953,
6497,
275,
1318,
14,
5005,
8,
1606,
12,
283,
533,
628,
5856,
8186,
3751,
4206,
12696,
6,
3308,
15337,
3308,
22257,
5832,
16,
61,
288,
340,
440,
6497,
26,
355,
372,
288,
1166,
275,
291,
14,
1231,
435,
1318,
14,
264,
400,
1957,
8,
5856,
12,
283,
6399,
628,
297,
5522,
5832,
16,
61,
199,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
20312,
603,
7455,
481,
13733,
22276,
1189,
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,
199,
624,
11039,
83,
367,
4178,
921,
31958,
75,
707,
14,
957,
15,
624,
199,
199,
504,
1275,
2330,
492,
598,
17787,
11039,
12,
18925,
12,
6430,
199,
504,
2508,
492,
1318,
199,
646,
900,
421,
199,
533,
481,
527,
75,
707,
39,
17787,
11039,
8,
39,
17787,
11039,
304,
272,
408,
11039,
367,
1834,
486,
4598,
1996,
641,
289,
527,
75,
707,
14,
957,
624,
272,
4637,
275,
298,
31958,
75,
707,
2,
272,
1738,
275,
298,
2859,
921,
31958,
75,
707,
14,
957,
2,
272,
3851,
275,
519,
2,
5169,
2859,
14144,
5547,
31958,
75,
707,
4537,
957,
32576,
273,
23135,
92,
15645,
2447,
7059,
10197,
3,
2807,
2924,
272,
511,
275,
334,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
273,
23135,
15,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
10665,
469,
288,
298,
3401,
582,
519,
2,
2859,
921,
73,
60,
68,
26240,
31958,
75,
707,
14,
957,
15,
9629,
15,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
15,
6977,
4537,
8476,
401,
288,
298,
835,
582,
6928,
12,
288,
298,
6691,
582,
469,
355,
298,
25372,
63,
344,
582,
841,
2898,
16771,
12,
355,
298,
25372,
63,
2227,
582,
298,
68,
16,
39,
29726,
90,
56,
82,
8656,
53,
401,
355,
298,
1213,
582,
298,
264,
26,
2662,
4292,
699,
1065,
386,
266,
699,
7570,
603,
27957,
820,
89,
371,
2084,
75,
13765,
543,
3872,
355,
298,
4196,
582,
1109,
12,
355,
298,
3397,
582,
2069,
12,
355,
298,
835,
582,
6928,
12,
355,
298,
2969,
582,
769,
12,
288,
1660,
267,
9998,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
15645,
15,
71,
56,
80,
43,
90,
74,
71,
41,
344,
33,
15,
1080,
14,
1360,
1288,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1336,
304,
267,
291,
14,
25372,
63,
2227,
275,
1336,
14,
923,
8,
17,
9,
267,
1166,
275,
11491,
15,
273,
23135,
19655,
1674,
908,
8,
277,
14,
1231,
12,
291,
14,
25372,
63,
2227,
9,
267,
598,
17787,
11039,
855,
826,
721,
277,
12,
1336,
12,
1166,
9,
339,
347,
3341,
8,
277,
12,
2034,
304,
267,
2323,
275,
469,
288,
298,
28900,
2,
260,
520,
291,
14,
25372,
63,
633,
12,
288,
298,
56,
13,
17935,
13,
3007,
582,
298,
4317,
10441,
401,
267,
789,
267,
1790,
275,
291,
14,
1069,
8,
288,
291,
14,
1231,
435,
3286,
12774,
15,
1178,
14,
26146,
401,
1083,
628,
4030,
401,
2323,
29,
2139,
12,
267,
7092,
505,
398,
1862,
275,
469,
288,
298,
56,
13,
2817,
582,
1790,
12,
288,
298,
2227,
2,
221,
520,
291,
14,
25372,
63,
2227,
12,
288,
14220,
258,
520,
1109,
8,
521,
14,
521,
4000,
267,
789,
267,
291,
14,
576,
275,
666,
275,
291,
14,
1069,
8,
288,
291,
14,
1231,
435,
3286,
12774,
15,
27074,
14,
26146,
401,
1862,
29,
1162,
12,
2323,
29,
2139,
12,
267,
7092,
1001,
342,
398,
2538,
275,
1318,
14,
5005,
8,
1606,
12,
3886,
1213,
7166,
15683,
1213,
9579,
59,
16,
1055,
1913,
342,
267,
2538,
12,
5501,
486,
17787,
63,
344,
275,
2538,
14,
25817,
10064,
531,
398,
372,
469,
288,
298,
25372,
63,
344,
2,
221,
520,
1318,
14,
1122,
63,
442,
8,
25372,
63,
344,
395,
288,
298,
25372,
63,
2227,
582,
291,
14,
25372,
63,
2227,
12,
288,
298,
1213,
2,
755,
520,
1318,
14,
22726,
8,
1213,
4439,
1046,
2522,
288,
298,
4196,
2,
755,
520,
666,
905,
16595,
2255,
288,
298,
3397,
2,
755,
520,
666,
905,
10417,
2255,
288,
298,
2969,
2,
263,
520,
666,
905,
2969,
4140,
1294,
11854,
1288,
288,
298,
835,
2,
755,
520,
822,
8,
576,
905,
4782,
10252,
267,
789,
339,
347,
5935,
8,
277,
12,
2034,
304,
267,
367,
1834,
315,
291,
14,
576,
905,
4782,
6229,
288,
1995,
298,
2859,
5424,
435,
1834,
905,
1569,
6417,
2255,
1834,
421,
199,
533,
481,
527,
75,
707,
5278,
11039,
8,
11039,
304,
272,
408,
11039,
367,
2754,
2058,
641,
289,
527,
75,
707,
14,
957,
624,
272,
4637,
275,
298,
31958,
75,
707,
2,
272,
1007,
3710,
275,
298,
1733,
2,
272,
1738,
275,
298,
2859,
921,
31958,
75,
707,
14,
957,
2,
272,
3851,
275,
519,
2,
5169,
2859,
14144,
5547,
31958,
75,
707,
4537,
957,
29478,
5169,
1733,
92,
1606,
2447,
6977,
2924,
272,
511,
275,
334,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
1733,
15,
581,
63,
3519,
11171,
4993,
10665,
469,
288,
298,
3401,
582,
481,
527,
75,
707,
39,
17787,
11039,
14,
3401,
12,
288,
298,
835,
582,
298,
8119,
6335,
401,
267,
9998,
267,
1689,
2859,
921,
31958,
75,
707,
14,
957,
15,
1606,
15,
19,
15,
3519,
11171,
4993,
15,
9161,
15,
1288,
272,
776,
339,
347,
636,
826,
721,
277,
12,
1336,
304,
267,
18925,
855,
826,
721,
277,
12,
1336,
9,
267,
291,
14,
515,
275,
1336,
14,
923,
8,
17,
9,
339,
347,
2974,
8,
277,
304,
267,
1166,
275,
291,
14,
1231,
435,
291,
14,
515,
267,
666,
275,
2420,
63,
22677,
582,
481,
527,
75,
707,
39,
17787,
11039,
93,
398,
1830,
715,
26,
288,
2034,
275,
291,
14,
1069,
8,
633,
680,
505,
288,
367,
931,
315,
1318,
14,
5005,
63,
1661,
8,
490,
2034,
12,
283,
533,
628,
12475,
63,
6226,
8186,
65,
4369,
628,
297,
5522,
735,
355,
1995,
6430,
14,
3737,
12,
291,
14,
1231,
435,
931,
12,
666,
953,
6497,
275,
1318,
14,
5005,
8,
1606,
12,
283,
533,
628,
5856,
8186,
3751,
4206,
12696,
6,
3308,
15337,
3308,
22257,
5832,
16,
61,
288,
340,
440,
6497,
26,
355,
372,
288,
1166,
275,
291,
14,
1231,
435,
1318,
14,
264,
400,
1957,
8,
5856,
12,
283,
6399,
628,
297,
5522,
5832,
16,
61,
199,
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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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,
0,
0
] |
th0mmeke/toyworld
|
evaluators/evaluator_summary.py
|
1
|
5124
|
"""
Created on 6/05/2013
@author: thom
"""
import logging
import string
from rdkit.Chem import AllChem as Chem
from evaluator import Evaluator
from molecular_population import MolecularPopulation
from molecule import Molecule
class EvaluatorSummary(Evaluator):
def get_result_titles(self):
return ["Number of unique reactants", "Number of reactant types", "Maximum times a molecule was a reactant", "Length of longest molecule"]
def evaluate(self, results_filename, **kwargs):
"""Calculates some interesting statistics for the experimental run.
:rtype: Number of unique reactants, number of reactant types, maximum times a molecule was a reactant, length of longest molecule"""
results = Evaluator.load_results(results_filename)
population = MolecularPopulation(population=results['initial_population'], reactions=results['reactions'], size=100)
initial_population = population.get_slice_by_time([0])
initial_average_ke = results['initial_kinetic_energy'] / (initial_population.get_population_size() * 1.0)
final_average_ke = results['final_kinetic_energy'] / (population.get_population_size() * 1.0)
changing = len(population.get_changing_items())
changing_percent = (changing * 1.0 / len(population.get_items())) * 100.0
supplied_items = set(item for item in initial_population.get_items() if initial_population.get_quantity(item) > 0)
final_items = set(item for item in population.get_items() if population.get_quantity(item) > 0)
supplied_atom_count = sum([Molecule(i).GetNumAtoms() * initial_population.get_quantity(i) for i in supplied_items])
final_atom_count = sum([Molecule(i).GetNumAtoms() * population.get_quantity(i) for i in final_items])
iteration = collisions = 0
reactant_ids = {}
reactant_smiles = {}
keys = set()
for reaction in results['reactions']:
keys = keys.union(set(reaction.keys()))
# if ReactionNetwork._is_reaction(reaction):
for reactant in reaction['reactants']:
try:
reactant_ids[reactant['id']].append(iteration)
except:
reactant_ids[reactant['id']] = [iteration]
try:
reactant_smiles[reactant['smiles']].append(iteration)
except:
reactant_smiles[reactant['smiles']] = [iteration]
iteration += 1
assert iteration + collisions == len(results['reactions'])
logging.info("We began with {} types of items; there were {} active types at the end out of {} (both supplied and discovered) overall".format(
len(supplied_items), len(final_items), len(population.get_items())))
logging.info("The initial population size was {}; at the end, {}".format(initial_population.get_population_size(), population.get_population_size()))
logging.info("The initial average ke was {}; at the end, {}".format(initial_average_ke, final_average_ke))
logging.info("Approximately {:.2f}% of the item types ({}) changed quantity during the simulation, while {:.2f}% didn't change at all".format(
changing_percent, changing, 100 - changing_percent))
logging.info("The simulation ran for t={} and {} iterations ({} reactions and {} simple collisions)".format(results['t'], len(results['reactions']), iteration, collisions))
logging.info("Supplied atoms = {}, final atoms = {}".format(supplied_atom_count, final_atom_count))
if supplied_atom_count != final_atom_count:
logging.info("Food items detected")
logging.info("There were {} unique reactants and {} reactant types".format(len(reactant_ids), len(reactant_smiles)))
sorted_items = sorted(final_items, key=lambda t: len(t), reverse=True)
logging.info("The longest molecule type was {}".format(sorted_items[0]))
reactant_smiles_occurences = [len(occurences) for id, occurences in reactant_smiles.iteritems()]
logging.info("{} molecule types were a reactant in more than one reaction".format(len([x for x in reactant_smiles_occurences if x > 1])))
logging.info("The minimum and maximum number of times a molecule type served as a reactant was {} and {}".format(min(reactant_smiles_occurences), max(reactant_smiles_occurences)))
reactant_id_occurences = [len(occurences) for id, occurences in reactant_ids.iteritems()]
logging.info("{} molecules were a reactant in more than one reaction (should be zero)".format(len([x for x in reactant_id_occurences if x > 1])))
final_population_sorted = sorted([(item, population.get_quantity(item)) for item in final_items], key=lambda t: t[1], reverse=True)
final_population_string = ["{} x {}".format(item, quantity) for item, quantity in final_population_sorted]
logging.info("Final population = {}".format(string.join(final_population_string, ", ")))
return len(reactant_ids), len(reactant_smiles), max(reactant_smiles_occurences), len(sorted_items[0])
|
gpl-3.0
|
[
624,
199,
10502,
641,
1227,
15,
1717,
15,
6965,
199,
199,
32,
2502,
26,
294,
676,
199,
624,
421,
199,
646,
2050,
199,
646,
1059,
199,
199,
504,
11517,
6065,
14,
20335,
77,
492,
2900,
20335,
77,
465,
445,
27037,
199,
199,
504,
29207,
492,
16494,
16530,
199,
504,
1303,
10251,
2238,
63,
16003,
492,
3930,
10251,
2238,
31824,
199,
504,
26350,
492,
3930,
14413,
421,
199,
533,
16494,
16530,
10407,
8,
10006,
16530,
304,
339,
347,
664,
63,
1099,
63,
8916,
8,
277,
304,
267,
372,
2097,
3259,
402,
3747,
295,
2442,
2285,
401,
298,
3259,
402,
295,
2442,
867,
2943,
401,
298,
10915,
5431,
282,
26350,
1990,
282,
295,
2442,
867,
401,
298,
4625,
402,
21303,
26350,
937,
339,
347,
9352,
8,
277,
12,
2058,
63,
1501,
12,
1011,
958,
304,
267,
408,
13862,
2335,
2005,
19604,
11076,
367,
314,
22820,
1255,
14,
398,
520,
4500,
26,
4860,
402,
3747,
295,
2442,
2285,
12,
1329,
402,
295,
2442,
867,
2943,
12,
5696,
5431,
282,
26350,
1990,
282,
295,
2442,
867,
12,
2582,
402,
21303,
26350,
624,
398,
2058,
275,
16494,
16530,
14,
912,
63,
2604,
8,
2604,
63,
1501,
9,
398,
16423,
275,
3930,
10251,
2238,
31824,
8,
16003,
29,
2604,
459,
2747,
63,
16003,
995,
295,
3723,
29,
2604,
459,
264,
3723,
995,
1568,
29,
1960,
9,
398,
2536,
63,
16003,
275,
16423,
14,
362,
63,
5224,
63,
991,
63,
521,
779,
16,
566,
267,
2536,
63,
8536,
63,
415,
275,
2058,
459,
2747,
63,
75,
1132,
764,
63,
8443,
418,
1182,
334,
2747,
63,
16003,
14,
362,
63,
16003,
63,
890,
342,
627,
413,
14,
16,
9,
398,
4242,
63,
8536,
63,
415,
275,
2058,
459,
5094,
63,
75,
1132,
764,
63,
8443,
418,
1182,
334,
16003,
14,
362,
63,
16003,
63,
890,
342,
627,
413,
14,
16,
9,
398,
13729,
275,
822,
8,
16003,
14,
362,
63,
29131,
63,
1744,
1012,
267,
13729,
63,
7045,
275,
334,
29131,
627,
413,
14,
16,
1182,
822,
8,
16003,
14,
362,
63,
1744,
4059,
627,
2948,
14,
16,
267,
6841,
63,
1744,
275,
663,
8,
1053,
367,
1242,
315,
2536,
63,
16003,
14,
362,
63,
1744,
342,
340,
2536,
63,
16003,
14,
362,
63,
10577,
8,
1053,
9,
690,
378,
9,
267,
4242,
63,
1744,
275,
663,
8,
1053,
367,
1242,
315,
16423,
14,
362,
63,
1744,
342,
340,
16423,
14,
362,
63,
10577,
8,
1053,
9,
690,
378,
9,
398,
6841,
63,
4188,
63,
835,
275,
3089,
779,
3716,
14413,
8,
73,
680,
1002,
5667,
33,
12606,
342,
627,
2536,
63,
16003,
14,
362,
63,
10577,
8,
73,
9,
367,
284,
315,
6841,
63,
1744,
566,
267,
4242,
63,
4188,
63,
835,
275,
3089,
779,
3716,
14413,
8,
73,
680,
1002,
5667,
33,
12606,
342,
627,
16423,
14,
362,
63,
10577,
8,
73,
9,
367,
284,
315,
4242,
63,
1744,
566,
398,
8494,
275,
30063,
275,
378,
267,
295,
2442,
867,
63,
1580,
275,
1052,
267,
295,
2442,
867,
63,
3300,
22894,
275,
1052,
267,
2883,
275,
663,
342,
398,
367,
26909,
315,
2058,
459,
264,
3723,
2565,
953,
2883,
275,
2883,
14,
8888,
8,
409,
8,
29834,
14,
1612,
4059,
953,
327,
340,
799,
1287,
4491,
423,
374,
63,
29834,
8,
29834,
304,
953,
367,
295,
2442,
867,
315,
26909,
459,
264,
2442,
2285,
2565,
355,
862,
26,
490,
295,
2442,
867,
63,
1580,
59,
264,
2442,
867,
459,
344,
418,
1055,
740,
8,
12575,
9,
355,
871,
26,
490,
295,
2442,
867,
63,
1580,
59,
264,
2442,
867,
459,
344,
6538,
275,
359,
12575,
61,
2234,
862,
26,
490,
295,
2442,
867,
63,
3300,
22894,
59,
264,
2442,
867,
459,
3300,
22894,
418,
1055,
740,
8,
12575,
9,
355,
871,
26,
490,
295,
2442,
867,
63,
3300,
22894,
59,
264,
2442,
867,
459,
3300,
22894,
6538,
275,
359,
12575,
61,
953,
8494,
847,
413,
398,
702,
8494,
435,
30063,
508,
822,
8,
2604,
459,
264,
3723,
1105,
398,
2050,
14,
815,
480,
6004,
506,
24975,
543,
1052,
2943,
402,
2974,
27,
2337,
4898,
1052,
4702,
2943,
737,
314,
1284,
734,
402,
1052,
334,
10727,
6841,
436,
24983,
9,
20347,
1674,
908,
8,
288,
822,
8,
22525,
63,
1744,
395,
822,
8,
5094,
63,
1744,
395,
822,
8,
16003,
14,
362,
63,
1744,
16890,
267,
2050,
14,
815,
480,
1918,
2536,
16423,
1568,
1990,
27978,
737,
314,
1284,
12,
8352,
908,
8,
2747,
63,
16003,
14,
362,
63,
16003,
63,
890,
1062,
16423,
14,
362,
63,
16003,
63,
890,
4059,
267,
2050,
14,
815,
480,
1918,
2536,
8095,
10074,
1990,
27978,
737,
314,
1284,
12,
8352,
908,
8,
2747,
63,
8536,
63,
415,
12,
4242,
63,
8536,
63,
415,
430,
267,
2050,
14,
815,
480,
13117,
8221,
6897,
590,
469,
14010,
18,
70,
22109,
402,
314,
1242,
2943,
11459,
1552,
2896,
12524,
5309,
314,
17625,
12,
1830,
469,
14010,
18,
70,
22109,
9980,
1133,
1570,
737,
1006,
1674,
908,
8,
288,
13729,
63,
7045,
12,
13729,
12,
2948,
446,
13729,
63,
7045,
430,
267,
2050,
14,
815,
480,
1918,
17625,
21471,
367,
307,
7622,
436,
1052,
10615,
334,
2440,
295,
3723,
436,
1052,
3486,
30063,
30351,
908,
8,
2604,
459,
84,
995,
822,
8,
2604,
459,
264,
3723,
3815,
8494,
12,
30063,
430,
267,
2050,
14,
815,
480,
17127,
1857,
14503,
275,
5479,
4242,
14503,
275,
8352,
908,
8,
22525,
63,
4188,
63,
835,
12,
4242,
63,
4188,
63,
835,
430,
267,
340,
6841,
63,
4188,
63,
835,
1137,
4242,
63,
4188,
63,
835,
26,
288,
2050,
14,
815,
480,
15563,
364,
2974,
10501,
531,
267,
2050,
14,
815,
480,
10924,
4898,
1052,
3747,
295,
2442,
2285,
436,
1052,
295,
2442,
867,
2943,
1674,
908,
8,
552,
8,
264,
2442,
867,
63,
1580,
395,
822,
8,
264,
2442,
867,
63,
3300,
22894,
1724,
267,
3355,
63,
1744,
275,
3355,
8,
5094,
63,
1744,
12,
790,
29,
2734,
307,
26,
822,
8,
84,
395,
3837,
29,
549,
9,
267,
2050,
14,
815,
480,
1918,
21303,
26350,
730,
1990,
8352,
908,
8,
5917,
63,
1744,
59,
16,
2459,
398,
295,
2442,
867,
63,
3300,
22894,
63,
679,
67,
608,
78,
823,
275,
359,
552,
8,
679,
67,
608,
78,
823,
9,
367
] |
[
199,
10502,
641,
1227,
15,
1717,
15,
6965,
199,
199,
32,
2502,
26,
294,
676,
199,
624,
421,
199,
646,
2050,
199,
646,
1059,
199,
199,
504,
11517,
6065,
14,
20335,
77,
492,
2900,
20335,
77,
465,
445,
27037,
199,
199,
504,
29207,
492,
16494,
16530,
199,
504,
1303,
10251,
2238,
63,
16003,
492,
3930,
10251,
2238,
31824,
199,
504,
26350,
492,
3930,
14413,
421,
199,
533,
16494,
16530,
10407,
8,
10006,
16530,
304,
339,
347,
664,
63,
1099,
63,
8916,
8,
277,
304,
267,
372,
2097,
3259,
402,
3747,
295,
2442,
2285,
401,
298,
3259,
402,
295,
2442,
867,
2943,
401,
298,
10915,
5431,
282,
26350,
1990,
282,
295,
2442,
867,
401,
298,
4625,
402,
21303,
26350,
937,
339,
347,
9352,
8,
277,
12,
2058,
63,
1501,
12,
1011,
958,
304,
267,
408,
13862,
2335,
2005,
19604,
11076,
367,
314,
22820,
1255,
14,
398,
520,
4500,
26,
4860,
402,
3747,
295,
2442,
2285,
12,
1329,
402,
295,
2442,
867,
2943,
12,
5696,
5431,
282,
26350,
1990,
282,
295,
2442,
867,
12,
2582,
402,
21303,
26350,
624,
398,
2058,
275,
16494,
16530,
14,
912,
63,
2604,
8,
2604,
63,
1501,
9,
398,
16423,
275,
3930,
10251,
2238,
31824,
8,
16003,
29,
2604,
459,
2747,
63,
16003,
995,
295,
3723,
29,
2604,
459,
264,
3723,
995,
1568,
29,
1960,
9,
398,
2536,
63,
16003,
275,
16423,
14,
362,
63,
5224,
63,
991,
63,
521,
779,
16,
566,
267,
2536,
63,
8536,
63,
415,
275,
2058,
459,
2747,
63,
75,
1132,
764,
63,
8443,
418,
1182,
334,
2747,
63,
16003,
14,
362,
63,
16003,
63,
890,
342,
627,
413,
14,
16,
9,
398,
4242,
63,
8536,
63,
415,
275,
2058,
459,
5094,
63,
75,
1132,
764,
63,
8443,
418,
1182,
334,
16003,
14,
362,
63,
16003,
63,
890,
342,
627,
413,
14,
16,
9,
398,
13729,
275,
822,
8,
16003,
14,
362,
63,
29131,
63,
1744,
1012,
267,
13729,
63,
7045,
275,
334,
29131,
627,
413,
14,
16,
1182,
822,
8,
16003,
14,
362,
63,
1744,
4059,
627,
2948,
14,
16,
267,
6841,
63,
1744,
275,
663,
8,
1053,
367,
1242,
315,
2536,
63,
16003,
14,
362,
63,
1744,
342,
340,
2536,
63,
16003,
14,
362,
63,
10577,
8,
1053,
9,
690,
378,
9,
267,
4242,
63,
1744,
275,
663,
8,
1053,
367,
1242,
315,
16423,
14,
362,
63,
1744,
342,
340,
16423,
14,
362,
63,
10577,
8,
1053,
9,
690,
378,
9,
398,
6841,
63,
4188,
63,
835,
275,
3089,
779,
3716,
14413,
8,
73,
680,
1002,
5667,
33,
12606,
342,
627,
2536,
63,
16003,
14,
362,
63,
10577,
8,
73,
9,
367,
284,
315,
6841,
63,
1744,
566,
267,
4242,
63,
4188,
63,
835,
275,
3089,
779,
3716,
14413,
8,
73,
680,
1002,
5667,
33,
12606,
342,
627,
16423,
14,
362,
63,
10577,
8,
73,
9,
367,
284,
315,
4242,
63,
1744,
566,
398,
8494,
275,
30063,
275,
378,
267,
295,
2442,
867,
63,
1580,
275,
1052,
267,
295,
2442,
867,
63,
3300,
22894,
275,
1052,
267,
2883,
275,
663,
342,
398,
367,
26909,
315,
2058,
459,
264,
3723,
2565,
953,
2883,
275,
2883,
14,
8888,
8,
409,
8,
29834,
14,
1612,
4059,
953,
327,
340,
799,
1287,
4491,
423,
374,
63,
29834,
8,
29834,
304,
953,
367,
295,
2442,
867,
315,
26909,
459,
264,
2442,
2285,
2565,
355,
862,
26,
490,
295,
2442,
867,
63,
1580,
59,
264,
2442,
867,
459,
344,
418,
1055,
740,
8,
12575,
9,
355,
871,
26,
490,
295,
2442,
867,
63,
1580,
59,
264,
2442,
867,
459,
344,
6538,
275,
359,
12575,
61,
2234,
862,
26,
490,
295,
2442,
867,
63,
3300,
22894,
59,
264,
2442,
867,
459,
3300,
22894,
418,
1055,
740,
8,
12575,
9,
355,
871,
26,
490,
295,
2442,
867,
63,
3300,
22894,
59,
264,
2442,
867,
459,
3300,
22894,
6538,
275,
359,
12575,
61,
953,
8494,
847,
413,
398,
702,
8494,
435,
30063,
508,
822,
8,
2604,
459,
264,
3723,
1105,
398,
2050,
14,
815,
480,
6004,
506,
24975,
543,
1052,
2943,
402,
2974,
27,
2337,
4898,
1052,
4702,
2943,
737,
314,
1284,
734,
402,
1052,
334,
10727,
6841,
436,
24983,
9,
20347,
1674,
908,
8,
288,
822,
8,
22525,
63,
1744,
395,
822,
8,
5094,
63,
1744,
395,
822,
8,
16003,
14,
362,
63,
1744,
16890,
267,
2050,
14,
815,
480,
1918,
2536,
16423,
1568,
1990,
27978,
737,
314,
1284,
12,
8352,
908,
8,
2747,
63,
16003,
14,
362,
63,
16003,
63,
890,
1062,
16423,
14,
362,
63,
16003,
63,
890,
4059,
267,
2050,
14,
815,
480,
1918,
2536,
8095,
10074,
1990,
27978,
737,
314,
1284,
12,
8352,
908,
8,
2747,
63,
8536,
63,
415,
12,
4242,
63,
8536,
63,
415,
430,
267,
2050,
14,
815,
480,
13117,
8221,
6897,
590,
469,
14010,
18,
70,
22109,
402,
314,
1242,
2943,
11459,
1552,
2896,
12524,
5309,
314,
17625,
12,
1830,
469,
14010,
18,
70,
22109,
9980,
1133,
1570,
737,
1006,
1674,
908,
8,
288,
13729,
63,
7045,
12,
13729,
12,
2948,
446,
13729,
63,
7045,
430,
267,
2050,
14,
815,
480,
1918,
17625,
21471,
367,
307,
7622,
436,
1052,
10615,
334,
2440,
295,
3723,
436,
1052,
3486,
30063,
30351,
908,
8,
2604,
459,
84,
995,
822,
8,
2604,
459,
264,
3723,
3815,
8494,
12,
30063,
430,
267,
2050,
14,
815,
480,
17127,
1857,
14503,
275,
5479,
4242,
14503,
275,
8352,
908,
8,
22525,
63,
4188,
63,
835,
12,
4242,
63,
4188,
63,
835,
430,
267,
340,
6841,
63,
4188,
63,
835,
1137,
4242,
63,
4188,
63,
835,
26,
288,
2050,
14,
815,
480,
15563,
364,
2974,
10501,
531,
267,
2050,
14,
815,
480,
10924,
4898,
1052,
3747,
295,
2442,
2285,
436,
1052,
295,
2442,
867,
2943,
1674,
908,
8,
552,
8,
264,
2442,
867,
63,
1580,
395,
822,
8,
264,
2442,
867,
63,
3300,
22894,
1724,
267,
3355,
63,
1744,
275,
3355,
8,
5094,
63,
1744,
12,
790,
29,
2734,
307,
26,
822,
8,
84,
395,
3837,
29,
549,
9,
267,
2050,
14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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
khchine5/opal
|
opal/tests/test_utils.py
|
1
|
2258
|
"""
Unittests for opal.utils
"""
import sys
from django.test import TestCase
from django.db.models import ForeignKey, CharField
from mock import patch
from opal.core.test import OpalTestCase
from opal import utils
class StringportTestCase(TestCase):
def test_import(self):
import collections
self.assertEqual(collections, utils.stringport('collections'))
def test_import_no_period(self):
with self.assertRaises(ImportError):
utils.stringport('wotcha')
def test_import_perioded_thing(self):
self.assertEqual(TestCase, utils.stringport('django.test.TestCase'))
def test_empty_name_is_valueerror(self):
with self.assertRaises(ValueError):
utils.stringport('')
class ItersubclassesTestCase(TestCase):
def test_tree_structure(self):
class A(object):
pass
class B(A):
pass
class C(B, utils.AbstractBase):
pass
class D(C):
pass
results = {i for i in utils._itersubclasses(A)}
self.assertEqual(results, set([B, D]))
def test_old_style_classes(self):
if sys.version_info[0] < 3:
class Old: pass
with self.assertRaises(TypeError):
list(utils._itersubclasses(Old))
def test_when_called_with_type(self):
expected = type.__subclasses__(type)
for s in expected:
self.assertIn(s, list(utils._itersubclasses(type)))
class FindTemplateTestCase(TestCase):
def test_find_template_first_exists(self):
self.assertEqual('base.html',
utils.find_template(['base.html', 'baser.html', 'basest.html']))
def test_find_template_one_exists(self):
self.assertEqual('base.html',
utils.find_template(['baser.html', 'base.html', 'basest.html']))
def test_find_template_none_exists(self):
self.assertEqual(None, utils.find_template(['baser.html', 'basest.html']))
class WriteTestCase(OpalTestCase):
def test_write(self):
with patch.object(utils, 'sys') as mocksys:
mocksys.argv = ['not', 'te$targs']
utils.write('this')
mocksys.stdout.write.assert_called_with('this\n')
|
agpl-3.0
|
[
624,
199,
1358,
1770,
83,
367,
1687,
279,
14,
1208,
199,
624,
199,
646,
984,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
697,
14,
992,
492,
12718,
12,
12064,
199,
504,
1683,
492,
3371,
199,
199,
504,
1687,
279,
14,
1018,
14,
396,
492,
9319,
279,
1746,
199,
199,
504,
1687,
279,
492,
3778,
199,
199,
533,
2624,
719,
1746,
8,
1746,
304,
339,
347,
511,
63,
646,
8,
277,
304,
267,
492,
5055,
267,
291,
14,
629,
8,
7882,
12,
3778,
14,
875,
719,
360,
7882,
1333,
339,
347,
511,
63,
646,
63,
889,
63,
5191,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
3778,
14,
875,
719,
360,
87,
357,
9518,
358,
339,
347,
511,
63,
646,
63,
5490,
380,
68,
63,
2127,
8,
277,
304,
267,
291,
14,
629,
8,
1746,
12,
3778,
14,
875,
719,
360,
1176,
14,
396,
14,
1746,
1333,
339,
347,
511,
63,
1667,
63,
354,
63,
374,
63,
585,
705,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
3778,
14,
875,
719,
8355,
421,
199,
533,
473,
878,
456,
2888,
1746,
8,
1746,
304,
272,
347,
511,
63,
2350,
63,
6976,
8,
277,
304,
267,
1021,
437,
8,
785,
304,
288,
986,
398,
1021,
699,
8,
33,
304,
288,
986,
398,
1021,
445,
8,
34,
12,
3778,
14,
8458,
1563,
304,
288,
986,
398,
1021,
577,
8,
35,
304,
288,
986,
398,
2058,
275,
469,
73,
367,
284,
315,
3778,
423,
15266,
456,
2888,
8,
33,
6769,
267,
291,
14,
629,
8,
2604,
12,
663,
779,
34,
12,
577,
2459,
339,
347,
511,
63,
1753,
63,
2487,
63,
2888,
8,
277,
304,
267,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
953,
1021,
21238,
26,
986,
288,
543,
291,
14,
1855,
8,
4333,
304,
355,
769,
8,
1208,
423,
15266,
456,
2888,
8,
16411,
430,
339,
347,
511,
63,
6526,
63,
3527,
63,
1045,
63,
466,
8,
277,
304,
267,
1420,
275,
730,
855,
19094,
721,
466,
9,
267,
367,
308,
315,
1420,
26,
288,
291,
14,
4080,
8,
83,
12,
769,
8,
1208,
423,
15266,
456,
2888,
8,
466,
1724,
421,
199,
533,
6668,
4231,
1746,
8,
1746,
304,
339,
347,
511,
63,
1623,
63,
1160,
63,
2246,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
360,
1095,
14,
1360,
297,
586,
3778,
14,
1623,
63,
1160,
2941,
1095,
14,
1360,
297,
283,
2470,
332,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
339,
347,
511,
63,
1623,
63,
1160,
63,
368,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
360,
1095,
14,
1360,
297,
586,
3778,
14,
1623,
63,
1160,
2941,
2470,
332,
14,
1360,
297,
283,
1095,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
339,
347,
511,
63,
1623,
63,
1160,
63,
3592,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
8,
403,
12,
3778,
14,
1623,
63,
1160,
2941,
2470,
332,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
421,
199,
533,
6990,
1746,
8,
4619,
279,
1746,
304,
339,
347,
511,
63,
952,
8,
277,
304,
267,
543,
3371,
14,
785,
8,
1208,
12,
283,
1274,
358,
465,
1683,
1274,
26,
288,
1683,
1274,
14,
3020,
275,
788,
1397,
297,
283,
266,
4,
84,
589,
418,
288,
3778,
14,
952,
360,
3749,
358,
288,
1683,
1274,
14,
2703,
14,
952,
14,
479,
63,
3527,
63,
1045,
360,
3749,
60,
78,
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
] |
[
199,
1358,
1770,
83,
367,
1687,
279,
14,
1208,
199,
624,
199,
646,
984,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
697,
14,
992,
492,
12718,
12,
12064,
199,
504,
1683,
492,
3371,
199,
199,
504,
1687,
279,
14,
1018,
14,
396,
492,
9319,
279,
1746,
199,
199,
504,
1687,
279,
492,
3778,
199,
199,
533,
2624,
719,
1746,
8,
1746,
304,
339,
347,
511,
63,
646,
8,
277,
304,
267,
492,
5055,
267,
291,
14,
629,
8,
7882,
12,
3778,
14,
875,
719,
360,
7882,
1333,
339,
347,
511,
63,
646,
63,
889,
63,
5191,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
17825,
304,
288,
3778,
14,
875,
719,
360,
87,
357,
9518,
358,
339,
347,
511,
63,
646,
63,
5490,
380,
68,
63,
2127,
8,
277,
304,
267,
291,
14,
629,
8,
1746,
12,
3778,
14,
875,
719,
360,
1176,
14,
396,
14,
1746,
1333,
339,
347,
511,
63,
1667,
63,
354,
63,
374,
63,
585,
705,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
3778,
14,
875,
719,
8355,
421,
199,
533,
473,
878,
456,
2888,
1746,
8,
1746,
304,
272,
347,
511,
63,
2350,
63,
6976,
8,
277,
304,
267,
1021,
437,
8,
785,
304,
288,
986,
398,
1021,
699,
8,
33,
304,
288,
986,
398,
1021,
445,
8,
34,
12,
3778,
14,
8458,
1563,
304,
288,
986,
398,
1021,
577,
8,
35,
304,
288,
986,
398,
2058,
275,
469,
73,
367,
284,
315,
3778,
423,
15266,
456,
2888,
8,
33,
6769,
267,
291,
14,
629,
8,
2604,
12,
663,
779,
34,
12,
577,
2459,
339,
347,
511,
63,
1753,
63,
2487,
63,
2888,
8,
277,
304,
267,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
953,
1021,
21238,
26,
986,
288,
543,
291,
14,
1855,
8,
4333,
304,
355,
769,
8,
1208,
423,
15266,
456,
2888,
8,
16411,
430,
339,
347,
511,
63,
6526,
63,
3527,
63,
1045,
63,
466,
8,
277,
304,
267,
1420,
275,
730,
855,
19094,
721,
466,
9,
267,
367,
308,
315,
1420,
26,
288,
291,
14,
4080,
8,
83,
12,
769,
8,
1208,
423,
15266,
456,
2888,
8,
466,
1724,
421,
199,
533,
6668,
4231,
1746,
8,
1746,
304,
339,
347,
511,
63,
1623,
63,
1160,
63,
2246,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
360,
1095,
14,
1360,
297,
586,
3778,
14,
1623,
63,
1160,
2941,
1095,
14,
1360,
297,
283,
2470,
332,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
339,
347,
511,
63,
1623,
63,
1160,
63,
368,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
360,
1095,
14,
1360,
297,
586,
3778,
14,
1623,
63,
1160,
2941,
2470,
332,
14,
1360,
297,
283,
1095,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
339,
347,
511,
63,
1623,
63,
1160,
63,
3592,
63,
2444,
8,
277,
304,
267,
291,
14,
629,
8,
403,
12,
3778,
14,
1623,
63,
1160,
2941,
2470,
332,
14,
1360,
297,
283,
1095,
270,
14,
1360,
5156,
421,
199,
533,
6990,
1746,
8,
4619,
279,
1746,
304,
339,
347,
511,
63,
952,
8,
277,
304,
267,
543,
3371,
14,
785,
8,
1208,
12,
283,
1274,
358,
465,
1683,
1274,
26,
288,
1683,
1274,
14,
3020,
275,
788,
1397,
297,
283,
266,
4,
84,
589,
418,
288,
3778,
14,
952,
360,
3749,
358,
288,
1683,
1274,
14,
2703,
14,
952,
14,
479,
63,
3527,
63,
1045,
360,
3749,
60,
78,
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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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
] |
pigate/mongo-python-driver
|
bson/son.py
|
68
|
8684
|
# Copyright 2009-2015 MongoDB, 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.
"""Tools for creating and manipulating SON, the Serialized Ocument Notation.
Regular dictionaries can be used instead of SON objects, but not when the order
of keys is important. A SON object can be used just like a normal Python
dictionary."""
import collections
import copy
import re
from bson.py3compat import iteritems
# This sort of sucks, but seems to be as good as it gets...
# This is essentially the same as re._pattern_type
RE_TYPE = type(re.compile(""))
class SON(dict):
"""SON data.
A subclass of dict that maintains ordering of keys and provides a
few extra niceties for dealing with SON. SON objects can be
converted to and from BSON.
The mapping from Python types to BSON types is as follows:
======================================= ============= ===================
Python Type BSON Type Supported Direction
======================================= ============= ===================
None null both
bool boolean both
int [#int]_ int32 / int64 py -> bson
long int64 py -> bson
`bson.int64.Int64` int64 both
float number (real) both
string string py -> bson
unicode string both
list array both
dict / `SON` object both
datetime.datetime [#dt]_ [#dt2]_ date both
`bson.regex.Regex` regex both
compiled re [#re]_ regex py -> bson
`bson.binary.Binary` binary both
`bson.objectid.ObjectId` oid both
`bson.dbref.DBRef` dbref both
None undefined bson -> py
unicode code bson -> py
`bson.code.Code` code py -> bson
unicode symbol bson -> py
bytes (Python 3) [#bytes]_ binary both
======================================= ============= ===================
Note that to save binary data it must be wrapped as an instance of
`bson.binary.Binary`. Otherwise it will be saved as a BSON string
and retrieved as unicode.
.. [#int] A Python int will be saved as a BSON int32 or BSON int64 depending
on its size. A BSON int32 will always decode to a Python int. A BSON
int64 will always decode to a :class:`~bson.int64.Int64`.
.. [#dt] datetime.datetime instances will be rounded to the nearest
millisecond when saved
.. [#dt2] all datetime.datetime instances are treated as *naive*. clients
should always use UTC.
.. [#re] :class:`~bson.regex.Regex` instances and regular expression
objects from ``re.compile()`` are both saved as BSON regular expressions.
BSON regular expressions are decoded as :class:`~bson.regex.Regex`
instances.
.. [#bytes] The bytes type from Python 3.x is encoded as BSON binary with
subtype 0. In Python 3.x it will be decoded back to bytes. In Python 2.x
it will be decoded to an instance of :class:`~bson.binary.Binary` with
subtype 0.
"""
def __init__(self, data=None, **kwargs):
self.__keys = []
dict.__init__(self)
self.update(data)
self.update(kwargs)
def __new__(cls, *args, **kwargs):
instance = super(SON, cls).__new__(cls, *args, **kwargs)
instance.__keys = []
return instance
def __repr__(self):
result = []
for key in self.__keys:
result.append("(%r, %r)" % (key, self[key]))
return "SON([%s])" % ", ".join(result)
def __setitem__(self, key, value):
if key not in self.__keys:
self.__keys.append(key)
dict.__setitem__(self, key, value)
def __delitem__(self, key):
self.__keys.remove(key)
dict.__delitem__(self, key)
def keys(self):
return list(self.__keys)
def copy(self):
other = SON()
other.update(self)
return other
# TODO this is all from UserDict.DictMixin. it could probably be made more
# efficient.
# second level definitions support higher levels
def __iter__(self):
for k in self.__keys:
yield k
def has_key(self, key):
return key in self.__keys
# third level takes advantage of second level definitions
def iteritems(self):
for k in self:
yield (k, self[k])
def iterkeys(self):
return self.__iter__()
# fourth level uses definitions from lower levels
def itervalues(self):
for _, v in self.iteritems():
yield v
def values(self):
return [v for _, v in self.iteritems()]
def items(self):
return [(key, self[key]) for key in self]
def clear(self):
self.__keys = []
super(SON, self).clear()
def setdefault(self, key, default=None):
try:
return self[key]
except KeyError:
self[key] = default
return default
def pop(self, key, *args):
if len(args) > 1:
raise TypeError("pop expected at most 2 arguments, got "\
+ repr(1 + len(args)))
try:
value = self[key]
except KeyError:
if args:
return args[0]
raise
del self[key]
return value
def popitem(self):
try:
k, v = next(self.iteritems())
except StopIteration:
raise KeyError('container is empty')
del self[k]
return (k, v)
def update(self, other=None, **kwargs):
# Make progressively weaker assumptions about "other"
if other is None:
pass
elif hasattr(other, 'iteritems'): # iteritems saves memory and lookups
for k, v in other.iteritems():
self[k] = v
elif hasattr(other, 'keys'):
for k in other.keys():
self[k] = other[k]
else:
for k, v in other:
self[k] = v
if kwargs:
self.update(kwargs)
def get(self, key, default=None):
try:
return self[key]
except KeyError:
return default
def __eq__(self, other):
"""Comparison to another SON is order-sensitive while comparison to a
regular dictionary is order-insensitive.
"""
if isinstance(other, SON):
return len(self) == len(other) and self.items() == other.items()
return self.to_dict() == other
def __ne__(self, other):
return not self == other
def __len__(self):
return len(self.__keys)
def to_dict(self):
"""Convert a SON document to a normal Python dictionary instance.
This is trickier than just *dict(...)* because it needs to be
recursive.
"""
def transform_value(value):
if isinstance(value, list):
return [transform_value(v) for v in value]
elif isinstance(value, collections.Mapping):
return dict([
(k, transform_value(v))
for k, v in iteritems(value)])
else:
return value
return transform_value(dict(self))
def __deepcopy__(self, memo):
out = SON()
val_id = id(self)
if val_id in memo:
return memo.get(val_id)
memo[val_id] = out
for k, v in self.iteritems():
if not isinstance(v, RE_TYPE):
v = copy.deepcopy(v, memo)
out[k] = v
return out
|
apache-2.0
|
[
3,
1898,
8937,
13,
7806,
28458,
12,
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,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
11654,
367,
6425,
436,
13335,
20529,
428,
615,
12,
314,
11973,
1759,
593,
67,
760,
2832,
425,
14,
199,
199,
16038,
11196,
883,
506,
1202,
3140,
402,
428,
615,
2251,
12,
1325,
440,
1380,
314,
1865,
199,
1618,
2883,
365,
11012,
14,
437,
428,
615,
909,
883,
506,
1202,
2951,
2839,
282,
3293,
2018,
199,
9086,
1041,
199,
199,
646,
5055,
199,
646,
1331,
199,
646,
295,
199,
199,
504,
330,
834,
14,
647,
19,
5819,
492,
10849,
421,
199,
3,
961,
4069,
402,
18741,
5618,
12,
1325,
12237,
370,
506,
465,
6954,
465,
652,
7545,
1396,
199,
3,
961,
365,
28891,
314,
2011,
465,
295,
423,
3401,
63,
466,
199,
907,
63,
2711,
275,
730,
8,
264,
14,
2014,
31348,
421,
199,
533,
428,
615,
8,
807,
304,
272,
408,
3377,
666,
14,
339,
437,
5516,
402,
1211,
626,
11075,
83,
7794,
402,
2883,
436,
6571,
282,
272,
9284,
2402,
14213,
1417,
367,
23654,
543,
428,
615,
14,
428,
615,
2251,
883,
506,
272,
6702,
370,
436,
687,
699,
3377,
14,
339,
710,
4412,
687,
2018,
2943,
370,
699,
3377,
2943,
365,
465,
11924,
26,
339,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
272,
2018,
2434,
19242,
699,
3377,
2434,
420,
26167,
25596,
414,
272,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
272,
488,
32542,
2973,
3698,
3865,
272,
2155,
32542,
5046,
263,
3865,
272,
1109,
10149,
442,
25276,
19242,
1109,
708,
1182,
1109,
772,
221,
1134,
1035,
330,
834,
272,
1846,
32542,
1109,
772,
3515,
1134,
1035,
330,
834,
272,
658,
66,
834,
14,
442,
772,
14,
3241,
772,
64,
9668,
1109,
772,
3515,
3865,
272,
2069,
27503,
1329,
334,
3093,
9,
221,
3865,
272,
1059,
15530,
1059,
260,
1134,
1035,
330,
834,
272,
2649,
22456,
1059,
260,
3865,
272,
769,
32542,
1625,
3515,
3865,
272,
1211,
1182,
658,
3377,
64,
17907,
909,
260,
3865,
272,
2197,
14,
2083,
10149,
3583,
25276,
10149,
3583,
18,
25276,
260,
1434,
3698,
3865,
272,
658,
66,
834,
14,
3821,
14,
5103,
64,
9668,
5163,
3515,
3865,
272,
10311,
295,
10149,
264,
25276,
9668,
5163,
3515,
1134,
1035,
330,
834,
272,
658,
66,
834,
14,
3008,
14,
6636,
64,
9326,
3366,
260,
3865,
272,
658,
66,
834,
14,
1113,
31157,
14,
1692,
1304,
64,
463,
20109,
3322,
3865,
272,
658,
66,
834,
14,
697,
1121,
14,
2846,
2891,
64,
9668,
1592,
1121,
3515,
3865,
272,
488,
32542,
10942,
420,
330,
834,
1035,
1134,
272,
2649,
22456,
1233,
3698,
330,
834,
1035,
1134,
272,
658,
66,
834,
14,
600,
14,
3034,
64,
12793,
1233,
3698,
1134,
1035,
330,
834,
272,
2649,
22456,
5272,
260,
330,
834,
1035,
1134,
272,
2783,
334,
4718,
650,
9,
10149,
2394,
25276,
5185,
3366,
260,
3865,
272,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
339,
3390,
626,
370,
3354,
3366,
666,
652,
1471,
506,
8072,
465,
376,
1256,
402,
272,
658,
66,
834,
14,
3008,
14,
6636,
2313,
6630,
652,
911,
506,
6290,
465,
282,
699,
3377,
1059,
272,
436,
12396,
465,
2649,
14,
339,
2508,
10149,
442,
61,
437,
2018,
1109,
911,
506,
6290,
465,
282,
699,
3377,
1109,
708,
503,
699,
3377,
1109,
772,
10298,
2126,
641,
2399,
1568,
14,
437,
699,
3377,
1109,
708,
911,
3544,
4849,
370,
282,
2018,
1109,
14,
437,
699,
3377,
2126,
1109,
772,
911,
3544,
4849,
370,
282,
520,
533,
6054,
66,
834,
14,
442,
772,
14,
3241,
772,
2313,
272,
2508,
10149,
3583,
61,
2197,
14,
2083,
4454,
911,
506,
24671,
370,
314,
17173,
2126,
15949,
4375,
1380,
6290,
272,
2508,
10149,
3583,
18,
61,
1006,
2197,
14,
2083,
4454,
787,
10184,
465,
627,
21578,
4856,
13431,
2126,
1077,
3544,
675,
12174,
14,
272,
2508,
10149,
264,
61,
520,
533,
6054,
66,
834,
14,
3821,
14,
5103,
64,
4454,
436,
5578,
3965,
2126,
2251,
687,
1124,
264,
14,
2014,
8497,
787,
3865,
6290,
465,
699,
3377,
5578,
8455,
14,
2126,
699,
3377,
5578,
8455,
787,
11203,
465,
520,
533,
6054,
66,
834,
14,
3821,
14,
5103,
64,
2126,
4454,
14,
272,
2508,
10149,
2394,
61,
710,
2783,
730,
687,
2018,
650,
14,
88,
365,
5737,
465,
699,
3377,
3366,
543,
2126,
15686,
378,
14,
1010,
2018,
650,
14,
88,
652,
911,
506,
11203,
1771,
370,
2783,
14,
1010,
2018,
499,
14,
88,
2126,
652,
911,
506,
11203,
370,
376,
1256,
402,
520,
533,
6054,
66,
834,
14,
3008,
14,
6636,
64,
543,
2126,
15686,
378,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
29,
403,
12,
1011,
958,
304,
267,
291,
855,
1612,
275,
942,
267,
1211,
855,
826,
721,
277,
9,
267,
291,
14,
873,
8,
576,
9,
267,
291,
14,
873,
8,
958,
9,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
1256,
275,
1613,
8,
3377,
12,
843,
2843,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
9,
267,
1256,
855,
1612,
275,
942,
267,
372,
1256,
339,
347,
636,
2722,
721,
277,
304,
267,
754,
275,
942,
267,
367,
790,
315,
291,
855,
1612,
26,
288,
754,
14,
740,
480,
4042,
82,
12,
450,
82,
2924,
450,
334,
498,
12,
291,
59,
498,
2459,
267,
372,
298,
3377,
779,
5,
83,
566,
2,
450,
3872,
3680,
904,
8,
1099,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790
] |
[
1898,
8937,
13,
7806,
28458,
12,
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,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
11654,
367,
6425,
436,
13335,
20529,
428,
615,
12,
314,
11973,
1759,
593,
67,
760,
2832,
425,
14,
199,
199,
16038,
11196,
883,
506,
1202,
3140,
402,
428,
615,
2251,
12,
1325,
440,
1380,
314,
1865,
199,
1618,
2883,
365,
11012,
14,
437,
428,
615,
909,
883,
506,
1202,
2951,
2839,
282,
3293,
2018,
199,
9086,
1041,
199,
199,
646,
5055,
199,
646,
1331,
199,
646,
295,
199,
199,
504,
330,
834,
14,
647,
19,
5819,
492,
10849,
421,
199,
3,
961,
4069,
402,
18741,
5618,
12,
1325,
12237,
370,
506,
465,
6954,
465,
652,
7545,
1396,
199,
3,
961,
365,
28891,
314,
2011,
465,
295,
423,
3401,
63,
466,
199,
907,
63,
2711,
275,
730,
8,
264,
14,
2014,
31348,
421,
199,
533,
428,
615,
8,
807,
304,
272,
408,
3377,
666,
14,
339,
437,
5516,
402,
1211,
626,
11075,
83,
7794,
402,
2883,
436,
6571,
282,
272,
9284,
2402,
14213,
1417,
367,
23654,
543,
428,
615,
14,
428,
615,
2251,
883,
506,
272,
6702,
370,
436,
687,
699,
3377,
14,
339,
710,
4412,
687,
2018,
2943,
370,
699,
3377,
2943,
365,
465,
11924,
26,
339,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
272,
2018,
2434,
19242,
699,
3377,
2434,
420,
26167,
25596,
414,
272,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
272,
488,
32542,
2973,
3698,
3865,
272,
2155,
32542,
5046,
263,
3865,
272,
1109,
10149,
442,
25276,
19242,
1109,
708,
1182,
1109,
772,
221,
1134,
1035,
330,
834,
272,
1846,
32542,
1109,
772,
3515,
1134,
1035,
330,
834,
272,
658,
66,
834,
14,
442,
772,
14,
3241,
772,
64,
9668,
1109,
772,
3515,
3865,
272,
2069,
27503,
1329,
334,
3093,
9,
221,
3865,
272,
1059,
15530,
1059,
260,
1134,
1035,
330,
834,
272,
2649,
22456,
1059,
260,
3865,
272,
769,
32542,
1625,
3515,
3865,
272,
1211,
1182,
658,
3377,
64,
17907,
909,
260,
3865,
272,
2197,
14,
2083,
10149,
3583,
25276,
10149,
3583,
18,
25276,
260,
1434,
3698,
3865,
272,
658,
66,
834,
14,
3821,
14,
5103,
64,
9668,
5163,
3515,
3865,
272,
10311,
295,
10149,
264,
25276,
9668,
5163,
3515,
1134,
1035,
330,
834,
272,
658,
66,
834,
14,
3008,
14,
6636,
64,
9326,
3366,
260,
3865,
272,
658,
66,
834,
14,
1113,
31157,
14,
1692,
1304,
64,
463,
20109,
3322,
3865,
272,
658,
66,
834,
14,
697,
1121,
14,
2846,
2891,
64,
9668,
1592,
1121,
3515,
3865,
272,
488,
32542,
10942,
420,
330,
834,
1035,
1134,
272,
2649,
22456,
1233,
3698,
330,
834,
1035,
1134,
272,
658,
66,
834,
14,
600,
14,
3034,
64,
12793,
1233,
3698,
1134,
1035,
330,
834,
272,
2649,
22456,
5272,
260,
330,
834,
1035,
1134,
272,
2783,
334,
4718,
650,
9,
10149,
2394,
25276,
5185,
3366,
260,
3865,
272,
19469,
23476,
221,
275,
5769,
221,
16248,
389,
339,
3390,
626,
370,
3354,
3366,
666,
652,
1471,
506,
8072,
465,
376,
1256,
402,
272,
658,
66,
834,
14,
3008,
14,
6636,
2313,
6630,
652,
911,
506,
6290,
465,
282,
699,
3377,
1059,
272,
436,
12396,
465,
2649,
14,
339,
2508,
10149,
442,
61,
437,
2018,
1109,
911,
506,
6290,
465,
282,
699,
3377,
1109,
708,
503,
699,
3377,
1109,
772,
10298,
2126,
641,
2399,
1568,
14,
437,
699,
3377,
1109,
708,
911,
3544,
4849,
370,
282,
2018,
1109,
14,
437,
699,
3377,
2126,
1109,
772,
911,
3544,
4849,
370,
282,
520,
533,
6054,
66,
834,
14,
442,
772,
14,
3241,
772,
2313,
272,
2508,
10149,
3583,
61,
2197,
14,
2083,
4454,
911,
506,
24671,
370,
314,
17173,
2126,
15949,
4375,
1380,
6290,
272,
2508,
10149,
3583,
18,
61,
1006,
2197,
14,
2083,
4454,
787,
10184,
465,
627,
21578,
4856,
13431,
2126,
1077,
3544,
675,
12174,
14,
272,
2508,
10149,
264,
61,
520,
533,
6054,
66,
834,
14,
3821,
14,
5103,
64,
4454,
436,
5578,
3965,
2126,
2251,
687,
1124,
264,
14,
2014,
8497,
787,
3865,
6290,
465,
699,
3377,
5578,
8455,
14,
2126,
699,
3377,
5578,
8455,
787,
11203,
465,
520,
533,
6054,
66,
834,
14,
3821,
14,
5103,
64,
2126,
4454,
14,
272,
2508,
10149,
2394,
61,
710,
2783,
730,
687,
2018,
650,
14,
88,
365,
5737,
465,
699,
3377,
3366,
543,
2126,
15686,
378,
14,
1010,
2018,
650,
14,
88,
652,
911,
506,
11203,
1771,
370,
2783,
14,
1010,
2018,
499,
14,
88,
2126,
652,
911,
506,
11203,
370,
376,
1256,
402,
520,
533,
6054,
66,
834,
14,
3008,
14,
6636,
64,
543,
2126,
15686,
378,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
666,
29,
403,
12,
1011,
958,
304,
267,
291,
855,
1612,
275,
942,
267,
1211,
855,
826,
721,
277,
9,
267,
291,
14,
873,
8,
576,
9,
267,
291,
14,
873,
8,
958,
9,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
1256,
275,
1613,
8,
3377,
12,
843,
2843,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
9,
267,
1256,
855,
1612,
275,
942,
267,
372,
1256,
339,
347,
636,
2722,
721,
277,
304,
267,
754,
275,
942,
267,
367,
790,
315,
291,
855,
1612,
26,
288,
754,
14,
740,
480,
4042,
82,
12,
450,
82,
2924,
450,
334,
498,
12,
291,
59,
498,
2459,
267,
372,
298,
3377,
779,
5,
83,
566,
2,
450,
3872,
3680,
904,
8,
1099,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aleaxit/pysolper
|
latrop/lib/dist/werkzeug/contrib/profiler.py
|
25
|
3962
|
# -*- coding: utf-8 -*-
"""
werkzeug.contrib.profiler
~~~~~~~~~~~~~~~~~~~~~~~~~
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the :mod:`profile` or
:mod:`cProfile` module to do the profiling and writes the stats to the
stream provided (defaults to stderr).
Example usage::
from werkzeug.contrib.profiler import ProfilerMiddleware
app = ProfilerMiddleware(app)
:copyright: (c) 2010 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import sys
try:
try:
from cProfile import Profile
except ImportError:
from profile import Profile
from pstats import Stats
available = True
except ImportError:
available = False
class MergeStream(object):
"""An object that redirects `write` calls to multiple streams.
Use this to log to both `sys.stdout` and a file::
f = open('profiler.log', 'w')
stream = MergeStream(sys.stdout, f)
profiler = ProfilerMiddleware(app, stream)
"""
def __init__(self, *streams):
if not streams:
raise TypeError('at least one stream must be given')
self.streams = streams
def write(self, data):
for stream in self.streams:
stream.write(data)
class ProfilerMiddleware(object):
"""Simple profiler middleware. Wraps a WSGI application and profiles
a request. This intentionally buffers the response so that timings are
more exact.
For the exact meaning of `sort_by` and `restrictions` consult the
:mod:`profile` documentation.
:param app: the WSGI application to profile.
:param stream: the stream for the profiled stats. defaults to stderr.
:param sort_by: a tuple of columns to sort the result by.
:param restrictions: a tuple of profiling strictions.
"""
def __init__(self, app, stream=None,
sort_by=('time', 'calls'), restrictions=()):
if not available:
raise RuntimeError('the profiler is not available because '
'profile or pstat is not installed.')
self._app = app
self._stream = stream or sys.stdout
self._sort_by = sort_by
self._restrictions = restrictions
def __call__(self, environ, start_response):
response_body = []
def catching_start_response(status, headers, exc_info=None):
start_response(status, headers, exc_info)
return response_body.append
def runapp():
appiter = self._app(environ, catching_start_response)
response_body.extend(appiter)
if hasattr(appiter, 'close'):
appiter.close()
p = Profile()
p.runcall(runapp)
body = ''.join(response_body)
stats = Stats(p, stream=self._stream)
stats.sort_stats(*self._sort_by)
self._stream.write('-' * 80)
self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO'))
stats.print_stats(*self._restrictions)
self._stream.write('-' * 80 + '\n\n')
return [body]
def make_action(app_factory, hostname='localhost', port=5000,
threaded=False, processes=1, stream=None,
sort_by=('time', 'calls'), restrictions=()):
"""Return a new callback for :mod:`werkzeug.script` that starts a local
server with the profiler enabled::
from werkzeug.contrib import profiler
action_profile = profiler.make_action(make_app)
"""
def action(hostname=('h', hostname), port=('p', port),
threaded=threaded, processes=processes):
"""Start a new development server."""
from werkzeug.serving import run_simple
app = ProfilerMiddleware(app_factory(), stream, sort_by, restrictions)
run_simple(hostname, port, app, False, None, threaded, processes)
return action
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
2828,
14,
20132,
272,
18294,
4919,
94,
339,
961,
859,
6571,
282,
3486,
9279,
23173,
10816,
367,
17196,
272,
5888,
25263,
5618,
315,
3330,
4223,
14,
221,
2779,
4440,
314,
520,
1494,
1705,
2913,
64,
503,
272,
520,
1494,
1705,
67,
5736,
64,
859,
370,
886,
314,
30238,
436,
14511,
314,
5020,
370,
314,
272,
2547,
2741,
334,
4322,
370,
4635,
680,
339,
5679,
4503,
447,
398,
687,
10380,
14,
2828,
14,
20132,
492,
14386,
82,
6608,
267,
1145,
275,
14386,
82,
6608,
8,
571,
9,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
984,
199,
893,
26,
272,
862,
26,
267,
687,
286,
5736,
492,
14386,
272,
871,
3545,
26,
267,
687,
4690,
492,
14386,
272,
687,
299,
3200,
492,
29062,
272,
2808,
275,
715,
199,
2590,
3545,
26,
272,
2808,
275,
756,
421,
199,
533,
14076,
3296,
8,
785,
304,
272,
408,
2493,
909,
626,
17784,
658,
952,
64,
4882,
370,
3663,
13788,
14,
272,
3645,
642,
370,
943,
370,
3865,
658,
1274,
14,
2703,
64,
436,
282,
570,
447,
398,
289,
275,
1551,
360,
20132,
14,
793,
297,
283,
87,
358,
267,
2547,
275,
14076,
3296,
8,
1274,
14,
2703,
12,
289,
9,
267,
23173,
275,
14386,
82,
6608,
8,
571,
12,
2547,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
11231,
304,
267,
340,
440,
13788,
26,
288,
746,
3146,
360,
292,
5210,
1373,
2547,
1471,
506,
1627,
358,
267,
291,
14,
11231,
275,
13788,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
367,
2547,
315,
291,
14,
11231,
26,
288,
2547,
14,
952,
8,
576,
9,
421,
199,
533,
14386,
82,
6608,
8,
785,
304,
272,
408,
3184,
23173,
10816,
14,
221,
644,
8146,
282,
9279,
4223,
436,
17390,
272,
282,
1056,
14,
221,
961,
32005,
19383,
314,
1177,
880,
626,
221,
27337,
787,
272,
1655,
5835,
14,
339,
2104,
314,
5835,
11150,
402,
658,
3191,
63,
991,
64,
436,
658,
12099,
2452,
64,
13447,
427,
314,
272,
520,
1494,
1705,
2913,
64,
3794,
14,
339,
520,
635,
1145,
26,
314,
9279,
4223,
370,
4690,
14,
272,
520,
635,
2547,
26,
314,
2547,
367,
314,
4690,
68,
5020,
14,
221,
4243,
370,
4635,
14,
272,
520,
635,
4069,
63,
991,
26,
282,
2008,
402,
4362,
370,
4069,
314,
754,
701,
14,
272,
520,
635,
24488,
26,
282,
2008,
402,
30238,
4024,
2452,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1145,
12,
2547,
29,
403,
12,
326,
4069,
63,
991,
7782,
521,
297,
283,
5352,
659,
24488,
23603,
267,
340,
440,
2808,
26,
288,
746,
6064,
360,
1589,
23173,
365,
440,
2808,
2952,
283,
3044,
283,
2913,
503,
299,
3736,
365,
440,
4903,
2659,
267,
291,
423,
571,
275,
1145,
267,
291,
423,
1745,
275,
2547,
503,
984,
14,
2703,
267,
291,
423,
3191,
63,
991,
275,
4069,
63,
991,
267,
291,
423,
12099,
2452,
275,
24488,
339,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1177,
63,
2030,
275,
942,
398,
347,
8579,
316,
63,
928,
63,
1310,
8,
1205,
12,
2323,
12,
3178,
63,
815,
29,
403,
304,
288,
1343,
63,
1310,
8,
1205,
12,
2323,
12,
3178,
63,
815,
9,
288,
372,
1177,
63,
2030,
14,
740,
398,
347,
1255,
571,
837,
288,
1145,
1661,
275,
291,
423,
571,
8,
2314,
12,
8579,
316,
63,
928,
63,
1310,
9,
288,
1177,
63,
2030,
14,
2880,
8,
571,
1661,
9,
288,
340,
2688,
8,
571,
1661,
12,
283,
1600,
735,
355,
1145,
1661,
14,
1600,
342,
398,
299,
275,
14386,
342,
267,
299,
14,
1065,
1250,
8,
1065,
571,
9,
267,
2396,
275,
6522,
904,
8,
1310,
63,
2030,
9,
267,
5020,
275,
29062,
8,
80,
12,
2547,
29,
277,
423,
1745,
9,
267,
5020,
14,
3191,
63,
3200,
2031,
277,
423,
3191,
63,
991,
9,
398,
291,
423,
1745,
14,
952,
3654,
7,
627,
5939,
9,
267,
291,
423,
1745,
14,
952,
2258,
78,
3243,
26,
450,
82,
60,
78,
7,
450,
6160,
14,
362,
360,
3243,
63,
4531,
1333,
267,
5020,
14,
1361,
63,
3200,
2031,
277,
423,
12099,
2452,
9,
267,
291,
423,
1745,
14,
952,
3654,
7,
627,
5939,
435,
1557,
78,
60,
78,
358,
398,
372,
359,
2030,
61,
421,
199,
318,
1852,
63,
1287,
8,
571,
63,
3702,
12,
6246,
534,
5967,
297,
1844,
29,
13128,
12,
355,
25396,
29,
797,
12,
10358,
29,
17,
12,
2547,
29,
403,
12,
355,
4069,
63,
991,
7782,
521,
297,
283,
5352,
659,
24488,
23603,
272,
408,
1767,
282,
892,
3233,
367,
520,
1494,
1705,
17719,
14,
1579,
64,
626,
9174,
282,
2257,
272,
1654,
543,
314,
23173,
5223,
447,
398,
687,
10380,
14,
2828,
492,
23173,
267,
1595,
63,
2913,
275,
23173,
14,
1875,
63,
1287,
8,
1875,
63,
571,
9,
272,
408,
272,
347,
1595,
8,
4269,
7782,
72,
297,
6246,
395,
1844,
7782,
80,
297,
1844,
395,
2049,
25396,
29,
19710,
12,
10358,
29,
11816,
304,
267,
408,
3162,
282,
892,
16367,
1654,
1041,
267,
687,
10380,
14,
14717,
492,
1255,
63,
4129,
267,
1145,
275,
14386,
82,
6608,
8,
571,
63,
3702,
1062,
2547,
12,
4069,
63,
991,
12,
24488,
9,
267,
1255,
63,
4129,
8,
4269,
12,
1844,
12,
1145,
12,
756,
12,
488,
12,
25396,
12,
10358,
9,
272,
372,
1595,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
2828,
14,
20132,
272,
18294,
4919,
94,
339,
961,
859,
6571,
282,
3486,
9279,
23173,
10816,
367,
17196,
272,
5888,
25263,
5618,
315,
3330,
4223,
14,
221,
2779,
4440,
314,
520,
1494,
1705,
2913,
64,
503,
272,
520,
1494,
1705,
67,
5736,
64,
859,
370,
886,
314,
30238,
436,
14511,
314,
5020,
370,
314,
272,
2547,
2741,
334,
4322,
370,
4635,
680,
339,
5679,
4503,
447,
398,
687,
10380,
14,
2828,
14,
20132,
492,
14386,
82,
6608,
267,
1145,
275,
14386,
82,
6608,
8,
571,
9,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
984,
199,
893,
26,
272,
862,
26,
267,
687,
286,
5736,
492,
14386,
272,
871,
3545,
26,
267,
687,
4690,
492,
14386,
272,
687,
299,
3200,
492,
29062,
272,
2808,
275,
715,
199,
2590,
3545,
26,
272,
2808,
275,
756,
421,
199,
533,
14076,
3296,
8,
785,
304,
272,
408,
2493,
909,
626,
17784,
658,
952,
64,
4882,
370,
3663,
13788,
14,
272,
3645,
642,
370,
943,
370,
3865,
658,
1274,
14,
2703,
64,
436,
282,
570,
447,
398,
289,
275,
1551,
360,
20132,
14,
793,
297,
283,
87,
358,
267,
2547,
275,
14076,
3296,
8,
1274,
14,
2703,
12,
289,
9,
267,
23173,
275,
14386,
82,
6608,
8,
571,
12,
2547,
9,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
11231,
304,
267,
340,
440,
13788,
26,
288,
746,
3146,
360,
292,
5210,
1373,
2547,
1471,
506,
1627,
358,
267,
291,
14,
11231,
275,
13788,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
367,
2547,
315,
291,
14,
11231,
26,
288,
2547,
14,
952,
8,
576,
9,
421,
199,
533,
14386,
82,
6608,
8,
785,
304,
272,
408,
3184,
23173,
10816,
14,
221,
644,
8146,
282,
9279,
4223,
436,
17390,
272,
282,
1056,
14,
221,
961,
32005,
19383,
314,
1177,
880,
626,
221,
27337,
787,
272,
1655,
5835,
14,
339,
2104,
314,
5835,
11150,
402,
658,
3191,
63,
991,
64,
436,
658,
12099,
2452,
64,
13447,
427,
314,
272,
520,
1494,
1705,
2913,
64,
3794,
14,
339,
520,
635,
1145,
26,
314,
9279,
4223,
370,
4690,
14,
272,
520,
635,
2547,
26,
314,
2547,
367,
314,
4690,
68,
5020,
14,
221,
4243,
370,
4635,
14,
272,
520,
635,
4069,
63,
991,
26,
282,
2008,
402,
4362,
370,
4069,
314,
754,
701,
14,
272,
520,
635,
24488,
26,
282,
2008,
402,
30238,
4024,
2452,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1145,
12,
2547,
29,
403,
12,
326,
4069,
63,
991,
7782,
521,
297,
283,
5352,
659,
24488,
23603,
267,
340,
440,
2808,
26,
288,
746,
6064,
360,
1589,
23173,
365,
440,
2808,
2952,
283,
3044,
283,
2913,
503,
299,
3736,
365,
440,
4903,
2659,
267,
291,
423,
571,
275,
1145,
267,
291,
423,
1745,
275,
2547,
503,
984,
14,
2703,
267,
291,
423,
3191,
63,
991,
275,
4069,
63,
991,
267,
291,
423,
12099,
2452,
275,
24488,
339,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1177,
63,
2030,
275,
942,
398,
347,
8579,
316,
63,
928,
63,
1310,
8,
1205,
12,
2323,
12,
3178,
63,
815,
29,
403,
304,
288,
1343,
63,
1310,
8,
1205,
12,
2323,
12,
3178,
63,
815,
9,
288,
372,
1177,
63,
2030,
14,
740,
398,
347,
1255,
571,
837,
288,
1145,
1661,
275,
291,
423,
571,
8,
2314,
12,
8579,
316,
63,
928,
63,
1310,
9,
288,
1177,
63,
2030,
14,
2880,
8,
571,
1661,
9,
288,
340,
2688,
8,
571,
1661,
12,
283,
1600,
735,
355,
1145,
1661,
14,
1600,
342,
398,
299,
275,
14386,
342,
267,
299,
14,
1065,
1250,
8,
1065,
571,
9,
267,
2396,
275,
6522,
904,
8,
1310,
63,
2030,
9,
267,
5020,
275,
29062,
8,
80,
12,
2547,
29,
277,
423,
1745,
9,
267,
5020,
14,
3191,
63,
3200,
2031,
277,
423,
3191,
63,
991,
9,
398,
291,
423,
1745,
14,
952,
3654,
7,
627,
5939,
9,
267,
291,
423,
1745,
14,
952,
2258,
78,
3243,
26,
450,
82,
60,
78,
7,
450,
6160,
14,
362,
360,
3243,
63,
4531,
1333,
267,
5020,
14,
1361,
63,
3200,
2031,
277,
423,
12099,
2452,
9,
267,
291,
423,
1745,
14,
952,
3654,
7,
627,
5939,
435,
1557,
78,
60,
78,
358,
398,
372,
359,
2030,
61,
421,
199,
318,
1852,
63,
1287,
8,
571,
63,
3702,
12,
6246,
534,
5967,
297,
1844,
29,
13128,
12,
355,
25396,
29,
797,
12,
10358,
29,
17,
12,
2547,
29,
403,
12,
355,
4069,
63,
991,
7782,
521,
297,
283,
5352,
659,
24488,
23603,
272,
408,
1767,
282,
892,
3233,
367,
520,
1494,
1705,
17719,
14,
1579,
64,
626,
9174,
282,
2257,
272,
1654,
543,
314,
23173,
5223,
447,
398,
687,
10380,
14,
2828,
492,
23173,
267,
1595,
63,
2913,
275,
23173,
14,
1875,
63,
1287,
8,
1875,
63,
571,
9,
272,
408,
272,
347,
1595,
8,
4269,
7782,
72,
297,
6246,
395,
1844,
7782,
80,
297,
1844,
395,
2049,
25396,
29,
19710,
12,
10358,
29,
11816,
304,
267,
408,
3162,
282,
892,
16367,
1654,
1041,
267,
687,
10380,
14,
14717,
492,
1255,
63,
4129,
267,
1145,
275,
14386,
82,
6608,
8,
571,
63,
3702,
1062,
2547,
12,
4069,
63,
991,
12,
24488,
9,
267,
1255,
63,
4129,
8,
4269,
12,
1844,
12,
1145,
12,
756,
12,
488,
12,
25396,
12,
10358,
9,
272,
372,
1595,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
diogocs1/comps
|
web/openerp/report/printscreen/ps_list.py
|
381
|
11955
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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 openerp
from openerp.report.interface import report_int
import openerp.tools as tools
from openerp.tools.safe_eval import safe_eval as eval
from lxml import etree
from openerp.report import render, report_sxw
import locale
import time, os
from operator import itemgetter
from datetime import datetime
class report_printscreen_list(report_int):
def __init__(self, name):
report_int.__init__(self, name)
self.context = {}
self.groupby = []
self.cr=''
def _parse_node(self, root_node):
result = []
for node in root_node:
field_name = node.get('name')
if not eval(str(node.attrib.get('invisible',False)),{'context':self.context}):
if node.tag == 'field':
if field_name in self.groupby:
continue
result.append(field_name)
else:
result.extend(self._parse_node(node))
return result
def _parse_string(self, view):
try:
dom = etree.XML(view.encode('utf-8'))
except Exception:
dom = etree.XML(view)
return self._parse_node(dom)
def create(self, cr, uid, ids, datas, context=None):
if not context:
context={}
self.cr=cr
self.context = context
self.groupby = context.get('group_by',[])
self.groupby_no_leaf = context.get('group_by_no_leaf',False)
registry = openerp.registry(cr.dbname)
model = registry[datas['model']]
model_id = registry['ir.model'].search(cr, uid, [('model','=',model._name)])
model_desc = model._description
if model_id:
model_desc = registry['ir.model'].browse(cr, uid, model_id[0], context).name
self.title = model_desc
datas['ids'] = ids
result = model.fields_view_get(cr, uid, view_type='tree', context=context)
fields_order = self.groupby + self._parse_string(result['arch'])
if self.groupby:
rows = []
def get_groupby_data(groupby = [], domain = []):
records = model.read_group(cr, uid, domain, fields_order, groupby , 0, None, context)
for rec in records:
rec['__group'] = True
rec['__no_leaf'] = self.groupby_no_leaf
rec['__grouped_by'] = groupby[0] if (isinstance(groupby, list) and groupby) else groupby
for f in fields_order:
if f not in rec:
rec.update({f:False})
elif isinstance(rec[f], tuple):
rec[f] = rec[f][1]
rows.append(rec)
inner_groupby = (rec.get('__context', {})).get('group_by',[])
inner_domain = rec.get('__domain', [])
if inner_groupby:
get_groupby_data(inner_groupby, inner_domain)
else:
if self.groupby_no_leaf:
continue
child_ids = model.search(cr, uid, inner_domain)
res = model.read(cr, uid, child_ids, result['fields'].keys(), context)
res.sort(lambda x,y: cmp(ids.index(x['id']), ids.index(y['id'])))
rows.extend(res)
dom = [('id','in',ids)]
if self.groupby_no_leaf and len(ids) and not ids[0]:
dom = datas.get('_domain',[])
get_groupby_data(self.groupby, dom)
else:
rows = model.read(cr, uid, datas['ids'], result['fields'].keys(), context)
ids2 = map(itemgetter('id'), rows) # getting the ids from read result
if datas['ids'] != ids2: # sorted ids were not taken into consideration for print screen
rows_new = []
for id in datas['ids']:
rows_new += [elem for elem in rows if elem['id'] == id]
rows = rows_new
res = self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model_desc)
return self.obj.get(), 'pdf'
def _create_table(self, uid, ids, fields, fields_order, results, context, title=''):
pageSize=[297.0, 210.0]
new_doc = etree.Element("report")
config = etree.SubElement(new_doc, 'config')
def _append_node(name, text):
n = etree.SubElement(config, name)
n.text = text
#_append_node('date', time.strftime('%d/%m/%Y'))
_append_node('date', time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))))
_append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
_append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,))
_append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,))
_append_node('report-header', title)
registry = openerp.registry(self.cr.dbname)
_append_node('company', registry['res.users'].browse(self.cr,uid,uid).company_id.name)
rpt_obj = registry['res.users']
rml_obj=report_sxw.rml_parse(self.cr, uid, rpt_obj._name,context)
_append_node('header-date', str(rml_obj.formatLang(time.strftime("%Y-%m-%d"),date=True))+' ' + str(time.strftime("%H:%M")))
l = []
t = 0
strmax = (pageSize[0]-40) * 2.8346
temp = []
tsum = []
for i in range(0, len(fields_order)):
temp.append(0)
tsum.append(0)
ince = -1
for f in fields_order:
s = 0
ince += 1
if fields[f]['type'] in ('date','time','datetime','float','integer'):
s = 60
strmax -= s
if fields[f]['type'] in ('float','integer'):
temp[ince] = 1
else:
t += fields[f].get('size', 80) / 28 + 1
l.append(s)
for pos in range(len(l)):
if not l[pos]:
s = fields[fields_order[pos]].get('size', 80) / 28 + 1
l[pos] = strmax * s / t
_append_node('tableSize', ','.join(map(str,l)) )
header = etree.SubElement(new_doc, 'header')
for f in fields_order:
field = etree.SubElement(header, 'field')
field.text = tools.ustr(fields[f]['string'] or '')
lines = etree.SubElement(new_doc, 'lines')
for line in results:
node_line = etree.SubElement(lines, 'row')
count = -1
for f in fields_order:
float_flag = 0
count += 1
if fields[f]['type']=='many2one' and line[f]:
if not line.get('__group'):
line[f] = line[f][1]
if fields[f]['type']=='selection' and line[f]:
for key, value in fields[f]['selection']:
if key == line[f]:
line[f] = value
break
if fields[f]['type'] in ('one2many','many2many') and line[f]:
line[f] = '( '+tools.ustr(len(line[f])) + ' )'
if fields[f]['type'] == 'float' and line[f]:
precision=(('digits' in fields[f]) and fields[f]['digits'][1]) or 2
prec ='%.' + str(precision) +'f'
line[f]=prec%(line[f])
float_flag = 1
if fields[f]['type'] == 'date' and line[f]:
new_d1 = line[f]
if not line.get('__group'):
format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))
d1 = datetime.strptime(line[f],'%Y-%m-%d')
new_d1 = d1.strftime(format)
line[f] = new_d1
if fields[f]['type'] == 'time' and line[f]:
new_d1 = line[f]
if not line.get('__group'):
format = str(locale.nl_langinfo(locale.T_FMT))
d1 = datetime.strptime(line[f], '%H:%M:%S')
new_d1 = d1.strftime(format)
line[f] = new_d1
if fields[f]['type'] == 'datetime' and line[f]:
new_d1 = line[f]
if not line.get('__group'):
format = str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))+' '+str(locale.nl_langinfo(locale.T_FMT))
d1 = datetime.strptime(line[f], '%Y-%m-%d %H:%M:%S')
new_d1 = d1.strftime(format)
line[f] = new_d1
if line.get('__group'):
col = etree.SubElement(node_line, 'col', para='group', tree='no')
else:
col = etree.SubElement(node_line, 'col', para='yes', tree='no')
# Prevent empty labels in groups
if f == line.get('__grouped_by') and line.get('__group') and not line[f] and not float_flag and not temp[count]:
col.text = line[f] = 'Undefined'
col.set('tree', 'undefined')
if line[f] is not None:
col.text = tools.ustr(line[f] or '')
if float_flag:
col.set('tree','float')
if line.get('__no_leaf') and temp[count] == 1 and f != 'id' and not line['__context']['group_by']:
tsum[count] = float(tsum[count]) + float(line[f])
if not line.get('__group') and f != 'id' and temp[count] == 1:
tsum[count] = float(tsum[count]) + float(line[f])
else:
col.text = '/'
node_line = etree.SubElement(lines, 'row')
for f in range(0, len(fields_order)):
col = etree.SubElement(node_line, 'col', para='group', tree='no')
col.set('tree', 'float')
if tsum[f] is not None:
if tsum[f] != 0.0:
digits = fields[fields_order[f]].get('digits', (16, 2))
prec = '%%.%sf' % (digits[1], )
total = prec % (tsum[f], )
txt = str(total or '')
else:
txt = str(tsum[f] or '')
else:
txt = '/'
if f == 0:
txt ='Total'
col.set('tree','no')
col.text = tools.ustr(txt or '')
transform = etree.XSLT(
etree.parse(os.path.join(tools.config['root_path'],
'addons/base/report/custom_new.xsl')))
rml = etree.tostring(transform(new_doc))
self.obj = render.rml(rml, title=self.title)
self.obj.render()
return True
report_printscreen_list('report.printscreen.list')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
apache-2.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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5166,
199,
504,
5166,
14,
3070,
14,
3266,
492,
3622,
63,
442,
199,
646,
5166,
14,
2537,
465,
7249,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
504,
14490,
221,
492,
7559,
199,
504,
5166,
14,
3070,
492,
3795,
12,
3622,
63,
20851,
199,
646,
5867,
199,
199,
646,
900,
12,
747,
199,
504,
4182,
492,
1242,
7416,
199,
504,
2197,
492,
2197,
421,
199,
533,
3622,
63,
1361,
5410,
63,
513,
8,
3070,
63,
442,
304,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
3622,
63,
442,
855,
826,
721,
277,
12,
536,
9,
267,
291,
14,
1100,
275,
1052,
267,
291,
14,
16968,
275,
942,
267,
291,
14,
1556,
19070,
339,
347,
485,
1122,
63,
932,
8,
277,
12,
1738,
63,
932,
304,
267,
754,
275,
942,
267,
367,
1031,
315,
1738,
63,
932,
26,
288,
901,
63,
354,
275,
1031,
14,
362,
360,
354,
358,
288,
340,
440,
3468,
8,
495,
8,
932,
14,
6640,
14,
362,
360,
262,
6604,
297,
797,
1826,
1445,
1100,
356,
277,
14,
1100,
22558,
355,
340,
1031,
14,
1450,
508,
283,
698,
356,
490,
340,
901,
63,
354,
315,
291,
14,
16968,
26,
717,
1980,
490,
754,
14,
740,
8,
698,
63,
354,
9,
355,
587,
26,
490,
754,
14,
2880,
8,
277,
423,
1122,
63,
932,
8,
932,
430,
267,
372,
754,
339,
347,
485,
1122,
63,
875,
8,
277,
12,
2455,
304,
267,
862,
26,
288,
8266,
275,
7559,
14,
4317,
8,
1345,
14,
2143,
360,
1624,
13,
24,
1333,
267,
871,
2186,
26,
288,
8266,
275,
7559,
14,
4317,
8,
1345,
9,
267,
372,
291,
423,
1122,
63,
932,
8,
4556,
9,
339,
347,
1218,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15012,
12,
1067,
29,
403,
304,
267,
340,
440,
1067,
26,
288,
1067,
7622,
267,
291,
14,
1556,
29,
1556,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
16968,
275,
1067,
14,
362,
360,
923,
63,
991,
23993,
566,
267,
291,
14,
16968,
63,
889,
63,
8914,
275,
1067,
14,
362,
360,
923,
63,
991,
63,
889,
63,
8914,
297,
797,
9,
267,
7086,
275,
5166,
14,
5189,
8,
1556,
14,
13238,
9,
267,
1402,
275,
7086,
59,
11563,
459,
1238,
6538,
267,
1402,
63,
344,
275,
7086,
459,
723,
14,
1238,
2278,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
18937,
1238,
423,
354,
3948,
267,
1402,
63,
3257,
275,
1402,
423,
1802,
267,
340,
1402,
63,
344,
26,
288,
1402,
63,
3257,
275,
7086,
459,
723,
14,
1238,
2278,
4570,
8,
1556,
12,
1747,
12,
1402,
63,
344,
59,
16,
467,
1067,
680,
354,
267,
291,
14,
1213,
275,
1402,
63,
3257,
267,
15012,
459,
1580,
418,
275,
2762,
267,
754,
275,
1402,
14,
955,
63,
1345,
63,
362,
8,
1556,
12,
1747,
12,
2455,
63,
466,
534,
2350,
297,
1067,
29,
1100,
9,
267,
1504,
63,
1648,
275,
221,
291,
14,
16968,
435,
291,
423,
1122,
63,
875,
8,
1099,
459,
1047,
1105,
267,
340,
291,
14,
16968,
26,
288,
4730,
275,
942,
288,
347,
664,
63,
16968,
63,
576,
8,
16968,
275,
990,
2881,
275,
12319,
355,
5767,
275,
221,
1402,
14,
739,
63,
923,
8,
1556,
12,
1747,
12,
2881,
12,
1504,
63,
1648,
12,
20371,
2360,
378,
12,
488,
12,
1067,
9,
355,
367,
6488,
315,
5767,
26,
490,
6488,
13742,
923,
418,
275,
715,
490,
6488,
13742,
889,
63,
8914,
418,
275,
291,
14,
16968,
63,
889,
63,
8914,
490,
6488,
13742,
22674,
63,
991,
418,
275,
20371,
59,
16,
61,
340,
334,
6074,
8,
16968,
12,
769,
9,
436,
20371,
9,
587,
20371,
490,
367,
289,
315,
1504,
63,
1648,
26,
717,
340,
289,
440,
315,
6488,
26,
1169,
6488,
14,
873,
2561,
70,
26,
797,
1552,
717,
916,
1228,
8,
2761,
59,
70,
467,
2008,
304,
1169,
6488,
59,
70,
61,
275,
6488,
59,
70,
1527,
17,
61,
490,
4730,
14,
740,
8,
2761,
9,
490,
6506,
63,
16968,
275,
334,
2761,
14,
362,
10714,
1100,
297,
1052,
4992,
362,
360,
923,
63,
991,
23993,
566,
490,
6506,
63,
2261,
275,
6488,
14,
362,
10714,
2261,
297,
3073,
490,
340,
6506,
63,
16968,
26,
717,
664,
63,
16968,
63,
576,
8,
5216,
63,
16968,
12,
6506,
63,
2261,
9,
490,
587,
26,
717,
340,
291,
14,
16968,
63,
889,
63,
8914,
26,
1169,
1980,
717,
1982,
63,
1580,
275,
1402,
14,
1733,
8,
1556,
12,
1747,
12,
6506,
63,
2261,
9,
717,
522,
275,
1402,
14,
739,
8,
1556,
12,
1747,
12,
1982,
63,
1580,
12,
754,
459,
955,
2278,
1612,
1062,
1067,
9,
717,
522,
14,
3191,
8,
2734,
671,
12,
89,
26,
10467,
8,
1580,
14,
1080,
8,
88,
459,
344,
3815,
2762,
14,
1080,
8,
89,
459,
344,
26991,
717,
4730,
14,
2880,
8,
470,
9,
288,
8266,
275,
4274,
344,
1673,
262,
297
] |
[
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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5166,
199,
504,
5166,
14,
3070,
14,
3266,
492,
3622,
63,
442,
199,
646,
5166,
14,
2537,
465,
7249,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
199,
504,
14490,
221,
492,
7559,
199,
504,
5166,
14,
3070,
492,
3795,
12,
3622,
63,
20851,
199,
646,
5867,
199,
199,
646,
900,
12,
747,
199,
504,
4182,
492,
1242,
7416,
199,
504,
2197,
492,
2197,
421,
199,
533,
3622,
63,
1361,
5410,
63,
513,
8,
3070,
63,
442,
304,
272,
347,
636,
826,
721,
277,
12,
536,
304,
267,
3622,
63,
442,
855,
826,
721,
277,
12,
536,
9,
267,
291,
14,
1100,
275,
1052,
267,
291,
14,
16968,
275,
942,
267,
291,
14,
1556,
19070,
339,
347,
485,
1122,
63,
932,
8,
277,
12,
1738,
63,
932,
304,
267,
754,
275,
942,
267,
367,
1031,
315,
1738,
63,
932,
26,
288,
901,
63,
354,
275,
1031,
14,
362,
360,
354,
358,
288,
340,
440,
3468,
8,
495,
8,
932,
14,
6640,
14,
362,
360,
262,
6604,
297,
797,
1826,
1445,
1100,
356,
277,
14,
1100,
22558,
355,
340,
1031,
14,
1450,
508,
283,
698,
356,
490,
340,
901,
63,
354,
315,
291,
14,
16968,
26,
717,
1980,
490,
754,
14,
740,
8,
698,
63,
354,
9,
355,
587,
26,
490,
754,
14,
2880,
8,
277,
423,
1122,
63,
932,
8,
932,
430,
267,
372,
754,
339,
347,
485,
1122,
63,
875,
8,
277,
12,
2455,
304,
267,
862,
26,
288,
8266,
275,
7559,
14,
4317,
8,
1345,
14,
2143,
360,
1624,
13,
24,
1333,
267,
871,
2186,
26,
288,
8266,
275,
7559,
14,
4317,
8,
1345,
9,
267,
372,
291,
423,
1122,
63,
932,
8,
4556,
9,
339,
347,
1218,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15012,
12,
1067,
29,
403,
304,
267,
340,
440,
1067,
26,
288,
1067,
7622,
267,
291,
14,
1556,
29,
1556,
267,
291,
14,
1100,
275,
1067,
267,
291,
14,
16968,
275,
1067,
14,
362,
360,
923,
63,
991,
23993,
566,
267,
291,
14,
16968,
63,
889,
63,
8914,
275,
1067,
14,
362,
360,
923,
63,
991,
63,
889,
63,
8914,
297,
797,
9,
267,
7086,
275,
5166,
14,
5189,
8,
1556,
14,
13238,
9,
267,
1402,
275,
7086,
59,
11563,
459,
1238,
6538,
267,
1402,
63,
344,
275,
7086,
459,
723,
14,
1238,
2278,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
18937,
1238,
423,
354,
3948,
267,
1402,
63,
3257,
275,
1402,
423,
1802,
267,
340,
1402,
63,
344,
26,
288,
1402,
63,
3257,
275,
7086,
459,
723,
14,
1238,
2278,
4570,
8,
1556,
12,
1747,
12,
1402,
63,
344,
59,
16,
467,
1067,
680,
354,
267,
291,
14,
1213,
275,
1402,
63,
3257,
267,
15012,
459,
1580,
418,
275,
2762,
267,
754,
275,
1402,
14,
955,
63,
1345,
63,
362,
8,
1556,
12,
1747,
12,
2455,
63,
466,
534,
2350,
297,
1067,
29,
1100,
9,
267,
1504,
63,
1648,
275,
221,
291,
14,
16968,
435,
291,
423,
1122,
63,
875,
8,
1099,
459,
1047,
1105,
267,
340,
291,
14,
16968,
26,
288,
4730,
275,
942,
288,
347,
664,
63,
16968,
63,
576,
8,
16968,
275,
990,
2881,
275,
12319,
355,
5767,
275,
221,
1402,
14,
739,
63,
923,
8,
1556,
12,
1747,
12,
2881,
12,
1504,
63,
1648,
12,
20371,
2360,
378,
12,
488,
12,
1067,
9,
355,
367,
6488,
315,
5767,
26,
490,
6488,
13742,
923,
418,
275,
715,
490,
6488,
13742,
889,
63,
8914,
418,
275,
291,
14,
16968,
63,
889,
63,
8914,
490,
6488,
13742,
22674,
63,
991,
418,
275,
20371,
59,
16,
61,
340,
334,
6074,
8,
16968,
12,
769,
9,
436,
20371,
9,
587,
20371,
490,
367,
289,
315,
1504,
63,
1648,
26,
717,
340,
289,
440,
315,
6488,
26,
1169,
6488,
14,
873,
2561,
70,
26,
797,
1552,
717,
916,
1228,
8,
2761,
59,
70,
467,
2008,
304,
1169,
6488,
59,
70,
61,
275,
6488,
59,
70,
1527,
17,
61,
490,
4730,
14,
740,
8,
2761,
9,
490,
6506,
63,
16968,
275,
334,
2761,
14,
362,
10714,
1100,
297,
1052,
4992,
362,
360,
923,
63,
991,
23993,
566,
490,
6506,
63,
2261,
275,
6488,
14,
362,
10714,
2261,
297,
3073,
490,
340,
6506,
63,
16968,
26,
717,
664,
63,
16968,
63,
576,
8,
5216,
63,
16968,
12,
6506,
63,
2261,
9,
490,
587,
26,
717,
340,
291,
14,
16968,
63,
889,
63,
8914,
26,
1169,
1980,
717,
1982,
63,
1580,
275,
1402,
14,
1733,
8,
1556,
12,
1747,
12,
6506,
63,
2261,
9,
717,
522,
275,
1402,
14,
739,
8,
1556,
12,
1747,
12,
1982,
63,
1580,
12,
754,
459,
955,
2278,
1612,
1062,
1067,
9,
717,
522,
14,
3191,
8,
2734,
671,
12,
89,
26,
10467,
8,
1580,
14,
1080,
8,
88,
459,
344,
3815,
2762,
14,
1080,
8,
89,
459,
344,
26991,
717,
4730,
14,
2880,
8,
470,
9,
288,
8266,
275,
4274,
344,
1673,
262,
297,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TeamTwisted/external_chromium_org
|
net/tools/testserver/testserver_base.py
|
57
|
8501
|
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import BaseHTTPServer
import errno
import json
import optparse
import os
import re
import socket
import SocketServer
import struct
import sys
import warnings
import tlslite.errors
# Ignore deprecation warnings, they make our output more cluttered.
warnings.filterwarnings("ignore", category=DeprecationWarning)
if sys.platform == 'win32':
import msvcrt
# Using debug() seems to cause hangs on XP: see http://crbug.com/64515.
debug_output = sys.stderr
def debug(string):
debug_output.write(string + "\n")
debug_output.flush()
class Error(Exception):
"""Error class for this module."""
class OptionError(Error):
"""Error for bad command line options."""
class FileMultiplexer(object):
def __init__(self, fd1, fd2) :
self.__fd1 = fd1
self.__fd2 = fd2
def __del__(self) :
if self.__fd1 != sys.stdout and self.__fd1 != sys.stderr:
self.__fd1.close()
if self.__fd2 != sys.stdout and self.__fd2 != sys.stderr:
self.__fd2.close()
def write(self, text) :
self.__fd1.write(text)
self.__fd2.write(text)
def flush(self) :
self.__fd1.flush()
self.__fd2.flush()
class ClientRestrictingServerMixIn:
"""Implements verify_request to limit connections to our configured IP
address."""
def verify_request(self, _request, client_address):
return client_address[0] == self.server_address[0]
class BrokenPipeHandlerMixIn:
"""Allows the server to deal with "broken pipe" errors (which happen if the
browser quits with outstanding requests, like for the favicon). This mix-in
requires the class to derive from SocketServer.BaseServer and not override its
handle_error() method. """
def handle_error(self, request, client_address):
value = sys.exc_info()[1]
if isinstance(value, tlslite.errors.TLSClosedConnectionError):
print "testserver.py: Closed connection"
return
if isinstance(value, socket.error):
err = value.args[0]
if sys.platform in ('win32', 'cygwin'):
# "An established connection was aborted by the software in your host."
pipe_err = 10053
else:
pipe_err = errno.EPIPE
if err == pipe_err:
print "testserver.py: Broken pipe"
return
if err == errno.ECONNRESET:
print "testserver.py: Connection reset by peer"
return
SocketServer.BaseServer.handle_error(self, request, client_address)
class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
"""This is a specialization of BaseHTTPServer to allow it
to be exited cleanly (by setting its "stop" member to True)."""
def serve_forever(self):
self.stop = False
self.nonce_time = None
while not self.stop:
self.handle_request()
self.socket.close()
def MultiplexerHack(std_fd, log_fd):
"""Creates a FileMultiplexer that will write to both specified files.
When running on Windows XP bots, stdout and stderr will be invalid file
handles, so log_fd will be returned directly. (This does not occur if you
run the test suite directly from a console, but only if the output of the
test executable is redirected.)
"""
if std_fd.fileno() <= 0:
return log_fd
return FileMultiplexer(std_fd, log_fd)
class BasePageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def __init__(self, request, client_address, socket_server,
connect_handlers, get_handlers, head_handlers, post_handlers,
put_handlers):
self._connect_handlers = connect_handlers
self._get_handlers = get_handlers
self._head_handlers = head_handlers
self._post_handlers = post_handlers
self._put_handlers = put_handlers
BaseHTTPServer.BaseHTTPRequestHandler.__init__(
self, request, client_address, socket_server)
def log_request(self, *args, **kwargs):
# Disable request logging to declutter test log output.
pass
def _ShouldHandleRequest(self, handler_name):
"""Determines if the path can be handled by the handler.
We consider a handler valid if the path begins with the
handler name. It can optionally be followed by "?*", "/*".
"""
pattern = re.compile('%s($|\?|/).*' % handler_name)
return pattern.match(self.path)
def do_CONNECT(self):
for handler in self._connect_handlers:
if handler():
return
def do_GET(self):
for handler in self._get_handlers:
if handler():
return
def do_HEAD(self):
for handler in self._head_handlers:
if handler():
return
def do_POST(self):
for handler in self._post_handlers:
if handler():
return
def do_PUT(self):
for handler in self._put_handlers:
if handler():
return
class TestServerRunner(object):
"""Runs a test server and communicates with the controlling C++ test code.
Subclasses should override the create_server method to create their server
object, and the add_options method to add their own options.
"""
def __init__(self):
self.option_parser = optparse.OptionParser()
self.add_options()
def main(self):
self.options, self.args = self.option_parser.parse_args()
logfile = open(self.options.log_file, 'w')
sys.stderr = MultiplexerHack(sys.stderr, logfile)
if self.options.log_to_console:
sys.stdout = MultiplexerHack(sys.stdout, logfile)
else:
sys.stdout = logfile
server_data = {
'host': self.options.host,
}
self.server = self.create_server(server_data)
self._notify_startup_complete(server_data)
self.run_server()
def create_server(self, server_data):
"""Creates a server object and returns it.
Must populate server_data['port'], and can set additional server_data
elements if desired."""
raise NotImplementedError()
def run_server(self):
try:
self.server.serve_forever()
except KeyboardInterrupt:
print 'shutting down server'
self.server.stop = True
def add_options(self):
self.option_parser.add_option('--startup-pipe', type='int',
dest='startup_pipe',
help='File handle of pipe to parent process')
self.option_parser.add_option('--log-to-console', action='store_const',
const=True, default=False,
dest='log_to_console',
help='Enables or disables sys.stdout logging '
'to the console.')
self.option_parser.add_option('--log-file', default='testserver.log',
dest='log_file',
help='The name of the server log file.')
self.option_parser.add_option('--port', default=0, type='int',
help='Port used by the server. If '
'unspecified, the server will listen on an '
'ephemeral port.')
self.option_parser.add_option('--host', default='127.0.0.1',
dest='host',
help='Hostname or IP upon which the server '
'will listen. Client connections will also '
'only be allowed from this address.')
self.option_parser.add_option('--data-dir', dest='data_dir',
help='Directory from which to read the '
'files.')
def _notify_startup_complete(self, server_data):
# Notify the parent that we've started. (BaseServer subclasses
# bind their sockets on construction.)
if self.options.startup_pipe is not None:
server_data_json = json.dumps(server_data)
server_data_len = len(server_data_json)
print 'sending server_data: %s (%d bytes)' % (
server_data_json, server_data_len)
if sys.platform == 'win32':
fd = msvcrt.open_osfhandle(self.options.startup_pipe, 0)
else:
fd = self.options.startup_pipe
startup_pipe = os.fdopen(fd, "w")
# First write the data length as an unsigned 4-byte value. This
# is _not_ using network byte ordering since the other end of the
# pipe is on the same machine.
startup_pipe.write(struct.pack('=L', server_data_len))
startup_pipe.write(server_data_json)
startup_pipe.close()
|
bsd-3-clause
|
[
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
3523,
14938,
199,
646,
7554,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
17766,
3120,
199,
646,
2702,
199,
646,
984,
199,
646,
3598,
199,
199,
646,
15142,
5333,
14,
2550,
199,
199,
3,
14092,
17831,
3598,
12,
2985,
1852,
4154,
1072,
1655,
824,
337,
3014,
14,
199,
5451,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
9,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
492,
31756,
199,
199,
3,
11719,
3105,
342,
12237,
370,
7675,
394,
20068,
641,
1323,
48,
26,
1937,
1455,
921,
1556,
1266,
14,
957,
15,
13067,
1046,
14,
199,
1757,
63,
1199,
275,
984,
14,
3083,
199,
318,
3105,
8,
875,
304,
523,
3105,
63,
1199,
14,
952,
8,
875,
435,
1867,
78,
531,
523,
3105,
63,
1199,
14,
4939,
342,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
547,
1021,
367,
642,
859,
1041,
421,
199,
533,
3207,
547,
8,
547,
304,
523,
408,
547,
367,
4875,
1414,
1004,
1511,
1041,
421,
199,
533,
3814,
8433,
32200,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
6111,
17,
12,
6111,
18,
9,
520,
272,
291,
855,
2592,
17,
275,
6111,
17,
272,
291,
855,
2592,
18,
275,
6111,
18,
819,
347,
636,
2264,
721,
277,
9,
520,
272,
340,
291,
855,
2592,
17,
1137,
984,
14,
2703,
436,
291,
855,
2592,
17,
1137,
984,
14,
3083,
26,
489,
291,
855,
2592,
17,
14,
1600,
342,
272,
340,
291,
855,
2592,
18,
1137,
984,
14,
2703,
436,
291,
855,
2592,
18,
1137,
984,
14,
3083,
26,
489,
291,
855,
2592,
18,
14,
1600,
342,
819,
347,
2218,
8,
277,
12,
1318,
9,
520,
272,
291,
855,
2592,
17,
14,
952,
8,
505,
9,
272,
291,
855,
2592,
18,
14,
952,
8,
505,
9,
819,
347,
8976,
8,
277,
9,
520,
272,
291,
855,
2592,
17,
14,
4939,
342,
272,
291,
855,
2592,
18,
14,
4939,
342,
421,
199,
533,
6810,
497,
4768,
316,
3120,
26527,
26,
523,
408,
29452,
4911,
63,
1069,
370,
2304,
6947,
370,
4154,
7526,
3531,
523,
2287,
1041,
819,
347,
4911,
63,
1069,
8,
277,
12,
485,
1069,
12,
1890,
63,
1562,
304,
272,
372,
1890,
63,
1562,
59,
16,
61,
508,
291,
14,
1000,
63,
1562,
59,
16,
61,
421,
199,
533,
23804,
11867,
2461,
26527,
26,
523,
408,
19780,
314,
1654,
370,
7962,
543,
298,
15697,
5200,
2,
2552,
334,
6777,
5992,
340,
314,
523,
7042,
2173,
1405,
543,
734,
18126,
4145,
12,
2839,
367,
314,
29139,
680,
961,
13667,
13,
262,
523,
5074,
314,
1021,
370,
23519,
687,
17766,
3120,
14,
1563,
3120,
436,
440,
4278,
2399,
523,
2429,
63,
705,
342,
1083,
14,
408,
819,
347,
2429,
63,
705,
8,
277,
12,
1056,
12,
1890,
63,
1562,
304,
272,
574,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
272,
340,
1228,
8,
585,
12,
15142,
5333,
14,
2550,
14,
10224,
15190,
20349,
304,
489,
870,
298,
22471,
14,
647,
26,
5980,
939,
1950,
2,
489,
372,
272,
340,
1228,
8,
585,
12,
2838,
14,
705,
304,
489,
2329,
275,
574,
14,
589,
59,
16,
61,
489,
340,
984,
14,
3246,
315,
661,
2676,
708,
297,
283,
16680,
735,
267,
327,
298,
2493,
23594,
1950,
1990,
26815,
701,
314,
2032,
315,
2195,
1591,
2122,
267,
5200,
63,
1508,
275,
2948,
2481,
489,
587,
26,
267,
5200,
63,
1508,
275,
7554,
14,
37,
6089,
489,
340,
2329,
508,
5200,
63,
1508,
26,
267,
870,
298,
22471,
14,
647,
26,
23804,
5200,
2,
267,
372,
489,
340,
2329,
508,
7554,
14,
37,
17489,
18066,
26,
267,
870,
298,
22471,
14,
647,
26,
8113,
5305,
701,
9104,
2,
267,
372,
272,
17766,
3120,
14,
1563,
3120,
14,
2479,
63,
705,
8,
277,
12,
1056,
12,
1890,
63,
1562,
9,
421,
199,
533,
8015,
80,
461,
14938,
8,
1563,
14938,
14,
14938,
304,
523,
408,
2765,
365,
282,
4539,
2072,
402,
3523,
14938,
370,
2040,
652,
523,
370,
506,
22987,
3633,
590,
334,
991,
4260,
2399,
298,
2379,
2,
3653,
370,
715,
10477,
819,
347,
14062,
63,
21327,
8,
277,
304,
272,
291,
14,
2379,
275,
756,
272,
291,
14,
10667,
63,
521,
275,
488,
272,
1830,
440,
291,
14,
2379,
26,
489,
291,
14,
2479,
63,
1069,
342,
272,
291,
14,
3450,
14,
1600,
342,
421,
199,
318,
14326,
32200,
40,
564,
8,
1516,
63,
2592,
12,
943,
63,
2592,
304,
523,
408,
10607,
282,
3814,
8433,
32200,
626,
911,
2218,
370,
3865,
2013,
1584,
14,
819,
3979,
3879,
641,
5417,
1323,
48,
31726,
12,
3839,
436,
4635,
911,
506,
3866,
570,
523,
10022,
12,
880,
943,
63,
2592,
911,
506,
2138,
5370,
14,
221,
334,
2765,
1630,
440,
4781,
340,
1265,
523,
1255,
314,
511,
5241,
5370,
687,
282,
8559,
12,
1325,
1454,
340,
314,
1072,
402,
314,
523,
511,
7286,
365,
20884,
4959,
523,
408,
523,
340,
2418,
63,
2592,
14,
9843,
342,
2695,
378,
26,
272,
372,
943,
63,
2592,
523,
372,
3814,
8433,
32200,
8,
1516,
63,
2592,
12,
943,
63,
2592,
9,
421,
199,
533,
3523,
3276,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
819,
347,
636,
826,
721,
277,
12,
1056,
12,
1890,
63,
1562,
12,
2838,
63,
1000,
12,
2049,
4907,
63,
5586,
12,
664,
63,
5586,
12,
4854,
63,
5586,
12,
2963,
63,
5586,
12,
2049,
5324,
63,
5586,
304,
272,
291,
423,
2242,
63,
5586,
275,
4907,
63,
5586,
272,
291,
423,
362,
63,
5586,
275,
664,
63,
5586,
272,
291,
423,
2993,
63,
5586,
275,
4854,
63,
5586,
272,
291,
423,
1932,
63,
5586,
275,
2963,
63,
5586,
272,
291,
423,
524,
63,
5586,
275,
5324,
63,
5586,
272,
3523,
14938,
14,
1563,
23518,
855,
826,
721,
489,
291,
12,
1056,
12,
1890,
63,
1562,
12,
2838,
63,
1000,
9,
819,
347,
943,
63,
1069,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
17534
] |
[
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
3523,
14938,
199,
646,
7554,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
17766,
3120,
199,
646,
2702,
199,
646,
984,
199,
646,
3598,
199,
199,
646,
15142,
5333,
14,
2550,
199,
199,
3,
14092,
17831,
3598,
12,
2985,
1852,
4154,
1072,
1655,
824,
337,
3014,
14,
199,
5451,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
9,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
492,
31756,
199,
199,
3,
11719,
3105,
342,
12237,
370,
7675,
394,
20068,
641,
1323,
48,
26,
1937,
1455,
921,
1556,
1266,
14,
957,
15,
13067,
1046,
14,
199,
1757,
63,
1199,
275,
984,
14,
3083,
199,
318,
3105,
8,
875,
304,
523,
3105,
63,
1199,
14,
952,
8,
875,
435,
1867,
78,
531,
523,
3105,
63,
1199,
14,
4939,
342,
421,
199,
533,
4520,
8,
1726,
304,
523,
408,
547,
1021,
367,
642,
859,
1041,
421,
199,
533,
3207,
547,
8,
547,
304,
523,
408,
547,
367,
4875,
1414,
1004,
1511,
1041,
421,
199,
533,
3814,
8433,
32200,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
6111,
17,
12,
6111,
18,
9,
520,
272,
291,
855,
2592,
17,
275,
6111,
17,
272,
291,
855,
2592,
18,
275,
6111,
18,
819,
347,
636,
2264,
721,
277,
9,
520,
272,
340,
291,
855,
2592,
17,
1137,
984,
14,
2703,
436,
291,
855,
2592,
17,
1137,
984,
14,
3083,
26,
489,
291,
855,
2592,
17,
14,
1600,
342,
272,
340,
291,
855,
2592,
18,
1137,
984,
14,
2703,
436,
291,
855,
2592,
18,
1137,
984,
14,
3083,
26,
489,
291,
855,
2592,
18,
14,
1600,
342,
819,
347,
2218,
8,
277,
12,
1318,
9,
520,
272,
291,
855,
2592,
17,
14,
952,
8,
505,
9,
272,
291,
855,
2592,
18,
14,
952,
8,
505,
9,
819,
347,
8976,
8,
277,
9,
520,
272,
291,
855,
2592,
17,
14,
4939,
342,
272,
291,
855,
2592,
18,
14,
4939,
342,
421,
199,
533,
6810,
497,
4768,
316,
3120,
26527,
26,
523,
408,
29452,
4911,
63,
1069,
370,
2304,
6947,
370,
4154,
7526,
3531,
523,
2287,
1041,
819,
347,
4911,
63,
1069,
8,
277,
12,
485,
1069,
12,
1890,
63,
1562,
304,
272,
372,
1890,
63,
1562,
59,
16,
61,
508,
291,
14,
1000,
63,
1562,
59,
16,
61,
421,
199,
533,
23804,
11867,
2461,
26527,
26,
523,
408,
19780,
314,
1654,
370,
7962,
543,
298,
15697,
5200,
2,
2552,
334,
6777,
5992,
340,
314,
523,
7042,
2173,
1405,
543,
734,
18126,
4145,
12,
2839,
367,
314,
29139,
680,
961,
13667,
13,
262,
523,
5074,
314,
1021,
370,
23519,
687,
17766,
3120,
14,
1563,
3120,
436,
440,
4278,
2399,
523,
2429,
63,
705,
342,
1083,
14,
408,
819,
347,
2429,
63,
705,
8,
277,
12,
1056,
12,
1890,
63,
1562,
304,
272,
574,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
272,
340,
1228,
8,
585,
12,
15142,
5333,
14,
2550,
14,
10224,
15190,
20349,
304,
489,
870,
298,
22471,
14,
647,
26,
5980,
939,
1950,
2,
489,
372,
272,
340,
1228,
8,
585,
12,
2838,
14,
705,
304,
489,
2329,
275,
574,
14,
589,
59,
16,
61,
489,
340,
984,
14,
3246,
315,
661,
2676,
708,
297,
283,
16680,
735,
267,
327,
298,
2493,
23594,
1950,
1990,
26815,
701,
314,
2032,
315,
2195,
1591,
2122,
267,
5200,
63,
1508,
275,
2948,
2481,
489,
587,
26,
267,
5200,
63,
1508,
275,
7554,
14,
37,
6089,
489,
340,
2329,
508,
5200,
63,
1508,
26,
267,
870,
298,
22471,
14,
647,
26,
23804,
5200,
2,
267,
372,
489,
340,
2329,
508,
7554,
14,
37,
17489,
18066,
26,
267,
870,
298,
22471,
14,
647,
26,
8113,
5305,
701,
9104,
2,
267,
372,
272,
17766,
3120,
14,
1563,
3120,
14,
2479,
63,
705,
8,
277,
12,
1056,
12,
1890,
63,
1562,
9,
421,
199,
533,
8015,
80,
461,
14938,
8,
1563,
14938,
14,
14938,
304,
523,
408,
2765,
365,
282,
4539,
2072,
402,
3523,
14938,
370,
2040,
652,
523,
370,
506,
22987,
3633,
590,
334,
991,
4260,
2399,
298,
2379,
2,
3653,
370,
715,
10477,
819,
347,
14062,
63,
21327,
8,
277,
304,
272,
291,
14,
2379,
275,
756,
272,
291,
14,
10667,
63,
521,
275,
488,
272,
1830,
440,
291,
14,
2379,
26,
489,
291,
14,
2479,
63,
1069,
342,
272,
291,
14,
3450,
14,
1600,
342,
421,
199,
318,
14326,
32200,
40,
564,
8,
1516,
63,
2592,
12,
943,
63,
2592,
304,
523,
408,
10607,
282,
3814,
8433,
32200,
626,
911,
2218,
370,
3865,
2013,
1584,
14,
819,
3979,
3879,
641,
5417,
1323,
48,
31726,
12,
3839,
436,
4635,
911,
506,
3866,
570,
523,
10022,
12,
880,
943,
63,
2592,
911,
506,
2138,
5370,
14,
221,
334,
2765,
1630,
440,
4781,
340,
1265,
523,
1255,
314,
511,
5241,
5370,
687,
282,
8559,
12,
1325,
1454,
340,
314,
1072,
402,
314,
523,
511,
7286,
365,
20884,
4959,
523,
408,
523,
340,
2418,
63,
2592,
14,
9843,
342,
2695,
378,
26,
272,
372,
943,
63,
2592,
523,
372,
3814,
8433,
32200,
8,
1516,
63,
2592,
12,
943,
63,
2592,
9,
421,
199,
533,
3523,
3276,
2461,
8,
1563,
14938,
14,
1563,
23518,
304,
819,
347,
636,
826,
721,
277,
12,
1056,
12,
1890,
63,
1562,
12,
2838,
63,
1000,
12,
2049,
4907,
63,
5586,
12,
664,
63,
5586,
12,
4854,
63,
5586,
12,
2963,
63,
5586,
12,
2049,
5324,
63,
5586,
304,
272,
291,
423,
2242,
63,
5586,
275,
4907,
63,
5586,
272,
291,
423,
362,
63,
5586,
275,
664,
63,
5586,
272,
291,
423,
2993,
63,
5586,
275,
4854,
63,
5586,
272,
291,
423,
1932,
63,
5586,
275,
2963,
63,
5586,
272,
291,
423,
524,
63,
5586,
275,
5324,
63,
5586,
272,
3523,
14938,
14,
1563,
23518,
855,
826,
721,
489,
291,
12,
1056,
12,
1890,
63,
1562,
12,
2838,
63,
1000,
9,
819,
347,
943,
63,
1069,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
17534,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fxfitz/ansible
|
lib/ansible/modules/cloud/amazon/ec2_lc.py
|
17
|
24341
|
#!/usr/bin/python
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'certified'}
DOCUMENTATION = '''
---
module: ec2_lc
short_description: Create or delete AWS Autoscaling Launch Configurations
description:
- Can create or delete AWS Autoscaling Configurations
- Works with the ec2_asg module to manage Autoscaling Groups
notes:
- Amazon ASG Autoscaling Launch Configurations are immutable once created, so modifying the configuration after it is changed will not modify the
launch configuration on AWS. You must create a new config and assign it to the ASG instead.
- encrypted volumes are supported on versions >= 2.4
version_added: "1.6"
author:
- "Gareth Rushgrove (@garethr)"
- "Willem van Ketwich (@wilvk)"
options:
state:
description:
- Register or deregister the instance
default: present
choices: ['present', 'absent']
name:
description:
- Unique name for configuration
required: true
instance_type:
description:
- Instance type to use for the instance
required: true
image_id:
description:
- The AMI unique identifier to be used for the group
key_name:
description:
- The SSH key name to be used for access to managed instances
security_groups:
description:
- A list of security groups to apply to the instances. Since version 2.4 you can specify either security group names or IDs or a mix. Previous
to 2.4, for VPC instances, specify security group IDs and for EC2-Classic, specify either security group names or IDs.
volumes:
description:
- A list of volume dicts, each containing device name and optionally ephemeral id or snapshot id. Size and type (and number of iops for io
device type) must be specified for a new volume or a root volume, and may be passed for a snapshot volume. For any volume, a volume size less
than 1 will be interpreted as a request not to create the volume.
user_data:
description:
- Opaque blob of data which is made available to the ec2 instance. Mutually exclusive with I(user_data_path).
user_data_path:
description:
- Path to the file that contains userdata for the ec2 instances. Mutually exclusive with I(user_data).
version_added: "2.3"
kernel_id:
description:
- Kernel id for the EC2 instance
spot_price:
description:
- The spot price you are bidding. Only applies for an autoscaling group with spot instances.
instance_monitoring:
description:
- Specifies whether instances are launched with detailed monitoring.
type: bool
default: 'no'
assign_public_ip:
description:
- Used for Auto Scaling groups that launch instances into an Amazon Virtual Private Cloud. Specifies whether to assign a public IP address
to each instance launched in a Amazon VPC.
version_added: "1.8"
ramdisk_id:
description:
- A RAM disk id for the instances.
version_added: "1.8"
instance_profile_name:
description:
- The name or the Amazon Resource Name (ARN) of the instance profile associated with the IAM role for the instances.
version_added: "1.8"
ebs_optimized:
description:
- Specifies whether the instance is optimized for EBS I/O (true) or not (false).
default: false
version_added: "1.8"
classic_link_vpc_id:
description:
- Id of ClassicLink enabled VPC
version_added: "2.0"
classic_link_vpc_security_groups:
description:
- A list of security group IDs with which to associate the ClassicLink VPC instances.
version_added: "2.0"
vpc_id:
description:
- VPC ID, used when resolving security group names to IDs.
version_added: "2.4"
instance_id:
description:
- The Id of a running instance to use as a basis for a launch configuration. Can be used in place of image_id and instance_type.
version_added: "2.4"
placement_tenancy:
description:
- Determines whether the instance runs on single-tenant harware or not.
default: 'default'
version_added: "2.4"
extends_documentation_fragment:
- aws
- ec2
requirements:
- boto3 >= 1.4.4
'''
EXAMPLES = '''
# create a launch configuration using an AMI image and instance type as a basis
- name: note that encrypted volumes are only supported in >= Ansible 2.4
ec2_lc:
name: special
image_id: ami-XXX
key_name: default
security_groups: ['group', 'group2' ]
instance_type: t1.micro
volumes:
- device_name: /dev/sda1
volume_size: 100
volume_type: io1
iops: 3000
delete_on_termination: true
encrypted: true
- device_name: /dev/sdb
ephemeral: ephemeral0
# create a launch configuration using a running instance id as a basis
- ec2_lc:
name: special
instance_id: i-00a48b207ec59e948
key_name: default
security_groups: ['launch-wizard-2' ]
volumes:
- device_name: /dev/sda1
volume_size: 120
volume_type: io1
iops: 3000
delete_on_termination: true
# create a launch configuration to omit the /dev/sdf EBS device that is included in the AMI image
- ec2_lc:
name: special
image_id: ami-XXX
key_name: default
security_groups: ['group', 'group2' ]
instance_type: t1.micro
volumes:
- device_name: /dev/sdf
no_device: true
'''
RETURN = '''
arn:
description: The Amazon Resource Name of the launch configuration.
returned: when I(state=present)
type: string
sample: arn:aws:autoscaling:us-east-1:148830907657:launchConfiguration:888d9b58-d93a-40c4-90cf-759197a2621a:launchConfigurationName/launch_config_name
changed:
description: Whether the state of the launch configuration has changed.
returned: always
type: bool
sample: false
created_time:
description: The creation date and time for the launch configuration.
returned: when I(state=present)
type: string
sample: '2017-11-03 23:46:44.841000'
image_id:
description: The ID of the Amazon Machine Image used by the launch configuration.
returned: when I(state=present)
type: string
sample: ami-9be6f38c
instance_type:
description: The instance type for the instances.
returned: when I(state=present)
type: string
sample: t1.micro
name:
description: The name of the launch configuration.
returned: when I(state=present)
type: string
sample: launch_config_name
result:
description: The specification details for the launch configuration.
returned: when I(state=present)
type: complex
contains:
PlacementTenancy:
description: The tenancy of the instances, either default or dedicated.
returned: when I(state=present)
type: string
sample: default
associate_public_ip_address:
description: (EC2-VPC) Indicates whether to assign a public IP address to each instance.
returned: when I(state=present)
type: NoneType
sample: null
block_device_mappings:
description: A block device mapping, which specifies the block devices.
returned: when I(state=present)
type: complex
contains:
device_name:
description: The device name exposed to the EC2 instance (for example, /dev/sdh or xvdh).
returned: when I(state=present)
type: string
sample: /dev/sda1
ebs:
description: The information about the Amazon EBS volume.
returned: when I(state=present)
type: complex
contains:
snapshot_id:
description: The ID of the snapshot.
returned: when I(state=present)
type: NoneType
sample: null
volume_size:
description: The volume size, in GiB.
returned: when I(state=present)
type: string
sample: '100'
virtual_name:
description: The name of the virtual device (for example, ephemeral0).
returned: when I(state=present)
type: NoneType
sample: null
classic_link_vpc_id:
description: The ID of a ClassicLink-enabled VPC to link your EC2-Classic instances to.
returned: when I(state=present)
type: NoneType
sample: null
classic_link_vpc_security_groups:
description: The IDs of one or more security groups for the VPC specified in ClassicLinkVPCId.
returned: when I(state=present)
type: list
sample: []
created_time:
description: The creation date and time for the launch configuration.
returned: when I(state=present)
type: string
sample: '2017-11-03 23:46:44.841000'
delete_on_termination:
description: Indicates whether the volume is deleted on instance termination.
returned: when I(state=present)
type: bool
sample: true
ebs_optimized:
description: Indicates whether the instance is optimized for EBS I/O (true) or not (false).
returned: when I(state=present)
type: bool
sample: false
image_id:
description: The ID of the Amazon Machine Image used by the launch configuration.
returned: when I(state=present)
type: string
sample: ami-9be6f38c
instance_monitoring:
description: Indicates whether instances in this group are launched with detailed (true) or basic (false) monitoring.
returned: when I(state=present)
type: bool
sample: true
instance_profile_name:
description: The name or Amazon Resource Name (ARN) of the instance profile associated with the IAM role for the instance.
returned: when I(state=present)
type: string
sample: null
instance_type:
description: The instance type for the instances.
returned: when I(state=present)
type: string
sample: t1.micro
iops:
description: The number of I/O operations per second (IOPS) to provision for the volume.
returned: when I(state=present)
type: NoneType
sample: null
kernel_id:
description: The ID of the kernel associated with the AMI.
returned: when I(state=present)
type: string
sample: ''
key_name:
description: The name of the key pair.
returned: when I(state=present)
type: string
sample: testkey
launch_configuration_arn:
description: The Amazon Resource Name (ARN) of the launch configuration.
returned: when I(state=present)
type: string
sample: arn:aws:autoscaling:us-east-1:148830907657:launchConfiguration:888d9b58-d93a-40c4-90cf-759197a2621a:launchConfigurationName/launch_config_name
member:
description: ""
returned: when I(state=present)
type: string
sample: "\n "
name:
description: The name of the launch configuration.
returned: when I(state=present)
type: string
sample: launch_config_name
ramdisk_id:
description: The ID of the RAM disk associated with the AMI.
returned: when I(state=present)
type: string
sample: ''
security_groups:
description: The security groups to associate with the instances.
returned: when I(state=present)
type: list
sample:
- sg-5e27db2f
spot_price:
description: The price to bid when launching Spot Instances.
returned: when I(state=present)
type: NoneType
sample: null
use_block_device_types:
description: Indicates whether to suppress a device mapping.
returned: when I(state=present)
type: bool
sample: false
user_data:
description: The user data available to the instances.
returned: when I(state=present)
type: string
sample: ''
volume_type:
description: The volume type (one of standard, io1, gp2).
returned: when I(state=present)
type: NoneType
sample: null
security_groups:
description: The security groups to associate with the instances.
returned: when I(state=present)
type: list
sample:
- sg-5e27db2f
'''
import traceback
from ansible.module_utils.ec2 import (get_aws_connection_info, ec2_argument_spec, ec2_connect, camel_dict_to_snake_dict, get_ec2_security_group_ids_from_names,
boto3_conn, snake_dict_to_camel_dict, HAS_BOTO3)
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
try:
import botocore
except ImportError:
pass
def create_block_device_meta(module, volume):
# device_type has been used historically to represent volume_type,
# however ec2_vol uses volume_type, as does the BlockDeviceType, so
# we add handling for either/or but not both
if 'device_type' in volume:
if 'volume_type' in volume:
module.fail_json(msg='device_type is a deprecated name for volume_type. '
'Do not use both device_type and volume_type')
else:
module.deprecate('device_type is deprecated for block devices - use volume_type instead',
version=2.9)
# rewrite device_type key to volume_type
if 'device_type' in volume:
volume['volume_type'] = volume.pop('device_type')
if 'snapshot' not in volume and 'ephemeral' not in volume and 'no_device' not in volume:
if 'volume_size' not in volume:
module.fail_json(msg='Size must be specified when creating a new volume or modifying the root volume')
if 'snapshot' in volume:
if volume.get('volume_type') == 'io1' and 'iops' not in volume:
module.fail_json(msg='io1 volumes must have an iops value set')
if 'ephemeral' in volume:
if 'snapshot' in volume:
module.fail_json(msg='Cannot set both ephemeral and snapshot')
return_object = {}
if 'ephemeral' in volume:
return_object['VirtualName'] = volume.get('ephemeral')
if 'device_name' in volume:
return_object['DeviceName'] = volume.get('device_name')
if 'no_device' in volume:
return_object['NoDevice'] = volume.get('no_device')
if any(key in volume for key in ['snapshot', 'volume_size', 'volume_type', 'delete_on_termination', 'ips', 'encrypted']):
return_object['Ebs'] = {}
if 'snapshot' in volume:
return_object['Ebs']['SnapshotId'] = volume.get('snapshot')
if 'volume_size' in volume:
return_object['Ebs']['VolumeSize'] = int(volume.get('volume_size', 0))
if 'volume_type' in volume:
return_object['Ebs']['VolumeType'] = volume.get('volume_type')
if 'delete_on_termination' in volume:
return_object['Ebs']['DeleteOnTermination'] = volume.get('delete_on_termination', False)
if 'iops' in volume:
return_object['Ebs']['Iops'] = volume.get('iops')
if 'encrypted' in volume:
return_object['Ebs']['Encrypted'] = volume.get('encrypted')
return return_object
def create_launch_config(connection, module):
name = module.params.get('name')
vpc_id = module.params.get('vpc_id')
try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
ec2_connection = boto3_conn(module, 'client', 'ec2', region, ec2_url, **aws_connect_kwargs)
security_groups = get_ec2_security_group_ids_from_names(module.params.get('security_groups'), ec2_connection, vpc_id=vpc_id, boto3=True)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed to get Security Group IDs", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
except ValueError as e:
module.fail_json(msg="Failed to get Security Group IDs", exception=traceback.format_exc())
user_data = module.params.get('user_data')
user_data_path = module.params.get('user_data_path')
volumes = module.params['volumes']
instance_monitoring = module.params.get('instance_monitoring')
assign_public_ip = module.params.get('assign_public_ip')
instance_profile_name = module.params.get('instance_profile_name')
ebs_optimized = module.params.get('ebs_optimized')
classic_link_vpc_id = module.params.get('classic_link_vpc_id')
classic_link_vpc_security_groups = module.params.get('classic_link_vpc_security_groups')
block_device_mapping = []
convert_list = ['image_id', 'instance_type', 'instance_type', 'instance_id', 'placement_tenancy', 'key_name', 'kernel_id', 'ramdisk_id', 'spot_price']
launch_config = (snake_dict_to_camel_dict(dict((k.capitalize(), str(v)) for k, v in module.params.items() if v is not None and k in convert_list)))
if user_data_path:
try:
with open(user_data_path, 'r') as user_data_file:
user_data = user_data_file.read()
except IOError as e:
module.fail_json(msg="Failed to open file for reading", exception=traceback.format_exc())
if volumes:
for volume in volumes:
if 'device_name' not in volume:
module.fail_json(msg='Device name must be set for volume')
# Minimum volume size is 1GB. We'll use volume size explicitly set to 0 to be a signal not to create this volume
if 'volume_size' not in volume or int(volume['volume_size']) > 0:
block_device_mapping.append(create_block_device_meta(module, volume))
try:
launch_configs = connection.describe_launch_configurations(LaunchConfigurationNames=[name]).get('LaunchConfigurations')
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed to describe launch configuration by name", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
changed = False
result = {}
launch_config['LaunchConfigurationName'] = name
if security_groups is not None:
launch_config['SecurityGroups'] = security_groups
if classic_link_vpc_id is not None:
launch_config['ClassicLinkVPCId'] = classic_link_vpc_id
if instance_monitoring is not None:
launch_config['InstanceMonitoring'] = {'Enabled': instance_monitoring}
if classic_link_vpc_security_groups is not None:
launch_config['ClassicLinkVPCSecurityGroups'] = classic_link_vpc_security_groups
if block_device_mapping:
launch_config['BlockDeviceMappings'] = block_device_mapping
if instance_profile_name is not None:
launch_config['IamInstanceProfile'] = instance_profile_name
if assign_public_ip is not None:
launch_config['AssociatePublicIpAddress'] = assign_public_ip
if user_data is not None:
launch_config['UserData'] = user_data
if ebs_optimized is not None:
launch_config['EbsOptimized'] = ebs_optimized
if len(launch_configs) == 0:
try:
connection.create_launch_configuration(**launch_config)
launch_configs = connection.describe_launch_configurations(LaunchConfigurationNames=[name]).get('LaunchConfigurations')
changed = True
if launch_configs:
launch_config = launch_configs[0]
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed to create launch configuration", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
result = (dict((k, v) for k, v in launch_config.items()
if k not in ['Connection', 'CreatedTime', 'InstanceMonitoring', 'BlockDeviceMappings']))
result['CreatedTime'] = to_text(launch_config.get('CreatedTime'))
try:
result['InstanceMonitoring'] = module.boolean(launch_config.get('InstanceMonitoring').get('Enabled'))
except AttributeError:
result['InstanceMonitoring'] = False
result['BlockDeviceMappings'] = []
for block_device_mapping in launch_config.get('BlockDeviceMappings', []):
result['BlockDeviceMappings'].append(dict(device_name=block_device_mapping.get('DeviceName'), virtual_name=block_device_mapping.get('VirtualName')))
if block_device_mapping.get('Ebs') is not None:
result['BlockDeviceMappings'][-1]['ebs'] = dict(
snapshot_id=block_device_mapping.get('Ebs').get('SnapshotId'), volume_size=block_device_mapping.get('Ebs').get('VolumeSize'))
if user_data_path:
result['UserData'] = "hidden" # Otherwise, we dump binary to the user's terminal
return_object = {
'Name': result.get('LaunchConfigurationName'),
'CreatedTime': result.get('CreatedTime'),
'ImageId': result.get('ImageId'),
'Arn': result.get('LaunchConfigurationARN'),
'SecurityGroups': result.get('SecurityGroups'),
'InstanceType': result.get('InstanceType'),
'Result': result
}
module.exit_json(changed=changed, **camel_dict_to_snake_dict(return_object))
def delete_launch_config(connection, module):
try:
name = module.params.get('name')
launch_configs = connection.describe_launch_configurations(LaunchConfigurationNames=[name]).get('LaunchConfigurations')
if launch_configs:
connection.delete_launch_configuration(LaunchConfigurationName=launch_configs[0].get('LaunchConfigurationName'))
module.exit_json(changed=True)
else:
module.exit_json(changed=False)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Failed to delete launch configuration", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
name=dict(required=True),
image_id=dict(),
instance_id=dict(),
key_name=dict(),
security_groups=dict(default=[], type='list'),
user_data=dict(),
user_data_path=dict(type='path'),
kernel_id=dict(),
volumes=dict(type='list'),
instance_type=dict(),
state=dict(default='present', choices=['present', 'absent']),
spot_price=dict(type='float'),
ramdisk_id=dict(),
instance_profile_name=dict(),
ebs_optimized=dict(default=False, type='bool'),
associate_public_ip_address=dict(type='bool'),
instance_monitoring=dict(default=False, type='bool'),
assign_public_ip=dict(type='bool'),
classic_link_vpc_security_groups=dict(type='list'),
classic_link_vpc_id=dict(),
vpc_id=dict(),
placement_tenancy=dict(choices=['default', 'dedicated'])
)
)
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[['user_data', 'user_data_path']]
)
if not HAS_BOTO3:
module.fail_json(msg='boto3 required for this module')
try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
connection = boto3_conn(module, conn_type='client', resource='autoscaling', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.NoRegionError:
module.fail_json(msg=("region must be specified as a parameter in AWS_DEFAULT_REGION environment variable or in boto configuration file"))
except botocore.exceptions.ClientError as e:
module.fail_json(msg="unable to establish connection - " + str(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
state = module.params.get('state')
if state == 'present':
create_launch_config(connection, module)
elif state == 'absent':
delete_launch_config(connection, module)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7062,
18,
63,
10181,
199,
199,
3612,
63,
1802,
26,
2790,
503,
3145,
10168,
9195,
12153,
23615,
4094,
6556,
199,
199,
1802,
26,
523,
446,
6855,
1218,
503,
3145,
10168,
9195,
12153,
4094,
6556,
523,
446,
28099,
543,
314,
7062,
18,
63,
305,
71,
859,
370,
9635,
9195,
12153,
25031,
199,
199,
5983,
26,
523,
446,
14347,
437,
4254,
9195,
12153,
23615,
4094,
6556,
787,
17092,
5403,
2737,
12,
880,
24662,
314,
2897,
2410,
652,
365,
2896,
911,
440,
2811,
314,
272,
10623,
2897,
641,
10168,
14,
2047,
1471,
1218,
282,
892,
1101,
436,
5090,
652,
370,
314,
437,
4254,
3140,
14,
523,
446,
14862,
12158,
787,
3748,
641,
5459,
2356,
499,
14,
20,
199,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
199,
2502,
26,
523,
446,
298,
39,
1530,
273,
820,
2084,
71,
11750,
8593,
71,
1530,
28854,
2924,
523,
446,
298,
55,
382,
3701,
20744,
1804,
386,
87,
1158,
8593,
87,
382,
21405,
2924,
199,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
11828,
503,
477,
2683,
314,
1256,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
18276,
536,
367,
2897,
272,
1415,
26,
2549,
523,
1256,
63,
466,
26,
272,
1369,
26,
489,
446,
10066,
730,
370,
675,
367,
314,
1256,
272,
1415,
26,
2549,
523,
1834,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
31694,
3747,
5148,
370,
506,
1202,
367,
314,
1572,
523,
790,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
12027,
790,
536,
370,
506,
1202,
367,
2879,
370,
12883,
4454,
523,
6391,
63,
2634,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
6391,
4652,
370,
4838,
370,
314,
4454,
14,
9336,
1015,
499,
14,
20,
1265,
883,
4165,
1902,
6391,
1572,
1561,
503,
11449,
503,
282,
13667,
14,
221,
26902,
267,
370,
499,
14,
20,
12,
367,
19209,
4454,
12,
4165,
6391,
1572,
11449,
436,
367,
15352,
18,
13,
30722,
67,
12,
4165,
1902,
6391,
1572,
1561,
503,
11449,
14,
523,
12158,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
3301,
10809,
12,
1924,
3035,
2243,
536,
436,
14190,
26288,
1305,
503,
5740,
1305,
14,
14579,
436,
730,
334,
460,
1329,
402,
284,
1483,
367,
5890,
267,
2243,
730,
9,
1471,
506,
2013,
367,
282,
892,
3301,
503,
282,
1738,
3301,
12,
436,
1443,
506,
3032,
367,
282,
5740,
3301,
14,
2104,
1263,
3301,
12,
282,
3301,
1568,
6656,
267,
2419,
413,
911,
506,
11922,
465,
282,
1056,
440,
370,
1218,
314,
3301,
14,
523,
922,
63,
576,
26,
272,
1369,
26,
489,
446,
593,
10578,
9182,
402,
666,
1314,
365,
6326,
2808,
370,
314,
7062,
18,
1256,
14,
26550,
3163,
13914,
543,
473,
8,
751,
63,
576,
63,
515,
680,
523,
922,
63,
576,
63,
515,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
570,
626,
3509,
922,
576,
367,
314,
7062,
18,
4454,
14,
26550,
3163,
13914,
543,
473,
8,
751,
63,
576,
680,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
5114,
63,
344,
26,
272,
1369,
26,
489,
446,
24901,
1305,
367,
314,
15352,
18,
1256,
523,
23226,
63,
4777,
26,
272,
1369,
26,
489,
446,
710,
23226,
8033,
1265,
787,
330,
344,
1098,
14,
5972,
12966,
367,
376,
2599,
12153,
1572,
543,
23226,
4454,
14,
523,
1256,
63,
20554,
26,
272,
1369,
26,
489,
446,
11015,
3775,
4454,
787,
27725,
543,
16212,
20391,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
5090,
63,
3455,
63,
711,
26,
272,
1369,
26,
489,
446,
8051,
367,
9195,
17619,
316,
4652,
626,
10623,
4454,
1901,
376,
14347,
13311,
18551,
8142,
14,
11015,
3775,
370,
5090,
282,
4575,
3531,
2287,
267,
370,
1924,
1256,
27725,
315,
282,
14347,
19209,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
21394,
4032,
63,
344,
26,
272,
1369,
26,
489,
446,
437,
30207,
4543,
1305,
367,
314,
4454,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
1256,
63,
2913,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
314,
14347,
7337,
2812,
334,
26513,
9,
402,
314,
1256,
4690,
4568,
543,
314,
28155,
4719,
367,
314,
4454,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
325,
1533,
63,
25499,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
1256,
365,
20212,
367,
662,
11087,
473,
15,
47,
334,
2052,
9,
503,
440,
334,
3910,
680,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
31205,
63,
1073,
63,
11742,
63,
344,
26,
272,
1369,
26,
489,
446,
15418,
402,
8465,
2608,
67,
3834,
5223,
19209,
272,
1015,
63,
3270,
26,
298,
18,
14,
16,
2,
523,
31205,
63,
1073,
63,
11742,
63,
4416,
63,
2634,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
6391,
1572,
11449,
543,
1314,
370,
20133
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7062,
18,
63,
10181,
199,
199,
3612,
63,
1802,
26,
2790,
503,
3145,
10168,
9195,
12153,
23615,
4094,
6556,
199,
199,
1802,
26,
523,
446,
6855,
1218,
503,
3145,
10168,
9195,
12153,
4094,
6556,
523,
446,
28099,
543,
314,
7062,
18,
63,
305,
71,
859,
370,
9635,
9195,
12153,
25031,
199,
199,
5983,
26,
523,
446,
14347,
437,
4254,
9195,
12153,
23615,
4094,
6556,
787,
17092,
5403,
2737,
12,
880,
24662,
314,
2897,
2410,
652,
365,
2896,
911,
440,
2811,
314,
272,
10623,
2897,
641,
10168,
14,
2047,
1471,
1218,
282,
892,
1101,
436,
5090,
652,
370,
314,
437,
4254,
3140,
14,
523,
446,
14862,
12158,
787,
3748,
641,
5459,
2356,
499,
14,
20,
199,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
199,
2502,
26,
523,
446,
298,
39,
1530,
273,
820,
2084,
71,
11750,
8593,
71,
1530,
28854,
2924,
523,
446,
298,
55,
382,
3701,
20744,
1804,
386,
87,
1158,
8593,
87,
382,
21405,
2924,
199,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
11828,
503,
477,
2683,
314,
1256,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
18276,
536,
367,
2897,
272,
1415,
26,
2549,
523,
1256,
63,
466,
26,
272,
1369,
26,
489,
446,
10066,
730,
370,
675,
367,
314,
1256,
272,
1415,
26,
2549,
523,
1834,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
31694,
3747,
5148,
370,
506,
1202,
367,
314,
1572,
523,
790,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
12027,
790,
536,
370,
506,
1202,
367,
2879,
370,
12883,
4454,
523,
6391,
63,
2634,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
6391,
4652,
370,
4838,
370,
314,
4454,
14,
9336,
1015,
499,
14,
20,
1265,
883,
4165,
1902,
6391,
1572,
1561,
503,
11449,
503,
282,
13667,
14,
221,
26902,
267,
370,
499,
14,
20,
12,
367,
19209,
4454,
12,
4165,
6391,
1572,
11449,
436,
367,
15352,
18,
13,
30722,
67,
12,
4165,
1902,
6391,
1572,
1561,
503,
11449,
14,
523,
12158,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
3301,
10809,
12,
1924,
3035,
2243,
536,
436,
14190,
26288,
1305,
503,
5740,
1305,
14,
14579,
436,
730,
334,
460,
1329,
402,
284,
1483,
367,
5890,
267,
2243,
730,
9,
1471,
506,
2013,
367,
282,
892,
3301,
503,
282,
1738,
3301,
12,
436,
1443,
506,
3032,
367,
282,
5740,
3301,
14,
2104,
1263,
3301,
12,
282,
3301,
1568,
6656,
267,
2419,
413,
911,
506,
11922,
465,
282,
1056,
440,
370,
1218,
314,
3301,
14,
523,
922,
63,
576,
26,
272,
1369,
26,
489,
446,
593,
10578,
9182,
402,
666,
1314,
365,
6326,
2808,
370,
314,
7062,
18,
1256,
14,
26550,
3163,
13914,
543,
473,
8,
751,
63,
576,
63,
515,
680,
523,
922,
63,
576,
63,
515,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
570,
626,
3509,
922,
576,
367,
314,
7062,
18,
4454,
14,
26550,
3163,
13914,
543,
473,
8,
751,
63,
576,
680,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
5114,
63,
344,
26,
272,
1369,
26,
489,
446,
24901,
1305,
367,
314,
15352,
18,
1256,
523,
23226,
63,
4777,
26,
272,
1369,
26,
489,
446,
710,
23226,
8033,
1265,
787,
330,
344,
1098,
14,
5972,
12966,
367,
376,
2599,
12153,
1572,
543,
23226,
4454,
14,
523,
1256,
63,
20554,
26,
272,
1369,
26,
489,
446,
11015,
3775,
4454,
787,
27725,
543,
16212,
20391,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
5090,
63,
3455,
63,
711,
26,
272,
1369,
26,
489,
446,
8051,
367,
9195,
17619,
316,
4652,
626,
10623,
4454,
1901,
376,
14347,
13311,
18551,
8142,
14,
11015,
3775,
370,
5090,
282,
4575,
3531,
2287,
267,
370,
1924,
1256,
27725,
315,
282,
14347,
19209,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
21394,
4032,
63,
344,
26,
272,
1369,
26,
489,
446,
437,
30207,
4543,
1305,
367,
314,
4454,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
1256,
63,
2913,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
314,
14347,
7337,
2812,
334,
26513,
9,
402,
314,
1256,
4690,
4568,
543,
314,
28155,
4719,
367,
314,
4454,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
325,
1533,
63,
25499,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
1256,
365,
20212,
367,
662,
11087,
473,
15,
47,
334,
2052,
9,
503,
440,
334,
3910,
680,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
17,
14,
24,
2,
523,
31205,
63,
1073,
63,
11742,
63,
344,
26,
272,
1369,
26,
489,
446,
15418,
402,
8465,
2608,
67,
3834,
5223,
19209,
272,
1015,
63,
3270,
26,
298,
18,
14,
16,
2,
523,
31205,
63,
1073,
63,
11742,
63,
4416,
63,
2634,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
6391,
1572,
11449,
543,
1314,
370,
20133,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
buptlsl/django-rest-framework
|
rest_framework/utils/encoders.py
|
88
|
2310
|
"""
Helper classes for parsers.
"""
from __future__ import unicode_literals
import datetime
import decimal
import json
import uuid
from django.db.models.query import QuerySet
from django.utils import six, timezone
from django.utils.encoding import force_text
from django.utils.functional import Promise
from rest_framework.compat import total_seconds
class JSONEncoder(json.JSONEncoder):
"""
JSONEncoder subclass that knows how to encode date/time/timedelta,
decimal types, generators and other basic python objects.
"""
def default(self, obj):
# For Date Time string spec, see ECMA 262
# http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
if isinstance(obj, Promise):
return force_text(obj)
elif isinstance(obj, datetime.datetime):
representation = obj.isoformat()
if obj.microsecond:
representation = representation[:23] + representation[26:]
if representation.endswith('+00:00'):
representation = representation[:-6] + 'Z'
return representation
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.time):
if timezone and timezone.is_aware(obj):
raise ValueError("JSON can't represent timezone-aware times.")
representation = obj.isoformat()
if obj.microsecond:
representation = representation[:12]
return representation
elif isinstance(obj, datetime.timedelta):
return six.text_type(total_seconds(obj))
elif isinstance(obj, decimal.Decimal):
# Serializers will coerce decimals to strings by default.
return float(obj)
elif isinstance(obj, uuid.UUID):
return six.text_type(obj)
elif isinstance(obj, QuerySet):
return tuple(obj)
elif hasattr(obj, 'tolist'):
# Numpy arrays and array scalars.
return obj.tolist()
elif hasattr(obj, '__getitem__'):
try:
return dict(obj)
except:
pass
elif hasattr(obj, '__iter__'):
return tuple(item for item in obj)
return super(JSONEncoder, self).default(obj)
|
bsd-2-clause
|
[
624,
199,
4433,
3992,
367,
21295,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
6107,
199,
646,
2022,
199,
646,
5377,
199,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
18397,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
27724,
572,
199,
199,
504,
4618,
63,
4857,
14,
5819,
492,
3141,
63,
4515,
421,
199,
533,
4840,
6679,
8,
1001,
14,
23069,
304,
272,
408,
272,
4840,
6679,
5516,
626,
19428,
4212,
370,
3752,
1434,
15,
521,
15,
7473,
12,
272,
6107,
2943,
12,
16952,
436,
1163,
5678,
2366,
2251,
14,
272,
408,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
327,
2104,
6148,
4703,
1059,
3158,
12,
1937,
15352,
2054,
499,
2789,
267,
327,
1455,
921,
825,
391,
13,
4404,
6279,
14,
1308,
15,
825,
391,
13,
14820,
15,
21,
14,
17,
12645,
3321,
13,
1046,
14,
25,
14,
17,
14,
1046,
267,
340,
1228,
8,
1113,
12,
27724,
572,
304,
288,
372,
3542,
63,
505,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
2197,
14,
2083,
304,
288,
6025,
275,
1559,
14,
17070,
342,
288,
340,
1559,
14,
16627,
26,
355,
6025,
275,
6025,
1491,
1789,
61,
435,
6025,
59,
1479,
2938,
288,
340,
6025,
14,
4130,
19975,
383,
26,
383,
735,
355,
6025,
275,
6025,
4439,
22,
61,
435,
283,
58,
7,
288,
372,
6025,
267,
916,
1228,
8,
1113,
12,
2197,
14,
602,
304,
288,
372,
1559,
14,
17070,
342,
267,
916,
1228,
8,
1113,
12,
2197,
14,
521,
304,
288,
340,
7137,
436,
7137,
14,
374,
63,
14600,
8,
1113,
304,
355,
746,
1722,
480,
6243,
883,
1133,
2954,
7137,
13,
14600,
5431,
2685,
288,
6025,
275,
1559,
14,
17070,
342,
288,
340,
1559,
14,
16627,
26,
355,
6025,
275,
6025,
1491,
713,
61,
288,
372,
6025,
267,
916,
1228,
8,
1113,
12,
2197,
14,
7473,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
2923,
63,
4515,
8,
1113,
430,
267,
916,
1228,
8,
1113,
12,
6107,
14,
6745,
304,
288,
327,
11973,
6315,
911,
19874,
6107,
83,
370,
3326,
701,
849,
14,
288,
372,
2069,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
5377,
14,
8757,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
18397,
304,
288,
372,
2008,
8,
1113,
9,
267,
916,
2688,
8,
1113,
12,
283,
13633,
735,
288,
327,
20535,
6572,
436,
1625,
19945,
14,
288,
372,
1559,
14,
13633,
342,
267,
916,
2688,
8,
1113,
12,
2560,
6095,
12168,
288,
862,
26,
355,
372,
1211,
8,
1113,
9,
288,
871,
26,
355,
986,
267,
916,
2688,
8,
1113,
12,
2560,
1661,
12168,
288,
372,
2008,
8,
1053,
367,
1242,
315,
1559,
9,
267,
372,
1613,
8,
23069,
12,
291,
680,
885,
8,
1113,
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
] |
[
199,
4433,
3992,
367,
21295,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
6107,
199,
646,
2022,
199,
646,
5377,
199,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
18397,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
27724,
572,
199,
199,
504,
4618,
63,
4857,
14,
5819,
492,
3141,
63,
4515,
421,
199,
533,
4840,
6679,
8,
1001,
14,
23069,
304,
272,
408,
272,
4840,
6679,
5516,
626,
19428,
4212,
370,
3752,
1434,
15,
521,
15,
7473,
12,
272,
6107,
2943,
12,
16952,
436,
1163,
5678,
2366,
2251,
14,
272,
408,
272,
347,
849,
8,
277,
12,
1559,
304,
267,
327,
2104,
6148,
4703,
1059,
3158,
12,
1937,
15352,
2054,
499,
2789,
267,
327,
1455,
921,
825,
391,
13,
4404,
6279,
14,
1308,
15,
825,
391,
13,
14820,
15,
21,
14,
17,
12645,
3321,
13,
1046,
14,
25,
14,
17,
14,
1046,
267,
340,
1228,
8,
1113,
12,
27724,
572,
304,
288,
372,
3542,
63,
505,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
2197,
14,
2083,
304,
288,
6025,
275,
1559,
14,
17070,
342,
288,
340,
1559,
14,
16627,
26,
355,
6025,
275,
6025,
1491,
1789,
61,
435,
6025,
59,
1479,
2938,
288,
340,
6025,
14,
4130,
19975,
383,
26,
383,
735,
355,
6025,
275,
6025,
4439,
22,
61,
435,
283,
58,
7,
288,
372,
6025,
267,
916,
1228,
8,
1113,
12,
2197,
14,
602,
304,
288,
372,
1559,
14,
17070,
342,
267,
916,
1228,
8,
1113,
12,
2197,
14,
521,
304,
288,
340,
7137,
436,
7137,
14,
374,
63,
14600,
8,
1113,
304,
355,
746,
1722,
480,
6243,
883,
1133,
2954,
7137,
13,
14600,
5431,
2685,
288,
6025,
275,
1559,
14,
17070,
342,
288,
340,
1559,
14,
16627,
26,
355,
6025,
275,
6025,
1491,
713,
61,
288,
372,
6025,
267,
916,
1228,
8,
1113,
12,
2197,
14,
7473,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
2923,
63,
4515,
8,
1113,
430,
267,
916,
1228,
8,
1113,
12,
6107,
14,
6745,
304,
288,
327,
11973,
6315,
911,
19874,
6107,
83,
370,
3326,
701,
849,
14,
288,
372,
2069,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
5377,
14,
8757,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
1113,
9,
267,
916,
1228,
8,
1113,
12,
18397,
304,
288,
372,
2008,
8,
1113,
9,
267,
916,
2688,
8,
1113,
12,
283,
13633,
735,
288,
327,
20535,
6572,
436,
1625,
19945,
14,
288,
372,
1559,
14,
13633,
342,
267,
916,
2688,
8,
1113,
12,
2560,
6095,
12168,
288,
862,
26,
355,
372,
1211,
8,
1113,
9,
288,
871,
26,
355,
986,
267,
916,
2688,
8,
1113,
12,
2560,
1661,
12168,
288,
372,
2008,
8,
1053,
367,
1242,
315,
1559,
9,
267,
372,
1613,
8,
23069,
12,
291,
680,
885,
8,
1113,
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,
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
] |
google/pyaedj
|
toybox/server_py3/services.py
|
1
|
25101
|
"""Google Service API classes."""
__author__ = 'Pavel Simakov (psimakov@google.com)'
import datetime
import logging
import time
from dateutil import parser
from googleapiclient import discovery
from googleapiclient import errors
import pytz
from google.cloud import datastore
RFC3339_FORMAT = '%Y-%m-%dT%H:%M:%SZ' # RFC3339
def datetime_to_rfc3339(datetime_value):
return datetime_value.strftime(RFC3339_FORMAT)
def rfc3339_to_datetime(string_value):
return parser.parse(string_value)
def to_utc(value):
return value.replace(tzinfo=pytz.utc) # pylint: disable=g-tzinfo-replace
def to_tz_name(value, tz_name):
return value.astimezone(pytz.timezone(tz_name))
EPOCH = to_utc(datetime.datetime.utcfromtimestamp(0))
def timezone_aware_now(*unused_args):
return to_utc(datetime.datetime.utcnow())
class _DiscoveryUrlClientBuilder(object):
"""Builder for service clients from a Discovery URL."""
def __init__(self, api_name, api_version, api_key, credentials):
self._api_name = api_name
self._api_version = api_version
self._credentials = credentials
self._client = discovery.build(
self.api_name,
self.api_version,
developerKey=api_key,
credentials=self.credentials,
cache_discovery=False)
@property
def api_name(self):
return self._api_name
@property
def api_version(self):
return self._api_version
@property
def credentials(self):
return self._credentials
@property
def client(self):
return self._client
class _AbstractService(object):
"""Abstract service."""
API_NAME = None
API_VERSION = None
API_KEY = None
SCOPE = None
def __init__(self, credentials, client=None):
if client:
self._client = client
else:
self._client = self.new_client(credentials)
@classmethod
def new_client(cls, credentials):
assert cls.API_NAME, 'API_NAME is required'
assert cls.API_VERSION, 'API_VERSION is required'
assert cls.SCOPE, 'SCOPE is required'
return _DiscoveryUrlClientBuilder(
cls.API_NAME, cls.API_VERSION, cls.API_KEY, credentials).client
@property
def client(self):
return self._client
class IdentityToolkitService(_AbstractService):
"""IdentityToolkit API."""
API_NAME = 'identitytoolkit'
API_VERSION = 'v3'
SCOPE = 'https://www.googleapis.com/auth/identitytoolkit'
_MAX_PAGE_SIZE = 1000
def get_account_info_by_id(self, uid):
body = {
'localId': [uid]
}
result = self._client.relyingparty().getAccountInfo(
body=body).execute()
return result.get('users', [None])[0]
def get_account_info_by_email(self, email):
body = {
'email': [email]
}
result = self._client.relyingparty().getAccountInfo(
body=body).execute()
return result.get('users', [None])[0]
def download_account(self, page_token=None, max_results=None):
if max_results is None:
max_results = self._MAX_PAGE_SIZE
assert max_results >= 1 and max_results <= self._MAX_PAGE_SIZE
body = {
'maxResults': max_results
}
if page_token:
body.update({'nextPageToken': page_token})
return self._client.relyingparty().downloadAccount(body=body).execute()
class FirebaseAdminService(IdentityToolkitService):
"""Firebase Admin API."""
SCOPES = [
IdentityToolkitService.SCOPE,
'https://www.googleapis.com/auth/firebase.readonly'
]
PROVIDER_ID_GOOGLE = 'google.com'
def get_user(self, uid):
return self.get_account_info_by_id(uid)
def get_user_by_email(self, email):
return self.get_account_info_by_email(email)
def list_users(self, page_token=None, max_results=None):
return self.download_account(
page_token=page_token, max_results=max_results)
def list_all_users(self):
page_token = None
while True:
page = self.list_users(page_token=page_token)
for user in page.get('users', []):
yield user
page_token = page['nextPageToken']
if not page_token:
break
@classmethod
def get_user_id_for(cls, federated_provider_id, user):
for provider_info in user.get('providerUserInfo', {}):
if provider_info.get('providerId') == federated_provider_id:
return provider_info['federatedId']
return None
@classmethod
def get_obfuscated_gaia_id(cls, user):
return cls.get_user_id_for(cls.PROVIDER_ID_GOOGLE, user)
class DataLossPreventionService(_AbstractService):
"""Data Loss Prevention (DLP) API."""
API_NAME = 'dlp'
API_VERSION = 'v2'
SCOPE = 'https://www.googleapis.com/auth/cloud-platform'
# NOTE(psimakov): this API does not support 'projects/google.com:XYZ'
# notation; so we decided to use well known hardcoded project
PROJECT = 'a120-cdn'
def list_info_type_names(self):
"""Lists all known detectable info types."""
request = self._client.infoTypes().list()
type_names = set()
for item in request.execute().get('infoTypes', []):
type_names.add(item['name'])
return type_names
def _info_types_for(self, type_names):
type_info = []
for name in type_names:
type_info.append({
'name': name
})
return type_info
def inspect(self, project_id, content, type_names=None):
"""Inspects content for PII."""
if not type_names:
type_names = self.list_info_type_names()
request = self._client.projects().content().inspect(
parent=project_id,
body={
'inspectConfig': {
'infoTypes': self._info_types_for(type_names)
},
'item': {
'value': content,
}
}
)
return request.execute()
class LoggingService(_AbstractService):
"""Logging API."""
API_NAME = 'logging'
API_VERSION = 'v2'
SCOPE = 'https://www.googleapis.com/auth/logging.admin'
SCOPE_W = 'https://www.googleapis.com/auth/logging.write'
SEVERITY_INFO = 'INFO'
SEVERITY_WARNING = 'WARNING'
SEVERITY_ERROR = 'ERROR'
SEVERITY = set([SEVERITY_INFO, SEVERITY_WARNING, SEVERITY_ERROR])
LIST_PAGE_SIZE = 100
ORDER_BY_ASC = 'timestamp asc'
ORDER_BY_DESC = 'timestamp desc'
_SORT_ORDER = set([ORDER_BY_ASC, ORDER_BY_DESC])
def older_than_date_filter(self, start_datetime, field_name='timestamp'):
"""Formats date filter."""
# TODO(psimakov): we may loose record here
# datastore trims milliseconds from datetime; this is very bad news; it
# causes us to have infinite loop and make no progress
#
# consider the following example:
# imagine we received the last entry from the log service with timestamp
# 2018-02-05T05:12:59.787287Z; we put it into Datastore and it gets
# truncated to 2018-02-05T05:12:59Z; now we query for timestamp over
# 2018-02-05T05:12:59Z and get that last entry 2018-02-05T05:12:59.787287Z
# again; we save it again; we query again... infinite loop, no progress
#
# if we round up milliseconds, we can skip some entrie, but we will not get
# into infinite loop
start_datetime = start_datetime.replace(microsecond=0) + datetime.timedelta(
seconds=1)
return '{field_name} >= "{start_datetime}"'.format(
field_name=field_name,
start_datetime=datetime_to_rfc3339(start_datetime)
)
def date_range_filter(self, start_datetime, end_datetime,
field_name='timestamp'):
return '{field_name} >= "{start}" AND {field_name} <= "{end}"'.format(
field_name=field_name,
start=datetime_to_rfc3339(start_datetime),
end=datetime_to_rfc3339(end_datetime)
)
def list_entries(self, resource_name, afilter=None, page_size=None,
order_by=None, limit=None):
"""Lists entries."""
page_size = page_size if page_size else self.LIST_PAGE_SIZE
page_token = None
count = 0
while True:
body = {}
body['resourceNames'] = [resource_name]
if afilter:
body['filter'] = afilter
if page_size:
body['pageSize'] = page_size
if page_token:
body['pageToken'] = page_token
if order_by:
assert order_by in self._SORT_ORDER, order_by
body['orderBy'] = order_by
request = self._client.entries().list(body=body)
response = request.execute()
page_token = response.get('nextPageToken', None)
entries = response.get('entries', [])
for entry in entries:
yield entry
count += 1
if limit and limit <= count:
return
if not page_token:
return
def write_entry(self, from_project_id, from_module_id, to_project_id,
severity, message, args):
assert severity in self.SEVERITY
self._client.entries().write(body={
'entries': [{
'logName': (
'projects/{project_id}/logs/'
'cloudresourcemanager.googleapis.com%2F'
'activity'
).format(project_id=to_project_id),
'resource': {
'type': 'gae_app',
'labels': {
'project_id': from_project_id,
'module_id': from_module_id,
'version_id': 'prod'
}
},
'severity': severity,
'json_payload': {
'message': message,
'args': args
}
}],
'partialSuccess': False,
}).execute()
class MonitoringService(_AbstractService):
"""Monitoring API."""
API_NAME = 'monitoring'
API_VERSION = 'v3'
SCOPE = 'https://www.googleapis.com/auth/monitoring'
def get_metric(self, project_id, name, duration_sec, resolution_sec,
series_reducer, series_aligner):
"""Gets metrics data."""
end = timezone_aware_now()
start = end - datetime.timedelta(seconds=duration_sec)
request = self._client.projects().timeSeries().list(
name=project_id,
filter='metric.type="%s"' % name,
interval_startTime=datetime_to_rfc3339(start),
interval_endTime=datetime_to_rfc3339(end),
aggregation_crossSeriesReducer=series_reducer,
aggregation_perSeriesAligner=series_aligner,
aggregation_alignmentPeriod='%ss' % resolution_sec,
)
return request.execute()
def get_sum_metric(self, project_id, name, duration_sec, resolution_sec):
return self.get_metric(project_id, name, duration_sec, resolution_sec,
'REDUCE_SUM', 'ALIGN_SUM')
def get_mean_metric(self, project_id, name, duration_sec, resolution_sec):
return self.get_metric(project_id, name, duration_sec, resolution_sec,
'REDUCE_SUM', 'ALIGN_MEAN')
class DatastoreService(_AbstractService):
"""Datastore API."""
API_NAME = 'datastore'
API_VERSION = 'v1'
SCOPE = 'https://www.googleapis.com/auth/datastore'
def __init__(self, credentials, namespace, project_id):
client = datastore.Client(
credentials=credentials,
namespace=namespace,
project=project_id)
super(DatastoreService, self).__init__(None, client=client)
def query(self, kind, order=None):
return self._client.query(kind=kind, order=order)
def entity(self, key):
return datastore.Entity(key=key)
class BigQueryService(_AbstractService):
"""BigQuery API."""
API_NAME = 'bigquery'
API_VERSION = 'v2'
SCOPE = 'https://www.googleapis.com/auth/bigquery'
_JOB_STATE_DONE = 'DONE'
_JOB_STATE = set(['PENDING', 'RUNNING', _JOB_STATE_DONE])
_MAX_DEFAULT_LIST_RESULTS = 500
_WAIT_DELAY_SEC = 3
def __init__(self, credentials, project_id):
self._project_id = project_id
super(BigQueryService, self).__init__(credentials)
def dataset_exists(self, dataset_id):
"""Checks if dataset exists."""
request = self._client.datasets().get(
projectId=self._project_id,
datasetId=dataset_id)
try:
request.execute()
return True
except errors.HttpError as e:
if int(e.resp.status) == 404:
return False
raise
def dataset_insert(self, dataset_id, desc):
self._client.datasets().insert(
projectId=self._project_id,
body={
'datasetReference': {
'projectId': self._project_id,
'datasetId': dataset_id,
},
'description': desc,
}
).execute()
def dataset_delete(self, dataset_id):
self._client.datasets().delete(
projectId=self._project_id,
datasetId=dataset_id,
deleteContents=True
).execute()
def list_tables(self, dataset_id):
"""Lists all dataset tables."""
return self._client.tables().list(
projectId=self._project_id,
datasetId=dataset_id,
maxResults=self._MAX_DEFAULT_LIST_RESULTS).execute()
def table_exists(self, table_id, dataset_id):
"""Checks if table exists."""
request = self._client.tables().get(
projectId=self._project_id,
datasetId=dataset_id,
tableId=table_id)
try:
request.execute()
return True
except errors.HttpError as e:
if int(e.resp.status) == 404:
return False
raise
def table_update_desc(self, table_id, dataset_id, new_desc):
self._client.tables().update(
projectId=self._project_id,
datasetId=dataset_id,
tableId=table_id,
body={
'tableReference': {
'projectId': self._project_id,
'datasetId': dataset_id,
'tableId': table_id,
},
'description': new_desc,
}
).execute()
def table_insert(self, table_id, desc, dataset_id, schema):
self._client.tables().insert(
projectId=self._project_id,
datasetId=dataset_id,
body={
'tableReference': {
'projectId': self._project_id,
'datasetId': dataset_id,
'tableId': table_id,
},
'description': desc,
'schema': schema,
}
).execute()
def table_delete(self, table_id, dataset_id):
self._client.tables().delete(
projectId=self._project_id,
datasetId=dataset_id,
tableId=table_id
).execute()
def _table_insert_many(self, table_id, rows, dataset_id):
return self._client.tabledata().insertAll(
projectId=self._project_id,
datasetId=dataset_id,
tableId=table_id,
body={
'rows': rows
},
fields='insertErrors'
).execute()
def table_insert_all(self, table_id, rows, dataset_id):
"""Insert rows into table."""
def _try_once():
result = self._table_insert_many(table_id, rows, dataset_id)
if result.get('insertErrors'):
raise Exception('Error inserting batch into %s: %s' % (
dataset_id, result))
return result
try:
return _try_once()
except Exception as e:
text = str(e)
bad_gateway_error = 'HttpError 502' in text and '"Bad Gateway"' in text
socket_error = 'Unable to connect to server at URL' in text
if socket_error or bad_gateway_error:
logging.info('Retrying _table_insert_many(): %s',
'socket error' if socket_error else 'bad gateway')
return _try_once()
raise
def query(self, sql):
return self._client.jobs().query(
projectId=self._project_id,
body={
'useLegacySql': False,
'query': sql
}
).execute()
def _check_result(self, result, no_wait):
"""Waits for job to complete."""
job_id = result.get('jobReference', {}).get('jobId')
while True:
status = result.get('status', {})
assert 'errorResult' not in status, (
'Error executing job "%s":\n%s' % (job_id, status))
state = status.get('state')
assert state in self._JOB_STATE, 'Bad job state for:\n%s' % result
if status.get('state') == self._JOB_STATE_DONE or no_wait:
return result
assert job_id, 'No jobId for:\n%s' % result
time.sleep(self._WAIT_DELAY_SEC)
result = self._client.jobs().get(
projectId=self._project_id, jobId=job_id).execute()
def extract_table(self, table_id, dataset_id, resource_uri, no_wait=True):
"""Extracts table into gs://..."""
result = self._client.jobs().insert(
projectId=self._project_id,
body={
'configuration': {
'extract': {
'sourceTable': {
'projectId': self._project_id,
'datasetId': dataset_id,
'tableId': table_id
},
'destinationUris': [
resource_uri
],
'destinationFormat': 'NEWLINE_DELIMITED_JSON'
}
}
}).execute()
return self._check_result(result, no_wait)
def copy_table(self, existing_table_id, new_table_id, dataset_id,
no_wait=True):
"""Makes a copy of a table."""
result = self._client.jobs().insert(
projectId=self._project_id,
body={
'configuration': {
'copy': {
'sourceTable': {
'projectId': self._project_id,
'datasetId': dataset_id,
'tableId': existing_table_id
},
'destinationTable': {
'projectId': self._project_id,
'datasetId': dataset_id,
'tableId': new_table_id
},
}
}
}).execute()
return self._check_result(result, no_wait)
class SheetsService(_AbstractService):
"""Sheets API."""
API_NAME = 'sheets'
API_VERSION = 'v4'
SCOPE = 'https://www.googleapis.com/auth/spreadsheets.readonly'
SCOPE_W = 'https://www.googleapis.com/auth/spreadsheets'
def get_values(self, sheet_id, value_range):
cmd = self._client.spreadsheets().values().get(
spreadsheetId=sheet_id,
range=value_range,
valueRenderOption='FORMATTED_VALUE',
majorDimension='ROWS'
)
return cmd.execute()
@classmethod
def values_to_list_of_dicts(cls, values):
"""Converts values into dict or dicts, keyed by column name."""
items = []
headers = None
for row in values:
if headers is None:
headers = values[0]
continue
name_value = {}
index = 0
for value in row:
name_value[headers[index]] = value
index += 1
items.append(name_value)
return items
@classmethod
def values_to_dict_of_dicts(cls, values, key_col_name):
"""Converts values into dict or dicts, keyed by column name."""
dict_of_dicts = {}
headers = None
for row in values:
if headers is None:
headers = values[0]
continue
name_value = {}
index = 0
for value in row:
name_value[headers[index]] = value
index += 1
key = name_value[key_col_name]
assert key not in dict_of_dicts, key
dict_of_dicts[key] = name_value
return dict_of_dicts
def get_sheet(self, sheet_id, include_grid_data=True):
cmd = self._client.spreadsheets().get(
spreadsheetId=sheet_id,
includeGridData=include_grid_data
)
return cmd.execute()
def clear_sheet(self, sheet_id, value_range):
cmd = self._client.spreadsheets().values().clear(
spreadsheetId=sheet_id,
range=value_range,
body={}
)
return cmd.execute()
def update_sheet(self, sheet_id, value_range, value_range_body,
value_input_option='USER_ENTERED', replace_none_with=None):
"""Updates sheet."""
# the None cell values are ignored during updates;
# turn them into something else if merge is not desired
if replace_none_with is not None:
rows = []
for values in value_range_body['values']:
row = []
for value in values:
row.append(value if value is not None else replace_none_with)
rows.append(row)
value_range_body['values'] = rows
cmd = self._client.spreadsheets().values().update(
spreadsheetId=sheet_id,
range=value_range,
valueInputOption=value_input_option,
body=value_range_body
)
return cmd.execute()
def append_sheet(self, sheet_id, value_range, value_range_body,
value_input_option='USER_ENTERED',
insert_data_option='INSERT_ROWS'):
"""Appends values."""
cmd = self._client.spreadsheets().values().append(
spreadsheetId=sheet_id,
range=value_range,
valueInputOption=value_input_option,
insertDataOption=insert_data_option,
body=value_range_body
)
return cmd.execute()
def _colnum_string(n):
string = ''
while n > 0:
n, remainder = divmod(n - 1, 26)
string = chr(65 + remainder) + string
return string
def _init_column_names():
"""Initializes column names and their mapping to column index."""
mapping = {}
names = []
index = 1
while index < 256:
name = _colnum_string(index)
names.append(name)
mapping[name] = index
index += 1
return names, mapping
class SheetParser(object):
"""Helper clsass to parse sheet data."""
SHEET_TO_PYTHON_DATE_FORMAT = {
'm/d/yyyy': '%m/%d/%Y',
'yyyy/m/d': '%Y/%m/%d',
'yyyy-m-d': '%Y-%m-%d',
'yyyy"-"mm"-"dd': '%Y-%m-%d', # ugly... maybe this is user entered?
}
_COLUMN_NAMES, _COLUMN_NAME_TO_INDEX = _init_column_names()
def __init__(self, data):
assert 'sheets' in data
self._data = data
@classmethod
def col_index_for(cls, name):
return cls._COLUMN_NAME_TO_INDEX[name]
@classmethod
def col_name_for(cls, index):
assert index > 0
return cls._COLUMN_NAMES[index - 1]
def sheet(self, sheet_index):
assert sheet_index >= 0
sheets = self._data['sheets']
if sheet_index >= len(sheets):
return None
return sheets[sheet_index]
def sheets(self):
index = 0
for _ in self._data['sheets']:
yield index
index += 1
def rows(self, sheet_index):
index = 0
for _ in self._data['sheets'][sheet_index]['data'][0]['rowData']:
yield index
index += 1
def sheet_count(self):
return len(self._data['sheets'])
def row_count(self, sheet_index):
return self._data['sheets'][sheet_index][
'properties']['gridProperties']['rowCount']
def col_count(self, sheet_index):
return self._data['sheets'][sheet_index][
'properties']['gridProperties']['columnCount']
def row(self, sheet_index, row_index):
return self._data['sheets'][sheet_index]['data'][0]['rowData'][row_index]
def hyperlink(self, sheet_index, row_index, column_index):
"""Extracts cell hyperlink value."""
row = self.row(sheet_index, row_index)
if 'values' not in row:
return None
if len(row['values']) <= column_index:
return None
return row['values'][column_index].get('hyperlink')
def cell(self, sheet_index, row_index, column_index, get_as_string=False):
"""Extracts cell value."""
try:
row = self.row(sheet_index, row_index)
if 'values' not in row:
return None
if len(row['values']) <= column_index:
return None
if get_as_string:
cell_data = row['values'][column_index]
if 'formattedValue' in cell_data.keys():
return cell_data['formattedValue']
elif 'effectiveValue' in cell_data.keys():
return cell_data['effectiveValue'].values()[0]
else:
return None
aformat = row['values'][column_index].get('userEnteredFormat')
if aformat:
if 'DATE' == aformat.get('numberFormat', {}).get('type', {}):
pattern = aformat['numberFormat']['pattern']
value = row['values'][column_index].get('formattedValue')
if value:
return datetime.datetime.strptime(
value, self.SHEET_TO_PYTHON_DATE_FORMAT[pattern])
return row['values'][column_index].get(
'effectiveValue', {None: None}).values()[0]
except Exception as e: # pylint: disable=broad-except
raise Exception('Failed to get cell(%s, %s, %s):\n%s' % (
sheet_index, row_index, column_index, e))
def to_grid_map(self, sheet_index):
"""Converts sheet into dict of dicts."""
rows = {}
for rindex in xrange(0, self.row_count(sheet_index)):
values = {}
for cindex in xrange(0, self.col_count(sheet_index)):
value = self.cell(sheet_index, rindex, cindex)
if value:
values[str(cindex)] = value
if values:
rows[str(rindex)] = values
return rows
class PlusService(_AbstractService):
"""Google Plus API."""
API_NAME = 'plus'
API_VERSION = 'v1'
SCOPE = 'https://www.googleapis.com/auth/plus.login'
def get_person(self, user_id):
return self._client.people().get(userId=user_id).execute()
|
apache-2.0
|
[
624,
13266,
7591,
3261,
3992,
1041,
421,
199,
363,
2502,
363,
275,
283,
4232,
1090,
428,
11744,
7697,
86,
334,
18645,
19491,
86,
32,
3098,
14,
957,
3171,
421,
199,
646,
2197,
199,
646,
2050,
199,
646,
900,
199,
504,
22208,
492,
1798,
199,
504,
6233,
25661,
492,
13172,
199,
504,
6233,
25661,
492,
2552,
199,
646,
15444,
199,
504,
6233,
14,
4091,
492,
12007,
421,
199,
14468,
29536,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
7,
221,
327,
7329,
29536,
421,
199,
318,
2197,
63,
475,
63,
8973,
29536,
8,
2083,
63,
585,
304,
523,
372,
2197,
63,
585,
14,
6205,
8,
14468,
29536,
63,
4807,
9,
421,
199,
318,
18158,
29536,
63,
475,
63,
2083,
8,
875,
63,
585,
304,
523,
372,
1798,
14,
1122,
8,
875,
63,
585,
9,
421,
199,
318,
370,
63,
5834,
8,
585,
304,
523,
372,
574,
14,
1814,
8,
9374,
29,
21948,
14,
5834,
9,
221,
327,
4287,
26,
3507,
29,
71,
13,
9374,
13,
1814,
421,
199,
318,
370,
63,
3903,
63,
354,
8,
585,
12,
5823,
63,
354,
304,
523,
372,
574,
14,
29648,
8,
21948,
14,
7145,
8,
3903,
63,
354,
430,
421,
199,
37,
1512,
1244,
275,
370,
63,
5834,
8,
2083,
14,
2083,
14,
5834,
18531,
8,
16,
430,
421,
199,
318,
7137,
63,
14600,
63,
2131,
2031,
8618,
63,
589,
304,
523,
372,
370,
63,
5834,
8,
2083,
14,
2083,
14,
10779,
1012,
421,
199,
533,
485,
2825,
6913,
6417,
3041,
6437,
8,
785,
304,
523,
408,
6437,
367,
2435,
13431,
687,
282,
5289,
6913,
2851,
1041,
819,
347,
636,
826,
721,
277,
12,
2986,
63,
354,
12,
2986,
63,
1023,
12,
2986,
63,
498,
12,
6235,
304,
272,
291,
423,
1246,
63,
354,
275,
2986,
63,
354,
272,
291,
423,
1246,
63,
1023,
275,
2986,
63,
1023,
272,
291,
423,
6942,
275,
6235,
272,
291,
423,
1258,
275,
13172,
14,
1506,
8,
267,
291,
14,
1246,
63,
354,
12,
267,
291,
14,
1246,
63,
1023,
12,
267,
15030,
1197,
29,
1246,
63,
498,
12,
267,
6235,
29,
277,
14,
6942,
12,
267,
2581,
63,
14859,
29,
797,
9,
819,
768,
1829,
523,
347,
2986,
63,
354,
8,
277,
304,
272,
372,
291,
423,
1246,
63,
354,
819,
768,
1829,
523,
347,
2986,
63,
1023,
8,
277,
304,
272,
372,
291,
423,
1246,
63,
1023,
819,
768,
1829,
523,
347,
6235,
8,
277,
304,
272,
372,
291,
423,
6942,
819,
768,
1829,
523,
347,
1890,
8,
277,
304,
272,
372,
291,
423,
1258,
421,
199,
533,
485,
8458,
3167,
8,
785,
304,
523,
408,
8458,
2435,
1041,
819,
3261,
63,
2339,
275,
488,
523,
3261,
63,
4612,
275,
488,
523,
3261,
63,
3078,
275,
488,
523,
428,
1439,
1510,
275,
488,
819,
347,
636,
826,
721,
277,
12,
6235,
12,
1890,
29,
403,
304,
272,
340,
1890,
26,
489,
291,
423,
1258,
275,
1890,
272,
587,
26,
489,
291,
423,
1258,
275,
291,
14,
1222,
63,
1258,
8,
6942,
9,
819,
768,
3744,
523,
347,
892,
63,
1258,
8,
1886,
12,
6235,
304,
272,
702,
843,
14,
3735,
63,
2339,
12,
283,
3735,
63,
2339,
365,
1415,
7,
272,
702,
843,
14,
3735,
63,
4612,
12,
283,
3735,
63,
4612,
365,
1415,
7,
272,
702,
843,
14,
17998,
12,
283,
17998,
365,
1415,
7,
272,
372,
485,
2825,
6913,
6417,
3041,
6437,
8,
267,
843,
14,
3735,
63,
2339,
12,
843,
14,
3735,
63,
4612,
12,
843,
14,
3735,
63,
3078,
12,
6235,
680,
1258,
819,
768,
1829,
523,
347,
1890,
8,
277,
304,
272,
372,
291,
423,
1258,
421,
199,
533,
22034,
5157,
6065,
3167,
1547,
8458,
3167,
304,
523,
408,
10193,
5157,
6065,
3261,
1041,
819,
3261,
63,
2339,
275,
283,
5582,
31994,
7,
523,
3261,
63,
4612,
275,
283,
86,
19,
7,
523,
428,
1439,
1510,
275,
283,
2859,
921,
1544,
14,
17533,
14,
957,
15,
1178,
15,
5582,
31994,
7,
819,
485,
4283,
63,
12898,
63,
4305,
275,
5198,
819,
347,
664,
63,
2048,
63,
815,
63,
991,
63,
344,
8,
277,
12,
1747,
304,
272,
2396,
275,
469,
267,
283,
1832,
1304,
356,
359,
1535,
61,
272,
789,
272,
754,
275,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
362,
6009,
2354,
8,
267,
2396,
29,
2030,
680,
2526,
342,
272,
372,
754,
14,
362,
360,
3707,
297,
359,
403,
11057,
16,
61,
819,
347,
664,
63,
2048,
63,
815,
63,
991,
63,
2123,
8,
277,
12,
3031,
304,
272,
2396,
275,
469,
267,
283,
2123,
356,
359,
2123,
61,
272,
789,
272,
754,
275,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
362,
6009,
2354,
8,
267,
2396,
29,
2030,
680,
2526,
342,
272,
372,
754,
14,
362,
360,
3707,
297,
359,
403,
11057,
16,
61,
819,
347,
5235,
63,
2048,
8,
277,
12,
2034,
63,
1418,
29,
403,
12,
1390,
63,
2604,
29,
403,
304,
272,
340,
1390,
63,
2604,
365,
488,
26,
489,
1390,
63,
2604,
275,
291,
423,
4283,
63,
12898,
63,
4305,
272,
702,
1390,
63,
2604,
2356,
413,
436,
1390,
63,
2604,
2695,
291,
423,
4283,
63,
12898,
63,
4305,
272,
2396,
275,
469,
267,
283,
988,
6579,
356,
1390,
63,
2604,
272,
789,
272,
340,
2034,
63,
1418,
26,
489,
2396,
14,
873,
3252,
2184,
3276,
3264,
356,
2034,
63,
1418,
1552,
272,
372,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
4249,
6009,
8,
2030,
29,
2030,
680,
2526,
342,
421,
199,
533,
15967,
1095,
4880,
3167,
8,
10193,
5157,
6065,
3167,
304,
523,
408,
13081,
1095,
9516,
3261,
1041,
819,
428,
32324,
654,
275,
359,
489,
22034,
5157,
6065,
3167,
14,
17998,
12,
489,
283,
2859,
921,
1544,
14,
17533,
14,
957,
15,
1178,
15,
8935,
1095,
14,
6753,
7,
523,
1622,
523,
6837,
540,
63,
998,
63,
24243,
275,
283,
3098,
14,
957,
7,
819,
347,
664,
63,
751,
8,
277,
12,
1747,
304,
272,
372,
291,
14,
362,
63,
2048,
63,
815,
63,
991,
63,
344,
8,
1535,
9,
819,
347,
664,
63,
751,
63,
991,
63,
2123,
8,
277,
12,
3031,
304,
272,
372,
291,
14,
362,
63,
2048,
63,
815,
63,
991,
63,
2123
] |
[
13266,
7591,
3261,
3992,
1041,
421,
199,
363,
2502,
363,
275,
283,
4232,
1090,
428,
11744,
7697,
86,
334,
18645,
19491,
86,
32,
3098,
14,
957,
3171,
421,
199,
646,
2197,
199,
646,
2050,
199,
646,
900,
199,
504,
22208,
492,
1798,
199,
504,
6233,
25661,
492,
13172,
199,
504,
6233,
25661,
492,
2552,
199,
646,
15444,
199,
504,
6233,
14,
4091,
492,
12007,
421,
199,
14468,
29536,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
7,
221,
327,
7329,
29536,
421,
199,
318,
2197,
63,
475,
63,
8973,
29536,
8,
2083,
63,
585,
304,
523,
372,
2197,
63,
585,
14,
6205,
8,
14468,
29536,
63,
4807,
9,
421,
199,
318,
18158,
29536,
63,
475,
63,
2083,
8,
875,
63,
585,
304,
523,
372,
1798,
14,
1122,
8,
875,
63,
585,
9,
421,
199,
318,
370,
63,
5834,
8,
585,
304,
523,
372,
574,
14,
1814,
8,
9374,
29,
21948,
14,
5834,
9,
221,
327,
4287,
26,
3507,
29,
71,
13,
9374,
13,
1814,
421,
199,
318,
370,
63,
3903,
63,
354,
8,
585,
12,
5823,
63,
354,
304,
523,
372,
574,
14,
29648,
8,
21948,
14,
7145,
8,
3903,
63,
354,
430,
421,
199,
37,
1512,
1244,
275,
370,
63,
5834,
8,
2083,
14,
2083,
14,
5834,
18531,
8,
16,
430,
421,
199,
318,
7137,
63,
14600,
63,
2131,
2031,
8618,
63,
589,
304,
523,
372,
370,
63,
5834,
8,
2083,
14,
2083,
14,
10779,
1012,
421,
199,
533,
485,
2825,
6913,
6417,
3041,
6437,
8,
785,
304,
523,
408,
6437,
367,
2435,
13431,
687,
282,
5289,
6913,
2851,
1041,
819,
347,
636,
826,
721,
277,
12,
2986,
63,
354,
12,
2986,
63,
1023,
12,
2986,
63,
498,
12,
6235,
304,
272,
291,
423,
1246,
63,
354,
275,
2986,
63,
354,
272,
291,
423,
1246,
63,
1023,
275,
2986,
63,
1023,
272,
291,
423,
6942,
275,
6235,
272,
291,
423,
1258,
275,
13172,
14,
1506,
8,
267,
291,
14,
1246,
63,
354,
12,
267,
291,
14,
1246,
63,
1023,
12,
267,
15030,
1197,
29,
1246,
63,
498,
12,
267,
6235,
29,
277,
14,
6942,
12,
267,
2581,
63,
14859,
29,
797,
9,
819,
768,
1829,
523,
347,
2986,
63,
354,
8,
277,
304,
272,
372,
291,
423,
1246,
63,
354,
819,
768,
1829,
523,
347,
2986,
63,
1023,
8,
277,
304,
272,
372,
291,
423,
1246,
63,
1023,
819,
768,
1829,
523,
347,
6235,
8,
277,
304,
272,
372,
291,
423,
6942,
819,
768,
1829,
523,
347,
1890,
8,
277,
304,
272,
372,
291,
423,
1258,
421,
199,
533,
485,
8458,
3167,
8,
785,
304,
523,
408,
8458,
2435,
1041,
819,
3261,
63,
2339,
275,
488,
523,
3261,
63,
4612,
275,
488,
523,
3261,
63,
3078,
275,
488,
523,
428,
1439,
1510,
275,
488,
819,
347,
636,
826,
721,
277,
12,
6235,
12,
1890,
29,
403,
304,
272,
340,
1890,
26,
489,
291,
423,
1258,
275,
1890,
272,
587,
26,
489,
291,
423,
1258,
275,
291,
14,
1222,
63,
1258,
8,
6942,
9,
819,
768,
3744,
523,
347,
892,
63,
1258,
8,
1886,
12,
6235,
304,
272,
702,
843,
14,
3735,
63,
2339,
12,
283,
3735,
63,
2339,
365,
1415,
7,
272,
702,
843,
14,
3735,
63,
4612,
12,
283,
3735,
63,
4612,
365,
1415,
7,
272,
702,
843,
14,
17998,
12,
283,
17998,
365,
1415,
7,
272,
372,
485,
2825,
6913,
6417,
3041,
6437,
8,
267,
843,
14,
3735,
63,
2339,
12,
843,
14,
3735,
63,
4612,
12,
843,
14,
3735,
63,
3078,
12,
6235,
680,
1258,
819,
768,
1829,
523,
347,
1890,
8,
277,
304,
272,
372,
291,
423,
1258,
421,
199,
533,
22034,
5157,
6065,
3167,
1547,
8458,
3167,
304,
523,
408,
10193,
5157,
6065,
3261,
1041,
819,
3261,
63,
2339,
275,
283,
5582,
31994,
7,
523,
3261,
63,
4612,
275,
283,
86,
19,
7,
523,
428,
1439,
1510,
275,
283,
2859,
921,
1544,
14,
17533,
14,
957,
15,
1178,
15,
5582,
31994,
7,
819,
485,
4283,
63,
12898,
63,
4305,
275,
5198,
819,
347,
664,
63,
2048,
63,
815,
63,
991,
63,
344,
8,
277,
12,
1747,
304,
272,
2396,
275,
469,
267,
283,
1832,
1304,
356,
359,
1535,
61,
272,
789,
272,
754,
275,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
362,
6009,
2354,
8,
267,
2396,
29,
2030,
680,
2526,
342,
272,
372,
754,
14,
362,
360,
3707,
297,
359,
403,
11057,
16,
61,
819,
347,
664,
63,
2048,
63,
815,
63,
991,
63,
2123,
8,
277,
12,
3031,
304,
272,
2396,
275,
469,
267,
283,
2123,
356,
359,
2123,
61,
272,
789,
272,
754,
275,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
362,
6009,
2354,
8,
267,
2396,
29,
2030,
680,
2526,
342,
272,
372,
754,
14,
362,
360,
3707,
297,
359,
403,
11057,
16,
61,
819,
347,
5235,
63,
2048,
8,
277,
12,
2034,
63,
1418,
29,
403,
12,
1390,
63,
2604,
29,
403,
304,
272,
340,
1390,
63,
2604,
365,
488,
26,
489,
1390,
63,
2604,
275,
291,
423,
4283,
63,
12898,
63,
4305,
272,
702,
1390,
63,
2604,
2356,
413,
436,
1390,
63,
2604,
2695,
291,
423,
4283,
63,
12898,
63,
4305,
272,
2396,
275,
469,
267,
283,
988,
6579,
356,
1390,
63,
2604,
272,
789,
272,
340,
2034,
63,
1418,
26,
489,
2396,
14,
873,
3252,
2184,
3276,
3264,
356,
2034,
63,
1418,
1552,
272,
372,
291,
423,
1258,
14,
264,
6670,
7522,
1252,
4249,
6009,
8,
2030,
29,
2030,
680,
2526,
342,
421,
199,
533,
15967,
1095,
4880,
3167,
8,
10193,
5157,
6065,
3167,
304,
523,
408,
13081,
1095,
9516,
3261,
1041,
819,
428,
32324,
654,
275,
359,
489,
22034,
5157,
6065,
3167,
14,
17998,
12,
489,
283,
2859,
921,
1544,
14,
17533,
14,
957,
15,
1178,
15,
8935,
1095,
14,
6753,
7,
523,
1622,
523,
6837,
540,
63,
998,
63,
24243,
275,
283,
3098,
14,
957,
7,
819,
347,
664,
63,
751,
8,
277,
12,
1747,
304,
272,
372,
291,
14,
362,
63,
2048,
63,
815,
63,
991,
63,
344,
8,
1535,
9,
819,
347,
664,
63,
751,
63,
991,
63,
2123,
8,
277,
12,
3031,
304,
272,
372,
291,
14,
362,
63,
2048,
63,
815,
63,
991,
63,
2123,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
junrao/kafka
|
tests/kafkatest/tests/connect_test.py
|
12
|
4906
|
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from kafkatest.tests.kafka_test import KafkaTest
from kafkatest.services.connect import ConnectStandaloneService
from kafkatest.services.console_consumer import ConsoleConsumer
from ducktape.utils.util import wait_until
from ducktape.mark import parametrize
import hashlib, subprocess, json
class ConnectStandaloneFileTest(KafkaTest):
"""
Simple test of Kafka Connect that produces data from a file in one
standalone process and consumes it on another, validating the output is
identical to the input.
"""
INPUT_FILE = "/mnt/connect.input"
OUTPUT_FILE = "/mnt/connect.output"
OFFSETS_FILE = "/mnt/connect.offsets"
TOPIC = "test"
FIRST_INPUT_LIST = ["foo", "bar", "baz"]
FIRST_INPUT = "\n".join(FIRST_INPUT_LIST) + "\n"
SECOND_INPUT_LIST = ["razz", "ma", "tazz"]
SECOND_INPUT = "\n".join(SECOND_INPUT_LIST) + "\n"
SCHEMA = { "type": "string", "optional": False }
def __init__(self, test_context):
super(ConnectStandaloneFileTest, self).__init__(test_context, num_zk=1, num_brokers=1, topics={
'test' : { 'partitions': 1, 'replication-factor': 1 }
})
self.source = ConnectStandaloneService(test_context, self.kafka, [self.INPUT_FILE, self.OFFSETS_FILE])
self.sink = ConnectStandaloneService(test_context, self.kafka, [self.OUTPUT_FILE, self.OFFSETS_FILE])
self.consumer_validator = ConsoleConsumer(test_context, 1, self.kafka, self.TOPIC, consumer_timeout_ms=1000)
@parametrize(converter="org.apache.kafka.connect.json.JsonConverter", schemas=True)
@parametrize(converter="org.apache.kafka.connect.json.JsonConverter", schemas=False)
@parametrize(converter="org.apache.kafka.connect.storage.StringConverter", schemas=None)
def test_file_source_and_sink(self, converter="org.apache.kafka.connect.json.JsonConverter", schemas=True):
assert converter != None, "converter type must be set"
# Template parameters
self.key_converter = converter
self.value_converter = converter
self.schemas = schemas
self.source.set_configs(lambda node: self.render("connect-standalone.properties", node=node), [self.render("connect-file-source.properties")])
self.sink.set_configs(lambda node: self.render("connect-standalone.properties", node=node), [self.render("connect-file-sink.properties")])
self.source.start()
self.sink.start()
# Generating data on the source node should generate new records and create new output on the sink node
self.source.node.account.ssh("echo -e -n " + repr(self.FIRST_INPUT) + " >> " + self.INPUT_FILE)
wait_until(lambda: self.validate_output(self.FIRST_INPUT), timeout_sec=60, err_msg="Data added to input file was not seen in the output file in a reasonable amount of time.")
# Restarting both should result in them picking up where they left off,
# only processing new data.
self.source.restart()
self.sink.restart()
self.source.node.account.ssh("echo -e -n " + repr(self.SECOND_INPUT) + " >> " + self.INPUT_FILE)
wait_until(lambda: self.validate_output(self.FIRST_INPUT + self.SECOND_INPUT), timeout_sec=60, err_msg="Sink output file never converged to the same state as the input file")
# Validate the format of the data in the Kafka topic
self.consumer_validator.run()
expected = json.dumps([line if not self.schemas else { "schema": self.SCHEMA, "payload": line } for line in self.FIRST_INPUT_LIST + self.SECOND_INPUT_LIST])
decoder = (json.loads if converter.endswith("JsonConverter") else str)
actual = json.dumps([decoder(x) for x in self.consumer_validator.messages_consumed[1]])
assert expected == actual, "Expected %s but saw %s in Kafka" % (expected, actual)
def validate_output(self, value):
try:
output_hash = list(self.sink.node.account.ssh_capture("md5sum " + self.OUTPUT_FILE))[0].strip().split()[0]
return output_hash == hashlib.md5(value).hexdigest()
except subprocess.CalledProcessError:
return False
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1022,
2756,
75,
27126,
14,
2219,
14,
26186,
63,
396,
492,
1804,
15294,
774,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
2242,
492,
15175,
18736,
10636,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
6614,
63,
8542,
492,
19809,
18186,
199,
504,
366,
10112,
502,
321,
14,
1208,
14,
1974,
492,
3618,
63,
8111,
199,
504,
366,
10112,
502,
321,
14,
1657,
492,
18117,
599,
806,
199,
646,
8337,
12,
3873,
12,
2022,
199,
199,
533,
15175,
18736,
10636,
1173,
774,
8,
43,
15294,
774,
304,
272,
408,
272,
5870,
511,
402,
1804,
15294,
15175,
626,
16904,
666,
687,
282,
570,
315,
1373,
272,
18042,
2112,
436,
9451,
83,
652,
641,
4573,
12,
1686,
1958,
314,
1072,
365,
272,
13130,
370,
314,
1324,
14,
272,
408,
339,
21955,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
1210,
2,
272,
18746,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
1199,
2,
339,
32633,
3597,
51,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
14253,
2,
339,
32582,
948,
275,
298,
396,
2,
339,
28137,
840,
63,
7321,
63,
4924,
275,
2097,
1421,
401,
298,
1700,
401,
298,
6185,
937,
272,
28137,
840,
63,
7321,
275,
1867,
78,
1674,
904,
8,
12903,
63,
7321,
63,
4924,
9,
435,
1867,
78,
2,
272,
5795,
1864,
36,
63,
7321,
63,
4924,
275,
2097,
345,
4348,
401,
298,
391,
401,
298,
502,
4348,
937,
272,
5795,
1864,
36,
63,
7321,
275,
1867,
78,
1674,
904,
8,
24236,
63,
7321,
63,
4924,
9,
435,
1867,
78,
2,
339,
428,
10364,
275,
469,
298,
466,
582,
298,
875,
401,
298,
4144,
582,
756,
789,
339,
347,
636,
826,
721,
277,
12,
511,
63,
1100,
304,
267,
1613,
8,
8631,
18736,
10636,
1173,
774,
12,
291,
2843,
826,
721,
396,
63,
1100,
12,
1967,
63,
20344,
29,
17,
12,
1967,
63,
20670,
75,
1192,
29,
17,
12,
17398,
3126,
288,
283,
396,
7,
520,
469,
283,
12553,
356,
413,
12,
283,
17144,
13,
4778,
356,
413,
789,
267,
3828,
398,
291,
14,
1365,
275,
15175,
18736,
10636,
3167,
8,
396,
63,
1100,
12,
291,
14,
26186,
12,
359,
277,
14,
7321,
63,
3817,
12,
291,
14,
14839,
51,
63,
3817,
566,
267,
291,
14,
11279,
275,
15175,
18736,
10636,
3167,
8,
396,
63,
1100,
12,
291,
14,
26186,
12,
359,
277,
14,
8414,
63,
3817,
12,
291,
14,
14839,
51,
63,
3817,
566,
267,
291,
14,
8542,
63,
11034,
275,
19809,
18186,
8,
396,
63,
1100,
12,
413,
12,
291,
14,
26186,
12,
291,
14,
23740,
12,
9790,
63,
2593,
63,
706,
29,
5279,
9,
339,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
549,
9,
272,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
797,
9,
272,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
3494,
14,
1558,
11907,
401,
32536,
29,
403,
9,
272,
347,
511,
63,
493,
63,
1365,
63,
460,
63,
11279,
8,
277,
12,
11109,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
549,
304,
267,
702,
11109,
1137,
488,
12,
298,
11256,
730,
1471,
506,
663,
2,
267,
327,
5458,
2633,
267,
291,
14,
498,
63,
11256,
275,
11109,
267,
291,
14,
585,
63,
11256,
275,
11109,
267,
291,
14,
9482,
275,
32536,
398,
291,
14,
1365,
14,
409,
63,
7532,
8,
2734,
1031,
26,
291,
14,
3352,
480,
2242,
13,
20323,
14,
3282,
401,
1031,
29,
932,
395,
359,
277,
14,
3352,
480,
2242,
13,
493,
13,
1365,
14,
3282,
13403,
267,
291,
14,
11279,
14,
409,
63,
7532,
8,
2734,
1031,
26,
291,
14,
3352,
480,
2242,
13,
20323,
14,
3282,
401,
1031,
29,
932,
395,
359,
277,
14,
3352,
480,
2242,
13,
493,
13,
11279,
14,
3282,
13403,
398,
291,
14,
1365,
14,
928,
342,
267,
291,
14,
11279,
14,
928,
342,
398,
327,
1464,
1958,
666,
641,
314,
1350,
1031,
1077,
3550,
892,
5767,
436,
1218,
892,
1072,
641,
314,
19241,
1031,
267,
291,
14,
1365,
14,
932,
14,
2048,
14,
5510,
480,
7878,
446,
69,
446,
78,
298,
435,
4700,
8,
277,
14,
12903,
63,
7321,
9,
435,
298,
4331,
298,
435,
291,
14,
7321,
63,
3817,
9,
267,
3618,
63,
8111,
8,
2734,
26,
291,
14,
3502,
63,
1199,
8,
277,
14,
12903,
63,
7321,
395,
2653,
63,
3321,
29,
2259,
12,
2329,
63,
1328,
628,
1451,
3483,
370,
1324,
570,
1990,
440,
6775,
315,
314,
1072,
570,
315,
282,
23255,
5982,
402,
900,
2685,
398,
327,
799,
15769,
3865,
1077,
754,
315,
3062,
12433,
1536,
2382,
2985,
3602,
2331,
12,
267,
327,
1454,
6661,
892,
666,
14,
267,
291,
14,
1365,
14,
10506,
342,
267,
291,
14,
11279,
14,
10506,
342,
398,
291,
14,
1365,
14,
932,
14,
2048,
14,
5510,
480,
7878,
446,
69,
446,
78,
298,
435,
4700,
8,
277,
14,
24236,
63,
7321,
9,
435,
298,
4331,
298,
435,
291,
14,
7321,
63,
3817,
9,
267,
3618,
63
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1022,
2756,
75,
27126,
14,
2219,
14,
26186,
63,
396,
492,
1804,
15294,
774,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
2242,
492,
15175,
18736,
10636,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
6614,
63,
8542,
492,
19809,
18186,
199,
504,
366,
10112,
502,
321,
14,
1208,
14,
1974,
492,
3618,
63,
8111,
199,
504,
366,
10112,
502,
321,
14,
1657,
492,
18117,
599,
806,
199,
646,
8337,
12,
3873,
12,
2022,
199,
199,
533,
15175,
18736,
10636,
1173,
774,
8,
43,
15294,
774,
304,
272,
408,
272,
5870,
511,
402,
1804,
15294,
15175,
626,
16904,
666,
687,
282,
570,
315,
1373,
272,
18042,
2112,
436,
9451,
83,
652,
641,
4573,
12,
1686,
1958,
314,
1072,
365,
272,
13130,
370,
314,
1324,
14,
272,
408,
339,
21955,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
1210,
2,
272,
18746,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
1199,
2,
339,
32633,
3597,
51,
63,
3817,
275,
3286,
20481,
15,
2242,
14,
14253,
2,
339,
32582,
948,
275,
298,
396,
2,
339,
28137,
840,
63,
7321,
63,
4924,
275,
2097,
1421,
401,
298,
1700,
401,
298,
6185,
937,
272,
28137,
840,
63,
7321,
275,
1867,
78,
1674,
904,
8,
12903,
63,
7321,
63,
4924,
9,
435,
1867,
78,
2,
272,
5795,
1864,
36,
63,
7321,
63,
4924,
275,
2097,
345,
4348,
401,
298,
391,
401,
298,
502,
4348,
937,
272,
5795,
1864,
36,
63,
7321,
275,
1867,
78,
1674,
904,
8,
24236,
63,
7321,
63,
4924,
9,
435,
1867,
78,
2,
339,
428,
10364,
275,
469,
298,
466,
582,
298,
875,
401,
298,
4144,
582,
756,
789,
339,
347,
636,
826,
721,
277,
12,
511,
63,
1100,
304,
267,
1613,
8,
8631,
18736,
10636,
1173,
774,
12,
291,
2843,
826,
721,
396,
63,
1100,
12,
1967,
63,
20344,
29,
17,
12,
1967,
63,
20670,
75,
1192,
29,
17,
12,
17398,
3126,
288,
283,
396,
7,
520,
469,
283,
12553,
356,
413,
12,
283,
17144,
13,
4778,
356,
413,
789,
267,
3828,
398,
291,
14,
1365,
275,
15175,
18736,
10636,
3167,
8,
396,
63,
1100,
12,
291,
14,
26186,
12,
359,
277,
14,
7321,
63,
3817,
12,
291,
14,
14839,
51,
63,
3817,
566,
267,
291,
14,
11279,
275,
15175,
18736,
10636,
3167,
8,
396,
63,
1100,
12,
291,
14,
26186,
12,
359,
277,
14,
8414,
63,
3817,
12,
291,
14,
14839,
51,
63,
3817,
566,
267,
291,
14,
8542,
63,
11034,
275,
19809,
18186,
8,
396,
63,
1100,
12,
413,
12,
291,
14,
26186,
12,
291,
14,
23740,
12,
9790,
63,
2593,
63,
706,
29,
5279,
9,
339,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
549,
9,
272,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
797,
9,
272,
768,
10396,
8,
11256,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
3494,
14,
1558,
11907,
401,
32536,
29,
403,
9,
272,
347,
511,
63,
493,
63,
1365,
63,
460,
63,
11279,
8,
277,
12,
11109,
628,
1308,
14,
3796,
14,
26186,
14,
2242,
14,
1001,
14,
9653,
11907,
401,
32536,
29,
549,
304,
267,
702,
11109,
1137,
488,
12,
298,
11256,
730,
1471,
506,
663,
2,
267,
327,
5458,
2633,
267,
291,
14,
498,
63,
11256,
275,
11109,
267,
291,
14,
585,
63,
11256,
275,
11109,
267,
291,
14,
9482,
275,
32536,
398,
291,
14,
1365,
14,
409,
63,
7532,
8,
2734,
1031,
26,
291,
14,
3352,
480,
2242,
13,
20323,
14,
3282,
401,
1031,
29,
932,
395,
359,
277,
14,
3352,
480,
2242,
13,
493,
13,
1365,
14,
3282,
13403,
267,
291,
14,
11279,
14,
409,
63,
7532,
8,
2734,
1031,
26,
291,
14,
3352,
480,
2242,
13,
20323,
14,
3282,
401,
1031,
29,
932,
395,
359,
277,
14,
3352,
480,
2242,
13,
493,
13,
11279,
14,
3282,
13403,
398,
291,
14,
1365,
14,
928,
342,
267,
291,
14,
11279,
14,
928,
342,
398,
327,
1464,
1958,
666,
641,
314,
1350,
1031,
1077,
3550,
892,
5767,
436,
1218,
892,
1072,
641,
314,
19241,
1031,
267,
291,
14,
1365,
14,
932,
14,
2048,
14,
5510,
480,
7878,
446,
69,
446,
78,
298,
435,
4700,
8,
277,
14,
12903,
63,
7321,
9,
435,
298,
4331,
298,
435,
291,
14,
7321,
63,
3817,
9,
267,
3618,
63,
8111,
8,
2734,
26,
291,
14,
3502,
63,
1199,
8,
277,
14,
12903,
63,
7321,
395,
2653,
63,
3321,
29,
2259,
12,
2329,
63,
1328,
628,
1451,
3483,
370,
1324,
570,
1990,
440,
6775,
315,
314,
1072,
570,
315,
282,
23255,
5982,
402,
900,
2685,
398,
327,
799,
15769,
3865,
1077,
754,
315,
3062,
12433,
1536,
2382,
2985,
3602,
2331,
12,
267,
327,
1454,
6661,
892,
666,
14,
267,
291,
14,
1365,
14,
10506,
342,
267,
291,
14,
11279,
14,
10506,
342,
398,
291,
14,
1365,
14,
932,
14,
2048,
14,
5510,
480,
7878,
446,
69,
446,
78,
298,
435,
4700,
8,
277,
14,
24236,
63,
7321,
9,
435,
298,
4331,
298,
435,
291,
14,
7321,
63,
3817,
9,
267,
3618,
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,
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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
] |
cjh1/AutobahnPython
|
examples/wamp/rpc/simple/example2/server.py
|
27
|
3522
|
###############################################################################
##
## Copyright 2011,2012 Tavendo GmbH
##
## 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, math
from twisted.python import log
from twisted.internet import reactor, defer
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.websocket import listenWS
from autobahn.wamp import exportRpc, \
WampServerFactory, \
WampServerProtocol
class Calc:
"""
A simple calc service we will export for Remote Procedure Calls (RPC).
All you need to do is use the @exportRpc decorator on methods
you want to provide for RPC and register a class instance in the
server factory (see below).
The method will be exported under the Python method name, or
under the (optional) name you can provide as an argument to the
decorator (see asyncSum()).
"""
@exportRpc
def add(self, x, y):
return x + y
@exportRpc
def sub(self, x, y):
return x - y
@exportRpc
def square(self, x):
MAX = 1000
if x > MAX:
## raise a custom exception
raise Exception("http://example.com/error#number_too_big",
"%d too big for me, max is %d" % (x, MAX),
MAX)
return x * x
@exportRpc
def sum(self, list):
return reduce(lambda x, y: x + y, list)
@exportRpc
def pickySum(self, list):
errs = []
for i in list:
if i % 3 == 0:
errs.append(i)
if len(errs) > 0:
raise Exception("http://example.com/error#invalid_numbers",
"one or more numbers are multiples of 3",
errs)
return reduce(lambda x, y: x + y, list)
@exportRpc
def sqrt(self, x):
return math.sqrt(x)
@exportRpc("asum")
def asyncSum(self, list):
## Simulate a slow function.
d = defer.Deferred()
reactor.callLater(3, d.callback, self.sum(list))
return d
class SimpleServerProtocol(WampServerProtocol):
"""
Demonstrates creating a simple server with Autobahn WebSockets that
responds to RPC calls.
"""
def onSessionOpen(self):
# when connection is established, we create our
# service instances ...
self.calc = Calc()
# .. and register them for RPC. that's it.
self.registerForRpc(self.calc, "http://example.com/simple/calc#")
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
log.startLogging(sys.stdout)
debug = True
else:
debug = False
factory = WampServerFactory("ws://localhost:9000", debugWamp = debug)
factory.protocol = SimpleServerProtocol
factory.setProtocolOptions(allowHixie76 = True)
listenWS(factory)
webdir = File(".")
web = Site(webdir)
reactor.listenTCP(8080, web)
reactor.run()
|
apache-2.0
|
[
11490,
199,
309,
199,
309,
221,
1898,
7760,
12,
7409,
377,
1214,
500,
79,
23428,
199,
309,
199,
309,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
309,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
309,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
309,
199,
309,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
309,
199,
309,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
309,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
309,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
309,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
309,
221,
4204,
1334,
314,
844,
14,
199,
309,
199,
11490,
199,
199,
646,
984,
12,
3473,
199,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
4901,
492,
9655,
12,
10133,
199,
504,
7390,
14,
2520,
14,
1000,
492,
11666,
199,
504,
7390,
14,
2520,
14,
1986,
492,
3814,
199,
199,
504,
2599,
2470,
6164,
14,
13508,
492,
6938,
5035,
199,
504,
2599,
2470,
6164,
14,
758,
311,
492,
4843,
15569,
12,
971,
2079,
644,
5282,
3120,
2927,
12,
971,
2079,
644,
5282,
3120,
3658,
421,
199,
533,
8256,
67,
26,
2043,
408,
2043,
437,
3486,
12831,
2435,
781,
911,
4843,
367,
17283,
2165,
12194,
28055,
334,
8171,
680,
8410,
2900,
1265,
1929,
370,
886,
365,
675,
314,
768,
3790,
15569,
7531,
641,
3102,
2043,
1265,
2934,
370,
5647,
367,
11785,
436,
2274,
282,
1021,
1256,
315,
314,
2043,
1654,
6434,
334,
3239,
5084,
680,
8410,
710,
1083,
911,
506,
16629,
1334,
314,
2018,
1083,
536,
12,
503,
2043,
1334,
314,
334,
4144,
9,
536,
1265,
883,
5647,
465,
376,
1423,
370,
314,
2043,
7531,
334,
3239,
5316,
6959,
8801,
2043,
408,
8410,
768,
3790,
15569,
2043,
347,
1050,
8,
277,
12,
671,
12,
612,
304,
489,
372,
671,
435,
612,
8410,
768,
3790,
15569,
2043,
347,
1007,
8,
277,
12,
671,
12,
612,
304,
489,
372,
671,
446,
612,
8410,
768,
3790,
15569,
2043,
347,
12386,
8,
277,
12,
671,
304,
489,
9141,
275,
5198,
489,
340,
671,
690,
9141,
26,
268,
925,
746,
282,
3537,
1919,
268,
746,
2186,
480,
1014,
921,
2694,
14,
957,
15,
705,
3,
1955,
63,
7354,
63,
5076,
401,
586,
2071,
68,
4634,
7282,
367,
562,
12,
1390,
365,
450,
68,
2,
450,
334,
88,
12,
9141,
395,
586,
9141,
9,
489,
372,
671,
627,
671,
8410,
768,
3790,
15569,
2043,
347,
3089,
8,
277,
12,
769,
304,
489,
372,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
769,
9,
8410,
768,
3790,
15569,
2043,
347,
3732,
89,
6959,
8,
277,
12,
769,
304,
489,
2329,
83,
275,
942,
489,
367,
284,
315,
769,
26,
268,
340,
284,
450,
650,
508,
378,
26,
288,
2329,
83,
14,
740,
8,
73,
9,
489,
340,
822,
8,
1508,
83,
9,
690,
378,
26,
268,
746,
2186,
480,
1014,
921,
2694,
14,
957,
15,
705,
3,
3197,
63,
10548,
401,
586,
298,
368,
503,
1655,
5579,
787,
3663,
83,
402,
650,
401,
586,
2329,
83,
9,
489,
372,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
769,
9,
8410,
768,
3790,
15569,
2043,
347,
7452,
8,
277,
12,
671,
304,
489,
372,
3473,
14,
5079,
8,
88,
9,
8410,
768,
3790,
15569,
480,
305,
453,
531,
2043,
347,
5316,
6959,
8,
277,
12,
769,
304,
489,
925,
10751,
5434,
282,
11999,
805,
14,
489,
366,
275,
10133,
14,
9937,
342,
489,
9655,
14,
1250,
22028,
8,
19,
12,
366,
14,
3058,
12,
291,
14,
1838,
8,
513,
430,
489,
372,
366,
421,
199,
533,
5870,
3120,
3658,
8,
55,
5282,
3120,
3658,
304,
2043,
408,
2043,
1487,
2106,
31216,
6425,
282,
3486,
1654,
543,
9195,
2470,
6164,
18846,
83,
626,
2043,
9163,
795,
370,
11785,
4882,
14,
2043,
408,
8410,
347,
641,
4434,
4299,
8,
277,
304,
2541,
327,
1380,
1950,
365,
23594,
12,
781,
1218,
4154,
489,
327,
2435,
4454,
2263,
489,
291,
14,
8104,
275,
8256,
67,
342,
2541,
327,
2508,
436,
2274,
3062,
367,
11785,
14,
626,
1159,
652,
14,
489,
291,
14,
2683,
1858,
15569,
8,
277,
14,
8104,
12,
298,
1014,
921,
2694,
14,
957,
15,
4129,
15,
8104,
3,
531,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
8410,
340,
822,
8,
1274,
14,
3020,
9,
690,
413,
436,
984,
14,
3020,
59,
17,
61,
508,
283,
1757,
356,
489,
943,
14,
928,
14054,
8,
1274,
14,
2703,
9,
489,
3105,
275,
715,
2043,
587,
26,
489,
3105,
275,
756,
8410,
6434,
275,
644,
5282,
3120,
2927,
480,
3569,
921,
5967,
26,
25,
1493,
401,
3105,
55,
5282,
275,
3105,
9,
2043,
6434,
14,
3922,
275,
5870,
3120,
3658,
2043,
6434,
14,
409,
3658,
4558,
8,
3306,
40,
1148,
1873,
2114,
275,
715,
9,
2043,
6938,
5035,
8,
3702,
9,
8410,
3330,
694,
275,
3814,
15857,
2043,
3330,
275,
11666,
8,
2520,
694,
9,
2043,
9655,
14,
5859,
9735,
8,
15844,
12,
3330,
9,
8410,
9655,
14,
1065,
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
] |
[
199,
309,
199,
309,
221,
1898,
7760,
12,
7409,
377,
1214,
500,
79,
23428,
199,
309,
199,
309,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
309,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
309,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
309,
199,
309,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
309,
199,
309,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
309,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
309,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
309,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
309,
221,
4204,
1334,
314,
844,
14,
199,
309,
199,
11490,
199,
199,
646,
984,
12,
3473,
199,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
4901,
492,
9655,
12,
10133,
199,
504,
7390,
14,
2520,
14,
1000,
492,
11666,
199,
504,
7390,
14,
2520,
14,
1986,
492,
3814,
199,
199,
504,
2599,
2470,
6164,
14,
13508,
492,
6938,
5035,
199,
504,
2599,
2470,
6164,
14,
758,
311,
492,
4843,
15569,
12,
971,
2079,
644,
5282,
3120,
2927,
12,
971,
2079,
644,
5282,
3120,
3658,
421,
199,
533,
8256,
67,
26,
2043,
408,
2043,
437,
3486,
12831,
2435,
781,
911,
4843,
367,
17283,
2165,
12194,
28055,
334,
8171,
680,
8410,
2900,
1265,
1929,
370,
886,
365,
675,
314,
768,
3790,
15569,
7531,
641,
3102,
2043,
1265,
2934,
370,
5647,
367,
11785,
436,
2274,
282,
1021,
1256,
315,
314,
2043,
1654,
6434,
334,
3239,
5084,
680,
8410,
710,
1083,
911,
506,
16629,
1334,
314,
2018,
1083,
536,
12,
503,
2043,
1334,
314,
334,
4144,
9,
536,
1265,
883,
5647,
465,
376,
1423,
370,
314,
2043,
7531,
334,
3239,
5316,
6959,
8801,
2043,
408,
8410,
768,
3790,
15569,
2043,
347,
1050,
8,
277,
12,
671,
12,
612,
304,
489,
372,
671,
435,
612,
8410,
768,
3790,
15569,
2043,
347,
1007,
8,
277,
12,
671,
12,
612,
304,
489,
372,
671,
446,
612,
8410,
768,
3790,
15569,
2043,
347,
12386,
8,
277,
12,
671,
304,
489,
9141,
275,
5198,
489,
340,
671,
690,
9141,
26,
268,
925,
746,
282,
3537,
1919,
268,
746,
2186,
480,
1014,
921,
2694,
14,
957,
15,
705,
3,
1955,
63,
7354,
63,
5076,
401,
586,
2071,
68,
4634,
7282,
367,
562,
12,
1390,
365,
450,
68,
2,
450,
334,
88,
12,
9141,
395,
586,
9141,
9,
489,
372,
671,
627,
671,
8410,
768,
3790,
15569,
2043,
347,
3089,
8,
277,
12,
769,
304,
489,
372,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
769,
9,
8410,
768,
3790,
15569,
2043,
347,
3732,
89,
6959,
8,
277,
12,
769,
304,
489,
2329,
83,
275,
942,
489,
367,
284,
315,
769,
26,
268,
340,
284,
450,
650,
508,
378,
26,
288,
2329,
83,
14,
740,
8,
73,
9,
489,
340,
822,
8,
1508,
83,
9,
690,
378,
26,
268,
746,
2186,
480,
1014,
921,
2694,
14,
957,
15,
705,
3,
3197,
63,
10548,
401,
586,
298,
368,
503,
1655,
5579,
787,
3663,
83,
402,
650,
401,
586,
2329,
83,
9,
489,
372,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
612,
12,
769,
9,
8410,
768,
3790,
15569,
2043,
347,
7452,
8,
277,
12,
671,
304,
489,
372,
3473,
14,
5079,
8,
88,
9,
8410,
768,
3790,
15569,
480,
305,
453,
531,
2043,
347,
5316,
6959,
8,
277,
12,
769,
304,
489,
925,
10751,
5434,
282,
11999,
805,
14,
489,
366,
275,
10133,
14,
9937,
342,
489,
9655,
14,
1250,
22028,
8,
19,
12,
366,
14,
3058,
12,
291,
14,
1838,
8,
513,
430,
489,
372,
366,
421,
199,
533,
5870,
3120,
3658,
8,
55,
5282,
3120,
3658,
304,
2043,
408,
2043,
1487,
2106,
31216,
6425,
282,
3486,
1654,
543,
9195,
2470,
6164,
18846,
83,
626,
2043,
9163,
795,
370,
11785,
4882,
14,
2043,
408,
8410,
347,
641,
4434,
4299,
8,
277,
304,
2541,
327,
1380,
1950,
365,
23594,
12,
781,
1218,
4154,
489,
327,
2435,
4454,
2263,
489,
291,
14,
8104,
275,
8256,
67,
342,
2541,
327,
2508,
436,
2274,
3062,
367,
11785,
14,
626,
1159,
652,
14,
489,
291,
14,
2683,
1858,
15569,
8,
277,
14,
8104,
12,
298,
1014,
921,
2694,
14,
957,
15,
4129,
15,
8104,
3,
531,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
8410,
340,
822,
8,
1274,
14,
3020,
9,
690,
413,
436,
984,
14,
3020,
59,
17,
61,
508,
283,
1757,
356,
489,
943,
14,
928,
14054,
8,
1274,
14,
2703,
9,
489,
3105,
275,
715,
2043,
587,
26,
489,
3105,
275,
756,
8410,
6434,
275,
644,
5282,
3120,
2927,
480,
3569,
921,
5967,
26,
25,
1493,
401,
3105,
55,
5282,
275,
3105,
9,
2043,
6434,
14,
3922,
275,
5870,
3120,
3658,
2043,
6434,
14,
409,
3658,
4558,
8,
3306,
40,
1148,
1873,
2114,
275,
715,
9,
2043,
6938,
5035,
8,
3702,
9,
8410,
3330,
694,
275,
3814,
15857,
2043,
3330,
275,
11666,
8,
2520,
694,
9,
2043,
9655,
14,
5859,
9735,
8,
15844,
12,
3330,
9,
8410,
9655,
14,
1065,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
runeh/dragonfly-stp-1
|
tools/get-interfaces/class_analizer.py
|
2
|
18250
|
import test_server, sys, os
"""
script to retrieve and analize javascript objects
starts a server ( test_server.py ) and loads one test after the other
it writes the results to "js_object_filters.js"
with -i flag it writes a list with all interfaces to "interfaces.txt"
"""
# for abstract interfaces
inheritances = \
{
"HTMLElement": "Element",
"Document": "Node",
"CharacterData": "Node"
}
# list of tests with: test name, mime type, test object, super class, list of additional properties ( optional )
def raw_tests():
return (
[
['window', 'HTML', 'this', "", WINDOW_PROPERTIES],
['element', 'XML', "document.createElement('test')", "Node"],
['xml-document', 'HTML', "document.implementation.createDocument('', 'test', null)", "Document"],
['html-document', 'HTML', "document.implementation.createHTMLDocument('')", "Document"],
['createAttribute', 'HTML', "document.createAttribute('foo')", "Node"],
['text', 'HTML', "document.createTextNode('')", "CharacterData"],
['cdata', 'HTML', "document.createCDATASection('')", "Text"],
['comment', 'HTML', "document.createComment('')", "CharacterData"],
['document-fragment', 'HTML', "document.createDocumentFragment()", "Node"],
['node-list', 'HTML', "document.createElement('div').getElementsByTagName('*')", ""],
['named-node-map', 'HTML', "document.createElement('div').attributes", ""],
['event', 'HTML', "document.createEvent('Events')", ""],
['html', 'HTML', "document.createElement('html')", "HTMLElement"],
['head', 'HTML', "document.createElement('head')", "HTMLElement"],
['link', 'HTML', "document.createElement('link')", "HTMLElement"],
['title', 'HTML', "document.createElement('title')", "HTMLElement"],
['meta', 'HTML', "document.createElement('meta')", "HTMLElement"],
['base', 'HTML', "document.createElement('base')", "HTMLElement"],
['style', 'HTML', "document.createElement('style')", "HTMLElement"],
['body', 'HTML', "document.createElement('body')", "HTMLElement"],
['unknown', 'HTML', "document.createElement('foo')", "HTMLElement"],
['input', 'HTML', "document.createElement('input')", "HTMLElement"],
['isindex', 'HTML', "document.createElement('isindex')", "HTMLElement"],
['form', 'HTML', "document.createElement('form')", "HTMLElement"],
['select', 'HTML', "document.createElement('select')", "HTMLElement"],
['optgroup', 'HTML', "document.createElement('optgroup')", "HTMLElement"],
['option', 'HTML', "document.createElement('option')", "HTMLElement"],
['textarea', 'HTML', "document.createElement('textarea')", "HTMLElement"],
['button', 'HTML', "document.createElement('button')", "HTMLElement"],
['label', 'HTML', "document.createElement('label')", "HTMLElement"],
['fieldset', 'HTML', "document.createElement('fieldset')", "HTMLElement"],
['legend', 'HTML', "document.createElement('legend')", "HTMLElement"],
['ul', 'HTML', "document.createElement('ul')", "HTMLElement"],
['ol', 'HTML', "document.createElement('ol')", "HTMLElement"],
['dl', 'HTML', "document.createElement('dl')", "HTMLElement"],
['dir', 'HTML', "document.createElement('dir')", "HTMLElement"],
['menu', 'HTML', "document.createElement('menu')", "HTMLElement"],
['li', 'HTML', "document.createElement('li')", "HTMLElement"],
['div', 'HTML', "document.createElement('div')", "HTMLElement"],
['p', 'HTML', "document.createElement('p')", "HTMLElement"],
['h1', 'HTML', "document.createElement('h1')", "HTMLElement"],
['q', 'HTML', "document.createElement('q')", "HTMLElement"],
['blockquote', 'HTML', "document.createElement('blockquote')", "HTMLElement"],
['pre', 'HTML', "document.createElement('pre')", "HTMLElement"],
['br', 'HTML', "document.createElement('br')", "HTMLElement"],
['basefont', 'HTML', "document.createElement('basefont')", "HTMLElement"],
['font', 'HTML', "document.createElement('font')", "HTMLElement"],
['ins', 'HTML', "document.createElement('ins')", "HTMLElement"],
['a', 'HTML', "document.createElement('a')", "HTMLElement"],
['image', 'HTML', "document.createElement('image')", "HTMLElement"],
['object', 'HTML', "document.createElement('object')", "HTMLElement"],
['param', 'HTML', "document.createElement('param')", "HTMLElement"],
['applet', 'HTML', "document.createElement('applet')", "HTMLElement"],
['map', 'HTML', "document.createElement('map')", "HTMLElement"],
['area', 'HTML', "document.createElement('area')", "HTMLElement"],
['script', 'HTML', "document.createElement('script')", "HTMLElement"],
['table', 'HTML', "document.createElement('table')", "HTMLElement"],
['caption', 'HTML', "document.createElement('caption')", "HTMLElement"],
['col', 'HTML', "document.createElement('col')", "HTMLElement"],
['thead', 'HTML', "document.createElement('thead')", "HTMLElement"],
['tbody', 'HTML', "document.createElement('tbody')", "HTMLElement"],
['tr', 'HTML', "document.createElement('tr')", "HTMLElement"],
['td', 'HTML', "document.createElement('td')", "HTMLElement"],
['frameset', 'HTML', "document.createElement('frameset')", "HTMLElement"],
['frame', 'HTML', "document.createElement('frame')", "HTMLElement"],
['iframe', 'HTML', "document.createElement('iframe')", "HTMLElement"],
]
)
MIME = \
{
'HTML': 'text/html',
'XML': 'application/xml'
}
f = open("get-interface.js", "rb")
JS_ONLOAD = f.read()
f.close()
TEMPLATES = \
{
"HTML": \
"""
<!doctype html>
<html>
<head>
<title> </title>
<style>
</style>
<script>
addEventListener('load', %s, false)
</script>
</head>
<body>
</body>
</html>
""" % JS_ONLOAD,
"XML": \
"""
<r>
<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
addEventListener('load', %s, false)
]]></script>
<t/>
</r>
""" % JS_ONLOAD
}
WINDOW_PROPERTIES = """[
'Array',
'Attr',
'Audio',
'Boolean',
'CDATASection',
'CSSMediaRule',
'CSSPrimitiveValue',
'CSSRule',
'CSSRuleList',
'CSSStyleDeclaration',
'CSSStyleSheet',
'CanvasGradient',
'CanvasPattern',
'CanvasRenderingContext2D',
'CanvasRenderingContext2DGame',
'CanvasRenderingContext3D',
'Comment',
'DOMError',
'DOMException',
'DOMImplementationLS',
'DOMParser',
'Date',
'Document',
'DocumentFragment',
'DocumentType',
'Element',
'Entity',
'EntityReference',
'Error',
'EvalError',
'Event',
'Function',
'HTMLAnchorElement',
'HTMLAppletElement',
'HTMLAreaElement',
'HTMLBRElement',
'HTMLBaseElement',
'HTMLBaseFontElement',
'HTMLBodyElement',
'HTMLButtonElement',
'HTMLCanvasElement',
'HTMLCollection',
'HTMLDListElement',
'HTMLDataListElement',
'HTMLDirectoryElement',
'HTMLDivElement',
'HTMLDocument',
'HTMLElement',
'HTMLEmbedElement',
'HTMLFieldSetElement',
'HTMLFontElement',
'HTMLFormElement',
'HTMLFrameElement',
'HTMLFrameSetElement',
'HTMLHRElement',
'HTMLHeadElement',
'HTMLHeadingElement',
'HTMLHtmlElement',
'HTMLIFrameElement',
'HTMLImageElement',
'HTMLInputElement',
'HTMLIsIndexElement',
'HTMLLIElement',
'HTMLLabelElement',
'HTMLLegendElement',
'HTMLLinkElement',
'HTMLMapElement',
'HTMLMarqueeElement',
'HTMLMenuElement',
'HTMLMetaElement',
'HTMLModElement',
'HTMLOListElement',
'HTMLObjectElement',
'HTMLOptGroupElement',
'HTMLOptionElement',
'HTMLOptionsCollection',
'HTMLOutputElement',
'HTMLParagraphElement',
'HTMLParamElement',
'HTMLPreElement',
'HTMLQuoteElement',
'HTMLScriptElement',
'HTMLSelectElement',
'HTMLStyleElement',
'HTMLTableCaptionElement',
'HTMLTableCellElement',
'HTMLTableColElement',
'HTMLTableElement',
'HTMLTableRowElement',
'HTMLTableSectionElement',
'HTMLTextAreaElement',
'HTMLTitleElement',
'HTMLUListElement',
'HTMLUnknownElement',
'Image',
'ImageData',
'Infinity',
'LSException',
'LSParser',
'LSParserFilter',
'Math',
'MediaList',
'MemoryError',
'MutationEvent',
'NaN',
'NamedNodeMap',
'Node',
'NodeFilter',
'NodeList',
'Notation',
'Number',
'Object',
'Option',
'Packages',
'ProcessingInstruction',
'RGBColor',
'Range',
'RangeError',
'RangeException',
'ReferenceError',
'RegExp',
'RepetitionElement',
'RepetitionEvent',
'SVGAElement',
'SVGAngle',
'SVGAnimateColorElement',
'SVGAnimateElement',
'SVGAnimateMotionElement',
'SVGAnimateTransformElement',
'SVGAnimationElement',
'SVGAudioElement',
'SVGCircleElement',
'SVGClipPathElement',
'SVGDefsElement',
'SVGDescElement',
'SVGDocument',
'SVGEllipseElement',
'SVGException',
'SVGFEBlendElement',
'SVGFEColorMatrixElement',
'SVGFEComponentTransferElement',
'SVGFECompositeElement',
'SVGFEConvolveMatrixElement',
'SVGFEDiffuseLightingElement',
'SVGFEDisplacementMapElement',
'SVGFEDistantLightElement',
'SVGFEFloodElement',
'SVGFEFuncAElement',
'SVGFEFuncBElement',
'SVGFEFuncGElement',
'SVGFEFuncRElement',
'SVGFEGaussianBlurElement',
'SVGFEImageElement',
'SVGFEMergeElement',
'SVGFEMergeNodeElement',
'SVGFEMorphologyElement',
'SVGFEOffsetElement',
'SVGFEPointLightElement',
'SVGFESpecularLightingElement',
'SVGFESpotLightElement',
'SVGFETileElement',
'SVGFETurbulenceElement',
'SVGFilterElement',
'SVGFontElement',
'SVGForeignObjectElement',
'SVGGElement',
'SVGGlyphElement',
'SVGImageElement',
'SVGLength',
'SVGLineElement',
'SVGLinearGradientElement',
'SVGMPathElement',
'SVGMarkerElement',
'SVGMaskElement',
'SVGMatrix',
'SVGMissingGlyphElement',
'SVGNumber',
'SVGPaint',
'SVGPathElement',
'SVGPathSeg',
'SVGPatternElement',
'SVGPoint',
'SVGPolygonElement',
'SVGPolylineElement',
'SVGPreserveAspectRatio',
'SVGRGBColor',
'SVGRadialGradientElement',
'SVGRect',
'SVGRectElement',
'SVGSVGElement',
'SVGScriptElement',
'SVGSetElement',
'SVGStopElement',
'SVGStyleElement',
'SVGSwitchElement',
'SVGSymbolElement',
'SVGTRefElement',
'SVGTSpanElement',
'SVGTextAreaElement',
'SVGTextContentElement',
'SVGTextElement',
'SVGTextPathElement',
'SVGTitleElement',
'SVGTransform',
'SVGUnitTypes',
'SVGUseElement',
'SVGVideoElement',
'SVGViewElement',
'SVGZoomAndPan',
'String',
'StyleSheetList',
'SyntaxError',
'Text',
'TypeError',
'URIError',
'XMLDocument',
'XMLHttpRequest',
'XMLSerializer',
'XPathEvaluator',
'XPathException',
'XPathExpression',
'XPathNSResolver',
'XPathNamespace',
'XPathResult',
'XSLTProcessor',
'__Opera_Internal_OHVBS',
'addEventListener',
'addEventStream',
'alert',
'attachEvent',
'back',
'captureEvents',
'clearInterval',
'clearTimeout',
'closed',
'confirm',
'decodeURI',
'decodeURIComponent',
'defaultStatus',
'detachEvent',
'dispatchEvent',
'document',
'encodeURI',
'encodeURIComponent',
'escape',
'eval',
'event',
'forward',
'frameElement',
'frames',
'getComputedStyle',
'getSelection',
'history',
'innerHeight',
'innerWidth',
'isFinite',
'isNaN',
'java',
'length',
'location',
'name',
'navigate',
'navigator',
'netscape',
'open',
'opener',
'opera',
'outerHeight',
'outerWidth',
'pageXOffset',
'pageYOffset',
'parent',
'parseFloat',
'parseInt',
'print',
'prompt',
'releaseEvents',
'removeEventListener',
'removeEventStream',
'screen',
'screenLeft',
'screenTop',
'screenX',
'screenY',
'self',
'setDocument',
'setInterval',
'setTimeout',
'status',
'stop',
'sun',
'top',
'undefined',
'unescape',
'window',
/* added in core 2.2 */
'ByteArray',
'CanvasRenderingContext3D',
'ClientRect',
'ClientRectList',
'SVGPath',
]"""
def tests():
for t in raw_tests():
test = {'name': t[0], 'test': TEMPLATES[t[1]] % (t[2], t[3], len(t) > 4 and t[4] or 'null' ), 'mime': MIME[t[1]] }
yield test
def print_result(result):
ret = []
if result["interface"]:
try:
ret.append("dom_interfaces." + result["interface"] + " = function()\n{\n")
result['properties'].sort(key = lambda s: s[0])
for name, value in result['properties']:
ret.append( " this." + name + " = \"" + value +"\";\n" )
ret.append("}\n")
if "inherits-from" in result:
ret.append("dom_interfaces." + result["interface"] + ".prototype = " + \
"js_object_filters." + result["inherits-from"] + ";\n")
ret.append("js_object_filters." + result["interface"] + " = " + \
"new dom_interfaces." + result["interface"] + "();\n\n")
except Exception, msg:
print msg
else:
print 'result["interface"] is not defined'
return "".join(ret)
interfaces = {}
depths = {}
def get_inheritance_depth(interface):
count = 0
i = interface
while i in interfaces and "inherits-from" in interfaces[i]:
i = interfaces[i]["inherits-from"]
count += 1
return count
def set_keys(interface):
ret = set()
default_values = ['null', '-1']
if "sub-classes" in interface:
for sub_class_name in interface["sub-classes"]:
sub_class = interfaces[sub_class_name]
if not len(ret):
ret = set(sub_class["props-dict"].keys())
else:
ret = ret & set(sub_class["props-dict"].keys())
interface["properties"] = []
interface["props-dict"] = {}
for prop in ret:
value = "not-set"
for sub_class_name in interface["sub-classes"]:
if value == "not-set":
value = interfaces[sub_class_name]["props-dict"][prop]
elif not value == interfaces[sub_class_name]["props-dict"][prop]:
value = value in default_values and value \
or interfaces[sub_class_name]["props-dict"][prop] in default_values and interfaces[sub_class_name]["props-dict"][prop] \
or ""
break
interface["properties"].append((prop, value))
interface["props-dict"][prop] = value
def evaluate(results):
UA = results.pop('UA')
results_evaled = {}
for r in results:
try:
result = eval(results[r])
results_evaled[r] = result
# interface, properties, inherits-from
if result['interface'] in interfaces:
print "interface already set: ", result['interface']
else:
interfaces[result['interface']] = result
if "inherits-from" in result and not result["inherits-from"] in interfaces:
super = interfaces[result["inherits-from"]] = {}
super["interface"] = result["inherits-from"]
super["properties"] = []
if super["interface"] in inheritances:
super["inherits-from"] = inheritances[super["interface"]]
result["props-dict"] = dict(result["properties"])
except Exception, msg:
print "eval failed", msg, r, results[r]
for i in interfaces:
depth = interfaces[i]["inheritance-depth"] = get_inheritance_depth(i)
if "inherits-from" in interfaces[i]:
super = interfaces[interfaces[i]["inherits-from"]]
if not "sub-classes" in super:
super["sub-classes"] = []
super["sub-classes"].append(i)
if not depth in depths:
depths[depth] = []
depths[depth].append(i)
temp = [{'k': key, 'v': depths[key]} for key in depths]
temp.sort( key = lambda d: d['k'] )
sorted = [d['v'] for d in temp[::-1]]
for supers in sorted[1:]:
for super in supers:
if "sub-classes" in interfaces[super]:
set_keys(interfaces[super])
else:
print super, "has no sub classes"
interfaces_sorted = [ interfaces[i] for i in interfaces]
interfaces_sorted.sort( key = lambda d: d["inheritance-depth"] )
for interface in interfaces_sorted:
cur = interface
ret = set(cur["properties"])
while "inherits-from" in cur:
cur = interfaces[cur["inherits-from"]]
ret = ret - set(cur["properties"])
interface["properties"] = [prop for prop in ret]
if '-i' in sys.argv:
f = open('interfaces.txt', 'wb')
f.write("/*\nfilters extracted from: " + UA.replace("\r", "") + "\n*/\n\n")
for interface in interfaces_sorted:
f.write(interface["interface"] + '\n')
f.close()
else:
f = open(os.path.join('js_object_filters.js'), 'wb')
f.write("/*\nfilters extracted from: " + UA.replace("\r", "") + "\n*/\n\n")
f.write("window.js_object_filters || ( window.js_object_filters = {} )\n")
f.write("window.dom_interfaces || ( window.dom_interfaces = {} )\n\n")
for interface in interfaces_sorted:
f.write(print_result(interface))
f.close()
test_server.run_tests(evaluate, tests())
|
apache-2.0
|
[
646,
511,
63,
1000,
12,
984,
12,
747,
199,
199,
624,
199,
1579,
370,
8044,
436,
376,
279,
794,
18910,
2251,
199,
17116,
282,
1654,
334,
511,
63,
1000,
14,
647,
776,
436,
14404,
1373,
511,
2410,
314,
1163,
199,
390,
14511,
314,
2058,
370,
298,
3596,
63,
785,
63,
4273,
14,
3596,
2,
199,
1045,
446,
73,
3305,
652,
14511,
282,
769,
543,
1006,
8386,
370,
298,
7436,
14,
2424,
2,
199,
624,
199,
199,
3,
367,
9006,
8386,
199,
13136,
83,
275,
971,
199,
91,
272,
298,
31428,
968,
582,
298,
2162,
401,
272,
298,
5564,
582,
298,
1716,
401,
272,
298,
14852,
1451,
582,
298,
1716,
2,
199,
93,
199,
199,
3,
769,
402,
2295,
543,
26,
511,
536,
12,
6660,
730,
12,
511,
909,
12,
1613,
1021,
12,
769,
402,
4722,
4382,
334,
2716,
776,
221,
199,
318,
3066,
63,
2219,
837,
272,
372,
334,
272,
359,
267,
788,
3806,
297,
283,
4943,
297,
283,
3749,
297,
4873,
20896,
1649,
55,
63,
18858,
29807,
467,
267,
788,
2108,
297,
283,
4317,
297,
298,
3554,
14,
20296,
360,
396,
18106,
298,
1716,
2255,
267,
788,
1652,
13,
3554,
297,
283,
4943,
297,
298,
3554,
14,
12236,
14,
981,
5564,
8594,
283,
396,
297,
2973,
4186,
298,
5564,
2255,
267,
788,
1360,
13,
3554,
297,
283,
4943,
297,
298,
3554,
14,
12236,
14,
981,
4943,
5564,
8355,
401,
298,
5564,
2255,
267,
788,
981,
1646,
297,
283,
4943,
297,
298,
3554,
14,
981,
1646,
360,
1421,
18106,
298,
1716,
2255,
267,
788,
505,
297,
283,
4943,
297,
298,
3554,
14,
981,
32540,
8355,
401,
298,
14852,
1451,
2255,
267,
788,
15892,
297,
283,
4943,
297,
298,
3554,
14,
981,
35,
28231,
15636,
8355,
401,
298,
1872,
2255,
267,
788,
3349,
297,
283,
4943,
297,
298,
3554,
14,
981,
7488,
8355,
401,
298,
14852,
1451,
2255,
267,
788,
3554,
13,
7677,
297,
283,
4943,
297,
298,
3554,
14,
981,
5564,
11080,
24017,
298,
1716,
2255,
267,
788,
932,
13,
513,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
1959,
15045,
360,
13418,
401,
298,
2255,
267,
788,
4579,
13,
932,
13,
1130,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
1959,
2987,
401,
298,
2255,
267,
788,
1430,
297,
283,
4943,
297,
298,
3554,
14,
981,
2390,
360,
11770,
18106,
298,
2255,
267,
788,
1360,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1360,
18106,
298,
31428,
968,
2255,
267,
788,
2993,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2993,
18106,
298,
31428,
968,
2255,
267,
788,
1073,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1073,
18106,
298,
31428,
968,
2255,
267,
788,
1213,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1213,
18106,
298,
31428,
968,
2255,
267,
788,
2024,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2024,
18106,
298,
31428,
968,
2255,
267,
788,
1095,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1095,
18106,
298,
31428,
968,
2255,
267,
788,
2487,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2487,
18106,
298,
31428,
968,
2255,
267,
788,
2030,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2030,
18106,
298,
31428,
968,
2255,
267,
788,
5187,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1421,
18106,
298,
31428,
968,
2255,
267,
788,
1210,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1210,
18106,
298,
31428,
968,
2255,
267,
788,
374,
1080,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
374,
1080,
18106,
298,
31428,
968,
2255,
267,
788,
964,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
964,
18106,
298,
31428,
968,
2255,
267,
788,
2416,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2416,
18106,
298,
31428,
968,
2255,
267,
788,
2992,
923,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2992,
923,
18106,
298,
31428,
968,
2255,
267,
788,
1422,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1422,
18106,
298,
31428,
968,
2255,
267,
788,
20895,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
20895,
18106,
298,
31428,
968,
2255,
267,
788,
3887,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3887,
18106,
298,
31428,
968,
2255,
267,
788,
1302,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1302,
18106,
298,
31428,
968,
2255,
267,
788,
698,
409,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
698,
409,
18106,
298,
31428,
968,
2255,
267,
788,
10231,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
10231,
18106,
298,
31428,
968,
2255,
267,
788,
348,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
348,
18106,
298,
31428,
968,
2255,
267,
788,
393,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
393,
18106,
298,
31428,
968,
2255,
267,
788,
5030,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
5030,
18106,
298,
31428,
968,
2255,
267,
788,
694,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
694,
18106,
298,
31428,
968,
2255,
267,
788,
4470,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
4470,
18106,
298,
31428,
968,
2255,
267,
788,
317,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
317,
18106,
298,
31428,
968,
2255,
267,
788,
3015,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
18106,
298,
31428,
968,
2255,
267,
788,
80,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
80,
18106,
298,
31428,
968,
2255,
267,
788,
72,
17,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
72,
17,
18106,
298,
31428,
968,
2255,
267,
788,
81,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
81,
18106,
298,
31428,
968,
2255,
267,
788,
28623,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
28623,
18106,
298,
31428,
968,
2255,
267,
788,
657,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
657,
18106,
298,
31428,
968,
2255,
267,
788,
3289,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3289,
18106,
298,
31428,
968,
2255,
267,
788,
1095,
4246,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1095,
4246,
18106,
298,
31428,
968,
2255,
267,
788,
4246,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
4246,
18106,
298
] |
[
511,
63,
1000,
12,
984,
12,
747,
199,
199,
624,
199,
1579,
370,
8044,
436,
376,
279,
794,
18910,
2251,
199,
17116,
282,
1654,
334,
511,
63,
1000,
14,
647,
776,
436,
14404,
1373,
511,
2410,
314,
1163,
199,
390,
14511,
314,
2058,
370,
298,
3596,
63,
785,
63,
4273,
14,
3596,
2,
199,
1045,
446,
73,
3305,
652,
14511,
282,
769,
543,
1006,
8386,
370,
298,
7436,
14,
2424,
2,
199,
624,
199,
199,
3,
367,
9006,
8386,
199,
13136,
83,
275,
971,
199,
91,
272,
298,
31428,
968,
582,
298,
2162,
401,
272,
298,
5564,
582,
298,
1716,
401,
272,
298,
14852,
1451,
582,
298,
1716,
2,
199,
93,
199,
199,
3,
769,
402,
2295,
543,
26,
511,
536,
12,
6660,
730,
12,
511,
909,
12,
1613,
1021,
12,
769,
402,
4722,
4382,
334,
2716,
776,
221,
199,
318,
3066,
63,
2219,
837,
272,
372,
334,
272,
359,
267,
788,
3806,
297,
283,
4943,
297,
283,
3749,
297,
4873,
20896,
1649,
55,
63,
18858,
29807,
467,
267,
788,
2108,
297,
283,
4317,
297,
298,
3554,
14,
20296,
360,
396,
18106,
298,
1716,
2255,
267,
788,
1652,
13,
3554,
297,
283,
4943,
297,
298,
3554,
14,
12236,
14,
981,
5564,
8594,
283,
396,
297,
2973,
4186,
298,
5564,
2255,
267,
788,
1360,
13,
3554,
297,
283,
4943,
297,
298,
3554,
14,
12236,
14,
981,
4943,
5564,
8355,
401,
298,
5564,
2255,
267,
788,
981,
1646,
297,
283,
4943,
297,
298,
3554,
14,
981,
1646,
360,
1421,
18106,
298,
1716,
2255,
267,
788,
505,
297,
283,
4943,
297,
298,
3554,
14,
981,
32540,
8355,
401,
298,
14852,
1451,
2255,
267,
788,
15892,
297,
283,
4943,
297,
298,
3554,
14,
981,
35,
28231,
15636,
8355,
401,
298,
1872,
2255,
267,
788,
3349,
297,
283,
4943,
297,
298,
3554,
14,
981,
7488,
8355,
401,
298,
14852,
1451,
2255,
267,
788,
3554,
13,
7677,
297,
283,
4943,
297,
298,
3554,
14,
981,
5564,
11080,
24017,
298,
1716,
2255,
267,
788,
932,
13,
513,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
1959,
15045,
360,
13418,
401,
298,
2255,
267,
788,
4579,
13,
932,
13,
1130,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
1959,
2987,
401,
298,
2255,
267,
788,
1430,
297,
283,
4943,
297,
298,
3554,
14,
981,
2390,
360,
11770,
18106,
298,
2255,
267,
788,
1360,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1360,
18106,
298,
31428,
968,
2255,
267,
788,
2993,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2993,
18106,
298,
31428,
968,
2255,
267,
788,
1073,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1073,
18106,
298,
31428,
968,
2255,
267,
788,
1213,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1213,
18106,
298,
31428,
968,
2255,
267,
788,
2024,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2024,
18106,
298,
31428,
968,
2255,
267,
788,
1095,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1095,
18106,
298,
31428,
968,
2255,
267,
788,
2487,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2487,
18106,
298,
31428,
968,
2255,
267,
788,
2030,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2030,
18106,
298,
31428,
968,
2255,
267,
788,
5187,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1421,
18106,
298,
31428,
968,
2255,
267,
788,
1210,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1210,
18106,
298,
31428,
968,
2255,
267,
788,
374,
1080,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
374,
1080,
18106,
298,
31428,
968,
2255,
267,
788,
964,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
964,
18106,
298,
31428,
968,
2255,
267,
788,
2416,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2416,
18106,
298,
31428,
968,
2255,
267,
788,
2992,
923,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
2992,
923,
18106,
298,
31428,
968,
2255,
267,
788,
1422,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1422,
18106,
298,
31428,
968,
2255,
267,
788,
20895,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
20895,
18106,
298,
31428,
968,
2255,
267,
788,
3887,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3887,
18106,
298,
31428,
968,
2255,
267,
788,
1302,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1302,
18106,
298,
31428,
968,
2255,
267,
788,
698,
409,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
698,
409,
18106,
298,
31428,
968,
2255,
267,
788,
10231,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
10231,
18106,
298,
31428,
968,
2255,
267,
788,
348,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
348,
18106,
298,
31428,
968,
2255,
267,
788,
393,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
393,
18106,
298,
31428,
968,
2255,
267,
788,
5030,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
5030,
18106,
298,
31428,
968,
2255,
267,
788,
694,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
694,
18106,
298,
31428,
968,
2255,
267,
788,
4470,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
4470,
18106,
298,
31428,
968,
2255,
267,
788,
317,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
317,
18106,
298,
31428,
968,
2255,
267,
788,
3015,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3015,
18106,
298,
31428,
968,
2255,
267,
788,
80,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
80,
18106,
298,
31428,
968,
2255,
267,
788,
72,
17,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
72,
17,
18106,
298,
31428,
968,
2255,
267,
788,
81,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
81,
18106,
298,
31428,
968,
2255,
267,
788,
28623,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
28623,
18106,
298,
31428,
968,
2255,
267,
788,
657,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
657,
18106,
298,
31428,
968,
2255,
267,
788,
3289,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
3289,
18106,
298,
31428,
968,
2255,
267,
788,
1095,
4246,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
1095,
4246,
18106,
298,
31428,
968,
2255,
267,
788,
4246,
297,
283,
4943,
297,
298,
3554,
14,
20296,
360,
4246,
18106,
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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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
] |
stackforge/refstack
|
refstack/db/utils.py
|
2
|
1871
|
# Copyright (c) 2015 Mirantis, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Utilities for database."""
from oslo_config import cfg
from oslo_log import log
CONF = cfg.CONF
LOG = log.getLogger(__name__)
class PluggableBackend(object):
"""A pluggable backend loaded lazily based on some value."""
def __init__(self, pivot, **backends):
"""Init."""
self.__backends = backends
self.__pivot = pivot
self.__backend = None
def __get_backend(self):
"""Get backend."""
if not self.__backend:
backend_name = CONF[self.__pivot]
if backend_name not in self.__backends: # pragma: no cover
raise Exception('Invalid backend: %s' % backend_name)
backend = self.__backends[backend_name]
if isinstance(backend, tuple): # pragma: no cover
name = backend[0]
fromlist = backend[1]
else:
name = backend
fromlist = backend
self.__backend = __import__(name, None, None, fromlist)
LOG.debug('backend %s', self.__backend)
return self.__backend
def __getattr__(self, key):
"""Proxy interface to backend."""
backend = self.__get_backend()
return getattr(backend, key)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6900,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
22905,
367,
3050,
1041,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
199,
199,
3103,
275,
4810,
14,
3103,
199,
4947,
275,
943,
14,
5572,
3460,
354,
3368,
421,
199,
533,
7497,
1518,
16725,
8447,
8,
785,
304,
272,
408,
33,
14202,
16725,
4865,
6511,
29667,
3444,
4079,
641,
2005,
574,
1041,
339,
347,
636,
826,
721,
277,
12,
22292,
12,
1011,
7765,
304,
267,
408,
9346,
1041,
267,
291,
855,
7765,
275,
14745,
267,
291,
855,
21558,
275,
22292,
267,
291,
855,
4620,
275,
488,
339,
347,
636,
362,
63,
4620,
8,
277,
304,
267,
408,
1002,
4865,
1041,
267,
340,
440,
291,
855,
4620,
26,
288,
4865,
63,
354,
275,
6392,
59,
277,
855,
21558,
61,
288,
340,
4865,
63,
354,
440,
315,
291,
855,
7765,
26,
221,
327,
11942,
26,
949,
8486,
355,
746,
2186,
360,
3364,
4865,
26,
450,
83,
7,
450,
4865,
63,
354,
9,
953,
4865,
275,
291,
855,
7765,
59,
4620,
63,
354,
61,
288,
340,
1228,
8,
4620,
12,
2008,
304,
221,
327,
11942,
26,
949,
8486,
355,
536,
275,
4865,
59,
16,
61,
355,
25321,
275,
4865,
59,
17,
61,
288,
587,
26,
355,
536,
275,
4865,
355,
25321,
275,
4865,
953,
291,
855,
4620,
275,
636,
646,
721,
354,
12,
488,
12,
488,
12,
25321,
9,
288,
5051,
14,
1757,
360,
4620,
450,
83,
297,
291,
855,
4620,
9,
267,
372,
291,
855,
4620,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
408,
4936,
3217,
370,
4865,
1041,
267,
4865,
275,
291,
855,
362,
63,
4620,
342,
267,
372,
2519,
8,
4620,
12,
790,
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
] |
[
1898,
334,
67,
9,
6900,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
22905,
367,
3050,
1041,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
199,
199,
3103,
275,
4810,
14,
3103,
199,
4947,
275,
943,
14,
5572,
3460,
354,
3368,
421,
199,
533,
7497,
1518,
16725,
8447,
8,
785,
304,
272,
408,
33,
14202,
16725,
4865,
6511,
29667,
3444,
4079,
641,
2005,
574,
1041,
339,
347,
636,
826,
721,
277,
12,
22292,
12,
1011,
7765,
304,
267,
408,
9346,
1041,
267,
291,
855,
7765,
275,
14745,
267,
291,
855,
21558,
275,
22292,
267,
291,
855,
4620,
275,
488,
339,
347,
636,
362,
63,
4620,
8,
277,
304,
267,
408,
1002,
4865,
1041,
267,
340,
440,
291,
855,
4620,
26,
288,
4865,
63,
354,
275,
6392,
59,
277,
855,
21558,
61,
288,
340,
4865,
63,
354,
440,
315,
291,
855,
7765,
26,
221,
327,
11942,
26,
949,
8486,
355,
746,
2186,
360,
3364,
4865,
26,
450,
83,
7,
450,
4865,
63,
354,
9,
953,
4865,
275,
291,
855,
7765,
59,
4620,
63,
354,
61,
288,
340,
1228,
8,
4620,
12,
2008,
304,
221,
327,
11942,
26,
949,
8486,
355,
536,
275,
4865,
59,
16,
61,
355,
25321,
275,
4865,
59,
17,
61,
288,
587,
26,
355,
536,
275,
4865,
355,
25321,
275,
4865,
953,
291,
855,
4620,
275,
636,
646,
721,
354,
12,
488,
12,
488,
12,
25321,
9,
288,
5051,
14,
1757,
360,
4620,
450,
83,
297,
291,
855,
4620,
9,
267,
372,
291,
855,
4620,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
408,
4936,
3217,
370,
4865,
1041,
267,
4865,
275,
291,
855,
362,
63,
4620,
342,
267,
372,
2519,
8,
4620,
12,
790,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
loseblue/vim-ycm-windows-64
|
third_party/requests/requests/packages/urllib3/contrib/pyopenssl.py
|
216
|
13871
|
'''SSL with SNI_-support for Python 2.
This needs the following packages installed:
* pyOpenSSL (tested with 0.13)
* ndg-httpsclient (tested with 0.3.2)
* pyasn1 (tested with 0.1.6)
To activate it call :func:`~urllib3.contrib.pyopenssl.inject_into_urllib3`.
This can be done in a ``sitecustomize`` module, or at any other time before
your application begins using ``urllib3``, like this::
try:
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()
except ImportError:
pass
Now you can use :mod:`urllib3` as you normally would, and it will support SNI
when the required modules are installed.
Activating this module also has the positive side effect of disabling SSL/TLS
encryption in Python 2 (see `CRIME attack`_).
If you want to configure the default list of supported cipher suites, you can
set the ``urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST`` variable.
Module Variables
----------------
:var DEFAULT_SSL_CIPHER_LIST: The list of supported SSL/TLS cipher suites.
Default: ``EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA256
EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EDH+aRSA EECDH RC4 !aNULL !eNULL !LOW !3DES
!MD5 !EXP !PSK !SRP !DSS'``
.. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication
.. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit)
'''
from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
from ndg.httpsclient.subj_alt_name import SubjectAltName as BaseSubjectAltName
import OpenSSL.SSL
from pyasn1.codec.der import decoder as der_decoder
from pyasn1.type import univ, constraint
from socket import _fileobject
import ssl
import select
from cStringIO import StringIO
from .. import connection
from .. import util
__all__ = ['inject_into_urllib3', 'extract_from_urllib3']
# SNI only *really* works if we can read the subjectAltName of certificates.
HAS_SNI = SUBJ_ALT_NAME_SUPPORT
# Map from urllib3 to PyOpenSSL compatible parameter-values.
_openssl_versions = {
ssl.PROTOCOL_SSLv23: OpenSSL.SSL.SSLv23_METHOD,
ssl.PROTOCOL_SSLv3: OpenSSL.SSL.SSLv3_METHOD,
ssl.PROTOCOL_TLSv1: OpenSSL.SSL.TLSv1_METHOD,
}
_openssl_verify = {
ssl.CERT_NONE: OpenSSL.SSL.VERIFY_NONE,
ssl.CERT_OPTIONAL: OpenSSL.SSL.VERIFY_PEER,
ssl.CERT_REQUIRED: OpenSSL.SSL.VERIFY_PEER
+ OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
}
# Default SSL/TLS cipher list.
# Recommendation by https://community.qualys.com/blogs/securitylabs/2013/08/05/
# configuring-apache-nginx-and-openssl-for-forward-secrecy
DEFAULT_SSL_CIPHER_LIST = 'EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM ' + \
'EECDH+ECDSA+SHA256 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EDH+aRSA ' + \
'EECDH RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS'
orig_util_HAS_SNI = util.HAS_SNI
orig_connection_ssl_wrap_socket = connection.ssl_wrap_socket
def inject_into_urllib3():
'Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.'
connection.ssl_wrap_socket = ssl_wrap_socket
util.HAS_SNI = HAS_SNI
def extract_from_urllib3():
'Undo monkey-patching by :func:`inject_into_urllib3`.'
connection.ssl_wrap_socket = orig_connection_ssl_wrap_socket
util.HAS_SNI = orig_util_HAS_SNI
### Note: This is a slightly bug-fixed version of same from ndg-httpsclient.
class SubjectAltName(BaseSubjectAltName):
'''ASN.1 implementation for subjectAltNames support'''
# There is no limit to how many SAN certificates a certificate may have,
# however this needs to have some limit so we'll set an arbitrarily high
# limit.
sizeSpec = univ.SequenceOf.sizeSpec + \
constraint.ValueSizeConstraint(1, 1024)
### Note: This is a slightly bug-fixed version of same from ndg-httpsclient.
def get_subj_alt_name(peer_cert):
# Search through extensions
dns_name = []
if not SUBJ_ALT_NAME_SUPPORT:
return dns_name
general_names = SubjectAltName()
for i in range(peer_cert.get_extension_count()):
ext = peer_cert.get_extension(i)
ext_name = ext.get_short_name()
if ext_name != 'subjectAltName':
continue
# PyOpenSSL returns extension data in ASN.1 encoded form
ext_dat = ext.get_data()
decoded_dat = der_decoder.decode(ext_dat,
asn1Spec=general_names)
for name in decoded_dat:
if not isinstance(name, SubjectAltName):
continue
for entry in range(len(name)):
component = name.getComponentByPosition(entry)
if component.getName() != 'dNSName':
continue
dns_name.append(str(component.getComponent()))
return dns_name
class fileobject(_fileobject):
def read(self, size=-1):
# Use max, disallow tiny reads in a loop as they are very inefficient.
# We never leave read() with any leftover data from a new recv() call
# in our internal buffer.
rbufsize = max(self._rbufsize, self.default_bufsize)
# Our use of StringIO rather than lists of string objects returned by
# recv() minimizes memory usage and fragmentation that occurs when
# rbufsize is large compared to the typical return value of recv().
buf = self._rbuf
buf.seek(0, 2) # seek end
if size < 0:
# Read until EOF
self._rbuf = StringIO() # reset _rbuf. we consume it via buf.
while True:
try:
data = self._sock.recv(rbufsize)
except OpenSSL.SSL.WantReadError:
continue
if not data:
break
buf.write(data)
return buf.getvalue()
else:
# Read until size bytes or EOF seen, whichever comes first
buf_len = buf.tell()
if buf_len >= size:
# Already have size bytes in our buffer? Extract and return.
buf.seek(0)
rv = buf.read(size)
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return rv
self._rbuf = StringIO() # reset _rbuf. we consume it via buf.
while True:
left = size - buf_len
# recv() will malloc the amount of memory given as its
# parameter even though it often returns much less data
# than that. The returned data string is short lived
# as we copy it into a StringIO and free it. This avoids
# fragmentation issues on many platforms.
try:
data = self._sock.recv(left)
except OpenSSL.SSL.WantReadError:
continue
if not data:
break
n = len(data)
if n == size and not buf_len:
# Shortcut. Avoid buffer data copies when:
# - We have no data in our buffer.
# AND
# - Our call to recv returned exactly the
# number of bytes we were asked to read.
return data
if n == left:
buf.write(data)
del data # explicit free
break
assert n <= left, "recv(%d) returned %d bytes" % (left, n)
buf.write(data)
buf_len += n
del data # explicit free
#assert buf_len == buf.tell()
return buf.getvalue()
def readline(self, size=-1):
buf = self._rbuf
buf.seek(0, 2) # seek end
if buf.tell() > 0:
# check if we already have it in our buffer
buf.seek(0)
bline = buf.readline(size)
if bline.endswith('\n') or len(bline) == size:
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return bline
del bline
if size < 0:
# Read until \n or EOF, whichever comes first
if self._rbufsize <= 1:
# Speed up unbuffered case
buf.seek(0)
buffers = [buf.read()]
self._rbuf = StringIO() # reset _rbuf. we consume it via buf.
data = None
recv = self._sock.recv
while True:
try:
while data != "\n":
data = recv(1)
if not data:
break
buffers.append(data)
except OpenSSL.SSL.WantReadError:
continue
break
return "".join(buffers)
buf.seek(0, 2) # seek end
self._rbuf = StringIO() # reset _rbuf. we consume it via buf.
while True:
try:
data = self._sock.recv(self._rbufsize)
except OpenSSL.SSL.WantReadError:
continue
if not data:
break
nl = data.find('\n')
if nl >= 0:
nl += 1
buf.write(data[:nl])
self._rbuf.write(data[nl:])
del data
break
buf.write(data)
return buf.getvalue()
else:
# Read until size bytes or \n or EOF seen, whichever comes first
buf.seek(0, 2) # seek end
buf_len = buf.tell()
if buf_len >= size:
buf.seek(0)
rv = buf.read(size)
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return rv
self._rbuf = StringIO() # reset _rbuf. we consume it via buf.
while True:
try:
data = self._sock.recv(self._rbufsize)
except OpenSSL.SSL.WantReadError:
continue
if not data:
break
left = size - buf_len
# did we just receive a newline?
nl = data.find('\n', 0, left)
if nl >= 0:
nl += 1
# save the excess data to _rbuf
self._rbuf.write(data[nl:])
if buf_len:
buf.write(data[:nl])
break
else:
# Shortcut. Avoid data copy through buf when returning
# a substring of our first recv().
return data[:nl]
n = len(data)
if n == size and not buf_len:
# Shortcut. Avoid data copy through buf when
# returning exactly all of our first recv().
return data
if n >= left:
buf.write(data[:left])
self._rbuf.write(data[left:])
break
buf.write(data)
buf_len += n
#assert buf_len == buf.tell()
return buf.getvalue()
class WrappedSocket(object):
'''API-compatibility wrapper for Python OpenSSL's Connection-class.'''
def __init__(self, connection, socket):
self.connection = connection
self.socket = socket
def fileno(self):
return self.socket.fileno()
def makefile(self, mode, bufsize=-1):
return fileobject(self.connection, mode, bufsize)
def settimeout(self, timeout):
return self.socket.settimeout(timeout)
def sendall(self, data):
return self.connection.sendall(data)
def close(self):
return self.connection.shutdown()
def getpeercert(self, binary_form=False):
x509 = self.connection.get_peer_certificate()
if not x509:
return x509
if binary_form:
return OpenSSL.crypto.dump_certificate(
OpenSSL.crypto.FILETYPE_ASN1,
x509)
return {
'subject': (
(('commonName', x509.get_subject().CN),),
),
'subjectAltName': [
('DNS', value)
for value in get_subj_alt_name(x509)
]
}
def _verify_callback(cnx, x509, err_no, err_depth, return_code):
return err_no == 0
def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
ca_certs=None, server_hostname=None,
ssl_version=None):
ctx = OpenSSL.SSL.Context(_openssl_versions[ssl_version])
if certfile:
ctx.use_certificate_file(certfile)
if keyfile:
ctx.use_privatekey_file(keyfile)
if cert_reqs != ssl.CERT_NONE:
ctx.set_verify(_openssl_verify[cert_reqs], _verify_callback)
if ca_certs:
try:
ctx.load_verify_locations(ca_certs, None)
except OpenSSL.SSL.Error as e:
raise ssl.SSLError('bad ca_certs: %r' % ca_certs, e)
# Disable TLS compression to migitate CRIME attack (issue #309)
OP_NO_COMPRESSION = 0x20000
ctx.set_options(OP_NO_COMPRESSION)
# Set list of supported ciphersuites.
ctx.set_cipher_list(DEFAULT_SSL_CIPHER_LIST)
cnx = OpenSSL.SSL.Connection(ctx, sock)
cnx.set_tlsext_host_name(server_hostname)
cnx.set_connect_state()
while True:
try:
cnx.do_handshake()
except OpenSSL.SSL.WantReadError:
select.select([sock], [], [])
continue
except OpenSSL.SSL.Error as e:
raise ssl.SSLError('bad handshake', e)
break
return WrappedSocket(cnx, sock)
|
gpl-3.0
|
[
2344,
5413,
543,
428,
16730,
32069,
4058,
367,
2018,
499,
14,
199,
199,
2765,
4839,
314,
2569,
6117,
4903,
26,
199,
199,
10,
1134,
22791,
334,
10453,
543,
378,
14,
969,
9,
199,
10,
5222,
71,
13,
1014,
551,
864,
334,
10453,
543,
378,
14,
19,
14,
18,
9,
199,
10,
1134,
6228,
17,
334,
10453,
543,
378,
14,
17,
14,
22,
9,
199,
199,
1378,
15422,
652,
1240,
520,
1532,
6054,
4078,
19,
14,
2828,
14,
647,
14837,
14,
14815,
63,
9924,
63,
4078,
19,
2313,
199,
2765,
883,
506,
4224,
315,
282,
1124,
2124,
26660,
1040,
859,
12,
503,
737,
1263,
1163,
900,
2544,
199,
12695,
4223,
22241,
1808,
1124,
4078,
19,
4542,
2839,
642,
447,
339,
862,
26,
267,
492,
4011,
19,
14,
2828,
14,
647,
14837,
267,
4011,
19,
14,
2828,
14,
647,
14837,
14,
14815,
63,
9924,
63,
4078,
19,
342,
272,
871,
3545,
26,
267,
986,
199,
199,
14351,
1265,
883,
675,
520,
1494,
1705,
4078,
19,
64,
465,
1265,
12252,
3955,
12,
436,
652,
911,
2291,
428,
16730,
199,
6526,
314,
1415,
4621,
787,
4903,
14,
199,
199,
13767,
86,
1958,
642,
859,
2597,
965,
314,
7317,
5366,
7763,
402,
30723,
7799,
15,
10224,
199,
15113,
315,
2018,
499,
334,
3239,
658,
2944,
3465,
23326,
18417,
680,
199,
199,
3917,
1265,
2934,
370,
7908,
314,
849,
769,
402,
3748,
10830,
24203,
12,
1265,
883,
199,
409,
314,
1124,
4078,
19,
14,
2828,
14,
647,
14837,
14,
3472,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
1040,
1750,
14,
199,
199,
2377,
17198,
199,
777,
199,
199,
26,
1391,
6186,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
26,
710,
769,
402,
3748,
7799,
15,
10224,
10830,
24203,
14,
272,
3758,
26,
1124,
37,
4220,
13860,
11,
4220,
23007,
11,
14494,
29009,
662,
4220,
13860,
11,
65,
12115,
11,
14494,
29009,
662,
4220,
13860,
11,
4220,
23007,
11,
8461,
3912,
272,
662,
4220,
13860,
11,
65,
12115,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8205,
20,
662,
13860,
11,
65,
12115,
662,
4220,
13860,
29256,
20,
8546,
65,
8084,
8546,
69,
8084,
8546,
5896,
8546,
19,
4448,
272,
8546,
5127,
21,
8546,
11992,
8546,
5067,
43,
8546,
32527,
8546,
36,
2300,
14700,
199,
199,
703,
485,
5167,
73,
26,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
3120,
63,
985,
63,
607,
21171,
199,
703,
485,
1408,
278,
23326,
26,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
2944,
3465,
2531,
4416,
63,
16971,
390,
9,
199,
199,
2344,
199,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
4266,
63,
7866,
63,
16257,
492,
7605,
42,
63,
19600,
63,
2339,
63,
10640,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
954,
74,
63,
4478,
63,
354,
492,
26793,
29171,
465,
3523,
13528,
29171,
199,
646,
14296,
14,
5413,
199,
504,
1134,
6228,
17,
14,
9276,
14,
424,
492,
10334,
465,
16921,
63,
8813,
199,
504,
1134,
6228,
17,
14,
466,
492,
17225,
12,
5828,
199,
504,
2838,
492,
485,
493,
785,
199,
646,
6149,
199,
646,
3504,
199,
504,
15073,
492,
5228,
199,
199,
504,
2508,
492,
1950,
199,
504,
2508,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
14815,
63,
9924,
63,
4078,
19,
297,
283,
5005,
63,
504,
63,
4078,
19,
418,
199,
199,
3,
428,
16730,
1454,
627,
29428,
10,
5419,
340,
781,
883,
1586,
314,
5420,
29171,
402,
14512,
14,
199,
13533,
63,
8199,
41,
275,
7605,
42,
63,
19600,
63,
2339,
63,
10640,
199,
199,
3,
9672,
687,
4011,
19,
370,
1611,
22791,
9025,
2725,
13,
1459,
14,
199,
63,
14837,
63,
6234,
275,
469,
272,
6149,
14,
9583,
63,
21082,
1789,
26,
14296,
14,
5413,
14,
21082,
1789,
63,
9977,
12,
272,
6149,
14,
9583,
63,
21082,
19,
26,
14296,
14,
5413,
14,
21082,
19,
63,
9977,
12,
272,
6149,
14,
9583,
63,
10224,
86,
17,
26,
14296,
14,
5413,
14,
10224,
86,
17,
63,
9977,
12,
199,
93,
199,
63,
14837,
63,
4712,
275,
469,
272,
6149,
14,
11163,
63,
9185,
26,
14296,
14,
5413,
14,
22443,
63,
9185,
12,
272,
6149,
14,
11163,
63,
21008,
26,
14296,
14,
5413,
14,
22443,
63,
31560,
12,
272,
6149,
14,
11163,
63,
12496,
26,
14296,
14,
5413,
14,
22443,
63,
31560,
2432,
435,
14296,
14,
5413,
14,
22443,
63,
8784,
63,
4656,
63,
2826,
63,
31560,
63,
11163,
12,
199,
93,
199,
199,
3,
3758,
7799,
15,
10224,
10830,
769,
14,
199,
3,
799,
22105,
701,
4178,
921,
9387,
14,
537,
588,
14,
957,
15,
66,
7270,
15,
4416,
76,
2101,
15,
6965,
15,
2036,
15,
1717,
15,
199,
3,
1101,
4039,
13,
3796,
13,
25826,
13,
460,
13,
14837,
13,
509,
13,
6688,
13,
261,
1353,
1480,
199,
3472,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
275,
283,
37,
4220,
13860,
11,
4220,
23007,
11,
14494,
29009,
662,
4220,
13860,
11,
65,
12115,
11,
14494,
29009,
283,
435,
971,
267,
283,
37,
4220,
13860,
11,
4220,
23007,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8205,
20,
662,
13860,
11,
65,
12115,
283,
435,
971,
267,
283,
37,
4220,
13860,
29256,
20,
8546,
65,
8084,
8546,
69,
8084,
8546,
5896,
8546,
19,
4448,
8546,
5127,
21,
8546,
11992,
8546,
5067,
43,
8546,
32527,
8546,
36,
2300,
7,
421,
199,
2981,
63,
1974,
63,
13533,
63,
8199,
41,
275,
4884,
14,
13533,
63,
8199,
41,
199,
2981,
63,
2105,
63,
4266,
63,
3823,
63,
3450,
275,
1950,
14,
4266,
63,
3823,
63,
3450,
421,
199,
318,
16182,
63,
9924,
63,
4078,
19,
837,
272,
283,
6671,
498,
13,
2068,
4011,
19,
543,
1611,
22791,
13,
894,
379,
7799,
13,
4058,
3530,
339,
1950,
14,
4266,
63,
3823,
63,
3450,
275,
6149,
63,
3823,
63,
3450,
272,
4884,
14,
13533,
63,
8199,
41,
275,
7509,
63,
8199,
41,
421,
199,
318,
5536,
63,
504,
63,
4078,
19,
837,
272,
283,
29832,
14198,
13,
2068,
316,
701,
520,
1532,
1705,
14815,
63,
9924,
63,
4078,
19,
2313,
7,
339,
1950,
14,
4266,
63,
3823,
63,
3450,
275,
2306,
63,
2105,
63,
4266,
63
] |
[
5413,
543,
428,
16730,
32069,
4058,
367,
2018,
499,
14,
199,
199,
2765,
4839,
314,
2569,
6117,
4903,
26,
199,
199,
10,
1134,
22791,
334,
10453,
543,
378,
14,
969,
9,
199,
10,
5222,
71,
13,
1014,
551,
864,
334,
10453,
543,
378,
14,
19,
14,
18,
9,
199,
10,
1134,
6228,
17,
334,
10453,
543,
378,
14,
17,
14,
22,
9,
199,
199,
1378,
15422,
652,
1240,
520,
1532,
6054,
4078,
19,
14,
2828,
14,
647,
14837,
14,
14815,
63,
9924,
63,
4078,
19,
2313,
199,
2765,
883,
506,
4224,
315,
282,
1124,
2124,
26660,
1040,
859,
12,
503,
737,
1263,
1163,
900,
2544,
199,
12695,
4223,
22241,
1808,
1124,
4078,
19,
4542,
2839,
642,
447,
339,
862,
26,
267,
492,
4011,
19,
14,
2828,
14,
647,
14837,
267,
4011,
19,
14,
2828,
14,
647,
14837,
14,
14815,
63,
9924,
63,
4078,
19,
342,
272,
871,
3545,
26,
267,
986,
199,
199,
14351,
1265,
883,
675,
520,
1494,
1705,
4078,
19,
64,
465,
1265,
12252,
3955,
12,
436,
652,
911,
2291,
428,
16730,
199,
6526,
314,
1415,
4621,
787,
4903,
14,
199,
199,
13767,
86,
1958,
642,
859,
2597,
965,
314,
7317,
5366,
7763,
402,
30723,
7799,
15,
10224,
199,
15113,
315,
2018,
499,
334,
3239,
658,
2944,
3465,
23326,
18417,
680,
199,
199,
3917,
1265,
2934,
370,
7908,
314,
849,
769,
402,
3748,
10830,
24203,
12,
1265,
883,
199,
409,
314,
1124,
4078,
19,
14,
2828,
14,
647,
14837,
14,
3472,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
1040,
1750,
14,
199,
199,
2377,
17198,
199,
777,
199,
199,
26,
1391,
6186,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
26,
710,
769,
402,
3748,
7799,
15,
10224,
10830,
24203,
14,
272,
3758,
26,
1124,
37,
4220,
13860,
11,
4220,
23007,
11,
14494,
29009,
662,
4220,
13860,
11,
65,
12115,
11,
14494,
29009,
662,
4220,
13860,
11,
4220,
23007,
11,
8461,
3912,
272,
662,
4220,
13860,
11,
65,
12115,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8205,
20,
662,
13860,
11,
65,
12115,
662,
4220,
13860,
29256,
20,
8546,
65,
8084,
8546,
69,
8084,
8546,
5896,
8546,
19,
4448,
272,
8546,
5127,
21,
8546,
11992,
8546,
5067,
43,
8546,
32527,
8546,
36,
2300,
14700,
199,
199,
703,
485,
5167,
73,
26,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
3120,
63,
985,
63,
607,
21171,
199,
703,
485,
1408,
278,
23326,
26,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
2944,
3465,
2531,
4416,
63,
16971,
390,
9,
199,
199,
2344,
199,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
4266,
63,
7866,
63,
16257,
492,
7605,
42,
63,
19600,
63,
2339,
63,
10640,
199,
504,
5222,
71,
14,
1014,
551,
864,
14,
954,
74,
63,
4478,
63,
354,
492,
26793,
29171,
465,
3523,
13528,
29171,
199,
646,
14296,
14,
5413,
199,
504,
1134,
6228,
17,
14,
9276,
14,
424,
492,
10334,
465,
16921,
63,
8813,
199,
504,
1134,
6228,
17,
14,
466,
492,
17225,
12,
5828,
199,
504,
2838,
492,
485,
493,
785,
199,
646,
6149,
199,
646,
3504,
199,
504,
15073,
492,
5228,
199,
199,
504,
2508,
492,
1950,
199,
504,
2508,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
14815,
63,
9924,
63,
4078,
19,
297,
283,
5005,
63,
504,
63,
4078,
19,
418,
199,
199,
3,
428,
16730,
1454,
627,
29428,
10,
5419,
340,
781,
883,
1586,
314,
5420,
29171,
402,
14512,
14,
199,
13533,
63,
8199,
41,
275,
7605,
42,
63,
19600,
63,
2339,
63,
10640,
199,
199,
3,
9672,
687,
4011,
19,
370,
1611,
22791,
9025,
2725,
13,
1459,
14,
199,
63,
14837,
63,
6234,
275,
469,
272,
6149,
14,
9583,
63,
21082,
1789,
26,
14296,
14,
5413,
14,
21082,
1789,
63,
9977,
12,
272,
6149,
14,
9583,
63,
21082,
19,
26,
14296,
14,
5413,
14,
21082,
19,
63,
9977,
12,
272,
6149,
14,
9583,
63,
10224,
86,
17,
26,
14296,
14,
5413,
14,
10224,
86,
17,
63,
9977,
12,
199,
93,
199,
63,
14837,
63,
4712,
275,
469,
272,
6149,
14,
11163,
63,
9185,
26,
14296,
14,
5413,
14,
22443,
63,
9185,
12,
272,
6149,
14,
11163,
63,
21008,
26,
14296,
14,
5413,
14,
22443,
63,
31560,
12,
272,
6149,
14,
11163,
63,
12496,
26,
14296,
14,
5413,
14,
22443,
63,
31560,
2432,
435,
14296,
14,
5413,
14,
22443,
63,
8784,
63,
4656,
63,
2826,
63,
31560,
63,
11163,
12,
199,
93,
199,
199,
3,
3758,
7799,
15,
10224,
10830,
769,
14,
199,
3,
799,
22105,
701,
4178,
921,
9387,
14,
537,
588,
14,
957,
15,
66,
7270,
15,
4416,
76,
2101,
15,
6965,
15,
2036,
15,
1717,
15,
199,
3,
1101,
4039,
13,
3796,
13,
25826,
13,
460,
13,
14837,
13,
509,
13,
6688,
13,
261,
1353,
1480,
199,
3472,
63,
5413,
63,
35,
1772,
3452,
63,
4924,
275,
283,
37,
4220,
13860,
11,
4220,
23007,
11,
14494,
29009,
662,
4220,
13860,
11,
65,
12115,
11,
14494,
29009,
283,
435,
971,
267,
283,
37,
4220,
13860,
11,
4220,
23007,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8461,
3912,
662,
4220,
13860,
11,
65,
12115,
11,
8205,
20,
662,
13860,
11,
65,
12115,
283,
435,
971,
267,
283,
37,
4220,
13860,
29256,
20,
8546,
65,
8084,
8546,
69,
8084,
8546,
5896,
8546,
19,
4448,
8546,
5127,
21,
8546,
11992,
8546,
5067,
43,
8546,
32527,
8546,
36,
2300,
7,
421,
199,
2981,
63,
1974,
63,
13533,
63,
8199,
41,
275,
4884,
14,
13533,
63,
8199,
41,
199,
2981,
63,
2105,
63,
4266,
63,
3823,
63,
3450,
275,
1950,
14,
4266,
63,
3823,
63,
3450,
421,
199,
318,
16182,
63,
9924,
63,
4078,
19,
837,
272,
283,
6671,
498,
13,
2068,
4011,
19,
543,
1611,
22791,
13,
894,
379,
7799,
13,
4058,
3530,
339,
1950,
14,
4266,
63,
3823,
63,
3450,
275,
6149,
63,
3823,
63,
3450,
272,
4884,
14,
13533,
63,
8199,
41,
275,
7509,
63,
8199,
41,
421,
199,
318,
5536,
63,
504,
63,
4078,
19,
837,
272,
283,
29832,
14198,
13,
2068,
316,
701,
520,
1532,
1705,
14815,
63,
9924,
63,
4078,
19,
2313,
7,
339,
1950,
14,
4266,
63,
3823,
63,
3450,
275,
2306,
63,
2105,
63,
4266,
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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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
] |
Intel-tensorflow/tensorflow
|
tensorflow/python/kernel_tests/random/random_poisson_test.py
|
9
|
6887
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for tensorflow.ops.random_ops.random_poisson."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.kernel_tests.random import util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.platform import test
from tensorflow.python.platform import tf_logging
# All supported dtypes for random_poisson().
_SUPPORTED_DTYPES = (dtypes.float16, dtypes.float32, dtypes.float64,
dtypes.int32, dtypes.int64)
class RandomPoissonTest(test.TestCase):
"""This is a large test due to the moments computation taking some time."""
def _Sampler(self, num, lam, dtype, use_gpu, seed=None):
def func():
with self.session(use_gpu=use_gpu, graph=ops.Graph()) as sess:
rng = random_ops.random_poisson(lam, [num], dtype=dtype, seed=seed)
ret = np.empty([10, num])
for i in xrange(10):
ret[i, :] = self.evaluate(rng)
return ret
return func
def testMoments(self):
try:
from scipy import stats # pylint: disable=g-import-not-at-top
except ImportError as e:
tf_logging.warn("Cannot test moments: %s", e)
return
# The moments test is a z-value test. This is the largest z-value
# we want to tolerate. Since the z-test approximates a unit normal
# distribution, it should almost definitely never exceed 6.
z_limit = 6.0
for dt in _SUPPORTED_DTYPES:
# Test when lam < 10 and when lam >= 10
for stride in 0, 4, 10:
for lam in (3., 20):
max_moment = 5
sampler = self._Sampler(10000, lam, dt, use_gpu=False, seed=12345)
z_scores = util.test_moment_matching(
sampler(),
max_moment,
stats.poisson(lam),
stride=stride,
)
self.assertAllLess(z_scores, z_limit)
# Checks that the CPU and GPU implementation returns the same results,
# given the same random seed
@test_util.run_deprecated_v1
def testCPUGPUMatch(self):
for dt in _SUPPORTED_DTYPES:
results = {}
for use_gpu in [False, True]:
sampler = self._Sampler(1000, 1.0, dt, use_gpu=use_gpu, seed=12345)
results[use_gpu] = sampler()
if dt == dtypes.float16:
self.assertAllClose(results[False], results[True], rtol=1e-3, atol=1e-3)
else:
self.assertAllClose(results[False], results[True], rtol=1e-6, atol=1e-6)
@test_util.run_deprecated_v1
def testSeed(self):
for dt in dtypes.float16, dtypes.float32, dtypes.float64:
sx = self._Sampler(1000, 1.0, dt, use_gpu=True, seed=345)
sy = self._Sampler(1000, 1.0, dt, use_gpu=True, seed=345)
self.assertAllEqual(sx(), sy())
@test_util.run_deprecated_v1
def testNoCSE(self):
"""CSE = constant subexpression eliminator.
SetIsStateful() should prevent two identical random ops from getting
merged.
"""
for dtype in dtypes.float16, dtypes.float32, dtypes.float64:
with self.cached_session():
rnd1 = random_ops.random_poisson(2.0, [24], dtype=dtype)
rnd2 = random_ops.random_poisson(2.0, [24], dtype=dtype)
diff = rnd2 - rnd1
# Since these are all positive integers, the norm will
# be at least 1 if they are different.
self.assertGreaterEqual(np.linalg.norm(diff.eval()), 1)
def testZeroShape(self):
with self.cached_session():
rnd = random_ops.random_poisson([], [], seed=12345)
self.assertEqual([0], rnd.get_shape().as_list())
self.assertAllClose(np.array([], dtype=np.float32), self.evaluate(rnd))
@test_util.run_deprecated_v1
def testShape(self):
# Fully known shape
rnd = random_ops.random_poisson(2.0, [150], seed=12345)
self.assertEqual([150], rnd.get_shape().as_list())
rnd = random_ops.random_poisson(
lam=array_ops.ones([1, 2, 3]),
shape=[150],
seed=12345)
self.assertEqual([150, 1, 2, 3], rnd.get_shape().as_list())
rnd = random_ops.random_poisson(
lam=array_ops.ones([1, 2, 3]),
shape=[20, 30],
seed=12345)
self.assertEqual([20, 30, 1, 2, 3], rnd.get_shape().as_list())
rnd = random_ops.random_poisson(
lam=array_ops.placeholder(dtypes.float32, shape=(2,)),
shape=[12],
seed=12345)
self.assertEqual([12, 2], rnd.get_shape().as_list())
# Partially known shape.
rnd = random_ops.random_poisson(
lam=array_ops.ones([7, 3]),
shape=array_ops.placeholder(dtypes.int32, shape=(1,)),
seed=12345)
self.assertEqual([None, 7, 3], rnd.get_shape().as_list())
rnd = random_ops.random_poisson(
lam=array_ops.ones([9, 6]),
shape=array_ops.placeholder(dtypes.int32, shape=(3,)),
seed=12345)
self.assertEqual([None, None, None, 9, 6], rnd.get_shape().as_list())
# Unknown shape.
rnd = random_ops.random_poisson(
lam=array_ops.placeholder(dtypes.float32),
shape=array_ops.placeholder(dtypes.int32),
seed=12345)
self.assertIs(None, rnd.get_shape().ndims)
rnd = random_ops.random_poisson(
lam=array_ops.placeholder(dtypes.float32),
shape=[50],
seed=12345)
self.assertIs(None, rnd.get_shape().ndims)
@test_util.run_deprecated_v1
def testDTypeCombinationsV2(self):
"""Tests random_poisson_v2() for all supported dtype combinations."""
with self.cached_session():
for lam_dt in _SUPPORTED_DTYPES:
for out_dt in _SUPPORTED_DTYPES:
random_ops.random_poisson(
constant_op.constant([1], dtype=lam_dt), [10],
dtype=out_dt).eval()
@test_util.run_deprecated_v1
def testInfRate(self):
sample = random_ops.random_poisson(shape=[2], lam=np.inf)
self.assertAllEqual([np.inf, np.inf], self.evaluate(sample))
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
1483,
14,
2355,
63,
1483,
14,
2355,
63,
29606,
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,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
4989,
63,
2219,
14,
2355,
492,
4884,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
199,
199,
3,
2900,
3748,
6674,
367,
2196,
63,
29606,
1252,
199,
63,
15925,
63,
36,
7893,
275,
334,
5717,
14,
1609,
975,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
12,
2151,
6674,
14,
442,
708,
12,
6674,
14,
442,
772,
9,
421,
199,
533,
9571,
1575,
18571,
774,
8,
396,
14,
1746,
304,
523,
408,
2765,
365,
282,
7031,
511,
7037,
370,
314,
29559,
14009,
16466,
2005,
900,
1041,
819,
347,
485,
27434,
8,
277,
12,
1967,
12,
25917,
12,
2152,
12,
675,
63,
6477,
12,
6347,
29,
403,
304,
339,
347,
2562,
837,
489,
543,
291,
14,
1730,
8,
1180,
63,
6477,
29,
1180,
63,
6477,
12,
3343,
29,
1483,
14,
4578,
1012,
465,
4043,
26,
267,
9038,
275,
2196,
63,
1483,
14,
2355,
63,
29606,
8,
17984,
12,
359,
1507,
467,
2152,
29,
2271,
12,
6347,
29,
5176,
9,
267,
2203,
275,
980,
14,
1667,
779,
709,
12,
1967,
566,
267,
367,
284,
315,
4945,
8,
709,
304,
881,
2203,
59,
73,
12,
12228,
275,
291,
14,
7383,
8,
12686,
9,
489,
372,
2203,
339,
372,
2562,
819,
347,
511,
3716,
1470,
8,
277,
304,
272,
862,
26,
489,
687,
7026,
492,
5020,
221,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
272,
871,
3545,
465,
325,
26,
489,
2833,
63,
4806,
14,
4050,
480,
6612,
511,
29559,
26,
450,
83,
401,
325,
9,
489,
372,
339,
327,
710,
29559,
511,
365,
282,
1315,
13,
585,
511,
14,
221,
961,
365,
314,
17451,
1315,
13,
585,
272,
327,
781,
2934,
370,
370,
1435,
323,
14,
9336,
314,
1315,
13,
396,
14106,
18187,
282,
4137,
3293,
272,
327,
4084,
12,
652,
1077,
18871,
28088,
590,
7078,
24068,
1227,
14,
272,
1315,
63,
3097,
275,
1227,
14,
16,
272,
367,
4487,
315,
485,
15925,
63,
36,
7893,
26,
489,
327,
1379,
1380,
25917,
665,
1616,
436,
1380,
25917,
2356,
1616,
489,
367,
7345,
315,
378,
12,
841,
12,
1616,
26,
267,
367,
25917,
315,
334,
19,
2020,
3388,
304,
881,
1390,
63,
17282,
275,
959,
881,
25906,
275,
291,
423,
27434,
8,
9943,
12,
25917,
12,
4487,
12,
675,
63,
6477,
29,
797,
12,
6347,
29,
13261,
9,
881,
1315,
63,
7107,
275,
4884,
14,
396,
63,
17282,
63,
9467,
8,
1598,
25906,
1062,
1598,
1390,
63,
17282,
12,
1598,
5020,
14,
29606,
8,
17984,
395,
1598,
7345,
29,
12318,
12,
881,
776,
881,
291,
14,
4686,
10958,
8,
90,
63,
7107,
12,
1315,
63,
3097,
9,
819,
327,
13813,
626,
314,
11952,
436,
18613,
4514,
2529,
314,
2011,
2058,
12,
523,
327,
1627,
314,
2011,
2196,
6347,
523,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
11011,
8225,
2639,
693,
8,
277,
304,
272,
367,
4487,
315,
485,
15925,
63,
36,
7893,
26,
489,
2058,
275,
1052,
489,
367,
675,
63,
6477,
315,
359,
797,
12,
715,
2189,
267,
25906,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
1180,
63,
6477,
12,
6347,
29,
13261,
9,
267,
2058,
59,
1180,
63,
6477,
61,
275,
25906,
342,
489,
340,
4487,
508,
6674,
14,
1609,
975,
26,
267,
291,
14,
7260,
8,
2604,
59,
797,
467,
2058,
59,
549,
467,
10561,
29,
17,
69,
13,
19,
12,
9543,
29,
17,
69,
13,
19,
9,
489,
587,
26,
267,
291,
14,
7260,
8,
2604,
59,
797,
467,
2058,
59,
549,
467,
10561,
29,
17,
69,
13,
22,
12,
9543,
29,
17,
69,
13,
22,
9,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
19554,
8,
277,
304,
272,
367,
4487,
315,
6674,
14,
1609,
975,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
26,
489,
23132,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
549,
12,
6347,
29,
9908,
9,
489,
1847,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
549,
12,
6347,
29,
9908,
9,
489,
291,
14,
7069,
8,
12915,
1062,
1847,
1012,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
1944,
35,
899,
8,
277,
304,
272,
408,
35,
899,
275,
4413,
1007,
5599,
20714,
707,
14,
339,
2494,
1831
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
1483,
14,
2355,
63,
1483,
14,
2355,
63,
29606,
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,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
4989,
63,
2219,
14,
2355,
492,
4884,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
199,
199,
3,
2900,
3748,
6674,
367,
2196,
63,
29606,
1252,
199,
63,
15925,
63,
36,
7893,
275,
334,
5717,
14,
1609,
975,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
12,
2151,
6674,
14,
442,
708,
12,
6674,
14,
442,
772,
9,
421,
199,
533,
9571,
1575,
18571,
774,
8,
396,
14,
1746,
304,
523,
408,
2765,
365,
282,
7031,
511,
7037,
370,
314,
29559,
14009,
16466,
2005,
900,
1041,
819,
347,
485,
27434,
8,
277,
12,
1967,
12,
25917,
12,
2152,
12,
675,
63,
6477,
12,
6347,
29,
403,
304,
339,
347,
2562,
837,
489,
543,
291,
14,
1730,
8,
1180,
63,
6477,
29,
1180,
63,
6477,
12,
3343,
29,
1483,
14,
4578,
1012,
465,
4043,
26,
267,
9038,
275,
2196,
63,
1483,
14,
2355,
63,
29606,
8,
17984,
12,
359,
1507,
467,
2152,
29,
2271,
12,
6347,
29,
5176,
9,
267,
2203,
275,
980,
14,
1667,
779,
709,
12,
1967,
566,
267,
367,
284,
315,
4945,
8,
709,
304,
881,
2203,
59,
73,
12,
12228,
275,
291,
14,
7383,
8,
12686,
9,
489,
372,
2203,
339,
372,
2562,
819,
347,
511,
3716,
1470,
8,
277,
304,
272,
862,
26,
489,
687,
7026,
492,
5020,
221,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
272,
871,
3545,
465,
325,
26,
489,
2833,
63,
4806,
14,
4050,
480,
6612,
511,
29559,
26,
450,
83,
401,
325,
9,
489,
372,
339,
327,
710,
29559,
511,
365,
282,
1315,
13,
585,
511,
14,
221,
961,
365,
314,
17451,
1315,
13,
585,
272,
327,
781,
2934,
370,
370,
1435,
323,
14,
9336,
314,
1315,
13,
396,
14106,
18187,
282,
4137,
3293,
272,
327,
4084,
12,
652,
1077,
18871,
28088,
590,
7078,
24068,
1227,
14,
272,
1315,
63,
3097,
275,
1227,
14,
16,
272,
367,
4487,
315,
485,
15925,
63,
36,
7893,
26,
489,
327,
1379,
1380,
25917,
665,
1616,
436,
1380,
25917,
2356,
1616,
489,
367,
7345,
315,
378,
12,
841,
12,
1616,
26,
267,
367,
25917,
315,
334,
19,
2020,
3388,
304,
881,
1390,
63,
17282,
275,
959,
881,
25906,
275,
291,
423,
27434,
8,
9943,
12,
25917,
12,
4487,
12,
675,
63,
6477,
29,
797,
12,
6347,
29,
13261,
9,
881,
1315,
63,
7107,
275,
4884,
14,
396,
63,
17282,
63,
9467,
8,
1598,
25906,
1062,
1598,
1390,
63,
17282,
12,
1598,
5020,
14,
29606,
8,
17984,
395,
1598,
7345,
29,
12318,
12,
881,
776,
881,
291,
14,
4686,
10958,
8,
90,
63,
7107,
12,
1315,
63,
3097,
9,
819,
327,
13813,
626,
314,
11952,
436,
18613,
4514,
2529,
314,
2011,
2058,
12,
523,
327,
1627,
314,
2011,
2196,
6347,
523,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
11011,
8225,
2639,
693,
8,
277,
304,
272,
367,
4487,
315,
485,
15925,
63,
36,
7893,
26,
489,
2058,
275,
1052,
489,
367,
675,
63,
6477,
315,
359,
797,
12,
715,
2189,
267,
25906,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
1180,
63,
6477,
12,
6347,
29,
13261,
9,
267,
2058,
59,
1180,
63,
6477,
61,
275,
25906,
342,
489,
340,
4487,
508,
6674,
14,
1609,
975,
26,
267,
291,
14,
7260,
8,
2604,
59,
797,
467,
2058,
59,
549,
467,
10561,
29,
17,
69,
13,
19,
12,
9543,
29,
17,
69,
13,
19,
9,
489,
587,
26,
267,
291,
14,
7260,
8,
2604,
59,
797,
467,
2058,
59,
549,
467,
10561,
29,
17,
69,
13,
22,
12,
9543,
29,
17,
69,
13,
22,
9,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
19554,
8,
277,
304,
272,
367,
4487,
315,
6674,
14,
1609,
975,
12,
6674,
14,
1609,
708,
12,
6674,
14,
1609,
772,
26,
489,
23132,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
549,
12,
6347,
29,
9908,
9,
489,
1847,
275,
291,
423,
27434,
8,
5279,
12,
413,
14,
16,
12,
4487,
12,
675,
63,
6477,
29,
549,
12,
6347,
29,
9908,
9,
489,
291,
14,
7069,
8,
12915,
1062,
1847,
1012,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
1944,
35,
899,
8,
277,
304,
272,
408,
35,
899,
275,
4413,
1007,
5599,
20714,
707,
14,
339,
2494,
1831,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
diegocortassa/TACTIC
|
src/context/client/tactic-api-python-4.0.api04/Lib/pkgutil.py
|
8
|
20584
|
"""Utilities to support packages."""
# NOTE: This module must remain compatible with Python 2.3, as it is shared
# by setuptools for distribution with Python 2.3 and up.
import os
import sys
import imp
import os.path
from types import ModuleType
__all__ = [
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
'walk_packages', 'iter_modules',
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
]
def read_code(stream):
# This helper is needed in order for the PEP 302 emulation to
# correctly handle compiled files
import marshal
magic = stream.read(4)
if magic != imp.get_magic():
return None
stream.read(4) # Skip timestamp
return marshal.load(stream)
def simplegeneric(func):
"""Make a trivial single-dispatch generic function"""
registry = {}
def wrapper(*args, **kw):
ob = args[0]
try:
cls = ob.__class__
except AttributeError:
cls = type(ob)
try:
mro = cls.__mro__
except AttributeError:
try:
class cls(cls, object):
pass
mro = cls.__mro__[1:]
except TypeError:
mro = object, # must be an ExtensionClass or some such :(
for t in mro:
if t in registry:
return registry[t](*args, **kw)
else:
return func(*args, **kw)
try:
wrapper.__name__ = func.__name__
except (TypeError, AttributeError):
pass # Python 2.3 doesn't allow functions to be renamed
def register(typ, func=None):
if func is None:
return lambda f: register(typ, f)
registry[typ] = func
return func
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
wrapper.register = register
return wrapper
def walk_packages(path=None, prefix='', onerror=None):
"""Yields (module_loader, name, ispkg) for all modules recursively
on path, or, if path is None, all accessible modules.
'path' should be either None or a list of paths to look for
modules in.
'prefix' is a string to output on the front of every module name
on output.
Note that this function must import all *packages* (NOT all
modules!) on the given path, in order to access the __path__
attribute to find submodules.
'onerror' is a function which gets called with one argument (the
name of the package which was being imported) if any exception
occurs while trying to import a package. If no onerror function is
supplied, ImportErrors are caught and ignored, while all other
exceptions are propagated, terminating the search.
Examples:
# list all modules python can access
walk_packages()
# list all submodules of ctypes
walk_packages(ctypes.__path__, ctypes.__name__+'.')
"""
def seen(p, m={}):
if p in m:
return True
m[p] = True
for importer, name, ispkg in iter_modules(path, prefix):
yield importer, name, ispkg
if ispkg:
try:
__import__(name)
except ImportError:
if onerror is not None:
onerror(name)
except Exception:
if onerror is not None:
onerror(name)
else:
raise
else:
path = getattr(sys.modules[name], '__path__', None) or []
# don't traverse path items we've seen before
path = [p for p in path if not seen(p)]
for item in walk_packages(path, name+'.', onerror):
yield item
def iter_modules(path=None, prefix=''):
"""Yields (module_loader, name, ispkg) for all submodules on path,
or, if path is None, all top-level modules on sys.path.
'path' should be either None or a list of paths to look for
modules in.
'prefix' is a string to output on the front of every module name
on output.
"""
if path is None:
importers = iter_importers()
else:
importers = map(get_importer, path)
yielded = {}
for i in importers:
for name, ispkg in iter_importer_modules(i, prefix):
if name not in yielded:
yielded[name] = 1
yield i, name, ispkg
#@simplegeneric
def iter_importer_modules(importer, prefix=''):
if not hasattr(importer, 'iter_modules'):
return []
return importer.iter_modules(prefix)
iter_importer_modules = simplegeneric(iter_importer_modules)
class ImpImporter:
"""PEP 302 Importer that wraps Python's "classic" import algorithm
ImpImporter(dirname) produces a PEP 302 importer that searches that
directory. ImpImporter(None) produces a PEP 302 importer that searches
the current sys.path, plus any modules that are frozen or built-in.
Note that ImpImporter does not currently support being used by placement
on sys.meta_path.
"""
def __init__(self, path=None):
self.path = path
def find_module(self, fullname, path=None):
# Note: we ignore 'path' argument since it is only used via meta_path
subname = fullname.split(".")[-1]
if subname != fullname and self.path is None:
return None
if self.path is None:
path = None
else:
path = [os.path.realpath(self.path)]
try:
file, filename, etc = imp.find_module(subname, path)
except ImportError:
return None
return ImpLoader(fullname, file, filename, etc)
def iter_modules(self, prefix=''):
if self.path is None or not os.path.isdir(self.path):
return
yielded = {}
import inspect
filenames = os.listdir(self.path)
filenames.sort() # handle packages before same-named modules
for fn in filenames:
modname = inspect.getmodulename(fn)
if modname=='__init__' or modname in yielded:
continue
path = os.path.join(self.path, fn)
ispkg = False
if not modname and os.path.isdir(path) and '.' not in fn:
modname = fn
for fn in os.listdir(path):
subname = inspect.getmodulename(fn)
if subname=='__init__':
ispkg = True
break
else:
continue # not a package
if modname and '.' not in modname:
yielded[modname] = 1
yield prefix + modname, ispkg
class ImpLoader:
"""PEP 302 Loader that wraps Python's "classic" import algorithm
"""
code = source = None
def __init__(self, fullname, file, filename, etc):
self.file = file
self.filename = filename
self.fullname = fullname
self.etc = etc
def load_module(self, fullname):
self._reopen()
try:
mod = imp.load_module(fullname, self.file, self.filename, self.etc)
finally:
if self.file:
self.file.close()
# Note: we don't set __loader__ because we want the module to look
# normal; i.e. this is just a wrapper for standard import machinery
return mod
def get_data(self, pathname):
return open(pathname, "rb").read()
def _reopen(self):
if self.file and self.file.closed:
mod_type = self.etc[2]
if mod_type==imp.PY_SOURCE:
self.file = open(self.filename, 'rU')
elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION):
self.file = open(self.filename, 'rb')
def _fix_name(self, fullname):
if fullname is None:
fullname = self.fullname
elif fullname != self.fullname:
raise ImportError("Loader for module %s cannot handle "
"module %s" % (self.fullname, fullname))
return fullname
def is_package(self, fullname):
fullname = self._fix_name(fullname)
return self.etc[2]==imp.PKG_DIRECTORY
def get_code(self, fullname=None):
fullname = self._fix_name(fullname)
if self.code is None:
mod_type = self.etc[2]
if mod_type==imp.PY_SOURCE:
source = self.get_source(fullname)
self.code = compile(source, self.filename, 'exec')
elif mod_type==imp.PY_COMPILED:
self._reopen()
try:
self.code = read_code(self.file)
finally:
self.file.close()
elif mod_type==imp.PKG_DIRECTORY:
self.code = self._get_delegate().get_code()
return self.code
def get_source(self, fullname=None):
fullname = self._fix_name(fullname)
if self.source is None:
mod_type = self.etc[2]
if mod_type==imp.PY_SOURCE:
self._reopen()
try:
self.source = self.file.read()
finally:
self.file.close()
elif mod_type==imp.PY_COMPILED:
if os.path.exists(self.filename[:-1]):
f = open(self.filename[:-1], 'rU')
self.source = f.read()
f.close()
elif mod_type==imp.PKG_DIRECTORY:
self.source = self._get_delegate().get_source()
return self.source
def _get_delegate(self):
return ImpImporter(self.filename).find_module('__init__')
def get_filename(self, fullname=None):
fullname = self._fix_name(fullname)
mod_type = self.etc[2]
if self.etc[2]==imp.PKG_DIRECTORY:
return self._get_delegate().get_filename()
elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
return self.filename
return None
try:
import zipimport
from zipimport import zipimporter
def iter_zipimport_modules(importer, prefix=''):
dirlist = zipimport._zip_directory_cache[importer.archive].keys()
dirlist.sort()
_prefix = importer.prefix
plen = len(_prefix)
yielded = {}
import inspect
for fn in dirlist:
if not fn.startswith(_prefix):
continue
fn = fn[plen:].split(os.sep)
if len(fn)==2 and fn[1].startswith('__init__.py'):
if fn[0] not in yielded:
yielded[fn[0]] = 1
yield fn[0], True
if len(fn)!=1:
continue
modname = inspect.getmodulename(fn[0])
if modname=='__init__':
continue
if modname and '.' not in modname and modname not in yielded:
yielded[modname] = 1
yield prefix + modname, False
iter_importer_modules.register(zipimporter, iter_zipimport_modules)
except ImportError:
pass
def get_importer(path_item):
"""Retrieve a PEP 302 importer for the given path item
The returned importer is cached in sys.path_importer_cache
if it was newly created by a path hook.
If there is no importer, a wrapper around the basic import
machinery is returned. This wrapper is never inserted into
the importer cache (None is inserted instead).
The cache (or part of it) can be cleared manually if a
rescan of sys.path_hooks is necessary.
"""
try:
importer = sys.path_importer_cache[path_item]
except KeyError:
for path_hook in sys.path_hooks:
try:
importer = path_hook(path_item)
break
except ImportError:
pass
else:
importer = None
sys.path_importer_cache.setdefault(path_item, importer)
if importer is None:
try:
importer = ImpImporter(path_item)
except ImportError:
importer = None
return importer
def iter_importers(fullname=""):
"""Yield PEP 302 importers for the given module name
If fullname contains a '.', the importers will be for the package
containing fullname, otherwise they will be importers for sys.meta_path,
sys.path, and Python's "classic" import machinery, in that order. If
the named module is in a package, that package is imported as a side
effect of invoking this function.
Non PEP 302 mechanisms (e.g. the Windows registry) used by the
standard import machinery to find files in alternative locations
are partially supported, but are searched AFTER sys.path. Normally,
these locations are searched BEFORE sys.path, preventing sys.path
entries from shadowing them.
For this to cause a visible difference in behaviour, there must
be a module or package name that is accessible via both sys.path
and one of the non PEP 302 file system mechanisms. In this case,
the emulation will find the former version, while the builtin
import mechanism will find the latter.
Items of the following types can be affected by this discrepancy:
imp.C_EXTENSION, imp.PY_SOURCE, imp.PY_COMPILED, imp.PKG_DIRECTORY
"""
if fullname.startswith('.'):
raise ImportError("Relative module names not supported")
if '.' in fullname:
# Get the containing package's __path__
pkg = '.'.join(fullname.split('.')[:-1])
if pkg not in sys.modules:
__import__(pkg)
path = getattr(sys.modules[pkg], '__path__', None) or []
else:
for importer in sys.meta_path:
yield importer
path = sys.path
for item in path:
yield get_importer(item)
if '.' not in fullname:
yield ImpImporter()
def get_loader(module_or_name):
"""Get a PEP 302 "loader" object for module_or_name
If the module or package is accessible via the normal import
mechanism, a wrapper around the relevant part of that machinery
is returned. Returns None if the module cannot be found or imported.
If the named module is not already imported, its containing package
(if any) is imported, in order to establish the package __path__.
This function uses iter_importers(), and is thus subject to the same
limitations regarding platform-specific special import locations such
as the Windows registry.
"""
if module_or_name in sys.modules:
module_or_name = sys.modules[module_or_name]
if isinstance(module_or_name, ModuleType):
module = module_or_name
loader = getattr(module, '__loader__', None)
if loader is not None:
return loader
fullname = module.__name__
else:
fullname = module_or_name
return find_loader(fullname)
def find_loader(fullname):
"""Find a PEP 302 "loader" object for fullname
If fullname contains dots, path must be the containing package's __path__.
Returns None if the module cannot be found or imported. This function uses
iter_importers(), and is thus subject to the same limitations regarding
platform-specific special import locations such as the Windows registry.
"""
for importer in iter_importers(fullname):
loader = importer.find_module(fullname)
if loader is not None:
return loader
return None
def extend_path(path, name):
"""Extend a package's path.
Intended use is to place the following code in a package's __init__.py:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
This will add to the package's __path__ all subdirectories of
directories on sys.path named after the package. This is useful
if one wants to distribute different parts of a single logical
package as multiple directories.
It also looks for *.pkg files beginning where * matches the name
argument. This feature is similar to *.pth files (see site.py),
except that it doesn't special-case lines starting with 'import'.
A *.pkg file is trusted at face value: apart from checking for
duplicates, all entries found in a *.pkg file are added to the
path, regardless of whether they are exist the filesystem. (This
is a feature.)
If the input path is not a list (as is the case for frozen
packages) it is returned unchanged. The input path is not
modified; an extended copy is returned. Items are only appended
to the copy at the end.
It is assumed that sys.path is a sequence. Items of sys.path that
are not (unicode or 8-bit) strings referring to existing
directories are ignored. Unicode items of sys.path that cause
errors when used as filenames may cause this function to raise an
exception (in line with os.path.isdir() behavior).
"""
if not isinstance(path, list):
# This could happen e.g. when this is called from inside a
# frozen package. Return the path unchanged in that case.
return path
pname = os.path.join(*name.split('.')) # Reconstitute as relative path
# Just in case os.extsep != '.'
sname = os.extsep.join(name.split('.'))
sname_pkg = sname + os.extsep + "pkg"
init_py = "__init__" + os.extsep + "py"
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
if not isinstance(dir, basestring) or not os.path.isdir(dir):
continue
subdir = os.path.join(dir, pname)
# XXX This may still add duplicate entries to path on
# case-insensitive filesystems
initfile = os.path.join(subdir, init_py)
if subdir not in path and os.path.isfile(initfile):
path.append(subdir)
# XXX Is this the right thing for subpackages like zope.app?
# It looks for a file named "zope.app.pkg"
pkgfile = os.path.join(dir, sname_pkg)
if os.path.isfile(pkgfile):
try:
f = open(pkgfile)
except IOError, msg:
sys.stderr.write("Can't open %s: %s\n" %
(pkgfile, msg))
else:
for line in f:
line = line.rstrip('\n')
if not line or line.startswith('#'):
continue
path.append(line) # Don't check for existence!
f.close()
return path
def get_data(package, resource):
"""Get a resource from a package.
This is a wrapper round the PEP 302 loader get_data API. The package
argument should be the name of a package, in standard module format
(foo.bar). The resource argument should be in the form of a relative
filename, using '/' as the path separator. The parent directory name '..'
is not allowed, and nor is a rooted name (starting with a '/').
The function returns a binary string, which is the contents of the
specified resource.
For packages located in the filesystem, which have already been imported,
this is the rough equivalent of
d = os.path.dirname(sys.modules[package].__file__)
data = open(os.path.join(d, resource), 'rb').read()
If the package cannot be located or loaded, or it uses a PEP 302 loader
which does not support get_data(), then None is returned.
"""
loader = get_loader(package)
if loader is None or not hasattr(loader, 'get_data'):
return None
mod = sys.modules.get(package) or loader.load_module(package)
if mod is None or not hasattr(mod, '__file__'):
return None
# Modify the resource name to be compatible with the loader.get_data
# signature - an os.path format "filename" starting with the dirname of
# the package's __file__
parts = resource.split('/')
parts.insert(0, os.path.dirname(mod.__file__))
resource_name = os.path.join(*parts)
return loader.get_data(resource_name)
|
epl-1.0
|
[
624,
22905,
370,
2291,
6117,
1041,
2999,
199,
3,
6944,
26,
961,
859,
1471,
5706,
9025,
543,
2018,
499,
14,
19,
12,
465,
652,
365,
5709,
202,
199,
3,
701,
9116,
367,
4084,
543,
2018,
499,
14,
19,
436,
1536,
14,
2999,
199,
646,
747,
202,
199,
646,
984,
202,
199,
646,
1742,
202,
199,
646,
747,
14,
515,
202,
199,
504,
2943,
492,
5673,
804,
2999,
199,
363,
452,
363,
275,
359,
1128,
283,
362,
63,
12138,
297,
283,
1661,
63,
3236,
27568,
297,
283,
362,
63,
3422,
297,
283,
1623,
63,
3422,
297,
1128,
283,
7757,
63,
5154,
297,
283,
1661,
63,
3112,
297,
1128,
283,
8499,
18484,
297,
283,
8499,
5455,
297,
283,
739,
63,
600,
297,
283,
2880,
63,
515,
297,
202,
199,
61,
2999,
199,
318,
1586,
63,
600,
8,
1745,
304,
1128,
327,
961,
5922,
365,
4346,
315,
1865,
367,
314,
13663,
11485,
15074,
370,
1128,
327,
6657,
2429,
10311,
1584,
1128,
492,
21985,
2958,
10628,
275,
2547,
14,
739,
8,
20,
9,
1128,
340,
10628,
1137,
1742,
14,
362,
63,
11523,
837,
1039,
372,
488,
2958,
2547,
14,
739,
8,
20,
9,
327,
8232,
4913,
1128,
372,
21985,
14,
912,
8,
1745,
9,
8065,
199,
318,
3486,
6767,
8,
1532,
304,
1128,
408,
5483,
282,
28586,
2849,
13,
6052,
7809,
805,
624,
1128,
7086,
275,
1052,
1128,
347,
4975,
2031,
589,
12,
1011,
829,
304,
1039,
2607,
275,
1249,
59,
16,
61,
1039,
862,
26,
1675,
843,
275,
2607,
855,
533,
363,
1039,
871,
4281,
26,
1675,
843,
275,
730,
8,
2873,
9,
1039,
862,
26,
1675,
30866,
275,
843,
855,
17335,
363,
1039,
871,
4281,
26,
1675,
862,
26,
2628,
1021,
843,
8,
1886,
12,
909,
304,
4906,
986,
2628,
30866,
275,
843,
855,
17335,
12298,
17,
2938,
1675,
871,
3146,
26,
2628,
30866,
275,
909,
12,
257,
327,
1471,
506,
376,
13282,
2543,
503,
2005,
4066,
221,
520,
8,
1039,
367,
307,
315,
30866,
26,
1675,
340,
307,
315,
7086,
26,
2628,
372,
7086,
59,
84,
61,
2031,
589,
12,
1011,
829,
9,
1039,
587,
26,
1675,
372,
2562,
2031,
589,
12,
1011,
829,
9,
1128,
862,
26,
1039,
4975,
855,
354,
363,
275,
2562,
855,
354,
363,
1128,
871,
334,
4333,
12,
4281,
304,
1039,
986,
259,
327,
2018,
499,
14,
19,
3181,
1133,
2040,
3423,
370,
506,
17864,
2958,
347,
2274,
8,
9749,
12,
2562,
29,
403,
304,
1039,
340,
2562,
365,
488,
26,
1675,
372,
2400,
289,
26,
2274,
8,
9749,
12,
289,
9,
1039,
7086,
59,
9749,
61,
275,
2562,
1039,
372,
2562,
2958,
4975,
855,
807,
363,
275,
2562,
855,
807,
363,
1128,
4975,
855,
1301,
363,
275,
2562,
855,
1301,
363,
1128,
4975,
14,
2683,
275,
2274,
1128,
372,
4975,
8065,
199,
318,
12778,
63,
5154,
8,
515,
29,
403,
12,
2403,
4581,
22852,
29,
403,
304,
1128,
408,
22889,
83,
334,
578,
63,
3422,
12,
536,
12,
365,
4600,
9,
367,
1006,
4621,
15035,
1128,
641,
931,
12,
503,
12,
340,
931,
365,
488,
12,
1006,
17909,
4621,
14,
2958,
283,
515,
7,
1077,
506,
1902,
488,
503,
282,
769,
402,
3792,
370,
3648,
367,
1128,
4621,
315,
14,
2958,
283,
1861,
7,
365,
282,
1059,
370,
1072,
641,
314,
13738,
402,
4036,
859,
536,
1128,
641,
1072,
14,
2958,
3390,
626,
642,
805,
1471,
492,
1006,
627,
5154,
10,
334,
4609,
1006,
1128,
4621,
21866,
641,
314,
1627,
931,
12,
315,
1865,
370,
2879,
314,
636,
515,
363,
1128,
2225,
370,
2342,
29449,
14,
2958,
283,
265,
705,
7,
365,
282,
805,
1314,
7545,
2797,
543,
1373,
1423,
334,
1589,
1128,
536,
402,
314,
2559,
1314,
1990,
3769,
8439,
9,
340,
1263,
1919,
1128,
11058,
1830,
9936,
370,
492,
282,
2559,
14,
221,
982,
949,
22852,
805,
365,
1128,
6841,
12,
3545,
83,
787,
15604,
436,
5525,
12,
1830,
1006,
1163,
1128,
4967,
787,
25350,
12,
5537,
1958,
314,
2754,
14,
2958,
6058,
26,
2958,
327,
769,
1006,
4621,
2366,
883,
2879,
1128,
12778,
63,
5154,
342,
2958,
327,
769,
1006,
29449,
402,
5577,
1128,
12778,
63,
5154,
8,
9798,
855,
515,
3108,
5577,
855,
354,
363,
18098,
358,
1128,
408,
2958,
347,
6775,
8,
80,
12,
333,
16420,
1039,
340,
299,
315,
333,
26,
1675,
372,
715,
1039,
333,
59,
80,
61,
275,
715,
2958,
367,
13479,
12,
536,
12,
365,
4600,
315,
2740,
63,
3112,
8,
515,
12,
2403,
304,
1039,
1995,
13479,
12,
536,
12,
365,
4600,
4341,
340,
365,
4600,
26,
1675,
862,
26,
2628,
636,
646,
721,
354,
9,
1675,
871,
3545,
26,
2628,
340,
22852,
365,
440,
488,
26,
4906,
22852,
8,
354,
9,
1675,
871,
2186,
26,
2628,
340,
22852,
365,
440,
488,
26,
4906,
22852,
8,
354,
9,
2628,
587,
26,
4906,
746,
1675,
587,
26,
2628,
931,
275,
2519,
8,
1274,
14,
3112,
59,
354,
467,
2560,
515,
7500,
488,
9,
503,
942,
24216,
327,
2793,
1133,
24749,
931,
2974,
781,
9064,
6775,
2544,
2628,
931,
275,
359,
80,
367,
299,
315,
931,
340,
440,
6775,
8,
80,
1874,
24216,
367,
1242,
315,
12778,
63,
5154,
8,
515,
12,
536,
18098,
297,
22852,
304,
4906,
1995,
1242,
8065,
199,
318,
2740,
63,
3112,
8,
515,
29,
403,
12,
2403,
9280,
1128,
408,
22889,
83,
334,
578,
63,
3422,
12,
536,
12,
365,
4600,
9,
367,
1006,
29449,
641,
931,
12,
1128,
503,
12,
340,
931,
365,
488,
12,
1006,
2746,
13,
1896,
4621,
641,
984,
14,
515,
14,
2958,
283,
515,
7,
1077,
506,
1902,
488,
503,
282,
769,
402,
3792,
370,
3648,
367,
1128,
4621,
315,
14,
2958,
283,
1861,
7,
365,
282,
1059,
370,
1072,
641,
314,
13738,
402,
4036,
859,
536,
1128,
641,
1072,
14,
1128,
408,
2958,
340,
931,
365,
488,
26,
1039,
1742,
27568,
275,
2740,
63,
3236,
27568,
342,
1128,
587,
26,
1039,
1742,
27568,
275,
2341,
8,
362,
63,
12138,
12,
931,
9,
2958,
28653,
275,
1052,
1128,
367,
284,
315,
1742,
27568,
26,
1039,
367,
536,
12,
365,
4600,
315,
2740,
63,
12138,
63,
3112,
8,
73,
12,
2403,
304,
1675,
340,
536,
440,
315,
28653,
26,
2628,
28653,
59,
354,
61,
275,
413,
2628,
1995,
284,
12,
536,
12
] |
[
22905,
370,
2291,
6117,
1041,
2999,
199,
3,
6944,
26,
961,
859,
1471,
5706,
9025,
543,
2018,
499,
14,
19,
12,
465,
652,
365,
5709,
202,
199,
3,
701,
9116,
367,
4084,
543,
2018,
499,
14,
19,
436,
1536,
14,
2999,
199,
646,
747,
202,
199,
646,
984,
202,
199,
646,
1742,
202,
199,
646,
747,
14,
515,
202,
199,
504,
2943,
492,
5673,
804,
2999,
199,
363,
452,
363,
275,
359,
1128,
283,
362,
63,
12138,
297,
283,
1661,
63,
3236,
27568,
297,
283,
362,
63,
3422,
297,
283,
1623,
63,
3422,
297,
1128,
283,
7757,
63,
5154,
297,
283,
1661,
63,
3112,
297,
1128,
283,
8499,
18484,
297,
283,
8499,
5455,
297,
283,
739,
63,
600,
297,
283,
2880,
63,
515,
297,
202,
199,
61,
2999,
199,
318,
1586,
63,
600,
8,
1745,
304,
1128,
327,
961,
5922,
365,
4346,
315,
1865,
367,
314,
13663,
11485,
15074,
370,
1128,
327,
6657,
2429,
10311,
1584,
1128,
492,
21985,
2958,
10628,
275,
2547,
14,
739,
8,
20,
9,
1128,
340,
10628,
1137,
1742,
14,
362,
63,
11523,
837,
1039,
372,
488,
2958,
2547,
14,
739,
8,
20,
9,
327,
8232,
4913,
1128,
372,
21985,
14,
912,
8,
1745,
9,
8065,
199,
318,
3486,
6767,
8,
1532,
304,
1128,
408,
5483,
282,
28586,
2849,
13,
6052,
7809,
805,
624,
1128,
7086,
275,
1052,
1128,
347,
4975,
2031,
589,
12,
1011,
829,
304,
1039,
2607,
275,
1249,
59,
16,
61,
1039,
862,
26,
1675,
843,
275,
2607,
855,
533,
363,
1039,
871,
4281,
26,
1675,
843,
275,
730,
8,
2873,
9,
1039,
862,
26,
1675,
30866,
275,
843,
855,
17335,
363,
1039,
871,
4281,
26,
1675,
862,
26,
2628,
1021,
843,
8,
1886,
12,
909,
304,
4906,
986,
2628,
30866,
275,
843,
855,
17335,
12298,
17,
2938,
1675,
871,
3146,
26,
2628,
30866,
275,
909,
12,
257,
327,
1471,
506,
376,
13282,
2543,
503,
2005,
4066,
221,
520,
8,
1039,
367,
307,
315,
30866,
26,
1675,
340,
307,
315,
7086,
26,
2628,
372,
7086,
59,
84,
61,
2031,
589,
12,
1011,
829,
9,
1039,
587,
26,
1675,
372,
2562,
2031,
589,
12,
1011,
829,
9,
1128,
862,
26,
1039,
4975,
855,
354,
363,
275,
2562,
855,
354,
363,
1128,
871,
334,
4333,
12,
4281,
304,
1039,
986,
259,
327,
2018,
499,
14,
19,
3181,
1133,
2040,
3423,
370,
506,
17864,
2958,
347,
2274,
8,
9749,
12,
2562,
29,
403,
304,
1039,
340,
2562,
365,
488,
26,
1675,
372,
2400,
289,
26,
2274,
8,
9749,
12,
289,
9,
1039,
7086,
59,
9749,
61,
275,
2562,
1039,
372,
2562,
2958,
4975,
855,
807,
363,
275,
2562,
855,
807,
363,
1128,
4975,
855,
1301,
363,
275,
2562,
855,
1301,
363,
1128,
4975,
14,
2683,
275,
2274,
1128,
372,
4975,
8065,
199,
318,
12778,
63,
5154,
8,
515,
29,
403,
12,
2403,
4581,
22852,
29,
403,
304,
1128,
408,
22889,
83,
334,
578,
63,
3422,
12,
536,
12,
365,
4600,
9,
367,
1006,
4621,
15035,
1128,
641,
931,
12,
503,
12,
340,
931,
365,
488,
12,
1006,
17909,
4621,
14,
2958,
283,
515,
7,
1077,
506,
1902,
488,
503,
282,
769,
402,
3792,
370,
3648,
367,
1128,
4621,
315,
14,
2958,
283,
1861,
7,
365,
282,
1059,
370,
1072,
641,
314,
13738,
402,
4036,
859,
536,
1128,
641,
1072,
14,
2958,
3390,
626,
642,
805,
1471,
492,
1006,
627,
5154,
10,
334,
4609,
1006,
1128,
4621,
21866,
641,
314,
1627,
931,
12,
315,
1865,
370,
2879,
314,
636,
515,
363,
1128,
2225,
370,
2342,
29449,
14,
2958,
283,
265,
705,
7,
365,
282,
805,
1314,
7545,
2797,
543,
1373,
1423,
334,
1589,
1128,
536,
402,
314,
2559,
1314,
1990,
3769,
8439,
9,
340,
1263,
1919,
1128,
11058,
1830,
9936,
370,
492,
282,
2559,
14,
221,
982,
949,
22852,
805,
365,
1128,
6841,
12,
3545,
83,
787,
15604,
436,
5525,
12,
1830,
1006,
1163,
1128,
4967,
787,
25350,
12,
5537,
1958,
314,
2754,
14,
2958,
6058,
26,
2958,
327,
769,
1006,
4621,
2366,
883,
2879,
1128,
12778,
63,
5154,
342,
2958,
327,
769,
1006,
29449,
402,
5577,
1128,
12778,
63,
5154,
8,
9798,
855,
515,
3108,
5577,
855,
354,
363,
18098,
358,
1128,
408,
2958,
347,
6775,
8,
80,
12,
333,
16420,
1039,
340,
299,
315,
333,
26,
1675,
372,
715,
1039,
333,
59,
80,
61,
275,
715,
2958,
367,
13479,
12,
536,
12,
365,
4600,
315,
2740,
63,
3112,
8,
515,
12,
2403,
304,
1039,
1995,
13479,
12,
536,
12,
365,
4600,
4341,
340,
365,
4600,
26,
1675,
862,
26,
2628,
636,
646,
721,
354,
9,
1675,
871,
3545,
26,
2628,
340,
22852,
365,
440,
488,
26,
4906,
22852,
8,
354,
9,
1675,
871,
2186,
26,
2628,
340,
22852,
365,
440,
488,
26,
4906,
22852,
8,
354,
9,
2628,
587,
26,
4906,
746,
1675,
587,
26,
2628,
931,
275,
2519,
8,
1274,
14,
3112,
59,
354,
467,
2560,
515,
7500,
488,
9,
503,
942,
24216,
327,
2793,
1133,
24749,
931,
2974,
781,
9064,
6775,
2544,
2628,
931,
275,
359,
80,
367,
299,
315,
931,
340,
440,
6775,
8,
80,
1874,
24216,
367,
1242,
315,
12778,
63,
5154,
8,
515,
12,
536,
18098,
297,
22852,
304,
4906,
1995,
1242,
8065,
199,
318,
2740,
63,
3112,
8,
515,
29,
403,
12,
2403,
9280,
1128,
408,
22889,
83,
334,
578,
63,
3422,
12,
536,
12,
365,
4600,
9,
367,
1006,
29449,
641,
931,
12,
1128,
503,
12,
340,
931,
365,
488,
12,
1006,
2746,
13,
1896,
4621,
641,
984,
14,
515,
14,
2958,
283,
515,
7,
1077,
506,
1902,
488,
503,
282,
769,
402,
3792,
370,
3648,
367,
1128,
4621,
315,
14,
2958,
283,
1861,
7,
365,
282,
1059,
370,
1072,
641,
314,
13738,
402,
4036,
859,
536,
1128,
641,
1072,
14,
1128,
408,
2958,
340,
931,
365,
488,
26,
1039,
1742,
27568,
275,
2740,
63,
3236,
27568,
342,
1128,
587,
26,
1039,
1742,
27568,
275,
2341,
8,
362,
63,
12138,
12,
931,
9,
2958,
28653,
275,
1052,
1128,
367,
284,
315,
1742,
27568,
26,
1039,
367,
536,
12,
365,
4600,
315,
2740,
63,
12138,
63,
3112,
8,
73,
12,
2403,
304,
1675,
340,
536,
440,
315,
28653,
26,
2628,
28653,
59,
354,
61,
275,
413,
2628,
1995,
284,
12,
536,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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template, abort, redirect, url_for, request, g
from flask_babelex import Babel,format_datetime, gettext, lazy_gettext
from flask_assets import Bundle, Environment
from os.path import exists
from os import environ, makedirs, getenv
from shutil import rmtree
from .blog import blog
from .docs import docs
from .main import main
from .parts import parts
from .rest import rest
from . import cms
from . import translation
import logging
app = Flask(__name__)
assets = Environment(app)
assets.register('css',Bundle('source/style.less',depends='source/*.less',filters=['less','cleancss']),output='css/style.css')
assets.register('js',Bundle('js/jquery-2.1.1.min.js','js/bootstrap.min.js'),output='js/all.js')
app.register_blueprint(main)
app.register_blueprint(blog)
app.register_blueprint(docs)
app.register_blueprint(parts)
app.register_blueprint(rest)
babel = Babel(app,default_domain=translation.messages_domain)
app.jinja_env.filters['markdown_docs'] = cms.markdown_docs
app.jinja_env.filters['markdown_blog'] = cms.markdown_blog
app.jinja_env.globals['gettext_parts'] = translation.gettext_parts
app.jinja_env.globals['gettext_docs'] = translation.gettext_docs
@babel.localeselector
def get_locale():
lang_code = getattr(g,'lang_code',None)
if lang_code is None:
lang_code = 'en'
return lang_code
@app.errorhandler(404)
def error_404(e):
g.lang_code = get_locale()
return render_template('error.html',
page={'title' : 'Page not found'},
title=gettext('Page not found (404)'),
message=gettext('The page you are looking for does not exist. Maybe you made a mistake while typing the URL')
), 404
@app.errorhandler(500)
def error_500(e):
g.lang_code = get_locale()
return render_template('error.html',
page={'title' : 'Server Error'},
title=gettext('Something went wrong (500)'),
message=gettext('An error happened while processing your request. This should not happen, we are very sorry. Please tell us about the this problem by sending a mail to BOLTS@ist-dein-freund.de and include the URL you were trying to access.')
), 500
@app.route("/")
@app.route("/index.html")
def index():
# page = {"title" : gettext("Home")} # not used
return render_template("redirect.html", url = url_for("main.index", lang_code=get_locale()))
if __name__ == "__main__":
app.run()
|
gpl-3.0
|
[
504,
7209,
492,
16704,
12,
3795,
63,
1160,
12,
12004,
12,
4660,
12,
1166,
63,
509,
12,
1056,
12,
486,
199,
504,
7209,
63,
66,
7570,
3113,
492,
699,
902,
12,
908,
63,
2083,
12,
9796,
12,
9617,
63,
5152,
199,
504,
7209,
63,
12186,
492,
29311,
12,
9711,
199,
504,
747,
14,
515,
492,
3495,
199,
504,
747,
492,
6160,
12,
1852,
3220,
12,
29626,
199,
504,
5145,
492,
20978,
199,
504,
1275,
11486,
492,
19936,
199,
504,
1275,
4757,
492,
9149,
199,
504,
1275,
973,
492,
2446,
199,
504,
1275,
4181,
492,
4184,
199,
504,
1275,
3911,
492,
4618,
199,
504,
1275,
492,
19240,
199,
504,
1275,
492,
7761,
199,
646,
2050,
421,
199,
571,
275,
16704,
3460,
354,
3368,
199,
199,
12186,
275,
9711,
8,
571,
9,
199,
199,
12186,
14,
2683,
360,
3919,
297,
12320,
360,
1365,
15,
2487,
14,
2003,
297,
8912,
534,
1365,
20362,
2003,
297,
4273,
2968,
2003,
1673,
3118,
3919,
3815,
1199,
534,
3919,
15,
2487,
14,
3919,
358,
199,
12186,
14,
2683,
360,
3596,
297,
12320,
360,
3596,
15,
22324,
13,
18,
14,
17,
14,
17,
14,
827,
14,
3596,
1673,
3596,
15,
11146,
14,
827,
14,
3596,
659,
1199,
534,
3596,
15,
452,
14,
3596,
358,
199,
199,
571,
14,
2683,
63,
15918,
8,
973,
9,
199,
571,
14,
2683,
63,
15918,
8,
11486,
9,
199,
571,
14,
2683,
63,
15918,
8,
4757,
9,
199,
571,
14,
2683,
63,
15918,
8,
4181,
9,
199,
571,
14,
2683,
63,
15918,
8,
3911,
9,
199,
199,
66,
902,
275,
699,
902,
8,
571,
12,
885,
63,
2261,
29,
6893,
14,
3431,
63,
2261,
9,
199,
199,
571,
14,
12264,
63,
1813,
14,
4273,
459,
15653,
63,
4757,
418,
275,
19240,
14,
15653,
63,
4757,
199,
571,
14,
12264,
63,
1813,
14,
4273,
459,
15653,
63,
11486,
418,
275,
19240,
14,
15653,
63,
11486,
199,
571,
14,
12264,
63,
1813,
14,
8473,
459,
5152,
63,
4181,
418,
275,
7761,
14,
5152,
63,
4181,
199,
571,
14,
12264,
63,
1813,
14,
8473,
459,
5152,
63,
4757,
418,
275,
7761,
14,
5152,
63,
4757,
199,
199,
32,
66,
902,
14,
5508,
6662,
199,
318,
664,
63,
5508,
837,
199,
198,
4159,
63,
600,
275,
2519,
8,
71,
2584,
4159,
63,
600,
297,
403,
9,
199,
198,
692,
6339,
63,
600,
365,
488,
26,
507,
198,
4159,
63,
600,
275,
283,
287,
7,
199,
198,
1107,
6339,
63,
600,
199,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
1125,
63,
5188,
8,
69,
304,
199,
198,
71,
14,
4159,
63,
600,
275,
664,
63,
5508,
342,
199,
198,
1107,
3795,
63,
1160,
360,
705,
14,
1360,
297,
507,
198,
1606,
3713,
1213,
7,
520,
283,
3276,
440,
1911,
2267,
507,
198,
1213,
29,
5152,
360,
3276,
440,
1911,
334,
5188,
11218,
507,
198,
1188,
29,
5152,
360,
1918,
2034,
1265,
787,
10023,
367,
1630,
440,
2187,
14,
23038,
1265,
6326,
282,
27572,
1728,
1830,
14090,
314,
2851,
358,
199,
198,
395,
7901,
199,
199,
32,
571,
14,
705,
2232,
8,
5783,
9,
199,
318,
1125,
63,
5783,
8,
69,
304,
199,
198,
71,
14,
4159,
63,
600,
275,
664,
63,
5508,
342,
199,
198,
1107,
3795,
63,
1160,
360,
705,
14,
1360,
297,
507,
198,
1606,
3713,
1213,
7,
520,
283,
3120,
4520,
2267,
507,
198,
1213,
29,
5152,
360,
20641,
22396,
6835,
334,
5783,
11218,
507,
198,
1188,
29,
5152,
360,
2493,
1125,
21056,
1830,
6661,
2195,
1056,
14,
961,
1077,
440,
5992,
12,
781,
787,
7437,
308,
21342,
14,
7754,
11480,
2739,
3595,
314,
642,
5160,
701,
10209,
282,
6016,
370,
699,
2228,
9730,
32,
631,
13,
271,
262,
13,
20153,
725,
14,
271,
436,
2387,
314,
2851,
1265,
4898,
9936,
370,
2879,
2659,
199,
198,
395,
6891,
421,
199,
32,
571,
14,
4449,
19031,
199,
32,
571,
14,
4449,
4769,
1080,
14,
1360,
531,
199,
318,
1478,
837,
199,
198,
3,
2034,
275,
2420,
1213,
2,
520,
9796,
480,
12054,
531,
93,
221,
327,
440,
1202,
199,
198,
1107,
3795,
63,
1160,
480,
4876,
14,
1360,
401,
1166,
275,
1166,
63,
509,
480,
973,
14,
1080,
401,
6339,
63,
600,
29,
362,
63,
5508,
4059,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
571,
14,
1065,
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
] |
[
7209,
492,
16704,
12,
3795,
63,
1160,
12,
12004,
12,
4660,
12,
1166,
63,
509,
12,
1056,
12,
486,
199,
504,
7209,
63,
66,
7570,
3113,
492,
699,
902,
12,
908,
63,
2083,
12,
9796,
12,
9617,
63,
5152,
199,
504,
7209,
63,
12186,
492,
29311,
12,
9711,
199,
504,
747,
14,
515,
492,
3495,
199,
504,
747,
492,
6160,
12,
1852,
3220,
12,
29626,
199,
504,
5145,
492,
20978,
199,
504,
1275,
11486,
492,
19936,
199,
504,
1275,
4757,
492,
9149,
199,
504,
1275,
973,
492,
2446,
199,
504,
1275,
4181,
492,
4184,
199,
504,
1275,
3911,
492,
4618,
199,
504,
1275,
492,
19240,
199,
504,
1275,
492,
7761,
199,
646,
2050,
421,
199,
571,
275,
16704,
3460,
354,
3368,
199,
199,
12186,
275,
9711,
8,
571,
9,
199,
199,
12186,
14,
2683,
360,
3919,
297,
12320,
360,
1365,
15,
2487,
14,
2003,
297,
8912,
534,
1365,
20362,
2003,
297,
4273,
2968,
2003,
1673,
3118,
3919,
3815,
1199,
534,
3919,
15,
2487,
14,
3919,
358,
199,
12186,
14,
2683,
360,
3596,
297,
12320,
360,
3596,
15,
22324,
13,
18,
14,
17,
14,
17,
14,
827,
14,
3596,
1673,
3596,
15,
11146,
14,
827,
14,
3596,
659,
1199,
534,
3596,
15,
452,
14,
3596,
358,
199,
199,
571,
14,
2683,
63,
15918,
8,
973,
9,
199,
571,
14,
2683,
63,
15918,
8,
11486,
9,
199,
571,
14,
2683,
63,
15918,
8,
4757,
9,
199,
571,
14,
2683,
63,
15918,
8,
4181,
9,
199,
571,
14,
2683,
63,
15918,
8,
3911,
9,
199,
199,
66,
902,
275,
699,
902,
8,
571,
12,
885,
63,
2261,
29,
6893,
14,
3431,
63,
2261,
9,
199,
199,
571,
14,
12264,
63,
1813,
14,
4273,
459,
15653,
63,
4757,
418,
275,
19240,
14,
15653,
63,
4757,
199,
571,
14,
12264,
63,
1813,
14,
4273,
459,
15653,
63,
11486,
418,
275,
19240,
14,
15653,
63,
11486,
199,
571,
14,
12264,
63,
1813,
14,
8473,
459,
5152,
63,
4181,
418,
275,
7761,
14,
5152,
63,
4181,
199,
571,
14,
12264,
63,
1813,
14,
8473,
459,
5152,
63,
4757,
418,
275,
7761,
14,
5152,
63,
4757,
199,
199,
32,
66,
902,
14,
5508,
6662,
199,
318,
664,
63,
5508,
837,
199,
198,
4159,
63,
600,
275,
2519,
8,
71,
2584,
4159,
63,
600,
297,
403,
9,
199,
198,
692,
6339,
63,
600,
365,
488,
26,
507,
198,
4159,
63,
600,
275,
283,
287,
7,
199,
198,
1107,
6339,
63,
600,
199,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
1125,
63,
5188,
8,
69,
304,
199,
198,
71,
14,
4159,
63,
600,
275,
664,
63,
5508,
342,
199,
198,
1107,
3795,
63,
1160,
360,
705,
14,
1360,
297,
507,
198,
1606,
3713,
1213,
7,
520,
283,
3276,
440,
1911,
2267,
507,
198,
1213,
29,
5152,
360,
3276,
440,
1911,
334,
5188,
11218,
507,
198,
1188,
29,
5152,
360,
1918,
2034,
1265,
787,
10023,
367,
1630,
440,
2187,
14,
23038,
1265,
6326,
282,
27572,
1728,
1830,
14090,
314,
2851,
358,
199,
198,
395,
7901,
199,
199,
32,
571,
14,
705,
2232,
8,
5783,
9,
199,
318,
1125,
63,
5783,
8,
69,
304,
199,
198,
71,
14,
4159,
63,
600,
275,
664,
63,
5508,
342,
199,
198,
1107,
3795,
63,
1160,
360,
705,
14,
1360,
297,
507,
198,
1606,
3713,
1213,
7,
520,
283,
3120,
4520,
2267,
507,
198,
1213,
29,
5152,
360,
20641,
22396,
6835,
334,
5783,
11218,
507,
198,
1188,
29,
5152,
360,
2493,
1125,
21056,
1830,
6661,
2195,
1056,
14,
961,
1077,
440,
5992,
12,
781,
787,
7437,
308,
21342,
14,
7754,
11480,
2739,
3595,
314,
642,
5160,
701,
10209,
282,
6016,
370,
699,
2228,
9730,
32,
631,
13,
271,
262,
13,
20153,
725,
14,
271,
436,
2387,
314,
2851,
1265,
4898,
9936,
370,
2879,
2659,
199,
198,
395,
6891,
421,
199,
32,
571,
14,
4449,
19031,
199,
32,
571,
14,
4449,
4769,
1080,
14,
1360,
531,
199,
318,
1478,
837,
199,
198,
3,
2034,
275,
2420,
1213,
2,
520,
9796,
480,
12054,
531,
93,
221,
327,
440,
1202,
199,
198,
1107,
3795,
63,
1160,
480,
4876,
14,
1360,
401,
1166,
275,
1166,
63,
509,
480,
973,
14,
1080,
401,
6339,
63,
600,
29,
362,
63,
5508,
4059,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
571,
14,
1065,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nicko96/Chrome-Infra
|
appengine/sheriff_o_matic/alerts_test.py
|
1
|
12204
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import alerts
import json
import random
import string
import unittest
import webtest
from google.appengine.api import memcache
from google.appengine.ext import testbed
class AlertsTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_all_stubs()
self.testapp = webtest.TestApp(alerts.app)
def tearDown(self):
self.testbed.deactivate()
def check_json_headers(self, res):
self.assertEqual(res.content_type, 'application/json')
# This is necessary for cross-site tools to retrieve alerts
self.assertEqual(res.headers['access-control-allow-origin'], '*')
def test_get_no_data_cached(self):
res = self.testapp.get('/alerts')
self.check_json_headers(res)
self.assertEqual(res.body, '{}')
def test_happy_path(self):
# Set it.
params = {'content': '{"alerts": ["hello", "world"]}'}
self.testapp.post('/alerts', params)
def happy_path():
# Get it.
res = self.testapp.get('/alerts')
self.check_json_headers(res)
data = json.loads(res.body)
# The server should have stuck a 'date' on there.
self.assertTrue('date' in data)
self.assertEqual(type(data['date']), int)
self.assertEqual(data['alerts'], ['hello', 'world'])
happy_path()
memcache.Client().flush_all()
happy_path()
def test_post_invalid_data_not_reflected(self):
params = {'content': '[{"this is not valid JSON'}
self.testapp.post('/alerts', params, status=400)
res = self.testapp.get('/alerts')
self.assertEqual(res.body, '{}')
def test_post_invalid_data_does_not_overwrite_valid_data(self):
# Populate the cache with something valid
params = {'content': '{"alerts": "everything is OK"}'}
self.testapp.post('/alerts', params)
self.testapp.post('/alerts', {'content': 'woozlwuzl'}, status=400)
res = self.testapp.get('/alerts')
self.check_json_headers(res)
data = json.loads(res.body)
self.assertEqual(data['alerts'], 'everything is OK')
def test_alerts_jsons_are_stored_in_history(self):
test_alerts1 = {'alerts': ['hello', 'world', '1']}
test_alerts2 = {'alerts': ['hello', 'world', '2']}
self.testapp.post('/alerts', {'content': json.dumps(test_alerts1)})
self.testapp.post('/alerts', {'content': json.dumps(test_alerts2)})
alerts_query = alerts.AlertsJSON.query().order(alerts.AlertsJSON.date)
stored_alerts = alerts_query.fetch(limit=3)
self.assertEqual(2, len(stored_alerts))
self.assertEqual(stored_alerts[0].type, 'alerts')
self.assertEqual(stored_alerts[1].type, 'alerts')
stored_alerts1 = json.loads(stored_alerts[0].json)
stored_alerts2 = json.loads(stored_alerts[1].json)
self.assertEqual(test_alerts1['alerts'], stored_alerts1['alerts'])
self.assertEqual(test_alerts2['alerts'], stored_alerts2['alerts'])
self.assertTrue('date' in stored_alerts1)
self.assertTrue('date' in stored_alerts2)
self.assertEqual(type(stored_alerts1['date']), int)
self.assertEqual(type(stored_alerts2['date']), int)
def test_repeating_alerts_are_not_stored_to_history(self):
test_alerts = {'alerts': ['hello', 'world']}
self.testapp.post('/alerts', {'content': json.dumps(test_alerts)})
test_alerts['last_builder_info'] = {'some': 'info'}
self.testapp.post('/alerts', {'content': json.dumps(test_alerts)})
stored_alerts = alerts.AlertsJSON.query().fetch(limit=2)
self.assertEqual(1, len(stored_alerts))
def test_alerts_jsons_are_retrieved_from_history(self):
test_alert = {'alerts': ['hello', 'world', '1']}
alerts.AlertsJSON(json=json.dumps(test_alert), type='alerts').put()
response = self.testapp.get('/alerts-history')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
parsed_json = json.loads(response.normal_body)
self.assertEqual(len(parsed_json['history']), 1)
entry_id = parsed_json['history'][0]
response = self.testapp.get('/alerts-history/%s' % entry_id)
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
parsed_json = json.loads(response.normal_body)
self.assertEqual(parsed_json['alerts'], test_alert['alerts'])
def test_provides_login_url(self):
response = self.testapp.get('/alerts-history')
self.assertIn('login-url', response)
def test_invalid_keys_return_400(self):
response = self.testapp.get('/alerts-history/kjhg$%T',
expect_errors=True)
self.assertEqual(response.status_int, 400)
self.assertEqual(response.content_type, 'application/json')
def test_non_existing_keys_return_404(self):
response = self.testapp.get('/alerts-history/5348024557502464',
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
def test_internal_alerts_can_only_retrieved_by_internal_users(self):
test_alert = {'alerts': ['hello', 'world', '1']}
internal_alert = alerts.AlertsJSON(json=json.dumps(test_alert),
type='internal-alerts')
internal_alert_key = internal_alert.put().integer_id()
# No signed-in user.
response = self.testapp.get('/alerts-history/%s' % internal_alert_key,
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
parsed_json = json.loads(response.normal_body)
self.assertNotIn('alerts', parsed_json)
# Non-internal user.
self.testbed.setup_env(USER_EMAIL='test@example.com', USER_ID='1',
USER_IS_ADMIN='1', overwrite=True)
response = self.testapp.get('/alerts-history/%s' % internal_alert_key,
expect_errors=True)
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, 'application/json')
parsed_json = json.loads(response.normal_body)
self.assertNotIn('alerts', parsed_json)
def test_lists_internal_alerts_to_internal_users_only(self):
test_alert = {'alerts': ['hello', 'world', '1']}
alerts.AlertsJSON(json=json.dumps(test_alert),
type='internal-alerts').put()
# No signed-in user.
response = self.testapp.get('/alerts-history')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 0)
# Non-internal user.
self.testbed.setup_env(USER_EMAIL='test@example.com', USER_ID='1',
USER_IS_ADMIN='1', overwrite=True)
response = self.testapp.get('/alerts-history')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 0)
# Internal user.
self.testbed.setup_env(USER_EMAIL='test@google.com', USER_ID='2',
USER_IS_ADMIN='1', overwrite=True)
response = self.testapp.get('/alerts-history')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 1)
def test_returned_alerts_from_history_are_paged(self):
for i in range(20):
test_alert = {'alerts': ['hello', 'world', i]}
alerts.AlertsJSON(json=json.dumps(test_alert), type='alerts').put()
response = self.testapp.get('/alerts-history?limit=15')
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 15)
self.assertEqual(response_json['has_more'], True)
url = '/alerts-history?limit=15&cursor=%s' % response_json['cursor']
response = self.testapp.get(url)
self.assertEqual(response.status_int, 200)
self.assertEqual(response.content_type, 'application/json')
response_json = json.loads(response.normal_body)
self.assertEqual(len(response_json['history']), 5)
self.assertEqual(response_json['has_more'], False)
def test_large_number_of_alerts(self):
# This generates ~2.5MB of JSON that compresses to ~750K. Real
# data compresses about 6x better.
random.seed(0xf00f00)
put_alerts = self.generate_fake_alerts(4000)
params = {'content': json.dumps(put_alerts)}
self.testapp.post('/alerts', params)
res = self.testapp.get('/alerts')
got_alerts = json.loads(res.body)
self.assertEquals(got_alerts['alerts'], put_alerts['alerts'])
def test_alerts_too_big_for_memcache(self):
random.seed(0xf00f00)
big_alerts = self.generate_fake_alerts(10000)
content = json.dumps(big_alerts)
self.assertTrue(len(content) > alerts.AlertsHandler.MAX_JSON_SIZE)
params = {'content': content}
self.testapp.post('/alerts', params)
res = self.testapp.get('/alerts')
got_alerts = json.loads(res.body)
self.assertEquals(got_alerts['alerts'], big_alerts['alerts'])
self.assertEquals(memcache.get(alerts.AlertsHandler.ALERTS_TYPE), None)
def test_update_alerts_when_last_was_stored_in_gcs(self):
random.seed(0xf00f00)
alerts_1 = self.generate_fake_alerts(10000)
content = json.dumps(alerts_1)
self.assertTrue(len(content) > alerts.AlertsHandler.MAX_JSON_SIZE)
params = {'content': content}
self.testapp.post('/alerts', params)
test_alerts2 = {'alerts': ['hello', 'world', '1']}
self.testapp.post('/alerts', {'content': json.dumps(test_alerts2)})
alerts_query = alerts.AlertsJSON.query().order(alerts.AlertsJSON.date)
stored_alerts = alerts_query.fetch(limit=3)
self.assertEqual(2, len(stored_alerts))
self.assertEqual(stored_alerts[0].type, 'alerts')
self.assertEqual(stored_alerts[1].type, 'alerts')
self.assertTrue(stored_alerts[0].use_gcs)
stored_alerts2 = json.loads(stored_alerts[1].json)
self.assertEqual(test_alerts2['alerts'], stored_alerts2['alerts'])
self.assertTrue('date' in stored_alerts2)
self.assertEqual(type(stored_alerts2['date']), int)
def generate_fake_alerts(self, n):
return {'alerts': [self.generate_fake_alert() for _ in range(n)]}
@staticmethod
def generate_fake_alert():
# fake labels
labels = [['', 'last_', 'latest_', 'failing_', 'passing_'],
['build', 'builder', 'revision'],
['', 's', '_url', '_reason', '_name']]
def label():
return string.join(map(random.choice, labels), '')
# fake values
def time():
return random.randint(1407976107614, 1408076107614) / 101.0
def build():
return random.randint(2737, 2894)
def revision():
return random.randint(288849, 289415)
tests = [['Activity', 'Async', 'Browser', 'Content', 'Input'],
['Manager', 'Card', 'Sandbox', 'Container'],
['Test.'],
['', 'Basic', 'Empty', 'More'],
['Mouse', 'App', 'Selection', 'Network', 'Grab'],
['Input', 'Click', 'Failure', 'Capture']]
def test():
return string.join(map(random.choice, tests), '')
def literal_array():
generator = random.choice([time, build, revision])
return [generator() for _ in range(random.randint(0, 10))]
def literal_map():
generators = [build, revision, test, literal_array]
obj = {}
for _ in range(random.randint(3, 9)):
obj[label()] = random.choice(generators)()
return obj
def value():
generators = [time, build, revision, test, literal_array,
literal_map]
return random.choice(generators)()
alert = {}
for _ in range(random.randint(6, 9)):
alert[label()] = value()
return alert
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
31529,
199,
646,
2022,
199,
646,
2196,
199,
646,
1059,
199,
646,
2882,
199,
646,
3330,
396,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
421,
199,
533,
437,
16676,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
272,
291,
14,
396,
6123,
14,
8222,
342,
272,
291,
14,
396,
6123,
14,
826,
63,
452,
63,
8957,
342,
272,
291,
14,
19700,
275,
3330,
396,
14,
774,
2640,
8,
24501,
14,
571,
9,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
396,
6123,
14,
24891,
342,
819,
347,
1104,
63,
1001,
63,
2139,
8,
277,
12,
522,
304,
272,
291,
14,
629,
8,
470,
14,
1317,
63,
466,
12,
283,
3578,
15,
1001,
358,
272,
327,
961,
365,
5784,
367,
8059,
13,
2124,
7249,
370,
8044,
31529,
272,
291,
14,
629,
8,
470,
14,
2139,
459,
2732,
13,
2785,
13,
3306,
13,
6493,
995,
6438,
358,
819,
347,
511,
63,
362,
63,
889,
63,
576,
63,
5245,
8,
277,
304,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
272,
291,
14,
629,
8,
470,
14,
2030,
12,
9005,
358,
819,
347,
511,
63,
72,
18869,
63,
515,
8,
277,
304,
272,
327,
2494,
652,
14,
272,
1862,
275,
791,
1317,
356,
17137,
24501,
582,
2097,
5006,
401,
298,
7617,
27635,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
9,
339,
347,
394,
18869,
63,
515,
837,
489,
327,
2372,
652,
14,
489,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
489,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
489,
666,
275,
2022,
14,
3640,
8,
470,
14,
2030,
9,
2541,
327,
710,
1654,
1077,
1172,
410,
10112,
282,
283,
602,
7,
641,
2337,
14,
489,
291,
14,
1815,
360,
602,
7,
315,
666,
9,
489,
291,
14,
629,
8,
466,
8,
576,
459,
602,
3815,
1109,
9,
2541,
291,
14,
629,
8,
576,
459,
24501,
995,
788,
5006,
297,
283,
7617,
1105,
339,
394,
18869,
63,
515,
342,
339,
21598,
14,
3041,
1252,
4939,
63,
452,
342,
339,
394,
18869,
63,
515,
342,
819,
347,
511,
63,
1932,
63,
3197,
63,
576,
63,
1397,
63,
1121,
2820,
8,
277,
304,
272,
1862,
275,
791,
1317,
356,
6730,
6641,
3749,
365,
440,
1686,
4840,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
12,
2004,
29,
5303,
9,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
629,
8,
470,
14,
2030,
12,
9005,
358,
819,
347,
511,
63,
1932,
63,
3197,
63,
576,
63,
9105,
63,
1397,
63,
14658,
63,
1078,
63,
576,
8,
277,
304,
272,
327,
31731,
314,
2581,
543,
6020,
1686,
272,
1862,
275,
791,
1317,
356,
17137,
24501,
582,
298,
14287,
2127,
365,
9949,
3570,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
9,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
283,
87,
1534,
90,
20692,
9494,
76,
2267,
2004,
29,
5303,
9,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
272,
666,
275,
2022,
14,
3640,
8,
470,
14,
2030,
9,
272,
291,
14,
629,
8,
576,
459,
24501,
995,
283,
14287,
2127,
365,
9949,
358,
819,
347,
511,
63,
24501,
63,
1001,
83,
63,
1530,
63,
16431,
63,
262,
63,
5570,
8,
277,
304,
272,
511,
63,
24501,
17,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
297,
283,
17,
12074,
272,
511,
63,
24501,
18,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
297,
283,
18,
12074,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
17,
11466,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
18,
11466,
272,
31529,
63,
1131,
275,
31529,
14,
33,
16676,
6243,
14,
1131,
1252,
1648,
8,
24501,
14,
33,
16676,
6243,
14,
602,
9,
272,
5489,
63,
24501,
275,
31529,
63,
1131,
14,
3535,
8,
3097,
29,
19,
9,
272,
291,
14,
629,
8,
18,
12,
822,
8,
16431,
63,
24501,
430,
272,
291,
14,
629,
8,
16431,
63,
24501,
59,
16,
1055,
466,
12,
283,
24501,
358,
272,
291,
14,
629,
8,
16431,
63,
24501,
59,
17,
1055,
466,
12,
283,
24501,
358,
272,
5489,
63,
24501,
17,
275,
2022,
14,
3640,
8,
16431,
63,
24501,
59,
16,
1055,
1001,
9,
272,
5489,
63,
24501,
18,
275,
2022,
14,
3640,
8,
16431,
63,
24501,
59,
17,
1055,
1001,
9,
272,
291,
14,
629,
8,
396,
63,
24501,
17,
459,
24501,
995,
5489,
63,
24501,
17,
459,
24501,
1105,
272,
291,
14,
629,
8,
396,
63,
24501,
18,
459,
24501,
995,
5489,
63,
24501,
18,
459,
24501,
1105,
272,
291,
14,
1815,
360,
602,
7,
315,
5489,
63,
24501,
17,
9,
272,
291,
14,
1815,
360,
602,
7,
315,
5489,
63,
24501,
18,
9,
272,
291,
14,
629,
8,
466,
8,
16431,
63,
24501,
17,
459,
602,
3815,
1109,
9,
272,
291,
14,
629,
8,
466,
8,
16431,
63,
24501,
18,
459,
602,
3815,
1109,
9,
819,
347,
511,
63,
5028,
1958,
63,
24501,
63,
1530,
63,
1397,
63,
16431,
63,
475,
63,
5570,
8,
277,
304,
272,
511,
63,
24501,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
12074,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
11466,
272,
511,
63,
24501,
459,
2019,
63,
5649,
63,
815,
418,
275,
791,
3972,
356,
283,
815,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
31529,
199,
646,
2022,
199,
646,
2196,
199,
646,
1059,
199,
646,
2882,
199,
646,
3330,
396,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
421,
199,
533,
437,
16676,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
272,
291,
14,
396,
6123,
14,
8222,
342,
272,
291,
14,
396,
6123,
14,
826,
63,
452,
63,
8957,
342,
272,
291,
14,
19700,
275,
3330,
396,
14,
774,
2640,
8,
24501,
14,
571,
9,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
396,
6123,
14,
24891,
342,
819,
347,
1104,
63,
1001,
63,
2139,
8,
277,
12,
522,
304,
272,
291,
14,
629,
8,
470,
14,
1317,
63,
466,
12,
283,
3578,
15,
1001,
358,
272,
327,
961,
365,
5784,
367,
8059,
13,
2124,
7249,
370,
8044,
31529,
272,
291,
14,
629,
8,
470,
14,
2139,
459,
2732,
13,
2785,
13,
3306,
13,
6493,
995,
6438,
358,
819,
347,
511,
63,
362,
63,
889,
63,
576,
63,
5245,
8,
277,
304,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
272,
291,
14,
629,
8,
470,
14,
2030,
12,
9005,
358,
819,
347,
511,
63,
72,
18869,
63,
515,
8,
277,
304,
272,
327,
2494,
652,
14,
272,
1862,
275,
791,
1317,
356,
17137,
24501,
582,
2097,
5006,
401,
298,
7617,
27635,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
9,
339,
347,
394,
18869,
63,
515,
837,
489,
327,
2372,
652,
14,
489,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
489,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
489,
666,
275,
2022,
14,
3640,
8,
470,
14,
2030,
9,
2541,
327,
710,
1654,
1077,
1172,
410,
10112,
282,
283,
602,
7,
641,
2337,
14,
489,
291,
14,
1815,
360,
602,
7,
315,
666,
9,
489,
291,
14,
629,
8,
466,
8,
576,
459,
602,
3815,
1109,
9,
2541,
291,
14,
629,
8,
576,
459,
24501,
995,
788,
5006,
297,
283,
7617,
1105,
339,
394,
18869,
63,
515,
342,
339,
21598,
14,
3041,
1252,
4939,
63,
452,
342,
339,
394,
18869,
63,
515,
342,
819,
347,
511,
63,
1932,
63,
3197,
63,
576,
63,
1397,
63,
1121,
2820,
8,
277,
304,
272,
1862,
275,
791,
1317,
356,
6730,
6641,
3749,
365,
440,
1686,
4840,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
12,
2004,
29,
5303,
9,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
629,
8,
470,
14,
2030,
12,
9005,
358,
819,
347,
511,
63,
1932,
63,
3197,
63,
576,
63,
9105,
63,
1397,
63,
14658,
63,
1078,
63,
576,
8,
277,
304,
272,
327,
31731,
314,
2581,
543,
6020,
1686,
272,
1862,
275,
791,
1317,
356,
17137,
24501,
582,
298,
14287,
2127,
365,
9949,
3570,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
1862,
9,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
283,
87,
1534,
90,
20692,
9494,
76,
2267,
2004,
29,
5303,
9,
272,
522,
275,
291,
14,
19700,
14,
362,
2336,
24501,
358,
272,
291,
14,
1074,
63,
1001,
63,
2139,
8,
470,
9,
272,
666,
275,
2022,
14,
3640,
8,
470,
14,
2030,
9,
272,
291,
14,
629,
8,
576,
459,
24501,
995,
283,
14287,
2127,
365,
9949,
358,
819,
347,
511,
63,
24501,
63,
1001,
83,
63,
1530,
63,
16431,
63,
262,
63,
5570,
8,
277,
304,
272,
511,
63,
24501,
17,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
297,
283,
17,
12074,
272,
511,
63,
24501,
18,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
297,
283,
18,
12074,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
17,
11466,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
18,
11466,
272,
31529,
63,
1131,
275,
31529,
14,
33,
16676,
6243,
14,
1131,
1252,
1648,
8,
24501,
14,
33,
16676,
6243,
14,
602,
9,
272,
5489,
63,
24501,
275,
31529,
63,
1131,
14,
3535,
8,
3097,
29,
19,
9,
272,
291,
14,
629,
8,
18,
12,
822,
8,
16431,
63,
24501,
430,
272,
291,
14,
629,
8,
16431,
63,
24501,
59,
16,
1055,
466,
12,
283,
24501,
358,
272,
291,
14,
629,
8,
16431,
63,
24501,
59,
17,
1055,
466,
12,
283,
24501,
358,
272,
5489,
63,
24501,
17,
275,
2022,
14,
3640,
8,
16431,
63,
24501,
59,
16,
1055,
1001,
9,
272,
5489,
63,
24501,
18,
275,
2022,
14,
3640,
8,
16431,
63,
24501,
59,
17,
1055,
1001,
9,
272,
291,
14,
629,
8,
396,
63,
24501,
17,
459,
24501,
995,
5489,
63,
24501,
17,
459,
24501,
1105,
272,
291,
14,
629,
8,
396,
63,
24501,
18,
459,
24501,
995,
5489,
63,
24501,
18,
459,
24501,
1105,
272,
291,
14,
1815,
360,
602,
7,
315,
5489,
63,
24501,
17,
9,
272,
291,
14,
1815,
360,
602,
7,
315,
5489,
63,
24501,
18,
9,
272,
291,
14,
629,
8,
466,
8,
16431,
63,
24501,
17,
459,
602,
3815,
1109,
9,
272,
291,
14,
629,
8,
466,
8,
16431,
63,
24501,
18,
459,
602,
3815,
1109,
9,
819,
347,
511,
63,
5028,
1958,
63,
24501,
63,
1530,
63,
1397,
63,
16431,
63,
475,
63,
5570,
8,
277,
304,
272,
511,
63,
24501,
275,
791,
24501,
356,
788,
5006,
297,
283,
7617,
12074,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
63,
24501,
11466,
272,
511,
63,
24501,
459,
2019,
63,
5649,
63,
815,
418,
275,
791,
3972,
356,
283,
815,
936,
272,
291,
14,
19700,
14,
1932,
2336,
24501,
297,
791,
1317,
356,
2022,
14,
4180,
8,
396,
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,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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
] |
skosukhin/spack
|
lib/spack/external/_pytest/recwarn.py
|
10
|
7361
|
""" recording warnings during test function execution. """
import inspect
import _pytest._code
import py
import sys
import warnings
import pytest
@pytest.yield_fixture
def recwarn(request):
"""Return a WarningsRecorder instance that provides these methods:
* ``pop(category=None)``: return last warning matching the category.
* ``clear()``: clear list of warnings
See http://docs.python.org/library/warnings.html for information
on warning categories.
"""
wrec = WarningsRecorder()
with wrec:
warnings.simplefilter('default')
yield wrec
def pytest_namespace():
return {'deprecated_call': deprecated_call,
'warns': warns}
def deprecated_call(func=None, *args, **kwargs):
""" assert that calling ``func(*args, **kwargs)`` triggers a
``DeprecationWarning`` or ``PendingDeprecationWarning``.
This function can be used as a context manager::
>>> import warnings
>>> def api_call_v2():
... warnings.warn('use v3 of this api', DeprecationWarning)
... return 200
>>> with deprecated_call():
... assert api_call_v2() == 200
Note: we cannot use WarningsRecorder here because it is still subject
to the mechanism that prevents warnings of the same type from being
triggered twice for the same module. See #1190.
"""
if not func:
return WarningsChecker(expected_warning=DeprecationWarning)
categories = []
def warn_explicit(message, category, *args, **kwargs):
categories.append(category)
old_warn_explicit(message, category, *args, **kwargs)
def warn(message, category=None, *args, **kwargs):
if isinstance(message, Warning):
categories.append(message.__class__)
else:
categories.append(category)
old_warn(message, category, *args, **kwargs)
old_warn = warnings.warn
old_warn_explicit = warnings.warn_explicit
warnings.warn_explicit = warn_explicit
warnings.warn = warn
try:
ret = func(*args, **kwargs)
finally:
warnings.warn_explicit = old_warn_explicit
warnings.warn = old_warn
deprecation_categories = (DeprecationWarning, PendingDeprecationWarning)
if not any(issubclass(c, deprecation_categories) for c in categories):
__tracebackhide__ = True
raise AssertionError("%r did not produce DeprecationWarning" % (func,))
return ret
def warns(expected_warning, *args, **kwargs):
"""Assert that code raises a particular class of warning.
Specifically, the input @expected_warning can be a warning class or
tuple of warning classes, and the code must return that warning
(if a single class) or one of those warnings (if a tuple).
This helper produces a list of ``warnings.WarningMessage`` objects,
one for each warning raised.
This function can be used as a context manager, or any of the other ways
``pytest.raises`` can be used::
>>> with warns(RuntimeWarning):
... warnings.warn("my warning", RuntimeWarning)
"""
wcheck = WarningsChecker(expected_warning)
if not args:
return wcheck
elif isinstance(args[0], str):
code, = args
assert isinstance(code, str)
frame = sys._getframe(1)
loc = frame.f_locals.copy()
loc.update(kwargs)
with wcheck:
code = _pytest._code.Source(code).compile()
py.builtin.exec_(code, frame.f_globals, loc)
else:
func = args[0]
with wcheck:
return func(*args[1:], **kwargs)
class RecordedWarning(object):
def __init__(self, message, category, filename, lineno, file, line):
self.message = message
self.category = category
self.filename = filename
self.lineno = lineno
self.file = file
self.line = line
class WarningsRecorder(object):
"""A context manager to record raised warnings.
Adapted from `warnings.catch_warnings`.
"""
def __init__(self, module=None):
self._module = sys.modules['warnings'] if module is None else module
self._entered = False
self._list = []
@property
def list(self):
"""The list of recorded warnings."""
return self._list
def __getitem__(self, i):
"""Get a recorded warning by index."""
return self._list[i]
def __iter__(self):
"""Iterate through the recorded warnings."""
return iter(self._list)
def __len__(self):
"""The number of recorded warnings."""
return len(self._list)
def pop(self, cls=Warning):
"""Pop the first recorded warning, raise exception if not exists."""
for i, w in enumerate(self._list):
if issubclass(w.category, cls):
return self._list.pop(i)
__tracebackhide__ = True
raise AssertionError("%r not found in warning list" % cls)
def clear(self):
"""Clear the list of recorded warnings."""
self._list[:] = []
def __enter__(self):
if self._entered:
__tracebackhide__ = True
raise RuntimeError("Cannot enter %r twice" % self)
self._entered = True
self._filters = self._module.filters
self._module.filters = self._filters[:]
self._showwarning = self._module.showwarning
def showwarning(message, category, filename, lineno,
file=None, line=None):
self._list.append(RecordedWarning(
message, category, filename, lineno, file, line))
# still perform old showwarning functionality
self._showwarning(
message, category, filename, lineno, file=file, line=line)
self._module.showwarning = showwarning
# allow the same warning to be raised more than once
self._module.simplefilter('always')
return self
def __exit__(self, *exc_info):
if not self._entered:
__tracebackhide__ = True
raise RuntimeError("Cannot exit %r without entering first" % self)
self._module.filters = self._filters
self._module.showwarning = self._showwarning
class WarningsChecker(WarningsRecorder):
def __init__(self, expected_warning=None, module=None):
super(WarningsChecker, self).__init__(module=module)
msg = ("exceptions must be old-style classes or "
"derived from Warning, not %s")
if isinstance(expected_warning, tuple):
for exc in expected_warning:
if not inspect.isclass(exc):
raise TypeError(msg % type(exc))
elif inspect.isclass(expected_warning):
expected_warning = (expected_warning,)
elif expected_warning is not None:
raise TypeError(msg % type(expected_warning))
self.expected_warning = expected_warning
def __exit__(self, *exc_info):
super(WarningsChecker, self).__exit__(*exc_info)
# only check if we're not currently handling an exception
if all(a is None for a in exc_info):
if self.expected_warning is not None:
if not any(r.category in self.expected_warning for r in self):
__tracebackhide__ = True
pytest.fail("DID NOT WARN")
|
lgpl-2.1
|
[
624,
20952,
3598,
5309,
511,
805,
6451,
14,
408,
199,
199,
646,
6485,
199,
199,
646,
485,
4462,
423,
600,
199,
646,
1134,
199,
646,
984,
199,
646,
3598,
199,
646,
4613,
421,
199,
32,
4462,
14,
11481,
63,
5997,
199,
318,
6488,
4050,
8,
1069,
304,
272,
408,
1767,
282,
644,
2627,
497,
16940,
1256,
626,
6571,
3520,
3102,
26,
339,
627,
1124,
1935,
8,
3710,
29,
403,
9719,
26,
372,
2061,
5721,
4877,
314,
4637,
14,
272,
627,
1124,
3584,
8497,
26,
5436,
769,
402,
3598,
339,
1666,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
5451,
14,
1360,
367,
2556,
272,
641,
5721,
9695,
14,
272,
408,
272,
336,
2761,
275,
644,
2627,
497,
16940,
342,
272,
543,
336,
2761,
26,
267,
3598,
14,
18815,
360,
885,
358,
267,
1995,
336,
2761,
421,
199,
318,
4613,
63,
3251,
837,
272,
372,
791,
6667,
63,
1250,
356,
5906,
63,
1250,
12,
288,
283,
19811,
356,
3429,
561,
93,
421,
199,
318,
5906,
63,
1250,
8,
1532,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
702,
626,
6358,
1124,
1532,
2031,
589,
12,
1011,
958,
9719,
18899,
282,
272,
1124,
15561,
1040,
503,
1124,
15960,
15561,
4345,
339,
961,
805,
883,
506,
1202,
465,
282,
1067,
5256,
447,
398,
1306,
492,
3598,
267,
1306,
347,
2986,
63,
1250,
63,
86,
18,
837,
267,
2263,
258,
3598,
14,
4050,
360,
1180,
373,
19,
402,
642,
2986,
297,
13413,
9,
267,
2263,
258,
372,
1926,
398,
1306,
543,
5906,
63,
1250,
837,
267,
2263,
259,
702,
2986,
63,
1250,
63,
86,
18,
342,
508,
1926,
339,
3390,
26,
781,
3913,
675,
644,
2627,
497,
16940,
2348,
2952,
652,
365,
5139,
5420,
272,
370,
314,
14729,
626,
21925,
3598,
402,
314,
2011,
730,
687,
3769,
272,
15572,
13373,
367,
314,
2011,
859,
14,
1666,
327,
845,
2710,
14,
272,
408,
272,
340,
440,
2562,
26,
267,
372,
644,
2627,
3048,
8,
2062,
63,
3764,
29,
15561,
9,
339,
9695,
275,
942,
339,
347,
7987,
63,
10306,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
304,
267,
9695,
14,
740,
8,
3710,
9,
267,
2269,
63,
4050,
63,
10306,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
7987,
8,
1188,
12,
4637,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
1228,
8,
1188,
12,
15902,
304,
288,
9695,
14,
740,
8,
1188,
855,
533,
3368,
267,
587,
26,
288,
9695,
14,
740,
8,
3710,
9,
267,
2269,
63,
4050,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
9,
339,
2269,
63,
4050,
275,
3598,
14,
4050,
272,
2269,
63,
4050,
63,
10306,
275,
3598,
14,
4050,
63,
10306,
272,
3598,
14,
4050,
63,
10306,
275,
7987,
63,
10306,
272,
3598,
14,
4050,
275,
7987,
272,
862,
26,
267,
2203,
275,
2562,
2031,
589,
12,
1011,
958,
9,
272,
3753,
26,
267,
3598,
14,
4050,
63,
10306,
275,
2269,
63,
4050,
63,
10306,
267,
3598,
14,
4050,
275,
2269,
63,
4050,
272,
17831,
63,
8906,
275,
334,
15561,
12,
29216,
15561,
9,
272,
340,
440,
1263,
8,
20179,
8,
67,
12,
17831,
63,
8906,
9,
367,
286,
315,
9695,
304,
267,
636,
6894,
8191,
363,
275,
715,
267,
746,
9070,
3647,
82,
8103,
440,
7389,
13413,
2,
450,
334,
1532,
4641,
272,
372,
2203,
421,
199,
318,
3429,
561,
8,
2062,
63,
3764,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
9699,
626,
1233,
6534,
282,
6770,
1021,
402,
5721,
14,
339,
30836,
12,
314,
1324,
768,
2062,
63,
3764,
883,
506,
282,
5721,
1021,
503,
272,
2008,
402,
5721,
3992,
12,
436,
314,
1233,
1471,
372,
626,
5721,
272,
334,
692,
282,
2849,
1021,
9,
503,
1373,
402,
5204,
3598,
334,
692,
282,
2008,
680,
339,
961,
5922,
16904,
282,
769,
402,
1124,
5451,
14,
3849,
2209,
1040,
2251,
12,
272,
1373,
367,
1924,
5721,
4915,
14,
339,
961,
805,
883,
506,
1202,
465,
282,
1067,
5256,
12,
503,
1263,
402,
314,
1163,
15217,
272,
1124,
4462,
14,
3536,
1040,
883,
506,
1202,
447,
398,
1306,
543,
3429,
561,
8,
14357,
3849,
304,
267,
2263,
259,
3598,
14,
4050,
480,
1662,
5721,
401,
25178,
9,
272,
408,
272,
336,
1074,
275,
644,
2627,
3048,
8,
2062,
63,
3764,
9,
272,
340,
440,
1249,
26,
267,
372,
336,
1074,
272,
916,
1228,
8,
589,
59,
16,
467,
620,
304,
267,
1233,
12,
275,
1249,
267,
702,
1228,
8,
600,
12,
620,
9,
267,
2787,
275,
984,
423,
20912,
8,
17,
9,
267,
4355,
275,
2787,
14,
70,
63,
9350,
14,
1574,
342,
267,
4355,
14,
873,
8,
958,
9,
398,
543,
336,
1074,
26,
288,
1233,
275,
485,
4462,
423,
600,
14,
2980,
8,
600,
680,
2014,
342,
288,
1134,
14,
5351,
14,
1628,
2531,
600,
12,
2787,
14,
70,
63,
8473,
12,
4355,
9,
272,
587,
26,
267,
2562,
275,
1249,
59,
16,
61,
267,
543,
336,
1074,
26,
288,
372,
2562,
2031,
589,
59,
17,
8429,
1011,
958,
9,
421,
199,
533,
799,
15402,
3849,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
3710,
275,
4637,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
5874,
267,
291,
14,
493,
275,
570,
267,
291,
14,
604,
275,
1004,
421,
199,
533,
644,
2627,
497,
16940,
8,
785,
304,
272,
408,
33,
1067,
5256,
370,
2777,
4915,
3598,
14,
339,
4431,
18309,
687,
658,
5451,
14,
9341,
63,
5451,
2313,
272,
408,
339,
347,
636,
826,
721,
277,
12,
859,
29,
403,
304,
267,
291,
423,
578,
275,
984,
14,
3112,
459,
5451,
418,
340,
859,
365,
488,
587,
859,
267,
291,
423,
287,
3014,
275,
756,
267,
291,
423,
513,
275,
942,
339,
768,
1829,
272,
347,
769,
8,
277,
304,
267,
408,
1918,
769,
402,
18894,
3598,
1041,
267,
372,
291,
423,
513,
339,
347,
636,
6095,
721,
277,
12,
284,
304,
267,
408,
1002,
282,
18894,
5721,
701,
1478,
1041,
267,
372,
291,
423,
513,
59,
73,
61,
339,
347,
636
] |
[
20952,
3598,
5309,
511,
805,
6451,
14,
408,
199,
199,
646,
6485,
199,
199,
646,
485,
4462,
423,
600,
199,
646,
1134,
199,
646,
984,
199,
646,
3598,
199,
646,
4613,
421,
199,
32,
4462,
14,
11481,
63,
5997,
199,
318,
6488,
4050,
8,
1069,
304,
272,
408,
1767,
282,
644,
2627,
497,
16940,
1256,
626,
6571,
3520,
3102,
26,
339,
627,
1124,
1935,
8,
3710,
29,
403,
9719,
26,
372,
2061,
5721,
4877,
314,
4637,
14,
272,
627,
1124,
3584,
8497,
26,
5436,
769,
402,
3598,
339,
1666,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
5451,
14,
1360,
367,
2556,
272,
641,
5721,
9695,
14,
272,
408,
272,
336,
2761,
275,
644,
2627,
497,
16940,
342,
272,
543,
336,
2761,
26,
267,
3598,
14,
18815,
360,
885,
358,
267,
1995,
336,
2761,
421,
199,
318,
4613,
63,
3251,
837,
272,
372,
791,
6667,
63,
1250,
356,
5906,
63,
1250,
12,
288,
283,
19811,
356,
3429,
561,
93,
421,
199,
318,
5906,
63,
1250,
8,
1532,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
702,
626,
6358,
1124,
1532,
2031,
589,
12,
1011,
958,
9719,
18899,
282,
272,
1124,
15561,
1040,
503,
1124,
15960,
15561,
4345,
339,
961,
805,
883,
506,
1202,
465,
282,
1067,
5256,
447,
398,
1306,
492,
3598,
267,
1306,
347,
2986,
63,
1250,
63,
86,
18,
837,
267,
2263,
258,
3598,
14,
4050,
360,
1180,
373,
19,
402,
642,
2986,
297,
13413,
9,
267,
2263,
258,
372,
1926,
398,
1306,
543,
5906,
63,
1250,
837,
267,
2263,
259,
702,
2986,
63,
1250,
63,
86,
18,
342,
508,
1926,
339,
3390,
26,
781,
3913,
675,
644,
2627,
497,
16940,
2348,
2952,
652,
365,
5139,
5420,
272,
370,
314,
14729,
626,
21925,
3598,
402,
314,
2011,
730,
687,
3769,
272,
15572,
13373,
367,
314,
2011,
859,
14,
1666,
327,
845,
2710,
14,
272,
408,
272,
340,
440,
2562,
26,
267,
372,
644,
2627,
3048,
8,
2062,
63,
3764,
29,
15561,
9,
339,
9695,
275,
942,
339,
347,
7987,
63,
10306,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
304,
267,
9695,
14,
740,
8,
3710,
9,
267,
2269,
63,
4050,
63,
10306,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
7987,
8,
1188,
12,
4637,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
1228,
8,
1188,
12,
15902,
304,
288,
9695,
14,
740,
8,
1188,
855,
533,
3368,
267,
587,
26,
288,
9695,
14,
740,
8,
3710,
9,
267,
2269,
63,
4050,
8,
1188,
12,
4637,
12,
627,
589,
12,
1011,
958,
9,
339,
2269,
63,
4050,
275,
3598,
14,
4050,
272,
2269,
63,
4050,
63,
10306,
275,
3598,
14,
4050,
63,
10306,
272,
3598,
14,
4050,
63,
10306,
275,
7987,
63,
10306,
272,
3598,
14,
4050,
275,
7987,
272,
862,
26,
267,
2203,
275,
2562,
2031,
589,
12,
1011,
958,
9,
272,
3753,
26,
267,
3598,
14,
4050,
63,
10306,
275,
2269,
63,
4050,
63,
10306,
267,
3598,
14,
4050,
275,
2269,
63,
4050,
272,
17831,
63,
8906,
275,
334,
15561,
12,
29216,
15561,
9,
272,
340,
440,
1263,
8,
20179,
8,
67,
12,
17831,
63,
8906,
9,
367,
286,
315,
9695,
304,
267,
636,
6894,
8191,
363,
275,
715,
267,
746,
9070,
3647,
82,
8103,
440,
7389,
13413,
2,
450,
334,
1532,
4641,
272,
372,
2203,
421,
199,
318,
3429,
561,
8,
2062,
63,
3764,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
9699,
626,
1233,
6534,
282,
6770,
1021,
402,
5721,
14,
339,
30836,
12,
314,
1324,
768,
2062,
63,
3764,
883,
506,
282,
5721,
1021,
503,
272,
2008,
402,
5721,
3992,
12,
436,
314,
1233,
1471,
372,
626,
5721,
272,
334,
692,
282,
2849,
1021,
9,
503,
1373,
402,
5204,
3598,
334,
692,
282,
2008,
680,
339,
961,
5922,
16904,
282,
769,
402,
1124,
5451,
14,
3849,
2209,
1040,
2251,
12,
272,
1373,
367,
1924,
5721,
4915,
14,
339,
961,
805,
883,
506,
1202,
465,
282,
1067,
5256,
12,
503,
1263,
402,
314,
1163,
15217,
272,
1124,
4462,
14,
3536,
1040,
883,
506,
1202,
447,
398,
1306,
543,
3429,
561,
8,
14357,
3849,
304,
267,
2263,
259,
3598,
14,
4050,
480,
1662,
5721,
401,
25178,
9,
272,
408,
272,
336,
1074,
275,
644,
2627,
3048,
8,
2062,
63,
3764,
9,
272,
340,
440,
1249,
26,
267,
372,
336,
1074,
272,
916,
1228,
8,
589,
59,
16,
467,
620,
304,
267,
1233,
12,
275,
1249,
267,
702,
1228,
8,
600,
12,
620,
9,
267,
2787,
275,
984,
423,
20912,
8,
17,
9,
267,
4355,
275,
2787,
14,
70,
63,
9350,
14,
1574,
342,
267,
4355,
14,
873,
8,
958,
9,
398,
543,
336,
1074,
26,
288,
1233,
275,
485,
4462,
423,
600,
14,
2980,
8,
600,
680,
2014,
342,
288,
1134,
14,
5351,
14,
1628,
2531,
600,
12,
2787,
14,
70,
63,
8473,
12,
4355,
9,
272,
587,
26,
267,
2562,
275,
1249,
59,
16,
61,
267,
543,
336,
1074,
26,
288,
372,
2562,
2031,
589,
59,
17,
8429,
1011,
958,
9,
421,
199,
533,
799,
15402,
3849,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
12,
4637,
12,
1788,
12,
5874,
12,
570,
12,
1004,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
3710,
275,
4637,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
5874,
267,
291,
14,
493,
275,
570,
267,
291,
14,
604,
275,
1004,
421,
199,
533,
644,
2627,
497,
16940,
8,
785,
304,
272,
408,
33,
1067,
5256,
370,
2777,
4915,
3598,
14,
339,
4431,
18309,
687,
658,
5451,
14,
9341,
63,
5451,
2313,
272,
408,
339,
347,
636,
826,
721,
277,
12,
859,
29,
403,
304,
267,
291,
423,
578,
275,
984,
14,
3112,
459,
5451,
418,
340,
859,
365,
488,
587,
859,
267,
291,
423,
287,
3014,
275,
756,
267,
291,
423,
513,
275,
942,
339,
768,
1829,
272,
347,
769,
8,
277,
304,
267,
408,
1918,
769,
402,
18894,
3598,
1041,
267,
372,
291,
423,
513,
339,
347,
636,
6095,
721,
277,
12,
284,
304,
267,
408,
1002,
282,
18894,
5721,
701,
1478,
1041,
267,
372,
291,
423,
513,
59,
73,
61,
339,
347,
636,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wldcordeiro/servo
|
components/script/dom/bindings/codegen/parser/tests/test_special_method_signature_mismatch.py
|
241
|
6622
|
def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch1 {
getter long long foo(long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch2 {
getter void foo(unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch3 {
getter boolean foo(unsigned long index, boolean extraArg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch4 {
getter boolean foo(unsigned long... index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch5 {
getter boolean foo(optional unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch6 {
getter boolean foo();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch7 {
deleter long long foo(long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch9 {
deleter boolean foo(unsigned long index, boolean extraArg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch10 {
deleter boolean foo(unsigned long... index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch11 {
deleter boolean foo(optional unsigned long index);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch12 {
deleter boolean foo();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch13 {
setter long long foo(long index, long long value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch15 {
setter boolean foo(unsigned long index, boolean value, long long extraArg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch16 {
setter boolean foo(unsigned long index, boolean... value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch17 {
setter boolean foo(unsigned long index, optional boolean value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch18 {
setter boolean foo();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch20 {
creator long long foo(long index, long long value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch22 {
creator boolean foo(unsigned long index, boolean value, long long extraArg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch23 {
creator boolean foo(unsigned long index, boolean... value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch24 {
creator boolean foo(unsigned long index, optional boolean value);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
threw = False
try:
parser.parse("""
interface SpecialMethodSignatureMismatch25 {
creator boolean foo();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should have thrown.")
|
mpl-2.0
|
[
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
17,
469,
1598,
15917,
1846,
1846,
3925,
8,
2809,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
18,
469,
1598,
15917,
2309,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
19,
469,
1598,
15917,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
20,
469,
1598,
15917,
5046,
3925,
8,
2244,
1846,
1396,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
21,
469,
1598,
15917,
5046,
3925,
8,
4144,
7381,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
22,
469,
1598,
15917,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
23,
469,
1598,
6070,
351,
1846,
1846,
3925,
8,
2809,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
25,
469,
1598,
6070,
351,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
709,
469,
1598,
6070,
351,
5046,
3925,
8,
2244,
1846,
1396,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
845,
469,
1598,
6070,
351,
5046,
3925,
8,
4144,
7381,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
713,
469,
1598,
6070,
351,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
969,
469,
1598,
18743,
1846,
1846,
3925,
8,
2809,
1478,
12,
1846,
1846,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1046,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
574,
12,
1846,
1846,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
975,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
1396,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1196,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
2716,
5046,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1085,
469,
1598,
18743,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1165,
469,
1598,
14875,
1846,
1846,
3925,
8,
2809,
1478,
12,
1846,
1846
] |
[
22817,
774,
8,
2087,
12,
20458,
304,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
17,
469,
1598,
15917,
1846,
1846,
3925,
8,
2809,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
18,
469,
1598,
15917,
2309,
3925,
8,
2244,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
19,
469,
1598,
15917,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
20,
469,
1598,
15917,
5046,
3925,
8,
2244,
1846,
1396,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
21,
469,
1598,
15917,
5046,
3925,
8,
4144,
7381,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
22,
469,
1598,
15917,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
23,
469,
1598,
6070,
351,
1846,
1846,
3925,
8,
2809,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
25,
469,
1598,
6070,
351,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
709,
469,
1598,
6070,
351,
5046,
3925,
8,
2244,
1846,
1396,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
845,
469,
1598,
6070,
351,
5046,
3925,
8,
4144,
7381,
1846,
1478,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
713,
469,
1598,
6070,
351,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
969,
469,
1598,
18743,
1846,
1846,
3925,
8,
2809,
1478,
12,
1846,
1846,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1046,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
574,
12,
1846,
1846,
2402,
6373,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
975,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
5046,
1396,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1196,
469,
1598,
18743,
5046,
3925,
8,
2244,
1846,
1478,
12,
2716,
5046,
574,
2736,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1085,
469,
1598,
18743,
5046,
3925,
7303,
288,
16735,
267,
7857,
398,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
298,
11408,
1172,
14031,
2685,
339,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
288,
3217,
12568,
3767,
10014,
23055,
1165,
469,
1598,
14875,
1846,
1846,
3925,
8,
2809,
1478,
12,
1846,
1846,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bogde/xbmc.serialepenet.ro
|
requests/packages/charade/cp949prober.py
|
2801
|
1782
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is mozilla.org 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 #########################
from .mbcharsetprober import MultiByteCharSetProber
from .codingstatemachine import CodingStateMachine
from .chardistribution import EUCKRDistributionAnalysis
from .mbcssm import CP949SMModel
class CP949Prober(MultiByteCharSetProber):
def __init__(self):
MultiByteCharSetProber.__init__(self)
self._mCodingSM = CodingStateMachine(CP949SMModel)
# NOTE: CP949 is a superset of EUC-KR, so the distribution should be
# not different.
self._mDistributionAnalyzer = EUCKRDistributionAnalysis()
self.reset()
def get_charset_name(self):
return "CP949"
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
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,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
26007,
27373,
24906,
199,
504,
1275,
887,
3919,
77,
492,
19701,
15674,
25335,
421,
199,
533,
19701,
15674,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
2890,
15674,
25335,
9,
267,
327,
6944,
26,
19701,
15674,
365,
282,
1613,
409,
402,
662,
13371,
13,
23063,
12,
880,
314,
4084,
1077,
506,
267,
327,
755,
440,
3365,
14,
267,
291,
423,
77,
8580,
17606,
275,
26007,
27373,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
2890,
15674,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1303,
6956,
14,
1308,
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,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
26007,
27373,
24906,
199,
504,
1275,
887,
3919,
77,
492,
19701,
15674,
25335,
421,
199,
533,
19701,
15674,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
2890,
15674,
25335,
9,
267,
327,
6944,
26,
19701,
15674,
365,
282,
1613,
409,
402,
662,
13371,
13,
23063,
12,
880,
314,
4084,
1077,
506,
267,
327,
755,
440,
3365,
14,
267,
291,
423,
77,
8580,
17606,
275,
26007,
27373,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
2890,
15674,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jetpacapp/closure-linter
|
build/lib/closure_linter/common/error.py
|
155
|
2070
|
#!/usr/bin/env python
#
# Copyright 2007 The Closure Linter 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.
"""Error object commonly used in linters."""
__author__ = ('robbyw@google.com (Robert Walker)',
'ajp@google.com (Andy Perelson)')
class Error(object):
"""Object representing a style error."""
def __init__(self, code, message, token, position, fix_data):
"""Initialize the error object.
Args:
code: The numeric error code.
message: The error message string.
token: The tokens.Token where the error occurred.
position: The position of the error within the token.
fix_data: Data to be used in autofixing. Codes with fix_data are:
GOOG_REQUIRES_NOT_ALPHABETIZED - List of string value tokens that are
class names in goog.requires calls.
"""
self.code = code
self.message = message
self.token = token
self.position = position
if token:
self.start_index = token.start_index
else:
self.start_index = 0
self.fix_data = fix_data
if self.position:
self.start_index += self.position.start
def Compare(a, b):
"""Compare two error objects, by source code order.
Args:
a: First error object.
b: Second error object.
Returns:
A Negative/0/Positive number when a is before/the same as/after b.
"""
line_diff = a.token.line_number - b.token.line_number
if line_diff:
return line_diff
return a.start_index - b.start_index
Compare = staticmethod(Compare)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
710,
5980,
3253,
491,
1058,
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,
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,
624,
547,
909,
28829,
1202,
315,
7403,
878,
1041,
199,
199,
363,
2502,
363,
275,
661,
29891,
991,
87,
32,
3098,
14,
957,
334,
3863,
12504,
644,
14976,
3196,
1598,
283,
9091,
80,
32,
3098,
14,
957,
334,
3325,
89,
11379,
264,
478,
265,
5942,
421,
199,
533,
4520,
8,
785,
304,
523,
408,
1692,
6144,
282,
3449,
1125,
1041,
819,
347,
636,
826,
721,
277,
12,
1233,
12,
1245,
12,
1526,
12,
3421,
12,
5325,
63,
576,
304,
272,
408,
9345,
314,
1125,
909,
14,
339,
3033,
26,
489,
1233,
26,
710,
8950,
1125,
1233,
14,
489,
1245,
26,
710,
1125,
1245,
1059,
14,
489,
1526,
26,
710,
4645,
14,
3264,
2382,
314,
1125,
8920,
14,
489,
3421,
26,
710,
3421,
402,
314,
1125,
4453,
314,
1526,
14,
489,
5325,
63,
576,
26,
3918,
370,
506,
1202,
315,
2599,
970,
316,
14,
221,
5495,
83,
543,
5325,
63,
576,
787,
26,
881,
9173,
39,
63,
5255,
41,
3830,
63,
4609,
63,
748,
9791,
1217,
775,
18732,
446,
3820,
402,
1059,
574,
4645,
626,
787,
881,
1021,
1561,
315,
2621,
974,
14,
6537,
4882,
14,
272,
408,
272,
291,
14,
600,
275,
1233,
272,
291,
14,
1188,
275,
1245,
272,
291,
14,
1418,
275,
1526,
272,
291,
14,
3124,
275,
3421,
272,
340,
1526,
26,
489,
291,
14,
928,
63,
1080,
275,
1526,
14,
928,
63,
1080,
272,
587,
26,
489,
291,
14,
928,
63,
1080,
275,
378,
272,
291,
14,
970,
63,
576,
275,
5325,
63,
576,
272,
340,
291,
14,
3124,
26,
489,
291,
14,
928,
63,
1080,
847,
291,
14,
3124,
14,
928,
819,
347,
18955,
8,
65,
12,
330,
304,
272,
408,
16051,
2877,
1125,
2251,
12,
701,
1350,
1233,
1865,
14,
339,
3033,
26,
489,
282,
26,
7758,
1125,
909,
14,
489,
330,
26,
16707,
1125,
909,
14,
339,
1803,
26,
489,
437,
32548,
15,
16,
15,
6951,
1329,
1380,
282,
365,
2544,
15,
1589,
2011,
465,
15,
4399,
330,
14,
272,
408,
272,
1004,
63,
3028,
275,
282,
14,
1418,
14,
604,
63,
1955,
446,
330,
14,
1418,
14,
604,
63,
1955,
272,
340,
1004,
63,
3028,
26,
489,
372,
1004,
63,
3028,
339,
372,
282,
14,
928,
63,
1080,
446,
330,
14,
928,
63,
1080,
523,
18955,
275,
12822,
8,
16051,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
710,
5980,
3253,
491,
1058,
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,
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,
624,
547,
909,
28829,
1202,
315,
7403,
878,
1041,
199,
199,
363,
2502,
363,
275,
661,
29891,
991,
87,
32,
3098,
14,
957,
334,
3863,
12504,
644,
14976,
3196,
1598,
283,
9091,
80,
32,
3098,
14,
957,
334,
3325,
89,
11379,
264,
478,
265,
5942,
421,
199,
533,
4520,
8,
785,
304,
523,
408,
1692,
6144,
282,
3449,
1125,
1041,
819,
347,
636,
826,
721,
277,
12,
1233,
12,
1245,
12,
1526,
12,
3421,
12,
5325,
63,
576,
304,
272,
408,
9345,
314,
1125,
909,
14,
339,
3033,
26,
489,
1233,
26,
710,
8950,
1125,
1233,
14,
489,
1245,
26,
710,
1125,
1245,
1059,
14,
489,
1526,
26,
710,
4645,
14,
3264,
2382,
314,
1125,
8920,
14,
489,
3421,
26,
710,
3421,
402,
314,
1125,
4453,
314,
1526,
14,
489,
5325,
63,
576,
26,
3918,
370,
506,
1202,
315,
2599,
970,
316,
14,
221,
5495,
83,
543,
5325,
63,
576,
787,
26,
881,
9173,
39,
63,
5255,
41,
3830,
63,
4609,
63,
748,
9791,
1217,
775,
18732,
446,
3820,
402,
1059,
574,
4645,
626,
787,
881,
1021,
1561,
315,
2621,
974,
14,
6537,
4882,
14,
272,
408,
272,
291,
14,
600,
275,
1233,
272,
291,
14,
1188,
275,
1245,
272,
291,
14,
1418,
275,
1526,
272,
291,
14,
3124,
275,
3421,
272,
340,
1526,
26,
489,
291,
14,
928,
63,
1080,
275,
1526,
14,
928,
63,
1080,
272,
587,
26,
489,
291,
14,
928,
63,
1080,
275,
378,
272,
291,
14,
970,
63,
576,
275,
5325,
63,
576,
272,
340,
291,
14,
3124,
26,
489,
291,
14,
928,
63,
1080,
847,
291,
14,
3124,
14,
928,
819,
347,
18955,
8,
65,
12,
330,
304,
272,
408,
16051,
2877,
1125,
2251,
12,
701,
1350,
1233,
1865,
14,
339,
3033,
26,
489,
282,
26,
7758,
1125,
909,
14,
489,
330,
26,
16707,
1125,
909,
14,
339,
1803,
26,
489,
437,
32548,
15,
16,
15,
6951,
1329,
1380,
282,
365,
2544,
15,
1589,
2011,
465,
15,
4399,
330,
14,
272,
408,
272,
1004,
63,
3028,
275,
282,
14,
1418,
14,
604,
63,
1955,
446,
330,
14,
1418,
14,
604,
63,
1955,
272,
340,
1004,
63,
3028,
26,
489,
372,
1004,
63,
3028,
339,
372,
282,
14,
928,
63,
1080,
446,
330,
14,
928,
63,
1080,
523,
18955,
275,
12822,
8,
16051,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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 (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__ = "Simone Campagna"
__all__ = [
'Test_invoice_main_stats',
]
import datetime
import os
import tempfile
import unittest
from invoice.log import get_null_logger
from invoice.invoice_collection import InvoiceCollection
from invoice.invoice_main import invoice_main
from invoice.invoice_db import InvoiceDb
from invoice.database.db_types import Path
from invoice.string_printer import StringPrinter
class Test_invoice_main_stats(unittest.TestCase):
STATS_YEAR_NO_TOTAL_LONG = """\
anno da: a: clienti fatture incasso %incasso
2014 2014-01-10 2014-01-27 2 2 158.00 100.00%
"""
STATS_YEAR_TOTAL_LONG = """\
anno da: a: clienti fatture incasso %incasso
2014 2014-01-10 2014-01-27 2 2 158.00 100.00%
TOTALE 2 2 158.00 100.00%
"""
STATS_YEAR_TOTAL_SHORT = """\
anno clienti fatture incasso %incasso
2014 2 2 158.00 100.00%
TOTALE 2 2 158.00 100.00%
"""
STATS_YEAR_TOTAL_FULL = """\
anno da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
2014 2014-01-10 2014-01-27 2 2 ########## 158.00 100.00% ##########
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_YEAR_DEFAULT = STATS_YEAR_TOTAL_LONG
STATS_MONTH_NO_TOTAL_LONG = """\
mese da: a: clienti fatture incasso %incasso
2014-01 2014-01-10 2014-01-27 2 2 158.00 100.00%
"""
STATS_MONTH_TOTAL_LONG = STATS_MONTH_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_MONTH_TOTAL_SHORT = """\
mese clienti fatture incasso %incasso
2014-01 2 2 158.00 100.00%
TOTALE 2 2 158.00 100.00%
"""
STATS_MONTH_TOTAL_FULL = """\
mese da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
2014-01 2014-01-10 2014-01-27 2 2 ########## 158.00 100.00% ##########
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_MONTH_DEFAULT = STATS_MONTH_TOTAL_LONG
STATS_WEEK_NO_TOTAL_LONG = """\
settimana da: a: clienti fatture incasso %incasso
2014:04 2014-01-20 2014-01-26 2 2 158.00 100.00%
"""
STATS_WEEK_TOTAL_LONG = STATS_WEEK_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_WEEK_TOTAL_SHORT = """\
settimana clienti fatture incasso %incasso
2014:04 2 2 158.00 100.00%
TOTALE 2 2 158.00 100.00%
"""
STATS_WEEK_TOTAL_FULL = """\
settimana da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
2014:04 2014-01-20 2014-01-26 2 2 ########## 158.00 100.00% ##########
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_WEEK_DEFAULT = STATS_WEEK_TOTAL_LONG
STATS_WEEKDAY_NO_TOTAL_LONG = """\
giorno da: a: clienti fatture incasso %incasso
Mercoledì 2014-01-22 2014-01-22 1 1 107.00 67.72%
Sabato 2014-01-25 2014-01-25 1 1 51.00 32.28%
"""
STATS_WEEKDAY_TOTAL_LONG = STATS_WEEKDAY_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_WEEKDAY_TOTAL_SHORT = """\
giorno clienti fatture incasso %incasso
Mercoledì 1 1 107.00 67.72%
Sabato 1 1 51.00 32.28%
TOTALE 2 2 158.00 100.00%
"""
STATS_WEEKDAY_TOTAL_FULL = """\
giorno da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
Mercoledì 2014-01-22 2014-01-22 1 1 ########## 107.00 67.72% ##########
Sabato 2014-01-25 2014-01-25 1 1 ########## 51.00 32.28% #####
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_WEEKDAY_DEFAULT = STATS_WEEKDAY_TOTAL_LONG
STATS_DAY_NO_TOTAL_LONG = """\
giorno da: a: clienti fatture incasso %incasso
2014-01-22 2014-01-22 2014-01-22 1 1 107.00 67.72%
2014-01-25 2014-01-25 2014-01-25 1 1 51.00 32.28%
"""
STATS_DAY_TOTAL_LONG = STATS_DAY_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_DAY_TOTAL_SHORT = """\
giorno clienti fatture incasso %incasso
2014-01-22 1 1 107.00 67.72%
2014-01-25 1 1 51.00 32.28%
TOTALE 2 2 158.00 100.00%
"""
STATS_DAY_TOTAL_FULL = """\
giorno da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
2014-01-22 2014-01-22 2014-01-22 1 1 ########## 107.00 67.72% ##########
2014-01-25 2014-01-25 2014-01-25 1 1 ########## 51.00 32.28% #####
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_DAY_DEFAULT = STATS_DAY_TOTAL_LONG
STATS_CLIENT_NO_TOTAL_LONG = """\
codice_fiscale da: a: nome cont. fatture incasso %incasso
BNNBRC01G01H663S 2014-01-22 2014-01-22 Robert Bruce Banner [---] 1 107.00 67.72%
WNYBRC01G01H663S 2014-01-25 2014-01-25 Bruce Wayne <---] 1 51.00 32.28%
"""
STATS_CLIENT_TOTAL_LONG = STATS_CLIENT_NO_TOTAL_LONG + """\
TOTALE -- -- 2 158.00 100.00%
"""
STATS_CLIENT_TOTAL_SHORT = """\
codice_fiscale nome cont. fatture incasso %incasso
BNNBRC01G01H663S Robert Bruce Banner [---] 1 107.00 67.72%
WNYBRC01G01H663S Bruce Wayne <---] 1 51.00 32.28%
TOTALE -- -- 2 158.00 100.00%
"""
STATS_CLIENT_TOTAL_FULL = """\
codice_fiscale da: a: nome cont. fatture h(fatture) incasso %incasso h(incasso)
BNNBRC01G01H663S 2014-01-22 2014-01-22 Robert Bruce Banner [---] 1 ########## 107.00 67.72% ##########
WNYBRC01G01H663S 2014-01-25 2014-01-25 Bruce Wayne <---] 1 ########## 51.00 32.28% #####
TOTALE -- -- 2 -- 158.00 100.00% --
"""
STATS_CLIENT_DEFAULT = STATS_CLIENT_TOTAL_LONG
STATS_CITY_NO_TOTAL_LONG = """\
città da: a: clienti fatture incasso %incasso
Gotham City 2014-01-25 2014-01-25 1 1 51.00 32.28%
Greenville 2014-01-22 2014-01-22 1 1 107.00 67.72%
"""
STATS_CITY_TOTAL_LONG = STATS_CITY_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_CITY_TOTAL_SHORT = """\
città clienti fatture incasso %incasso
Gotham City 1 1 51.00 32.28%
Greenville 1 1 107.00 67.72%
TOTALE 2 2 158.00 100.00%
"""
STATS_CITY_TOTAL_FULL = """\
città da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
Gotham City 2014-01-25 2014-01-25 1 1 ########## 51.00 32.28% #####
Greenville 2014-01-22 2014-01-22 1 1 ########## 107.00 67.72% ##########
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_CITY_DEFAULT = STATS_CITY_TOTAL_LONG
STATS_SERVICE_NO_TOTAL_LONG = """\
prestazione da: a: clienti fatture incasso %incasso
Group therapy for depressed superheroes 2014-01-25 2014-01-25 1 1 51.00 32.28%
Therapy for rage control 2014-01-22 2014-01-22 1 1 107.00 67.72%
"""
STATS_SERVICE_TOTAL_LONG = STATS_SERVICE_NO_TOTAL_LONG + """\
TOTALE 2 2 158.00 100.00%
"""
STATS_SERVICE_TOTAL_SHORT = """\
prestazione clienti fatture incasso %incasso
Group therapy for depressed superheroes 1 1 51.00 32.28%
Therapy for rage control 1 1 107.00 67.72%
TOTALE 2 2 158.00 100.00%
"""
STATS_SERVICE_TOTAL_FULL = """\
prestazione da: a: clienti fatture h(fatture) incasso %incasso h(incasso)
Group therapy for depressed superheroes 2014-01-25 2014-01-25 1 1 ########## 51.00 32.28% #####
Therapy for rage control 2014-01-22 2014-01-22 1 1 ########## 107.00 67.72% ##########
TOTALE 2 2 -- 158.00 100.00% --
"""
STATS_SERVICE_DEFAULT = STATS_SERVICE_TOTAL_LONG
STATS_TASK_NO_TOTAL_LONG = """\
codice_fiscale nome prestazione da: a: fatture incasso %incasso
BNNBRC01G01H663S Robert Bruce Banner Therapy for rage control 2014-01-22 2014-01-22 1 107.00 67.72%
WNYBRC01G01H663S Bruce Wayne Group therapy for depressed superheroes 2014-01-25 2014-01-25 1 51.00 32.28%
"""
STATS_TASK_TOTAL_LONG = STATS_TASK_NO_TOTAL_LONG + """\
TOTALE 2 158.00 100.00%
"""
STATS_TASK_TOTAL_SHORT = """\
codice_fiscale nome prestazione fatture incasso %incasso
BNNBRC01G01H663S Robert Bruce Banner Therapy for rage control 1 107.00 67.72%
WNYBRC01G01H663S Bruce Wayne Group therapy for depressed superheroes 1 51.00 32.28%
TOTALE 2 158.00 100.00%
"""
STATS_TASK_TOTAL_FULL = """\
codice_fiscale nome prestazione da: a: fatture h(fatture) incasso %incasso h(incasso)
BNNBRC01G01H663S Robert Bruce Banner Therapy for rage control 2014-01-22 2014-01-22 1 ########## 107.00 67.72% ##########
WNYBRC01G01H663S Bruce Wayne Group therapy for depressed superheroes 2014-01-25 2014-01-25 1 ########## 51.00 32.28% #####
TOTALE 2 -- 158.00 100.00% --
"""
STATS_TASK_DEFAULT = STATS_TASK_TOTAL_LONG
STATS_NONE_DEFAULT = STATS_MONTH_DEFAULT
STATS_NONE_TOTAL_LONG = STATS_MONTH_TOTAL_LONG
STATS_NONE_NO_TOTAL_LONG = STATS_MONTH_NO_TOTAL_LONG
STATS_NONE_TOTAL_SHORT = STATS_MONTH_TOTAL_SHORT
STATS_NONE_TOTAL_LONG = STATS_MONTH_TOTAL_LONG
STATS_NONE_TOTAL_FULL = STATS_MONTH_TOTAL_FULL
def setUp(self):
self.dirname = Path.db_to(os.path.join(os.path.dirname(__file__), '..', '..', 'example'))
self.logger = get_null_logger()
self.maxDiff = None
def _test_invoice_main_stats(self, stats_group, total, output, mode_flag=None):
with tempfile.TemporaryDirectory() as tmpdir:
rc_dir = os.path.join(tmpdir, 'rc_dir')
os.makedirs(rc_dir)
p = StringPrinter()
p.reset()
invoice_main(
printer=p,
logger=self.logger,
args=['init', '-R', rc_dir, os.path.join(self.dirname, '*.doc')],
)
self.assertEqual(p.string(), '')
p.reset()
invoice_main(
printer=p,
logger=self.logger,
args=['scan', '-R', rc_dir, '--progressbar=off'],
)
self.assertEqual(p.string(), '')
args=['stats', '-R', rc_dir, '-S', '2014-01-10', '-E', '2014-01-27']
if stats_group:
args.append('-g{}'.format(stats_group))
if total is not None:
if total:
args.append('--total=on')
else:
args.append('--total=off')
if mode_flag:
args.append(mode_flag)
invoice_main(
printer=p,
logger=self.logger,
args=args,
)
print(p.string())
self.assertEqual(p.string(), output)
def test_invoice_main_stats_service(self):
return self._test_invoice_main_stats('service', None, self.STATS_SERVICE_DEFAULT)
def test_invoice_main_stats_service_no_total(self):
return self._test_invoice_main_stats('service', False, self.STATS_SERVICE_NO_TOTAL_LONG)
def test_invoice_main_stats_service_total(self):
return self._test_invoice_main_stats('service', True, self.STATS_SERVICE_TOTAL_LONG)
def test_invoice_main_stats_service_total_short(self):
return self._test_invoice_main_stats('service', True, self.STATS_SERVICE_TOTAL_SHORT, '-s')
def test_invoice_main_stats_service_total_long(self):
return self._test_invoice_main_stats('service', True, self.STATS_SERVICE_TOTAL_LONG, '-l')
def test_invoice_main_stats_service_total_full(self):
return self._test_invoice_main_stats('service', True, self.STATS_SERVICE_TOTAL_FULL, '-f')
def test_invoice_main_stats_task(self):
return self._test_invoice_main_stats('task', None, self.STATS_TASK_DEFAULT)
def test_invoice_main_stats_task_no_total(self):
return self._test_invoice_main_stats('task', False, self.STATS_TASK_NO_TOTAL_LONG)
def test_invoice_main_stats_task_total(self):
return self._test_invoice_main_stats('task', True, self.STATS_TASK_TOTAL_LONG)
def test_invoice_main_stats_task_total_short(self):
return self._test_invoice_main_stats('task', True, self.STATS_TASK_TOTAL_SHORT, '-s')
def test_invoice_main_stats_task_total_long(self):
return self._test_invoice_main_stats('task', True, self.STATS_TASK_TOTAL_LONG, '-l')
def test_invoice_main_stats_task_total_full(self):
return self._test_invoice_main_stats('task', True, self.STATS_TASK_TOTAL_FULL, '-f')
def test_invoice_main_stats_year(self):
return self._test_invoice_main_stats('year', None, self.STATS_YEAR_DEFAULT)
def test_invoice_main_stats_year_no_total(self):
return self._test_invoice_main_stats('year', False, self.STATS_YEAR_NO_TOTAL_LONG)
def test_invoice_main_stats_year_total(self):
return self._test_invoice_main_stats('year', True, self.STATS_YEAR_TOTAL_LONG)
def test_invoice_main_stats_year_total_short(self):
return self._test_invoice_main_stats('year', True, self.STATS_YEAR_TOTAL_SHORT, '-s')
def test_invoice_main_stats_year_total_long(self):
return self._test_invoice_main_stats('year', True, self.STATS_YEAR_TOTAL_LONG, '-l')
def test_invoice_main_stats_year_total_full(self):
return self._test_invoice_main_stats('year', True, self.STATS_YEAR_TOTAL_FULL, '-f')
def test_invoice_main_stats_month(self):
return self._test_invoice_main_stats('month', None, self.STATS_MONTH_DEFAULT)
def test_invoice_main_stats_month_no_total(self):
return self._test_invoice_main_stats('month', False, self.STATS_MONTH_NO_TOTAL_LONG)
def test_invoice_main_stats_month_total(self):
return self._test_invoice_main_stats('month', True, self.STATS_MONTH_TOTAL_LONG)
def test_invoice_main_stats_month_total_short(self):
return self._test_invoice_main_stats('month', True, self.STATS_MONTH_TOTAL_SHORT, '-s')
def test_invoice_main_stats_month_total_long(self):
return self._test_invoice_main_stats('month', True, self.STATS_MONTH_TOTAL_LONG, '-l')
def test_invoice_main_stats_month_total_full(self):
return self._test_invoice_main_stats('month', True, self.STATS_MONTH_TOTAL_FULL, '-f')
def test_invoice_main_stats_week(self):
return self._test_invoice_main_stats('week', None, self.STATS_WEEK_DEFAULT)
def test_invoice_main_stats_week_no_total(self):
return self._test_invoice_main_stats('week', False, self.STATS_WEEK_NO_TOTAL_LONG)
def test_invoice_main_stats_week_total(self):
return self._test_invoice_main_stats('week', True, self.STATS_WEEK_TOTAL_LONG)
def test_invoice_main_stats_week_total_short(self):
return self._test_invoice_main_stats('week', True, self.STATS_WEEK_TOTAL_SHORT, '-s')
def test_invoice_main_stats_week_total_long(self):
return self._test_invoice_main_stats('week', True, self.STATS_WEEK_TOTAL_LONG, '-l')
def test_invoice_main_stats_week_total_full(self):
return self._test_invoice_main_stats('week', True, self.STATS_WEEK_TOTAL_FULL, '-f')
def test_invoice_main_stats_weekday(self):
return self._test_invoice_main_stats('weekday', None, self.STATS_WEEKDAY_DEFAULT)
def test_invoice_main_stats_weekday_no_total(self):
return self._test_invoice_main_stats('weekday', False, self.STATS_WEEKDAY_NO_TOTAL_LONG)
def test_invoice_main_stats_weekday_total(self):
return self._test_invoice_main_stats('weekday', True, self.STATS_WEEKDAY_TOTAL_LONG)
def test_invoice_main_stats_weekday_total_short(self):
return self._test_invoice_main_stats('weekday', True, self.STATS_WEEKDAY_TOTAL_SHORT, '--short')
def test_invoice_main_stats_weekday_total_long(self):
return self._test_invoice_main_stats('weekday', True, self.STATS_WEEKDAY_TOTAL_LONG, '--long')
def test_invoice_main_stats_weekday_total_full(self):
return self._test_invoice_main_stats('weekday', True, self.STATS_WEEKDAY_TOTAL_FULL, '--full')
def test_invoice_main_stats_day(self):
return self._test_invoice_main_stats('day', None, self.STATS_DAY_DEFAULT)
def test_invoice_main_stats_day_no_total(self):
return self._test_invoice_main_stats('day', False, self.STATS_DAY_NO_TOTAL_LONG)
def test_invoice_main_stats_day_total(self):
return self._test_invoice_main_stats('day', True, self.STATS_DAY_TOTAL_LONG)
def test_invoice_main_stats_day_total_short(self):
return self._test_invoice_main_stats('day', True, self.STATS_DAY_TOTAL_SHORT, '--short')
def test_invoice_main_stats_day_total_long(self):
return self._test_invoice_main_stats('day', True, self.STATS_DAY_TOTAL_LONG, '--long')
def test_invoice_main_stats_day_total_full(self):
return self._test_invoice_main_stats('day', True, self.STATS_DAY_TOTAL_FULL, '--full')
def test_invoice_main_stats_client(self):
return self._test_invoice_main_stats('client', None, self.STATS_CLIENT_DEFAULT)
def test_invoice_main_stats_client_no_total(self):
return self._test_invoice_main_stats('client', False, self.STATS_CLIENT_NO_TOTAL_LONG)
def test_invoice_main_stats_client_total(self):
return self._test_invoice_main_stats('client', True, self.STATS_CLIENT_TOTAL_LONG)
def test_invoice_main_stats_client_total_short(self):
return self._test_invoice_main_stats('client', True, self.STATS_CLIENT_TOTAL_SHORT, '--short')
def test_invoice_main_stats_client_total_long(self):
return self._test_invoice_main_stats('client', True, self.STATS_CLIENT_TOTAL_LONG, '--long')
def test_invoice_main_stats_client_total_full(self):
return self._test_invoice_main_stats('client', True, self.STATS_CLIENT_TOTAL_FULL, '--full')
def test_invoice_main_stats_city(self):
return self._test_invoice_main_stats('city', None, self.STATS_CITY_DEFAULT)
def test_invoice_main_stats_city(self):
return self._test_invoice_main_stats('city', False, self.STATS_CITY_NO_TOTAL_LONG)
def test_invoice_main_stats_city(self):
return self._test_invoice_main_stats('city', True, self.STATS_CITY_TOTAL_LONG)
def test_invoice_main_stats_city_short(self):
return self._test_invoice_main_stats('city', True, self.STATS_CITY_TOTAL_SHORT, '--short')
def test_invoice_main_stats_city_long(self):
return self._test_invoice_main_stats('city', True, self.STATS_CITY_TOTAL_LONG, '--long')
def test_invoice_main_stats_city_full(self):
return self._test_invoice_main_stats('city', True, self.STATS_CITY_TOTAL_FULL, '--full')
def test_invoice_main_stats_none(self):
return self._test_invoice_main_stats(None, None, self.STATS_NONE_DEFAULT)
def test_invoice_main_stats_none_no_total(self):
return self._test_invoice_main_stats(None, False, self.STATS_NONE_NO_TOTAL_LONG)
def test_invoice_main_stats_none_total(self):
return self._test_invoice_main_stats(None, True, self.STATS_NONE_TOTAL_LONG)
def test_invoice_main_stats_none_total_short(self):
return self._test_invoice_main_stats(None, True, self.STATS_NONE_TOTAL_SHORT, '-s')
def test_invoice_main_stats_none_total_long(self):
return self._test_invoice_main_stats(None, True, self.STATS_NONE_TOTAL_LONG, '-l')
def test_invoice_main_stats_none_total_full(self):
return self._test_invoice_main_stats(None, True, self.STATS_NONE_TOTAL_FULL, '-f')
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
259,
199,
3,
1898,
6900,
10751,
368,
24569,
643,
3540,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
298,
7467,
368,
24569,
643,
3540,
2,
199,
363,
452,
363,
275,
359,
272,
283,
774,
63,
5404,
63,
973,
63,
3200,
297,
199,
61,
199,
199,
646,
2197,
199,
646,
747,
199,
646,
5549,
199,
646,
2882,
199,
199,
504,
8485,
14,
793,
492,
664,
63,
2307,
63,
2921,
199,
504,
8485,
14,
5404,
63,
3627,
492,
19868,
7768,
199,
504,
8485,
14,
5404,
63,
973,
492,
8485,
63,
973,
199,
504,
8485,
14,
5404,
63,
697,
492,
19868,
8882,
199,
504,
8485,
14,
4659,
14,
697,
63,
1313,
492,
6912,
199,
504,
8485,
14,
875,
63,
11835,
492,
2624,
14131,
199,
199,
533,
1379,
63,
5404,
63,
973,
63,
3200,
8,
2796,
14,
1746,
304,
272,
13146,
51,
63,
19216,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
25264,
263,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
12375,
275,
9638,
199,
25264,
3515,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
257,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
17907,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
13003,
275,
9638,
199,
25264,
257,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
260,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
14742,
275,
9638,
199,
25264,
3515,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
394,
8,
70,
6796,
608,
9,
12864,
15923,
450,
6559,
15923,
394,
8,
6559,
15923,
9,
199,
7280,
257,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
21937,
309,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
21937,
309,
199,
15386,
37,
17907,
499,
755,
499,
1553,
3515,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
1553,
260,
199,
624,
272,
13146,
51,
63,
19216,
63,
3472,
275,
13146,
51,
63,
19216,
63,
15386,
63,
12375,
339,
13146,
51,
63,
16413,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
278,
261,
3698,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
13,
614,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
12375,
275,
13146,
51,
63,
16413,
63,
2826,
63,
15386,
63,
12375,
435,
9638,
199,
15386,
37,
19242,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
13003,
275,
9638,
199,
278,
261,
259,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
13,
614,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
263,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
14742,
275,
9638,
199,
278,
261,
3698,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
394,
8,
70,
6796,
608,
9,
12864,
15923,
450,
6559,
15923,
394,
8,
6559,
15923,
9,
199,
7280,
13,
614,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
21937,
309,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
21937,
309,
199,
15386,
37,
19242,
499,
755,
499,
1553,
3515,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
1553,
260,
199,
624,
272,
13146,
51,
63,
16413,
63,
3472,
275,
13146,
51,
63,
16413,
63,
15386,
63,
12375,
339,
13146,
51,
63,
24929,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
409,
280,
1237,
65,
263,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
26,
966,
257,
6927,
13,
614,
13,
1165,
6927,
13,
614,
13,
1479,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
24929,
63,
15386,
63,
12375,
275,
13146,
51,
63,
24929,
63,
2826,
63,
15386,
63,
12375,
435,
9638,
199,
15386,
37,
13293,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
24929,
63,
15386,
63,
13003,
275,
9638,
199,
409,
280,
1237,
65,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
26,
966,
260,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
3515,
499,
755,
499,
221,
413,
2010,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
259,
199,
3,
1898,
6900,
10751,
368,
24569,
643,
3540,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
298,
7467,
368,
24569,
643,
3540,
2,
199,
363,
452,
363,
275,
359,
272,
283,
774,
63,
5404,
63,
973,
63,
3200,
297,
199,
61,
199,
199,
646,
2197,
199,
646,
747,
199,
646,
5549,
199,
646,
2882,
199,
199,
504,
8485,
14,
793,
492,
664,
63,
2307,
63,
2921,
199,
504,
8485,
14,
5404,
63,
3627,
492,
19868,
7768,
199,
504,
8485,
14,
5404,
63,
973,
492,
8485,
63,
973,
199,
504,
8485,
14,
5404,
63,
697,
492,
19868,
8882,
199,
504,
8485,
14,
4659,
14,
697,
63,
1313,
492,
6912,
199,
504,
8485,
14,
875,
63,
11835,
492,
2624,
14131,
199,
199,
533,
1379,
63,
5404,
63,
973,
63,
3200,
8,
2796,
14,
1746,
304,
272,
13146,
51,
63,
19216,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
25264,
263,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
12375,
275,
9638,
199,
25264,
3515,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
257,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
17907,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
13003,
275,
9638,
199,
25264,
257,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
260,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
19216,
63,
15386,
63,
14742,
275,
9638,
199,
25264,
3515,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
394,
8,
70,
6796,
608,
9,
12864,
15923,
450,
6559,
15923,
394,
8,
6559,
15923,
9,
199,
7280,
257,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
21937,
309,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
21937,
309,
199,
15386,
37,
17907,
499,
755,
499,
1553,
3515,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
1553,
260,
199,
624,
272,
13146,
51,
63,
19216,
63,
3472,
275,
13146,
51,
63,
19216,
63,
15386,
63,
12375,
339,
13146,
51,
63,
16413,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
278,
261,
3698,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
13,
614,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
12375,
275,
13146,
51,
63,
16413,
63,
2826,
63,
15386,
63,
12375,
435,
9638,
199,
15386,
37,
19242,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
13003,
275,
9638,
199,
278,
261,
259,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
13,
614,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
263,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
16413,
63,
15386,
63,
14742,
275,
9638,
199,
278,
261,
3698,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
394,
8,
70,
6796,
608,
9,
12864,
15923,
450,
6559,
15923,
394,
8,
6559,
15923,
9,
199,
7280,
13,
614,
6927,
13,
614,
13,
709,
6927,
13,
614,
13,
1465,
755,
499,
755,
499,
21937,
309,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
21937,
309,
199,
15386,
37,
19242,
499,
755,
499,
1553,
3515,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
1553,
260,
199,
624,
272,
13146,
51,
63,
16413,
63,
3472,
275,
13146,
51,
63,
16413,
63,
15386,
63,
12375,
339,
13146,
51,
63,
24929,
63,
2826,
63,
15386,
63,
12375,
275,
9638,
199,
409,
280,
1237,
65,
263,
12927,
26,
260,
282,
26,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
26,
966,
257,
6927,
13,
614,
13,
1165,
6927,
13,
614,
13,
1479,
755,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
24929,
63,
15386,
63,
12375,
275,
13146,
51,
63,
24929,
63,
2826,
63,
15386,
63,
12375,
435,
9638,
199,
15386,
37,
13293,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
624,
272,
13146,
51,
63,
24929,
63,
15386,
63,
13003,
275,
9638,
199,
409,
280,
1237,
65,
5053,
287,
280,
289,
6796,
608,
12864,
15923,
450,
6559,
15923,
199,
7280,
26,
966,
260,
499,
755,
499,
221,
413,
2010,
14,
383,
221,
2948,
14,
383,
5,
199,
15386,
37,
3515,
499,
755,
499,
221,
413,
2010,
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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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
] |
jcoady9/python-for-android
|
python3-alpha/python3-src/Lib/ctypes/test/test_pointers.py
|
53
|
6273
|
import unittest, sys
from ctypes import *
import _ctypes_test
ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float]
python_types = [int, int, int, int, int, int,
int, int, int, int, float, float]
class PointersTestCase(unittest.TestCase):
def test_pointer_crash(self):
class A(POINTER(c_ulong)):
pass
POINTER(c_ulong)(c_ulong(22))
# Pointer can't set contents: has no _type_
self.assertRaises(TypeError, A, c_ulong(33))
def test_pass_pointers(self):
dll = CDLL(_ctypes_test.__file__)
func = dll._testfunc_p_p
func.restype = c_long
i = c_int(12345678)
## func.argtypes = (POINTER(c_int),)
address = func(byref(i))
self.assertEqual(c_int.from_address(address).value, 12345678)
func.restype = POINTER(c_int)
res = func(pointer(i))
self.assertEqual(res.contents.value, 12345678)
self.assertEqual(res[0], 12345678)
def test_change_pointers(self):
dll = CDLL(_ctypes_test.__file__)
func = dll._testfunc_p_p
i = c_int(87654)
func.restype = POINTER(c_int)
func.argtypes = (POINTER(c_int),)
res = func(pointer(i))
self.assertEqual(res[0], 87654)
self.assertEqual(res.contents.value, 87654)
# C code: *res = 54345
res[0] = 54345
self.assertEqual(i.value, 54345)
# C code:
# int x = 12321;
# res = &x
res.contents = c_int(12321)
self.assertEqual(i.value, 54345)
def test_callbacks_with_pointers(self):
# a function type receiving a pointer
PROTOTYPE = CFUNCTYPE(c_int, POINTER(c_int))
self.result = []
def func(arg):
for i in range(10):
## print arg[i],
self.result.append(arg[i])
## print
return 0
callback = PROTOTYPE(func)
dll = CDLL(_ctypes_test.__file__)
# This function expects a function pointer,
# and calls this with an integer pointer as parameter.
# The int pointer points to a table containing the numbers 1..10
doit = dll._testfunc_callback_with_pointer
## i = c_int(42)
## callback(byref(i))
## self.assertTrue(i.value == 84)
doit(callback)
## print self.result
doit(callback)
## print self.result
def test_basics(self):
from operator import delitem
for ct, pt in zip(ctype_types, python_types):
i = ct(42)
p = pointer(i)
## print type(p.contents), ct
self.assertTrue(type(p.contents) is ct)
# p.contents is the same as p[0]
## print p.contents
## self.assertTrue(p.contents == 42)
## self.assertTrue(p[0] == 42)
self.assertRaises(TypeError, delitem, p, 0)
def test_from_address(self):
from array import array
a = array('i', [100, 200, 300, 400, 500])
addr = a.buffer_info()[0]
p = POINTER(POINTER(c_int))
## print dir(p)
## print p.from_address
## print p.from_address(addr)[0][0]
def test_other(self):
class Table(Structure):
_fields_ = [("a", c_int),
("b", c_int),
("c", c_int)]
pt = pointer(Table(1, 2, 3))
self.assertEqual(pt.contents.a, 1)
self.assertEqual(pt.contents.b, 2)
self.assertEqual(pt.contents.c, 3)
pt.contents.c = 33
from ctypes import _pointer_type_cache
del _pointer_type_cache[Table]
def test_basic(self):
p = pointer(c_int(42))
# Although a pointer can be indexed, it ha no length
self.assertRaises(TypeError, len, p)
self.assertEqual(p[0], 42)
self.assertEqual(p.contents.value, 42)
def test_charpp(self):
"""Test that a character pointer-to-pointer is correctly passed"""
dll = CDLL(_ctypes_test.__file__)
func = dll._testfunc_c_p_p
func.restype = c_char_p
argv = (c_char_p * 2)()
argc = c_int( 2 )
argv[0] = b'hello'
argv[1] = b'world'
result = func( byref(argc), argv )
self.assertEqual(result, b'world')
def test_bug_1467852(self):
# http://sourceforge.net/tracker/?func=detail&atid=532154&aid=1467852&group_id=71702
x = c_int(5)
dummy = []
for i in range(32000):
dummy.append(c_int(i))
y = c_int(6)
p = pointer(x)
pp = pointer(p)
q = pointer(y)
pp[0] = q # <==
self.assertEqual(p[0], 6)
def test_c_void_p(self):
# http://sourceforge.net/tracker/?func=detail&aid=1518190&group_id=5470&atid=105470
if sizeof(c_void_p) == 4:
self.assertEqual(c_void_p(0xFFFFFFFF).value,
c_void_p(-1).value)
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value,
c_void_p(-1).value)
elif sizeof(c_void_p) == 8:
self.assertEqual(c_void_p(0xFFFFFFFF).value,
0xFFFFFFFF)
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFF).value,
c_void_p(-1).value)
self.assertEqual(c_void_p(0xFFFFFFFFFFFFFFFFFFFFFFFF).value,
c_void_p(-1).value)
self.assertRaises(TypeError, c_void_p, 3.14) # make sure floats are NOT accepted
self.assertRaises(TypeError, c_void_p, object()) # nor other objects
def test_pointers_bool(self):
# NULL pointers have a boolean False value, non-NULL pointers True.
self.assertEqual(bool(POINTER(c_int)()), False)
self.assertEqual(bool(pointer(c_int())), True)
self.assertEqual(bool(CFUNCTYPE(None)(0)), False)
self.assertEqual(bool(CFUNCTYPE(None)(42)), True)
# COM methods are boolean True:
if sys.platform == "win32":
mth = WINFUNCTYPE(None)(42, "name", (), None)
self.assertEqual(bool(mth), True)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
646,
2882,
12,
984,
199,
199,
504,
5577,
492,
627,
199,
646,
485,
9798,
63,
396,
199,
199,
3667,
63,
1313,
275,
359,
67,
63,
4414,
12,
286,
63,
20790,
12,
286,
63,
3612,
12,
286,
63,
27170,
12,
286,
63,
442,
12,
286,
63,
1635,
12,
326,
286,
63,
2809,
12,
286,
63,
15688,
12,
286,
63,
2809,
2809,
12,
286,
63,
32020,
12,
286,
63,
3157,
12,
286,
63,
1609,
61,
199,
1548,
63,
1313,
275,
359,
442,
12,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
355,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
2069,
12,
2069,
61,
199,
199,
533,
4376,
11005,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
3929,
63,
14807,
8,
277,
304,
398,
1021,
437,
8,
11260,
8,
67,
63,
15688,
2298,
288,
986,
398,
6569,
8,
67,
63,
15688,
5130,
67,
63,
15688,
8,
1081,
430,
267,
327,
28833,
883,
1133,
663,
4072,
26,
965,
949,
485,
466,
63,
267,
291,
14,
1855,
8,
4333,
12,
437,
12,
286,
63,
15688,
8,
1153,
430,
339,
347,
511,
63,
1529,
63,
555,
11005,
8,
277,
304,
267,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
2562,
275,
17112,
423,
396,
1532,
63,
80,
63,
80,
267,
2562,
14,
9990,
275,
286,
63,
2809,
398,
284,
275,
286,
63,
442,
8,
19542,
9,
199,
309,
263,
2562,
14,
10025,
275,
334,
11260,
8,
67,
63,
442,
16945,
267,
2287,
275,
2562,
8,
20447,
8,
73,
430,
267,
291,
14,
629,
8,
67,
63,
442,
14,
504,
63,
1562,
8,
1562,
680,
585,
12,
14763,
12970,
9,
398,
2562,
14,
9990,
275,
6569,
8,
67,
63,
442,
9,
267,
522,
275,
2562,
8,
3929,
8,
73,
430,
267,
291,
14,
629,
8,
470,
14,
4407,
14,
585,
12,
14763,
12970,
9,
267,
291,
14,
629,
8,
470,
59,
16,
467,
14763,
12970,
9,
339,
347,
511,
63,
1461,
63,
555,
11005,
8,
277,
304,
267,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
2562,
275,
17112,
423,
396,
1532,
63,
80,
63,
80,
398,
284,
275,
286,
63,
442,
8,
1555,
11157,
9,
267,
2562,
14,
9990,
275,
6569,
8,
67,
63,
442,
9,
267,
2562,
14,
10025,
275,
334,
11260,
8,
67,
63,
442,
16945,
398,
522,
275,
2562,
8,
3929,
8,
73,
430,
267,
291,
14,
629,
8,
470,
59,
16,
467,
10513,
11157,
9,
267,
291,
14,
629,
8,
470,
14,
4407,
14,
585,
12,
10513,
11157,
9,
398,
327,
445,
1233,
26,
627,
470,
275,
13470,
9908,
267,
522,
59,
16,
61,
275,
13470,
9908,
267,
291,
14,
629,
8,
73,
14,
585,
12,
13470,
9908,
9,
398,
327,
445,
1233,
26,
267,
327,
257,
1109,
671,
275,
3144,
12638,
27,
267,
327,
257,
522,
275,
1253,
88,
267,
522,
14,
4407,
275,
286,
63,
442,
8,
713,
12638,
9,
267,
291,
14,
629,
8,
73,
14,
585,
12,
13470,
9908,
9,
339,
347,
511,
63,
11948,
63,
1045,
63,
555,
11005,
8,
277,
304,
267,
327,
282,
805,
730,
18390,
282,
7849,
267,
3611,
14261,
4948,
275,
11093,
8,
67,
63,
442,
12,
6569,
8,
67,
63,
442,
430,
398,
291,
14,
1099,
275,
942,
398,
347,
2562,
8,
1273,
304,
288,
367,
284,
315,
1425,
8,
709,
304,
199,
309,
4483,
870,
1680,
59,
73,
467,
355,
291,
14,
1099,
14,
740,
8,
1273,
59,
73,
566,
199,
309,
3322,
870,
288,
372,
378,
267,
3233,
275,
3611,
14261,
4948,
8,
1532,
9,
398,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
327,
961,
805,
14292,
282,
805,
7849,
12,
267,
327,
436,
4882,
642,
543,
376,
3000,
7849,
465,
2725,
14,
267,
327,
710,
1109,
7849,
4501,
370,
282,
1817,
3035,
314,
5579,
413,
703,
709,
267,
886,
390,
275,
17112,
423,
396,
1532,
63,
3058,
63,
1045,
63,
3929,
199,
199,
309,
263,
284,
275,
286,
63,
442,
8,
2260,
9,
199,
309,
263,
3233,
8,
20447,
8,
73,
430,
199,
309,
263,
291,
14,
1815,
8,
73,
14,
585,
508,
8264,
9,
398,
886,
390,
8,
3058,
9,
199,
309,
263,
870,
291,
14,
1099,
267,
886,
390,
8,
3058,
9,
199,
309,
263,
870,
291,
14,
1099,
339,
347,
511,
63,
4316,
83,
8,
277,
304,
267,
687,
4182,
492,
9122,
563,
267,
367,
9428,
12,
10063,
315,
3482,
8,
3667,
63,
1313,
12,
2366,
63,
1313,
304,
288,
284,
275,
9428,
8,
2260,
9,
288,
299,
275,
7849,
8,
73,
9,
199,
309,
3322,
870,
730,
8,
80,
14,
4407,
395,
9428,
288,
291,
14,
1815,
8,
466,
8,
80,
14,
4407,
9,
365,
9428,
9,
288,
327,
299,
14,
4407,
365,
314,
2011,
465,
299,
59,
16,
61,
199,
309,
3322,
870,
299,
14,
4407,
199,
309,
3322,
291,
14,
1815,
8,
80,
14,
4407,
508,
5685,
9,
199,
309,
3322,
291,
14,
1815,
8,
80,
59,
16,
61,
508,
5685,
9,
953,
291,
14,
1855,
8,
4333,
12,
9122,
563,
12,
299,
12,
378,
9,
339,
347,
511,
63,
504,
63,
1562,
8,
277,
304,
267,
687,
1625,
492,
1625,
267,
282,
275,
1625,
360,
73,
297,
359,
1960,
12,
1926,
12,
9601,
12,
8290,
12,
6891,
566,
267,
5552,
275,
282,
14,
2738,
63,
815,
3430,
16,
61,
398,
299,
275,
6569,
8,
11260,
8,
67,
63,
442,
430,
199,
309,
263,
870,
2935,
8,
80,
9,
199,
309,
263,
870,
299,
14,
504,
63,
1562,
199,
309,
263,
870,
299,
14,
504,
63,
1562,
8,
2697,
2788,
16,
1527,
16,
61,
339,
347,
511,
63,
1848,
8,
277,
304,
267,
1021,
6957,
8,
10766,
304,
288,
485,
955,
63,
275,
10003,
65,
401,
286,
63,
442,
395,
717,
1689,
66,
401,
286,
63,
442,
395,
717,
1689,
67,
401,
286,
63,
442,
1874,
398,
10063,
275,
7849,
8,
3186,
8,
17,
12,
499,
12,
650,
430,
398,
291,
14,
629,
8,
541,
14,
4407,
14,
65,
12,
413,
9,
267,
291,
14,
629,
8,
541,
14,
4407,
14,
66,
12,
499,
9,
267,
291,
14,
629,
8,
541,
14,
4407,
14,
67,
12,
650,
9,
398
] |
[
2882,
12,
984,
199,
199,
504,
5577,
492,
627,
199,
646,
485,
9798,
63,
396,
199,
199,
3667,
63,
1313,
275,
359,
67,
63,
4414,
12,
286,
63,
20790,
12,
286,
63,
3612,
12,
286,
63,
27170,
12,
286,
63,
442,
12,
286,
63,
1635,
12,
326,
286,
63,
2809,
12,
286,
63,
15688,
12,
286,
63,
2809,
2809,
12,
286,
63,
32020,
12,
286,
63,
3157,
12,
286,
63,
1609,
61,
199,
1548,
63,
1313,
275,
359,
442,
12,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
355,
1109,
12,
1109,
12,
1109,
12,
1109,
12,
2069,
12,
2069,
61,
199,
199,
533,
4376,
11005,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
3929,
63,
14807,
8,
277,
304,
398,
1021,
437,
8,
11260,
8,
67,
63,
15688,
2298,
288,
986,
398,
6569,
8,
67,
63,
15688,
5130,
67,
63,
15688,
8,
1081,
430,
267,
327,
28833,
883,
1133,
663,
4072,
26,
965,
949,
485,
466,
63,
267,
291,
14,
1855,
8,
4333,
12,
437,
12,
286,
63,
15688,
8,
1153,
430,
339,
347,
511,
63,
1529,
63,
555,
11005,
8,
277,
304,
267,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
2562,
275,
17112,
423,
396,
1532,
63,
80,
63,
80,
267,
2562,
14,
9990,
275,
286,
63,
2809,
398,
284,
275,
286,
63,
442,
8,
19542,
9,
199,
309,
263,
2562,
14,
10025,
275,
334,
11260,
8,
67,
63,
442,
16945,
267,
2287,
275,
2562,
8,
20447,
8,
73,
430,
267,
291,
14,
629,
8,
67,
63,
442,
14,
504,
63,
1562,
8,
1562,
680,
585,
12,
14763,
12970,
9,
398,
2562,
14,
9990,
275,
6569,
8,
67,
63,
442,
9,
267,
522,
275,
2562,
8,
3929,
8,
73,
430,
267,
291,
14,
629,
8,
470,
14,
4407,
14,
585,
12,
14763,
12970,
9,
267,
291,
14,
629,
8,
470,
59,
16,
467,
14763,
12970,
9,
339,
347,
511,
63,
1461,
63,
555,
11005,
8,
277,
304,
267,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
2562,
275,
17112,
423,
396,
1532,
63,
80,
63,
80,
398,
284,
275,
286,
63,
442,
8,
1555,
11157,
9,
267,
2562,
14,
9990,
275,
6569,
8,
67,
63,
442,
9,
267,
2562,
14,
10025,
275,
334,
11260,
8,
67,
63,
442,
16945,
398,
522,
275,
2562,
8,
3929,
8,
73,
430,
267,
291,
14,
629,
8,
470,
59,
16,
467,
10513,
11157,
9,
267,
291,
14,
629,
8,
470,
14,
4407,
14,
585,
12,
10513,
11157,
9,
398,
327,
445,
1233,
26,
627,
470,
275,
13470,
9908,
267,
522,
59,
16,
61,
275,
13470,
9908,
267,
291,
14,
629,
8,
73,
14,
585,
12,
13470,
9908,
9,
398,
327,
445,
1233,
26,
267,
327,
257,
1109,
671,
275,
3144,
12638,
27,
267,
327,
257,
522,
275,
1253,
88,
267,
522,
14,
4407,
275,
286,
63,
442,
8,
713,
12638,
9,
267,
291,
14,
629,
8,
73,
14,
585,
12,
13470,
9908,
9,
339,
347,
511,
63,
11948,
63,
1045,
63,
555,
11005,
8,
277,
304,
267,
327,
282,
805,
730,
18390,
282,
7849,
267,
3611,
14261,
4948,
275,
11093,
8,
67,
63,
442,
12,
6569,
8,
67,
63,
442,
430,
398,
291,
14,
1099,
275,
942,
398,
347,
2562,
8,
1273,
304,
288,
367,
284,
315,
1425,
8,
709,
304,
199,
309,
4483,
870,
1680,
59,
73,
467,
355,
291,
14,
1099,
14,
740,
8,
1273,
59,
73,
566,
199,
309,
3322,
870,
288,
372,
378,
267,
3233,
275,
3611,
14261,
4948,
8,
1532,
9,
398,
17112,
275,
445,
15982,
1547,
9798,
63,
396,
855,
493,
3368,
267,
327,
961,
805,
14292,
282,
805,
7849,
12,
267,
327,
436,
4882,
642,
543,
376,
3000,
7849,
465,
2725,
14,
267,
327,
710,
1109,
7849,
4501,
370,
282,
1817,
3035,
314,
5579,
413,
703,
709,
267,
886,
390,
275,
17112,
423,
396,
1532,
63,
3058,
63,
1045,
63,
3929,
199,
199,
309,
263,
284,
275,
286,
63,
442,
8,
2260,
9,
199,
309,
263,
3233,
8,
20447,
8,
73,
430,
199,
309,
263,
291,
14,
1815,
8,
73,
14,
585,
508,
8264,
9,
398,
886,
390,
8,
3058,
9,
199,
309,
263,
870,
291,
14,
1099,
267,
886,
390,
8,
3058,
9,
199,
309,
263,
870,
291,
14,
1099,
339,
347,
511,
63,
4316,
83,
8,
277,
304,
267,
687,
4182,
492,
9122,
563,
267,
367,
9428,
12,
10063,
315,
3482,
8,
3667,
63,
1313,
12,
2366,
63,
1313,
304,
288,
284,
275,
9428,
8,
2260,
9,
288,
299,
275,
7849,
8,
73,
9,
199,
309,
3322,
870,
730,
8,
80,
14,
4407,
395,
9428,
288,
291,
14,
1815,
8,
466,
8,
80,
14,
4407,
9,
365,
9428,
9,
288,
327,
299,
14,
4407,
365,
314,
2011,
465,
299,
59,
16,
61,
199,
309,
3322,
870,
299,
14,
4407,
199,
309,
3322,
291,
14,
1815,
8,
80,
14,
4407,
508,
5685,
9,
199,
309,
3322,
291,
14,
1815,
8,
80,
59,
16,
61,
508,
5685,
9,
953,
291,
14,
1855,
8,
4333,
12,
9122,
563,
12,
299,
12,
378,
9,
339,
347,
511,
63,
504,
63,
1562,
8,
277,
304,
267,
687,
1625,
492,
1625,
267,
282,
275,
1625,
360,
73,
297,
359,
1960,
12,
1926,
12,
9601,
12,
8290,
12,
6891,
566,
267,
5552,
275,
282,
14,
2738,
63,
815,
3430,
16,
61,
398,
299,
275,
6569,
8,
11260,
8,
67,
63,
442,
430,
199,
309,
263,
870,
2935,
8,
80,
9,
199,
309,
263,
870,
299,
14,
504,
63,
1562,
199,
309,
263,
870,
299,
14,
504,
63,
1562,
8,
2697,
2788,
16,
1527,
16,
61,
339,
347,
511,
63,
1848,
8,
277,
304,
267,
1021,
6957,
8,
10766,
304,
288,
485,
955,
63,
275,
10003,
65,
401,
286,
63,
442,
395,
717,
1689,
66,
401,
286,
63,
442,
395,
717,
1689,
67,
401,
286,
63,
442,
1874,
398,
10063,
275,
7849,
8,
3186,
8,
17,
12,
499,
12,
650,
430,
398,
291,
14,
629,
8,
541,
14,
4407,
14,
65,
12,
413,
9,
267,
291,
14,
629,
8,
541,
14,
4407,
14,
66,
12,
499,
9,
267,
291,
14,
629,
8,
541,
14,
4407,
14,
67,
12,
650,
9,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
zasdfgbnm/qutip
|
qutip/testing.py
|
1
|
2011
|
# This file is part of QuTiP: Quantum Toolbox in Python.
#
# Copyright (c) 2011 and later, Paul D. Nation and Robert J. Johansson.
# 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 QuTiP: Quantum Toolbox in Python 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
# 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.
###############################################################################
def run():
"""
Run the nose test scripts for QuTiP.
"""
import nose
# runs tests in qutip.tests module only
nose.run(defaultTest="qutip.tests", argv=['nosetests', '-v'])
|
bsd-3-clause
|
[
3,
961,
570,
365,
1777,
402,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
14,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
436,
2945,
12,
28574,
577,
14,
653,
425,
436,
6848,
12504,
1603,
14,
7135,
19262,
385,
265,
14,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
259,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
259,
7647,
26,
199,
3,
199,
3,
259,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
755,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
259,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
259,
650,
14,
11443,
314,
536,
402,
314,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
6590,
314,
1561,
199,
3,
755,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
259,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
259,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
199,
3,
259,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
259,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
259,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
259,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
259,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
259,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
259,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
11490,
421,
199,
318,
1255,
837,
272,
408,
272,
3378,
314,
11354,
511,
10554,
367,
5843,
22731,
48,
14,
272,
408,
272,
492,
11354,
272,
327,
7858,
2295,
315,
2173,
8996,
14,
2219,
859,
1454,
272,
11354,
14,
1065,
8,
885,
774,
628,
392,
8996,
14,
2219,
401,
9238,
2968,
21085,
2219,
297,
2475,
86,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1777,
402,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
14,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
436,
2945,
12,
28574,
577,
14,
653,
425,
436,
6848,
12504,
1603,
14,
7135,
19262,
385,
265,
14,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
259,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
259,
7647,
26,
199,
3,
199,
3,
259,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
755,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
259,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
259,
650,
14,
11443,
314,
536,
402,
314,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
6590,
314,
1561,
199,
3,
755,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
259,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
259,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
199,
3,
259,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
259,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
259,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
259,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
259,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
259,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
259,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
11490,
421,
199,
318,
1255,
837,
272,
408,
272,
3378,
314,
11354,
511,
10554,
367,
5843,
22731,
48,
14,
272,
408,
272,
492,
11354,
272,
327,
7858,
2295,
315,
2173,
8996,
14,
2219,
859,
1454,
272,
11354,
14,
1065,
8,
885,
774,
628,
392,
8996,
14,
2219,
401,
9238,
2968,
21085,
2219,
297,
2475,
86,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
1tush/reviewboard
|
reviewboard/webapi/resources/original_file.py
|
1
|
1231
|
from __future__ import unicode_literals
from django.core.exceptions import ObjectDoesNotExist
from djblets.webapi.errors import DOES_NOT_EXIST
from reviewboard.webapi.resources import resources
from reviewboard.webapi.resources.base_original_file import \
BaseOriginalFileResource
class OriginalFileResource(BaseOriginalFileResource):
"""Provides the unpatched file corresponding to a file diff."""
name = 'original_file'
def get_filediff(self, request, *args, **kwargs):
"""Returns the FileDiff, or an error, for the given parameters."""
review_request_resource = resources.review_request
try:
review_request = review_request_resource.get_object(
request, *args, **kwargs)
except ObjectDoesNotExist:
return DOES_NOT_EXIST
if not review_request_resource.has_access_permissions(request,
review_request):
return self._no_access_error(request.user)
try:
return resources.filediff.get_object(request, *args, **kwargs)
except ObjectDoesNotExist:
return DOES_NOT_EXIST
original_file_resource = OriginalFileResource()
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
366,
74,
830,
1086,
14,
2520,
1246,
14,
2550,
492,
3506,
654,
63,
4609,
63,
13301,
199,
199,
504,
11248,
3576,
14,
2520,
1246,
14,
4435,
492,
5944,
199,
504,
11248,
3576,
14,
2520,
1246,
14,
4435,
14,
1095,
63,
5043,
63,
493,
492,
971,
272,
3523,
17286,
1173,
4031,
421,
199,
533,
12769,
1173,
4031,
8,
1563,
17286,
1173,
4031,
304,
272,
408,
17473,
314,
625,
22631,
570,
5226,
370,
282,
570,
3915,
1041,
272,
536,
275,
283,
5043,
63,
493,
7,
339,
347,
664,
63,
493,
3028,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
3407,
314,
3814,
10746,
12,
503,
376,
1125,
12,
367,
314,
1627,
2633,
1041,
267,
11248,
63,
1069,
63,
1927,
275,
5944,
14,
8578,
63,
1069,
398,
862,
26,
288,
11248,
63,
1069,
275,
11248,
63,
1069,
63,
1927,
14,
362,
63,
785,
8,
355,
1056,
12,
627,
589,
12,
1011,
958,
9,
267,
871,
24803,
26,
288,
372,
3506,
654,
63,
4609,
63,
13301,
398,
340,
440,
11248,
63,
1069,
63,
1927,
14,
1989,
63,
2732,
63,
6060,
8,
1069,
12,
16854,
11248,
63,
1069,
304,
288,
372,
291,
423,
889,
63,
2732,
63,
705,
8,
1069,
14,
751,
9,
398,
862,
26,
288,
372,
5944,
14,
493,
3028,
14,
362,
63,
785,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
871,
24803,
26,
288,
372,
3506,
654,
63,
4609,
63,
13301,
421,
199,
5043,
63,
493,
63,
1927,
275,
12769,
1173,
4031,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
366,
74,
830,
1086,
14,
2520,
1246,
14,
2550,
492,
3506,
654,
63,
4609,
63,
13301,
199,
199,
504,
11248,
3576,
14,
2520,
1246,
14,
4435,
492,
5944,
199,
504,
11248,
3576,
14,
2520,
1246,
14,
4435,
14,
1095,
63,
5043,
63,
493,
492,
971,
272,
3523,
17286,
1173,
4031,
421,
199,
533,
12769,
1173,
4031,
8,
1563,
17286,
1173,
4031,
304,
272,
408,
17473,
314,
625,
22631,
570,
5226,
370,
282,
570,
3915,
1041,
272,
536,
275,
283,
5043,
63,
493,
7,
339,
347,
664,
63,
493,
3028,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
3407,
314,
3814,
10746,
12,
503,
376,
1125,
12,
367,
314,
1627,
2633,
1041,
267,
11248,
63,
1069,
63,
1927,
275,
5944,
14,
8578,
63,
1069,
398,
862,
26,
288,
11248,
63,
1069,
275,
11248,
63,
1069,
63,
1927,
14,
362,
63,
785,
8,
355,
1056,
12,
627,
589,
12,
1011,
958,
9,
267,
871,
24803,
26,
288,
372,
3506,
654,
63,
4609,
63,
13301,
398,
340,
440,
11248,
63,
1069,
63,
1927,
14,
1989,
63,
2732,
63,
6060,
8,
1069,
12,
16854,
11248,
63,
1069,
304,
288,
372,
291,
423,
889,
63,
2732,
63,
705,
8,
1069,
14,
751,
9,
398,
862,
26,
288,
372,
5944,
14,
493,
3028,
14,
362,
63,
785,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
871,
24803,
26,
288,
372,
3506,
654,
63,
4609,
63,
13301,
421,
199,
5043,
63,
493,
63,
1927,
275,
12769,
1173,
4031,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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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
] |
ff94315/hiwifi-openwrt-HC5661-HC5761
|
staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/python2.7/logging/__init__.py
|
27
|
59975
|
# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Logging package for Python. Based on PEP 282 and comments thereto in
comp.lang.python, and influenced by Apache's log4j system.
Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
import sys, os, time, cStringIO, traceback, warnings, weakref
__all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO',
'LogRecord', 'Logger', 'LoggerAdapter', 'NOTSET', 'NullHandler',
'StreamHandler', 'WARN', 'WARNING', 'addLevelName', 'basicConfig',
'captureWarnings', 'critical', 'debug', 'disable', 'error',
'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass',
'info', 'log', 'makeLogRecord', 'setLoggerClass', 'warn', 'warning']
try:
import codecs
except ImportError:
codecs = None
try:
import thread
import threading
except ImportError:
thread = None
__author__ = "Vinay Sajip <vinay_sajip@red-dove.com>"
__status__ = "production"
__version__ = "0.5.1.2"
__date__ = "07 February 2010"
#---------------------------------------------------------------------------
# Miscellaneous module data
#---------------------------------------------------------------------------
try:
unicode
_unicode = True
except NameError:
_unicode = False
#
# _srcfile is used when walking the stack to check when we've got the first
# caller stack frame.
#
if hasattr(sys, 'frozen'): #support for py2exe
_srcfile = "logging%s__init__%s" % (os.sep, __file__[-4:])
elif __file__[-4:].lower() in ['.pyc', '.pyo']:
_srcfile = __file__[:-4] + '.py'
else:
_srcfile = __file__
_srcfile = os.path.normcase(_srcfile)
# next bit filched from 1.5.2's inspect.py
def currentframe():
"""Return the frame object for the caller's stack frame."""
try:
raise Exception
except:
return sys.exc_info()[2].tb_frame.f_back
if hasattr(sys, '_getframe'): currentframe = lambda: sys._getframe(3)
# done filching
# _srcfile is only used in conjunction with sys._getframe().
# To provide compatibility with older versions of Python, set _srcfile
# to None if _getframe() is not available; this value will prevent
# findCaller() from being called.
#if not hasattr(sys, "_getframe"):
# _srcfile = None
#
#_startTime is used as the base when calculating the relative time of events
#
_startTime = time.time()
#
#raiseExceptions is used to see if exceptions during handling should be
#propagated
#
raiseExceptions = 1
#
# If you don't want threading information in the log, set this to zero
#
logThreads = 1
#
# If you don't want multiprocessing information in the log, set this to zero
#
logMultiprocessing = 1
#
# If you don't want process information in the log, set this to zero
#
logProcesses = 1
#---------------------------------------------------------------------------
# Level related stuff
#---------------------------------------------------------------------------
#
# Default levels and level names, these can be replaced with any positive set
# of values having corresponding names. There is a pseudo-level, NOTSET, which
# is only really there as a lower limit for user-defined levels. Handlers and
# loggers are initialized with NOTSET so that they will log all messages, even
# at user-defined levels.
#
CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0
_levelNames = {
CRITICAL : 'CRITICAL',
ERROR : 'ERROR',
WARNING : 'WARNING',
INFO : 'INFO',
DEBUG : 'DEBUG',
NOTSET : 'NOTSET',
'CRITICAL' : CRITICAL,
'ERROR' : ERROR,
'WARN' : WARNING,
'WARNING' : WARNING,
'INFO' : INFO,
'DEBUG' : DEBUG,
'NOTSET' : NOTSET,
}
def getLevelName(level):
"""
Return the textual representation of logging level 'level'.
If the level is one of the predefined levels (CRITICAL, ERROR, WARNING,
INFO, DEBUG) then you get the corresponding string. If you have
associated levels with names using addLevelName then the name you have
associated with 'level' is returned.
If a numeric value corresponding to one of the defined levels is passed
in, the corresponding string representation is returned.
Otherwise, the string "Level %s" % level is returned.
"""
return _levelNames.get(level, ("Level %s" % level))
def addLevelName(level, levelName):
"""
Associate 'levelName' with 'level'.
This is used when converting levels to text during message formatting.
"""
_acquireLock()
try: #unlikely to cause an exception, but you never know...
_levelNames[level] = levelName
_levelNames[levelName] = level
finally:
_releaseLock()
def _checkLevel(level):
if isinstance(level, int):
rv = level
elif str(level) == level:
if level not in _levelNames:
raise ValueError("Unknown level: %r" % level)
rv = _levelNames[level]
else:
raise TypeError("Level not an integer or a valid string: %r" % level)
return rv
#---------------------------------------------------------------------------
# Thread-related stuff
#---------------------------------------------------------------------------
#
#_lock is used to serialize access to shared data structures in this module.
#This needs to be an RLock because fileConfig() creates and configures
#Handlers, and so might arbitrary user threads. Since Handler code updates the
#shared dictionary _handlers, it needs to acquire the lock. But if configuring,
#the lock would already have been acquired - so we need an RLock.
#The same argument applies to Loggers and Manager.loggerDict.
#
if thread:
_lock = threading.RLock()
else:
_lock = None
def _acquireLock():
"""
Acquire the module-level lock for serializing access to shared data.
This should be released with _releaseLock().
"""
if _lock:
_lock.acquire()
def _releaseLock():
"""
Release the module-level lock acquired by calling _acquireLock().
"""
if _lock:
_lock.release()
#---------------------------------------------------------------------------
# The logging record
#---------------------------------------------------------------------------
class LogRecord(object):
"""
A LogRecord instance represents an event being logged.
LogRecord instances are created every time something is logged. They
contain all the information pertinent to the event being logged. The
main information passed in is in msg and args, which are combined
using str(msg) % args to create the message field of the record. The
record also includes information such as when the record was created,
the source line where the logging call was made, and any exception
information to be logged.
"""
def __init__(self, name, level, pathname, lineno,
msg, args, exc_info, func=None):
"""
Initialize a logging record with interesting information.
"""
ct = time.time()
self.name = name
self.msg = msg
#
# The following statement allows passing of a dictionary as a sole
# argument, so that you can do something like
# logging.debug("a %(a)d b %(b)s", {'a':1, 'b':2})
# Suggested by Stefan Behnel.
# Note that without the test for args[0], we get a problem because
# during formatting, we test to see if the arg is present using
# 'if self.args:'. If the event being logged is e.g. 'Value is %d'
# and if the passed arg fails 'if self.args:' then no formatting
# is done. For example, logger.warn('Value is %d', 0) would log
# 'Value is %d' instead of 'Value is 0'.
# For the use case of passing a dictionary, this should not be a
# problem.
if args and len(args) == 1 and isinstance(args[0], dict) and args[0]:
args = args[0]
self.args = args
self.levelname = getLevelName(level)
self.levelno = level
self.pathname = pathname
try:
self.filename = os.path.basename(pathname)
self.module = os.path.splitext(self.filename)[0]
except (TypeError, ValueError, AttributeError):
self.filename = pathname
self.module = "Unknown module"
self.exc_info = exc_info
self.exc_text = None # used to cache the traceback text
self.lineno = lineno
self.funcName = func
self.created = ct
self.msecs = (ct - long(ct)) * 1000
self.relativeCreated = (self.created - _startTime) * 1000
if logThreads and thread:
self.thread = thread.get_ident()
self.threadName = threading.current_thread().name
else:
self.thread = None
self.threadName = None
if not logMultiprocessing:
self.processName = None
else:
self.processName = 'MainProcess'
mp = sys.modules.get('multiprocessing')
if mp is not None:
# Errors may occur if multiprocessing has not finished loading
# yet - e.g. if a custom import hook causes third-party code
# to run when multiprocessing calls import. See issue 8200
# for an example
try:
self.processName = mp.current_process().name
except StandardError:
pass
if logProcesses and hasattr(os, 'getpid'):
self.process = os.getpid()
else:
self.process = None
def __str__(self):
return '<LogRecord: %s, %s, %s, %s, "%s">'%(self.name, self.levelno,
self.pathname, self.lineno, self.msg)
def getMessage(self):
"""
Return the message for this LogRecord.
Return the message for this LogRecord after merging any user-supplied
arguments with the message.
"""
if not _unicode: #if no unicode support...
msg = str(self.msg)
else:
msg = self.msg
if not isinstance(msg, basestring):
try:
msg = str(self.msg)
except UnicodeError:
msg = self.msg #Defer encoding till later
if self.args:
msg = msg % self.args
return msg
def makeLogRecord(dict):
"""
Make a LogRecord whose attributes are defined by the specified dictionary,
This function is useful for converting a logging event received over
a socket connection (which is sent as a dictionary) into a LogRecord
instance.
"""
rv = LogRecord(None, None, "", 0, "", (), None, None)
rv.__dict__.update(dict)
return rv
#---------------------------------------------------------------------------
# Formatter classes and functions
#---------------------------------------------------------------------------
class Formatter(object):
"""
Formatter instances are used to convert a LogRecord to text.
Formatters need to know how a LogRecord is constructed. They are
responsible for converting a LogRecord to (usually) a string which can
be interpreted by either a human or an external system. The base Formatter
allows a formatting string to be specified. If none is supplied, the
default value of "%s(message)\\n" is used.
The Formatter can be initialized with a format string which makes use of
knowledge of the LogRecord attributes - e.g. the default value mentioned
above makes use of the fact that the user's message and arguments are pre-
formatted into a LogRecord's message attribute. Currently, the useful
attributes in a LogRecord are described by:
%(name)s Name of the logger (logging channel)
%(levelno)s Numeric logging level for the message (DEBUG, INFO,
WARNING, ERROR, CRITICAL)
%(levelname)s Text logging level for the message ("DEBUG", "INFO",
"WARNING", "ERROR", "CRITICAL")
%(pathname)s Full pathname of the source file where the logging
call was issued (if available)
%(filename)s Filename portion of pathname
%(module)s Module (name portion of filename)
%(lineno)d Source line number where the logging call was issued
(if available)
%(funcName)s Function name
%(created)f Time when the LogRecord was created (time.time()
return value)
%(asctime)s Textual time when the LogRecord was created
%(msecs)d Millisecond portion of the creation time
%(relativeCreated)d Time in milliseconds when the LogRecord was created,
relative to the time the logging module was loaded
(typically at application startup time)
%(thread)d Thread ID (if available)
%(threadName)s Thread name (if available)
%(process)d Process ID (if available)
%(message)s The result of record.getMessage(), computed just as
the record is emitted
"""
converter = time.localtime
def __init__(self, fmt=None, datefmt=None):
"""
Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a
default as described above. Allow for specialized date formatting with
the optional datefmt argument (if omitted, you get the ISO8601 format).
"""
if fmt:
self._fmt = fmt
else:
self._fmt = "%(message)s"
self.datefmt = datefmt
def formatTime(self, record, datefmt=None):
"""
Return the creation time of the specified LogRecord as formatted text.
This method should be called from format() by a formatter which
wants to make use of a formatted time. This method can be overridden
in formatters to provide for any specific requirement, but the
basic behaviour is as follows: if datefmt (a string) is specified,
it is used with time.strftime() to format the creation time of the
record. Otherwise, the ISO8601 format is used. The resulting
string is returned. This function uses a user-configurable function
to convert the creation time to a tuple. By default, time.localtime()
is used; to change this for a particular formatter instance, set the
'converter' attribute to a function with the same signature as
time.localtime() or time.gmtime(). To change it for all formatters,
for example if you want all logging times to be shown in GMT,
set the 'converter' attribute in the Formatter class.
"""
ct = self.converter(record.created)
if datefmt:
s = time.strftime(datefmt, ct)
else:
t = time.strftime("%Y-%m-%d %H:%M:%S", ct)
s = "%s,%03d" % (t, record.msecs)
return s
def formatException(self, ei):
"""
Format and return the specified exception information as a string.
This default implementation just uses
traceback.print_exception()
"""
sio = cStringIO.StringIO()
traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
s = sio.getvalue()
sio.close()
if s[-1:] == "\n":
s = s[:-1]
return s
def usesTime(self):
"""
Check if the format uses the creation time of the record.
"""
return self._fmt.find("%(asctime)") >= 0
def format(self, record):
"""
Format the specified record as text.
The record's attribute dictionary is used as the operand to a
string formatting operation which yields the returned string.
Before formatting the dictionary, a couple of preparatory steps
are carried out. The message attribute of the record is computed
using LogRecord.getMessage(). If the formatting string uses the
time (as determined by a call to usesTime(), formatTime() is
called to format the event time. If there is exception information,
it is formatted using formatException() and appended to the message.
"""
record.message = record.getMessage()
if self.usesTime():
record.asctime = self.formatTime(record, self.datefmt)
s = self._fmt % record.__dict__
if record.exc_info:
# Cache the traceback text to avoid converting it multiple times
# (it's constant anyway)
if not record.exc_text:
record.exc_text = self.formatException(record.exc_info)
if record.exc_text:
if s[-1:] != "\n":
s = s + "\n"
try:
s = s + record.exc_text
except UnicodeError:
# Sometimes filenames have non-ASCII chars, which can lead
# to errors when s is Unicode and record.exc_text is str
# See issue 8924.
# We also use replace for when there are multiple
# encodings, e.g. UTF-8 for the filesystem and latin-1
# for a script. See issue 13232.
s = s + record.exc_text.decode(sys.getfilesystemencoding(),
'replace')
return s
#
# The default formatter to use when no other is specified
#
_defaultFormatter = Formatter()
class BufferingFormatter(object):
"""
A formatter suitable for formatting a number of records.
"""
def __init__(self, linefmt=None):
"""
Optionally specify a formatter which will be used to format each
individual record.
"""
if linefmt:
self.linefmt = linefmt
else:
self.linefmt = _defaultFormatter
def formatHeader(self, records):
"""
Return the header string for the specified records.
"""
return ""
def formatFooter(self, records):
"""
Return the footer string for the specified records.
"""
return ""
def format(self, records):
"""
Format the specified records and return the result as a string.
"""
rv = ""
if len(records) > 0:
rv = rv + self.formatHeader(records)
for record in records:
rv = rv + self.linefmt.format(record)
rv = rv + self.formatFooter(records)
return rv
#---------------------------------------------------------------------------
# Filter classes and functions
#---------------------------------------------------------------------------
class Filter(object):
"""
Filter instances are used to perform arbitrary filtering of LogRecords.
Loggers and Handlers can optionally use Filter instances to filter
records as desired. The base filter class only allows events which are
below a certain point in the logger hierarchy. For example, a filter
initialized with "A.B" will allow events logged by loggers "A.B",
"A.B.C", "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If
initialized with the empty string, all events are passed.
"""
def __init__(self, name=''):
"""
Initialize a filter.
Initialize with the name of the logger which, together with its
children, will have its events allowed through the filter. If no
name is specified, allow every event.
"""
self.name = name
self.nlen = len(name)
def filter(self, record):
"""
Determine if the specified record is to be logged.
Is the specified record to be logged? Returns 0 for no, nonzero for
yes. If deemed appropriate, the record may be modified in-place.
"""
if self.nlen == 0:
return 1
elif self.name == record.name:
return 1
elif record.name.find(self.name, 0, self.nlen) != 0:
return 0
return (record.name[self.nlen] == ".")
class Filterer(object):
"""
A base class for loggers and handlers which allows them to share
common code.
"""
def __init__(self):
"""
Initialize the list of filters to be an empty list.
"""
self.filters = []
def addFilter(self, filter):
"""
Add the specified filter to this handler.
"""
if not (filter in self.filters):
self.filters.append(filter)
def removeFilter(self, filter):
"""
Remove the specified filter from this handler.
"""
if filter in self.filters:
self.filters.remove(filter)
def filter(self, record):
"""
Determine if a record is loggable by consulting all the filters.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
"""
rv = 1
for f in self.filters:
if not f.filter(record):
rv = 0
break
return rv
#---------------------------------------------------------------------------
# Handler classes and functions
#---------------------------------------------------------------------------
_handlers = weakref.WeakValueDictionary() #map of handler names to handlers
_handlerList = [] # added to allow handlers to be removed in reverse of order initialized
def _removeHandlerRef(wr):
"""
Remove a handler reference from the internal cleanup list.
"""
# This function can be called during module teardown, when globals are
# set to None. If _acquireLock is None, assume this is the case and do
# nothing.
if _acquireLock is not None:
_acquireLock()
try:
if wr in _handlerList:
_handlerList.remove(wr)
finally:
_releaseLock()
def _addHandlerRef(handler):
"""
Add a handler to the internal cleanup list using a weak reference.
"""
_acquireLock()
try:
_handlerList.append(weakref.ref(handler, _removeHandlerRef))
finally:
_releaseLock()
class Handler(Filterer):
"""
Handler instances dispatch logging events to specific destinations.
The base handler class. Acts as a placeholder which defines the Handler
interface. Handlers can optionally use Formatter instances to format
records as desired. By default, no formatter is specified; in this case,
the 'raw' message as determined by record.message is logged.
"""
def __init__(self, level=NOTSET):
"""
Initializes the instance - basically setting the formatter to None
and the filter list to empty.
"""
Filterer.__init__(self)
self._name = None
self.level = _checkLevel(level)
self.formatter = None
# Add the handler to the global _handlerList (for cleanup on shutdown)
_addHandlerRef(self)
self.createLock()
def get_name(self):
return self._name
def set_name(self, name):
_acquireLock()
try:
if self._name in _handlers:
del _handlers[self._name]
self._name = name
if name:
_handlers[name] = self
finally:
_releaseLock()
name = property(get_name, set_name)
def createLock(self):
"""
Acquire a thread lock for serializing access to the underlying I/O.
"""
if thread:
self.lock = threading.RLock()
else:
self.lock = None
def acquire(self):
"""
Acquire the I/O thread lock.
"""
if self.lock:
self.lock.acquire()
def release(self):
"""
Release the I/O thread lock.
"""
if self.lock:
self.lock.release()
def setLevel(self, level):
"""
Set the logging level of this handler.
"""
self.level = _checkLevel(level)
def format(self, record):
"""
Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
"""
if self.formatter:
fmt = self.formatter
else:
fmt = _defaultFormatter
return fmt.format(record)
def emit(self, record):
"""
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so
raises a NotImplementedError.
"""
raise NotImplementedError('emit must be implemented '
'by Handler subclasses')
def handle(self, record):
"""
Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
"""
rv = self.filter(record)
if rv:
self.acquire()
try:
self.emit(record)
finally:
self.release()
return rv
def setFormatter(self, fmt):
"""
Set the formatter for this handler.
"""
self.formatter = fmt
def flush(self):
"""
Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
"""
pass
def close(self):
"""
Tidy up any resources used by the handler.
This version removes the handler from an internal map of handlers,
_handlers, which is used for handler lookup by name. Subclasses
should ensure that this gets called from overridden close()
methods.
"""
#get the module data lock, as we're updating a shared structure.
_acquireLock()
try: #unlikely to raise an exception, but you never know...
if self._name and self._name in _handlers:
del _handlers[self._name]
finally:
_releaseLock()
def handleError(self, record):
"""
Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
"""
if raiseExceptions and sys.stderr: # see issue 13807
ei = sys.exc_info()
try:
traceback.print_exception(ei[0], ei[1], ei[2],
None, sys.stderr)
sys.stderr.write('Logged from file %s, line %s\n' % (
record.filename, record.lineno))
except IOError:
pass # see issue 5971
finally:
del ei
class StreamHandler(Handler):
"""
A handler class which writes logging records, appropriately formatted,
to a stream. Note that this class does not close the stream, as
sys.stdout or sys.stderr may be used.
"""
def __init__(self, stream=None):
"""
Initialize the handler.
If stream is not specified, sys.stderr is used.
"""
Handler.__init__(self)
if stream is None:
stream = sys.stderr
self.stream = stream
def flush(self):
"""
Flushes the stream.
"""
if self.stream and hasattr(self.stream, "flush"):
self.stream.flush()
def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
The record is then written to the stream with a trailing newline. If
exception information is present, it is formatted using
traceback.print_exception and appended to the stream. If the stream
has an 'encoding' attribute, it is used to determine how to do the
output to the stream.
"""
try:
msg = self.format(record)
stream = self.stream
fs = "%s\n"
if not _unicode: #if no unicode support...
stream.write(fs % msg)
else:
try:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None)):
ufs = fs.decode(stream.encoding)
try:
stream.write(ufs % msg)
except UnicodeEncodeError:
#Printing to terminals sometimes fails. For example,
#with an encoding of 'cp1251', the above write will
#work if written to a stream opened or wrapped by
#the codecs module, but fail when writing to a
#terminal even when the codepage is set to cp1251.
#An extra encoding step seems to be needed.
stream.write((ufs % msg).encode(stream.encoding))
else:
stream.write(fs % msg)
except UnicodeError:
stream.write(fs % msg.encode("UTF-8"))
self.flush()
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
class FileHandler(StreamHandler):
"""
A handler class which writes formatted logging records to disk files.
"""
def __init__(self, filename, mode='a', encoding=None, delay=0):
"""
Open the specified file and use it as the stream for logging.
"""
#keep the absolute path, otherwise derived classes which use this
#may come a cropper when the current directory changes
if codecs is None:
encoding = None
self.baseFilename = os.path.abspath(filename)
self.mode = mode
self.encoding = encoding
if delay:
#We don't open the stream, but we still need to call the
#Handler constructor to set level, formatter, lock etc.
Handler.__init__(self)
self.stream = None
else:
StreamHandler.__init__(self, self._open())
def close(self):
"""
Closes the stream.
"""
if self.stream:
self.flush()
if hasattr(self.stream, "close"):
self.stream.close()
StreamHandler.close(self)
self.stream = None
def _open(self):
"""
Open the current base file with the (original) mode and encoding.
Return the resulting stream.
"""
if self.encoding is None:
stream = open(self.baseFilename, self.mode)
else:
stream = codecs.open(self.baseFilename, self.mode, self.encoding)
return stream
def emit(self, record):
"""
Emit a record.
If the stream was not opened because 'delay' was specified in the
constructor, open it before calling the superclass's emit.
"""
if self.stream is None:
self.stream = self._open()
StreamHandler.emit(self, record)
#---------------------------------------------------------------------------
# Manager classes and functions
#---------------------------------------------------------------------------
class PlaceHolder(object):
"""
PlaceHolder instances are used in the Manager logger hierarchy to take
the place of nodes for which no loggers have been defined. This class is
intended for internal use only and not as part of the public API.
"""
def __init__(self, alogger):
"""
Initialize with the specified logger being a child of this placeholder.
"""
#self.loggers = [alogger]
self.loggerMap = { alogger : None }
def append(self, alogger):
"""
Add the specified logger as a child of this placeholder.
"""
#if alogger not in self.loggers:
if alogger not in self.loggerMap:
#self.loggers.append(alogger)
self.loggerMap[alogger] = None
#
# Determine which class to use when instantiating loggers.
#
_loggerClass = None
def setLoggerClass(klass):
"""
Set the class to be used when instantiating a logger. The class should
define __init__() such that only a name argument is required, and the
__init__() should call Logger.__init__()
"""
if klass != Logger:
if not issubclass(klass, Logger):
raise TypeError("logger not derived from logging.Logger: "
+ klass.__name__)
global _loggerClass
_loggerClass = klass
def getLoggerClass():
"""
Return the class to be used when instantiating a logger.
"""
return _loggerClass
class Manager(object):
"""
There is [under normal circumstances] just one Manager instance, which
holds the hierarchy of loggers.
"""
def __init__(self, rootnode):
"""
Initialize the manager with the root node of the logger hierarchy.
"""
self.root = rootnode
self.disable = 0
self.emittedNoHandlerWarning = 0
self.loggerDict = {}
self.loggerClass = None
def getLogger(self, name):
"""
Get a logger with the specified name (channel name), creating it
if it doesn't yet exist. This name is a dot-separated hierarchical
name, such as "a", "a.b", "a.b.c" or similar.
If a PlaceHolder existed for the specified name [i.e. the logger
didn't exist but a child of it did], replace it with the created
logger and fix up the parent/child references which pointed to the
placeholder to now point to the logger.
"""
rv = None
if not isinstance(name, basestring):
raise TypeError('A logger name must be string or Unicode')
if isinstance(name, unicode):
name = name.encode('utf-8')
_acquireLock()
try:
if name in self.loggerDict:
rv = self.loggerDict[name]
if isinstance(rv, PlaceHolder):
ph = rv
rv = (self.loggerClass or _loggerClass)(name)
rv.manager = self
self.loggerDict[name] = rv
self._fixupChildren(ph, rv)
self._fixupParents(rv)
else:
rv = (self.loggerClass or _loggerClass)(name)
rv.manager = self
self.loggerDict[name] = rv
self._fixupParents(rv)
finally:
_releaseLock()
return rv
def setLoggerClass(self, klass):
"""
Set the class to be used when instantiating a logger with this Manager.
"""
if klass != Logger:
if not issubclass(klass, Logger):
raise TypeError("logger not derived from logging.Logger: "
+ klass.__name__)
self.loggerClass = klass
def _fixupParents(self, alogger):
"""
Ensure that there are either loggers or placeholders all the way
from the specified logger to the root of the logger hierarchy.
"""
name = alogger.name
i = name.rfind(".")
rv = None
while (i > 0) and not rv:
substr = name[:i]
if substr not in self.loggerDict:
self.loggerDict[substr] = PlaceHolder(alogger)
else:
obj = self.loggerDict[substr]
if isinstance(obj, Logger):
rv = obj
else:
assert isinstance(obj, PlaceHolder)
obj.append(alogger)
i = name.rfind(".", 0, i - 1)
if not rv:
rv = self.root
alogger.parent = rv
def _fixupChildren(self, ph, alogger):
"""
Ensure that children of the placeholder ph are connected to the
specified logger.
"""
name = alogger.name
namelen = len(name)
for c in ph.loggerMap.keys():
#The if means ... if not c.parent.name.startswith(nm)
if c.parent.name[:namelen] != name:
alogger.parent = c.parent
c.parent = alogger
#---------------------------------------------------------------------------
# Logger classes and functions
#---------------------------------------------------------------------------
class Logger(Filterer):
"""
Instances of the Logger class represent a single logging channel. A
"logging channel" indicates an area of an application. Exactly how an
"area" is defined is up to the application developer. Since an
application can have any number of areas, logging channels are identified
by a unique string. Application areas can be nested (e.g. an area
of "input processing" might include sub-areas "read CSV files", "read
XLS files" and "read Gnumeric files"). To cater for this natural nesting,
channel names are organized into a namespace hierarchy where levels are
separated by periods, much like the Java or Python package namespace. So
in the instance given above, channel names might be "input" for the upper
level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels.
There is no arbitrary limit to the depth of nesting.
"""
def __init__(self, name, level=NOTSET):
"""
Initialize the logger with a name and an optional level.
"""
Filterer.__init__(self)
self.name = name
self.level = _checkLevel(level)
self.parent = None
self.propagate = 1
self.handlers = []
self.disabled = 0
def setLevel(self, level):
"""
Set the logging level of this logger.
"""
self.level = _checkLevel(level)
def debug(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'DEBUG'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.debug("Houston, we have a %s", "thorny problem", exc_info=1)
"""
if self.isEnabledFor(DEBUG):
self._log(DEBUG, msg, args, **kwargs)
def info(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'INFO'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.info("Houston, we have a %s", "interesting problem", exc_info=1)
"""
if self.isEnabledFor(INFO):
self._log(INFO, msg, args, **kwargs)
def warning(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'WARNING'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.warning("Houston, we have a %s", "bit of a problem", exc_info=1)
"""
if self.isEnabledFor(WARNING):
self._log(WARNING, msg, args, **kwargs)
warn = warning
def error(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'ERROR'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.error("Houston, we have a %s", "major problem", exc_info=1)
"""
if self.isEnabledFor(ERROR):
self._log(ERROR, msg, args, **kwargs)
def exception(self, msg, *args):
"""
Convenience method for logging an ERROR with exception information.
"""
self.error(msg, exc_info=1, *args)
def critical(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'CRITICAL'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.critical("Houston, we have a %s", "major disaster", exc_info=1)
"""
if self.isEnabledFor(CRITICAL):
self._log(CRITICAL, msg, args, **kwargs)
fatal = critical
def log(self, level, msg, *args, **kwargs):
"""
Log 'msg % args' with the integer severity 'level'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.log(level, "We have a %s", "mysterious problem", exc_info=1)
"""
if not isinstance(level, int):
if raiseExceptions:
raise TypeError("level must be an integer")
else:
return
if self.isEnabledFor(level):
self._log(level, msg, args, **kwargs)
def findCaller(self):
"""
Find the stack frame of the caller so that we can note the source
file name, line number and function name.
"""
f = currentframe()
#On some versions of IronPython, currentframe() returns None if
#IronPython isn't run with -X:Frames.
if f is not None:
f = f.f_back
rv = "(unknown file)", 0, "(unknown function)"
while hasattr(f, "f_code"):
co = f.f_code
filename = os.path.normcase(co.co_filename)
if filename == _srcfile:
f = f.f_back
continue
rv = (co.co_filename, f.f_lineno, co.co_name)
break
return rv
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None):
"""
A factory method which can be overridden in subclasses to create
specialized LogRecords.
"""
rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
if extra is not None:
for key in extra:
if (key in ["message", "asctime"]) or (key in rv.__dict__):
raise KeyError("Attempt to overwrite %r in LogRecord" % key)
rv.__dict__[key] = extra[key]
return rv
def _log(self, level, msg, args, exc_info=None, extra=None):
"""
Low-level logging routine which creates a LogRecord and then calls
all the handlers of this logger to handle the record.
"""
if _srcfile:
#IronPython doesn't track Python frames, so findCaller throws an
#exception on some versions of IronPython. We trap it here so that
#IronPython can use logging.
try:
fn, lno, func = self.findCaller()
except ValueError:
fn, lno, func = "(unknown file)", 0, "(unknown function)"
else:
fn, lno, func = "(unknown file)", 0, "(unknown function)"
if exc_info:
if not isinstance(exc_info, tuple):
exc_info = sys.exc_info()
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
self.handle(record)
def handle(self, record):
"""
Call the handlers for the specified record.
This method is used for unpickled records received from a socket, as
well as those created locally. Logger-level filtering is applied.
"""
if (not self.disabled) and self.filter(record):
self.callHandlers(record)
def addHandler(self, hdlr):
"""
Add the specified handler to this logger.
"""
_acquireLock()
try:
if not (hdlr in self.handlers):
self.handlers.append(hdlr)
finally:
_releaseLock()
def removeHandler(self, hdlr):
"""
Remove the specified handler from this logger.
"""
_acquireLock()
try:
if hdlr in self.handlers:
self.handlers.remove(hdlr)
finally:
_releaseLock()
def callHandlers(self, record):
"""
Pass a record to all relevant handlers.
Loop through all handlers for this logger and its parents in the
logger hierarchy. If no handler was found, output a one-off error
message to sys.stderr. Stop searching up the hierarchy whenever a
logger with the "propagate" attribute set to zero is found - that
will be the last logger whose handlers are called.
"""
c = self
found = 0
while c:
for hdlr in c.handlers:
found = found + 1
if record.levelno >= hdlr.level:
hdlr.handle(record)
if not c.propagate:
c = None #break out
else:
c = c.parent
if (found == 0) and raiseExceptions and not self.manager.emittedNoHandlerWarning:
sys.stderr.write("No handlers could be found for logger"
" \"%s\"\n" % self.name)
self.manager.emittedNoHandlerWarning = 1
def getEffectiveLevel(self):
"""
Get the effective level for this logger.
Loop through this logger and its parents in the logger hierarchy,
looking for a non-zero logging level. Return the first one found.
"""
logger = self
while logger:
if logger.level:
return logger.level
logger = logger.parent
return NOTSET
def isEnabledFor(self, level):
"""
Is this logger enabled for level 'level'?
"""
if self.manager.disable >= level:
return 0
return level >= self.getEffectiveLevel()
def getChild(self, suffix):
"""
Get a logger which is a descendant to this one.
This is a convenience method, such that
logging.getLogger('abc').getChild('def.ghi')
is the same as
logging.getLogger('abc.def.ghi')
It's useful, for example, when the parent logger is named using
__name__ rather than a literal string.
"""
if self.root is not self:
suffix = '.'.join((self.name, suffix))
return self.manager.getLogger(suffix)
class RootLogger(Logger):
"""
A root logger is not that different to any other logger, except that
it must have a logging level and there is only one instance of it in
the hierarchy.
"""
def __init__(self, level):
"""
Initialize the logger with the name "root".
"""
Logger.__init__(self, "root", level)
_loggerClass = Logger
class LoggerAdapter(object):
"""
An adapter for loggers which makes it easier to specify contextual
information in logging output.
"""
def __init__(self, logger, extra):
"""
Initialize the adapter with a logger and a dict-like object which
provides contextual information. This constructor signature allows
easy stacking of LoggerAdapters, if so desired.
You can effectively pass keyword arguments as shown in the
following example:
adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2"))
"""
self.logger = logger
self.extra = extra
def process(self, msg, kwargs):
"""
Process the logging message and keyword arguments passed in to
a logging call to insert contextual information. You can either
manipulate the message itself, the keyword args or both. Return
the message and kwargs modified (or not) to suit your needs.
Normally, you'll only need to override this one method in a
LoggerAdapter subclass for your specific needs.
"""
kwargs["extra"] = self.extra
return msg, kwargs
def debug(self, msg, *args, **kwargs):
"""
Delegate a debug call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.debug(msg, *args, **kwargs)
def info(self, msg, *args, **kwargs):
"""
Delegate an info call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.info(msg, *args, **kwargs)
def warning(self, msg, *args, **kwargs):
"""
Delegate a warning call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.warning(msg, *args, **kwargs)
def error(self, msg, *args, **kwargs):
"""
Delegate an error call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.error(msg, *args, **kwargs)
def exception(self, msg, *args, **kwargs):
"""
Delegate an exception call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
kwargs["exc_info"] = 1
self.logger.error(msg, *args, **kwargs)
def critical(self, msg, *args, **kwargs):
"""
Delegate a critical call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.critical(msg, *args, **kwargs)
def log(self, level, msg, *args, **kwargs):
"""
Delegate a log call to the underlying logger, after adding
contextual information from this adapter instance.
"""
msg, kwargs = self.process(msg, kwargs)
self.logger.log(level, msg, *args, **kwargs)
def isEnabledFor(self, level):
"""
See if the underlying logger is enabled for the specified level.
"""
return self.logger.isEnabledFor(level)
root = RootLogger(WARNING)
Logger.root = root
Logger.manager = Manager(Logger.root)
#---------------------------------------------------------------------------
# Configuration classes and functions
#---------------------------------------------------------------------------
BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
def basicConfig(**kwargs):
"""
Do basic configuration for the logging system.
This function does nothing if the root logger already has handlers
configured. It is a convenience method intended for use by simple scripts
to do one-shot configuration of the logging package.
The default behaviour is to create a StreamHandler which writes to
sys.stderr, set a formatter using the BASIC_FORMAT format string, and
add the handler to the root logger.
A number of optional keyword arguments may be specified, which can alter
the default behaviour.
filename Specifies that a FileHandler be created, using the specified
filename, rather than a StreamHandler.
filemode Specifies the mode to open the file, if filename is specified
(if filemode is unspecified, it defaults to 'a').
format Use the specified format string for the handler.
datefmt Use the specified date/time format.
level Set the root logger level to the specified level.
stream Use the specified stream to initialize the StreamHandler. Note
that this argument is incompatible with 'filename' - if both
are present, 'stream' is ignored.
Note that you could specify a stream created using open(filename, mode)
rather than passing the filename and mode in. However, it should be
remembered that StreamHandler does not close its stream (since it may be
using sys.stdout or sys.stderr), whereas FileHandler closes its stream
when the handler is closed.
"""
# Add thread safety in case someone mistakenly calls
# basicConfig() from multiple threads
_acquireLock()
try:
if len(root.handlers) == 0:
filename = kwargs.get("filename")
if filename:
mode = kwargs.get("filemode", 'a')
hdlr = FileHandler(filename, mode)
else:
stream = kwargs.get("stream")
hdlr = StreamHandler(stream)
fs = kwargs.get("format", BASIC_FORMAT)
dfs = kwargs.get("datefmt", None)
fmt = Formatter(fs, dfs)
hdlr.setFormatter(fmt)
root.addHandler(hdlr)
level = kwargs.get("level")
if level is not None:
root.setLevel(level)
finally:
_releaseLock()
#---------------------------------------------------------------------------
# Utility functions at module level.
# Basically delegate everything to the root logger.
#---------------------------------------------------------------------------
def getLogger(name=None):
"""
Return a logger with the specified name, creating it if necessary.
If no name is specified, return the root logger.
"""
if name:
return Logger.manager.getLogger(name)
else:
return root
#def getRootLogger():
# """
# Return the root logger.
#
# Note that getLogger('') now does the same thing, so this function is
# deprecated and may disappear in the future.
# """
# return root
def critical(msg, *args, **kwargs):
"""
Log a message with severity 'CRITICAL' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.critical(msg, *args, **kwargs)
fatal = critical
def error(msg, *args, **kwargs):
"""
Log a message with severity 'ERROR' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.error(msg, *args, **kwargs)
def exception(msg, *args):
"""
Log a message with severity 'ERROR' on the root logger,
with exception information.
"""
error(msg, exc_info=1, *args)
def warning(msg, *args, **kwargs):
"""
Log a message with severity 'WARNING' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.warning(msg, *args, **kwargs)
warn = warning
def info(msg, *args, **kwargs):
"""
Log a message with severity 'INFO' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.info(msg, *args, **kwargs)
def debug(msg, *args, **kwargs):
"""
Log a message with severity 'DEBUG' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.debug(msg, *args, **kwargs)
def log(level, msg, *args, **kwargs):
"""
Log 'msg % args' with the integer severity 'level' on the root logger.
"""
if len(root.handlers) == 0:
basicConfig()
root.log(level, msg, *args, **kwargs)
def disable(level):
"""
Disable all logging calls of severity 'level' and below.
"""
root.manager.disable = level
def shutdown(handlerList=_handlerList):
"""
Perform any cleanup actions in the logging system (e.g. flushing
buffers).
Should be called at application exit.
"""
for wr in reversed(handlerList[:]):
#errors might occur, for example, if files are locked
#we just ignore them if raiseExceptions is not set
try:
h = wr()
if h:
try:
h.acquire()
h.flush()
h.close()
except (IOError, ValueError):
# Ignore errors which might be caused
# because handlers have been closed but
# references to them are still around at
# application exit.
pass
finally:
h.release()
except:
if raiseExceptions:
raise
#else, swallow
#Let's try and shutdown automatically on application exit...
import atexit
atexit.register(shutdown)
# Null handler
class NullHandler(Handler):
"""
This handler does nothing. It's intended to be used to avoid the
"No handlers could be found for logger XXX" one-off warning. This is
important for library code, which may contain code to log events. If a user
of the library does not configure logging, the one-off warning might be
produced; to avoid this, the library developer simply needs to instantiate
a NullHandler and add it to the top-level logger of the library module or
package.
"""
def handle(self, record):
pass
def emit(self, record):
pass
def createLock(self):
self.lock = None
# Warnings integration
_warnings_showwarning = None
def _showwarning(message, category, filename, lineno, file=None, line=None):
"""
Implementation of showwarnings which redirects to logging, which will first
check to see if the file parameter is None. If a file is specified, it will
delegate to the original warnings implementation of showwarning. Otherwise,
it will call warnings.formatwarning and will log the resulting string to a
warnings logger named "py.warnings" with level logging.WARNING.
"""
if file is not None:
if _warnings_showwarning is not None:
_warnings_showwarning(message, category, filename, lineno, file, line)
else:
s = warnings.formatwarning(message, category, filename, lineno, line)
logger = getLogger("py.warnings")
if not logger.handlers:
logger.addHandler(NullHandler())
logger.warning("%s", s)
def captureWarnings(capture):
"""
If capture is true, redirect all warnings to the logging package.
If capture is False, ensure that warnings are not redirected to logging
but to their original destinations.
"""
global _warnings_showwarning
if capture:
if _warnings_showwarning is None:
_warnings_showwarning = warnings.showwarning
warnings.showwarning = _showwarning
else:
if _warnings_showwarning is not None:
warnings.showwarning = _warnings_showwarning
_warnings_showwarning = None
|
gpl-2.0
|
[
3,
1898,
12521,
13,
6542,
701,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
626,
199,
3,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
199,
3,
21038,
3794,
12,
436,
626,
314,
536,
402,
28882,
1187,
428,
9091,
711,
199,
3,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
1126,
24522,
370,
4084,
199,
3,
402,
314,
2032,
1928,
2488,
12,
5313,
6791,
4983,
14,
199,
3,
812,
568,
3448,
13950,
42,
1772,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
4141,
12,
6931,
199,
3,
11727,
5292,
2990,
1634,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
199,
3,
812,
568,
3448,
13950,
42,
1772,
6262,
7024,
2381,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
199,
3,
1821,
6736,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
199,
3,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
199,
14054,
2559,
367,
2018,
14,
21311,
641,
13663,
499,
2564,
436,
6786,
2337,
475,
315,
199,
863,
14,
4159,
14,
1548,
12,
436,
315,
24585,
68,
701,
3668,
1159,
943,
20,
74,
2656,
14,
199,
199,
7384,
334,
35,
9,
12521,
13,
6542,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
199,
199,
1378,
675,
12,
9329,
283,
646,
2050,
7,
436,
943,
13437,
1,
199,
624,
199,
199,
646,
984,
12,
747,
12,
900,
12,
15073,
12,
5190,
12,
3598,
12,
13852,
199,
199,
363,
452,
363,
275,
788,
27271,
63,
4807,
297,
283,
3299,
316,
7772,
297,
283,
21539,
297,
283,
5287,
297,
283,
3170,
297,
1779,
283,
29086,
297,
283,
21982,
297,
283,
4131,
297,
283,
7772,
297,
283,
2461,
297,
283,
4531,
297,
1779,
283,
2445,
5433,
297,
283,
4455,
297,
283,
4455,
10200,
297,
283,
4609,
3597,
297,
283,
8849,
2461,
297,
1779,
283,
22482,
297,
283,
17449,
297,
283,
9171,
297,
283,
525,
4670,
985,
297,
283,
19602,
297,
1779,
283,
12685,
15921,
297,
283,
13138,
297,
283,
1757,
297,
283,
5993,
297,
283,
705,
297,
1779,
283,
1971,
297,
283,
16208,
297,
283,
362,
4670,
985,
297,
283,
5572,
297,
283,
5572,
2543,
297,
1779,
283,
815,
297,
283,
793,
297,
283,
1875,
2445,
5433,
297,
283,
409,
4455,
2543,
297,
283,
4050,
297,
283,
3764,
418,
199,
199,
893,
26,
272,
492,
6010,
199,
2590,
3545,
26,
272,
6010,
275,
488,
199,
199,
893,
26,
272,
492,
2462,
272,
492,
5796,
199,
2590,
3545,
26,
272,
2462,
275,
488,
199,
199,
363,
2502,
363,
221,
275,
298,
54,
262,
1187,
428,
9091,
711,
665,
11908,
1187,
63,
2231,
74,
711,
32,
581,
13,
1117,
432,
14,
957,
4335,
199,
363,
1205,
363,
221,
275,
298,
10777,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
21,
14,
17,
14,
18,
2,
199,
363,
602,
363,
259,
275,
298,
1780,
21141,
26709,
7129,
2,
199,
199,
7656,
13715,
199,
3,
257,
12481,
19549,
859,
666,
199,
7656,
13715,
199,
893,
26,
272,
2649,
272,
485,
2975,
275,
715,
199,
2590,
12746,
26,
272,
485,
2975,
275,
756,
199,
199,
3,
199,
3,
485,
29903,
365,
1202,
1380,
12778,
316,
314,
3464,
370,
1104,
1380,
781,
9064,
4788,
314,
1642,
199,
3,
8025,
3464,
2787,
14,
199,
3,
199,
692,
2688,
8,
1274,
12,
283,
11202,
735,
327,
4058,
367,
1134,
18,
5803,
272,
485,
29903,
275,
298,
4806,
5,
83,
363,
826,
363,
5,
83,
2,
450,
334,
736,
14,
4127,
12,
636,
493,
363,
1988,
20,
5728,
199,
4164,
636,
493,
363,
1988,
20,
11455,
2325,
342,
315,
18953,
11357,
297,
1987,
22345,
2565,
272,
485,
29903,
275,
636,
493,
363,
4439,
20,
61,
435,
1987,
647,
7,
199,
2836,
26,
272,
485,
29903,
275,
636,
493,
363,
199,
63,
29903,
275,
747,
14,
515,
14,
21288,
1547,
29903,
9,
199,
199,
3,
2163,
4546,
1794,
1809,
687,
413,
14,
21,
14,
18,
1159,
6485,
14,
647,
199,
318,
1453,
1943,
837,
272,
408,
1767,
314,
2787,
909,
367,
314,
8025,
1159,
3464,
2787,
1041,
272,
862,
26,
267,
746,
2186,
272,
871,
26,
267,
372,
984,
14,
2804,
63,
815,
3430,
18,
1055,
5842,
63,
1943,
14,
70,
63,
894,
199,
199,
692,
2688,
8,
1274,
12,
2513,
20912,
735,
1453,
1943,
275,
2400,
26,
984,
423,
20912,
8,
19,
9,
199,
3,
4224,
1794,
335,
316,
199,
199,
3,
485,
29903,
365,
1454,
1202,
315,
22888,
543,
984,
423,
20912,
1252,
199,
3,
4005,
5647,
7163,
543,
12731,
5459,
402,
2018,
12,
663,
485,
29903,
199,
3,
370,
488,
340,
485,
20912,
342,
365,
440,
2808,
27,
642,
574,
911,
7981,
199,
3,
2342,
6584,
1435,
342,
687,
3769,
2797,
14,
199,
3,
692,
440,
2688,
8,
1274,
12,
2668,
20912,
2349,
199,
3,
259,
485,
29903,
275,
488,
199,
199,
3,
199,
20930,
28276,
365,
1202,
465,
314,
1300,
1380,
26079,
314,
3847,
900,
402,
4474,
199,
3,
199,
63,
28276,
275,
900,
14,
521,
342,
199,
199,
3,
199,
3,
3730,
16836,
365,
1202,
370,
1937,
340,
4967,
5309,
7252,
1077,
506,
199,
3,
496,
15351,
972,
199,
3,
199,
3730,
16836,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
5796,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
22785,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
12866,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
3947,
6338,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
2112,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
25857,
275,
413,
199,
199,
7656,
13715,
199,
3,
257,
20400,
4048,
8292,
199,
7656,
13715,
199,
3,
199,
3,
3758,
11106,
436
] |
[
1898,
12521,
13,
6542,
701,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
626,
199,
3,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
199,
3,
21038,
3794,
12,
436,
626,
314,
536,
402,
28882,
1187,
428,
9091,
711,
199,
3,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
1126,
24522,
370,
4084,
199,
3,
402,
314,
2032,
1928,
2488,
12,
5313,
6791,
4983,
14,
199,
3,
812,
568,
3448,
13950,
42,
1772,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
4141,
12,
6931,
199,
3,
11727,
5292,
2990,
1634,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
199,
3,
812,
568,
3448,
13950,
42,
1772,
6262,
7024,
2381,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
199,
3,
1821,
6736,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
199,
3,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
199,
14054,
2559,
367,
2018,
14,
21311,
641,
13663,
499,
2564,
436,
6786,
2337,
475,
315,
199,
863,
14,
4159,
14,
1548,
12,
436,
315,
24585,
68,
701,
3668,
1159,
943,
20,
74,
2656,
14,
199,
199,
7384,
334,
35,
9,
12521,
13,
6542,
28882,
1187,
428,
9091,
711,
14,
2900,
5924,
5702,
14,
199,
199,
1378,
675,
12,
9329,
283,
646,
2050,
7,
436,
943,
13437,
1,
199,
624,
199,
199,
646,
984,
12,
747,
12,
900,
12,
15073,
12,
5190,
12,
3598,
12,
13852,
199,
199,
363,
452,
363,
275,
788,
27271,
63,
4807,
297,
283,
3299,
316,
7772,
297,
283,
21539,
297,
283,
5287,
297,
283,
3170,
297,
1779,
283,
29086,
297,
283,
21982,
297,
283,
4131,
297,
283,
7772,
297,
283,
2461,
297,
283,
4531,
297,
1779,
283,
2445,
5433,
297,
283,
4455,
297,
283,
4455,
10200,
297,
283,
4609,
3597,
297,
283,
8849,
2461,
297,
1779,
283,
22482,
297,
283,
17449,
297,
283,
9171,
297,
283,
525,
4670,
985,
297,
283,
19602,
297,
1779,
283,
12685,
15921,
297,
283,
13138,
297,
283,
1757,
297,
283,
5993,
297,
283,
705,
297,
1779,
283,
1971,
297,
283,
16208,
297,
283,
362,
4670,
985,
297,
283,
5572,
297,
283,
5572,
2543,
297,
1779,
283,
815,
297,
283,
793,
297,
283,
1875,
2445,
5433,
297,
283,
409,
4455,
2543,
297,
283,
4050,
297,
283,
3764,
418,
199,
199,
893,
26,
272,
492,
6010,
199,
2590,
3545,
26,
272,
6010,
275,
488,
199,
199,
893,
26,
272,
492,
2462,
272,
492,
5796,
199,
2590,
3545,
26,
272,
2462,
275,
488,
199,
199,
363,
2502,
363,
221,
275,
298,
54,
262,
1187,
428,
9091,
711,
665,
11908,
1187,
63,
2231,
74,
711,
32,
581,
13,
1117,
432,
14,
957,
4335,
199,
363,
1205,
363,
221,
275,
298,
10777,
2,
199,
363,
1023,
363,
275,
298,
16,
14,
21,
14,
17,
14,
18,
2,
199,
363,
602,
363,
259,
275,
298,
1780,
21141,
26709,
7129,
2,
199,
199,
7656,
13715,
199,
3,
257,
12481,
19549,
859,
666,
199,
7656,
13715,
199,
893,
26,
272,
2649,
272,
485,
2975,
275,
715,
199,
2590,
12746,
26,
272,
485,
2975,
275,
756,
199,
199,
3,
199,
3,
485,
29903,
365,
1202,
1380,
12778,
316,
314,
3464,
370,
1104,
1380,
781,
9064,
4788,
314,
1642,
199,
3,
8025,
3464,
2787,
14,
199,
3,
199,
692,
2688,
8,
1274,
12,
283,
11202,
735,
327,
4058,
367,
1134,
18,
5803,
272,
485,
29903,
275,
298,
4806,
5,
83,
363,
826,
363,
5,
83,
2,
450,
334,
736,
14,
4127,
12,
636,
493,
363,
1988,
20,
5728,
199,
4164,
636,
493,
363,
1988,
20,
11455,
2325,
342,
315,
18953,
11357,
297,
1987,
22345,
2565,
272,
485,
29903,
275,
636,
493,
363,
4439,
20,
61,
435,
1987,
647,
7,
199,
2836,
26,
272,
485,
29903,
275,
636,
493,
363,
199,
63,
29903,
275,
747,
14,
515,
14,
21288,
1547,
29903,
9,
199,
199,
3,
2163,
4546,
1794,
1809,
687,
413,
14,
21,
14,
18,
1159,
6485,
14,
647,
199,
318,
1453,
1943,
837,
272,
408,
1767,
314,
2787,
909,
367,
314,
8025,
1159,
3464,
2787,
1041,
272,
862,
26,
267,
746,
2186,
272,
871,
26,
267,
372,
984,
14,
2804,
63,
815,
3430,
18,
1055,
5842,
63,
1943,
14,
70,
63,
894,
199,
199,
692,
2688,
8,
1274,
12,
2513,
20912,
735,
1453,
1943,
275,
2400,
26,
984,
423,
20912,
8,
19,
9,
199,
3,
4224,
1794,
335,
316,
199,
199,
3,
485,
29903,
365,
1454,
1202,
315,
22888,
543,
984,
423,
20912,
1252,
199,
3,
4005,
5647,
7163,
543,
12731,
5459,
402,
2018,
12,
663,
485,
29903,
199,
3,
370,
488,
340,
485,
20912,
342,
365,
440,
2808,
27,
642,
574,
911,
7981,
199,
3,
2342,
6584,
1435,
342,
687,
3769,
2797,
14,
199,
3,
692,
440,
2688,
8,
1274,
12,
2668,
20912,
2349,
199,
3,
259,
485,
29903,
275,
488,
199,
199,
3,
199,
20930,
28276,
365,
1202,
465,
314,
1300,
1380,
26079,
314,
3847,
900,
402,
4474,
199,
3,
199,
63,
28276,
275,
900,
14,
521,
342,
199,
199,
3,
199,
3,
3730,
16836,
365,
1202,
370,
1937,
340,
4967,
5309,
7252,
1077,
506,
199,
3,
496,
15351,
972,
199,
3,
199,
3730,
16836,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
5796,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
22785,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
12866,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
3947,
6338,
275,
413,
199,
199,
3,
199,
3,
982,
1265,
2793,
1133,
2934,
2112,
2556,
315,
314,
943,
12,
663,
642,
370,
4697,
199,
3,
199,
793,
25857,
275,
413,
199,
199,
7656,
13715,
199,
3,
257,
20400,
4048,
8292,
199,
7656,
13715,
199,
3,
199,
3,
3758,
11106,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hargup/sympy
|
sympy/polys/subresultants_qq_zz.py
|
33
|
79948
|
# -*- coding: utf-8 -*-
"""
This module contains functions for the computation
of Euclidean, generalized Sturmian and (modified) subresultant
polynomial remainder sequences (prs's).
The pseudo-remainder function prem() of sympy is _not_ used
by any of the functions in the module.
Instead of prem() we use the function
rem_z().
Included is also the function quo_z().
1. Theoretical background:
==========================
Consider the polynomials f, g ∈ Z[x] of degrees deg(f) = n and
deg(g) = m with n ≥ m.
Definition 1:
=============
The sign sequence of a polynomial remainder sequence (prs) is the
sequence of signs of the leading coefficients of its polynomials.
Sign sequences can be computed with the function:
sign_seq(poly_seq, x)
Definition 2:
=============
A polynomial remainder sequence (prs) is called complete if the
degree difference between any two consecutive polynomials is 1;
otherwise, it called incomplete.
It is understood that f, g belong to the sequences mentioned in
the two definitions.
1A. Euclidean and subresultant prs's:
=====================================
The subresultant prs of f, g is a sequence of polynomials in Z[x]
analogous to the Euclidean prs, the sequence obtained by applying
on f, g Euclid’s algorithm for polynomial greatest common divisors
(gcd) in Q[x].
The subresultant prs differs from the Euclidean prs in that the
coefficients of each polynomial in the former sequence are determinants
--- also referred to as subresultants --- of appropriately selected
sub-matrices of sylvester1(f, g, x), Sylvester’s matrix of 1840 of
dimensions (n + m) × (n + m).
Recall that the determinant of sylvester1(f, g, x) itself is
called the resultant of f, g and serves as a criterion of whether
the two polynomials have common roots or not.
In sympy the resultant is computed with the function
resultant(f, g, x). This function does _not_ evaluate the
determinant of sylvester(f, g, x, 1); instead, it returns
the last member of the subresultant prs of f, g, multiplied
(if needed) by an appropriate power of -1; see the caveat below.
Caveat: If Df = degree(f, x) and Dg = degree(g, x), then:
resultant(f, g, x) = (-1)**(Df*Dg) * resultant(g, f, x).
For complete prs’s the sign sequence of the Euclidean prs of f, g
is identical to the sign sequence of the subresultant prs of f, g
and the coefficients of one sequence are easily computed from the
coefficients of the other.
For incomplete prs’s the polynomials in the subresultant prs, generally
differ in sign from those of the Euclidean prs, and --- unlike the
case of complete prs’s --- it is not at all obvious how to compute
the coefficients of one sequence from the coefficients of the other.
1B. Sturmian and modified subresultant prs's:
=============================================
For the same polynomials f, g ∈ Z[x] mentioned above, their ``modified''
subresultant prs is a sequence of polynomials similar to the Sturmian
prs, the sequence obtained by applying in Q[x] Sturm’s algorithm on f, g.
The two sequences differ in that the coefficients of each polynomial
in the modified subresultant prs are the determinants --- also referred
to as modified subresultants --- of appropriately selected sub-matrices
of sylvester2(f, g, x), Sylvester’s matrix of 1853 of dimensions 2n × 2n.
The determinant of sylvester2 itself is called the modified resultant
of f, g and it also can serve as a criterion of whether the two
polynomials have common roots or not.
For complete prs’s the sign sequence of the Sturmian prs of f, g is
identical to the sign sequence of the modified subresultant prs of
f, g and the coefficients of one sequence are easily computed from
the coefficients of the other.
For incomplete prs’s the polynomials in the modified subresultant prs,
generally differ in sign from those of the Sturmian prs, and --- unlike
the case of complete prs’s --- it is not at all obvious how to compute
the coefficients of one sequence from the coefficients of the other.
As Sylvester pointed out, the coefficients of the polynomial remainders
obtained as (modified) subresultants are the smallest possible without
introducing rationals and without computing (integer) greatest common
divisors.
1C. On terminology:
===================
Whence the terminology? Well generalized Sturmian prs's are
``modifications'' of Euclidean prs's; the hint came from the title
of the Pell-Gordon paper of 1917.
In the literature one also encounters the name ``non signed'' and
``signed'' prs for Euclidean and Sturmian prs respectively.
Likewise ``non signed'' and ``signed'' subresultant prs for
subresultant and modified subresultant prs respectively.
2. Functions in the module:
===========================
No function utilizes sympy's function prem().
2A. Matrices:
=============
The functions sylvester(f, g, x, method=1) and
sylvester(f, g, x, method=2) compute either Sylvester matrix.
They can be used to compute (modified) subresultant prs's by
direct determinant evaluation.
The function bezout(f, g, x, method='prs') provides a matrix of
smaller dimensions than either Sylvester matrix. It is the function
of choice for computing (modified) subresultant prs's by direct
determinant evaluation.
sylvester(f, g, x, method=1)
sylvester(f, g, x, method=2)
bezout(f, g, x, method='prs')
The following identity holds:
bezout(f, g, x, method='prs') =
backward_eye(deg(f))*bezout(f, g, x, method='bz')*backward_eye(deg(f))
2B. Subresultant and modified subresultant prs's by
===================================================
determinant evaluation:
=======================
Instead of utilizing the Sylvester matrices, we employ
the Bezout matrix of smaller dimensions.
subresultants_bezout(f, g, x)
modified_subresultants_bezout(f, g, x)
2C. Subresultant prs's by ONE determinant evaluation:
=====================================================
All three functions in this section evaluate one determinant
per remainder polynomial; this is the determinant of an
appropriately selected sub-matrix of sylvester1(f, g, x),
Sylvester’s matrix of 1840.
To compute the remainder polynomials the function
subresultants_rem(f, g, x) employs rem(f, g, x).
By contrast, the other two functions implement Van Vleck’s ideas
of 1900 and compute the remainder polynomials by trinagularizing
sylvester2(f, g, x), Sylvester’s matrix of 1853.
subresultants_rem(f, g, x)
subresultants_vv(f, g, x)
subresultants_vv_2(f, g, x).
2E. Euclidean, Sturmian prs's in Q[x]:
======================================
euclid_q(f, g, x)
sturm_q(f, g, x)
2F. Euclidean, Sturmian and (modified) subresultant prs's P-G:
==============================================================
All functions in this section are based on the Pell-Gordon (P-G)
theorem of 1917.
Computations are done in Q[x], employing the function rem(f, g, x)
for the computation of the remainder polynomials.
euclid_pg(f, g, x)
sturm pg(f, g, x)
subresultants_pg(f, g, x)
modified_subresultants_pg(f, g, x)
2G. Euclidean, Sturmian and (modified) subresultant prs's A-M-V:
================================================================
All functions in this section are based on the Akritas-Malaschonok-
Vigklas (A-M-V) theorem of 2015.
Computations are done in Z[x], employing the function rem_z(f, g, x)
for the computation of the remainder polynomials.
euclid_amv(f, g, x)
sturm_amv(f, g, x)
subresultants_amv(f, g, x)
modified_subresultants_amv(f, g, x)
2Ga. Exception:
===============
subresultants_amv_q(f, g, x)
This function employs rem(f, g, x) for the computation of
the remainder polynomials, despite the fact that it implements
the A-M-V Theorem.
It is included in our module in order to show that theorems P-G
and A-M-V can be implemented utilizing either the function
rem(f, g, x) or the function rem_z(f, g, x).
For clearly historical reasons --- since the Collins-Brown-Traub
coefficients-reduction factor β_i was not available in 1917 ---
we have implemented the Pell-Gordon theorem with the function
rem(f, g, x) and the A-M-V Theorem with the function rem_z(f, g, x).
"""
from __future__ import print_function, division
from sympy import (Abs, degree, expand, eye, floor, LC, Matrix, nan, Poly, pprint)
from sympy import (QQ, quo, rem, S, sign, simplify, summation, var, zeros)
def sylvester(f, g, x, method = 1):
'''
The input polynomials f, g are in Z[x] or in Q[x].
Let mx = max( degree(f, x) , degree(g, x) ).
a. If method = 1 (default), computes sylvester1, Sylvester's matrix of 1840
of dimension (m + n) x (m + n). The determinants of properly chosen
submatrices of this matrix (a.k.a. subresultants) can be
used to compute the coefficients of the Euclidean PRS of f, g.
b. If method = 2, computes sylvester2, Sylvester's matrix of 1853
of dimension (2*mx) x (2*mx). The determinants of properly chosen
submatrices of this matrix (a.k.a. ``modified'' subresultants) can be
used to compute the coefficients of the Sturmian PRS of f, g.
Applications of these Matrices can be found in the references below.
Especially, for applications of sylvester2, see the first reference!!
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem
by Van Vleck Regarding Sturm Sequences. Serdica Journal of Computing,
Vol. 7, No 4, 101–134, 2013.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
'''
# obtain degrees of polys
m, n = degree( Poly(f, x), x), degree( Poly(g, x), x)
# Special cases:
# A:: case m = n < 0 (i.e. both polys are 0)
if m == n and n < 0:
return Matrix([])
# B:: case m = n = 0 (i.e. both polys are constants)
if m == n and n == 0:
return Matrix([])
# C:: m == 0 and n < 0 or m < 0 and n == 0
# (i.e. one poly is constant and the other is 0)
if m == 0 and n < 0:
return Matrix([])
elif m < 0 and n == 0:
return Matrix([])
# D:: m >= 1 and n < 0 or m < 0 and n >=1
# (i.e. one poly is of degree >=1 and the other is 0)
if m >= 1 and n < 0:
return Matrix([0])
elif m < 0 and n >= 1:
return Matrix([0])
fp = Poly(f, x).all_coeffs()
gp = Poly(g, x).all_coeffs()
# Sylvester's matrix of 1840 (default; a.k.a. sylvester1)
if method <= 1:
M = zeros(m + n)
k = 0
for i in range(n):
j = k
for coeff in fp:
M[i, j] = coeff
j = j + 1
k = k + 1
k = 0
for i in range(n, m + n):
j = k
for coeff in gp:
M[i, j] = coeff
j = j + 1
k = k + 1
return M
# Sylvester's matrix of 1853 (a.k.a sylvester2)
if method >= 2:
if len(fp) < len(gp):
h = []
for i in range(len(gp) - len(fp)):
h.append(0)
fp[ : 0] = h
else:
h = []
for i in range(len(fp) - len(gp)):
h.append(0)
gp[ : 0] = h
mx = max(m, n)
dim = 2*mx
M = zeros( dim )
k = 0
for i in range( mx ):
j = k
for coeff in fp:
M[2*i, j] = coeff
j = j + 1
j = k
for coeff in gp:
M[2*i + 1, j] = coeff
j = j + 1
k = k + 1
return M
def sign_seq(poly_seq, x):
"""
Given a sequence of polynomials poly_seq, it returns
the sequence of signs of the leading coefficients of
the polynomials in poly_seq.
"""
return [sign(LC(poly_seq[i], x)) for i in range(len(poly_seq))]
def bezout(p, q, x, method='bz'):
"""
The input polynomials p, q are in Z[x] or in Q[x]. Let
mx = max( degree(p, x) , degree(q, x) ).
The default option bezout(p, q, x, method='bz') returns Bezout's
symmetric matrix of p and q, of dimensions (mx) x (mx). The
determinant of this matrix is equal to the determinant of sylvester2,
Sylvester's matrix of 1853, whose dimensions are (2*mx) x (2*mx);
however the subresultants of these two matrices may differ.
The other option, bezout(p, q, x, 'prs'), is of interest to us
in this module because it returns a matrix equivalent to sylvester2.
In this case all subresultants of the two matrices are identical.
Both the subresultant polynomial remainder sequence (prs) and
the modified subresultant prs of p and q can be computed by
evaluating determinants of appropriately selected submatrices of
bezout(p, q, x, 'prs') --- one determinant per coefficient of the
remainder polynomials.
The matrices bezout(p, q, x, 'bz') and bezout(p, q, x, 'prs')
are related by the formula
bezout(p, q, x, 'prs') =
backward_eye(deg(p)) * bezout(p, q, x, 'bz') * backward_eye(deg(p)),
where backward_eye() is the backward identity function.
References:
===========
1. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants
and Their Applications. Appl. Algebra in Engin., Communic. and Comp.,
Vol. 15, 233–266, 2004.
"""
# obtain degrees of polys
m, n = degree( Poly(p, x), x), degree( Poly(q, x), x)
# Special cases:
# A:: case m = n < 0 (i.e. both polys are 0)
if m == n and n < 0:
return Matrix([])
# B:: case m = n = 0 (i.e. both polys are constants)
if m == n and n == 0:
return Matrix([])
# C:: m == 0 and n < 0 or m < 0 and n == 0
# (i.e. one poly is constant and the other is 0)
if m == 0 and n < 0:
return Matrix([])
elif m < 0 and n == 0:
return Matrix([])
# D:: m >= 1 and n < 0 or m < 0 and n >=1
# (i.e. one poly is of degree >=1 and the other is 0)
if m >= 1 and n < 0:
return Matrix([0])
elif m < 0 and n >= 1:
return Matrix([0])
y = var('y')
# expr is 0 when x = y
expr = p * q.subs({x:y}) - p.subs({x:y}) * q
# hence expr is exactly divisible by x - y
poly = Poly( quo(expr, x-y), x, y)
# form Bezout matrix and store them in B as indicated to get
# the LC coefficient of each poly either in the first position
# of each row (method='prs') or in the last (method='bz').
mx = max(m, n)
B = zeros(mx)
for i in range(mx):
for j in range(mx):
if method == 'prs':
B[mx - 1 - i, mx - 1 - j] = poly.nth(i, j)
else:
B[i, j] = poly.nth(i, j)
return B
def backward_eye(n):
'''
Returns the backward identity matrix of dimensions n x n.
Needed to "turn" the Bezout matrices
so that the leading coefficients are first.
See docstring of the function bezout(p, q, x, method='bz').
'''
M = eye(n) # identity matrix of order n
for i in range(int(M.rows / 2)):
M.row_swap(0 + i, M.rows - 1 - i)
return M
def process_bezout_output(poly_seq, x):
"""
poly_seq is a polynomial remainder sequence computed either by
subresultants_bezout or by modified_subresultants_bezout.
This function removes from poly_seq all zero polynomials as well
as all those whose degree is equal to the degree of a previous
polynomial in poly_seq, as we scan it from left to right.
"""
L = poly_seq[:] # get a copy of the input sequence
d = degree(L[1], x)
i = 2
while i < len(L):
d_i = degree(L[i], x)
if d_i < 0: # zero poly
L.remove(L[i])
i = i - 1
if d == d_i: # poly degree equals degree of previous poly
L.remove(L[i])
i = i - 1
if d_i >= 0:
d = d_i
i = i + 1
return L
def subresultants_bezout(p, q, x):
"""
The input polynomials p, q are in Z[x] or in Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant polynomial remainder sequence
of p, q by evaluating determinants of appropriately selected
submatrices of bezout(p, q, x, 'prs'). The dimensions of the
latter are deg(p) x deg(p).
Each coefficient is computed by evaluating the determinant of the
corresponding submatrix of bezout(p, q, x, 'prs').
bezout(p, q, x, 'prs) is used instead of sylvester(p, q, x, 1),
Sylvester's matrix of 1840, because the dimensions of the latter
are (deg(p) + deg(q)) x (deg(p) + deg(q)).
If the subresultant prs is complete, then the output coincides
with the Euclidean sequence of the polynomials p, q.
References:
===========
1. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants
and Their Applications. Appl. Algebra in Engin., Communic. and Comp.,
Vol. 15, 233–266, 2004.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
f, g = p, q
n = degF = degree(f, x)
m = degG = degree(g, x)
# make sure proper degrees
if n == 0 and m == 0:
return [f, g]
if n < m:
n, m, degF, degG, f, g = m, n, degG, degF, g, f
if n > 0 and m == 0:
return [f, g]
SR_L = [f, g] # subresultant list
F = LC(f, x)**(degF - degG)
# form the bezout matrix
B = bezout(f, g, x, 'prs')
# pick appropriate submatrices of B
# and form subresultant polys
if degF > degG:
j = 2
if degF == degG:
j = 1
while j <= degF:
M = B[0:j, :]
k, coeff_L = j - 1, []
while k <= degF - 1:
coeff_L.append(M[: ,0 : j].det())
if k < degF - 1:
M.col_swap(j - 1, k + 1)
k = k + 1
# apply Theorem 2.1 in the paper by Toca & Vega 2004
# to get correct signs
SR_L.append((int((-1)**(j*(j-1)/2)) * Poly(coeff_L, x) / F).as_expr())
j = j + 1
return process_bezout_output(SR_L, x)
def modified_subresultants_bezout(p, q, x):
"""
The input polynomials p, q are in Z[x] or in Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the modified subresultant polynomial remainder sequence
of p, q by evaluating determinants of appropriately selected
submatrices of bezout(p, q, x, 'prs'). The dimensions of the
latter are deg(p) x deg(p).
Each coefficient is computed by evaluating the determinant of the
corresponding submatrix of bezout(p, q, x, 'prs').
bezout(p, q, x, 'prs') is used instead of sylvester(p, q, x, 2),
Sylvester's matrix of 1853, because the dimensions of the latter
are 2*deg(p) x 2*deg(p).
If the modified subresultant prs is complete, and LC( p ) > 0, the output
coincides with the (generalized) Sturm's sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
2. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants
and Their Applications. Appl. Algebra in Engin., Communic. and Comp.,
Vol. 15, 233–266, 2004.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
f, g = p, q
n = degF = degree(f, x)
m = degG = degree(g, x)
# make sure proper degrees
if n == 0 and m == 0:
return [f, g]
if n < m:
n, m, degF, degG, f, g = m, n, degG, degF, g, f
if n > 0 and m == 0:
return [f, g]
SR_L = [f, g] # subresultant list
# form the bezout matrix
B = bezout(f, g, x, 'prs')
# pick appropriate submatrices of B
# and form subresultant polys
if degF > degG:
j = 2
if degF == degG:
j = 1
while j <= degF:
M = B[0:j, :]
k, coeff_L = j - 1, []
while k <= degF - 1:
coeff_L.append(M[: ,0 : j].det())
if k < degF - 1:
M.col_swap(j - 1, k + 1)
k = k + 1
## Theorem 2.1 in the paper by Toca & Vega 2004 is _not needed_
## in this case since
## the bezout matrix is equivalent to sylvester2
SR_L.append(( Poly(coeff_L, x)).as_expr())
j = j + 1
return process_bezout_output(SR_L, x)
def sturm_pg(p, q, x, method=0):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the (generalized) Sturm sequence of p and q in Z[x] or Q[x].
If q = diff(p, x, 1) it is the usual Sturm sequence.
A. If method == 0, default, the remainder coefficients of the sequence
are (in absolute value) ``modified'' subresultants, which for non-monic
polynomials are greater than the coefficients of the corresponding
subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).
B. If method == 1, the remainder coefficients of the sequence are (in
absolute value) subresultants, which for non-monic polynomials are
smaller than the coefficients of the corresponding ``modified''
subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).
If the Sturm sequence is complete, method=0 and LC( p ) > 0, the coefficients
of the polynomials in the sequence are ``modified'' subresultants.
That is, they are determinants of appropriately selected submatrices of
sylvester2, Sylvester's matrix of 1853. In this case the Sturm sequence
coincides with the ``modified'' subresultant prs, of the polynomials
p, q.
If the Sturm sequence is incomplete and method=0 then the signs of the
coefficients of the polynomials in the sequence may differ from the signs
of the coefficients of the corresponding polynomials in the ``modified''
subresultant prs; however, the absolute values are the same.
To compute the coefficients, no determinant evaluation takes place. Instead,
polynomial divisions in Q[x] are performed, using the function rem(p, q, x);
the coefficients of the remainders computed this way become (``modified'')
subresultants with the help of the Pell-Gordon Theorem of 1917.
See also the function euclid_pg(p, q, x).
References:
===========
1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding
the Highest Common Factor of Two Polynomials. Annals of MatheMatics,
Second Series, 18 (1917), No. 4, 188–193.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
d0 = degree(p, x)
d1 = degree(q, x)
if d0 == 0 and d1 == 0:
return [p, q]
if d1 > d0:
d0, d1 = d1, d0
p, q = q, p
if d0 > 0 and d1 == 0:
return [p,q]
# make sure LC(p) > 0
flag = 0
if LC(p,x) < 0:
flag = 1
p = -p
q = -q
# initialize
lcf = LC(p, x)**(d0 - d1) # lcf * subr = modified subr
a0, a1 = p, q # the input polys
sturm_seq = [a0, a1] # the output list
del0 = d0 - d1 # degree difference
rho1 = LC(a1, x) # leading coeff of a1
exp_deg = d1 - 1 # expected degree of a2
a2 = - rem(a0, a1, domain=QQ) # first remainder
rho2 = LC(a2,x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
deg_diff_new = exp_deg - d2 # expected - actual degree
del1 = d1 - d2 # degree difference
# mul_fac is the factor by which a2 is multiplied to
# get integer coefficients
mul_fac_old = rho1**(del0 + del1 - deg_diff_new)
# append accordingly
if method == 0:
sturm_seq.append( simplify(lcf * a2 * Abs(mul_fac_old)))
else:
sturm_seq.append( simplify( a2 * Abs(mul_fac_old)))
# main loop
deg_diff_old = deg_diff_new
while d2 > 0:
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
del0 = del1 # update degree difference
exp_deg = d1 - 1 # new expected degree
a2 = - rem(a0, a1, domain=QQ) # new remainder
rho3 = LC(a2, x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
deg_diff_new = exp_deg - d2 # expected - actual degree
del1 = d1 - d2 # degree difference
# take into consideration the power
# rho1**deg_diff_old that was "left out"
expo_old = deg_diff_old # rho1 raised to this power
expo_new = del0 + del1 - deg_diff_new # rho2 raised to this power
# update variables and append
mul_fac_new = rho2**(expo_new) * rho1**(expo_old) * mul_fac_old
deg_diff_old, mul_fac_old = deg_diff_new, mul_fac_new
rho1, rho2 = rho2, rho3
if method == 0:
sturm_seq.append( simplify(lcf * a2 * Abs(mul_fac_old)))
else:
sturm_seq.append( simplify( a2 * Abs(mul_fac_old)))
if flag: # change the sign of the sequence
sturm_seq = [-i for i in sturm_seq]
# gcd is of degree > 0 ?
m = len(sturm_seq)
if sturm_seq[m - 1] == nan or sturm_seq[m - 1] == 0:
sturm_seq.pop(m - 1)
return sturm_seq
def sturm_q(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the (generalized) Sturm sequence of p and q in Q[x].
Polynomial divisions in Q[x] are performed, using the function rem(p, q, x).
The coefficients of the polynomials in the Sturm sequence can be uniquely
determined from the corresponding coefficients of the polynomials found
either in:
(a) the ``modified'' subresultant prs, (references 1, 2)
or in
(b) the subresultant prs (reference 3).
References:
===========
1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding
the Highest Common Factor of Two Polynomials. Annals of MatheMatics,
Second Series, 18 (1917), No. 4, 188–193.
2 Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
d0 = degree(p, x)
d1 = degree(q, x)
if d0 == 0 and d1 == 0:
return [p, q]
if d1 > d0:
d0, d1 = d1, d0
p, q = q, p
if d0 > 0 and d1 == 0:
return [p,q]
# make sure LC(p) > 0
flag = 0
if LC(p,x) < 0:
flag = 1
p = -p
q = -q
# initialize
a0, a1 = p, q # the input polys
sturm_seq = [a0, a1] # the output list
a2 = -rem(a0, a1, domain=QQ) # first remainder
d2 = degree(a2, x) # degree of a2
sturm_seq.append( a2 )
# main loop
while d2 > 0:
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
a2 = -rem(a0, a1, domain=QQ) # new remainder
d2 = degree(a2, x) # actual degree of a2
sturm_seq.append( a2 )
if flag: # change the sign of the sequence
sturm_seq = [-i for i in sturm_seq]
# gcd is of degree > 0 ?
m = len(sturm_seq)
if sturm_seq[m - 1] == nan or sturm_seq[m - 1] == 0:
sturm_seq.pop(m - 1)
return sturm_seq
def sturm_amv(p, q, x, method=0):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the (generalized) Sturm sequence of p and q in Z[x] or Q[x].
If q = diff(p, x, 1) it is the usual Sturm sequence.
A. If method == 0, default, the remainder coefficients of the
sequence are (in absolute value) ``modified'' subresultants, which
for non-monic polynomials are greater than the coefficients of the
corresponding subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).
B. If method == 1, the remainder coefficients of the sequence are (in
absolute value) subresultants, which for non-monic polynomials are
smaller than the coefficients of the corresponding ``modified''
subresultants by the factor Abs( LC(p)**( deg(p)- deg(q)) ).
If the Sturm sequence is complete, method=0 and LC( p ) > 0, then the
coefficients of the polynomials in the sequence are ``modified'' subresultants.
That is, they are determinants of appropriately selected submatrices of
sylvester2, Sylvester's matrix of 1853. In this case the Sturm sequence
coincides with the ``modified'' subresultant prs, of the polynomials
p, q.
If the Sturm sequence is incomplete and method=0 then the signs of the
coefficients of the polynomials in the sequence may differ from the signs
of the coefficients of the corresponding polynomials in the ``modified''
subresultant prs; however, the absolute values are the same.
To compute the coefficients, no determinant evaluation takes place.
Instead, we first compute the euclidean sequence of p and q using
euclid_amv(p, q, x) and then: (a) change the signs of the remainders in the
Euclidean sequence according to the pattern "-, -, +, +, -, -, +, +,..."
(see Lemma 1 in the 1st reference or Theorem 3 in the 2nd reference)
and (b) if method=0, assuming deg(p) > deg(q), we multiply the remainder
coefficients of the Euclidean sequence times the factor
Abs( LC(p)**( deg(p)- deg(q)) ) to make them modified subresultants.
See also the function sturm_pg(p, q, x).
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders
Obtained in Finding the Greatest Common Divisor of Two Polynomials.'' Serdica
Journal of Computing, to appear.
3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial
Remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].''
Submitted for publication.
"""
# compute the euclidean sequence
prs = euclid_amv(p, q, x)
# defensive
if prs == [] or len(prs) == 2:
return prs
# the coefficients in prs are subresultants and hence are smaller
# than the corresponding subresultants by the factor
# Abs( LC(prs[0])**( deg(prs[0]) - deg(prs[1])) ); Theorem 2, 2nd reference.
lcf = Abs( LC(prs[0])**( degree(prs[0], x) - degree(prs[1], x) ) )
# the signs of the first two polys in the sequence stay the same
sturm_seq = [prs[0], prs[1]]
# change the signs according to "-, -, +, +, -, -, +, +,..."
# and multiply times lcf if needed
flag = 0
m = len(prs)
i = 2
while i <= m-1:
if flag == 0:
sturm_seq.append( - prs[i] )
i = i + 1
if i == m:
break
sturm_seq.append( - prs[i] )
i = i + 1
flag = 1
elif flag == 1:
sturm_seq.append( prs[i] )
i = i + 1
if i == m:
break
sturm_seq.append( prs[i] )
i = i + 1
flag = 0
# subresultants or modified subresultants?
if method == 0 and lcf > 1:
aux_seq = [sturm_seq[0], sturm_seq[1]]
for i in range(2, m):
aux_seq.append(simplify(sturm_seq[i] * lcf ))
sturm_seq = aux_seq
return sturm_seq
def euclid_pg(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the Euclidean sequence of p and q in Z[x] or Q[x].
If the Euclidean sequence is complete the coefficients of the polynomials
in the sequence are subresultants. That is, they are determinants of
appropriately selected submatrices of sylvester1, Sylvester's matrix of 1840.
In this case the Euclidean sequence coincides with the subresultant prs
of the polynomials p, q.
If the Euclidean sequence is incomplete the signs of the coefficients of the
polynomials in the sequence may differ from the signs of the coefficients of
the corresponding polynomials in the subresultant prs; however, the absolute
values are the same.
To compute the Euclidean sequence, no determinant evaluation takes place.
We first compute the (generalized) Sturm sequence of p and q using
sturm_pg(p, q, x, 1), in which case the coefficients are (in absolute value)
equal to subresultants. Then we change the signs of the remainders in the
Sturm sequence according to the pattern "-, -, +, +, -, -, +, +,..." ;
see Lemma 1 in the 1st reference or Theorem 3 in the 2nd reference as well as
the function sturm_pg(p, q, x).
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders
Obtained in Finding the Greatest Common Divisor of Two Polynomials.'' Serdica
Journal of Computing, to appear.
3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial
Remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].''
Submitted for publication.
"""
# compute the sturmian sequence using the Pell-Gordon (or AMV) theorem
# with the coefficients in the prs being (in absolute value) subresultants
prs = sturm_pg(p, q, x, 1) ## any other method would do
# defensive
if prs == [] or len(prs) == 2:
return prs
# the signs of the first two polys in the sequence stay the same
euclid_seq = [prs[0], prs[1]]
# change the signs according to "-, -, +, +, -, -, +, +,..."
flag = 0
m = len(prs)
i = 2
while i <= m-1:
if flag == 0:
euclid_seq.append(- prs[i] )
i = i + 1
if i == m:
break
euclid_seq.append(- prs[i] )
i = i + 1
flag = 1
elif flag == 1:
euclid_seq.append(prs[i] )
i = i + 1
if i == m:
break
euclid_seq.append(prs[i] )
i = i + 1
flag = 0
return euclid_seq
def euclid_q(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the Euclidean sequence of p and q in Q[x].
Polynomial divisions in Q[x] are performed, using the function rem(p, q, x).
The coefficients of the polynomials in the Euclidean sequence can be uniquely
determined from the corresponding coefficients of the polynomials found
either in:
(a) the ``modified'' subresultant polynomial remainder sequence,
(references 1, 2)
or in
(b) the subresultant polynomial remainder sequence (references 3).
References:
===========
1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding
the Highest Common Factor of Two Polynomials. Annals of MatheMatics,
Second Series, 18 (1917), No. 4, 188–193.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
d0 = degree(p, x)
d1 = degree(q, x)
if d0 == 0 and d1 == 0:
return [p, q]
if d1 > d0:
d0, d1 = d1, d0
p, q = q, p
if d0 > 0 and d1 == 0:
return [p,q]
# make sure LC(p) > 0
flag = 0
if LC(p,x) < 0:
flag = 1
p = -p
q = -q
# initialize
a0, a1 = p, q # the input polys
euclid_seq = [a0, a1] # the output list
a2 = rem(a0, a1, domain=QQ) # first remainder
d2 = degree(a2, x) # degree of a2
euclid_seq.append( a2 )
# main loop
while d2 > 0:
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
a2 = rem(a0, a1, domain=QQ) # new remainder
d2 = degree(a2, x) # actual degree of a2
euclid_seq.append( a2 )
if flag: # change the sign of the sequence
euclid_seq = [-i for i in euclid_seq]
# gcd is of degree > 0 ?
m = len(euclid_seq)
if euclid_seq[m - 1] == nan or euclid_seq[m - 1] == 0:
euclid_seq.pop(m - 1)
return euclid_seq
def euclid_amv(f, g, x):
"""
f, g are polynomials in Z[x] or Q[x]. It is assumed
that degree(f, x) >= degree(g, x).
Computes the Euclidean sequence of p and q in Z[x] or Q[x].
If the Euclidean sequence is complete the coefficients of the polynomials
in the sequence are subresultants. That is, they are determinants of
appropriately selected submatrices of sylvester1, Sylvester's matrix of 1840.
In this case the Euclidean sequence coincides with the subresultant prs,
of the polynomials p, q.
If the Euclidean sequence is incomplete the signs of the coefficients of the
polynomials in the sequence may differ from the signs of the coefficients of
the corresponding polynomials in the subresultant prs; however, the absolute
values are the same.
To compute the coefficients, no determinant evaluation takes place.
Instead, polynomial divisions in Z[x] or Q[x] are performed, using
the function rem_z(f, g, x); the coefficients of the remainders
computed this way become subresultants with the help of the
Collins-Brown-Traub formula for coefficient reduction.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial
remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].''
Submitted for publication.
"""
# make sure neither f nor g is 0
if f == 0 or g == 0:
return [f, g]
# make sure proper degrees
d0 = degree(f, x)
d1 = degree(g, x)
if d0 == 0 and d1 == 0:
return [f, g]
if d1 > d0:
d0, d1 = d1, d0
f, g = g, f
if d0 > 0 and d1 == 0:
return [f, g]
# initialize
a0 = f
a1 = g
euclid_seq = [a0, a1]
deg_dif_p1, c = degree(a0, x) - degree(a1, x) + 1, -1
# compute the first polynomial of the prs
i = 1
a2 = rem_z(a0, a1, x) / Abs( (-1)**deg_dif_p1 ) # first remainder
euclid_seq.append( a2 )
d2 = degree(a2, x) # actual degree of a2
# main loop
while d2 >= 1:
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
i += 1
sigma0 = -LC(a0)
c = (sigma0**(deg_dif_p1 - 1)) / (c**(deg_dif_p1 - 2))
deg_dif_p1 = degree(a0, x) - d2 + 1
a2 = rem_z(a0, a1, x) / Abs( ((c**(deg_dif_p1 - 1)) * sigma0) )
euclid_seq.append( a2 )
d2 = degree(a2, x) # actual degree of a2
# gcd is of degree > 0 ?
m = len(euclid_seq)
if euclid_seq[m - 1] == nan or euclid_seq[m - 1] == 0:
euclid_seq.pop(m - 1)
return euclid_seq
def modified_subresultants_pg(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the ``modified'' subresultant prs of p and q in Z[x] or Q[x];
the coefficients of the polynomials in the sequence are
``modified'' subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester2, Sylvester's matrix of 1853.
To compute the coefficients, no determinant evaluation takes place. Instead,
polynomial divisions in Q[x] are performed, using the function rem(p, q, x);
the coefficients of the remainders computed this way become ``modified''
subresultants with the help of the Pell-Gordon Theorem of 1917.
If the ``modified'' subresultant prs is complete, and LC( p ) > 0, it coincides
with the (generalized) Sturm sequence of the polynomials p, q.
References:
===========
1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding
the Highest Common Factor of Two Polynomials. Annals of MatheMatics,
Second Series, 18 (1917), No. 4, 188–193.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
d0 = degree(p,x)
d1 = degree(q,x)
if d0 == 0 and d1 == 0:
return [p, q]
if d1 > d0:
d0, d1 = d1, d0
p, q = q, p
if d0 > 0 and d1 == 0:
return [p,q]
# initialize
k = var('k') # index in summation formula
u_list = [] # of elements (-1)**u_i
subres_l = [p, q] # mod. subr. prs output list
a0, a1 = p, q # the input polys
del0 = d0 - d1 # degree difference
degdif = del0 # save it
rho_1 = LC(a0) # lead. coeff (a0)
# Initialize Pell-Gordon variables
rho_list_minus_1 = sign( LC(a0, x)) # sign of LC(a0)
rho1 = LC(a1, x) # leading coeff of a1
rho_list = [ sign(rho1)] # of signs
p_list = [del0] # of degree differences
u = summation(k, (k, 1, p_list[0])) # value of u
u_list.append(u) # of u values
v = sum(p_list) # v value
# first remainder
exp_deg = d1 - 1 # expected degree of a2
a2 = - rem(a0, a1, domain=QQ) # first remainder
rho2 = LC(a2, x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
deg_diff_new = exp_deg - d2 # expected - actual degree
del1 = d1 - d2 # degree difference
# mul_fac is the factor by which a2 is multiplied to
# get integer coefficients
mul_fac_old = rho1**(del0 + del1 - deg_diff_new)
# update Pell-Gordon variables
p_list.append(1 + deg_diff_new) # deg_diff_new is 0 for complete seq
# apply Pell-Gordon formula (7) in second reference
num = 1 # numerator of fraction
for k in range(len(u_list)):
num *= (-1)**u_list[k]
num = num * (-1)**v
# denominator depends on complete / incomplete seq
if deg_diff_new == 0: # complete seq
den = 1
for k in range(len(rho_list)):
den *= rho_list[k]**(p_list[k] + p_list[k + 1])
den = den * rho_list_minus_1
else: # incomplete seq
den = 1
for k in range(len(rho_list)-1):
den *= rho_list[k]**(p_list[k] + p_list[k + 1])
den = den * rho_list_minus_1
expo = (p_list[len(rho_list) - 1] + p_list[len(rho_list)] - deg_diff_new)
den = den * rho_list[len(rho_list) - 1]**expo
# the sign of the determinant depends on sg(num / den)
if sign(num / den) > 0:
subres_l.append( simplify(rho_1**degdif*a2* Abs(mul_fac_old) ) )
else:
subres_l.append(- simplify(rho_1**degdif*a2* Abs(mul_fac_old) ) )
# update Pell-Gordon variables
k = var('k')
rho_list.append( sign(rho2))
u = summation(k, (k, 1, p_list[len(p_list) - 1]))
u_list.append(u)
v = sum(p_list)
deg_diff_old=deg_diff_new
# main loop
while d2 > 0:
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
del0 = del1 # update degree difference
exp_deg = d1 - 1 # new expected degree
a2 = - rem(a0, a1, domain=QQ) # new remainder
rho3 = LC(a2, x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
deg_diff_new = exp_deg - d2 # expected - actual degree
del1 = d1 - d2 # degree difference
# take into consideration the power
# rho1**deg_diff_old that was "left out"
expo_old = deg_diff_old # rho1 raised to this power
expo_new = del0 + del1 - deg_diff_new # rho2 raised to this power
mul_fac_new = rho2**(expo_new) * rho1**(expo_old) * mul_fac_old
# update variables
deg_diff_old, mul_fac_old = deg_diff_new, mul_fac_new
rho1, rho2 = rho2, rho3
# update Pell-Gordon variables
p_list.append(1 + deg_diff_new) # deg_diff_new is 0 for complete seq
# apply Pell-Gordon formula (7) in second reference
num = 1 # numerator
for k in range(len(u_list)):
num *= (-1)**u_list[k]
num = num * (-1)**v
# denominator depends on complete / incomplete seq
if deg_diff_new == 0: # complete seq
den = 1
for k in range(len(rho_list)):
den *= rho_list[k]**(p_list[k] + p_list[k + 1])
den = den * rho_list_minus_1
else: # incomplete seq
den = 1
for k in range(len(rho_list)-1):
den *= rho_list[k]**(p_list[k] + p_list[k + 1])
den = den * rho_list_minus_1
expo = (p_list[len(rho_list) - 1] + p_list[len(rho_list)] - deg_diff_new)
den = den * rho_list[len(rho_list) - 1]**expo
# the sign of the determinant depends on sg(num / den)
if sign(num / den) > 0:
subres_l.append( simplify(rho_1**degdif*a2* Abs(mul_fac_old) ) )
else:
subres_l.append(- simplify(rho_1**degdif*a2* Abs(mul_fac_old) ) )
# update Pell-Gordon variables
k = var('k')
rho_list.append( sign(rho2))
u = summation(k, (k, 1, p_list[len(p_list) - 1]))
u_list.append(u)
v = sum(p_list)
# gcd is of degree > 0 ?
m = len(subres_l)
if subres_l[m - 1] == nan or subres_l[m - 1] == 0:
subres_l.pop(m - 1)
# LC( p ) < 0
m = len(subres_l) # list may be shorter now due to deg(gcd ) > 0
if LC( p ) < 0:
aux_seq = [subres_l[0], subres_l[1]]
for i in range(2, m):
aux_seq.append(simplify(subres_l[i] * (-1) ))
subres_l = aux_seq
return subres_l
def subresultants_pg(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant prs of p and q in Z[x] or Q[x], from
the modified subresultant prs of p and q.
The coefficients of the polynomials in these two sequences differ only
in sign and the factor LC(p)**( deg(p)- deg(q)) as stated in
Theorem 2 of the reference.
The coefficients of the polynomials in the output sequence are
subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester1, Sylvester's matrix of 1840.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ‘‘On the Remainders
Obtained in Finding the Greatest Common Divisor of Two Polynomials.''
Serdica Journal of Computing, to appear.
"""
# compute the modified subresultant prs
lst = modified_subresultants_pg(p,q,x) ## any other method would do
# defensive
if lst == [] or len(lst) == 2:
return lst
# the coefficients in lst are modified subresultants and, hence, are
# greater than those of the corresponding subresultants by the factor
# LC(lst[0])**( deg(lst[0]) - deg(lst[1])); see Theorem 2 in reference.
lcf = LC(lst[0])**( degree(lst[0], x) - degree(lst[1], x) )
# Initialize the subresultant prs list
subr_seq = [lst[0], lst[1]]
# compute the degree sequences m_i and j_i of Theorem 2 in reference.
deg_seq = [degree(Poly(poly, x), x) for poly in lst]
deg = deg_seq[0]
deg_seq_s = deg_seq[1:-1]
m_seq = [m-1 for m in deg_seq_s]
j_seq = [deg - m for m in m_seq]
# compute the AMV factors of Theorem 2 in reference.
fact = [(-1)**( j*(j-1)/S(2) ) for j in j_seq]
# shortened list without the first two polys
lst_s = lst[2:]
# poly lst_s[k] is multiplied times fact[k], divided by lcf
# and appended to the subresultant prs list
m = len(fact)
for k in range(m):
if sign(fact[k]) == -1:
subr_seq.append(-lst_s[k] / lcf)
else:
subr_seq.append(lst_s[k] / lcf)
return subr_seq
def subresultants_amv_q(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant prs of p and q in Q[x];
the coefficients of the polynomials in the sequence are
subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester1, Sylvester's matrix of 1840.
To compute the coefficients, no determinant evaluation takes place.
Instead, polynomial divisions in Q[x] are performed, using the
function rem(p, q, x); the coefficients of the remainders
computed this way become subresultants with the help of the
Akritas-Malaschonok-Vigklas Theorem of 2015.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial
remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].''
Submitted for publication.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
d0 = degree(p, x)
d1 = degree(q, x)
if d0 == 0 and d1 == 0:
return [p, q]
if d1 > d0:
d0, d1 = d1, d0
p, q = q, p
if d0 > 0 and d1 == 0:
return [p, q]
# initialize
i, s = 0, 0 # counters for remainders & odd elements
p_odd_index_sum = 0 # contains the sum of p_1, p_3, etc
subres_l = [p, q] # subresultant prs output list
a0, a1 = p, q # the input polys
sigma1 = LC(a1, x) # leading coeff of a1
p0 = d0 - d1 # degree difference
if p0 % 2 == 1:
s += 1
phi = floor( (s + 1) / 2 )
mul_fac = 1
d2 = d1
# main loop
while d2 > 0:
i += 1
a2 = rem(a0, a1, domain= QQ) # new remainder
if i == 1:
sigma2 = LC(a2, x)
else:
sigma3 = LC(a2, x)
sigma1, sigma2 = sigma2, sigma3
d2 = degree(a2, x)
p1 = d1 - d2
psi = i + phi + p_odd_index_sum
# new mul_fac
mul_fac = sigma1**(p0 + 1) * mul_fac
## compute the sign of the first fraction in formula (9) of the paper
# numerator
num = (-1)**psi
# denominator
den = sign(mul_fac)
# the sign of the determinant depends on sign( num / den ) != 0
if sign(num / den) > 0:
subres_l.append( simplify(expand(a2* Abs(mul_fac))))
else:
subres_l.append(- simplify(expand(a2* Abs(mul_fac))))
## bring into mul_fac the missing power of sigma if there was a degree gap
if p1 - 1 > 0:
mul_fac = mul_fac * sigma1**(p1 - 1)
# update AMV variables
a0, a1, d0, d1 = a1, a2, d1, d2
p0 = p1
if p0 % 2 ==1:
s += 1
phi = floor( (s + 1) / 2 )
if i%2 == 1:
p_odd_index_sum += p0 # p_i has odd index
# gcd is of degree > 0 ?
m = len(subres_l)
if subres_l[m - 1] == nan or subres_l[m - 1] == 0:
subres_l.pop(m - 1)
return subres_l
def compute_sign(base, expo):
'''
base != 0 and expo >= 0 are integers;
returns the sign of base**expo without
evaluating the power itself!
'''
sb = sign(base)
if sb == 1:
return 1
pe = expo % 2
if pe == 0:
return -sb
else:
return sb
def rem_z(p, q, x):
'''
Intended mainly for p, q polynomials in Z[x] so that,
on dividing p by q, the remainder will also be in Z[x]. (However,
it also works fine for polynomials in Q[x].) It is assumed
that degree(p, x) >= degree(q, x).
It premultiplies p by the _absolute_ value of the leading coefficient
of q, raised to the power deg(p) - deg(q) + 1 and then performs
polynomial division in Q[x], using the function rem(p, q, x).
By contrast the function prem(p, q, x) does _not_ use the absolute
value of the leading coefficient of q.
This results not only in ``messing up the signs'' of the Euclidean and
Sturmian prs's as mentioned in the second reference,
but also in violation of the main results of the first and third
references --- Theorem 4 and Theorem 1 respectively. Theorems 4 and 1
establish a one-to-one correspondence between the Euclidean and the
Sturmian prs of p, q, on one hand, and the subresultant prs of p, q,
on the other.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders
Obtained in Finding the Greatest Common Divisor of Two Polynomials.''
Serdica Journal of Computing, to appear.
2. http://planetMath.org/sturmstheorem
3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on
the Theory of Subresultants.'' Submitted for publication.
'''
delta = (degree(p, x) - degree(q, x) + 1)
return rem(Abs(LC(q, x))**delta * p, q, x)
def quo_z(p, q, x):
"""
Intended mainly for p, q polynomials in Z[x] so that,
on dividing p by q, the quotient will also be in Z[x]. (However,
it also works fine for polynomials in Q[x].) It is assumed
that degree(p, x) >= degree(q, x).
It premultiplies p by the _absolute_ value of the leading coefficient
of q, raised to the power deg(p) - deg(q) + 1 and then performs
polynomial division in Q[x], using the function quo(p, q, x).
By contrast the function pquo(p, q, x) does _not_ use the absolute
value of the leading coefficient of q.
See also function rem_z(p, q, x) for additional comments and references.
"""
delta = (degree(p, x) - degree(q, x) + 1)
return quo(Abs(LC(q, x))**delta * p, q, x)
def subresultants_amv(f, g, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(f, x) >= degree(g, x).
Computes the subresultant prs of p and q in Z[x] or Q[x];
the coefficients of the polynomials in the sequence are
subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester1, Sylvester's matrix of 1840.
To compute the coefficients, no determinant evaluation takes place.
Instead, polynomial divisions in Z[x] or Q[x] are performed, using
the function rem_z(p, q, x); the coefficients of the remainders
computed this way become subresultants with the help of the
Akritas-Malaschonok-Vigklas Theorem of 2015 and the Collins-Brown-
Traub formula for coefficient reduction.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result
on the Theory of Subresultants.'' Submitted for publication.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial
remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].''
Submitted for publication.
"""
# make sure neither f nor g is 0
if f == 0 or g == 0:
return [f, g]
# make sure proper degrees
d0 = degree(f, x)
d1 = degree(g, x)
if d0 == 0 and d1 == 0:
return [f, g]
if d1 > d0:
d0, d1 = d1, d0
f, g = g, f
if d0 > 0 and d1 == 0:
return [f, g]
# initialize
a0 = f
a1 = g
subres_l = [a0, a1]
deg_dif_p1, c = degree(a0, x) - degree(a1, x) + 1, -1
# initialize AMV variables
sigma1 = LC(a1, x) # leading coeff of a1
i, s = 0, 0 # counters for remainders & odd elements
p_odd_index_sum = 0 # contains the sum of p_1, p_3, etc
p0 = deg_dif_p1 - 1
if p0 % 2 == 1:
s += 1
phi = floor( (s + 1) / 2 )
# compute the first polynomial of the prs
i += 1
a2 = rem_z(a0, a1, x) / Abs( (-1)**deg_dif_p1 ) # first remainder
sigma2 = LC(a2, x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
p1 = d1 - d2 # degree difference
# sgn_den is the factor, the denominator 1st fraction of (9),
# by which a2 is multiplied to get integer coefficients
sgn_den = compute_sign( sigma1, p0 + 1 )
## compute sign of the 1st fraction in formula (9) of the paper
# numerator
psi = i + phi + p_odd_index_sum
num = (-1)**psi
# denominator
den = sgn_den
# the sign of the determinant depends on sign(num / den) != 0
if sign(num / den) > 0:
subres_l.append( a2 )
else:
subres_l.append( -a2 )
# update AMV variable
if p1 % 2 == 1:
s += 1
# bring in the missing power of sigma if there was gap
if p1 - 1 > 0:
sgn_den = sgn_den * compute_sign( sigma1, p1 - 1 )
# main loop
while d2 >= 1:
phi = floor( (s + 1) / 2 )
if i%2 == 1:
p_odd_index_sum += p1 # p_i has odd index
a0, a1, d0, d1 = a1, a2, d1, d2 # update polys and degrees
p0 = p1 # update degree difference
i += 1
sigma0 = -LC(a0)
c = (sigma0**(deg_dif_p1 - 1)) / (c**(deg_dif_p1 - 2))
deg_dif_p1 = degree(a0, x) - d2 + 1
a2 = rem_z(a0, a1, x) / Abs( ((c**(deg_dif_p1 - 1)) * sigma0) )
sigma3 = LC(a2, x) # leading coeff of a2
d2 = degree(a2, x) # actual degree of a2
p1 = d1 - d2 # degree difference
psi = i + phi + p_odd_index_sum
# update variables
sigma1, sigma2 = sigma2, sigma3
# new sgn_den
sgn_den = compute_sign( sigma1, p0 + 1 ) * sgn_den
# compute the sign of the first fraction in formula (9) of the paper
# numerator
num = (-1)**psi
# denominator
den = sgn_den
# the sign of the determinant depends on sign( num / den ) != 0
if sign(num / den) > 0:
subres_l.append( a2 )
else:
subres_l.append( -a2 )
# update AMV variable
if p1 % 2 ==1:
s += 1
# bring in the missing power of sigma if there was gap
if p1 - 1 > 0:
sgn_den = sgn_den * compute_sign( sigma1, p1 - 1 )
# gcd is of degree > 0 ?
m = len(subres_l)
if subres_l[m - 1] == nan or subres_l[m - 1] == 0:
subres_l.pop(m - 1)
return subres_l
def modified_subresultants_amv(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the modified subresultant prs of p and q in Z[x] or Q[x],
from the subresultant prs of p and q.
The coefficients of the polynomials in the two sequences differ only
in sign and the factor LC(p)**( deg(p)- deg(q)) as stated in
Theorem 2 of the reference.
The coefficients of the polynomials in the output sequence are
modified subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester2, Sylvester's matrix of 1853.
If the modified subresultant prs is complete, and LC( p ) > 0, it coincides
with the (generalized) Sturm's sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ‘‘On the Remainders
Obtained in Finding the Greatest Common Divisor of Two Polynomials.''
Serdica Journal of Computing, to appear.
"""
# compute the subresultant prs
lst = subresultants_amv(p,q,x) ## any other method would do
# defensive
if lst == [] or len(lst) == 2:
return lst
# the coefficients in lst are subresultants and, hence, smaller than those
# of the corresponding modified subresultants by the factor
# LC(lst[0])**( deg(lst[0]) - deg(lst[1])); see Theorem 2.
lcf = LC(lst[0])**( degree(lst[0], x) - degree(lst[1], x) )
# Initialize the modified subresultant prs list
subr_seq = [lst[0], lst[1]]
# compute the degree sequences m_i and j_i of Theorem 2
deg_seq = [degree(Poly(poly, x), x) for poly in lst]
deg = deg_seq[0]
deg_seq_s = deg_seq[1:-1]
m_seq = [m-1 for m in deg_seq_s]
j_seq = [deg - m for m in m_seq]
# compute the AMV factors of Theorem 2
fact = [(-1)**( j*(j-1)/S(2) ) for j in j_seq]
# shortened list without the first two polys
lst_s = lst[2:]
# poly lst_s[k] is multiplied times fact[k] and times lcf
# and appended to the subresultant prs list
m = len(fact)
for k in range(m):
if sign(fact[k]) == -1:
subr_seq.append( simplify(-lst_s[k] * lcf) )
else:
subr_seq.append( simplify(lst_s[k] * lcf) )
return subr_seq
def correct_sign(deg_f, deg_g, s1, rdel, cdel):
"""
Used in various subresultant prs algorithms.
Evaluates the determinant, (a.k.a. subresultant) of a properly selected
submatrix of s1, Sylvester's matrix of 1840, to get the correct sign
and value of the leading coefficient of a given polynomial remainder.
deg_f, deg_g are the degrees of the original polynomials p, q for which the
matrix s1 = sylvester(p, q, x, 1) was constructed.
rdel denotes the expected degree of the remainder; it is the number of
rows to be deleted from each group of rows in s1 as described in the
reference below.
cdel denotes the expected degree minus the actual degree of the remainder;
it is the number of columns to be deleted --- starting with the last column
forming the square matrix --- from the matrix resulting after the row deletions.
References:
===========
Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences
and Modified Subresultant Polynomial Remainder Sequences.''
Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.
"""
M = s1[:, :] # copy of matrix s1
# eliminate rdel rows from the first deg_g rows
for i in range(M.rows - deg_f - 1, M.rows - deg_f - rdel - 1, -1):
M.row_del(i)
# eliminate rdel rows from the last deg_f rows
for i in range(M.rows - 1, M.rows - rdel - 1, -1):
M.row_del(i)
# eliminate cdel columns
for i in range(cdel):
M.col_del(M.rows - 1)
# define submatrix
Md = M[:, 0: M.rows]
return Md.det()
def subresultants_rem(p, q, x):
"""
p, q are polynomials in Z[x] or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant prs of p and q in Z[x] or Q[x];
the coefficients of the polynomials in the sequence are
subresultants. That is, they are determinants of appropriately
selected submatrices of sylvester1, Sylvester's matrix of 1840.
To compute the coefficients polynomial divisions in Q[x] are
performed, using the function rem(p, q, x). The coefficients
of the remainders computed this way become subresultants by evaluating
one subresultant per remainder --- that of the leading coefficient.
This way we obtain the correct sign and value of the leading coefficient
of the remainder and we easily ``force'' the rest of the coefficients
to become subresultants.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G.:``Three New Methods for Computing Subresultant
Polynomial Remainder Sequences (PRS’s).'' Serdica Journal of Computing,
to appear.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
f, g = p, q
n = deg_f = degree(f, x)
m = deg_g = degree(g, x)
if n == 0 and m == 0:
return [f, g]
if n < m:
n, m, deg_f, deg_g, f, g = m, n, deg_g, deg_f, g, f
if n > 0 and m == 0:
return [f, g]
# initialize
s1 = sylvester(f, g, x, 1)
sr_list = [f, g] # subresultant list
# main loop
while deg_g > 0:
r = rem(p, q, x)
d = degree(r, x)
if d < 0:
return sr_list
# make coefficients subresultants evaluating ONE determinant
exp_deg = deg_g - 1 # expected degree
sign_value = correct_sign(n, m, s1, exp_deg, exp_deg - d)
r = simplify((r / LC(r, x)) * sign_value)
# append poly with subresultant coeffs
sr_list.append(r)
# update degrees and polys
deg_f, deg_g = deg_g, d
p, q = q, r
# gcd is of degree > 0 ?
m = len(sr_list)
if sr_list[m - 1] == nan or sr_list[m - 1] == 0:
sr_list.pop(m - 1)
return sr_list
def pivot(M, i, j):
'''
M is a matrix, and M[i, j] specifies the pivot element.
All elements below M[i, j], in the j-th column, will
be zeroed, if they are not already 0, according to
Dodgson-Bareiss' integer preserving transformations.
References:
===========
1. Akritas, A. G.: ``A new method for computing polynomial greatest
common divisors and polynomial remainder sequences.''
Numerische MatheMatik 52, 119-127, 1988.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem
by Van Vleck Regarding Sturm Sequences.''
Serdica Journal of Computing, 7, No 4, 101–134, 2013.
'''
ma = M[:, :] # copy of matrix M
rs = ma.rows # No. of rows
cs = ma.cols # No. of cols
for r in range(i+1, rs):
if ma[r, j] != 0:
for c in range(j + 1, cs):
ma[r, c] = ma[i, j] * ma[r, c] - ma[i, c] * ma[r, j]
ma[r, j] = 0
return ma
def rotate_r(L, k):
'''
Rotates right by k. L is a row of a matrix or a list.
'''
ll = list(L)
if ll == []:
return []
for i in range(k):
el = ll.pop(len(ll) - 1)
ll.insert(0, el)
return ll if type(L) is list else Matrix([ll])
def rotate_l(L, k):
'''
Rotates left by k. L is a row of a matrix or a list.
'''
ll = list(L)
if ll == []:
return []
for i in range(k):
el = ll.pop(0)
ll.insert(len(ll) - 1, el)
return ll if type(L) is list else Matrix([ll])
def row2poly(row, deg, x):
'''
Converts the row of a matrix to a poly of degree deg and variable x.
Some entries at the beginning and/or at the end of the row may be zero.
'''
k = 0
poly = []
leng = len(row)
# find the beginning of the poly ; i.e. the first
# non-zero element of the row
while row[k] == 0:
k = k + 1
# append the next deg + 1 elements to poly
for j in range( deg + 1):
if k + j <= leng:
poly.append(row[k + j])
return Poly(poly, x)
def create_ma(deg_f, deg_g, row1, row2, col_num):
'''
Creates a ``small'' matrix M to be triangularized.
deg_f, deg_g are the degrees of the divident and of the
divisor polynomials respectively, deg_g > deg_f.
The coefficients of the divident poly are the elements
in row2 and those of the divisor poly are the elements
in row1.
col_num defines the number of columns of the matrix M.
'''
if deg_g - deg_f >= 1:
print('Reverse degrees')
return
m = zeros(deg_f - deg_g + 2, col_num)
for i in range(deg_f - deg_g + 1):
m[i, :] = rotate_r(row1, i)
m[deg_f - deg_g + 1, :] = row2
return m
def find_degree(M, deg_f):
'''
Finds the degree of the poly corresponding (after triangularization)
to the _last_ row of the ``small'' matrix M, created by create_ma().
deg_f is the degree of the divident poly.
If _last_ row is all 0's returns None.
'''
j = deg_f
for i in range(0, M.cols):
if M[M.rows - 1, i] == 0:
j = j - 1
else:
return j if j >= 0 else 0
def final_touches(s2, r, deg_g):
"""
s2 is sylvester2, r is the row pointer in s2,
deg_g is the degree of the poly last inserted in s2.
After a gcd of degree > 0 has been found with Van Vleck's
method, and was inserted into s2, if its last term is not
in the last column of s2, then it is inserted as many
times as needed, rotated right by one each time, until
the condition is met.
"""
R = s2.row(r-1)
# find the first non zero term
for i in range(s2.cols):
if R[0,i] == 0:
continue
else:
break
# missing rows until last term is in last column
mr = s2.cols - (i + deg_g + 1)
# insert them by replacing the existing entries in the row
i = 0
while mr != 0 and r + i < s2.rows :
s2[r + i, : ] = rotate_r(R, i + 1)
i += 1
mr -= 1
return s2
def subresultants_vv(p, q, x, method = 0):
"""
p, q are polynomials in Z[x] (intended) or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant prs of p, q by triangularizing,
in Z[x] or in Q[x], all the smaller matrices encountered in the
process of triangularizing sylvester2, Sylvester's matrix of 1853;
see references 1 and 2 for Van Vleck's method. With each remainder,
sylvester2 gets updated and is prepared to be printed if requested.
If sylvester2 has small dimensions and you want to see the final,
triangularized matrix use this version with method=1; otherwise,
use either this version with method=0 (default) or the faster version,
subresultants_vv_2(p, q, x), where sylvester2 is used implicitly.
Sylvester's matrix sylvester1 is also used to compute one
subresultant per remainder; namely, that of the leading
coefficient, in order to obtain the correct sign and to
force the remainder coefficients to become subresultants.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
If the final, triangularized matrix s2 is printed, then:
(a) if deg(p) - deg(q) > 1 or deg( gcd(p, q) ) > 0, several
of the last rows in s2 will remain unprocessed;
(b) if deg(p) - deg(q) == 0, p will not appear in the final matrix.
References:
===========
1. Akritas, A. G.: ``A new method for computing polynomial greatest
common divisors and polynomial remainder sequences.''
Numerische MatheMatik 52, 119-127, 1988.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem
by Van Vleck Regarding Sturm Sequences.''
Serdica Journal of Computing, 7, No 4, 101–134, 2013.
3. Akritas, A. G.:``Three New Methods for Computing Subresultant
Polynomial Remainder Sequences (PRS’s).'' Serdica Journal of Computing,
to appear.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
f, g = p, q
n = deg_f = degree(f, x)
m = deg_g = degree(g, x)
if n == 0 and m == 0:
return [f, g]
if n < m:
n, m, deg_f, deg_g, f, g = m, n, deg_g, deg_f, g, f
if n > 0 and m == 0:
return [f, g]
# initialize
s1 = sylvester(f, g, x, 1)
s2 = sylvester(f, g, x, 2)
sr_list = [f, g]
col_num = 2 * n # columns in s2
# make two rows (row0, row1) of poly coefficients
row0 = Poly(f, x, domain = QQ).all_coeffs()
leng0 = len(row0)
for i in range(col_num - leng0):
row0.append(0)
row0 = Matrix([row0])
row1 = Poly(g,x, domain = QQ).all_coeffs()
leng1 = len(row1)
for i in range(col_num - leng1):
row1.append(0)
row1 = Matrix([row1])
# row pointer for deg_f - deg_g == 1; may be reset below
r = 2
# modify first rows of s2 matrix depending on poly degrees
if deg_f - deg_g > 1:
r = 1
# replacing the existing entries in the rows of s2,
# insert row0 (deg_f - deg_g - 1) times, rotated each time
for i in range(deg_f - deg_g - 1):
s2[r + i, : ] = rotate_r(row0, i + 1)
r = r + deg_f - deg_g - 1
# insert row1 (deg_f - deg_g) times, rotated each time
for i in range(deg_f - deg_g):
s2[r + i, : ] = rotate_r(row1, r + i)
r = r + deg_f - deg_g
if deg_f - deg_g == 0:
r = 0
# main loop
while deg_g > 0:
# create a small matrix M, and triangularize it;
M = create_ma(deg_f, deg_g, row1, row0, col_num)
# will need only the first and last rows of M
for i in range(deg_f - deg_g + 1):
M1 = pivot(M, i, i)
M = M1[:, :]
# treat last row of M as poly; find its degree
d = find_degree(M, deg_f)
if d == None:
break
exp_deg = deg_g - 1
# evaluate one determinant & make coefficients subresultants
sign_value = correct_sign(n, m, s1, exp_deg, exp_deg - d)
poly = row2poly(M[M.rows - 1, :], d, x)
temp2 = LC(poly, x)
poly = simplify((poly / temp2) * sign_value)
# update s2 by inserting first row of M as needed
row0 = M[0, :]
for i in range(deg_g - d):
s2[r + i, :] = rotate_r(row0, r + i)
r = r + deg_g - d
# update s2 by inserting last row of M as needed
row1 = rotate_l(M[M.rows - 1, :], deg_f - d)
row1 = (row1 / temp2) * sign_value
for i in range(deg_g - d):
s2[r + i, :] = rotate_r(row1, r + i)
r = r + deg_g - d
# update degrees
deg_f, deg_g = deg_g, d
# append poly with subresultant coeffs
sr_list.append(poly)
# final touches to print the s2 matrix
if method != 0 and s2.rows > 2:
s2 = final_touches(s2, r, deg_g)
pprint(s2)
elif method != 0 and s2.rows == 2:
s2[1, :] = rotate_r(s2.row(1), 1)
pprint(s2)
return sr_list
def subresultants_vv_2(p, q, x):
"""
p, q are polynomials in Z[x] (intended) or Q[x]. It is assumed
that degree(p, x) >= degree(q, x).
Computes the subresultant prs of p, q by triangularizing,
in Z[x] or in Q[x], all the smaller matrices encountered in the
process of triangularizing sylvester2, Sylvester's matrix of 1853;
see references 1 and 2 for Van Vleck's method.
If the sylvester2 matrix has big dimensions use this version,
where sylvester2 is used implicitly. If you want to see the final,
triangularized matrix sylvester2, then use the first version,
subresultants_vv(p, q, x, 1).
sylvester1, Sylvester's matrix of 1840, is also used to compute
one subresultant per remainder; namely, that of the leading
coefficient, in order to obtain the correct sign and to
``force'' the remainder coefficients to become subresultants.
If the subresultant prs is complete, then it coincides with the
Euclidean sequence of the polynomials p, q.
References:
===========
1. Akritas, A. G.: ``A new method for computing polynomial greatest
common divisors and polynomial remainder sequences.''
Numerische MatheMatik 52, 119-127, 1988.
2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem
by Van Vleck Regarding Sturm Sequences.''
Serdica Journal of Computing, 7, No 4, 101–134, 2013.
3. Akritas, A. G.:``Three New Methods for Computing Subresultant
Polynomial Remainder Sequences (PRS’s).'' Serdica Journal of Computing,
to appear.
"""
# make sure neither p nor q is 0
if p == 0 or q == 0:
return [p, q]
# make sure proper degrees
f, g = p, q
n = deg_f = degree(f, x)
m = deg_g = degree(g, x)
if n == 0 and m == 0:
return [f, g]
if n < m:
n, m, deg_f, deg_g, f, g = m, n, deg_g, deg_f, g, f
if n > 0 and m == 0:
return [f, g]
# initialize
s1 = sylvester(f, g, x, 1)
sr_list = [f, g] # subresultant list
col_num = 2 * n # columns in sylvester2
# make two rows (row0, row1) of poly coefficients
row0 = Poly(f, x, domain = QQ).all_coeffs()
leng0 = len(row0)
for i in range(col_num - leng0):
row0.append(0)
row0 = Matrix([row0])
row1 = Poly(g,x, domain = QQ).all_coeffs()
leng1 = len(row1)
for i in range(col_num - leng1):
row1.append(0)
row1 = Matrix([row1])
# main loop
while deg_g > 0:
# create a small matrix M, and triangularize it
M = create_ma(deg_f, deg_g, row1, row0, col_num)
for i in range(deg_f - deg_g + 1):
M1 = pivot(M, i, i)
M = M1[:, :]
# treat last row of M as poly; find its degree
d = find_degree(M, deg_f)
if d == None:
return sr_list
exp_deg = deg_g - 1
# evaluate one determinant & make coefficients subresultants
sign_value = correct_sign(n, m, s1, exp_deg, exp_deg - d)
poly = row2poly(M[M.rows - 1, :], d, x)
poly = simplify((poly / LC(poly, x)) * sign_value)
# append poly with subresultant coeffs
sr_list.append(poly)
# update degrees and rows
deg_f, deg_g = deg_g, d
row0 = row1
row1 = Poly(poly, x, domain = QQ).all_coeffs()
leng1 = len(row1)
for i in range(col_num - leng1):
row1.append(0)
row1 = Matrix([row1])
return sr_list
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2765,
859,
3509,
3423,
367,
314,
14009,
199,
1618,
662,
24941,
12,
8605,
1759,
1933,
300,
2664,
290,
436,
334,
5540,
9,
1007,
1099,
867,
199,
22104,
15748,
8013,
334,
80,
2393,
1159,
680,
199,
199,
1918,
15984,
13,
23850,
805,
876,
77,
342,
402,
5840,
365,
485,
1397,
63,
1202,
199,
991,
1263,
402,
314,
3423,
315,
314,
859,
14,
199,
199,
13962,
13558,
402,
876,
77,
342,
781,
675,
314,
805,
199,
199,
13179,
63,
90,
1252,
199,
199,
607,
3331,
365,
2597,
314,
805,
28419,
63,
90,
1252,
199,
199,
17,
14,
710,
720,
3294,
8020,
26,
199,
1280,
17575,
199,
714,
16994,
314,
27599,
289,
12,
486,
22410,
231,
231,
3107,
59,
88,
61,
402,
14358,
7926,
8,
70,
9,
275,
302,
436,
199,
6458,
8,
71,
9,
275,
333,
543,
302,
22410,
232,
99,
333,
14,
199,
199,
10701,
413,
26,
199,
9152,
199,
1918,
2070,
3414,
402,
282,
11849,
15748,
3414,
334,
80,
2393,
9,
365,
314,
199,
4041,
402,
27624,
402,
314,
9186,
12343,
402,
2399,
27599,
14,
199,
199,
4940,
8013,
883,
506,
9235,
543,
314,
805,
26,
199,
199,
1037,
63,
3610,
8,
6023,
63,
3610,
12,
671,
9,
199,
199,
10701,
499,
26,
199,
9152,
199,
33,
11849,
15748,
3414,
334,
80,
2393,
9,
365,
2797,
4890,
340,
314,
199,
10956,
8865,
3382,
1263,
2877,
23376,
27599,
365,
413,
27,
199,
26617,
12,
652,
2797,
17110,
14,
199,
199,
7940,
365,
1334,
14308,
364,
626,
289,
12,
486,
13511,
370,
314,
8013,
26239,
315,
199,
1589,
2877,
10269,
14,
199,
199,
17,
33,
14,
662,
24941,
436,
1007,
1099,
867,
299,
2393,
1159,
26,
199,
2486,
19989,
199,
1918,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
365,
282,
3414,
402,
27599,
315,
3107,
59,
88,
61,
199,
290,
2548,
1785,
370,
314,
662,
24941,
299,
2393,
12,
314,
3414,
15884,
701,
18876,
199,
265,
289,
12,
486,
662,
947,
7401,
21045,
83,
5563,
367,
11849,
486,
622,
270,
2863,
487,
27215,
199,
8,
22795,
9,
315,
1413,
59,
88,
1055,
199,
199,
1918,
1007,
1099,
867,
299,
2393,
22754,
687,
314,
662,
24941,
299,
2393,
315,
626,
314,
199,
30477,
402,
1924,
11849,
315,
314,
26610,
3414,
787,
4563,
2285,
199,
2595,
2597,
25713,
370,
465,
1007,
1099,
2285,
10894,
402,
22497,
4895,
199,
954,
13,
19032,
402,
1847,
24279,
351,
17,
8,
70,
12,
486,
12,
671,
395,
5515,
24279,
351,
21045,
83,
3634,
402,
413,
13462,
402,
199,
13320,
334,
78,
435,
333,
9,
13333,
246,
334,
78,
435,
333,
680,
199,
199,
497,
1250,
626,
314,
4563,
867,
402,
1847,
24279,
351,
17,
8,
70,
12,
486,
12,
671,
9,
6337,
365,
199,
3527,
314,
754,
867,
402,
289,
12,
486,
436,
23739,
465,
282,
17392,
402,
3775,
199,
1589,
2877,
27599,
1172,
2863,
14361,
503,
440,
14,
199,
199,
607,
5840,
314,
754,
867,
365,
9235,
543,
314,
805,
199,
1099,
867,
8,
70,
12,
486,
12,
671,
680,
961,
805,
1630,
485,
1397,
63,
9352,
314,
199,
17061,
867,
402,
1847,
24279,
351,
8,
70,
12,
486,
12,
671,
12,
413,
2736,
3140,
12,
652,
2529,
199,
1589,
2061,
3653,
402,
314,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
12,
29597,
199,
8,
692,
4346,
9,
701,
376,
5827,
7074,
402,
446,
17,
27,
1937,
314,
286,
811,
292,
5084,
14,
199,
199,
35,
811,
292,
26,
982,
577,
70,
275,
13666,
8,
70,
12,
671,
9,
436,
577,
71,
275,
13666,
8,
71,
12,
671,
395,
2066,
26,
199,
199,
1099,
867,
8,
70,
12,
486,
12,
671,
9,
275,
5868,
17,
25288,
36,
70,
10,
36,
71,
9,
627,
754,
867,
8,
71,
12,
289,
12,
671,
680,
199,
199,
1858,
4890,
299,
2393,
21045,
83,
314,
2070,
3414,
402,
314,
662,
24941,
299,
2393,
402,
289,
12,
486,
199,
374,
13130,
370,
314,
2070,
3414,
402,
314,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
199,
460,
314,
12343,
402,
1373,
3414,
221,
787,
16174,
9235,
687,
314,
199,
30477,
402,
314,
221,
1163,
14,
199,
199,
1858,
17110,
299,
2393,
21045,
83,
314,
27599,
315,
314,
1007,
1099,
867,
299,
2393,
12,
16711,
199,
328,
1260,
315,
2070,
687,
5204,
402,
314,
662,
24941,
299,
2393,
12,
436,
10894,
29750,
314,
199,
2546,
402,
4890,
299,
2393,
21045,
83,
10894,
652,
365,
440,
737,
1006,
25259,
4212,
370,
4526,
199,
1589,
12343,
402,
1373,
3414,
687,
314,
12343,
402,
314,
221,
1163,
14,
199,
199,
17,
34,
14,
1933,
300,
2664,
290,
436,
6042,
1007,
1099,
867,
299,
2393,
1159,
26,
199,
2486,
9152,
199,
1858,
314,
2011,
27599,
289,
12,
486,
22410,
231,
231,
3107,
59,
88,
61,
26239,
3432,
12,
3932,
1124,
5540,
891,
199,
954,
1099,
867,
299,
2393,
365,
282,
3414,
402,
27599,
8545,
370,
314,
1933,
300,
2664,
290,
199,
80,
2393,
12,
314,
3414,
15884,
701,
18876,
315,
1413,
59,
88,
61,
1933,
12410,
21045,
83,
5563,
641,
289,
12,
486,
14,
199,
199,
1918,
2877,
8013,
14460,
315,
626,
314,
12343,
402,
1924,
11849,
199,
262,
314,
6042,
1007,
1099,
867,
299,
2393,
787,
314,
4563,
2285,
10894,
2597,
25713,
199,
475,
465,
6042,
1007,
1099,
2285,
10894,
402,
22497,
4895,
221,
1007,
13,
19032,
199,
1618,
1847,
24279,
351,
18,
8,
70,
12,
486,
12,
671,
395,
5515,
24279,
351,
21045,
83,
3634,
402,
413,
23901,
402,
7365,
499,
78,
13333,
246,
499,
78,
14,
199,
199,
1918,
4563,
867,
402,
1847,
24279,
351,
18,
6337,
365,
2797,
314,
6042,
754,
867,
199,
1618,
289,
12,
486,
436,
652,
2597,
883,
14062,
465,
282,
17392,
402,
3775,
314,
2877,
199,
22104,
83,
1172,
2863,
14361,
503,
440,
14,
199,
199,
1858,
4890,
299,
2393,
21045,
83,
314,
221,
2070,
3414,
402,
314,
1933,
300,
2664,
290,
299,
2393,
402,
289,
12,
486,
365,
199,
14576,
370,
314,
2070,
3414,
402,
314,
6042,
1007,
1099,
867,
299,
2393,
402,
199,
70,
12,
486,
436,
314,
12343,
402,
1373,
3414,
221,
787,
16174,
9235,
687,
199,
1589,
12343,
402,
314,
1163,
14,
199
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2765,
859,
3509,
3423,
367,
314,
14009,
199,
1618,
662,
24941,
12,
8605,
1759,
1933,
300,
2664,
290,
436,
334,
5540,
9,
1007,
1099,
867,
199,
22104,
15748,
8013,
334,
80,
2393,
1159,
680,
199,
199,
1918,
15984,
13,
23850,
805,
876,
77,
342,
402,
5840,
365,
485,
1397,
63,
1202,
199,
991,
1263,
402,
314,
3423,
315,
314,
859,
14,
199,
199,
13962,
13558,
402,
876,
77,
342,
781,
675,
314,
805,
199,
199,
13179,
63,
90,
1252,
199,
199,
607,
3331,
365,
2597,
314,
805,
28419,
63,
90,
1252,
199,
199,
17,
14,
710,
720,
3294,
8020,
26,
199,
1280,
17575,
199,
714,
16994,
314,
27599,
289,
12,
486,
22410,
231,
231,
3107,
59,
88,
61,
402,
14358,
7926,
8,
70,
9,
275,
302,
436,
199,
6458,
8,
71,
9,
275,
333,
543,
302,
22410,
232,
99,
333,
14,
199,
199,
10701,
413,
26,
199,
9152,
199,
1918,
2070,
3414,
402,
282,
11849,
15748,
3414,
334,
80,
2393,
9,
365,
314,
199,
4041,
402,
27624,
402,
314,
9186,
12343,
402,
2399,
27599,
14,
199,
199,
4940,
8013,
883,
506,
9235,
543,
314,
805,
26,
199,
199,
1037,
63,
3610,
8,
6023,
63,
3610,
12,
671,
9,
199,
199,
10701,
499,
26,
199,
9152,
199,
33,
11849,
15748,
3414,
334,
80,
2393,
9,
365,
2797,
4890,
340,
314,
199,
10956,
8865,
3382,
1263,
2877,
23376,
27599,
365,
413,
27,
199,
26617,
12,
652,
2797,
17110,
14,
199,
199,
7940,
365,
1334,
14308,
364,
626,
289,
12,
486,
13511,
370,
314,
8013,
26239,
315,
199,
1589,
2877,
10269,
14,
199,
199,
17,
33,
14,
662,
24941,
436,
1007,
1099,
867,
299,
2393,
1159,
26,
199,
2486,
19989,
199,
1918,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
365,
282,
3414,
402,
27599,
315,
3107,
59,
88,
61,
199,
290,
2548,
1785,
370,
314,
662,
24941,
299,
2393,
12,
314,
3414,
15884,
701,
18876,
199,
265,
289,
12,
486,
662,
947,
7401,
21045,
83,
5563,
367,
11849,
486,
622,
270,
2863,
487,
27215,
199,
8,
22795,
9,
315,
1413,
59,
88,
1055,
199,
199,
1918,
1007,
1099,
867,
299,
2393,
22754,
687,
314,
662,
24941,
299,
2393,
315,
626,
314,
199,
30477,
402,
1924,
11849,
315,
314,
26610,
3414,
787,
4563,
2285,
199,
2595,
2597,
25713,
370,
465,
1007,
1099,
2285,
10894,
402,
22497,
4895,
199,
954,
13,
19032,
402,
1847,
24279,
351,
17,
8,
70,
12,
486,
12,
671,
395,
5515,
24279,
351,
21045,
83,
3634,
402,
413,
13462,
402,
199,
13320,
334,
78,
435,
333,
9,
13333,
246,
334,
78,
435,
333,
680,
199,
199,
497,
1250,
626,
314,
4563,
867,
402,
1847,
24279,
351,
17,
8,
70,
12,
486,
12,
671,
9,
6337,
365,
199,
3527,
314,
754,
867,
402,
289,
12,
486,
436,
23739,
465,
282,
17392,
402,
3775,
199,
1589,
2877,
27599,
1172,
2863,
14361,
503,
440,
14,
199,
199,
607,
5840,
314,
754,
867,
365,
9235,
543,
314,
805,
199,
1099,
867,
8,
70,
12,
486,
12,
671,
680,
961,
805,
1630,
485,
1397,
63,
9352,
314,
199,
17061,
867,
402,
1847,
24279,
351,
8,
70,
12,
486,
12,
671,
12,
413,
2736,
3140,
12,
652,
2529,
199,
1589,
2061,
3653,
402,
314,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
12,
29597,
199,
8,
692,
4346,
9,
701,
376,
5827,
7074,
402,
446,
17,
27,
1937,
314,
286,
811,
292,
5084,
14,
199,
199,
35,
811,
292,
26,
982,
577,
70,
275,
13666,
8,
70,
12,
671,
9,
436,
577,
71,
275,
13666,
8,
71,
12,
671,
395,
2066,
26,
199,
199,
1099,
867,
8,
70,
12,
486,
12,
671,
9,
275,
5868,
17,
25288,
36,
70,
10,
36,
71,
9,
627,
754,
867,
8,
71,
12,
289,
12,
671,
680,
199,
199,
1858,
4890,
299,
2393,
21045,
83,
314,
2070,
3414,
402,
314,
662,
24941,
299,
2393,
402,
289,
12,
486,
199,
374,
13130,
370,
314,
2070,
3414,
402,
314,
1007,
1099,
867,
299,
2393,
402,
289,
12,
486,
199,
460,
314,
12343,
402,
1373,
3414,
221,
787,
16174,
9235,
687,
314,
199,
30477,
402,
314,
221,
1163,
14,
199,
199,
1858,
17110,
299,
2393,
21045,
83,
314,
27599,
315,
314,
1007,
1099,
867,
299,
2393,
12,
16711,
199,
328,
1260,
315,
2070,
687,
5204,
402,
314,
662,
24941,
299,
2393,
12,
436,
10894,
29750,
314,
199,
2546,
402,
4890,
299,
2393,
21045,
83,
10894,
652,
365,
440,
737,
1006,
25259,
4212,
370,
4526,
199,
1589,
12343,
402,
1373,
3414,
687,
314,
12343,
402,
314,
221,
1163,
14,
199,
199,
17,
34,
14,
1933,
300,
2664,
290,
436,
6042,
1007,
1099,
867,
299,
2393,
1159,
26,
199,
2486,
9152,
199,
1858,
314,
2011,
27599,
289,
12,
486,
22410,
231,
231,
3107,
59,
88,
61,
26239,
3432,
12,
3932,
1124,
5540,
891,
199,
954,
1099,
867,
299,
2393,
365,
282,
3414,
402,
27599,
8545,
370,
314,
1933,
300,
2664,
290,
199,
80,
2393,
12,
314,
3414,
15884,
701,
18876,
315,
1413,
59,
88,
61,
1933,
12410,
21045,
83,
5563,
641,
289,
12,
486,
14,
199,
199,
1918,
2877,
8013,
14460,
315,
626,
314,
12343,
402,
1924,
11849,
199,
262,
314,
6042,
1007,
1099,
867,
299,
2393,
787,
314,
4563,
2285,
10894,
2597,
25713,
199,
475,
465,
6042,
1007,
1099,
2285,
10894,
402,
22497,
4895,
221,
1007,
13,
19032,
199,
1618,
1847,
24279,
351,
18,
8,
70,
12,
486,
12,
671,
395,
5515,
24279,
351,
21045,
83,
3634,
402,
413,
23901,
402,
7365,
499,
78,
13333,
246,
499,
78,
14,
199,
199,
1918,
4563,
867,
402,
1847,
24279,
351,
18,
6337,
365,
2797,
314,
6042,
754,
867,
199,
1618,
289,
12,
486,
436,
652,
2597,
883,
14062,
465,
282,
17392,
402,
3775,
314,
2877,
199,
22104,
83,
1172,
2863,
14361,
503,
440,
14,
199,
199,
1858,
4890,
299,
2393,
21045,
83,
314,
221,
2070,
3414,
402,
314,
1933,
300,
2664,
290,
299,
2393,
402,
289,
12,
486,
365,
199,
14576,
370,
314,
2070,
3414,
402,
314,
6042,
1007,
1099,
867,
299,
2393,
402,
199,
70,
12,
486,
436,
314,
12343,
402,
1373,
3414,
221,
787,
16174,
9235,
687,
199,
1589,
12343,
402,
314,
1163,
14,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
acsone/social
|
mail_notification_email_template/tests/test_mail_notification_email_template.py
|
1
|
1446
|
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from mock import patch
from openerp.tests.common import TransactionCase
class TestMailNotificationEmailTemplate(TransactionCase):
def test_mail_notification_email_template(self):
# we install a template for discussions, so we simply post
# something somewhere. We know the demo user is subscribed on the
# whole company group
demo_partner = self.env.ref('base.partner_demo')
demo_partner.write({'notify_email': 'always'})
demo_partner_mails = self.env['mail.mail'].search([
('recipient_ids', '=', demo_partner.id),
])
# pylint: disable=translation-required
self.env.ref('mail.group_all_employees').message_post(
body='hello world', type='comment', subtype='mail.mt_comment')
notifications = self.env['mail.mail'].search([
('recipient_ids', '=', demo_partner.id),
]) - demo_partner_mails
self.assertTrue(notifications)
# check that our template was used
self.assertTrue('<h2>Dear ' in n.body for n in notifications)
# check we can actually send our mail
with patch.object(
self.env['ir.mail_server'].__class__, 'send_email'
) as mock_send_email:
notifications.send()
mock_send_email.assert_called()
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
22405,
103,
7800,
377,
2523,
80,
699,
54,
665,
1014,
921,
728,
80,
14,
7530,
30,
199,
3,
844,
437,
12006,
13,
19,
14,
16,
503,
2945,
334,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
680,
199,
504,
1683,
492,
3371,
199,
504,
5166,
14,
2219,
14,
2330,
492,
18244,
1538,
421,
199,
533,
1379,
13681,
11598,
7035,
4231,
8,
10161,
1538,
304,
272,
347,
511,
63,
1198,
63,
6761,
63,
2123,
63,
1160,
8,
277,
304,
267,
327,
781,
3907,
282,
1978,
367,
4339,
527,
1356,
12,
880,
781,
9329,
2963,
267,
327,
6020,
23430,
14,
2136,
5715,
314,
14779,
922,
365,
30400,
641,
314,
267,
327,
8852,
7233,
1572,
267,
14779,
63,
3899,
275,
291,
14,
1813,
14,
1121,
360,
1095,
14,
3899,
63,
8768,
358,
267,
14779,
63,
3899,
14,
952,
3252,
6814,
63,
2123,
356,
283,
9223,
3071,
267,
14779,
63,
3899,
63,
1198,
83,
275,
291,
14,
1813,
459,
1198,
14,
1198,
2278,
1733,
779,
288,
661,
10043,
63,
1580,
297,
6291,
14779,
63,
3899,
14,
344,
395,
267,
4794,
267,
327,
4287,
26,
3507,
29,
6893,
13,
2427,
267,
291,
14,
1813,
14,
1121,
360,
1198,
14,
923,
63,
452,
63,
24561,
1959,
1188,
63,
1932,
8,
288,
2396,
534,
5006,
6701,
297,
730,
534,
3349,
297,
15686,
534,
1198,
14,
2037,
63,
3349,
358,
267,
13116,
275,
291,
14,
1813,
459,
1198,
14,
1198,
2278,
1733,
779,
288,
661,
10043,
63,
1580,
297,
6291,
14779,
63,
3899,
14,
344,
395,
267,
4794,
446,
14779,
63,
3899,
63,
1198,
83,
267,
291,
14,
1815,
8,
12782,
9,
267,
327,
1104,
626,
4154,
1978,
1990,
1202,
267,
291,
14,
1815,
4827,
72,
18,
30,
872,
285,
283,
315,
302,
14,
2030,
367,
302,
315,
13116,
9,
267,
327,
1104,
781,
883,
5965,
3222,
4154,
6016,
267,
543,
3371,
14,
785,
8,
355,
291,
14,
1813,
459,
723,
14,
1198,
63,
1000,
418,
855,
533,
3108,
283,
2254,
63,
2123,
7,
267,
776,
465,
1683,
63,
2254,
63,
2123,
26,
288,
13116,
14,
2254,
342,
288,
1683,
63,
2254,
63,
2123,
14,
479,
63,
3527,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
22405,
103,
7800,
377,
2523,
80,
699,
54,
665,
1014,
921,
728,
80,
14,
7530,
30,
199,
3,
844,
437,
12006,
13,
19,
14,
16,
503,
2945,
334,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
680,
199,
504,
1683,
492,
3371,
199,
504,
5166,
14,
2219,
14,
2330,
492,
18244,
1538,
421,
199,
533,
1379,
13681,
11598,
7035,
4231,
8,
10161,
1538,
304,
272,
347,
511,
63,
1198,
63,
6761,
63,
2123,
63,
1160,
8,
277,
304,
267,
327,
781,
3907,
282,
1978,
367,
4339,
527,
1356,
12,
880,
781,
9329,
2963,
267,
327,
6020,
23430,
14,
2136,
5715,
314,
14779,
922,
365,
30400,
641,
314,
267,
327,
8852,
7233,
1572,
267,
14779,
63,
3899,
275,
291,
14,
1813,
14,
1121,
360,
1095,
14,
3899,
63,
8768,
358,
267,
14779,
63,
3899,
14,
952,
3252,
6814,
63,
2123,
356,
283,
9223,
3071,
267,
14779,
63,
3899,
63,
1198,
83,
275,
291,
14,
1813,
459,
1198,
14,
1198,
2278,
1733,
779,
288,
661,
10043,
63,
1580,
297,
6291,
14779,
63,
3899,
14,
344,
395,
267,
4794,
267,
327,
4287,
26,
3507,
29,
6893,
13,
2427,
267,
291,
14,
1813,
14,
1121,
360,
1198,
14,
923,
63,
452,
63,
24561,
1959,
1188,
63,
1932,
8,
288,
2396,
534,
5006,
6701,
297,
730,
534,
3349,
297,
15686,
534,
1198,
14,
2037,
63,
3349,
358,
267,
13116,
275,
291,
14,
1813,
459,
1198,
14,
1198,
2278,
1733,
779,
288,
661,
10043,
63,
1580,
297,
6291,
14779,
63,
3899,
14,
344,
395,
267,
4794,
446,
14779,
63,
3899,
63,
1198,
83,
267,
291,
14,
1815,
8,
12782,
9,
267,
327,
1104,
626,
4154,
1978,
1990,
1202,
267,
291,
14,
1815,
4827,
72,
18,
30,
872,
285,
283,
315,
302,
14,
2030,
367,
302,
315,
13116,
9,
267,
327,
1104,
781,
883,
5965,
3222,
4154,
6016,
267,
543,
3371,
14,
785,
8,
355,
291,
14,
1813,
459,
723,
14,
1198,
63,
1000,
418,
855,
533,
3108,
283,
2254,
63,
2123,
7,
267,
776,
465,
1683,
63,
2254,
63,
2123,
26,
288,
13116,
14,
2254,
342,
288,
1683,
63,
2254,
63,
2123,
14,
479,
63,
3527,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rgayon/plaso
|
tests/parsers/symantec.py
|
1
|
2461
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the Symantec AV Log parser."""
from __future__ import unicode_literals
import unittest
from plaso.parsers import symantec
from tests.parsers import test_lib
class SymantecAccessProtectionUnitTest(test_lib.ParserTestCase):
"""Tests for the Symantec AV Log parser."""
# pylint: disable=protected-access
def testGetTimeElementsTuple(self):
"""Tests the _GetTimeElementsTuple function."""
parser = symantec.SymantecParser()
expected_time_elements_tuple = (2002, 11, 19, 8, 1, 34)
time_elements_tuple = parser._GetTimeElementsTuple('200A13080122')
self.assertEqual(time_elements_tuple, expected_time_elements_tuple)
expected_time_elements_tuple = (2012, 11, 30, 10, 47, 29)
time_elements_tuple = parser._GetTimeElementsTuple('2A0A1E0A2F1D')
self.assertEqual(time_elements_tuple, expected_time_elements_tuple)
def testParse(self):
"""Tests the Parse function."""
parser = symantec.SymantecParser()
storage_writer = self._ParseFile(['Symantec.Log'], parser)
self.assertEqual(storage_writer.number_of_warnings, 0)
self.assertEqual(storage_writer.number_of_events, 8)
# The order in which DSVParser generates events is nondeterministic
# hence we sort the events.
events = list(storage_writer.GetSortedEvents())
# Test the second entry:
event = events[1]
self.CheckTimestamp(event.timestamp, '2012-11-30 10:47:29.000000')
event_data = self._GetEventDataOfEvent(storage_writer, event)
self.assertEqual(event_data.user, 'davnads')
expected_file = (
'D:\\Twinkle_Prod$\\VM11 XXX\\outside\\test.exe.txt')
self.assertEqual(event_data.file, expected_file)
expected_message = (
'Event Name: GL_EVENT_INFECTION; '
'Category Name: GL_CAT_INFECTION; '
'Malware Name: W32.Changeup!gen33; '
'Malware Path: '
'D:\\Twinkle_Prod$\\VM11 XXX\\outside\\test.exe.txt; '
'Action0: Unknown; '
'Action1: Clean virus from file; '
'Action2: Delete infected file; '
'Scan ID: 0; '
'Event Data: 201\t4\t6\t1\t65542\t0\t0\t0\t0\t0\t0')
expected_short_message = (
'D:\\Twinkle_Prod$\\VM11 XXX\\outside\\test.exe.txt; '
'W32.Changeup!gen33; '
'Unknown; ...')
self._TestGetMessageStrings(
event_data, expected_message, expected_short_message)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
5515,
1237,
266,
67,
437,
54,
5297,
1798,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2882,
199,
199,
504,
1620,
305,
79,
14,
11531,
492,
1847,
1237,
266,
67,
199,
199,
504,
2295,
14,
11531,
492,
511,
63,
773,
421,
199,
533,
5515,
1237,
266,
67,
3946,
32322,
29037,
8,
396,
63,
773,
14,
2842,
1746,
304,
523,
408,
2925,
367,
314,
5515,
1237,
266,
67,
437,
54,
5297,
1798,
1041,
819,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
819,
347,
19970,
1366,
6255,
7075,
8,
277,
304,
272,
408,
2925,
314,
485,
1002,
1366,
6255,
7075,
805,
1041,
272,
1798,
275,
1847,
1237,
266,
67,
14,
4323,
1237,
266,
67,
2842,
342,
339,
1420,
63,
521,
63,
5527,
63,
2960,
275,
334,
15135,
12,
4119,
12,
5851,
12,
1695,
12,
413,
12,
8177,
9,
272,
900,
63,
5527,
63,
2960,
275,
1798,
423,
1002,
1366,
6255,
7075,
360,
1840,
33,
969,
2036,
614,
1081,
358,
272,
291,
14,
629,
8,
521,
63,
5527,
63,
2960,
12,
1420,
63,
521,
63,
5527,
63,
2960,
9,
339,
1420,
63,
521,
63,
5527,
63,
2960,
275,
334,
7409,
12,
4119,
12,
4233,
12,
1616,
12,
10954,
12,
7349,
9,
272,
900,
63,
5527,
63,
2960,
275,
1798,
423,
1002,
1366,
6255,
7075,
360,
18,
33,
16,
33,
17,
37,
16,
33,
18,
38,
17,
36,
358,
272,
291,
14,
629,
8,
521,
63,
5527,
63,
2960,
12,
1420,
63,
521,
63,
5527,
63,
2960,
9,
819,
347,
511,
4003,
8,
277,
304,
272,
408,
2925,
314,
6077,
805,
1041,
272,
1798,
275,
1847,
1237,
266,
67,
14,
4323,
1237,
266,
67,
2842,
342,
272,
4887,
63,
5491,
275,
291,
423,
4003,
1173,
2941,
4323,
1237,
266,
67,
14,
2445,
995,
1798,
9,
339,
291,
14,
629,
8,
3494,
63,
5491,
14,
1955,
63,
1618,
63,
5451,
12,
378,
9,
272,
291,
14,
629,
8,
3494,
63,
5491,
14,
1955,
63,
1618,
63,
4368,
12,
1695,
9,
339,
327,
710,
1865,
315,
1314,
577,
4985,
2842,
12821,
4474,
365,
2222,
30709,
272,
327,
19407,
781,
4069,
314,
4474,
14,
272,
4474,
275,
769,
8,
3494,
63,
5491,
14,
17526,
1376,
11770,
1012,
339,
327,
1379,
314,
3499,
2397,
26,
272,
1566,
275,
4474,
59,
17,
61,
339,
291,
14,
1799,
10239,
8,
1430,
14,
3954,
12,
283,
7409,
13,
845,
13,
1216,
1616,
26,
2417,
26,
1398,
14,
3273,
358,
339,
1566,
63,
576,
275,
291,
423,
1002,
2390,
1451,
3466,
2390,
8,
3494,
63,
5491,
12,
1566,
9,
272,
291,
14,
629,
8,
1430,
63,
576,
14,
751,
12,
283,
983,
6002,
9402,
358,
272,
1420,
63,
493,
275,
334,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
358,
272,
291,
14,
629,
8,
1430,
63,
576,
14,
493,
12,
1420,
63,
493,
9,
339,
1420,
63,
1188,
275,
334,
267,
283,
2390,
2812,
26,
3563,
63,
8193,
63,
11384,
23658,
27,
283,
267,
283,
7841,
2812,
26,
3563,
63,
11206,
63,
11384,
23658,
27,
283,
267,
283,
31147,
1068,
2812,
26,
644,
708,
14,
4001,
384,
1,
2268,
1153,
27,
283,
267,
283,
31147,
1068,
6912,
26,
283,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
27,
283,
267,
283,
3310,
16,
26,
14831,
27,
283,
267,
283,
3310,
17,
26,
12762,
18291,
527,
687,
570,
27,
283,
267,
283,
3310,
18,
26,
8496,
315,
771,
1522,
570,
27,
283,
267,
283,
15936,
2870,
26,
378,
27,
283,
267,
283,
2390,
3918,
26,
1784,
60,
84,
20,
60,
84,
22,
60,
84,
17,
60,
84,
10027,
2260,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
358,
272,
1420,
63,
3612,
63,
1188,
275,
334,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
27,
283,
267,
283,
55,
708,
14,
4001,
384,
1,
2268,
1153,
27,
283,
267,
283,
5912,
27,
2263,
358,
339,
291,
423,
774,
1002,
2209,
12672,
8,
267,
1566,
63,
576,
12,
1420,
63,
1188,
12,
1420,
63,
3612,
63,
1188,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
5515,
1237,
266,
67,
437,
54,
5297,
1798,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2882,
199,
199,
504,
1620,
305,
79,
14,
11531,
492,
1847,
1237,
266,
67,
199,
199,
504,
2295,
14,
11531,
492,
511,
63,
773,
421,
199,
533,
5515,
1237,
266,
67,
3946,
32322,
29037,
8,
396,
63,
773,
14,
2842,
1746,
304,
523,
408,
2925,
367,
314,
5515,
1237,
266,
67,
437,
54,
5297,
1798,
1041,
819,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
819,
347,
19970,
1366,
6255,
7075,
8,
277,
304,
272,
408,
2925,
314,
485,
1002,
1366,
6255,
7075,
805,
1041,
272,
1798,
275,
1847,
1237,
266,
67,
14,
4323,
1237,
266,
67,
2842,
342,
339,
1420,
63,
521,
63,
5527,
63,
2960,
275,
334,
15135,
12,
4119,
12,
5851,
12,
1695,
12,
413,
12,
8177,
9,
272,
900,
63,
5527,
63,
2960,
275,
1798,
423,
1002,
1366,
6255,
7075,
360,
1840,
33,
969,
2036,
614,
1081,
358,
272,
291,
14,
629,
8,
521,
63,
5527,
63,
2960,
12,
1420,
63,
521,
63,
5527,
63,
2960,
9,
339,
1420,
63,
521,
63,
5527,
63,
2960,
275,
334,
7409,
12,
4119,
12,
4233,
12,
1616,
12,
10954,
12,
7349,
9,
272,
900,
63,
5527,
63,
2960,
275,
1798,
423,
1002,
1366,
6255,
7075,
360,
18,
33,
16,
33,
17,
37,
16,
33,
18,
38,
17,
36,
358,
272,
291,
14,
629,
8,
521,
63,
5527,
63,
2960,
12,
1420,
63,
521,
63,
5527,
63,
2960,
9,
819,
347,
511,
4003,
8,
277,
304,
272,
408,
2925,
314,
6077,
805,
1041,
272,
1798,
275,
1847,
1237,
266,
67,
14,
4323,
1237,
266,
67,
2842,
342,
272,
4887,
63,
5491,
275,
291,
423,
4003,
1173,
2941,
4323,
1237,
266,
67,
14,
2445,
995,
1798,
9,
339,
291,
14,
629,
8,
3494,
63,
5491,
14,
1955,
63,
1618,
63,
5451,
12,
378,
9,
272,
291,
14,
629,
8,
3494,
63,
5491,
14,
1955,
63,
1618,
63,
4368,
12,
1695,
9,
339,
327,
710,
1865,
315,
1314,
577,
4985,
2842,
12821,
4474,
365,
2222,
30709,
272,
327,
19407,
781,
4069,
314,
4474,
14,
272,
4474,
275,
769,
8,
3494,
63,
5491,
14,
17526,
1376,
11770,
1012,
339,
327,
1379,
314,
3499,
2397,
26,
272,
1566,
275,
4474,
59,
17,
61,
339,
291,
14,
1799,
10239,
8,
1430,
14,
3954,
12,
283,
7409,
13,
845,
13,
1216,
1616,
26,
2417,
26,
1398,
14,
3273,
358,
339,
1566,
63,
576,
275,
291,
423,
1002,
2390,
1451,
3466,
2390,
8,
3494,
63,
5491,
12,
1566,
9,
272,
291,
14,
629,
8,
1430,
63,
576,
14,
751,
12,
283,
983,
6002,
9402,
358,
272,
1420,
63,
493,
275,
334,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
358,
272,
291,
14,
629,
8,
1430,
63,
576,
14,
493,
12,
1420,
63,
493,
9,
339,
1420,
63,
1188,
275,
334,
267,
283,
2390,
2812,
26,
3563,
63,
8193,
63,
11384,
23658,
27,
283,
267,
283,
7841,
2812,
26,
3563,
63,
11206,
63,
11384,
23658,
27,
283,
267,
283,
31147,
1068,
2812,
26,
644,
708,
14,
4001,
384,
1,
2268,
1153,
27,
283,
267,
283,
31147,
1068,
6912,
26,
283,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
27,
283,
267,
283,
3310,
16,
26,
14831,
27,
283,
267,
283,
3310,
17,
26,
12762,
18291,
527,
687,
570,
27,
283,
267,
283,
3310,
18,
26,
8496,
315,
771,
1522,
570,
27,
283,
267,
283,
15936,
2870,
26,
378,
27,
283,
267,
283,
2390,
3918,
26,
1784,
60,
84,
20,
60,
84,
22,
60,
84,
17,
60,
84,
10027,
2260,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
60,
84,
16,
358,
272,
1420,
63,
3612,
63,
1188,
275,
334,
267,
283,
36,
18589,
22879,
2292,
274,
63,
30966,
4,
1103,
6849,
845,
5787,
1103,
22431,
1103,
396,
14,
5803,
14,
2424,
27,
283,
267,
283,
55,
708,
14,
4001,
384,
1,
2268,
1153,
27,
283,
267,
283,
5912,
27,
2263,
358,
339,
291,
423,
774,
1002,
2209,
12672,
8,
267,
1566,
63,
576,
12,
1420,
63,
1188,
12,
1420,
63,
3612,
63,
1188,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zploskey/servo
|
tests/wpt/css-tests/tools/wptserve/tests/functional/test_server.py
|
86
|
1285
|
import unittest
import urllib2
import wptserve
from .base import TestUsingServer
class TestFileHandler(TestUsingServer):
def test_not_handled(self):
with self.assertRaises(urllib2.HTTPError) as cm:
resp = self.request("/not_existing")
self.assertEqual(cm.exception.code, 404)
class TestRewriter(TestUsingServer):
def test_rewrite(self):
@wptserve.handlers.handler
def handler(request, response):
return request.request_path
route = ("GET", "/test/rewritten", handler)
self.server.rewriter.register("GET", "/test/original", route[1])
self.server.router.register(*route)
resp = self.request("/test/original")
self.assertEqual(200, resp.getcode())
self.assertEqual("/test/rewritten", resp.read())
class TestRequestHandler(TestUsingServer):
def test_exception(self):
@wptserve.handlers.handler
def handler(request, response):
raise Exception
route = ("GET", "/test/raises", handler)
self.server.router.register(*route)
with self.assertRaises(urllib2.HTTPError) as cm:
resp = self.request("/test/raises")
self.assertEqual(cm.exception.code, 500)
if __name__ == "__main__":
unittest.main()
|
mpl-2.0
|
[
646,
2882,
199,
646,
4011,
18,
199,
199,
646,
336,
541,
4909,
199,
504,
1275,
1095,
492,
1379,
10369,
3120,
199,
199,
533,
1379,
21982,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
1397,
63,
11217,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
4078,
18,
14,
12815,
9,
465,
6904,
26,
288,
3085,
275,
291,
14,
1069,
4769,
1397,
63,
5952,
531,
398,
291,
14,
629,
8,
4400,
14,
1971,
14,
600,
12,
7901,
9,
199,
199,
533,
1379,
497,
5491,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
14366,
8,
277,
304,
267,
768,
32460,
4909,
14,
5586,
14,
2232,
267,
347,
3016,
8,
1069,
12,
1177,
304,
288,
372,
1056,
14,
1069,
63,
515,
398,
7475,
275,
1689,
2970,
401,
3286,
396,
15,
264,
8938,
401,
3016,
9,
267,
291,
14,
1000,
14,
264,
5491,
14,
2683,
480,
2970,
401,
3286,
396,
15,
5043,
401,
7475,
59,
17,
566,
267,
291,
14,
1000,
14,
4995,
14,
2683,
2031,
4449,
9,
267,
3085,
275,
291,
14,
1069,
4769,
396,
15,
5043,
531,
267,
291,
14,
629,
8,
1840,
12,
3085,
14,
362,
600,
1012,
267,
291,
14,
629,
4769,
396,
15,
264,
8938,
401,
3085,
14,
739,
1012,
199,
199,
533,
1379,
11149,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
1971,
8,
277,
304,
267,
768,
32460,
4909,
14,
5586,
14,
2232,
267,
347,
3016,
8,
1069,
12,
1177,
304,
288,
746,
2186,
398,
7475,
275,
1689,
2970,
401,
3286,
396,
15,
3536,
401,
3016,
9,
267,
291,
14,
1000,
14,
4995,
14,
2683,
2031,
4449,
9,
267,
543,
291,
14,
1855,
8,
4078,
18,
14,
12815,
9,
465,
6904,
26,
288,
3085,
275,
291,
14,
1069,
4769,
396,
15,
3536,
531,
398,
291,
14,
629,
8,
4400,
14,
1971,
14,
600,
12,
6891,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
646,
4011,
18,
199,
199,
646,
336,
541,
4909,
199,
504,
1275,
1095,
492,
1379,
10369,
3120,
199,
199,
533,
1379,
21982,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
1397,
63,
11217,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
4078,
18,
14,
12815,
9,
465,
6904,
26,
288,
3085,
275,
291,
14,
1069,
4769,
1397,
63,
5952,
531,
398,
291,
14,
629,
8,
4400,
14,
1971,
14,
600,
12,
7901,
9,
199,
199,
533,
1379,
497,
5491,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
14366,
8,
277,
304,
267,
768,
32460,
4909,
14,
5586,
14,
2232,
267,
347,
3016,
8,
1069,
12,
1177,
304,
288,
372,
1056,
14,
1069,
63,
515,
398,
7475,
275,
1689,
2970,
401,
3286,
396,
15,
264,
8938,
401,
3016,
9,
267,
291,
14,
1000,
14,
264,
5491,
14,
2683,
480,
2970,
401,
3286,
396,
15,
5043,
401,
7475,
59,
17,
566,
267,
291,
14,
1000,
14,
4995,
14,
2683,
2031,
4449,
9,
267,
3085,
275,
291,
14,
1069,
4769,
396,
15,
5043,
531,
267,
291,
14,
629,
8,
1840,
12,
3085,
14,
362,
600,
1012,
267,
291,
14,
629,
4769,
396,
15,
264,
8938,
401,
3085,
14,
739,
1012,
199,
199,
533,
1379,
11149,
8,
774,
10369,
3120,
304,
272,
347,
511,
63,
1971,
8,
277,
304,
267,
768,
32460,
4909,
14,
5586,
14,
2232,
267,
347,
3016,
8,
1069,
12,
1177,
304,
288,
746,
2186,
398,
7475,
275,
1689,
2970,
401,
3286,
396,
15,
3536,
401,
3016,
9,
267,
291,
14,
1000,
14,
4995,
14,
2683,
2031,
4449,
9,
267,
543,
291,
14,
1855,
8,
4078,
18,
14,
12815,
9,
465,
6904,
26,
288,
3085,
275,
291,
14,
1069,
4769,
396,
15,
3536,
531,
398,
291,
14,
629,
8,
4400,
14,
1971,
14,
600,
12,
6891,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
beckdaniel/GPy
|
GPy/inference/latent_function_inference/svgp.py
|
15
|
5144
|
from . import LatentFunctionInference
from ...util import linalg
from ...util import choleskies
import numpy as np
from .posterior import Posterior
from scipy.linalg.blas import dgemm, dsymm, dtrmm
class SVGP(LatentFunctionInference):
def inference(self, q_u_mean, q_u_chol, kern, X, Z, likelihood, Y, mean_function=None, Y_metadata=None, KL_scale=1.0, batch_scale=1.0):
num_data, _ = Y.shape
num_inducing, num_outputs = q_u_mean.shape
#expand cholesky representation
L = choleskies.flat_to_triang(q_u_chol)
S = np.empty((num_outputs, num_inducing, num_inducing))
[np.dot(L[i,:,:], L[i,:,:].T, S[i,:,:]) for i in range(num_outputs)]
#Si,_ = linalg.dpotri(np.asfortranarray(L), lower=1)
Si = choleskies.multiple_dpotri(L)
logdetS = np.array([2.*np.sum(np.log(np.abs(np.diag(L[i,:,:])))) for i in range(L.shape[0])])
if np.any(np.isinf(Si)):
raise ValueError("Cholesky representation unstable")
#compute mean function stuff
if mean_function is not None:
prior_mean_u = mean_function.f(Z)
prior_mean_f = mean_function.f(X)
else:
prior_mean_u = np.zeros((num_inducing, num_outputs))
prior_mean_f = np.zeros((num_data, num_outputs))
#compute kernel related stuff
Kmm = kern.K(Z)
Kmn = kern.K(Z, X)
Knn_diag = kern.Kdiag(X)
Lm = linalg.jitchol(Kmm)
logdetKmm = 2.*np.sum(np.log(np.diag(Lm)))
Kmmi, _ = linalg.dpotri(Lm)
#compute the marginal means and variances of q(f)
A, _ = linalg.dpotrs(Lm, Kmn)
mu = prior_mean_f + np.dot(A.T, q_u_mean - prior_mean_u)
v = np.empty((num_data, num_outputs))
for i in range(num_outputs):
tmp = dtrmm(1.0,L[i].T, A, lower=0, trans_a=0)
v[:,i] = np.sum(np.square(tmp),0)
v += (Knn_diag - np.sum(A*Kmn,0))[:,None]
#compute the KL term
Kmmim = np.dot(Kmmi, q_u_mean)
KLs = -0.5*logdetS -0.5*num_inducing + 0.5*logdetKmm + 0.5*np.sum(Kmmi[None,:,:]*S,1).sum(1) + 0.5*np.sum(q_u_mean*Kmmim,0)
KL = KLs.sum()
#gradient of the KL term (assuming zero mean function)
dKL_dm = Kmmim.copy()
dKL_dS = 0.5*(Kmmi[None,:,:] - Si)
dKL_dKmm = 0.5*num_outputs*Kmmi - 0.5*Kmmi.dot(S.sum(0)).dot(Kmmi) - 0.5*Kmmim.dot(Kmmim.T)
if mean_function is not None:
#adjust KL term for mean function
Kmmi_mfZ = np.dot(Kmmi, prior_mean_u)
KL += -np.sum(q_u_mean*Kmmi_mfZ)
KL += 0.5*np.sum(Kmmi_mfZ*prior_mean_u)
#adjust gradient for mean fucntion
dKL_dm -= Kmmi_mfZ
dKL_dKmm += Kmmim.dot(Kmmi_mfZ.T)
dKL_dKmm -= 0.5*Kmmi_mfZ.dot(Kmmi_mfZ.T)
#compute gradients for mean_function
dKL_dmfZ = Kmmi_mfZ - Kmmim
#quadrature for the likelihood
F, dF_dmu, dF_dv, dF_dthetaL = likelihood.variational_expectations(Y, mu, v, Y_metadata=Y_metadata)
#rescale the F term if working on a batch
F, dF_dmu, dF_dv = F*batch_scale, dF_dmu*batch_scale, dF_dv*batch_scale
if dF_dthetaL is not None:
dF_dthetaL = dF_dthetaL.sum(1).sum(1)*batch_scale
#derivatives of expected likelihood, assuming zero mean function
Adv = A[None,:,:]*dF_dv.T[:,None,:] # As if dF_Dv is diagonal, D, M, N
Admu = A.dot(dF_dmu)
Adv = np.ascontiguousarray(Adv) # makes for faster operations later...(inc dsymm)
AdvA = np.dot(Adv.reshape(-1, num_data),A.T).reshape(num_outputs, num_inducing, num_inducing )
tmp = np.sum([np.dot(a,s) for a, s in zip(AdvA, S)],0).dot(Kmmi)
dF_dKmm = -Admu.dot(Kmmim.T) + AdvA.sum(0) - tmp - tmp.T
dF_dKmm = 0.5*(dF_dKmm + dF_dKmm.T) # necessary? GPy bug?
tmp = S.reshape(-1, num_inducing).dot(Kmmi).reshape(num_outputs, num_inducing , num_inducing )
tmp = 2.*(tmp - np.eye(num_inducing)[None, :,:])
dF_dKmn = Kmmim.dot(dF_dmu.T)
for a,b in zip(tmp, Adv):
dF_dKmn += np.dot(a.T, b)
dF_dm = Admu
dF_dS = AdvA
#adjust gradient to account for mean function
if mean_function is not None:
dF_dmfX = dF_dmu.copy()
dF_dmfZ = -Admu
dF_dKmn -= np.dot(Kmmi_mfZ, dF_dmu.T)
dF_dKmm += Admu.dot(Kmmi_mfZ.T)
#sum (gradients of) expected likelihood and KL part
log_marginal = F.sum() - KL
dL_dm, dL_dS, dL_dKmm, dL_dKmn = dF_dm - dKL_dm, dF_dS- dKL_dS, dF_dKmm- dKL_dKmm, dF_dKmn
dL_dchol = 2.*np.array([np.dot(a,b) for a, b in zip(dL_dS, L) ])
dL_dchol = choleskies.triang_to_flat(dL_dchol)
grad_dict = {'dL_dKmm':dL_dKmm, 'dL_dKmn':dL_dKmn, 'dL_dKdiag': dF_dv.sum(1), 'dL_dm':dL_dm, 'dL_dchol':dL_dchol, 'dL_dthetaL':dF_dthetaL}
if mean_function is not None:
grad_dict['dL_dmfZ'] = dF_dmfZ - dKL_dmfZ
grad_dict['dL_dmfX'] = dF_dmfX
return Posterior(mean=q_u_mean, cov=S.T, K=Kmm, prior_mean=prior_mean_u), log_marginal, grad_dict
|
bsd-3-clause
|
[
504,
1275,
492,
491,
323,
343,
3481,
29731,
199,
504,
2263,
1974,
492,
16727,
199,
504,
2263,
1974,
492,
2468,
274,
1339,
1500,
199,
646,
2680,
465,
980,
199,
504,
1275,
31228,
492,
25987,
17514,
199,
504,
7026,
14,
10096,
14,
21044,
492,
366,
303,
596,
12,
366,
1786,
596,
12,
366,
454,
596,
199,
199,
533,
14056,
8225,
8,
16500,
343,
3481,
29731,
304,
339,
347,
17353,
8,
277,
12,
1894,
63,
85,
63,
3670,
12,
1894,
63,
85,
63,
27972,
12,
4303,
78,
12,
1323,
12,
3107,
12,
22046,
12,
1488,
12,
4615,
63,
1593,
29,
403,
12,
1488,
63,
2343,
29,
403,
12,
1804,
44,
63,
3467,
29,
17,
14,
16,
12,
3522,
63,
3467,
29,
17,
14,
16,
304,
398,
1967,
63,
576,
12,
485,
275,
1488,
14,
1392,
267,
1967,
63,
688,
947,
316,
12,
1967,
63,
4467,
275,
1894,
63,
85,
63,
3670,
14,
1392,
398,
327,
4441,
2468,
19881,
6025,
267,
491,
275,
2468,
274,
1339,
1500,
14,
7088,
63,
475,
63,
599,
621,
8,
81,
63,
85,
63,
27972,
9,
7318,
428,
275,
980,
14,
1667,
1332,
1507,
63,
4467,
12,
1967,
63,
688,
947,
316,
12,
1967,
63,
688,
947,
316,
430,
267,
359,
1590,
14,
3287,
8,
44,
59,
73,
32306,
8429,
491,
59,
73,
32306,
11455,
52,
12,
428,
59,
73,
32306,
5728,
367,
284,
315,
1425,
8,
1507,
63,
4467,
1874,
267,
327,
18934,
16987,
275,
16727,
14,
5780,
357,
322,
8,
1590,
14,
305,
18496,
1144,
8,
44,
395,
5117,
29,
17,
9,
267,
428,
73,
275,
2468,
274,
1339,
1500,
14,
6048,
63,
5780,
357,
322,
8,
44,
9,
267,
943,
9886,
51,
275,
980,
14,
1144,
779,
18,
2795,
1590,
14,
1838,
8,
1590,
14,
793,
8,
1590,
14,
2101,
8,
1590,
14,
6706,
8,
44,
59,
73,
32306,
16720,
430,
367,
284,
315,
1425,
8,
44,
14,
1392,
59,
16,
24310,
398,
340,
980,
14,
1629,
8,
1590,
14,
29326,
8,
18934,
2298,
288,
746,
1722,
480,
6209,
19881,
6025,
625,
11989,
531,
398,
327,
3357,
4615,
805,
8292,
267,
340,
4615,
63,
1593,
365,
440,
488,
26,
288,
6791,
63,
3670,
63,
85,
275,
4615,
63,
1593,
14,
70,
8,
58,
9,
288,
6791,
63,
3670,
63,
70,
275,
4615,
63,
1593,
14,
70,
8,
56,
9,
267,
587,
26,
288,
6791,
63,
3670,
63,
85,
275,
980,
14,
4250,
1332,
1507,
63,
688,
947,
316,
12,
1967,
63,
4467,
430,
288,
6791,
63,
3670,
63,
70,
275,
980,
14,
4250,
1332,
1507,
63,
576,
12,
1967,
63,
4467,
430,
398,
327,
3357,
5114,
4048,
8292,
267,
1804,
596,
275,
4303,
78,
14,
43,
8,
58,
9,
267,
1804,
10344,
275,
4303,
78,
14,
43,
8,
58,
12,
1323,
9,
267,
1804,
4411,
63,
6706,
275,
4303,
78,
14,
43,
6706,
8,
56,
9,
267,
491,
77,
275,
16727,
14,
74,
9414,
393,
8,
43,
596,
9,
267,
943,
9886,
43,
596,
275,
499,
2795,
1590,
14,
1838,
8,
1590,
14,
793,
8,
1590,
14,
6706,
8,
23041,
1724,
267,
1804,
596,
73,
12,
485,
275,
16727,
14,
5780,
357,
322,
8,
23041,
9,
398,
327,
3357,
314,
11042,
279,
4910,
436,
11773,
83,
402,
1894,
8,
70,
9,
267,
437,
12,
485,
275,
16727,
14,
5780,
357,
2393,
8,
23041,
12,
1804,
10344,
9,
267,
8504,
275,
6791,
63,
3670,
63,
70,
435,
980,
14,
3287,
8,
33,
14,
52,
12,
1894,
63,
85,
63,
3670,
446,
6791,
63,
3670,
63,
85,
9,
267,
373,
275,
980,
14,
1667,
1332,
1507,
63,
576,
12,
1967,
63,
4467,
430,
267,
367,
284,
315,
1425,
8,
1507,
63,
4467,
304,
288,
3529,
275,
366,
454,
596,
8,
17,
14,
16,
12,
44,
59,
73,
1055,
52,
12,
437,
12,
5117,
29,
16,
12,
1752,
63,
65,
29,
16,
9,
288,
373,
3981,
73,
61,
275,
980,
14,
1838,
8,
1590,
14,
9646,
8,
2791,
395,
16,
9,
267,
373,
847,
334,
43,
4411,
63,
6706,
446,
980,
14,
1838,
8,
33,
10,
43,
10344,
12,
16,
430,
3981,
403,
61,
398,
327,
3357,
314,
1804,
44,
6707,
267,
1804,
596,
1017,
275,
980,
14,
3287,
8,
43,
596,
73,
12,
1894,
63,
85,
63,
3670,
9,
267,
1804,
44,
83,
275,
446,
16,
14,
21,
10,
793,
9886,
51,
446,
16,
14,
21,
10,
1507,
63,
688,
947,
316,
435,
378,
14,
21,
10,
793,
9886,
43,
596,
435,
378,
14,
21,
10,
1590,
14,
1838,
8,
43,
596,
73,
59,
403,
32306,
2938,
10,
51,
12,
17,
680,
1838,
8,
17,
9,
435,
378,
14,
21,
10,
1590,
14,
1838,
8,
81,
63,
85,
63,
3670,
10,
43,
596,
1017,
12,
16,
9,
267,
1804,
44,
275,
1804,
44,
83,
14,
1838,
342,
267,
327,
7490,
402,
314,
1804,
44,
6707,
334,
405,
12848,
4697,
4615,
805,
9,
267,
366,
14307,
63,
6428,
275,
1804,
596,
1017,
14,
1574,
342,
267,
366,
14307,
63,
68,
51,
275,
378,
14,
21,
5830,
43,
596,
73,
59,
403,
32306,
2938,
446,
428,
73,
9,
267,
366,
14307,
63,
68,
43,
596,
275,
378,
14,
21,
10,
1507,
63,
4467,
10,
43,
596,
73,
446,
378,
14,
21,
10,
43,
596,
73,
14,
3287,
8,
51,
14,
1838,
8,
16,
4992,
3287,
8,
43,
596,
73,
9,
446,
378,
14,
21,
10,
43,
596,
1017,
14,
3287,
8,
43,
596,
1017,
14,
52,
9,
398,
340,
4615,
63,
1593,
365,
440,
488,
26,
288,
327,
10917,
1804,
44,
6707,
367,
4615,
805,
288,
1804,
596,
73,
63,
11821,
58,
275,
980,
14,
3287,
8,
43,
596,
73,
12,
6791,
63,
3670,
63,
85,
9,
288,
1804,
44,
847,
446,
1590,
14,
1838,
8,
81,
63,
85,
63,
3670,
10,
43,
596,
73,
63,
11821,
58,
9,
288,
1804,
44,
847,
378,
14,
21,
10,
1590,
14,
1838,
8,
43,
596,
73,
63,
11821,
58,
10,
13775,
63,
3670,
63,
85,
9,
953,
327,
10917,
6709,
367,
4615,
289,
947,
78,
296,
288,
366,
14307,
63,
6428,
4862,
1804,
596,
73,
63,
11821,
58,
288,
366,
14307,
63,
68,
43,
596,
847,
1804,
596,
1017,
14,
3287,
8,
43,
596,
73
] |
[
1275,
492,
491,
323,
343,
3481,
29731,
199,
504,
2263,
1974,
492,
16727,
199,
504,
2263,
1974,
492,
2468,
274,
1339,
1500,
199,
646,
2680,
465,
980,
199,
504,
1275,
31228,
492,
25987,
17514,
199,
504,
7026,
14,
10096,
14,
21044,
492,
366,
303,
596,
12,
366,
1786,
596,
12,
366,
454,
596,
199,
199,
533,
14056,
8225,
8,
16500,
343,
3481,
29731,
304,
339,
347,
17353,
8,
277,
12,
1894,
63,
85,
63,
3670,
12,
1894,
63,
85,
63,
27972,
12,
4303,
78,
12,
1323,
12,
3107,
12,
22046,
12,
1488,
12,
4615,
63,
1593,
29,
403,
12,
1488,
63,
2343,
29,
403,
12,
1804,
44,
63,
3467,
29,
17,
14,
16,
12,
3522,
63,
3467,
29,
17,
14,
16,
304,
398,
1967,
63,
576,
12,
485,
275,
1488,
14,
1392,
267,
1967,
63,
688,
947,
316,
12,
1967,
63,
4467,
275,
1894,
63,
85,
63,
3670,
14,
1392,
398,
327,
4441,
2468,
19881,
6025,
267,
491,
275,
2468,
274,
1339,
1500,
14,
7088,
63,
475,
63,
599,
621,
8,
81,
63,
85,
63,
27972,
9,
7318,
428,
275,
980,
14,
1667,
1332,
1507,
63,
4467,
12,
1967,
63,
688,
947,
316,
12,
1967,
63,
688,
947,
316,
430,
267,
359,
1590,
14,
3287,
8,
44,
59,
73,
32306,
8429,
491,
59,
73,
32306,
11455,
52,
12,
428,
59,
73,
32306,
5728,
367,
284,
315,
1425,
8,
1507,
63,
4467,
1874,
267,
327,
18934,
16987,
275,
16727,
14,
5780,
357,
322,
8,
1590,
14,
305,
18496,
1144,
8,
44,
395,
5117,
29,
17,
9,
267,
428,
73,
275,
2468,
274,
1339,
1500,
14,
6048,
63,
5780,
357,
322,
8,
44,
9,
267,
943,
9886,
51,
275,
980,
14,
1144,
779,
18,
2795,
1590,
14,
1838,
8,
1590,
14,
793,
8,
1590,
14,
2101,
8,
1590,
14,
6706,
8,
44,
59,
73,
32306,
16720,
430,
367,
284,
315,
1425,
8,
44,
14,
1392,
59,
16,
24310,
398,
340,
980,
14,
1629,
8,
1590,
14,
29326,
8,
18934,
2298,
288,
746,
1722,
480,
6209,
19881,
6025,
625,
11989,
531,
398,
327,
3357,
4615,
805,
8292,
267,
340,
4615,
63,
1593,
365,
440,
488,
26,
288,
6791,
63,
3670,
63,
85,
275,
4615,
63,
1593,
14,
70,
8,
58,
9,
288,
6791,
63,
3670,
63,
70,
275,
4615,
63,
1593,
14,
70,
8,
56,
9,
267,
587,
26,
288,
6791,
63,
3670,
63,
85,
275,
980,
14,
4250,
1332,
1507,
63,
688,
947,
316,
12,
1967,
63,
4467,
430,
288,
6791,
63,
3670,
63,
70,
275,
980,
14,
4250,
1332,
1507,
63,
576,
12,
1967,
63,
4467,
430,
398,
327,
3357,
5114,
4048,
8292,
267,
1804,
596,
275,
4303,
78,
14,
43,
8,
58,
9,
267,
1804,
10344,
275,
4303,
78,
14,
43,
8,
58,
12,
1323,
9,
267,
1804,
4411,
63,
6706,
275,
4303,
78,
14,
43,
6706,
8,
56,
9,
267,
491,
77,
275,
16727,
14,
74,
9414,
393,
8,
43,
596,
9,
267,
943,
9886,
43,
596,
275,
499,
2795,
1590,
14,
1838,
8,
1590,
14,
793,
8,
1590,
14,
6706,
8,
23041,
1724,
267,
1804,
596,
73,
12,
485,
275,
16727,
14,
5780,
357,
322,
8,
23041,
9,
398,
327,
3357,
314,
11042,
279,
4910,
436,
11773,
83,
402,
1894,
8,
70,
9,
267,
437,
12,
485,
275,
16727,
14,
5780,
357,
2393,
8,
23041,
12,
1804,
10344,
9,
267,
8504,
275,
6791,
63,
3670,
63,
70,
435,
980,
14,
3287,
8,
33,
14,
52,
12,
1894,
63,
85,
63,
3670,
446,
6791,
63,
3670,
63,
85,
9,
267,
373,
275,
980,
14,
1667,
1332,
1507,
63,
576,
12,
1967,
63,
4467,
430,
267,
367,
284,
315,
1425,
8,
1507,
63,
4467,
304,
288,
3529,
275,
366,
454,
596,
8,
17,
14,
16,
12,
44,
59,
73,
1055,
52,
12,
437,
12,
5117,
29,
16,
12,
1752,
63,
65,
29,
16,
9,
288,
373,
3981,
73,
61,
275,
980,
14,
1838,
8,
1590,
14,
9646,
8,
2791,
395,
16,
9,
267,
373,
847,
334,
43,
4411,
63,
6706,
446,
980,
14,
1838,
8,
33,
10,
43,
10344,
12,
16,
430,
3981,
403,
61,
398,
327,
3357,
314,
1804,
44,
6707,
267,
1804,
596,
1017,
275,
980,
14,
3287,
8,
43,
596,
73,
12,
1894,
63,
85,
63,
3670,
9,
267,
1804,
44,
83,
275,
446,
16,
14,
21,
10,
793,
9886,
51,
446,
16,
14,
21,
10,
1507,
63,
688,
947,
316,
435,
378,
14,
21,
10,
793,
9886,
43,
596,
435,
378,
14,
21,
10,
1590,
14,
1838,
8,
43,
596,
73,
59,
403,
32306,
2938,
10,
51,
12,
17,
680,
1838,
8,
17,
9,
435,
378,
14,
21,
10,
1590,
14,
1838,
8,
81,
63,
85,
63,
3670,
10,
43,
596,
1017,
12,
16,
9,
267,
1804,
44,
275,
1804,
44,
83,
14,
1838,
342,
267,
327,
7490,
402,
314,
1804,
44,
6707,
334,
405,
12848,
4697,
4615,
805,
9,
267,
366,
14307,
63,
6428,
275,
1804,
596,
1017,
14,
1574,
342,
267,
366,
14307,
63,
68,
51,
275,
378,
14,
21,
5830,
43,
596,
73,
59,
403,
32306,
2938,
446,
428,
73,
9,
267,
366,
14307,
63,
68,
43,
596,
275,
378,
14,
21,
10,
1507,
63,
4467,
10,
43,
596,
73,
446,
378,
14,
21,
10,
43,
596,
73,
14,
3287,
8,
51,
14,
1838,
8,
16,
4992,
3287,
8,
43,
596,
73,
9,
446,
378,
14,
21,
10,
43,
596,
1017,
14,
3287,
8,
43,
596,
1017,
14,
52,
9,
398,
340,
4615,
63,
1593,
365,
440,
488,
26,
288,
327,
10917,
1804,
44,
6707,
367,
4615,
805,
288,
1804,
596,
73,
63,
11821,
58,
275,
980,
14,
3287,
8,
43,
596,
73,
12,
6791,
63,
3670,
63,
85,
9,
288,
1804,
44,
847,
446,
1590,
14,
1838,
8,
81,
63,
85,
63,
3670,
10,
43,
596,
73,
63,
11821,
58,
9,
288,
1804,
44,
847,
378,
14,
21,
10,
1590,
14,
1838,
8,
43,
596,
73,
63,
11821,
58,
10,
13775,
63,
3670,
63,
85,
9,
953,
327,
10917,
6709,
367,
4615,
289,
947,
78,
296,
288,
366,
14307,
63,
6428,
4862,
1804,
596,
73,
63,
11821,
58,
288,
366,
14307,
63,
68,
43,
596,
847,
1804,
596,
1017,
14,
3287,
8,
43,
596,
73,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
datsfosure/ansible
|
lib/ansible/inventory/expand_hosts.py
|
71
|
4415
|
# (c) 2012, Zettar Inc.
# Written by Chin Fang <fangchin@zettar.com>
#
# This file is part of Ansible
#
# 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/>.
#
'''
This module is for enhancing ansible's inventory parsing capability such
that it can deal with hostnames specified using a simple pattern in the
form of [beg:end], example: [1:5], [a:c], [D:G]. If beg is not specified,
it defaults to 0.
If beg is given and is left-zero-padded, e.g. '001', it is taken as a
formatting hint when the range is expanded. e.g. [001:010] is to be
expanded into 001, 002 ...009, 010.
Note that when beg is specified with left zero padding, then the length of
end must be the same as that of beg, else an exception is raised.
'''
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import string
from ansible import errors
def detect_range(line = None):
'''
A helper function that checks a given host line to see if it contains
a range pattern described in the docstring above.
Returnes True if the given line contains a pattern, else False.
'''
if 0 <= line.find("[") < line.find(":") < line.find("]"):
return True
else:
return False
def expand_hostname_range(line = None):
'''
A helper function that expands a given line that contains a pattern
specified in top docstring, and returns a list that consists of the
expanded version.
The '[' and ']' characters are used to maintain the pseudo-code
appearance. They are replaced in this function with '|' to ease
string splitting.
References: http://ansible.github.com/patterns.html#hosts-and-groups
'''
all_hosts = []
if line:
# A hostname such as db[1:6]-node is considered to consists
# three parts:
# head: 'db'
# nrange: [1:6]; range() is a built-in. Can't use the name
# tail: '-node'
# Add support for multiple ranges in a host so:
# db[01:10:3]node-[01:10]
# - to do this we split off at the first [...] set, getting the list
# of hosts and then repeat until none left.
# - also add an optional third parameter which contains the step. (Default: 1)
# so range can be [01:10:2] -> 01 03 05 07 09
# FIXME: make this work for alphabetic sequences too.
(head, nrange, tail) = line.replace('[','|',1).replace(']','|',1).split('|')
bounds = nrange.split(":")
if len(bounds) != 2 and len(bounds) != 3:
raise errors.AnsibleError("host range incorrectly specified")
beg = bounds[0]
end = bounds[1]
if len(bounds) == 2:
step = 1
else:
step = bounds[2]
if not beg:
beg = "0"
if not end:
raise errors.AnsibleError("host range end value missing")
if beg[0] == '0' and len(beg) > 1:
rlen = len(beg) # range length formatting hint
if rlen != len(end):
raise errors.AnsibleError("host range format incorrectly specified!")
fill = lambda _: str(_).zfill(rlen) # range sequence
else:
fill = str
try:
i_beg = string.ascii_letters.index(beg)
i_end = string.ascii_letters.index(end)
if i_beg > i_end:
raise errors.AnsibleError("host range format incorrectly specified!")
seq = string.ascii_letters[i_beg:i_end+1]
except ValueError: # not an alpha range
seq = range(int(beg), int(end)+1, int(step))
for rseq in seq:
hname = ''.join((head, fill(rseq), tail))
if detect_range(hname):
all_hosts.extend( expand_hostname_range( hname ) )
else:
all_hosts.append(hname)
return all_hosts
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
12,
3107,
386,
5369,
3277,
14,
199,
3,
27694,
701,
2799,
262,
481,
621,
665,
70,
621,
335,
262,
32,
90,
386,
5369,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
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,
3,
199,
199,
2344,
199,
2765,
859,
365,
367,
655,
72,
15763,
3242,
1159,
8200,
6057,
19854,
4066,
199,
9099,
652,
883,
7962,
543,
1591,
1247,
2013,
1808,
282,
3486,
3851,
315,
314,
199,
964,
402,
359,
26349,
26,
500,
467,
2893,
26,
359,
17,
26,
21,
467,
359,
65,
26,
67,
467,
359,
36,
26,
39,
1055,
982,
31191,
365,
440,
2013,
12,
199,
390,
4243,
370,
378,
14,
199,
199,
3917,
31191,
365,
1627,
436,
365,
3602,
13,
4262,
13,
25201,
12,
325,
14,
71,
14,
283,
4587,
297,
652,
365,
9394,
465,
282,
199,
20034,
8328,
1380,
314,
1425,
365,
11507,
14,
325,
14,
71,
14,
359,
4587,
26,
9523,
61,
365,
370,
506,
199,
15645,
1901,
378,
614,
12,
378,
996,
2263,
8581,
12,
378,
709,
14,
199,
199,
7443,
626,
1380,
31191,
365,
2013,
543,
3602,
4697,
6273,
12,
2066,
314,
2582,
402,
199,
500,
1471,
506,
314,
2011,
465,
626,
402,
31191,
12,
587,
376,
1919,
365,
4915,
14,
199,
2344,
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,
1059,
199,
199,
504,
3242,
492,
2552,
199,
199,
318,
9696,
63,
1842,
8,
604,
275,
488,
304,
272,
1449,
272,
437,
5922,
805,
626,
5920,
282,
1627,
1591,
1004,
370,
1937,
340,
652,
3509,
272,
282,
1425,
3851,
11736,
315,
314,
9214,
3432,
14,
339,
1432,
397,
715,
340,
314,
1627,
1004,
3509,
282,
3851,
12,
587,
756,
14,
272,
1449,
272,
340,
378,
2695,
1004,
14,
1623,
10994,
531,
665,
1004,
14,
1623,
20063,
665,
1004,
14,
1623,
480,
61,
2349,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
6544,
63,
4269,
63,
1842,
8,
604,
275,
488,
304,
272,
1449,
272,
437,
5922,
805,
626,
1437,
5915,
282,
1627,
1004,
626,
3509,
282,
3851,
272,
2013,
315,
2746,
9214,
12,
436,
2529,
282,
769,
626,
18581,
402,
314,
272,
11507,
1015,
14,
339,
710,
22640,
436,
24840,
4110,
787,
1202,
370,
11075,
314,
15984,
13,
600,
272,
7468,
554,
14,
9322,
787,
8717,
315,
642,
805,
543,
24628,
370,
325,
482,
272,
1059,
26518,
14,
339,
14504,
26,
1455,
921,
4853,
14,
5031,
14,
957,
15,
7435,
14,
1360,
3,
5146,
13,
460,
13,
2634,
272,
1449,
272,
1006,
63,
5146,
275,
942,
272,
340,
1004,
26,
267,
327,
437,
6246,
4066,
465,
1592,
59,
17,
26,
22,
11285,
932,
365,
8652,
370,
18581,
267,
327,
7795,
4184,
26,
267,
327,
4854,
26,
283,
697,
7,
267,
327,
302,
1842,
26,
359,
17,
26,
22,
11566,
1425,
342,
365,
282,
6137,
13,
262,
14,
6855,
1133,
675,
314,
536,
267,
327,
9483,
26,
2475,
932,
7,
398,
327,
2654,
2291,
367,
3663,
12271,
315,
282,
1591,
880,
26,
267,
327,
1592,
59,
614,
26,
709,
26,
19,
61,
932,
13,
59,
614,
26,
709,
61,
267,
327,
446,
370,
886,
642,
781,
3715,
2331,
737,
314,
1642,
359,
18737,
663,
12,
10232,
314,
769,
267,
327,
257,
402,
7057,
436,
2066,
11982,
5133,
7179,
3602,
14,
267,
327,
446,
2597,
1050,
376,
2716,
10919,
2725,
1314,
3509,
314,
3650,
14,
334,
2698,
26,
413,
9,
267,
327,
257,
880,
1425,
883,
506,
359,
614,
26,
709,
26,
18,
61,
1035,
17163,
30569,
22528,
24937,
21798,
267,
327,
7600,
26,
1852,
642,
1736,
367,
23331,
764,
8013,
4634,
14,
398,
334,
2993,
12,
302,
1842,
12,
9483,
9,
275,
1004,
14,
1814,
11894,
1673,
26320,
17,
680,
1814,
360,
61,
1673,
26320,
17,
680,
1294,
20137,
358,
267,
10461,
275,
302,
1842,
14,
1294,
20063,
267,
340,
822,
8,
9632,
9,
1137,
499,
436,
822,
8,
9632,
9,
1137,
650,
26,
288,
746,
2552,
14,
29107,
480,
1102,
1425,
22743,
2013,
531,
267,
31191,
275,
10461,
59,
16,
61,
267,
1284,
275,
10461,
59,
17,
61,
267,
340,
822,
8,
9632,
9,
508,
499,
26,
288,
3650,
275,
413,
267,
587,
26,
288,
3650,
275,
10461,
59,
18,
61,
267,
340,
440,
31191,
26,
288,
31191,
275,
298,
16,
2,
267,
340,
440,
1284,
26,
288,
746,
2552,
14,
29107,
480,
1102,
1425,
1284,
574,
4124,
531,
267,
340,
31191,
59,
16,
61,
508,
283,
16,
7,
436,
822,
8,
26349,
9,
690,
413,
26,
288,
24746,
275,
822,
8,
26349,
9,
327,
1425,
2582,
10803,
8328,
288,
340,
24746,
1137,
822,
8,
500,
304,
355,
746,
2552,
14,
29107,
480,
1102,
1425,
1475,
22743,
2013,
9124,
288,
5554,
275,
2400,
24700,
620,
1547,
680,
26626,
8,
82,
552,
9,
221,
327,
1425,
3414,
267,
587,
26,
288,
5554,
275,
620,
398,
862,
26,
288,
284,
63,
26349,
275,
1059,
14,
4371,
63,
16415,
14,
1080,
8,
26349,
9,
288,
284,
63,
500,
275,
1059,
14,
4371,
63,
16415,
14,
1080,
8,
500,
9,
288,
340,
284,
63,
26349,
690,
284,
63,
500,
26,
355,
746,
2552,
14,
29107,
480,
1102,
1425,
1475,
22743,
2013,
9124,
288,
5412,
275,
1059,
14,
4371
] |
[
334,
67,
9,
6029,
12,
3107,
386,
5369,
3277,
14,
199,
3,
27694,
701,
2799,
262,
481,
621,
665,
70,
621,
335,
262,
32,
90,
386,
5369,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
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,
3,
199,
199,
2344,
199,
2765,
859,
365,
367,
655,
72,
15763,
3242,
1159,
8200,
6057,
19854,
4066,
199,
9099,
652,
883,
7962,
543,
1591,
1247,
2013,
1808,
282,
3486,
3851,
315,
314,
199,
964,
402,
359,
26349,
26,
500,
467,
2893,
26,
359,
17,
26,
21,
467,
359,
65,
26,
67,
467,
359,
36,
26,
39,
1055,
982,
31191,
365,
440,
2013,
12,
199,
390,
4243,
370,
378,
14,
199,
199,
3917,
31191,
365,
1627,
436,
365,
3602,
13,
4262,
13,
25201,
12,
325,
14,
71,
14,
283,
4587,
297,
652,
365,
9394,
465,
282,
199,
20034,
8328,
1380,
314,
1425,
365,
11507,
14,
325,
14,
71,
14,
359,
4587,
26,
9523,
61,
365,
370,
506,
199,
15645,
1901,
378,
614,
12,
378,
996,
2263,
8581,
12,
378,
709,
14,
199,
199,
7443,
626,
1380,
31191,
365,
2013,
543,
3602,
4697,
6273,
12,
2066,
314,
2582,
402,
199,
500,
1471,
506,
314,
2011,
465,
626,
402,
31191,
12,
587,
376,
1919,
365,
4915,
14,
199,
2344,
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,
1059,
199,
199,
504,
3242,
492,
2552,
199,
199,
318,
9696,
63,
1842,
8,
604,
275,
488,
304,
272,
1449,
272,
437,
5922,
805,
626,
5920,
282,
1627,
1591,
1004,
370,
1937,
340,
652,
3509,
272,
282,
1425,
3851,
11736,
315,
314,
9214,
3432,
14,
339,
1432,
397,
715,
340,
314,
1627,
1004,
3509,
282,
3851,
12,
587,
756,
14,
272,
1449,
272,
340,
378,
2695,
1004,
14,
1623,
10994,
531,
665,
1004,
14,
1623,
20063,
665,
1004,
14,
1623,
480,
61,
2349,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
6544,
63,
4269,
63,
1842,
8,
604,
275,
488,
304,
272,
1449,
272,
437,
5922,
805,
626,
1437,
5915,
282,
1627,
1004,
626,
3509,
282,
3851,
272,
2013,
315,
2746,
9214,
12,
436,
2529,
282,
769,
626,
18581,
402,
314,
272,
11507,
1015,
14,
339,
710,
22640,
436,
24840,
4110,
787,
1202,
370,
11075,
314,
15984,
13,
600,
272,
7468,
554,
14,
9322,
787,
8717,
315,
642,
805,
543,
24628,
370,
325,
482,
272,
1059,
26518,
14,
339,
14504,
26,
1455,
921,
4853,
14,
5031,
14,
957,
15,
7435,
14,
1360,
3,
5146,
13,
460,
13,
2634,
272,
1449,
272,
1006,
63,
5146,
275,
942,
272,
340,
1004,
26,
267,
327,
437,
6246,
4066,
465,
1592,
59,
17,
26,
22,
11285,
932,
365,
8652,
370,
18581,
267,
327,
7795,
4184,
26,
267,
327,
4854,
26,
283,
697,
7,
267,
327,
302,
1842,
26,
359,
17,
26,
22,
11566,
1425,
342,
365,
282,
6137,
13,
262,
14,
6855,
1133,
675,
314,
536,
267,
327,
9483,
26,
2475,
932,
7,
398,
327,
2654,
2291,
367,
3663,
12271,
315,
282,
1591,
880,
26,
267,
327,
1592,
59,
614,
26,
709,
26,
19,
61,
932,
13,
59,
614,
26,
709,
61,
267,
327,
446,
370,
886,
642,
781,
3715,
2331,
737,
314,
1642,
359,
18737,
663,
12,
10232,
314,
769,
267,
327,
257,
402,
7057,
436,
2066,
11982,
5133,
7179,
3602,
14,
267,
327,
446,
2597,
1050,
376,
2716,
10919,
2725,
1314,
3509,
314,
3650,
14,
334,
2698,
26,
413,
9,
267,
327,
257,
880,
1425,
883,
506,
359,
614,
26,
709,
26,
18,
61,
1035,
17163,
30569,
22528,
24937,
21798,
267,
327,
7600,
26,
1852,
642,
1736,
367,
23331,
764,
8013,
4634,
14,
398,
334,
2993,
12,
302,
1842,
12,
9483,
9,
275,
1004,
14,
1814,
11894,
1673,
26320,
17,
680,
1814,
360,
61,
1673,
26320,
17,
680,
1294,
20137,
358,
267,
10461,
275,
302,
1842,
14,
1294,
20063,
267,
340,
822,
8,
9632,
9,
1137,
499,
436,
822,
8,
9632,
9,
1137,
650,
26,
288,
746,
2552,
14,
29107,
480,
1102,
1425,
22743,
2013,
531,
267,
31191,
275,
10461,
59,
16,
61,
267,
1284,
275,
10461,
59,
17,
61,
267,
340,
822,
8,
9632,
9,
508,
499,
26,
288,
3650,
275,
413,
267,
587,
26,
288,
3650,
275,
10461,
59,
18,
61,
267,
340,
440,
31191,
26,
288,
31191,
275,
298,
16,
2,
267,
340,
440,
1284,
26,
288,
746,
2552,
14,
29107,
480,
1102,
1425,
1284,
574,
4124,
531,
267,
340,
31191,
59,
16,
61,
508,
283,
16,
7,
436,
822,
8,
26349,
9,
690,
413,
26,
288,
24746,
275,
822,
8,
26349,
9,
327,
1425,
2582,
10803,
8328,
288,
340,
24746,
1137,
822,
8,
500,
304,
355,
746,
2552,
14,
29107,
480,
1102,
1425,
1475,
22743,
2013,
9124,
288,
5554,
275,
2400,
24700,
620,
1547,
680,
26626,
8,
82,
552,
9,
221,
327,
1425,
3414,
267,
587,
26,
288,
5554,
275,
620,
398,
862,
26,
288,
284,
63,
26349,
275,
1059,
14,
4371,
63,
16415,
14,
1080,
8,
26349,
9,
288,
284,
63,
500,
275,
1059,
14,
4371,
63,
16415,
14,
1080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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
] |
gangadhar-kadam/smrterp
|
erpnext/setup/install.py
|
3
|
3025
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
<a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
def after_install():
frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
set_single_defaults()
import_country_and_currency()
from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts
import_charts()
frappe.db.set_default('desktop:home_page', 'setup-wizard')
feature_setup()
from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
add_all_roles_to("Administrator")
frappe.db.commit()
def import_country_and_currency():
from frappe.country_info import get_all
data = get_all()
for name in data:
country = frappe._dict(data[name])
if not frappe.db.exists("Country", name):
frappe.get_doc({
"doctype": "Country",
"country_name": name,
"code": country.code,
"date_format": country.date_format or "dd-mm-yyyy",
"time_zones": "\n".join(country.timezones or [])
}).insert()
if country.currency and not frappe.db.exists("Currency", country.currency):
frappe.get_doc({
"doctype": "Currency",
"currency_name": country.currency,
"fraction": country.currency_fraction,
"symbol": country.currency_symbol,
"fraction_units": country.currency_fraction_units,
"number_format": country.number_format
}).insert()
# enable frequently used currencies
for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
frappe.db.set_value("Currency", currency, "enabled", 1)
def feature_setup():
"""save global defaults and features setup"""
doc = frappe.get_doc("Features Setup", "Features Setup")
doc.ignore_permissions = True
# store value as 1 for all these fields
flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
'fs_page_break', 'fs_more_info', 'fs_pos_view'
]
for f in flds:
doc.set(f, 1)
doc.save()
def set_single_defaults():
for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
where parent=%s""", dt)
if default_values:
try:
b = frappe.get_doc(dt, dt)
for fieldname, value in default_values:
b.set(fieldname, value)
b.save()
except frappe.MandatoryError:
pass
frappe.db.set_default("date_format", "dd-mm-yyyy")
frappe.db.set_value("Outgoing Email Settings", "Outgoing Email Settings", "footer",
default_mail_footer)
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
6950,
199,
199,
504,
6950,
492,
485,
199,
199,
885,
63,
1198,
63,
12781,
275,
8894,
3015,
3449,
628,
8358,
26,
1520,
5326,
27,
1318,
13,
5743,
26,
2451,
27,
3164,
26,
327,
13997,
8186,
7241,
30,
17367,
4799,
199,
198,
28,
65,
3449,
628,
2326,
26,
327,
13997,
2,
4369,
628,
1014,
921,
281,
23416,
14,
1308,
1743,
6758,
5765,
1108,
65,
2957,
3015,
11193,
199,
199,
318,
2410,
63,
3174,
837,
199,
198,
9098,
14,
362,
63,
1301,
3252,
6356,
356,
298,
7422,
401,
298,
3756,
63,
354,
582,
298,
8014,
7769,
3570,
680,
3176,
342,
199,
198,
409,
63,
4780,
63,
4322,
342,
199,
198,
646,
63,
6063,
63,
460,
63,
4968,
342,
199,
198,
504,
29106,
14,
8370,
14,
6356,
14,
9019,
63,
1618,
63,
8370,
14,
646,
63,
31522,
492,
492,
63,
31522,
199,
198,
646,
63,
31522,
342,
199,
198,
9098,
14,
697,
14,
409,
63,
885,
360,
14487,
26,
4219,
63,
1606,
297,
283,
2758,
13,
9819,
358,
199,
198,
4445,
63,
2758,
342,
199,
198,
504,
29106,
14,
2758,
14,
1606,
14,
2758,
63,
9819,
14,
2758,
63,
9819,
492,
1050,
63,
452,
63,
8050,
63,
475,
199,
198,
525,
63,
452,
63,
8050,
63,
475,
480,
31972,
531,
199,
198,
9098,
14,
697,
14,
3543,
342,
199,
199,
318,
492,
63,
6063,
63,
460,
63,
4968,
837,
199,
198,
504,
6950,
14,
6063,
63,
815,
492,
664,
63,
452,
199,
198,
576,
275,
664,
63,
452,
342,
421,
198,
509,
536,
315,
666,
26,
507,
198,
6063,
275,
6950,
423,
807,
8,
576,
59,
354,
566,
507,
198,
692,
440,
6950,
14,
697,
14,
2444,
480,
17393,
401,
536,
304,
686,
198,
9098,
14,
362,
63,
1301,
2561,
1585,
198,
2,
6356,
582,
298,
17393,
401,
1585,
198,
2,
6063,
63,
354,
582,
536,
12,
1585,
198,
2,
600,
582,
9023,
14,
600,
12,
1585,
198,
2,
602,
63,
908,
582,
9023,
14,
602,
63,
908,
503,
298,
617,
13,
596,
13,
18322,
401,
1585,
198,
2,
521,
63,
13325,
582,
1867,
78,
1674,
904,
8,
6063,
14,
7145,
83,
503,
3073,
686,
198,
21385,
3176,
342,
2742,
198,
692,
9023,
14,
4968,
436,
440,
6950,
14,
697,
14,
2444,
480,
19567,
401,
9023,
14,
4968,
304,
686,
198,
9098,
14,
362,
63,
1301,
2561,
1585,
198,
2,
6356,
582,
298,
19567,
401,
1585,
198,
2,
4968,
63,
354,
582,
9023,
14,
4968,
12,
1585,
198,
2,
13054,
582,
9023,
14,
4968,
63,
13054,
12,
1585,
198,
2,
5155,
582,
9023,
14,
4968,
63,
5155,
12,
1585,
198,
2,
13054,
63,
5260,
582,
9023,
14,
4968,
63,
13054,
63,
5260,
12,
1585,
198,
2,
1955,
63,
908,
582,
9023,
14,
1955,
63,
908,
686,
198,
21385,
3176,
342,
421,
198,
3,
4756,
28914,
590,
1202,
1094,
828,
2578,
199,
198,
509,
9952,
315,
1689,
568,
50,
401,
298,
1668,
36,
401,
298,
6487,
48,
401,
298,
37,
1230,
401,
298,
33,
1149,
401,
298,
33,
3383,
401,
298,
42,
4521,
401,
298,
12874,
57,
401,
298,
1244,
38,
2349,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
19567,
401,
9952,
12,
298,
3827,
401,
413,
9,
199,
199,
318,
3878,
63,
2758,
837,
199,
198,
624,
2117,
2288,
4243,
436,
4534,
3272,
624,
199,
198,
1301,
275,
6950,
14,
362,
63,
1301,
480,
10807,
12439,
401,
298,
10807,
12439,
531,
199,
198,
1301,
14,
4247,
63,
6060,
275,
715,
421,
198,
3,
3877,
574,
465,
413,
367,
1006,
3520,
1504,
199,
198,
2327,
795,
275,
788,
2319,
63,
1053,
63,
2171,
63,
12712,
297,
283,
2319,
63,
1053,
63,
2912,
63,
12712,
297,
283,
2319,
63,
3289,
5915,
297,
283,
2319,
63,
1053,
63,
22091,
297,
507,
198,
7,
2319,
63,
1053,
63,
14652,
297,
283,
2319,
63,
1389,
316,
63,
5087,
297,
283,
2319,
63,
1053,
63,
923,
63,
262,
63,
5087,
297,
507,
198,
7,
2319,
63,
20775,
297,
283,
2319,
63,
12775,
297,
283,
2319,
63,
2297,
6851,
297,
283,
2319,
63,
9533,
63,
2297,
6851,
297,
507,
198,
7,
2319,
63,
4399,
63,
16175,
63,
3615,
279,
6011,
297,
283,
2319,
63,
6776,
297,
283,
2319,
63,
16175,
63,
9975,
297,
507,
198,
7,
2319,
63,
6794,
5985,
63,
5404,
297,
283,
2319,
63,
1712,
297,
283,
2319,
63,
1237,
7415,
319,
4039,
297,
283,
2319,
63,
9161,
297,
507,
198,
7,
2319,
63,
1606,
63,
4785,
297,
283,
2319,
63,
6878,
63,
815,
297,
283,
2319,
63,
1712,
63,
1345,
7,
199,
198,
61,
199,
198,
509,
289,
315,
2717,
795,
26,
507,
198,
1301,
14,
409,
8,
70,
12,
413,
9,
199,
198,
1301,
14,
2117,
342,
199,
199,
318,
663,
63,
4780,
63,
4322,
837,
199,
198,
509,
4487,
315,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
3768,
804,
64,
2382,
365,
4780,
29,
17,
624,
304,
507,
198,
885,
63,
1459,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
18887,
12,
658,
885,
64,
687,
658,
2902,
3768,
792,
64,
686,
198,
4509,
1676,
2458,
83,
7208,
4487,
9,
507,
198,
692,
849,
63,
1459,
26,
686,
198,
893,
26,
1585,
198,
66,
275,
6950,
14,
362,
63,
1301,
8,
3583,
12,
4487,
9,
1585,
198,
509,
18887,
12,
574,
315,
849,
63,
1459,
26,
1871,
198,
66,
14,
409,
8,
13646,
12,
574,
9,
1585,
198,
66,
14,
2117,
342,
686,
198,
2590,
6950,
14,
45,
13530,
547,
26,
1585,
198,
1529,
421,
198,
9098,
14,
697,
14,
409,
63,
885,
480,
602,
63,
908,
401,
298,
617,
13,
596,
13,
18322,
531,
421,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
2204,
10947,
11426,
13303,
401,
298,
2204,
10947,
11426,
13303,
401,
298,
12781,
401,
507,
198,
885,
63,
1198,
63,
12781,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6171,
12,
6001,
8144,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
6950,
199,
199,
504,
6950,
492,
485,
199,
199,
885,
63,
1198,
63,
12781,
275,
8894,
3015,
3449,
628,
8358,
26,
1520,
5326,
27,
1318,
13,
5743,
26,
2451,
27,
3164,
26,
327,
13997,
8186,
7241,
30,
17367,
4799,
199,
198,
28,
65,
3449,
628,
2326,
26,
327,
13997,
2,
4369,
628,
1014,
921,
281,
23416,
14,
1308,
1743,
6758,
5765,
1108,
65,
2957,
3015,
11193,
199,
199,
318,
2410,
63,
3174,
837,
199,
198,
9098,
14,
362,
63,
1301,
3252,
6356,
356,
298,
7422,
401,
298,
3756,
63,
354,
582,
298,
8014,
7769,
3570,
680,
3176,
342,
199,
198,
409,
63,
4780,
63,
4322,
342,
199,
198,
646,
63,
6063,
63,
460,
63,
4968,
342,
199,
198,
504,
29106,
14,
8370,
14,
6356,
14,
9019,
63,
1618,
63,
8370,
14,
646,
63,
31522,
492,
492,
63,
31522,
199,
198,
646,
63,
31522,
342,
199,
198,
9098,
14,
697,
14,
409,
63,
885,
360,
14487,
26,
4219,
63,
1606,
297,
283,
2758,
13,
9819,
358,
199,
198,
4445,
63,
2758,
342,
199,
198,
504,
29106,
14,
2758,
14,
1606,
14,
2758,
63,
9819,
14,
2758,
63,
9819,
492,
1050,
63,
452,
63,
8050,
63,
475,
199,
198,
525,
63,
452,
63,
8050,
63,
475,
480,
31972,
531,
199,
198,
9098,
14,
697,
14,
3543,
342,
199,
199,
318,
492,
63,
6063,
63,
460,
63,
4968,
837,
199,
198,
504,
6950,
14,
6063,
63,
815,
492,
664,
63,
452,
199,
198,
576,
275,
664,
63,
452,
342,
421,
198,
509,
536,
315,
666,
26,
507,
198,
6063,
275,
6950,
423,
807,
8,
576,
59,
354,
566,
507,
198,
692,
440,
6950,
14,
697,
14,
2444,
480,
17393,
401,
536,
304,
686,
198,
9098,
14,
362,
63,
1301,
2561,
1585,
198,
2,
6356,
582,
298,
17393,
401,
1585,
198,
2,
6063,
63,
354,
582,
536,
12,
1585,
198,
2,
600,
582,
9023,
14,
600,
12,
1585,
198,
2,
602,
63,
908,
582,
9023,
14,
602,
63,
908,
503,
298,
617,
13,
596,
13,
18322,
401,
1585,
198,
2,
521,
63,
13325,
582,
1867,
78,
1674,
904,
8,
6063,
14,
7145,
83,
503,
3073,
686,
198,
21385,
3176,
342,
2742,
198,
692,
9023,
14,
4968,
436,
440,
6950,
14,
697,
14,
2444,
480,
19567,
401,
9023,
14,
4968,
304,
686,
198,
9098,
14,
362,
63,
1301,
2561,
1585,
198,
2,
6356,
582,
298,
19567,
401,
1585,
198,
2,
4968,
63,
354,
582,
9023,
14,
4968,
12,
1585,
198,
2,
13054,
582,
9023,
14,
4968,
63,
13054,
12,
1585,
198,
2,
5155,
582,
9023,
14,
4968,
63,
5155,
12,
1585,
198,
2,
13054,
63,
5260,
582,
9023,
14,
4968,
63,
13054,
63,
5260,
12,
1585,
198,
2,
1955,
63,
908,
582,
9023,
14,
1955,
63,
908,
686,
198,
21385,
3176,
342,
421,
198,
3,
4756,
28914,
590,
1202,
1094,
828,
2578,
199,
198,
509,
9952,
315,
1689,
568,
50,
401,
298,
1668,
36,
401,
298,
6487,
48,
401,
298,
37,
1230,
401,
298,
33,
1149,
401,
298,
33,
3383,
401,
298,
42,
4521,
401,
298,
12874,
57,
401,
298,
1244,
38,
2349,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
19567,
401,
9952,
12,
298,
3827,
401,
413,
9,
199,
199,
318,
3878,
63,
2758,
837,
199,
198,
624,
2117,
2288,
4243,
436,
4534,
3272,
624,
199,
198,
1301,
275,
6950,
14,
362,
63,
1301,
480,
10807,
12439,
401,
298,
10807,
12439,
531,
199,
198,
1301,
14,
4247,
63,
6060,
275,
715,
421,
198,
3,
3877,
574,
465,
413,
367,
1006,
3520,
1504,
199,
198,
2327,
795,
275,
788,
2319,
63,
1053,
63,
2171,
63,
12712,
297,
283,
2319,
63,
1053,
63,
2912,
63,
12712,
297,
283,
2319,
63,
3289,
5915,
297,
283,
2319,
63,
1053,
63,
22091,
297,
507,
198,
7,
2319,
63,
1053,
63,
14652,
297,
283,
2319,
63,
1389,
316,
63,
5087,
297,
283,
2319,
63,
1053,
63,
923,
63,
262,
63,
5087,
297,
507,
198,
7,
2319,
63,
20775,
297,
283,
2319,
63,
12775,
297,
283,
2319,
63,
2297,
6851,
297,
283,
2319,
63,
9533,
63,
2297,
6851,
297,
507,
198,
7,
2319,
63,
4399,
63,
16175,
63,
3615,
279,
6011,
297,
283,
2319,
63,
6776,
297,
283,
2319,
63,
16175,
63,
9975,
297,
507,
198,
7,
2319,
63,
6794,
5985,
63,
5404,
297,
283,
2319,
63,
1712,
297,
283,
2319,
63,
1237,
7415,
319,
4039,
297,
283,
2319,
63,
9161,
297,
507,
198,
7,
2319,
63,
1606,
63,
4785,
297,
283,
2319,
63,
6878,
63,
815,
297,
283,
2319,
63,
1712,
63,
1345,
7,
199,
198,
61,
199,
198,
509,
289,
315,
2717,
795,
26,
507,
198,
1301,
14,
409,
8,
70,
12,
413,
9,
199,
198,
1301,
14,
2117,
342,
199,
199,
318,
663,
63,
4780,
63,
4322,
837,
199,
198,
509,
4487,
315,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
536,
687,
658,
2902,
3768,
804,
64,
2382,
365,
4780,
29,
17,
624,
304,
507,
198,
885,
63,
1459,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
18887,
12,
658,
885,
64,
687,
658,
2902,
3768,
792,
64,
686,
198,
4509,
1676,
2458,
83,
7208,
4487,
9,
507,
198,
692,
849,
63,
1459,
26,
686,
198,
893,
26,
1585,
198,
66,
275,
6950,
14,
362,
63,
1301,
8,
3583,
12,
4487,
9,
1585,
198,
509,
18887,
12,
574,
315,
849,
63,
1459,
26,
1871,
198,
66,
14,
409,
8,
13646,
12,
574,
9,
1585,
198,
66,
14,
2117,
342,
686,
198,
2590,
6950,
14,
45,
13530,
547,
26,
1585,
198,
1529,
421,
198,
9098,
14,
697,
14,
409,
63,
885,
480,
602,
63,
908,
401,
298,
617,
13,
596,
13,
18322,
531,
421,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
2204,
10947,
11426,
13303,
401,
298,
2204,
10947,
11426,
13303,
401,
298,
12781,
401,
507,
198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,
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
] |
fvcproductions/dotfiles
|
bin/alfred/Alfred.alfredpreferences/workflows/user.workflow.DEDF5652-6FEF-4776-80D8-ACEDF577D06A/lxml/html/_html5builder.py
|
110
|
3246
|
"""
Legacy module - don't use in new code!
html5lib now has its own proper implementation.
This module implements a tree builder for html5lib that generates lxml
html element trees. This module uses camelCase as it follows the
html5lib style guide.
"""
from html5lib.treebuilders import _base, etree as etree_builders
from lxml import html, etree
class DocumentType(object):
def __init__(self, name, publicId, systemId):
self.name = name
self.publicId = publicId
self.systemId = systemId
class Document(object):
def __init__(self):
self._elementTree = None
self.childNodes = []
def appendChild(self, element):
self._elementTree.getroot().addnext(element._element)
class TreeBuilder(_base.TreeBuilder):
documentClass = Document
doctypeClass = DocumentType
elementClass = None
commentClass = None
fragmentClass = Document
def __init__(self, *args, **kwargs):
html_builder = etree_builders.getETreeModule(html, fullTree=False)
etree_builder = etree_builders.getETreeModule(etree, fullTree=False)
self.elementClass = html_builder.Element
self.commentClass = etree_builder.Comment
_base.TreeBuilder.__init__(self, *args, **kwargs)
def reset(self):
_base.TreeBuilder.reset(self)
self.rootInserted = False
self.initialComments = []
self.doctype = None
def getDocument(self):
return self.document._elementTree
def getFragment(self):
fragment = []
element = self.openElements[0]._element
if element.text:
fragment.append(element.text)
fragment.extend(element.getchildren())
if element.tail:
fragment.append(element.tail)
return fragment
def insertDoctype(self, name, publicId, systemId):
doctype = self.doctypeClass(name, publicId, systemId)
self.doctype = doctype
def insertComment(self, data, parent=None):
if not self.rootInserted:
self.initialComments.append(data)
else:
_base.TreeBuilder.insertComment(self, data, parent)
def insertRoot(self, name):
buf = []
if self.doctype and self.doctype.name:
buf.append('<!DOCTYPE %s' % self.doctype.name)
if self.doctype.publicId is not None or self.doctype.systemId is not None:
buf.append(' PUBLIC "%s" "%s"' % (self.doctype.publicId,
self.doctype.systemId))
buf.append('>')
buf.append('<html></html>')
root = html.fromstring(''.join(buf))
# Append the initial comments:
for comment in self.initialComments:
root.addprevious(etree.Comment(comment))
# Create the root document and add the ElementTree to it
self.document = self.documentClass()
self.document._elementTree = root.getroottree()
# Add the root element to the internal child/open data structures
root_element = self.elementClass(name)
root_element._element = root
self.document.childNodes.append(root_element)
self.openElements.append(root_element)
self.rootInserted = True
|
mit
|
[
624,
199,
22628,
859,
446,
2793,
1133,
675,
315,
892,
1233,
1,
199,
199,
1360,
21,
773,
3063,
965,
2399,
5705,
5576,
4514,
14,
199,
199,
2765,
859,
9031,
282,
3123,
6545,
367,
3517,
21,
773,
626,
12821,
14490,
199,
1360,
1819,
14416,
14,
221,
961,
859,
4440,
31129,
1538,
465,
652,
11924,
314,
199,
1360,
21,
773,
3449,
22885,
14,
199,
624,
199,
199,
504,
3517,
21,
773,
14,
2350,
20968,
492,
485,
1095,
12,
7559,
465,
7559,
63,
20968,
199,
504,
14490,
492,
3517,
12,
7559,
421,
199,
533,
7543,
804,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
25311,
275,
25753,
267,
291,
14,
20150,
275,
22873,
199,
199,
533,
7543,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2108,
3987,
275,
488,
267,
291,
14,
10626,
275,
942,
339,
347,
5666,
3493,
8,
277,
12,
1819,
304,
267,
291,
423,
2108,
3987,
14,
24544,
1252,
525,
2184,
8,
2108,
423,
2108,
9,
421,
199,
533,
12178,
6437,
1547,
1095,
14,
20437,
304,
272,
2213,
2543,
275,
7543,
272,
13265,
2543,
275,
7543,
804,
272,
1819,
2543,
275,
488,
272,
3721,
2543,
275,
488,
272,
7956,
2543,
275,
7543,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3517,
63,
5649,
275,
7559,
63,
20968,
14,
362,
775,
850,
2377,
8,
1360,
12,
2615,
3987,
29,
797,
9,
267,
7559,
63,
5649,
275,
7559,
63,
20968,
14,
362,
775,
850,
2377,
8,
9464,
12,
2615,
3987,
29,
797,
9,
267,
291,
14,
2108,
2543,
275,
3517,
63,
5649,
14,
2162,
267,
291,
14,
3349,
2543,
275,
7559,
63,
5649,
14,
7488,
267,
485,
1095,
14,
20437,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
5305,
8,
277,
304,
267,
485,
1095,
14,
20437,
14,
3958,
8,
277,
9,
267,
291,
14,
1231,
607,
9449,
275,
756,
267,
291,
14,
2747,
18929,
275,
942,
267,
291,
14,
6356,
275,
488,
339,
347,
664,
5564,
8,
277,
304,
267,
372,
291,
14,
3554,
423,
2108,
3987,
339,
347,
664,
11080,
8,
277,
304,
267,
7956,
275,
942,
267,
1819,
275,
291,
14,
14369,
59,
16,
18289,
2108,
267,
340,
1819,
14,
505,
26,
288,
7956,
14,
740,
8,
2108,
14,
505,
9,
267,
7956,
14,
2880,
8,
2108,
14,
362,
3223,
1012,
267,
340,
1819,
14,
1521,
26,
288,
7956,
14,
740,
8,
2108,
14,
1521,
9,
267,
372,
7956,
339,
347,
5518,
21629,
8,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
13265,
275,
291,
14,
6356,
2543,
8,
354,
12,
25753,
12,
22873,
9,
267,
291,
14,
6356,
275,
13265,
339,
347,
5518,
7488,
8,
277,
12,
666,
12,
1676,
29,
403,
304,
267,
340,
440,
291,
14,
1231,
607,
9449,
26,
288,
291,
14,
2747,
18929,
14,
740,
8,
576,
9,
267,
587,
26,
288,
485,
1095,
14,
20437,
14,
3176,
7488,
8,
277,
12,
666,
12,
1676,
9,
339,
347,
5518,
6405,
8,
277,
12,
536,
304,
267,
4123,
275,
942,
267,
340,
291,
14,
6356,
436,
291,
14,
6356,
14,
354,
26,
288,
4123,
14,
740,
4827,
1,
16556,
450,
83,
7,
450,
291,
14,
6356,
14,
354,
9,
288,
340,
291,
14,
6356,
14,
25311,
365,
440,
488,
503,
291,
14,
6356,
14,
20150,
365,
440,
488,
26,
355,
4123,
14,
740,
360,
21755,
2071,
83,
2,
2071,
83,
4507,
450,
334,
277,
14,
6356,
14,
25311,
12,
8179,
291,
14,
6356,
14,
20150,
430,
288,
4123,
14,
740,
28781,
267,
4123,
14,
740,
4827,
1360,
2957,
1360,
5971,
267,
1738,
275,
3517,
14,
13521,
17840,
904,
8,
1436,
430,
398,
327,
18726,
314,
2536,
6786,
26,
267,
367,
3721,
315,
291,
14,
2747,
18929,
26,
288,
1738,
14,
525,
6352,
8,
9464,
14,
7488,
8,
3349,
430,
398,
327,
2790,
314,
1738,
2213,
436,
1050,
314,
13139,
370,
652,
267,
291,
14,
3554,
275,
291,
14,
3554,
2543,
342,
267,
291,
14,
3554,
423,
2108,
3987,
275,
1738,
14,
24544,
2350,
342,
398,
327,
2654,
314,
1738,
1819,
370,
314,
5007,
1982,
15,
1490,
666,
13955,
267,
1738,
63,
2108,
275,
291,
14,
2108,
2543,
8,
354,
9,
267,
1738,
63,
2108,
423,
2108,
275,
1738,
267,
291,
14,
3554,
14,
10626,
14,
740,
8,
1231,
63,
2108,
9,
267,
291,
14,
14369,
14,
740,
8,
1231,
63,
2108,
9,
398,
291,
14,
1231,
607,
9449,
275,
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
] |
[
199,
22628,
859,
446,
2793,
1133,
675,
315,
892,
1233,
1,
199,
199,
1360,
21,
773,
3063,
965,
2399,
5705,
5576,
4514,
14,
199,
199,
2765,
859,
9031,
282,
3123,
6545,
367,
3517,
21,
773,
626,
12821,
14490,
199,
1360,
1819,
14416,
14,
221,
961,
859,
4440,
31129,
1538,
465,
652,
11924,
314,
199,
1360,
21,
773,
3449,
22885,
14,
199,
624,
199,
199,
504,
3517,
21,
773,
14,
2350,
20968,
492,
485,
1095,
12,
7559,
465,
7559,
63,
20968,
199,
504,
14490,
492,
3517,
12,
7559,
421,
199,
533,
7543,
804,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
25311,
275,
25753,
267,
291,
14,
20150,
275,
22873,
199,
199,
533,
7543,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2108,
3987,
275,
488,
267,
291,
14,
10626,
275,
942,
339,
347,
5666,
3493,
8,
277,
12,
1819,
304,
267,
291,
423,
2108,
3987,
14,
24544,
1252,
525,
2184,
8,
2108,
423,
2108,
9,
421,
199,
533,
12178,
6437,
1547,
1095,
14,
20437,
304,
272,
2213,
2543,
275,
7543,
272,
13265,
2543,
275,
7543,
804,
272,
1819,
2543,
275,
488,
272,
3721,
2543,
275,
488,
272,
7956,
2543,
275,
7543,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3517,
63,
5649,
275,
7559,
63,
20968,
14,
362,
775,
850,
2377,
8,
1360,
12,
2615,
3987,
29,
797,
9,
267,
7559,
63,
5649,
275,
7559,
63,
20968,
14,
362,
775,
850,
2377,
8,
9464,
12,
2615,
3987,
29,
797,
9,
267,
291,
14,
2108,
2543,
275,
3517,
63,
5649,
14,
2162,
267,
291,
14,
3349,
2543,
275,
7559,
63,
5649,
14,
7488,
267,
485,
1095,
14,
20437,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
5305,
8,
277,
304,
267,
485,
1095,
14,
20437,
14,
3958,
8,
277,
9,
267,
291,
14,
1231,
607,
9449,
275,
756,
267,
291,
14,
2747,
18929,
275,
942,
267,
291,
14,
6356,
275,
488,
339,
347,
664,
5564,
8,
277,
304,
267,
372,
291,
14,
3554,
423,
2108,
3987,
339,
347,
664,
11080,
8,
277,
304,
267,
7956,
275,
942,
267,
1819,
275,
291,
14,
14369,
59,
16,
18289,
2108,
267,
340,
1819,
14,
505,
26,
288,
7956,
14,
740,
8,
2108,
14,
505,
9,
267,
7956,
14,
2880,
8,
2108,
14,
362,
3223,
1012,
267,
340,
1819,
14,
1521,
26,
288,
7956,
14,
740,
8,
2108,
14,
1521,
9,
267,
372,
7956,
339,
347,
5518,
21629,
8,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
13265,
275,
291,
14,
6356,
2543,
8,
354,
12,
25753,
12,
22873,
9,
267,
291,
14,
6356,
275,
13265,
339,
347,
5518,
7488,
8,
277,
12,
666,
12,
1676,
29,
403,
304,
267,
340,
440,
291,
14,
1231,
607,
9449,
26,
288,
291,
14,
2747,
18929,
14,
740,
8,
576,
9,
267,
587,
26,
288,
485,
1095,
14,
20437,
14,
3176,
7488,
8,
277,
12,
666,
12,
1676,
9,
339,
347,
5518,
6405,
8,
277,
12,
536,
304,
267,
4123,
275,
942,
267,
340,
291,
14,
6356,
436,
291,
14,
6356,
14,
354,
26,
288,
4123,
14,
740,
4827,
1,
16556,
450,
83,
7,
450,
291,
14,
6356,
14,
354,
9,
288,
340,
291,
14,
6356,
14,
25311,
365,
440,
488,
503,
291,
14,
6356,
14,
20150,
365,
440,
488,
26,
355,
4123,
14,
740,
360,
21755,
2071,
83,
2,
2071,
83,
4507,
450,
334,
277,
14,
6356,
14,
25311,
12,
8179,
291,
14,
6356,
14,
20150,
430,
288,
4123,
14,
740,
28781,
267,
4123,
14,
740,
4827,
1360,
2957,
1360,
5971,
267,
1738,
275,
3517,
14,
13521,
17840,
904,
8,
1436,
430,
398,
327,
18726,
314,
2536,
6786,
26,
267,
367,
3721,
315,
291,
14,
2747,
18929,
26,
288,
1738,
14,
525,
6352,
8,
9464,
14,
7488,
8,
3349,
430,
398,
327,
2790,
314,
1738,
2213,
436,
1050,
314,
13139,
370,
652,
267,
291,
14,
3554,
275,
291,
14,
3554,
2543,
342,
267,
291,
14,
3554,
423,
2108,
3987,
275,
1738,
14,
24544,
2350,
342,
398,
327,
2654,
314,
1738,
1819,
370,
314,
5007,
1982,
15,
1490,
666,
13955,
267,
1738,
63,
2108,
275,
291,
14,
2108,
2543,
8,
354,
9,
267,
1738,
63,
2108,
423,
2108,
275,
1738,
267,
291,
14,
3554,
14,
10626,
14,
740,
8,
1231,
63,
2108,
9,
267,
291,
14,
14369,
14,
740,
8,
1231,
63,
2108,
9,
398,
291,
14,
1231,
607,
9449,
275,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bobcyw/django
|
tests/model_validation/tests.py
|
292
|
2117
|
from django.core import management
from django.core.checks import Error, run_checks
from django.db.models.signals import post_init
from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.utils import six
class OnPostInit(object):
def __call__(self, **kwargs):
pass
def on_post_init(**kwargs):
pass
@override_settings(
INSTALLED_APPS=['django.contrib.auth', 'django.contrib.contenttypes'],
SILENCED_SYSTEM_CHECKS=['fields.W342'], # ForeignKey(unique=True)
)
class ModelValidationTest(SimpleTestCase):
def test_models_validate(self):
# All our models should validate properly
# Validation Tests:
# * choices= Iterable of Iterables
# See: https://code.djangoproject.com/ticket/20430
# * related_name='+' doesn't clash with another '+'
# See: https://code.djangoproject.com/ticket/21375
management.call_command("check", stdout=six.StringIO())
def test_model_signal(self):
unresolved_references = post_init.unresolved_references.copy()
post_init.connect(on_post_init, sender='missing-app.Model')
post_init.connect(OnPostInit(), sender='missing-app.Model')
errors = run_checks()
expected = [
Error(
"The 'on_post_init' function was connected to the 'post_init' "
"signal with a lazy reference to the 'missing-app.Model' "
"sender, which has not been installed.",
hint=None,
obj='model_validation.tests',
id='signals.E001',
),
Error(
"An instance of the 'OnPostInit' class was connected to "
"the 'post_init' signal with a lazy reference to the "
"'missing-app.Model' sender, which has not been installed.",
hint=None,
obj='model_validation.tests',
id='signals.E001',
)
]
self.assertEqual(errors, expected)
post_init.unresolved_references = unresolved_references
|
bsd-3-clause
|
[
504,
1639,
14,
1018,
492,
10041,
199,
504,
1639,
14,
1018,
14,
8625,
492,
4520,
12,
1255,
63,
8625,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
826,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
4068,
6564,
9346,
8,
785,
304,
272,
347,
636,
1250,
721,
277,
12,
1011,
958,
304,
267,
986,
421,
199,
318,
641,
63,
1932,
63,
826,
3682,
958,
304,
272,
986,
421,
199,
32,
4415,
63,
1751,
8,
272,
31061,
63,
14219,
2968,
1176,
14,
2828,
14,
1178,
297,
283,
1176,
14,
2828,
14,
10778,
995,
272,
428,
1193,
9415,
1149,
63,
12711,
63,
8936,
51,
2968,
955,
14,
55,
14519,
995,
221,
327,
12718,
8,
3235,
29,
549,
9,
199,
9,
199,
533,
5822,
13816,
774,
8,
17968,
304,
272,
347,
511,
63,
992,
63,
3502,
8,
277,
304,
267,
327,
2900,
4154,
1709,
1077,
4107,
7684,
267,
327,
19381,
6496,
26,
267,
327,
257,
627,
3415,
29,
19937,
402,
19937,
83,
267,
327,
755,
1666,
26,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
6686,
1216,
267,
327,
257,
627,
4048,
63,
354,
534,
4786,
3181,
1133,
30109,
543,
4573,
20246,
267,
327,
755,
1666,
26,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
14271,
2194,
267,
10041,
14,
1250,
63,
1531,
480,
1074,
401,
3839,
29,
4174,
14,
6424,
1012,
339,
347,
511,
63,
1238,
63,
4653,
8,
277,
304,
267,
625,
13697,
63,
12635,
275,
2963,
63,
826,
14,
324,
13697,
63,
12635,
14,
1574,
342,
267,
2963,
63,
826,
14,
2242,
8,
265,
63,
1932,
63,
826,
12,
8904,
534,
4752,
13,
571,
14,
1685,
358,
267,
2963,
63,
826,
14,
2242,
8,
3314,
6564,
9346,
1062,
8904,
534,
4752,
13,
571,
14,
1685,
358,
398,
2552,
275,
1255,
63,
8625,
342,
267,
1420,
275,
359,
288,
4520,
8,
355,
298,
1918,
283,
265,
63,
1932,
63,
826,
7,
805,
1990,
8539,
370,
314,
283,
1932,
63,
826,
7,
298,
355,
298,
4653,
543,
282,
9617,
3659,
370,
314,
283,
4752,
13,
571,
14,
1685,
7,
298,
355,
298,
8114,
12,
1314,
965,
440,
2757,
4903,
4765,
355,
8328,
29,
403,
12,
355,
1559,
534,
1238,
63,
6136,
14,
2219,
297,
355,
1305,
534,
10458,
14,
37,
4587,
297,
288,
2318,
288,
4520,
8,
355,
298,
2493,
1256,
402,
314,
283,
3314,
6564,
9346,
7,
1021,
1990,
8539,
370,
298,
355,
298,
1589,
283,
1932,
63,
826,
7,
4673,
543,
282,
9617,
3659,
370,
314,
298,
355,
3546,
4752,
13,
571,
14,
1685,
7,
8904,
12,
1314,
965,
440,
2757,
4903,
4765,
355,
8328,
29,
403,
12,
355,
1559,
534,
1238,
63,
6136,
14,
2219,
297,
355,
1305,
534,
10458,
14,
37,
4587,
297,
288,
776,
267,
1622,
267,
291,
14,
629,
8,
2550,
12,
1420,
9,
398,
2963,
63,
826,
14,
324,
13697,
63,
12635,
275,
625,
13697,
63,
12635,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1018,
492,
10041,
199,
504,
1639,
14,
1018,
14,
8625,
492,
4520,
12,
1255,
63,
8625,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
826,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
4068,
6564,
9346,
8,
785,
304,
272,
347,
636,
1250,
721,
277,
12,
1011,
958,
304,
267,
986,
421,
199,
318,
641,
63,
1932,
63,
826,
3682,
958,
304,
272,
986,
421,
199,
32,
4415,
63,
1751,
8,
272,
31061,
63,
14219,
2968,
1176,
14,
2828,
14,
1178,
297,
283,
1176,
14,
2828,
14,
10778,
995,
272,
428,
1193,
9415,
1149,
63,
12711,
63,
8936,
51,
2968,
955,
14,
55,
14519,
995,
221,
327,
12718,
8,
3235,
29,
549,
9,
199,
9,
199,
533,
5822,
13816,
774,
8,
17968,
304,
272,
347,
511,
63,
992,
63,
3502,
8,
277,
304,
267,
327,
2900,
4154,
1709,
1077,
4107,
7684,
267,
327,
19381,
6496,
26,
267,
327,
257,
627,
3415,
29,
19937,
402,
19937,
83,
267,
327,
755,
1666,
26,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
6686,
1216,
267,
327,
257,
627,
4048,
63,
354,
534,
4786,
3181,
1133,
30109,
543,
4573,
20246,
267,
327,
755,
1666,
26,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
14271,
2194,
267,
10041,
14,
1250,
63,
1531,
480,
1074,
401,
3839,
29,
4174,
14,
6424,
1012,
339,
347,
511,
63,
1238,
63,
4653,
8,
277,
304,
267,
625,
13697,
63,
12635,
275,
2963,
63,
826,
14,
324,
13697,
63,
12635,
14,
1574,
342,
267,
2963,
63,
826,
14,
2242,
8,
265,
63,
1932,
63,
826,
12,
8904,
534,
4752,
13,
571,
14,
1685,
358,
267,
2963,
63,
826,
14,
2242,
8,
3314,
6564,
9346,
1062,
8904,
534,
4752,
13,
571,
14,
1685,
358,
398,
2552,
275,
1255,
63,
8625,
342,
267,
1420,
275,
359,
288,
4520,
8,
355,
298,
1918,
283,
265,
63,
1932,
63,
826,
7,
805,
1990,
8539,
370,
314,
283,
1932,
63,
826,
7,
298,
355,
298,
4653,
543,
282,
9617,
3659,
370,
314,
283,
4752,
13,
571,
14,
1685,
7,
298,
355,
298,
8114,
12,
1314,
965,
440,
2757,
4903,
4765,
355,
8328,
29,
403,
12,
355,
1559,
534,
1238,
63,
6136,
14,
2219,
297,
355,
1305,
534,
10458,
14,
37,
4587,
297,
288,
2318,
288,
4520,
8,
355,
298,
2493,
1256,
402,
314,
283,
3314,
6564,
9346,
7,
1021,
1990,
8539,
370,
298,
355,
298,
1589,
283,
1932,
63,
826,
7,
4673,
543,
282,
9617,
3659,
370,
314,
298,
355,
3546,
4752,
13,
571,
14,
1685,
7,
8904,
12,
1314,
965,
440,
2757,
4903,
4765,
355,
8328,
29,
403,
12,
355,
1559,
534,
1238,
63,
6136,
14,
2219,
297,
355,
1305,
534,
10458,
14,
37,
4587,
297,
288,
776,
267,
1622,
267,
291,
14,
629,
8,
2550,
12,
1420,
9,
398,
2963,
63,
826,
14,
324,
13697,
63,
12635,
275,
625,
13697,
63,
12635,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
md384/media-reminder
|
mediadownloader/subtitles/open_subtitles.py
|
1
|
3048
|
import io
import os
import struct
import urllib.request
import zipfile
from xmlrpc.client import ServerProxy
from mediadownloader.subtitles.base_subtitles import BaseSubtitles
class OpenSubtitles(BaseSubtitles):
OPENSUBTITLES_SERVER = 'http://api.opensubtitles.org/xml-rpc'
USER_AGENT = 'OSTestUserAgentTemp'
def __init__(self, user_agent=USER_AGENT):
self.xmlrpc = ServerProxy(OpenSubtitles.OPENSUBTITLES_SERVER, allow_none=True)
self.token = self.xmlrpc.LogIn('', '', 'eng', user_agent)['token']
def has_subtitles(self, file_path):
hash = self._hash_file(file_path)
file_size = os.path.getsize(file_path)
return self._search_by_hash(hash, file_size) is not None
def download(self, file_path, subtitle_path):
dl_url = self._search_by_hash(self._hash_file(file_path), self._get_file_size(file_path))
if not dl_url:
raise Exception()
self._download_subtitles(dl_url, subtitle_path)
@staticmethod
def _hash_file(filepath):
try:
longlongformat = '<q' # little-endian long long
bytesize = struct.calcsize(longlongformat)
f = open(filepath, "rb")
filesize = os.path.getsize(filepath)
hash = filesize
if filesize < 65536 * 2:
return "SizeError"
for x in range(65536 // bytesize):
buffer = f.read(bytesize)
(l_value,) = struct.unpack(longlongformat, buffer)
hash += l_value
hash = hash & 0xFFFFFFFFFFFFFFFF # to remain as 64bit number
f.seek(max(0, filesize - 65536), 0)
for x in range(65536 // bytesize):
buffer = f.read(bytesize)
(l_value,) = struct.unpack(longlongformat, buffer)
hash += l_value
hash = hash & 0xFFFFFFFFFFFFFFFF
f.close()
returned_hash = "%016x" % hash
return returned_hash
except IOError:
return "IOError"
def _search_by_hash(self, hash, size):
if not self.token:
raise PermissionError('Token is null, login first')
data = self.xmlrpc.SearchSubtitles(self.token, [{'moviehash': hash, 'moviebytesize': str(size),
'sublanguageid': 'eng'}])['data']
if len(data) == 0:
return None
else:
return data[0]['ZipDownloadLink']
@staticmethod
def _download_subtitles(url, output_path):
with urllib.request.urlopen(url) as zipresp:
with zipfile.ZipFile(io.BytesIO(zipresp.read())) as zfile, open(output_path, 'wb') as out_file:
file = list(filter(lambda x: x.endswith('.srt'), zfile.namelist()))
if len(file) != 1:
raise RuntimeError('Cannot extract subtitles')
out_file.write(zfile.read(file[0]))
@staticmethod
def _get_file_size(path):
return os.path.getsize(path)
|
mit
|
[
646,
5890,
199,
646,
747,
199,
646,
2702,
199,
646,
4011,
14,
1069,
199,
646,
10392,
199,
504,
15432,
14,
1258,
492,
7146,
4936,
199,
199,
504,
25796,
350,
944,
3422,
14,
16858,
14,
1095,
63,
16858,
492,
3523,
2610,
8916,
421,
199,
533,
3232,
2610,
8916,
8,
1563,
2610,
8916,
304,
339,
24164,
6348,
52,
649,
11344,
63,
6613,
275,
283,
1014,
921,
1246,
14,
1490,
16858,
14,
1308,
15,
1652,
13,
4354,
7,
272,
13044,
63,
14565,
275,
283,
3100,
774,
1899,
7788,
6530,
7,
339,
347,
636,
826,
721,
277,
12,
922,
63,
4054,
29,
3791,
63,
14565,
304,
267,
291,
14,
17596,
275,
7146,
4936,
8,
4299,
2610,
8916,
14,
9935,
6348,
52,
649,
11344,
63,
6613,
12,
2040,
63,
3592,
29,
549,
9,
267,
291,
14,
1418,
275,
291,
14,
17596,
14,
2445,
607,
8594,
3260,
283,
7420,
297,
922,
63,
4054,
11820,
1418,
418,
339,
347,
965,
63,
16858,
8,
277,
12,
570,
63,
515,
304,
267,
2631,
275,
291,
423,
2227,
63,
493,
8,
493,
63,
515,
9,
267,
570,
63,
890,
275,
747,
14,
515,
14,
20733,
8,
493,
63,
515,
9,
267,
372,
291,
423,
1733,
63,
991,
63,
2227,
8,
2227,
12,
570,
63,
890,
9,
365,
440,
488,
339,
347,
5235,
8,
277,
12,
570,
63,
515,
12,
18197,
63,
515,
304,
267,
15396,
63,
633,
275,
291,
423,
1733,
63,
991,
63,
2227,
8,
277,
423,
2227,
63,
493,
8,
493,
63,
515,
395,
291,
423,
362,
63,
493,
63,
890,
8,
493,
63,
515,
430,
267,
340,
440,
15396,
63,
633,
26,
288,
746,
2186,
342,
267,
291,
423,
4249,
63,
16858,
8,
5030,
63,
633,
12,
18197,
63,
515,
9,
339,
768,
4639,
272,
347,
485,
2227,
63,
493,
8,
7218,
304,
267,
862,
26,
288,
1846,
2809,
908,
275,
2650,
81,
7,
221,
327,
12050,
13,
15009,
1846,
1846,
288,
3696,
890,
275,
2702,
14,
21691,
8,
2809,
2809,
908,
9,
953,
289,
275,
1551,
8,
7218,
12,
298,
4848,
531,
953,
23858,
275,
747,
14,
515,
14,
20733,
8,
7218,
9,
288,
2631,
275,
23858,
953,
340,
23858,
665,
25980,
627,
499,
26,
355,
372,
298,
2320,
547,
2,
953,
367,
671,
315,
1425,
8,
10027,
1344,
5001,
3696,
890,
304,
355,
3335,
275,
289,
14,
739,
8,
4414,
890,
9,
355,
334,
76,
63,
585,
4258,
275,
2702,
14,
5301,
8,
2809,
2809,
908,
12,
3335,
9,
355,
2631,
847,
634,
63,
585,
355,
2631,
275,
2631,
1253,
378,
32158,
18073,
221,
327,
370,
5706,
465,
5049,
2075,
1329,
953,
289,
14,
5507,
8,
988,
8,
16,
12,
23858,
446,
25980,
395,
378,
9,
288,
367,
671,
315,
1425,
8,
10027,
1344,
5001,
3696,
890,
304,
355,
3335,
275,
289,
14,
739,
8,
4414,
890,
9,
355,
334,
76,
63,
585,
4258,
275,
2702,
14,
5301,
8,
2809,
2809,
908,
12,
3335,
9,
355,
2631,
847,
634,
63,
585,
355,
2631,
275,
2631,
1253,
378,
32158,
18073,
953,
289,
14,
1600,
342,
288,
2138,
63,
2227,
275,
2071,
10882,
88,
2,
450,
2631,
288,
372,
2138,
63,
2227,
267,
871,
5925,
26,
288,
372,
298,
13760,
2,
339,
347,
485,
1733,
63,
991,
63,
2227,
8,
277,
12,
2631,
12,
1568,
304,
267,
340,
440,
291,
14,
1418,
26,
288,
746,
8779,
547,
360,
3264,
365,
2973,
12,
4676,
1642,
358,
267,
666,
275,
291,
14,
17596,
14,
5278,
2610,
8916,
8,
277,
14,
1418,
12,
9016,
10888,
2227,
356,
2631,
12,
283,
10888,
4414,
890,
356,
620,
8,
890,
395,
12740,
283,
954,
3671,
344,
356,
283,
7420,
936,
566,
459,
576,
418,
267,
340,
822,
8,
576,
9,
508,
378,
26,
288,
372,
488,
267,
587,
26,
288,
372,
666,
59,
16,
2733,
8674,
11950,
3834,
418,
339,
768,
4639,
272,
347,
485,
4249,
63,
16858,
8,
633,
12,
1072,
63,
515,
304,
267,
543,
4011,
14,
1069,
14,
10890,
8,
633,
9,
465,
3482,
4518,
26,
288,
543,
10392,
14,
15016,
8,
2308,
14,
15466,
8,
3065,
4518,
14,
739,
4059,
465,
1315,
493,
12,
1551,
8,
1199,
63,
515,
12,
283,
6603,
358,
465,
734,
63,
493,
26,
355,
570,
275,
769,
8,
1541,
8,
2734,
671,
26,
671,
14,
4130,
5175,
24336,
659,
1315,
493,
14,
23841,
4059,
355,
340,
822,
8,
493,
9,
1137,
413,
26,
490,
746,
6064,
360,
6612,
5536,
19297,
358,
355,
734,
63,
493,
14,
952,
8,
90,
493,
14,
739,
8,
493,
59,
16,
2459,
339,
768,
4639,
272,
347,
485,
362,
63,
493,
63,
890,
8,
515,
304,
267,
372,
747,
14,
515,
14,
20733,
8,
515,
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
] |
[
5890,
199,
646,
747,
199,
646,
2702,
199,
646,
4011,
14,
1069,
199,
646,
10392,
199,
504,
15432,
14,
1258,
492,
7146,
4936,
199,
199,
504,
25796,
350,
944,
3422,
14,
16858,
14,
1095,
63,
16858,
492,
3523,
2610,
8916,
421,
199,
533,
3232,
2610,
8916,
8,
1563,
2610,
8916,
304,
339,
24164,
6348,
52,
649,
11344,
63,
6613,
275,
283,
1014,
921,
1246,
14,
1490,
16858,
14,
1308,
15,
1652,
13,
4354,
7,
272,
13044,
63,
14565,
275,
283,
3100,
774,
1899,
7788,
6530,
7,
339,
347,
636,
826,
721,
277,
12,
922,
63,
4054,
29,
3791,
63,
14565,
304,
267,
291,
14,
17596,
275,
7146,
4936,
8,
4299,
2610,
8916,
14,
9935,
6348,
52,
649,
11344,
63,
6613,
12,
2040,
63,
3592,
29,
549,
9,
267,
291,
14,
1418,
275,
291,
14,
17596,
14,
2445,
607,
8594,
3260,
283,
7420,
297,
922,
63,
4054,
11820,
1418,
418,
339,
347,
965,
63,
16858,
8,
277,
12,
570,
63,
515,
304,
267,
2631,
275,
291,
423,
2227,
63,
493,
8,
493,
63,
515,
9,
267,
570,
63,
890,
275,
747,
14,
515,
14,
20733,
8,
493,
63,
515,
9,
267,
372,
291,
423,
1733,
63,
991,
63,
2227,
8,
2227,
12,
570,
63,
890,
9,
365,
440,
488,
339,
347,
5235,
8,
277,
12,
570,
63,
515,
12,
18197,
63,
515,
304,
267,
15396,
63,
633,
275,
291,
423,
1733,
63,
991,
63,
2227,
8,
277,
423,
2227,
63,
493,
8,
493,
63,
515,
395,
291,
423,
362,
63,
493,
63,
890,
8,
493,
63,
515,
430,
267,
340,
440,
15396,
63,
633,
26,
288,
746,
2186,
342,
267,
291,
423,
4249,
63,
16858,
8,
5030,
63,
633,
12,
18197,
63,
515,
9,
339,
768,
4639,
272,
347,
485,
2227,
63,
493,
8,
7218,
304,
267,
862,
26,
288,
1846,
2809,
908,
275,
2650,
81,
7,
221,
327,
12050,
13,
15009,
1846,
1846,
288,
3696,
890,
275,
2702,
14,
21691,
8,
2809,
2809,
908,
9,
953,
289,
275,
1551,
8,
7218,
12,
298,
4848,
531,
953,
23858,
275,
747,
14,
515,
14,
20733,
8,
7218,
9,
288,
2631,
275,
23858,
953,
340,
23858,
665,
25980,
627,
499,
26,
355,
372,
298,
2320,
547,
2,
953,
367,
671,
315,
1425,
8,
10027,
1344,
5001,
3696,
890,
304,
355,
3335,
275,
289,
14,
739,
8,
4414,
890,
9,
355,
334,
76,
63,
585,
4258,
275,
2702,
14,
5301,
8,
2809,
2809,
908,
12,
3335,
9,
355,
2631,
847,
634,
63,
585,
355,
2631,
275,
2631,
1253,
378,
32158,
18073,
221,
327,
370,
5706,
465,
5049,
2075,
1329,
953,
289,
14,
5507,
8,
988,
8,
16,
12,
23858,
446,
25980,
395,
378,
9,
288,
367,
671,
315,
1425,
8,
10027,
1344,
5001,
3696,
890,
304,
355,
3335,
275,
289,
14,
739,
8,
4414,
890,
9,
355,
334,
76,
63,
585,
4258,
275,
2702,
14,
5301,
8,
2809,
2809,
908,
12,
3335,
9,
355,
2631,
847,
634,
63,
585,
355,
2631,
275,
2631,
1253,
378,
32158,
18073,
953,
289,
14,
1600,
342,
288,
2138,
63,
2227,
275,
2071,
10882,
88,
2,
450,
2631,
288,
372,
2138,
63,
2227,
267,
871,
5925,
26,
288,
372,
298,
13760,
2,
339,
347,
485,
1733,
63,
991,
63,
2227,
8,
277,
12,
2631,
12,
1568,
304,
267,
340,
440,
291,
14,
1418,
26,
288,
746,
8779,
547,
360,
3264,
365,
2973,
12,
4676,
1642,
358,
267,
666,
275,
291,
14,
17596,
14,
5278,
2610,
8916,
8,
277,
14,
1418,
12,
9016,
10888,
2227,
356,
2631,
12,
283,
10888,
4414,
890,
356,
620,
8,
890,
395,
12740,
283,
954,
3671,
344,
356,
283,
7420,
936,
566,
459,
576,
418,
267,
340,
822,
8,
576,
9,
508,
378,
26,
288,
372,
488,
267,
587,
26,
288,
372,
666,
59,
16,
2733,
8674,
11950,
3834,
418,
339,
768,
4639,
272,
347,
485,
4249,
63,
16858,
8,
633,
12,
1072,
63,
515,
304,
267,
543,
4011,
14,
1069,
14,
10890,
8,
633,
9,
465,
3482,
4518,
26,
288,
543,
10392,
14,
15016,
8,
2308,
14,
15466,
8,
3065,
4518,
14,
739,
4059,
465,
1315,
493,
12,
1551,
8,
1199,
63,
515,
12,
283,
6603,
358,
465,
734,
63,
493,
26,
355,
570,
275,
769,
8,
1541,
8,
2734,
671,
26,
671,
14,
4130,
5175,
24336,
659,
1315,
493,
14,
23841,
4059,
355,
340,
822,
8,
493,
9,
1137,
413,
26,
490,
746,
6064,
360,
6612,
5536,
19297,
358,
355,
734,
63,
493,
14,
952,
8,
90,
493,
14,
739,
8,
493,
59,
16,
2459,
339,
768,
4639,
272,
347,
485,
362,
63,
493,
63,
890,
8,
515,
304,
267,
372,
747,
14,
515,
14,
20733,
8,
515,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
faint32/shadowsocks
|
tests/test_udp_src.py
|
1009
|
2482
|
#!/usr/bin/python
import socket
import socks
SERVER_IP = '127.0.0.1'
SERVER_PORT = 1081
if __name__ == '__main__':
# Test 1: same source port IPv4
sock_out = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_out.set_proxy(socks.SOCKS5, SERVER_IP, SERVER_PORT)
sock_out.bind(('127.0.0.1', 9000))
sock_in1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in1.bind(('127.0.0.1', 9001))
sock_in2.bind(('127.0.0.1', 9002))
sock_out.sendto(b'data', ('127.0.0.1', 9001))
result1 = sock_in1.recvfrom(8)
sock_out.sendto(b'data', ('127.0.0.1', 9002))
result2 = sock_in2.recvfrom(8)
sock_out.close()
sock_in1.close()
sock_in2.close()
# make sure they're from the same source port
assert result1 == result2
# Test 2: same source port IPv6
# try again from the same port but IPv6
sock_out = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_out.set_proxy(socks.SOCKS5, SERVER_IP, SERVER_PORT)
sock_out.bind(('127.0.0.1', 9000))
sock_in1 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in2 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in1.bind(('::1', 9001))
sock_in2.bind(('::1', 9002))
sock_out.sendto(b'data', ('::1', 9001))
result1 = sock_in1.recvfrom(8)
sock_out.sendto(b'data', ('::1', 9002))
result2 = sock_in2.recvfrom(8)
sock_out.close()
sock_in1.close()
sock_in2.close()
# make sure they're from the same source port
assert result1 == result2
# Test 3: different source ports IPv6
sock_out = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_out.set_proxy(socks.SOCKS5, SERVER_IP, SERVER_PORT)
sock_out.bind(('127.0.0.1', 9003))
sock_in1 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in1.bind(('::1', 9001))
sock_out.sendto(b'data', ('::1', 9001))
result3 = sock_in1.recvfrom(8)
# make sure they're from different source ports
assert result1 != result3
sock_out.close()
sock_in1.close()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
2838,
199,
646,
6771,
83,
421,
199,
6613,
63,
1772,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
6613,
63,
3657,
275,
1616,
2835,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
1379,
413,
26,
2011,
1350,
1844,
6509,
20,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
1493,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
18,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
339,
6771,
63,
262,
17,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
4587,
430,
272,
6771,
63,
262,
18,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
7432,
430,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
4587,
430,
272,
754,
17,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
7432,
430,
272,
754,
18,
275,
6771,
63,
262,
18,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
272,
6771,
63,
262,
18,
14,
1600,
342,
339,
327,
1852,
3238,
2985,
3984,
687,
314,
2011,
1350,
1844,
272,
702,
754,
17,
508,
754,
18,
339,
327,
1379,
499,
26,
2011,
1350,
1844,
6509,
22,
272,
327,
862,
4020,
687,
314,
2011,
1844,
1325,
6509,
22,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
1493,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
18,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
339,
6771,
63,
262,
17,
14,
3409,
1332,
356,
26,
17,
297,
1749,
4587,
430,
272,
6771,
63,
262,
18,
14,
3409,
1332,
356,
26,
17,
297,
1749,
7432,
430,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
4587,
430,
272,
754,
17,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
7432,
430,
272,
754,
18,
275,
6771,
63,
262,
18,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
272,
6771,
63,
262,
18,
14,
1600,
342,
339,
327,
1852,
3238,
2985,
3984,
687,
314,
2011,
1350,
1844,
272,
702,
754,
17,
508,
754,
18,
339,
327,
1379,
650,
26,
3365,
1350,
8873,
6509,
22,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
8262,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
17,
14,
3409,
1332,
356,
26,
17,
297,
1749,
4587,
430,
272,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
4587,
430,
272,
754,
19,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
327,
1852,
3238,
2985,
3984,
687,
3365,
1350,
8873,
272,
702,
754,
17,
1137,
754,
19,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
2838,
199,
646,
6771,
83,
421,
199,
6613,
63,
1772,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
6613,
63,
3657,
275,
1616,
2835,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
1379,
413,
26,
2011,
1350,
1844,
6509,
20,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
1493,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
18,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
339,
6771,
63,
262,
17,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
4587,
430,
272,
6771,
63,
262,
18,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
7432,
430,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
4587,
430,
272,
754,
17,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
7432,
430,
272,
754,
18,
275,
6771,
63,
262,
18,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
272,
6771,
63,
262,
18,
14,
1600,
342,
339,
327,
1852,
3238,
2985,
3984,
687,
314,
2011,
1350,
1844,
272,
702,
754,
17,
508,
754,
18,
339,
327,
1379,
499,
26,
2011,
1350,
1844,
6509,
22,
272,
327,
862,
4020,
687,
314,
2011,
1844,
1325,
6509,
22,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
1493,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
18,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
339,
6771,
63,
262,
17,
14,
3409,
1332,
356,
26,
17,
297,
1749,
4587,
430,
272,
6771,
63,
262,
18,
14,
3409,
1332,
356,
26,
17,
297,
1749,
7432,
430,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
4587,
430,
272,
754,
17,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
7432,
430,
272,
754,
18,
275,
6771,
63,
262,
18,
14,
7637,
504,
8,
24,
9,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
272,
6771,
63,
262,
18,
14,
1600,
342,
339,
327,
1852,
3238,
2985,
3984,
687,
314,
2011,
1350,
1844,
272,
702,
754,
17,
508,
754,
18,
339,
327,
1379,
650,
26,
3365,
1350,
8873,
6509,
22,
272,
6771,
63,
548,
275,
6771,
83,
14,
5096,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
12,
1816,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
548,
14,
409,
63,
3280,
8,
21234,
14,
9469,
51,
21,
12,
23578,
63,
1772,
12,
23578,
63,
3657,
9,
272,
6771,
63,
548,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
1749,
8262,
430,
339,
6771,
63,
262,
17,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
22,
12,
2838,
14,
9469,
63,
25351,
12,
2490,
2838,
14,
15096,
63,
17457,
9,
272,
6771,
63,
262,
17,
14,
3409,
1332,
356,
26,
17,
297,
1749,
4587,
430,
272,
6771,
63,
548,
14,
23267,
8,
66,
5121,
419,
297,
334,
356,
26,
17,
297,
1749,
4587,
430,
272,
754,
19,
275,
6771,
63,
262,
17,
14,
7637,
504,
8,
24,
9,
339,
327,
1852,
3238,
2985,
3984,
687,
3365,
1350,
8873,
272,
702,
754,
17,
1137,
754,
19,
339,
6771,
63,
548,
14,
1600,
342,
272,
6771,
63,
262,
17,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
USGSDenverPychron/pychron
|
pychron/experiment/tests/renumber_aliquot_test.py
|
1
|
1352
|
from pychron.experiment.utilities.aliquot_numbering import renumber_aliquots
__author__ = 'ross'
import unittest
class MockRun(object):
def __init__(self, l, uda, pos):
self.labnumber = l
self.user_defined_aliquot = uda
self.position = pos
class RenumberAliquotTestCase(unittest.TestCase):
def test_renumber(self):
runs = [MockRun('12345', 2, 2),
MockRun('12345', 2, 2),
MockRun('12345', 2, 2),
MockRun('bu-01-01', 0, 0),
MockRun('12345', 1, 1),
MockRun('12345', 1, 1),
MockRun('12345', 1, 1),
MockRun('12345', 3, 3),
MockRun('12345', 3, 3),
MockRun('12345', 3, 3),
]
renumber_aliquots(runs)
r=runs[0]
self.assertTupleEqual((r.user_defined_aliquot, r.position),
(1,2))
r=runs[1]
self.assertTupleEqual((r.user_defined_aliquot, r.position),
(1,2))
r=runs[5]
self.assertTupleEqual((r.user_defined_aliquot, r.position),
(2,1))
r=runs[7]
self.assertTupleEqual((r.user_defined_aliquot, r.position),
(3,3))
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
504,
1134,
31649,
14,
10873,
14,
16355,
14,
10874,
5184,
63,
1955,
316,
492,
295,
1955,
63,
10874,
5184,
83,
199,
199,
363,
2502,
363,
275,
283,
3685,
7,
199,
199,
646,
2882,
421,
199,
533,
4420,
2540,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
634,
12,
399,
983,
12,
2086,
304,
267,
291,
14,
5561,
1955,
275,
634,
267,
291,
14,
751,
63,
4037,
63,
10874,
5184,
275,
399,
983,
267,
291,
14,
3124,
275,
2086,
421,
199,
533,
10055,
884,
6985,
5184,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
828,
884,
8,
277,
304,
267,
7858,
275,
359,
3346,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
464,
13,
614,
13,
614,
297,
378,
12,
378,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
1622,
398,
295,
1955,
63,
10874,
5184,
83,
8,
10802,
9,
398,
519,
29,
10802,
59,
16,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
17,
12,
18,
430,
398,
519,
29,
10802,
59,
17,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
17,
12,
18,
430,
398,
519,
29,
10802,
59,
21,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
18,
12,
17,
430,
398,
519,
29,
10802,
59,
23,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
19,
12,
19,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1134,
31649,
14,
10873,
14,
16355,
14,
10874,
5184,
63,
1955,
316,
492,
295,
1955,
63,
10874,
5184,
83,
199,
199,
363,
2502,
363,
275,
283,
3685,
7,
199,
199,
646,
2882,
421,
199,
533,
4420,
2540,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
634,
12,
399,
983,
12,
2086,
304,
267,
291,
14,
5561,
1955,
275,
634,
267,
291,
14,
751,
63,
4037,
63,
10874,
5184,
275,
399,
983,
267,
291,
14,
3124,
275,
2086,
421,
199,
533,
10055,
884,
6985,
5184,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
828,
884,
8,
277,
304,
267,
7858,
275,
359,
3346,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
13261,
297,
499,
12,
499,
395,
355,
4420,
2540,
360,
464,
13,
614,
13,
614,
297,
378,
12,
378,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
413,
12,
413,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
4420,
2540,
360,
13261,
297,
650,
12,
650,
395,
355,
1622,
398,
295,
1955,
63,
10874,
5184,
83,
8,
10802,
9,
398,
519,
29,
10802,
59,
16,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
17,
12,
18,
430,
398,
519,
29,
10802,
59,
17,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
17,
12,
18,
430,
398,
519,
29,
10802,
59,
21,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
18,
12,
17,
430,
398,
519,
29,
10802,
59,
23,
61,
267,
291,
14,
479,
7075,
591,
1332,
82,
14,
751,
63,
4037,
63,
10874,
5184,
12,
519,
14,
3124,
395,
2892,
334,
19,
12,
19,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
morreene/tradenews
|
venv/Lib/site-packages/webassets/ext/jinja2.py
|
4
|
10611
|
from __future__ import absolute_import
import warnings
import jinja2
from jinja2.ext import Extension
from jinja2 import nodes
from webassets import Bundle
from webassets.loaders import GlobLoader, LoaderError
from webassets.exceptions import ImminentDeprecationWarning
__all__ = ('assets', 'Jinja2Loader',)
class AssetsExtension(Extension):
"""
As opposed to the Django tag, this tag is slightly more capable due
to the expressive powers inherited from Jinja. For example:
{% assets "src1.js", "src2.js", get_src3(),
filter=("jsmin", "gzip"), output=get_output() %}
{% endassets %}
"""
tags = set(['assets'])
BundleClass = Bundle # Helpful for mocking during tests.
def __init__(self, environment):
super(AssetsExtension, self).__init__(environment)
# Add the defaults to the environment
environment.extend(
assets_environment=None,
)
def parse(self, parser):
lineno = next(parser.stream).lineno
files = []
output = nodes.Const(None)
filters = nodes.Const(None)
dbg = nodes.Const(None)
depends = nodes.Const(None)
# Parse the arguments
first = True
while parser.stream.current.type != 'block_end':
if not first:
parser.stream.expect('comma')
first = False
# Lookahead to see if this is an assignment (an option)
if parser.stream.current.test('name') and parser.stream.look().test('assign'):
name = next(parser.stream).value
parser.stream.skip()
value = parser.parse_expression()
if name == 'filters':
filters = value
elif name == 'filter':
filters = value
warnings.warn('The "filter" option of the {%% assets %%} '
'template tag has been renamed to '
'"filters" for consistency reasons '
'(line %s).' % lineno,
ImminentDeprecationWarning)
elif name == 'output':
output = value
elif name == 'debug':
dbg = value
elif name == 'depends':
depends = value
else:
parser.fail('Invalid keyword argument: %s' % name)
# Otherwise assume a source file is given, which may be any
# expression, except note that strings are handled separately above.
else:
expression = parser.parse_expression()
if isinstance(expression, (nodes.List, nodes.Tuple)):
files.extend(expression.iter_child_nodes())
else:
files.append(expression)
# Parse the contents of this tag
body = parser.parse_statements(['name:endassets'], drop_needle=True)
# We want to make some values available to the body of our tag.
# Specifically, the file url(s) (ASSET_URL), and any extra dict set in
# the bundle (EXTRA).
#
# A short interlope: I would have preferred to make the values of the
# extra dict available directly. Unfortunately, the way Jinja2 does
# things makes this problematic. I'll explain.
#
# Jinja2 generates Python code from it's AST which it then executes.
# So the way extensions implement making custom variables available to
# a block of code is by generating a ``CallBlock``, which essentially
# wraps our child nodes in a Python function. The arguments of this
# function are the values that are available to our tag contents.
#
# But we need to generate this ``CallBlock`` now, during parsing, and
# right now we don't know the actual ``Bundle.extra`` values yet. We
# only resolve the bundle during rendering!
#
# This would easily be solved if Jinja2 where to allow extensions to
# scope it's context, which is a dict of values that templates can
# access, just like in Django (you might see on occasion
# ``context.resolve('foo')`` calls in Jinja2's generated code).
# However, it seems the context is essentially only for the initial
# set of data passed to render(). There are some statements by Armin
# that this might change at some point, but I've run into this problem
# before, and I'm not holding my breath.
#
# I **really** did try to get around this, including crazy things like
# inserting custom Python code by patching the tag child nodes::
#
# rv = object.__new__(nodes.InternalName)
# # l_EXTRA is the argument we defined for the CallBlock/Macro
# # Letting Jinja define l_kwargs is also possible
# nodes.Node.__init__(rv, '; context.vars.update(l_EXTRA)',
# lineno=lineno)
# # Scope required to ensure our code on top
# body = [rv, nodes.Scope(body)]
#
# This custom code would run at the top of the function in which the
# CallBlock node would wrap the code generated from our tag's child
# nodes. Note that it actually does works, but doesn't clear the values
# at the end of the scope).
#
# If it is possible to do this, it certainly isn't reasonable/
#
# There is of course another option altogether: Simple resolve the tag
# definition to a bundle right here and now, thus get access to the
# extra dict, make all values arguments to the CallBlock (Limited to
# 255 arguments to a Python function!). And while that would work fine
# in 99% of cases, it wouldn't be correct. The compiled template could
# be cached and used with different bundles/environments, and this
# would require the bundle to resolve at parse time, and hardcode it's
# extra values.
#
# Interlope end.
#
# Summary: We have to be satisfied with a single EXTRA variable.
args = [nodes.Name('ASSET_URL', 'param'),
nodes.Name('EXTRA', 'param')]
# Return a ``CallBlock``, which means Jinja2 will call a Python method
# of ours when the tag needs to be rendered. That method can then
# render the template body.
call = self.call_method(
# Note: Changing the args here requires updating ``Jinja2Loader``
'_render_assets', args=[filters, output, dbg, depends, nodes.List(files)])
call_block = nodes.CallBlock(call, args, [], body)
call_block.set_lineno(lineno)
return call_block
@classmethod
def resolve_contents(cls, contents, env):
"""Resolve bundle names."""
result = []
for f in contents:
try:
result.append(env[f])
except KeyError:
result.append(f)
return result
def _render_assets(self, filter, output, dbg, depends, files, caller=None):
env = self.environment.assets_environment
if env is None:
raise RuntimeError('No assets environment configured in '+
'Jinja2 environment')
# Construct a bundle with the given options
bundle_kwargs = {
'output': output,
'filters': filter,
'debug': dbg,
'depends': depends,
}
bundle = self.BundleClass(
*self.resolve_contents(files, env), **bundle_kwargs)
# Retrieve urls (this may or may not cause a build)
with bundle.bind(env):
urls = bundle.urls()
# For each url, execute the content of this template tag (represented
# by the macro ```caller`` given to use by Jinja2).
result = u""
for url in urls:
result += caller(url, bundle.extra)
return result
assets = AssetsExtension # nicer import name
class Jinja2Loader(GlobLoader):
"""Parse all the Jinja2 templates in the given directory, try to
find bundles in active use.
Try all the given environments to parse the template, until we
succeed.
"""
def __init__(self, assets_env, directories, jinja2_envs, charset='utf8', jinja_ext='*.html'):
self.asset_env = assets_env
self.directories = directories
self.jinja2_envs = jinja2_envs
self.charset = charset
self.jinja_ext = jinja_ext
def load_bundles(self):
bundles = []
for template_dir in self.directories:
for filename in self.glob_files((template_dir, self.jinja_ext)):
bundles.extend(self.with_file(filename, self._parse) or [])
return bundles
def _parse(self, filename, contents):
for i, env in enumerate(self.jinja2_envs):
try:
t = env.parse(contents.decode(self.charset))
except jinja2.exceptions.TemplateSyntaxError as e:
#print ('jinja parser (env %d) failed: %s'% (i, e))
pass
else:
result = []
def _recurse_node(node_to_search):
for node in node_to_search.iter_child_nodes():
if isinstance(node, jinja2.nodes.Call):
if isinstance(node.node, jinja2.nodes.ExtensionAttribute)\
and node.node.identifier == AssetsExtension.identifier:
filter, output, dbg, depends, files = node.args
bundle = Bundle(
*AssetsExtension.resolve_contents(files.as_const(), self.asset_env),
**{
'output': output.as_const(),
'depends': depends.as_const(),
'filters': filter.as_const()})
result.append(bundle)
else:
_recurse_node(node)
for node in t.iter_child_nodes():
_recurse_node(node)
return result
else:
raise LoaderError('Jinja parser failed on %s, tried %d environments' % (
filename, len(self.jinja2_envs)))
return False
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
3598,
199,
646,
10321,
18,
199,
504,
10321,
18,
14,
832,
492,
13282,
199,
504,
10321,
18,
492,
3380,
199,
504,
3330,
12186,
492,
29311,
199,
504,
3330,
12186,
14,
16370,
492,
598,
1191,
5455,
12,
22865,
547,
199,
504,
3330,
12186,
14,
3924,
492,
473,
596,
262,
484,
15561,
421,
199,
363,
452,
363,
275,
661,
12186,
297,
283,
42,
4135,
18,
5455,
9538,
421,
199,
533,
3709,
2193,
6382,
8,
6382,
304,
272,
408,
272,
3709,
25068,
370,
314,
5634,
1947,
12,
642,
1947,
365,
18023,
1655,
4021,
461,
7037,
272,
370,
314,
1437,
470,
3398,
13131,
1192,
12623,
687,
17300,
14,
2104,
2893,
26,
398,
7749,
17202,
298,
2164,
17,
14,
3596,
401,
298,
2164,
18,
14,
3596,
401,
664,
63,
2164,
19,
1062,
2116,
2457,
15387,
3596,
827,
401,
298,
12256,
1288,
1072,
29,
362,
63,
1199,
342,
3674,
267,
7749,
1284,
12186,
3674,
272,
408,
339,
3762,
275,
663,
2941,
12186,
1105,
339,
29311,
2543,
275,
29311,
257,
327,
15456,
1893,
367,
1683,
316,
5309,
2295,
14,
339,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
1613,
8,
2822,
2193,
6382,
12,
291,
2843,
826,
721,
5418,
9,
398,
327,
2654,
314,
4243,
370,
314,
3734,
267,
3734,
14,
2880,
8,
288,
17202,
63,
5418,
29,
403,
12,
267,
776,
339,
347,
2198,
8,
277,
12,
1798,
304,
267,
5874,
275,
2163,
8,
2087,
14,
1745,
680,
3469,
398,
1584,
275,
942,
267,
1072,
275,
3380,
14,
6361,
8,
403,
9,
267,
4766,
275,
3380,
14,
6361,
8,
403,
9,
267,
24465,
275,
3380,
14,
6361,
8,
403,
9,
267,
8350,
275,
3380,
14,
6361,
8,
403,
9,
398,
327,
6077,
314,
2368,
267,
1642,
275,
715,
267,
1830,
1798,
14,
1745,
14,
1818,
14,
466,
1137,
283,
1457,
63,
500,
356,
288,
340,
440,
1642,
26,
355,
1798,
14,
1745,
14,
4921,
360,
13184,
358,
288,
1642,
275,
756,
953,
327,
12077,
10938,
370,
1937,
340,
642,
365,
376,
9801,
334,
290,
945,
9,
288,
340,
1798,
14,
1745,
14,
1818,
14,
396,
360,
354,
358,
436,
1798,
14,
1745,
14,
11660,
1252,
396,
360,
5038,
735,
355,
536,
275,
2163,
8,
2087,
14,
1745,
680,
585,
355,
1798,
14,
1745,
14,
2759,
342,
355,
574,
275,
1798,
14,
1122,
63,
5599,
342,
355,
340,
536,
508,
283,
4273,
356,
490,
4766,
275,
574,
355,
916,
536,
508,
283,
1541,
356,
490,
4766,
275,
574,
490,
3598,
14,
4050,
360,
1918,
298,
1541,
2,
945,
402,
314,
7749,
5,
17202,
11539,
93,
283,
3303,
283,
1160,
1947,
965,
2757,
17864,
370,
283,
3303,
5522,
4273,
2,
367,
17754,
14872,
283,
3303,
8189,
604,
450,
83,
28823,
450,
5874,
12,
2511,
473,
596,
262,
484,
15561,
9,
355,
916,
536,
508,
283,
1199,
356,
490,
1072,
275,
574,
355,
916,
536,
508,
283,
1757,
356,
490,
24465,
275,
574,
355,
916,
536,
508,
283,
8912,
356,
490,
8350,
275,
574,
355,
587,
26,
490,
1798,
14,
1633,
360,
3364,
4252,
1423,
26,
450,
83,
7,
450,
536,
9,
288,
327,
6630,
5534,
282,
1350,
570,
365,
1627,
12,
1314,
1443,
506,
1263,
288,
327,
3965,
12,
871,
5317,
626,
3326,
787,
8860,
18159,
3432,
14,
288,
587,
26,
355,
3965,
275,
1798,
14,
1122,
63,
5599,
342,
355,
340,
1228,
8,
5599,
12,
334,
2415,
14,
1296,
12,
3380,
14,
7075,
2298,
490,
1584,
14,
2880,
8,
5599,
14,
1661,
63,
1739,
63,
2415,
1012,
355,
587,
26,
490,
1584,
14,
740,
8,
5599,
9,
398,
327,
6077,
314,
4072,
402,
642,
1947,
267,
2396,
275,
1798,
14,
1122,
63,
15384,
2941,
354,
26,
500,
12186,
995,
5978,
63,
9321,
274,
29,
549,
9,
398,
327,
2136,
2934,
370,
1852,
2005,
1338,
2808,
370,
314,
2396,
402,
4154,
1947,
14,
267,
327,
30836,
12,
314,
570,
1166,
8,
83,
9,
334,
1179,
3597,
63,
2632,
395,
436,
1263,
2402,
1211,
663,
315,
267,
327,
314,
8844,
334,
18555,
680,
267,
327,
267,
327,
437,
3974,
1640,
14363,
26,
473,
3955,
1172,
14388,
370,
1852,
314,
1338,
402,
314,
267,
327,
2402,
1211,
2808,
5370,
14,
31076,
12,
314,
4340,
17300,
18,
1630,
267,
327,
7645,
7704,
642,
557,
31197,
14,
473,
7171,
27797,
14,
267,
327,
267,
327,
17300,
18,
12821,
2018,
1233,
687,
652,
1159,
20788,
1314,
652,
2066,
24956,
14,
267,
327,
2002,
314,
4340,
5478,
5669,
10663,
3537,
2860,
2808,
370,
267,
327,
282,
1853,
402,
1233,
365,
701,
12999,
282,
1124,
2176,
3142,
4542,
1314,
28891,
267,
327,
14018,
4154,
1982,
3380,
315,
282,
2018,
805,
14,
710,
2368,
402,
642,
267,
327,
805,
787,
314,
1338,
626,
787,
2808,
370,
4154,
1947,
4072,
14,
267,
327,
267,
327,
11017,
781,
1929,
370,
3550,
642,
1124,
2176,
3142,
1040,
3063,
12,
5309,
6057,
12,
436,
267,
327,
2451,
3063,
781,
2793,
1133,
5715,
314,
3503,
1124,
12320,
14,
2911,
1040,
1338,
5966,
14,
2136,
267,
327,
1454,
7512,
314,
8844,
5309,
14066,
1,
267,
327,
267,
327,
961,
3955,
16174,
506,
308,
7064,
340,
17300,
18,
2382,
370,
2040,
5478,
370,
267,
327,
4194,
652,
1159,
1067,
12,
1314,
365,
282,
1211,
402,
1338,
626,
7009,
883,
267,
327,
2879,
12,
2951,
2839,
315,
5634,
334,
13297,
5594,
1937,
641,
14706,
305,
1636,
267,
327,
1124,
1100,
14,
6983,
360,
1421,
358,
1040,
4882,
315,
17300,
18,
1159,
4046,
1233,
680,
267,
327,
9738,
12,
652,
12237,
314,
1067,
365,
28891,
1454,
367,
314,
2536,
267,
327,
663,
402,
666,
3032,
370,
3795,
1252,
6006,
787,
2005,
9834,
701,
1952,
827,
267,
327,
626,
642,
5594,
1570,
737,
2005,
2376,
12,
1325,
473,
9064,
1255,
1901,
642,
5160,
267,
327,
2544,
12,
436,
473,
6704,
440,
17573,
3002,
330,
264,
1619,
14,
267,
327,
267,
327,
473,
1011,
29428,
538,
8103,
862,
370,
664,
6818,
642,
12,
5893,
286,
30566,
7645,
2839,
267,
327,
28498,
3537,
2018,
1233,
701,
3371,
316,
314,
1947,
1982,
3380,
447,
267,
327,
267,
327,
263,
4336,
275,
909,
855,
1222,
721,
2415,
14,
8405,
985,
9,
267,
327,
263,
327,
634,
63,
18555,
365,
314,
1423,
781
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
3598,
199,
646,
10321,
18,
199,
504,
10321,
18,
14,
832,
492,
13282,
199,
504,
10321,
18,
492,
3380,
199,
504,
3330,
12186,
492,
29311,
199,
504,
3330,
12186,
14,
16370,
492,
598,
1191,
5455,
12,
22865,
547,
199,
504,
3330,
12186,
14,
3924,
492,
473,
596,
262,
484,
15561,
421,
199,
363,
452,
363,
275,
661,
12186,
297,
283,
42,
4135,
18,
5455,
9538,
421,
199,
533,
3709,
2193,
6382,
8,
6382,
304,
272,
408,
272,
3709,
25068,
370,
314,
5634,
1947,
12,
642,
1947,
365,
18023,
1655,
4021,
461,
7037,
272,
370,
314,
1437,
470,
3398,
13131,
1192,
12623,
687,
17300,
14,
2104,
2893,
26,
398,
7749,
17202,
298,
2164,
17,
14,
3596,
401,
298,
2164,
18,
14,
3596,
401,
664,
63,
2164,
19,
1062,
2116,
2457,
15387,
3596,
827,
401,
298,
12256,
1288,
1072,
29,
362,
63,
1199,
342,
3674,
267,
7749,
1284,
12186,
3674,
272,
408,
339,
3762,
275,
663,
2941,
12186,
1105,
339,
29311,
2543,
275,
29311,
257,
327,
15456,
1893,
367,
1683,
316,
5309,
2295,
14,
339,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
1613,
8,
2822,
2193,
6382,
12,
291,
2843,
826,
721,
5418,
9,
398,
327,
2654,
314,
4243,
370,
314,
3734,
267,
3734,
14,
2880,
8,
288,
17202,
63,
5418,
29,
403,
12,
267,
776,
339,
347,
2198,
8,
277,
12,
1798,
304,
267,
5874,
275,
2163,
8,
2087,
14,
1745,
680,
3469,
398,
1584,
275,
942,
267,
1072,
275,
3380,
14,
6361,
8,
403,
9,
267,
4766,
275,
3380,
14,
6361,
8,
403,
9,
267,
24465,
275,
3380,
14,
6361,
8,
403,
9,
267,
8350,
275,
3380,
14,
6361,
8,
403,
9,
398,
327,
6077,
314,
2368,
267,
1642,
275,
715,
267,
1830,
1798,
14,
1745,
14,
1818,
14,
466,
1137,
283,
1457,
63,
500,
356,
288,
340,
440,
1642,
26,
355,
1798,
14,
1745,
14,
4921,
360,
13184,
358,
288,
1642,
275,
756,
953,
327,
12077,
10938,
370,
1937,
340,
642,
365,
376,
9801,
334,
290,
945,
9,
288,
340,
1798,
14,
1745,
14,
1818,
14,
396,
360,
354,
358,
436,
1798,
14,
1745,
14,
11660,
1252,
396,
360,
5038,
735,
355,
536,
275,
2163,
8,
2087,
14,
1745,
680,
585,
355,
1798,
14,
1745,
14,
2759,
342,
355,
574,
275,
1798,
14,
1122,
63,
5599,
342,
355,
340,
536,
508,
283,
4273,
356,
490,
4766,
275,
574,
355,
916,
536,
508,
283,
1541,
356,
490,
4766,
275,
574,
490,
3598,
14,
4050,
360,
1918,
298,
1541,
2,
945,
402,
314,
7749,
5,
17202,
11539,
93,
283,
3303,
283,
1160,
1947,
965,
2757,
17864,
370,
283,
3303,
5522,
4273,
2,
367,
17754,
14872,
283,
3303,
8189,
604,
450,
83,
28823,
450,
5874,
12,
2511,
473,
596,
262,
484,
15561,
9,
355,
916,
536,
508,
283,
1199,
356,
490,
1072,
275,
574,
355,
916,
536,
508,
283,
1757,
356,
490,
24465,
275,
574,
355,
916,
536,
508,
283,
8912,
356,
490,
8350,
275,
574,
355,
587,
26,
490,
1798,
14,
1633,
360,
3364,
4252,
1423,
26,
450,
83,
7,
450,
536,
9,
288,
327,
6630,
5534,
282,
1350,
570,
365,
1627,
12,
1314,
1443,
506,
1263,
288,
327,
3965,
12,
871,
5317,
626,
3326,
787,
8860,
18159,
3432,
14,
288,
587,
26,
355,
3965,
275,
1798,
14,
1122,
63,
5599,
342,
355,
340,
1228,
8,
5599,
12,
334,
2415,
14,
1296,
12,
3380,
14,
7075,
2298,
490,
1584,
14,
2880,
8,
5599,
14,
1661,
63,
1739,
63,
2415,
1012,
355,
587,
26,
490,
1584,
14,
740,
8,
5599,
9,
398,
327,
6077,
314,
4072,
402,
642,
1947,
267,
2396,
275,
1798,
14,
1122,
63,
15384,
2941,
354,
26,
500,
12186,
995,
5978,
63,
9321,
274,
29,
549,
9,
398,
327,
2136,
2934,
370,
1852,
2005,
1338,
2808,
370,
314,
2396,
402,
4154,
1947,
14,
267,
327,
30836,
12,
314,
570,
1166,
8,
83,
9,
334,
1179,
3597,
63,
2632,
395,
436,
1263,
2402,
1211,
663,
315,
267,
327,
314,
8844,
334,
18555,
680,
267,
327,
267,
327,
437,
3974,
1640,
14363,
26,
473,
3955,
1172,
14388,
370,
1852,
314,
1338,
402,
314,
267,
327,
2402,
1211,
2808,
5370,
14,
31076,
12,
314,
4340,
17300,
18,
1630,
267,
327,
7645,
7704,
642,
557,
31197,
14,
473,
7171,
27797,
14,
267,
327,
267,
327,
17300,
18,
12821,
2018,
1233,
687,
652,
1159,
20788,
1314,
652,
2066,
24956,
14,
267,
327,
2002,
314,
4340,
5478,
5669,
10663,
3537,
2860,
2808,
370,
267,
327,
282,
1853,
402,
1233,
365,
701,
12999,
282,
1124,
2176,
3142,
4542,
1314,
28891,
267,
327,
14018,
4154,
1982,
3380,
315,
282,
2018,
805,
14,
710,
2368,
402,
642,
267,
327,
805,
787,
314,
1338,
626,
787,
2808,
370,
4154,
1947,
4072,
14,
267,
327,
267,
327,
11017,
781,
1929,
370,
3550,
642,
1124,
2176,
3142,
1040,
3063,
12,
5309,
6057,
12,
436,
267,
327,
2451,
3063,
781,
2793,
1133,
5715,
314,
3503,
1124,
12320,
14,
2911,
1040,
1338,
5966,
14,
2136,
267,
327,
1454,
7512,
314,
8844,
5309,
14066,
1,
267,
327,
267,
327,
961,
3955,
16174,
506,
308,
7064,
340,
17300,
18,
2382,
370,
2040,
5478,
370,
267,
327,
4194,
652,
1159,
1067,
12,
1314,
365,
282,
1211,
402,
1338,
626,
7009,
883,
267,
327,
2879,
12,
2951,
2839,
315,
5634,
334,
13297,
5594,
1937,
641,
14706,
305,
1636,
267,
327,
1124,
1100,
14,
6983,
360,
1421,
358,
1040,
4882,
315,
17300,
18,
1159,
4046,
1233,
680,
267,
327,
9738,
12,
652,
12237,
314,
1067,
365,
28891,
1454,
367,
314,
2536,
267,
327,
663,
402,
666,
3032,
370,
3795,
1252,
6006,
787,
2005,
9834,
701,
1952,
827,
267,
327,
626,
642,
5594,
1570,
737,
2005,
2376,
12,
1325,
473,
9064,
1255,
1901,
642,
5160,
267,
327,
2544,
12,
436,
473,
6704,
440,
17573,
3002,
330,
264,
1619,
14,
267,
327,
267,
327,
473,
1011,
29428,
538,
8103,
862,
370,
664,
6818,
642,
12,
5893,
286,
30566,
7645,
2839,
267,
327,
28498,
3537,
2018,
1233,
701,
3371,
316,
314,
1947,
1982,
3380,
447,
267,
327,
267,
327,
263,
4336,
275,
909,
855,
1222,
721,
2415,
14,
8405,
985,
9,
267,
327,
263,
327,
634,
63,
18555,
365,
314,
1423,
781,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Anonymouslemming/ansible
|
lib/ansible/utils/helpers.py
|
38
|
1272
|
# (c) 2016, Ansible by Red Hat <info@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.module_utils.six import string_types
def pct_to_int(value, num_items, min_value=1):
'''
Converts a given value to a percentage if specified as "x%",
otherwise converts the given value to an integer.
'''
if isinstance(value, string_types) and value.endswith('%'):
value_pct = int(value.replace("%", ""))
return int((value_pct / 100.0) * num_items) or min_value
else:
return int(value)
|
gpl-3.0
|
[
3,
334,
67,
9,
7800,
12,
2622,
701,
9572,
13002,
665,
815,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
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,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
421,
199,
318,
299,
319,
63,
475,
63,
442,
8,
585,
12,
1967,
63,
1744,
12,
1748,
63,
585,
29,
17,
304,
272,
1449,
272,
19107,
282,
1627,
574,
370,
282,
16327,
340,
2013,
465,
298,
88,
31181,
272,
4257,
15373,
314,
1627,
574,
370,
376,
3000,
14,
272,
1449,
272,
340,
1228,
8,
585,
12,
1059,
63,
1313,
9,
436,
574,
14,
4130,
3508,
735,
267,
574,
63,
20778,
275,
1109,
8,
585,
14,
1814,
3647,
401,
25491,
267,
372,
1109,
1332,
585,
63,
20778,
1182,
2948,
14,
16,
9,
627,
1967,
63,
1744,
9,
503,
1748,
63,
585,
272,
587,
26,
267,
372,
1109,
8,
585,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
7800,
12,
2622,
701,
9572,
13002,
665,
815,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
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,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
421,
199,
318,
299,
319,
63,
475,
63,
442,
8,
585,
12,
1967,
63,
1744,
12,
1748,
63,
585,
29,
17,
304,
272,
1449,
272,
19107,
282,
1627,
574,
370,
282,
16327,
340,
2013,
465,
298,
88,
31181,
272,
4257,
15373,
314,
1627,
574,
370,
376,
3000,
14,
272,
1449,
272,
340,
1228,
8,
585,
12,
1059,
63,
1313,
9,
436,
574,
14,
4130,
3508,
735,
267,
574,
63,
20778,
275,
1109,
8,
585,
14,
1814,
3647,
401,
25491,
267,
372,
1109,
1332,
585,
63,
20778,
1182,
2948,
14,
16,
9,
627,
1967,
63,
1744,
9,
503,
1748,
63,
585,
272,
587,
26,
267,
372,
1109,
8,
585,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
avanov/django
|
tests/unmanaged_models/models.py
|
98
|
3699
|
"""
Models can have a ``managed`` attribute, which specifies whether the SQL code
is generated for the table on various manage.py operations.
"""
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
# All of these models are created in the database by Django.
@python_2_unicode_compatible
class A01(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
class Meta:
db_table = 'a01'
def __str__(self):
return self.f_a
@python_2_unicode_compatible
class B01(models.Model):
fk_a = models.ForeignKey(A01)
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
class Meta:
db_table = 'b01'
# 'managed' is True by default. This tests we can set it explicitly.
managed = True
def __str__(self):
return self.f_a
@python_2_unicode_compatible
class C01(models.Model):
mm_a = models.ManyToManyField(A01, db_table='d01')
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
class Meta:
db_table = 'c01'
def __str__(self):
return self.f_a
# All of these models use the same tables as the previous set (they are shadows
# of possibly a subset of the columns). There should be no creation errors,
# since we have told Django they aren't managed by Django.
@python_2_unicode_compatible
class A02(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
class Meta:
db_table = 'a01'
managed = False
def __str__(self):
return self.f_a
@python_2_unicode_compatible
class B02(models.Model):
class Meta:
db_table = 'b01'
managed = False
fk_a = models.ForeignKey(A02)
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
def __str__(self):
return self.f_a
# To re-use the many-to-many intermediate table, we need to manually set up
# things up.
@python_2_unicode_compatible
class C02(models.Model):
mm_a = models.ManyToManyField(A02, through="Intermediate")
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
class Meta:
db_table = 'c01'
managed = False
def __str__(self):
return self.f_a
class Intermediate(models.Model):
a02 = models.ForeignKey(A02, db_column="a01_id")
c02 = models.ForeignKey(C02, db_column="c01_id")
class Meta:
db_table = 'd01'
managed = False
# These next models test the creation (or not) of many to many join tables
# between managed and unmanaged models. A join table between two unmanaged
# models shouldn't be automatically created (see #10647).
#
# Firstly, we need some models that will create the tables, purely so that the
# tables are created. This is a test setup, not a requirement for unmanaged
# models.
class Proxy1(models.Model):
class Meta:
db_table = "unmanaged_models_proxy1"
class Proxy2(models.Model):
class Meta:
db_table = "unmanaged_models_proxy2"
class Unmanaged1(models.Model):
class Meta:
managed = False
db_table = "unmanaged_models_proxy1"
# Unmanged with an m2m to unmanaged: the intermediary table won't be created.
class Unmanaged2(models.Model):
mm = models.ManyToManyField(Unmanaged1)
class Meta:
managed = False
db_table = "unmanaged_models_proxy2"
# Here's an unmanaged model with an m2m to a managed one; the intermediary
# table *will* be created (unless given a custom `through` as for C02 above).
class Managed1(models.Model):
mm = models.ManyToManyField(Unmanaged1)
|
bsd-3-clause
|
[
624,
199,
20474,
883,
1172,
282,
1124,
11122,
1040,
2225,
12,
1314,
9314,
3775,
314,
5385,
1233,
199,
374,
4046,
367,
314,
1817,
641,
7750,
9635,
14,
647,
5331,
14,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
3,
221,
2900,
402,
3520,
1709,
787,
2737,
315,
314,
3050,
701,
5634,
14,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
437,
614,
8,
992,
14,
1685,
304,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
65,
614,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
699,
614,
8,
992,
14,
1685,
304,
272,
14830,
63,
65,
275,
1709,
14,
3190,
8,
33,
614,
9,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
66,
614,
7,
267,
327,
283,
11122,
7,
365,
715,
701,
849,
14,
961,
2295,
781,
883,
663,
652,
7662,
14,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
445,
614,
8,
992,
14,
1685,
304,
272,
8562,
63,
65,
275,
1709,
14,
7624,
8,
33,
614,
12,
1592,
63,
1224,
534,
68,
614,
358,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
67,
614,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
199,
199,
3,
2900,
402,
3520,
1709,
675,
314,
2011,
6716,
465,
314,
4136,
663,
334,
29002,
787,
15084,
83,
199,
3,
402,
12570,
282,
10026,
402,
314,
4362,
680,
6006,
1077,
506,
949,
7143,
2552,
12,
199,
3,
3967,
781,
1172,
370,
1447,
5634,
2985,
10621,
1133,
12883,
701,
5634,
14,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
437,
996,
8,
992,
14,
1685,
304,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
65,
614,
7,
267,
12883,
275,
756,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
699,
996,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
66,
614,
7,
267,
12883,
275,
756,
339,
14830,
63,
65,
275,
1709,
14,
3190,
8,
33,
996,
9,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
3,
4005,
295,
13,
1180,
314,
5002,
13,
475,
13,
3479,
13197,
1817,
12,
781,
1929,
370,
10250,
663,
1536,
199,
3,
7645,
1536,
14,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
445,
996,
8,
992,
14,
1685,
304,
272,
8562,
63,
65,
275,
1709,
14,
7624,
8,
33,
996,
12,
4012,
628,
2620,
5050,
531,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
67,
614,
7,
267,
12883,
275,
756,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
533,
6551,
5050,
8,
992,
14,
1685,
304,
272,
282,
996,
275,
1709,
14,
3190,
8,
33,
996,
12,
1592,
63,
2301,
628,
65,
614,
63,
344,
531,
272,
286,
996,
275,
1709,
14,
3190,
8,
35,
996,
12,
1592,
63,
2301,
628,
67,
614,
63,
344,
531,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
68,
614,
7,
267,
12883,
275,
756,
421,
199,
3,
5723,
2163,
1709,
511,
314,
7143,
334,
269,
440,
9,
402,
5002,
370,
5002,
4263,
6716,
199,
3,
3382,
12883,
436,
625,
11122,
1709,
14,
437,
4263,
1817,
3382,
2877,
625,
11122,
199,
3,
1709,
9296,
1133,
506,
5847,
2737,
334,
3239,
327,
709,
8557,
680,
199,
3,
199,
199,
3,
7758,
590,
12,
781,
1929,
2005,
1709,
626,
911,
1218,
314,
6716,
12,
15111,
590,
880,
626,
314,
199,
3,
6716,
787,
2737,
14,
961,
365,
282,
511,
3272,
12,
440,
282,
10685,
367,
625,
11122,
199,
3,
1709,
14,
199,
533,
12373,
17,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
17,
2,
421,
199,
533,
12373,
18,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
18,
2,
421,
199,
533,
1910,
11122,
17,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
12883,
275,
756,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
17,
2,
421,
199,
3,
1910,
77,
618,
68,
543,
376,
333,
18,
77,
370,
625,
11122,
26,
314,
1640,
30747,
1817,
7859,
1133,
506,
2737,
14,
199,
533,
1910,
11122,
18,
8,
992,
14,
1685,
304,
272,
8562,
275,
1709,
14,
7624,
8,
1358,
11122,
17,
9,
339,
1021,
6288,
26,
267,
12883,
275,
756,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
18,
2,
421,
199,
3,
11842,
1159,
376,
625,
11122,
1402,
543,
376,
333,
18,
77,
370,
282,
12883
] |
[
199,
20474,
883,
1172,
282,
1124,
11122,
1040,
2225,
12,
1314,
9314,
3775,
314,
5385,
1233,
199,
374,
4046,
367,
314,
1817,
641,
7750,
9635,
14,
647,
5331,
14,
199,
624,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
3,
221,
2900,
402,
3520,
1709,
787,
2737,
315,
314,
3050,
701,
5634,
14,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
437,
614,
8,
992,
14,
1685,
304,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
65,
614,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
699,
614,
8,
992,
14,
1685,
304,
272,
14830,
63,
65,
275,
1709,
14,
3190,
8,
33,
614,
9,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
66,
614,
7,
267,
327,
283,
11122,
7,
365,
715,
701,
849,
14,
961,
2295,
781,
883,
663,
652,
7662,
14,
267,
12883,
275,
715,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
445,
614,
8,
992,
14,
1685,
304,
272,
8562,
63,
65,
275,
1709,
14,
7624,
8,
33,
614,
12,
1592,
63,
1224,
534,
68,
614,
358,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
67,
614,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
199,
199,
3,
2900,
402,
3520,
1709,
675,
314,
2011,
6716,
465,
314,
4136,
663,
334,
29002,
787,
15084,
83,
199,
3,
402,
12570,
282,
10026,
402,
314,
4362,
680,
6006,
1077,
506,
949,
7143,
2552,
12,
199,
3,
3967,
781,
1172,
370,
1447,
5634,
2985,
10621,
1133,
12883,
701,
5634,
14,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
437,
996,
8,
992,
14,
1685,
304,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
65,
614,
7,
267,
12883,
275,
756,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
699,
996,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
66,
614,
7,
267,
12883,
275,
756,
339,
14830,
63,
65,
275,
1709,
14,
3190,
8,
33,
996,
9,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
3,
4005,
295,
13,
1180,
314,
5002,
13,
475,
13,
3479,
13197,
1817,
12,
781,
1929,
370,
10250,
663,
1536,
199,
3,
7645,
1536,
14,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
445,
996,
8,
992,
14,
1685,
304,
272,
8562,
63,
65,
275,
1709,
14,
7624,
8,
33,
996,
12,
4012,
628,
2620,
5050,
531,
272,
289,
63,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
12,
1592,
63,
1080,
29,
549,
9,
272,
289,
63,
66,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
67,
614,
7,
267,
12883,
275,
756,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
70,
63,
65,
421,
199,
533,
6551,
5050,
8,
992,
14,
1685,
304,
272,
282,
996,
275,
1709,
14,
3190,
8,
33,
996,
12,
1592,
63,
2301,
628,
65,
614,
63,
344,
531,
272,
286,
996,
275,
1709,
14,
3190,
8,
35,
996,
12,
1592,
63,
2301,
628,
67,
614,
63,
344,
531,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
68,
614,
7,
267,
12883,
275,
756,
421,
199,
3,
5723,
2163,
1709,
511,
314,
7143,
334,
269,
440,
9,
402,
5002,
370,
5002,
4263,
6716,
199,
3,
3382,
12883,
436,
625,
11122,
1709,
14,
437,
4263,
1817,
3382,
2877,
625,
11122,
199,
3,
1709,
9296,
1133,
506,
5847,
2737,
334,
3239,
327,
709,
8557,
680,
199,
3,
199,
199,
3,
7758,
590,
12,
781,
1929,
2005,
1709,
626,
911,
1218,
314,
6716,
12,
15111,
590,
880,
626,
314,
199,
3,
6716,
787,
2737,
14,
961,
365,
282,
511,
3272,
12,
440,
282,
10685,
367,
625,
11122,
199,
3,
1709,
14,
199,
533,
12373,
17,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
17,
2,
421,
199,
533,
12373,
18,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
18,
2,
421,
199,
533,
1910,
11122,
17,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
12883,
275,
756,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
17,
2,
421,
199,
3,
1910,
77,
618,
68,
543,
376,
333,
18,
77,
370,
625,
11122,
26,
314,
1640,
30747,
1817,
7859,
1133,
506,
2737,
14,
199,
533,
1910,
11122,
18,
8,
992,
14,
1685,
304,
272,
8562,
275,
1709,
14,
7624,
8,
1358,
11122,
17,
9,
339,
1021,
6288,
26,
267,
12883,
275,
756,
267,
1592,
63,
1224,
275,
298,
324,
11122,
63,
992,
63,
3280,
18,
2,
421,
199,
3,
11842,
1159,
376,
625,
11122,
1402,
543,
376,
333,
18,
77,
370,
282,
12883,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ikargis/horizon_fod
|
openstack_dashboard/dashboards/project/networks/ports/views.py
|
12
|
2782
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 NEC Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse # noqa
from django.utils.translation import ugettext_lazy as _ # noqa
from horizon import exceptions
from horizon import forms
from horizon import tabs
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.networks.ports \
import forms as project_forms
from openstack_dashboard.dashboards.project.networks.ports \
import tabs as project_tabs
class DetailView(tabs.TabView):
tab_group_class = project_tabs.PortDetailTabs
template_name = 'project/networks/ports/detail.html'
class UpdateView(forms.ModalFormView):
form_class = project_forms.UpdatePort
template_name = 'project/networks/ports/update.html'
context_object_name = 'port'
success_url = 'horizon:project:networks:detail'
def get_success_url(self):
return reverse(self.success_url,
args=(self.kwargs['network_id'],))
def _get_object(self, *args, **kwargs):
if not hasattr(self, "_object"):
port_id = self.kwargs['port_id']
try:
self._object = api.neutron.port_get(self.request, port_id)
except Exception:
redirect = reverse("horizon:project:networks:detail",
args=(self.kwargs['network_id'],))
msg = _('Unable to retrieve port details')
exceptions.handle(self.request, msg, redirect=redirect)
return self._object
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
port = self._get_object()
context['port_id'] = port['id']
context['network_id'] = port['network_id']
return context
def get_initial(self):
port = self._get_object()
return {'port_id': port['id'],
'network_id': port['network_id'],
'tenant_id': port['tenant_id'],
'name': port['name'],
'admin_state': port['admin_state_up'],
'device_id': port['device_id'],
'device_owner': port['device_owner']}
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
653,
4220,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
221,
327,
8151,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
12187,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
7642,
14,
5203,
971,
272,
492,
4513,
465,
2199,
63,
3351,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
7642,
14,
5203,
971,
272,
492,
12187,
465,
2199,
63,
8741,
421,
199,
533,
13302,
2768,
8,
8741,
14,
7690,
2768,
304,
272,
5174,
63,
923,
63,
533,
275,
2199,
63,
8741,
14,
4313,
8064,
23085,
272,
1978,
63,
354,
275,
283,
1715,
15,
7642,
15,
5203,
15,
5506,
14,
1360,
7,
421,
199,
533,
6162,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
2199,
63,
3351,
14,
4152,
4313,
272,
1978,
63,
354,
275,
283,
1715,
15,
7642,
15,
5203,
15,
873,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
719,
7,
272,
3182,
63,
633,
275,
283,
16561,
26,
1715,
26,
7642,
26,
5506,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
8,
277,
14,
3742,
63,
633,
12,
2432,
1249,
2687,
277,
14,
958,
459,
1200,
63,
344,
995,
430,
339,
347,
485,
362,
63,
785,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
2688,
8,
277,
12,
2668,
785,
2349,
288,
1844,
63,
344,
275,
291,
14,
958,
459,
719,
63,
344,
418,
288,
862,
26,
355,
291,
423,
785,
275,
2986,
14,
10271,
14,
719,
63,
362,
8,
277,
14,
1069,
12,
1844,
63,
344,
9,
288,
871,
2186,
26,
355,
4660,
275,
3837,
480,
16561,
26,
1715,
26,
7642,
26,
5506,
401,
3521,
1249,
2687,
277,
14,
958,
459,
1200,
63,
344,
995,
430,
355,
1499,
275,
4018,
6005,
370,
8044,
1844,
2436,
358,
355,
4967,
14,
2479,
8,
277,
14,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
267,
372,
291,
423,
785,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
4152,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1844,
275,
291,
423,
362,
63,
785,
342,
267,
1067,
459,
719,
63,
344,
418,
275,
1844,
459,
344,
418,
267,
1067,
459,
1200,
63,
344,
418,
275,
1844,
459,
1200,
63,
344,
418,
267,
372,
1067,
339,
347,
664,
63,
2747,
8,
277,
304,
267,
1844,
275,
291,
423,
362,
63,
785,
342,
267,
372,
791,
719,
63,
344,
356,
1844,
459,
344,
995,
355,
283,
1200,
63,
344,
356,
1844,
459,
1200,
63,
344,
995,
355,
283,
4647,
63,
344,
356,
1844,
459,
4647,
63,
344,
995,
355,
283,
354,
356,
1844,
459,
354,
995,
355,
283,
2113,
63,
929,
356,
1844,
459,
2113,
63,
929,
63,
384,
995,
355,
283,
1782,
63,
344,
356,
1844,
459,
1782,
63,
344,
995,
355,
283,
1782,
63,
4597,
356,
1844,
459,
1782,
63,
4597,
12074,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
653,
4220,
11098,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
221,
327,
8151,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
221,
327,
8151,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
12187,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
7642,
14,
5203,
971,
272,
492,
4513,
465,
2199,
63,
3351,
199,
504,
13869,
63,
9743,
14,
30424,
14,
1715,
14,
7642,
14,
5203,
971,
272,
492,
12187,
465,
2199,
63,
8741,
421,
199,
533,
13302,
2768,
8,
8741,
14,
7690,
2768,
304,
272,
5174,
63,
923,
63,
533,
275,
2199,
63,
8741,
14,
4313,
8064,
23085,
272,
1978,
63,
354,
275,
283,
1715,
15,
7642,
15,
5203,
15,
5506,
14,
1360,
7,
421,
199,
533,
6162,
2768,
8,
3351,
14,
23689,
2821,
2768,
304,
272,
1824,
63,
533,
275,
2199,
63,
3351,
14,
4152,
4313,
272,
1978,
63,
354,
275,
283,
1715,
15,
7642,
15,
5203,
15,
873,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
719,
7,
272,
3182,
63,
633,
275,
283,
16561,
26,
1715,
26,
7642,
26,
5506,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
8,
277,
14,
3742,
63,
633,
12,
2432,
1249,
2687,
277,
14,
958,
459,
1200,
63,
344,
995,
430,
339,
347,
485,
362,
63,
785,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
2688,
8,
277,
12,
2668,
785,
2349,
288,
1844,
63,
344,
275,
291,
14,
958,
459,
719,
63,
344,
418,
288,
862,
26,
355,
291,
423,
785,
275,
2986,
14,
10271,
14,
719,
63,
362,
8,
277,
14,
1069,
12,
1844,
63,
344,
9,
288,
871,
2186,
26,
355,
4660,
275,
3837,
480,
16561,
26,
1715,
26,
7642,
26,
5506,
401,
3521,
1249,
2687,
277,
14,
958,
459,
1200,
63,
344,
995,
430,
355,
1499,
275,
4018,
6005,
370,
8044,
1844,
2436,
358,
355,
4967,
14,
2479,
8,
277,
14,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
267,
372,
291,
423,
785,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
4152,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1844,
275,
291,
423,
362,
63,
785,
342,
267,
1067,
459,
719,
63,
344,
418,
275,
1844,
459,
344,
418,
267,
1067,
459,
1200,
63,
344,
418,
275,
1844,
459,
1200,
63,
344,
418,
267,
372,
1067,
339,
347,
664,
63,
2747,
8,
277,
304,
267,
1844,
275,
291,
423,
362,
63,
785,
342,
267,
372,
791,
719,
63,
344,
356,
1844,
459,
344,
995,
355,
283,
1200,
63,
344,
356,
1844,
459,
1200,
63,
344,
995,
355,
283,
4647,
63,
344,
356,
1844,
459,
4647,
63,
344,
995,
355,
283,
354,
356,
1844,
459,
354,
995,
355,
283,
2113,
63,
929,
356,
1844,
459,
2113,
63,
929,
63,
384,
995,
355,
283,
1782,
63,
344,
356,
1844,
459,
1782,
63,
344,
995,
355,
283,
1782,
63,
4597,
356,
1844,
459,
1782,
63,
4597,
12074,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
daler/trackhub
|
trackhub/base.py
|
1
|
4408
|
from __future__ import absolute_import
import os
import warnings
import tempfile
from collections import OrderedDict
def deprecation_handler(source, filename, kwargs):
if 'local_fn' in kwargs:
warnings.warn(
'Please use the argument "source" instead of "local_fn"',
DeprecationWarning)
if source is not None:
raise ValueError(
'Both "source" and "local_fn" are specified. Please use '
'just "source"')
source = kwargs.pop('local_fn')
if 'remote_fn' in kwargs:
warnings.warn(
'Please use the argument "source" instead of "remote_fn"',
DeprecationWarning)
if filename is not None:
raise ValueError(
'Both "filename" and "remote_fn" are specified. Please use '
'just "filename"')
filename = kwargs.pop('remote_fn')
return source, filename
class HubComponent(object):
"""
Base class for various track hub components. Several methods must be
overridden by subclasses.
"""
def __init__(self):
self.children = []
self.parent = None
def _render(self, staging='staging'):
"""
Renders the object to file. Must be overridden by subclass.
Can return None if nothing to be done for the subclass.
"""
raise NotImplementedError(
"%s: subclasses must define their own _render() method"
% self.__class__.__name__)
def validate(self):
"""
Runs validation, raising exceptions as needed. Must be overridden by
subclass.
"""
raise NotImplementedError(
"%s: subclasses must define their own validate() method"
% self.__class__.__name__)
def add_child(self, child):
"""
Adds self as parent to child, and then adds child.
"""
child.parent = self
self.children.append(child)
return child
def add_parent(self, parent):
"""
Adds self as child of parent, then adds parent.
"""
parent.add_child(self)
self.parent = parent
return parent
def root(self, cls=None, level=0):
"""
Returns the top-most HubComponent in the hierarchy.
If `cls` is not None, then return the top-most attribute HubComponent
that is an instance of class `cls`.
For a fully-constructed track hub (and `cls=None`), this should return
a a Hub object for every component in the hierarchy.
"""
if cls is None:
if self.parent is None:
return self, level
else:
if isinstance(self, cls):
if not isinstance(self.parent, cls):
return self, level
if self.parent is None:
return None, None
return self.parent.root(cls, level - 1)
def leaves(self, cls, level=0, intermediate=False):
"""
Returns an iterator of the HubComponent leaves that are of class `cls`.
If `intermediate` is True, then return any intermediate classes as
well.
"""
if intermediate:
if isinstance(self, cls):
yield self, level
elif len(self.children) == 0:
if isinstance(self, cls):
yield self, level
else:
raise StopIteration
for child in self.children:
for leaf, _level in child.leaves(
cls, level + 1, intermediate=intermediate
):
yield leaf, _level
def render(self, staging=None):
"""
Renders the object to file, returning a list of created files.
Calls validation code, and, as long as each child is also a subclass of
:class:`HubComponent`, the rendering is recursive.
"""
self.validate()
created_files = OrderedDict()
if staging is None:
staging = tempfile.mkdtemp()
this = self._render(staging)
if this:
created_files[repr(self)] = this
for child in self.children:
created_files[repr(child)] = child.render(staging)
return created_files
def makedirs(self, fn):
dirname = os.path.dirname(fn)
if not os.path.exists(dirname):
os.makedirs(dirname)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
747,
199,
646,
3598,
199,
646,
5549,
199,
504,
5055,
492,
8773,
421,
199,
318,
17831,
63,
2232,
8,
1365,
12,
1788,
12,
2074,
304,
272,
340,
283,
1832,
63,
2324,
7,
315,
2074,
26,
267,
3598,
14,
4050,
8,
288,
283,
8254,
675,
314,
1423,
298,
1365,
2,
3140,
402,
298,
1832,
63,
2324,
6949,
288,
13413,
9,
267,
340,
1350,
365,
440,
488,
26,
288,
746,
1722,
8,
355,
283,
18088,
298,
1365,
2,
436,
298,
1832,
63,
2324,
2,
787,
2013,
14,
7754,
675,
283,
355,
283,
4764,
298,
1365,
9008,
267,
1350,
275,
2074,
14,
1935,
360,
1832,
63,
2324,
358,
339,
340,
283,
3846,
63,
2324,
7,
315,
2074,
26,
267,
3598,
14,
4050,
8,
288,
283,
8254,
675,
314,
1423,
298,
1365,
2,
3140,
402,
298,
3846,
63,
2324,
6949,
288,
13413,
9,
267,
340,
1788,
365,
440,
488,
26,
288,
746,
1722,
8,
355,
283,
18088,
298,
1501,
2,
436,
298,
3846,
63,
2324,
2,
787,
2013,
14,
7754,
675,
283,
355,
283,
4764,
298,
1501,
9008,
267,
1788,
275,
2074,
14,
1935,
360,
3846,
63,
2324,
358,
272,
372,
1350,
12,
1788,
421,
199,
533,
869,
456,
7004,
8,
785,
304,
272,
408,
272,
3523,
1021,
367,
7750,
4426,
26726,
7323,
14,
221,
3240,
422,
279,
3102,
1471,
506,
272,
10087,
701,
9180,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3223,
275,
942,
267,
291,
14,
1708,
275,
488,
339,
347,
485,
3352,
8,
277,
12,
28512,
534,
26840,
735,
267,
408,
267,
10055,
7735,
314,
909,
370,
570,
14,
221,
9498,
506,
10087,
701,
5516,
14,
398,
6855,
372,
488,
340,
6548,
370,
506,
4224,
367,
314,
5516,
14,
267,
408,
267,
746,
4279,
8,
288,
2071,
83,
26,
9180,
1471,
5627,
3932,
5705,
485,
3352,
342,
1083,
2,
288,
450,
291,
855,
533,
4914,
354,
3368,
339,
347,
4107,
8,
277,
304,
267,
408,
267,
23773,
6411,
12,
17026,
4967,
465,
4346,
14,
221,
9498,
506,
10087,
701,
267,
5516,
14,
267,
408,
267,
746,
4279,
8,
288,
2071,
83,
26,
9180,
1471,
5627,
3932,
5705,
4107,
342,
1083,
2,
288,
450,
291,
855,
533,
4914,
354,
3368,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
408,
267,
15747,
291,
465,
1676,
370,
1982,
12,
436,
2066,
9584,
1982,
14,
267,
408,
267,
1982,
14,
1708,
275,
291,
267,
291,
14,
3223,
14,
740,
8,
1739,
9,
267,
372,
1982,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
408,
267,
15747,
291,
465,
1982,
402,
1676,
12,
2066,
9584,
1676,
14,
267,
408,
267,
1676,
14,
525,
63,
1739,
8,
277,
9,
267,
291,
14,
1708,
275,
1676,
267,
372,
1676,
339,
347,
1738,
8,
277,
12,
843,
29,
403,
12,
2166,
29,
16,
304,
267,
408,
267,
1803,
314,
2746,
13,
2786,
869,
456,
7004,
315,
314,
14446,
14,
398,
982,
658,
1886,
64,
365,
440,
488,
12,
2066,
372,
314,
2746,
13,
2786,
2225,
869,
456,
7004,
267,
626,
365,
376,
1256,
402,
1021,
658,
1886,
2313,
398,
2104,
282,
9999,
13,
388,
11614,
4426,
26726,
334,
460,
658,
1886,
29,
403,
29984,
642,
1077,
372,
267,
282,
282,
869,
456,
909,
367,
4036,
3931,
315,
314,
14446,
14,
267,
408,
267,
340,
843,
365,
488,
26,
288,
340,
291,
14,
1708,
365,
488,
26,
355,
372,
291,
12,
2166,
267,
587,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
340,
440,
1228,
8,
277,
14,
1708,
12,
843,
304,
490,
372,
291,
12,
2166,
398,
340,
291,
14,
1708,
365,
488,
26,
288,
372,
488,
12,
488,
398,
372,
291,
14,
1708,
14,
1231,
8,
1886,
12,
2166,
446,
413,
9,
339,
347,
16733,
8,
277,
12,
843,
12,
2166,
29,
16,
12,
13197,
29,
797,
304,
267,
408,
267,
1803,
376,
6122,
402,
314,
869,
456,
7004,
16733,
626,
787,
402,
1021,
658,
1886,
2313,
398,
982,
658,
15940,
64,
365,
715,
12,
2066,
372,
1263,
13197,
3992,
465,
267,
5521,
14,
267,
408,
267,
340,
13197,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
1995,
291,
12,
2166,
267,
916,
822,
8,
277,
14,
3223,
9,
508,
378,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
1995,
291,
12,
2166,
288,
587,
26,
355,
746,
10852,
398,
367,
1982,
315,
291,
14,
3223,
26,
288,
367,
11747,
12,
485,
1896,
315,
1982,
14,
16554,
8,
355,
843,
12,
2166,
435,
413,
12,
13197,
29,
15940,
288,
3461,
490,
1995,
11747,
12,
485,
1896,
339,
347,
3795,
8,
277,
12,
28512,
29,
403,
304,
267,
408,
267,
10055,
7735,
314,
909,
370,
570,
12,
8152,
282,
769,
402,
2737,
1584,
14,
398,
28055,
6411,
1233,
12,
436,
12,
465,
1846,
465,
1924,
1982,
365,
2597,
282,
5516,
402,
267,
520,
533,
1705,
15338,
7004,
3559,
314,
14066,
365,
9133,
14,
267,
408,
267,
291,
14,
3502,
342,
267,
2737,
63,
1725,
275,
8773,
342,
267,
340,
28512,
365,
488,
26,
288,
28512,
275,
5549,
14,
11983,
342,
267,
642,
275,
291,
423,
3352,
8,
26840,
9,
267,
340,
642,
26,
288,
2737,
63,
1725,
59,
2722,
8,
277,
1874,
275,
642,
267,
367,
1982,
315,
291,
14,
3223,
26,
288,
2737,
63,
1725,
59,
2722,
8,
1739,
1874,
275,
1982,
14,
3352,
8,
26840,
9,
267,
372,
2737,
63,
1725,
339,
347,
1852,
3220,
8,
277,
12,
4325,
304,
267,
9017,
275,
747,
14,
515,
14,
3475,
8,
2324,
9,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
3475,
304,
288,
747,
14,
8347,
8,
3475,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
747,
199,
646,
3598,
199,
646,
5549,
199,
504,
5055,
492,
8773,
421,
199,
318,
17831,
63,
2232,
8,
1365,
12,
1788,
12,
2074,
304,
272,
340,
283,
1832,
63,
2324,
7,
315,
2074,
26,
267,
3598,
14,
4050,
8,
288,
283,
8254,
675,
314,
1423,
298,
1365,
2,
3140,
402,
298,
1832,
63,
2324,
6949,
288,
13413,
9,
267,
340,
1350,
365,
440,
488,
26,
288,
746,
1722,
8,
355,
283,
18088,
298,
1365,
2,
436,
298,
1832,
63,
2324,
2,
787,
2013,
14,
7754,
675,
283,
355,
283,
4764,
298,
1365,
9008,
267,
1350,
275,
2074,
14,
1935,
360,
1832,
63,
2324,
358,
339,
340,
283,
3846,
63,
2324,
7,
315,
2074,
26,
267,
3598,
14,
4050,
8,
288,
283,
8254,
675,
314,
1423,
298,
1365,
2,
3140,
402,
298,
3846,
63,
2324,
6949,
288,
13413,
9,
267,
340,
1788,
365,
440,
488,
26,
288,
746,
1722,
8,
355,
283,
18088,
298,
1501,
2,
436,
298,
3846,
63,
2324,
2,
787,
2013,
14,
7754,
675,
283,
355,
283,
4764,
298,
1501,
9008,
267,
1788,
275,
2074,
14,
1935,
360,
3846,
63,
2324,
358,
272,
372,
1350,
12,
1788,
421,
199,
533,
869,
456,
7004,
8,
785,
304,
272,
408,
272,
3523,
1021,
367,
7750,
4426,
26726,
7323,
14,
221,
3240,
422,
279,
3102,
1471,
506,
272,
10087,
701,
9180,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3223,
275,
942,
267,
291,
14,
1708,
275,
488,
339,
347,
485,
3352,
8,
277,
12,
28512,
534,
26840,
735,
267,
408,
267,
10055,
7735,
314,
909,
370,
570,
14,
221,
9498,
506,
10087,
701,
5516,
14,
398,
6855,
372,
488,
340,
6548,
370,
506,
4224,
367,
314,
5516,
14,
267,
408,
267,
746,
4279,
8,
288,
2071,
83,
26,
9180,
1471,
5627,
3932,
5705,
485,
3352,
342,
1083,
2,
288,
450,
291,
855,
533,
4914,
354,
3368,
339,
347,
4107,
8,
277,
304,
267,
408,
267,
23773,
6411,
12,
17026,
4967,
465,
4346,
14,
221,
9498,
506,
10087,
701,
267,
5516,
14,
267,
408,
267,
746,
4279,
8,
288,
2071,
83,
26,
9180,
1471,
5627,
3932,
5705,
4107,
342,
1083,
2,
288,
450,
291,
855,
533,
4914,
354,
3368,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
408,
267,
15747,
291,
465,
1676,
370,
1982,
12,
436,
2066,
9584,
1982,
14,
267,
408,
267,
1982,
14,
1708,
275,
291,
267,
291,
14,
3223,
14,
740,
8,
1739,
9,
267,
372,
1982,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
408,
267,
15747,
291,
465,
1982,
402,
1676,
12,
2066,
9584,
1676,
14,
267,
408,
267,
1676,
14,
525,
63,
1739,
8,
277,
9,
267,
291,
14,
1708,
275,
1676,
267,
372,
1676,
339,
347,
1738,
8,
277,
12,
843,
29,
403,
12,
2166,
29,
16,
304,
267,
408,
267,
1803,
314,
2746,
13,
2786,
869,
456,
7004,
315,
314,
14446,
14,
398,
982,
658,
1886,
64,
365,
440,
488,
12,
2066,
372,
314,
2746,
13,
2786,
2225,
869,
456,
7004,
267,
626,
365,
376,
1256,
402,
1021,
658,
1886,
2313,
398,
2104,
282,
9999,
13,
388,
11614,
4426,
26726,
334,
460,
658,
1886,
29,
403,
29984,
642,
1077,
372,
267,
282,
282,
869,
456,
909,
367,
4036,
3931,
315,
314,
14446,
14,
267,
408,
267,
340,
843,
365,
488,
26,
288,
340,
291,
14,
1708,
365,
488,
26,
355,
372,
291,
12,
2166,
267,
587,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
340,
440,
1228,
8,
277,
14,
1708,
12,
843,
304,
490,
372,
291,
12,
2166,
398,
340,
291,
14,
1708,
365,
488,
26,
288,
372,
488,
12,
488,
398,
372,
291,
14,
1708,
14,
1231,
8,
1886,
12,
2166,
446,
413,
9,
339,
347,
16733,
8,
277,
12,
843,
12,
2166,
29,
16,
12,
13197,
29,
797,
304,
267,
408,
267,
1803,
376,
6122,
402,
314,
869,
456,
7004,
16733,
626,
787,
402,
1021,
658,
1886,
2313,
398,
982,
658,
15940,
64,
365,
715,
12,
2066,
372,
1263,
13197,
3992,
465,
267,
5521,
14,
267,
408,
267,
340,
13197,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
1995,
291,
12,
2166,
267,
916,
822,
8,
277,
14,
3223,
9,
508,
378,
26,
288,
340,
1228,
8,
277,
12,
843,
304,
355,
1995,
291,
12,
2166,
288,
587,
26,
355,
746,
10852,
398,
367,
1982,
315,
291,
14,
3223,
26,
288,
367,
11747,
12,
485,
1896,
315,
1982,
14,
16554,
8,
355,
843,
12,
2166,
435,
413,
12,
13197,
29,
15940,
288,
3461,
490,
1995,
11747,
12,
485,
1896,
339,
347,
3795,
8,
277,
12,
28512,
29,
403,
304,
267,
408,
267,
10055,
7735,
314,
909,
370,
570,
12,
8152,
282,
769,
402,
2737,
1584,
14,
398,
28055,
6411,
1233,
12,
436,
12,
465,
1846,
465,
1924,
1982,
365,
2597,
282,
5516,
402,
267,
520,
533,
1705,
15338,
7004,
3559,
314,
14066,
365,
9133,
14,
267,
408,
267,
291,
14,
3502,
342,
267,
2737,
63,
1725,
275,
8773,
342,
267,
340,
28512,
365,
488,
26,
288,
28512,
275,
5549,
14,
11983,
342,
267,
642,
275,
291,
423,
3352,
8,
26840,
9,
267,
340,
642,
26,
288,
2737,
63,
1725,
59,
2722,
8,
277,
1874,
275,
642,
267,
367,
1982,
315,
291,
14,
3223,
26,
288,
2737,
63,
1725,
59,
2722,
8,
1739,
1874,
275,
1982,
14,
3352,
8,
26840,
9,
267,
372,
2737,
63,
1725,
339,
347,
1852,
3220,
8,
277,
12,
4325,
304,
267,
9017,
275,
747,
14,
515,
14,
3475,
8,
2324,
9,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
3475,
304,
288,
747,
14,
8347,
8,
3475,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lukeiwanski/tensorflow
|
tensorflow/contrib/distributions/python/ops/mvn_diag.py
|
13
|
8814
|
# 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.
# ==============================================================================
"""Multivariate Normal distribution classes."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.distributions.python.ops import distribution_util
from tensorflow.contrib.distributions.python.ops import mvn_linear_operator as mvn_linop
from tensorflow.python.framework import ops
from tensorflow.python.ops import nn
from tensorflow.python.util import deprecation
__all__ = [
"MultivariateNormalDiag",
"MultivariateNormalDiagWithSoftplusScale",
]
class MultivariateNormalDiag(
mvn_linop.MultivariateNormalLinearOperator):
"""The multivariate normal distribution on `R^k`.
The Multivariate Normal distribution is defined over `R^k` and parameterized
by a (batch of) length-`k` `loc` vector (aka "mu") and a (batch of) `k x k`
`scale` matrix; `covariance = scale @ scale.T` where `@` denotes
matrix-multiplication.
#### Mathematical Details
The probability density function (pdf) is,
```none
pdf(x; loc, scale) = exp(-0.5 ||y||**2) / Z,
y = inv(scale) @ (x - loc),
Z = (2 pi)**(0.5 k) |det(scale)|,
```
where:
* `loc` is a vector in `R^k`,
* `scale` is a linear operator in `R^{k x k}`, `cov = scale @ scale.T`,
* `Z` denotes the normalization constant, and,
* `||y||**2` denotes the squared Euclidean norm of `y`.
A (non-batch) `scale` matrix is:
```none
scale = diag(scale_diag + scale_identity_multiplier * ones(k))
```
where:
* `scale_diag.shape = [k]`, and,
* `scale_identity_multiplier.shape = []`.
Additional leading dimensions (if any) will index batches.
If both `scale_diag` and `scale_identity_multiplier` are `None`, then
`scale` is the Identity matrix.
The MultivariateNormal distribution is a member of the [location-scale
family](https://en.wikipedia.org/wiki/Location-scale_family), i.e., it can be
constructed as,
```none
X ~ MultivariateNormal(loc=0, scale=1) # Identity scale, zero shift.
Y = scale @ X + loc
```
#### Examples
```python
tfd = tf.contrib.distributions
# Initialize a single 2-variate Gaussian.
mvn = tfd.MultivariateNormalDiag(
loc=[1., -1],
scale_diag=[1, 2.])
mvn.mean().eval()
# ==> [1., -1]
mvn.stddev().eval()
# ==> [1., 2]
# Evaluate this on an observation in `R^2`, returning a scalar.
mvn.prob([-1., 0]).eval() # shape: []
# Initialize a 3-batch, 2-variate scaled-identity Gaussian.
mvn = tfd.MultivariateNormalDiag(
loc=[1., -1],
scale_identity_multiplier=[1, 2., 3])
mvn.mean().eval() # shape: [3, 2]
# ==> [[1., -1]
# [1, -1],
# [1, -1]]
mvn.stddev().eval() # shape: [3, 2]
# ==> [[1., 1],
# [2, 2],
# [3, 3]]
# Evaluate this on an observation in `R^2`, returning a length-3 vector.
mvn.prob([-1., 0]).eval() # shape: [3]
# Initialize a 2-batch of 3-variate Gaussians.
mvn = tfd.MultivariateNormalDiag(
loc=[[1., 2, 3],
[11, 22, 33]] # shape: [2, 3]
scale_diag=[[1., 2, 3],
[0.5, 1, 1.5]]) # shape: [2, 3]
# Evaluate this on a two observations, each in `R^3`, returning a length-2
# vector.
x = [[-1., 0, 1],
[-11, 0, 11.]] # shape: [2, 3].
mvn.prob(x).eval() # shape: [2]
```
"""
@deprecation.deprecated(
"2018-10-01",
"The TensorFlow Distributions library has moved to "
"TensorFlow Probability "
"(https://github.com/tensorflow/probability). You "
"should update all references to use `tfp.distributions` "
"instead of `tf.contrib.distributions`.",
warn_once=True)
def __init__(self,
loc=None,
scale_diag=None,
scale_identity_multiplier=None,
validate_args=False,
allow_nan_stats=True,
name="MultivariateNormalDiag"):
"""Construct Multivariate Normal distribution on `R^k`.
The `batch_shape` is the broadcast shape between `loc` and `scale`
arguments.
The `event_shape` is given by last dimension of the matrix implied by
`scale`. The last dimension of `loc` (if provided) must broadcast with this.
Recall that `covariance = scale @ scale.T`. A (non-batch) `scale` matrix is:
```none
scale = diag(scale_diag + scale_identity_multiplier * ones(k))
```
where:
* `scale_diag.shape = [k]`, and,
* `scale_identity_multiplier.shape = []`.
Additional leading dimensions (if any) will index batches.
If both `scale_diag` and `scale_identity_multiplier` are `None`, then
`scale` is the Identity matrix.
Args:
loc: Floating-point `Tensor`. If this is set to `None`, `loc` is
implicitly `0`. When specified, may have shape `[B1, ..., Bb, k]` where
`b >= 0` and `k` is the event size.
scale_diag: Non-zero, floating-point `Tensor` representing a diagonal
matrix added to `scale`. May have shape `[B1, ..., Bb, k]`, `b >= 0`,
and characterizes `b`-batches of `k x k` diagonal matrices added to
`scale`. When both `scale_identity_multiplier` and `scale_diag` are
`None` then `scale` is the `Identity`.
scale_identity_multiplier: Non-zero, floating-point `Tensor` representing
a scaled-identity-matrix added to `scale`. May have shape
`[B1, ..., Bb]`, `b >= 0`, and characterizes `b`-batches of scaled
`k x k` identity matrices added to `scale`. When both
`scale_identity_multiplier` and `scale_diag` are `None` then `scale` is
the `Identity`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`,
statistics (e.g., mean, mode, variance) use the value "`NaN`" to
indicate the result is undefined. When `False`, an exception is raised
if one or more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
Raises:
ValueError: if at most `scale_identity_multiplier` is specified.
"""
parameters = dict(locals())
with ops.name_scope(name) as name:
with ops.name_scope("init", values=[
loc, scale_diag, scale_identity_multiplier]):
# No need to validate_args while making diag_scale. The returned
# LinearOperatorDiag has an assert_non_singular method that is called by
# the Bijector.
scale = distribution_util.make_diag_scale(
loc=loc,
scale_diag=scale_diag,
scale_identity_multiplier=scale_identity_multiplier,
validate_args=False,
assert_positive=False)
super(MultivariateNormalDiag, self).__init__(
loc=loc,
scale=scale,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
name=name)
self._parameters = parameters
class MultivariateNormalDiagWithSoftplusScale(MultivariateNormalDiag):
"""MultivariateNormalDiag with `diag_stddev = softplus(diag_stddev)`."""
@deprecation.deprecated(
"2018-10-01",
"The TensorFlow Distributions library has moved to "
"TensorFlow Probability "
"(https://github.com/tensorflow/probability). You "
"should update all references to use `tfp.distributions` "
"instead of `tf.contrib.distributions`.",
warn_once=True)
def __init__(self,
loc,
scale_diag,
validate_args=False,
allow_nan_stats=True,
name="MultivariateNormalDiagWithSoftplusScale"):
parameters = dict(locals())
with ops.name_scope(name, values=[scale_diag]) as name:
super(MultivariateNormalDiagWithSoftplusScale, self).__init__(
loc=loc,
scale_diag=nn.softplus(scale_diag),
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
name=name)
self._parameters = parameters
|
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,
3947,
13805,
11514,
4084,
3992,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
4084,
63,
1974,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
333,
6002,
63,
6676,
63,
3856,
465,
333,
6002,
63,
472,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
421,
199,
363,
452,
363,
275,
359,
272,
298,
3947,
13805,
6241,
16094,
401,
272,
298,
3947,
13805,
6241,
16094,
3007,
51,
1618,
15436,
527,
9944,
401,
199,
61,
421,
199,
533,
6879,
13805,
6241,
16094,
8,
272,
333,
6002,
63,
472,
411,
14,
3947,
13805,
6241,
26463,
304,
523,
408,
1918,
32409,
3293,
4084,
641,
658,
50,
62,
75,
2313,
819,
710,
6879,
13805,
11514,
4084,
365,
3247,
1806,
658,
50,
62,
75,
64,
436,
29526,
523,
701,
282,
334,
2912,
402,
9,
2582,
13,
64,
75,
64,
658,
2102,
64,
5477,
334,
24685,
298,
6553,
531,
436,
282,
334,
2912,
402,
9,
658,
75,
671,
1022,
64,
523,
658,
3467,
64,
3634,
27,
658,
15024,
275,
4666,
768,
4666,
14,
52,
64,
2382,
658,
32,
64,
477,
5983,
523,
3634,
13,
8016,
1863,
14,
819,
14055,
16593,
28491,
15621,
819,
710,
12224,
13650,
805,
334,
5607,
9,
365,
12,
819,
10841,
3592,
523,
11249,
8,
88,
27,
4355,
12,
4666,
9,
275,
1437,
2801,
16,
14,
21,
12208,
89,
10644,
538,
18,
9,
1182,
3107,
12,
523,
612,
275,
4572,
8,
3467,
9,
768,
334,
88,
446,
4355,
395,
523,
3107,
275,
334,
18,
6682,
25288,
16,
14,
21,
1022,
9,
1204,
9886,
8,
3467,
8636,
12,
523,
10841,
819,
2382,
26,
819,
627,
658,
2102,
64,
365,
282,
5477,
315,
658,
50,
62,
75,
3559,
523,
627,
658,
3467,
64,
365,
282,
7798,
4182,
315,
658,
50,
11683,
75,
671,
1022,
93,
3559,
658,
8695,
275,
4666,
768,
4666,
14,
52,
3559,
523,
627,
658,
58,
64,
477,
5983,
314,
16973,
4413,
12,
436,
12,
523,
627,
658,
10644,
89,
10644,
538,
18,
64,
477,
5983,
314,
20478,
662,
24941,
6316,
402,
658,
89,
2313,
819,
437,
334,
2865,
13,
2912,
9,
658,
3467,
64,
3634,
365,
26,
819,
10841,
3592,
523,
4666,
275,
8348,
8,
3467,
63,
6706,
435,
4666,
63,
5582,
63,
15812,
627,
7869,
8,
75,
430,
523,
10841,
819,
2382,
26,
819,
627,
658,
3467,
63,
6706,
14,
1392,
275,
359,
75,
61,
3559,
436,
12,
523,
627,
658,
3467,
63,
5582,
63,
15812,
14,
1392,
275,
942,
2313,
819,
10961,
9186,
7365,
334,
692,
1263,
9,
911,
1478,
19593,
14,
819,
982,
3865,
658,
3467,
63,
6706,
64,
436,
658,
3467,
63,
5582,
63,
15812,
64,
787,
658,
403,
3559,
2066,
523,
658,
3467,
64,
365,
314,
22034,
3634,
14,
819,
710,
6879,
13805,
6241,
4084,
365,
282,
3653,
402,
314,
359,
1985,
13,
3467,
523,
9614,
8738,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
6592,
13,
3467,
63,
6606,
395,
284,
14,
69,
2020,
652,
883,
506,
523,
14701,
465,
12,
819,
10841,
3592,
523,
1323,
6146,
6879,
13805,
6241,
8,
2102,
29,
16,
12,
4666,
29,
17,
9,
257,
327,
22034,
4666,
12,
4697,
7706,
14,
523,
1488,
275,
4666,
768,
1323,
435,
4355,
523,
10841,
819,
14055,
6058,
819,
10841,
1548,
523,
307,
2592,
275,
2833,
14,
2828,
14,
5613,
819,
327,
11578,
282,
2849,
499,
13,
13805,
17131,
14,
523,
333,
6002,
275,
307,
2592,
14,
3947,
13805,
6241,
16094,
8,
489,
4355,
1524,
17,
2020,
446,
17,
467,
489,
4666,
63,
6706,
1524,
17,
12,
499,
14444,
819,
333,
6002,
14,
3670,
1252,
2579,
342,
523,
327,
25375,
359,
17,
2020,
446,
17,
61,
819,
333,
6002,
14,
21672,
1252,
2579,
342,
523,
327,
25375,
359,
17,
2020,
499,
61,
819,
327,
27450,
642,
641,
376,
20038,
315,
658,
50,
62,
18,
3559,
8152,
282,
6917,
14,
523,
333,
6002,
14,
6101,
11468,
17,
2020,
378,
6575,
2579,
342,
221,
327,
2215,
26,
942,
819,
327,
11578,
282,
650,
13,
2912,
12,
499,
13,
13805,
17923,
13,
5582,
17131,
14,
523,
333,
6002,
275,
307,
2592,
14,
3947,
13805,
6241,
16094,
8,
489,
4355,
1524,
17,
2020,
446,
17,
467,
489,
4666,
63,
5582,
63,
15812,
1524,
17,
12,
499,
2020,
650,
566,
819,
333,
6002,
14,
3670,
1252,
2579,
342,
221,
327,
2215,
26,
359,
19,
12,
499,
61,
523,
327,
25375,
3474,
17,
2020,
446,
17,
61,
523,
327,
420,
359,
17,
12,
446,
17,
467,
523,
327,
420,
359,
17,
12,
446,
17,
2677,
819,
333,
6002,
14,
21672,
1252,
2579,
342,
221,
327,
2215,
26,
359,
19,
12,
499,
61,
523,
327,
25375,
3474,
17,
2020,
413,
467,
523,
327,
420,
359,
18,
12,
499,
467,
523,
327,
420,
359,
19,
12,
650,
2677,
819,
327,
27450,
642,
641,
376,
20038,
315,
658,
50,
62,
18,
3559,
8152,
282,
2582,
13,
19,
5477,
14,
523,
333,
6002,
14,
6101,
11468,
17,
2020,
378,
6575,
2579,
342,
221,
327,
2215,
26,
359,
19,
61,
819,
327,
11578,
282,
499
] |
[
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,
3947,
13805,
11514,
4084,
3992,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
4084,
63,
1974,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
333,
6002,
63,
6676,
63,
3856,
465,
333,
6002,
63,
472,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
421,
199,
363,
452,
363,
275,
359,
272,
298,
3947,
13805,
6241,
16094,
401,
272,
298,
3947,
13805,
6241,
16094,
3007,
51,
1618,
15436,
527,
9944,
401,
199,
61,
421,
199,
533,
6879,
13805,
6241,
16094,
8,
272,
333,
6002,
63,
472,
411,
14,
3947,
13805,
6241,
26463,
304,
523,
408,
1918,
32409,
3293,
4084,
641,
658,
50,
62,
75,
2313,
819,
710,
6879,
13805,
11514,
4084,
365,
3247,
1806,
658,
50,
62,
75,
64,
436,
29526,
523,
701,
282,
334,
2912,
402,
9,
2582,
13,
64,
75,
64,
658,
2102,
64,
5477,
334,
24685,
298,
6553,
531,
436,
282,
334,
2912,
402,
9,
658,
75,
671,
1022,
64,
523,
658,
3467,
64,
3634,
27,
658,
15024,
275,
4666,
768,
4666,
14,
52,
64,
2382,
658,
32,
64,
477,
5983,
523,
3634,
13,
8016,
1863,
14,
819,
14055,
16593,
28491,
15621,
819,
710,
12224,
13650,
805,
334,
5607,
9,
365,
12,
819,
10841,
3592,
523,
11249,
8,
88,
27,
4355,
12,
4666,
9,
275,
1437,
2801,
16,
14,
21,
12208,
89,
10644,
538,
18,
9,
1182,
3107,
12,
523,
612,
275,
4572,
8,
3467,
9,
768,
334,
88,
446,
4355,
395,
523,
3107,
275,
334,
18,
6682,
25288,
16,
14,
21,
1022,
9,
1204,
9886,
8,
3467,
8636,
12,
523,
10841,
819,
2382,
26,
819,
627,
658,
2102,
64,
365,
282,
5477,
315,
658,
50,
62,
75,
3559,
523,
627,
658,
3467,
64,
365,
282,
7798,
4182,
315,
658,
50,
11683,
75,
671,
1022,
93,
3559,
658,
8695,
275,
4666,
768,
4666,
14,
52,
3559,
523,
627,
658,
58,
64,
477,
5983,
314,
16973,
4413,
12,
436,
12,
523,
627,
658,
10644,
89,
10644,
538,
18,
64,
477,
5983,
314,
20478,
662,
24941,
6316,
402,
658,
89,
2313,
819,
437,
334,
2865,
13,
2912,
9,
658,
3467,
64,
3634,
365,
26,
819,
10841,
3592,
523,
4666,
275,
8348,
8,
3467,
63,
6706,
435,
4666,
63,
5582,
63,
15812,
627,
7869,
8,
75,
430,
523,
10841,
819,
2382,
26,
819,
627,
658,
3467,
63,
6706,
14,
1392,
275,
359,
75,
61,
3559,
436,
12,
523,
627,
658,
3467,
63,
5582,
63,
15812,
14,
1392,
275,
942,
2313,
819,
10961,
9186,
7365,
334,
692,
1263,
9,
911,
1478,
19593,
14,
819,
982,
3865,
658,
3467,
63,
6706,
64,
436,
658,
3467,
63,
5582,
63,
15812,
64,
787,
658,
403,
3559,
2066,
523,
658,
3467,
64,
365,
314,
22034,
3634,
14,
819,
710,
6879,
13805,
6241,
4084,
365,
282,
3653,
402,
314,
359,
1985,
13,
3467,
523,
9614,
8738,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
6592,
13,
3467,
63,
6606,
395,
284,
14,
69,
2020,
652,
883,
506,
523,
14701,
465,
12,
819,
10841,
3592,
523,
1323,
6146,
6879,
13805,
6241,
8,
2102,
29,
16,
12,
4666,
29,
17,
9,
257,
327,
22034,
4666,
12,
4697,
7706,
14,
523,
1488,
275,
4666,
768,
1323,
435,
4355,
523,
10841,
819,
14055,
6058,
819,
10841,
1548,
523,
307,
2592,
275,
2833,
14,
2828,
14,
5613,
819,
327,
11578,
282,
2849,
499,
13,
13805,
17131,
14,
523,
333,
6002,
275,
307,
2592,
14,
3947,
13805,
6241,
16094,
8,
489,
4355,
1524,
17,
2020,
446,
17,
467,
489,
4666,
63,
6706,
1524,
17,
12,
499,
14444,
819,
333,
6002,
14,
3670,
1252,
2579,
342,
523,
327,
25375,
359,
17,
2020,
446,
17,
61,
819,
333,
6002,
14,
21672,
1252,
2579,
342,
523,
327,
25375,
359,
17,
2020,
499,
61,
819,
327,
27450,
642,
641,
376,
20038,
315,
658,
50,
62,
18,
3559,
8152,
282,
6917,
14,
523,
333,
6002,
14,
6101,
11468,
17,
2020,
378,
6575,
2579,
342,
221,
327,
2215,
26,
942,
819,
327,
11578,
282,
650,
13,
2912,
12,
499,
13,
13805,
17923,
13,
5582,
17131,
14,
523,
333,
6002,
275,
307,
2592,
14,
3947,
13805,
6241,
16094,
8,
489,
4355,
1524,
17,
2020,
446,
17,
467,
489,
4666,
63,
5582,
63,
15812,
1524,
17,
12,
499,
2020,
650,
566,
819,
333,
6002,
14,
3670,
1252,
2579,
342,
221,
327,
2215,
26,
359,
19,
12,
499,
61,
523,
327,
25375,
3474,
17,
2020,
446,
17,
61,
523,
327,
420,
359,
17,
12,
446,
17,
467,
523,
327,
420,
359,
17,
12,
446,
17,
2677,
819,
333,
6002,
14,
21672,
1252,
2579,
342,
221,
327,
2215,
26,
359,
19,
12,
499,
61,
523,
327,
25375,
3474,
17,
2020,
413,
467,
523,
327,
420,
359,
18,
12,
499,
467,
523,
327,
420,
359,
19,
12,
650,
2677,
819,
327,
27450,
642,
641,
376,
20038,
315,
658,
50,
62,
18,
3559,
8152,
282,
2582,
13,
19,
5477,
14,
523,
333,
6002,
14,
6101,
11468,
17,
2020,
378,
6575,
2579,
342,
221,
327,
2215,
26,
359,
19,
61,
819,
327,
11578,
282,
499,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Petr-Kovalev/nupic-win32
|
external/linux32/lib/python2.6/site-packages/matplotlib/_mathtext_data.py
|
69
|
57988
|
"""
font data tables for truetype and afm computer modern fonts
"""
# this dict maps symbol names to fontnames, glyphindex. To get the
# glyph index from the character code, you have to use get_charmap
"""
from matplotlib.ft2font import FT2Font
font = FT2Font('/usr/local/share/matplotlib/cmr10.ttf')
items = font.get_charmap().items()
items.sort()
for charcode, glyphind in items:
print charcode, glyphind
"""
latex_to_bakoma = {
r'\oint' : ('cmex10', 45),
r'\bigodot' : ('cmex10', 50),
r'\bigoplus' : ('cmex10', 55),
r'\bigotimes' : ('cmex10', 59),
r'\sum' : ('cmex10', 51),
r'\prod' : ('cmex10', 24),
r'\int' : ('cmex10', 56),
r'\bigcup' : ('cmex10', 28),
r'\bigcap' : ('cmex10', 60),
r'\biguplus' : ('cmex10', 32),
r'\bigwedge' : ('cmex10', 4),
r'\bigvee' : ('cmex10', 37),
r'\coprod' : ('cmex10', 42),
r'\__sqrt__' : ('cmex10', 48),
r'\leftbrace' : ('cmex10', 92),
r'{' : ('cmex10', 92),
r'\{' : ('cmex10', 92),
r'\rightbrace' : ('cmex10', 130),
r'}' : ('cmex10', 130),
r'\}' : ('cmex10', 130),
r'\leftangle' : ('cmex10', 97),
r'\rightangle' : ('cmex10', 64),
r'\langle' : ('cmex10', 97),
r'\rangle' : ('cmex10', 64),
r'\widehat' : ('cmex10', 15),
r'\widetilde' : ('cmex10', 52),
r'\omega' : ('cmmi10', 29),
r'\varepsilon' : ('cmmi10', 20),
r'\vartheta' : ('cmmi10', 22),
r'\varrho' : ('cmmi10', 61),
r'\varsigma' : ('cmmi10', 41),
r'\varphi' : ('cmmi10', 6),
r'\leftharpoonup' : ('cmmi10', 108),
r'\leftharpoondown' : ('cmmi10', 68),
r'\rightharpoonup' : ('cmmi10', 117),
r'\rightharpoondown' : ('cmmi10', 77),
r'\triangleright' : ('cmmi10', 130),
r'\triangleleft' : ('cmmi10', 89),
r'.' : ('cmmi10', 51),
r',' : ('cmmi10', 44),
r'<' : ('cmmi10', 99),
r'/' : ('cmmi10', 98),
r'>' : ('cmmi10', 107),
r'\flat' : ('cmmi10', 131),
r'\natural' : ('cmmi10', 90),
r'\sharp' : ('cmmi10', 50),
r'\smile' : ('cmmi10', 97),
r'\frown' : ('cmmi10', 58),
r'\ell' : ('cmmi10', 102),
r'\imath' : ('cmmi10', 8),
r'\jmath' : ('cmmi10', 65),
r'\wp' : ('cmmi10', 14),
r'\alpha' : ('cmmi10', 13),
r'\beta' : ('cmmi10', 35),
r'\gamma' : ('cmmi10', 24),
r'\delta' : ('cmmi10', 38),
r'\epsilon' : ('cmmi10', 54),
r'\zeta' : ('cmmi10', 10),
r'\eta' : ('cmmi10', 5),
r'\theta' : ('cmmi10', 18),
r'\iota' : ('cmmi10', 28),
r'\lambda' : ('cmmi10', 9),
r'\mu' : ('cmmi10', 32),
r'\nu' : ('cmmi10', 34),
r'\xi' : ('cmmi10', 7),
r'\pi' : ('cmmi10', 36),
r'\kappa' : ('cmmi10', 30),
r'\rho' : ('cmmi10', 39),
r'\sigma' : ('cmmi10', 21),
r'\tau' : ('cmmi10', 43),
r'\upsilon' : ('cmmi10', 25),
r'\phi' : ('cmmi10', 42),
r'\chi' : ('cmmi10', 17),
r'\psi' : ('cmmi10', 31),
r'|' : ('cmsy10', 47),
r'\|' : ('cmsy10', 47),
r'(' : ('cmr10', 119),
r'\leftparen' : ('cmr10', 119),
r'\rightparen' : ('cmr10', 68),
r')' : ('cmr10', 68),
r'+' : ('cmr10', 76),
r'0' : ('cmr10', 40),
r'1' : ('cmr10', 100),
r'2' : ('cmr10', 49),
r'3' : ('cmr10', 110),
r'4' : ('cmr10', 59),
r'5' : ('cmr10', 120),
r'6' : ('cmr10', 69),
r'7' : ('cmr10', 127),
r'8' : ('cmr10', 77),
r'9' : ('cmr10', 22),
r':' : ('cmr10', 85),
r';' : ('cmr10', 31),
r'=' : ('cmr10', 41),
r'\leftbracket' : ('cmr10', 62),
r'[' : ('cmr10', 62),
r'\rightbracket' : ('cmr10', 72),
r']' : ('cmr10', 72),
r'\%' : ('cmr10', 48),
r'%' : ('cmr10', 48),
r'\$' : ('cmr10', 99),
r'@' : ('cmr10', 111),
r'\_' : ('cmtt10', 79),
r'\Gamma' : ('cmr10', 19),
r'\Delta' : ('cmr10', 6),
r'\Theta' : ('cmr10', 7),
r'\Lambda' : ('cmr10', 14),
r'\Xi' : ('cmr10', 3),
r'\Pi' : ('cmr10', 17),
r'\Sigma' : ('cmr10', 10),
r'\Upsilon' : ('cmr10', 11),
r'\Phi' : ('cmr10', 9),
r'\Psi' : ('cmr10', 15),
r'\Omega' : ('cmr10', 12),
# these are mathml names, I think. I'm just using them for the
# tex methods noted
r'\circumflexaccent' : ('cmr10', 124), # for \hat
r'\combiningbreve' : ('cmr10', 81), # for \breve
r'\combiningoverline' : ('cmr10', 131), # for \bar
r'\combininggraveaccent' : ('cmr10', 114), # for \grave
r'\combiningacuteaccent' : ('cmr10', 63), # for \accute
r'\combiningdiaeresis' : ('cmr10', 91), # for \ddot
r'\combiningtilde' : ('cmr10', 75), # for \tilde
r'\combiningrightarrowabove' : ('cmmi10', 110), # for \vec
r'\combiningdotabove' : ('cmr10', 26), # for \dot
r'\leftarrow' : ('cmsy10', 10),
r'\uparrow' : ('cmsy10', 25),
r'\downarrow' : ('cmsy10', 28),
r'\leftrightarrow' : ('cmsy10', 24),
r'\nearrow' : ('cmsy10', 99),
r'\searrow' : ('cmsy10', 57),
r'\simeq' : ('cmsy10', 108),
r'\Leftarrow' : ('cmsy10', 104),
r'\Rightarrow' : ('cmsy10', 112),
r'\Uparrow' : ('cmsy10', 60),
r'\Downarrow' : ('cmsy10', 68),
r'\Leftrightarrow' : ('cmsy10', 51),
r'\nwarrow' : ('cmsy10', 65),
r'\swarrow' : ('cmsy10', 116),
r'\propto' : ('cmsy10', 15),
r'\prime' : ('cmsy10', 73),
r"'" : ('cmsy10', 73),
r'\infty' : ('cmsy10', 32),
r'\in' : ('cmsy10', 59),
r'\ni' : ('cmsy10', 122),
r'\bigtriangleup' : ('cmsy10', 80),
r'\bigtriangledown' : ('cmsy10', 132),
r'\slash' : ('cmsy10', 87),
r'\forall' : ('cmsy10', 21),
r'\exists' : ('cmsy10', 5),
r'\neg' : ('cmsy10', 20),
r'\emptyset' : ('cmsy10', 33),
r'\Re' : ('cmsy10', 95),
r'\Im' : ('cmsy10', 52),
r'\top' : ('cmsy10', 100),
r'\bot' : ('cmsy10', 11),
r'\aleph' : ('cmsy10', 26),
r'\cup' : ('cmsy10', 6),
r'\cap' : ('cmsy10', 19),
r'\uplus' : ('cmsy10', 58),
r'\wedge' : ('cmsy10', 43),
r'\vee' : ('cmsy10', 96),
r'\vdash' : ('cmsy10', 109),
r'\dashv' : ('cmsy10', 66),
r'\lfloor' : ('cmsy10', 117),
r'\rfloor' : ('cmsy10', 74),
r'\lceil' : ('cmsy10', 123),
r'\rceil' : ('cmsy10', 81),
r'\lbrace' : ('cmsy10', 92),
r'\rbrace' : ('cmsy10', 105),
r'\mid' : ('cmsy10', 47),
r'\vert' : ('cmsy10', 47),
r'\Vert' : ('cmsy10', 44),
r'\updownarrow' : ('cmsy10', 94),
r'\Updownarrow' : ('cmsy10', 53),
r'\backslash' : ('cmsy10', 126),
r'\wr' : ('cmsy10', 101),
r'\nabla' : ('cmsy10', 110),
r'\sqcup' : ('cmsy10', 67),
r'\sqcap' : ('cmsy10', 118),
r'\sqsubseteq' : ('cmsy10', 75),
r'\sqsupseteq' : ('cmsy10', 124),
r'\S' : ('cmsy10', 129),
r'\dag' : ('cmsy10', 71),
r'\ddag' : ('cmsy10', 127),
r'\P' : ('cmsy10', 130),
r'\clubsuit' : ('cmsy10', 18),
r'\diamondsuit' : ('cmsy10', 34),
r'\heartsuit' : ('cmsy10', 22),
r'-' : ('cmsy10', 17),
r'\cdot' : ('cmsy10', 78),
r'\times' : ('cmsy10', 13),
r'*' : ('cmsy10', 9),
r'\ast' : ('cmsy10', 9),
r'\div' : ('cmsy10', 31),
r'\diamond' : ('cmsy10', 48),
r'\pm' : ('cmsy10', 8),
r'\mp' : ('cmsy10', 98),
r'\oplus' : ('cmsy10', 16),
r'\ominus' : ('cmsy10', 56),
r'\otimes' : ('cmsy10', 30),
r'\oslash' : ('cmsy10', 107),
r'\odot' : ('cmsy10', 64),
r'\bigcirc' : ('cmsy10', 115),
r'\circ' : ('cmsy10', 72),
r'\bullet' : ('cmsy10', 84),
r'\asymp' : ('cmsy10', 121),
r'\equiv' : ('cmsy10', 35),
r'\subseteq' : ('cmsy10', 103),
r'\supseteq' : ('cmsy10', 42),
r'\leq' : ('cmsy10', 14),
r'\geq' : ('cmsy10', 29),
r'\preceq' : ('cmsy10', 79),
r'\succeq' : ('cmsy10', 131),
r'\sim' : ('cmsy10', 27),
r'\approx' : ('cmsy10', 23),
r'\subset' : ('cmsy10', 50),
r'\supset' : ('cmsy10', 86),
r'\ll' : ('cmsy10', 85),
r'\gg' : ('cmsy10', 40),
r'\prec' : ('cmsy10', 93),
r'\succ' : ('cmsy10', 49),
r'\rightarrow' : ('cmsy10', 12),
r'\to' : ('cmsy10', 12),
r'\spadesuit' : ('cmsy10', 7),
}
latex_to_cmex = {
r'\__sqrt__' : 112,
r'\bigcap' : 92,
r'\bigcup' : 91,
r'\bigodot' : 75,
r'\bigoplus' : 77,
r'\bigotimes' : 79,
r'\biguplus' : 93,
r'\bigvee' : 95,
r'\bigwedge' : 94,
r'\coprod' : 97,
r'\int' : 90,
r'\leftangle' : 173,
r'\leftbrace' : 169,
r'\oint' : 73,
r'\prod' : 89,
r'\rightangle' : 174,
r'\rightbrace' : 170,
r'\sum' : 88,
r'\widehat' : 98,
r'\widetilde' : 101,
}
latex_to_standard = {
r'\cong' : ('psyr', 64),
r'\Delta' : ('psyr', 68),
r'\Phi' : ('psyr', 70),
r'\Gamma' : ('psyr', 89),
r'\alpha' : ('psyr', 97),
r'\beta' : ('psyr', 98),
r'\chi' : ('psyr', 99),
r'\delta' : ('psyr', 100),
r'\varepsilon' : ('psyr', 101),
r'\phi' : ('psyr', 102),
r'\gamma' : ('psyr', 103),
r'\eta' : ('psyr', 104),
r'\iota' : ('psyr', 105),
r'\varpsi' : ('psyr', 106),
r'\kappa' : ('psyr', 108),
r'\nu' : ('psyr', 110),
r'\pi' : ('psyr', 112),
r'\theta' : ('psyr', 113),
r'\rho' : ('psyr', 114),
r'\sigma' : ('psyr', 115),
r'\tau' : ('psyr', 116),
r'\upsilon' : ('psyr', 117),
r'\varpi' : ('psyr', 118),
r'\omega' : ('psyr', 119),
r'\xi' : ('psyr', 120),
r'\psi' : ('psyr', 121),
r'\zeta' : ('psyr', 122),
r'\sim' : ('psyr', 126),
r'\leq' : ('psyr', 163),
r'\infty' : ('psyr', 165),
r'\clubsuit' : ('psyr', 167),
r'\diamondsuit' : ('psyr', 168),
r'\heartsuit' : ('psyr', 169),
r'\spadesuit' : ('psyr', 170),
r'\leftrightarrow' : ('psyr', 171),
r'\leftarrow' : ('psyr', 172),
r'\uparrow' : ('psyr', 173),
r'\rightarrow' : ('psyr', 174),
r'\downarrow' : ('psyr', 175),
r'\pm' : ('psyr', 176),
r'\geq' : ('psyr', 179),
r'\times' : ('psyr', 180),
r'\propto' : ('psyr', 181),
r'\partial' : ('psyr', 182),
r'\bullet' : ('psyr', 183),
r'\div' : ('psyr', 184),
r'\neq' : ('psyr', 185),
r'\equiv' : ('psyr', 186),
r'\approx' : ('psyr', 187),
r'\ldots' : ('psyr', 188),
r'\aleph' : ('psyr', 192),
r'\Im' : ('psyr', 193),
r'\Re' : ('psyr', 194),
r'\wp' : ('psyr', 195),
r'\otimes' : ('psyr', 196),
r'\oplus' : ('psyr', 197),
r'\oslash' : ('psyr', 198),
r'\cap' : ('psyr', 199),
r'\cup' : ('psyr', 200),
r'\supset' : ('psyr', 201),
r'\supseteq' : ('psyr', 202),
r'\subset' : ('psyr', 204),
r'\subseteq' : ('psyr', 205),
r'\in' : ('psyr', 206),
r'\notin' : ('psyr', 207),
r'\angle' : ('psyr', 208),
r'\nabla' : ('psyr', 209),
r'\textregistered' : ('psyr', 210),
r'\copyright' : ('psyr', 211),
r'\texttrademark' : ('psyr', 212),
r'\Pi' : ('psyr', 213),
r'\prod' : ('psyr', 213),
r'\surd' : ('psyr', 214),
r'\__sqrt__' : ('psyr', 214),
r'\cdot' : ('psyr', 215),
r'\urcorner' : ('psyr', 216),
r'\vee' : ('psyr', 217),
r'\wedge' : ('psyr', 218),
r'\Leftrightarrow' : ('psyr', 219),
r'\Leftarrow' : ('psyr', 220),
r'\Uparrow' : ('psyr', 221),
r'\Rightarrow' : ('psyr', 222),
r'\Downarrow' : ('psyr', 223),
r'\Diamond' : ('psyr', 224),
r'\langle' : ('psyr', 225),
r'\Sigma' : ('psyr', 229),
r'\sum' : ('psyr', 229),
r'\forall' : ('psyr', 34),
r'\exists' : ('psyr', 36),
r'\lceil' : ('psyr', 233),
r'\lbrace' : ('psyr', 123),
r'\Psi' : ('psyr', 89),
r'\bot' : ('psyr', 0136),
r'\Omega' : ('psyr', 0127),
r'\leftbracket' : ('psyr', 0133),
r'\rightbracket' : ('psyr', 0135),
r'\leftbrace' : ('psyr', 123),
r'\leftparen' : ('psyr', 050),
r'\prime' : ('psyr', 0242),
r'\sharp' : ('psyr', 043),
r'\slash' : ('psyr', 057),
r'\Lamda' : ('psyr', 0114),
r'\neg' : ('psyr', 0330),
r'\Upsilon' : ('psyr', 0241),
r'\rightbrace' : ('psyr', 0175),
r'\rfloor' : ('psyr', 0373),
r'\lambda' : ('psyr', 0154),
r'\to' : ('psyr', 0256),
r'\Xi' : ('psyr', 0130),
r'\emptyset' : ('psyr', 0306),
r'\lfloor' : ('psyr', 0353),
r'\rightparen' : ('psyr', 051),
r'\rceil' : ('psyr', 0371),
r'\ni' : ('psyr', 047),
r'\epsilon' : ('psyr', 0145),
r'\Theta' : ('psyr', 0121),
r'\langle' : ('psyr', 0341),
r'\leftangle' : ('psyr', 0341),
r'\rangle' : ('psyr', 0361),
r'\rightangle' : ('psyr', 0361),
r'\rbrace' : ('psyr', 0175),
r'\circ' : ('psyr', 0260),
r'\diamond' : ('psyr', 0340),
r'\mu' : ('psyr', 0155),
r'\mid' : ('psyr', 0352),
r'\imath' : ('pncri8a', 105),
r'\%' : ('pncr8a', 37),
r'\$' : ('pncr8a', 36),
r'\{' : ('pncr8a', 123),
r'\}' : ('pncr8a', 125),
r'\backslash' : ('pncr8a', 92),
r'\ast' : ('pncr8a', 42),
r'\circumflexaccent' : ('pncri8a', 124), # for \hat
r'\combiningbreve' : ('pncri8a', 81), # for \breve
r'\combininggraveaccent' : ('pncri8a', 114), # for \grave
r'\combiningacuteaccent' : ('pncri8a', 63), # for \accute
r'\combiningdiaeresis' : ('pncri8a', 91), # for \ddot
r'\combiningtilde' : ('pncri8a', 75), # for \tilde
r'\combiningrightarrowabove' : ('pncri8a', 110), # for \vec
r'\combiningdotabove' : ('pncri8a', 26), # for \dot
}
# Automatically generated.
type12uni = {'uni24C8': 9416,
'aring': 229,
'uni22A0': 8864,
'uni2292': 8850,
'quotedblright': 8221,
'uni03D2': 978,
'uni2215': 8725,
'uni03D0': 976,
'V': 86,
'dollar': 36,
'uni301E': 12318,
'uni03D5': 981,
'four': 52,
'uni25A0': 9632,
'uni013C': 316,
'uni013B': 315,
'uni013E': 318,
'Yacute': 221,
'uni25DE': 9694,
'uni013F': 319,
'uni255A': 9562,
'uni2606': 9734,
'uni0180': 384,
'uni22B7': 8887,
'uni044F': 1103,
'uni22B5': 8885,
'uni22B4': 8884,
'uni22AE': 8878,
'uni22B2': 8882,
'uni22B1': 8881,
'uni22B0': 8880,
'uni25CD': 9677,
'uni03CE': 974,
'uni03CD': 973,
'uni03CC': 972,
'uni03CB': 971,
'uni03CA': 970,
'uni22B8': 8888,
'uni22C9': 8905,
'uni0449': 1097,
'uni20DD': 8413,
'uni20DC': 8412,
'uni20DB': 8411,
'uni2231': 8753,
'uni25CF': 9679,
'uni306E': 12398,
'uni03D1': 977,
'uni01A1': 417,
'uni20D7': 8407,
'uni03D6': 982,
'uni2233': 8755,
'uni20D2': 8402,
'uni20D1': 8401,
'uni20D0': 8400,
'P': 80,
'uni22BE': 8894,
'uni22BD': 8893,
'uni22BC': 8892,
'uni22BB': 8891,
'underscore': 95,
'uni03C8': 968,
'uni03C7': 967,
'uni0328': 808,
'uni03C5': 965,
'uni03C4': 964,
'uni03C3': 963,
'uni03C2': 962,
'uni03C1': 961,
'uni03C0': 960,
'uni2010': 8208,
'uni0130': 304,
'uni0133': 307,
'uni0132': 306,
'uni0135': 309,
'uni0134': 308,
'uni0137': 311,
'uni0136': 310,
'uni0139': 313,
'uni0138': 312,
'uni2244': 8772,
'uni229A': 8858,
'uni2571': 9585,
'uni0278': 632,
'uni2239': 8761,
'p': 112,
'uni3019': 12313,
'uni25CB': 9675,
'uni03DB': 987,
'uni03DC': 988,
'uni03DA': 986,
'uni03DF': 991,
'uni03DD': 989,
'uni013D': 317,
'uni220A': 8714,
'uni220C': 8716,
'uni220B': 8715,
'uni220E': 8718,
'uni220D': 8717,
'uni220F': 8719,
'uni22CC': 8908,
'Otilde': 213,
'uni25E5': 9701,
'uni2736': 10038,
'perthousand': 8240,
'zero': 48,
'uni279B': 10139,
'dotlessi': 305,
'uni2279': 8825,
'Scaron': 352,
'zcaron': 382,
'uni21D8': 8664,
'egrave': 232,
'uni0271': 625,
'uni01AA': 426,
'uni2332': 9010,
'section': 167,
'uni25E4': 9700,
'Icircumflex': 206,
'ntilde': 241,
'uni041E': 1054,
'ampersand': 38,
'uni041C': 1052,
'uni041A': 1050,
'uni22AB': 8875,
'uni21DB': 8667,
'dotaccent': 729,
'uni0416': 1046,
'uni0417': 1047,
'uni0414': 1044,
'uni0415': 1045,
'uni0412': 1042,
'uni0413': 1043,
'degree': 176,
'uni0411': 1041,
'K': 75,
'uni25EB': 9707,
'uni25EF': 9711,
'uni0418': 1048,
'uni0419': 1049,
'uni2263': 8803,
'uni226E': 8814,
'uni2251': 8785,
'uni02C8': 712,
'uni2262': 8802,
'acircumflex': 226,
'uni22B3': 8883,
'uni2261': 8801,
'uni2394': 9108,
'Aring': 197,
'uni2260': 8800,
'uni2254': 8788,
'uni0436': 1078,
'uni2267': 8807,
'k': 107,
'uni22C8': 8904,
'uni226A': 8810,
'uni231F': 8991,
'smalltilde': 732,
'uni2201': 8705,
'uni2200': 8704,
'uni2203': 8707,
'uni02BD': 701,
'uni2205': 8709,
'uni2204': 8708,
'Agrave': 192,
'uni2206': 8710,
'uni2209': 8713,
'uni2208': 8712,
'uni226D': 8813,
'uni2264': 8804,
'uni263D': 9789,
'uni2258': 8792,
'uni02D3': 723,
'uni02D2': 722,
'uni02D1': 721,
'uni02D0': 720,
'uni25E1': 9697,
'divide': 247,
'uni02D5': 725,
'uni02D4': 724,
'ocircumflex': 244,
'uni2524': 9508,
'uni043A': 1082,
'uni24CC': 9420,
'asciitilde': 126,
'uni22B9': 8889,
'uni24D2': 9426,
'uni211E': 8478,
'uni211D': 8477,
'uni24DD': 9437,
'uni211A': 8474,
'uni211C': 8476,
'uni211B': 8475,
'uni25C6': 9670,
'uni017F': 383,
'uni017A': 378,
'uni017C': 380,
'uni017B': 379,
'uni0346': 838,
'uni22F1': 8945,
'uni22F0': 8944,
'two': 50,
'uni2298': 8856,
'uni24D1': 9425,
'E': 69,
'uni025D': 605,
'scaron': 353,
'uni2322': 8994,
'uni25E3': 9699,
'uni22BF': 8895,
'F': 70,
'uni0440': 1088,
'uni255E': 9566,
'uni22BA': 8890,
'uni0175': 373,
'uni0174': 372,
'uni0177': 375,
'uni0176': 374,
'bracketleft': 91,
'uni0170': 368,
'uni0173': 371,
'uni0172': 370,
'asciicircum': 94,
'uni0179': 377,
'uni2590': 9616,
'uni25E2': 9698,
'uni2119': 8473,
'uni2118': 8472,
'uni25CC': 9676,
'f': 102,
'ordmasculine': 186,
'uni229B': 8859,
'uni22A1': 8865,
'uni2111': 8465,
'uni2110': 8464,
'uni2113': 8467,
'uni2112': 8466,
'mu': 181,
'uni2281': 8833,
'paragraph': 182,
'nine': 57,
'uni25EC': 9708,
'v': 118,
'uni040C': 1036,
'uni0113': 275,
'uni22D0': 8912,
'uni21CC': 8652,
'uni21CB': 8651,
'uni21CA': 8650,
'uni22A5': 8869,
'uni21CF': 8655,
'uni21CE': 8654,
'uni21CD': 8653,
'guilsinglleft': 8249,
'backslash': 92,
'uni2284': 8836,
'uni224E': 8782,
'uni224D': 8781,
'uni224F': 8783,
'uni224A': 8778,
'uni2287': 8839,
'uni224C': 8780,
'uni224B': 8779,
'uni21BD': 8637,
'uni2286': 8838,
'uni030F': 783,
'uni030D': 781,
'uni030E': 782,
'uni030B': 779,
'uni030C': 780,
'uni030A': 778,
'uni026E': 622,
'uni026D': 621,
'six': 54,
'uni026A': 618,
'uni026C': 620,
'uni25C1': 9665,
'uni20D6': 8406,
'uni045B': 1115,
'uni045C': 1116,
'uni256B': 9579,
'uni045A': 1114,
'uni045F': 1119,
'uni045E': 1118,
'A': 65,
'uni2569': 9577,
'uni0458': 1112,
'uni0459': 1113,
'uni0452': 1106,
'uni0453': 1107,
'uni2562': 9570,
'uni0451': 1105,
'uni0456': 1110,
'uni0457': 1111,
'uni0454': 1108,
'uni0455': 1109,
'icircumflex': 238,
'uni0307': 775,
'uni0304': 772,
'uni0305': 773,
'uni0269': 617,
'uni0268': 616,
'uni0300': 768,
'uni0301': 769,
'uni0265': 613,
'uni0264': 612,
'uni0267': 615,
'uni0266': 614,
'uni0261': 609,
'uni0260': 608,
'uni0263': 611,
'uni0262': 610,
'a': 97,
'uni2207': 8711,
'uni2247': 8775,
'uni2246': 8774,
'uni2241': 8769,
'uni2240': 8768,
'uni2243': 8771,
'uni2242': 8770,
'uni2312': 8978,
'ogonek': 731,
'uni2249': 8777,
'uni2248': 8776,
'uni3030': 12336,
'q': 113,
'uni21C2': 8642,
'uni21C1': 8641,
'uni21C0': 8640,
'uni21C7': 8647,
'uni21C6': 8646,
'uni21C5': 8645,
'uni21C4': 8644,
'uni225F': 8799,
'uni212C': 8492,
'uni21C8': 8648,
'uni2467': 9319,
'oacute': 243,
'uni028F': 655,
'uni028E': 654,
'uni026F': 623,
'uni028C': 652,
'uni028B': 651,
'uni028A': 650,
'uni2510': 9488,
'ograve': 242,
'edieresis': 235,
'uni22CE': 8910,
'uni22CF': 8911,
'uni219F': 8607,
'comma': 44,
'uni22CA': 8906,
'uni0429': 1065,
'uni03C6': 966,
'uni0427': 1063,
'uni0426': 1062,
'uni0425': 1061,
'uni0424': 1060,
'uni0423': 1059,
'uni0422': 1058,
'uni0421': 1057,
'uni0420': 1056,
'uni2465': 9317,
'uni24D0': 9424,
'uni2464': 9316,
'uni0430': 1072,
'otilde': 245,
'uni2661': 9825,
'uni24D6': 9430,
'uni2466': 9318,
'uni24D5': 9429,
'uni219A': 8602,
'uni2518': 9496,
'uni22B6': 8886,
'uni2461': 9313,
'uni24D4': 9428,
'uni2460': 9312,
'uni24EA': 9450,
'guillemotright': 187,
'ecircumflex': 234,
'greater': 62,
'uni2011': 8209,
'uacute': 250,
'uni2462': 9314,
'L': 76,
'bullet': 8226,
'uni02A4': 676,
'uni02A7': 679,
'cedilla': 184,
'uni02A2': 674,
'uni2015': 8213,
'uni22C4': 8900,
'uni22C5': 8901,
'uni22AD': 8877,
'uni22C7': 8903,
'uni22C0': 8896,
'uni2016': 8214,
'uni22C2': 8898,
'uni22C3': 8899,
'uni24CF': 9423,
'uni042F': 1071,
'uni042E': 1070,
'uni042D': 1069,
'ydieresis': 255,
'l': 108,
'logicalnot': 172,
'uni24CA': 9418,
'uni0287': 647,
'uni0286': 646,
'uni0285': 645,
'uni0284': 644,
'uni0283': 643,
'uni0282': 642,
'uni0281': 641,
'uni027C': 636,
'uni2664': 9828,
'exclamdown': 161,
'uni25C4': 9668,
'uni0289': 649,
'uni0288': 648,
'uni039A': 922,
'endash': 8211,
'uni2640': 9792,
'uni20E4': 8420,
'uni0473': 1139,
'uni20E1': 8417,
'uni2642': 9794,
'uni03B8': 952,
'uni03B9': 953,
'agrave': 224,
'uni03B4': 948,
'uni03B5': 949,
'uni03B6': 950,
'uni03B7': 951,
'uni03B0': 944,
'uni03B1': 945,
'uni03B2': 946,
'uni03B3': 947,
'uni2555': 9557,
'Adieresis': 196,
'germandbls': 223,
'Odieresis': 214,
'space': 32,
'uni0126': 294,
'uni0127': 295,
'uni0124': 292,
'uni0125': 293,
'uni0122': 290,
'uni0123': 291,
'uni0120': 288,
'uni0121': 289,
'quoteright': 8217,
'uni2560': 9568,
'uni2556': 9558,
'ucircumflex': 251,
'uni2561': 9569,
'uni2551': 9553,
'uni25B2': 9650,
'uni2550': 9552,
'uni2563': 9571,
'uni2553': 9555,
'G': 71,
'uni2564': 9572,
'uni2552': 9554,
'quoteleft': 8216,
'uni2565': 9573,
'uni2572': 9586,
'uni2568': 9576,
'uni2566': 9574,
'W': 87,
'uni214A': 8522,
'uni012F': 303,
'uni012D': 301,
'uni012E': 302,
'uni012B': 299,
'uni012C': 300,
'uni255C': 9564,
'uni012A': 298,
'uni2289': 8841,
'Q': 81,
'uni2320': 8992,
'uni2321': 8993,
'g': 103,
'uni03BD': 957,
'uni03BE': 958,
'uni03BF': 959,
'uni2282': 8834,
'uni2285': 8837,
'uni03BA': 954,
'uni03BB': 955,
'uni03BC': 956,
'uni2128': 8488,
'uni25B7': 9655,
'w': 119,
'uni0302': 770,
'uni03DE': 990,
'uni25DA': 9690,
'uni0303': 771,
'uni0463': 1123,
'uni0462': 1122,
'uni3018': 12312,
'uni2514': 9492,
'question': 63,
'uni25B3': 9651,
'uni24E1': 9441,
'one': 49,
'uni200A': 8202,
'uni2278': 8824,
'ring': 730,
'uni0195': 405,
'figuredash': 8210,
'uni22EC': 8940,
'uni0339': 825,
'uni0338': 824,
'uni0337': 823,
'uni0336': 822,
'uni0335': 821,
'uni0333': 819,
'uni0332': 818,
'uni0331': 817,
'uni0330': 816,
'uni01C1': 449,
'uni01C0': 448,
'uni01C3': 451,
'uni01C2': 450,
'uni2353': 9043,
'uni0308': 776,
'uni2218': 8728,
'uni2219': 8729,
'uni2216': 8726,
'uni2217': 8727,
'uni2214': 8724,
'uni0309': 777,
'uni2609': 9737,
'uni2213': 8723,
'uni2210': 8720,
'uni2211': 8721,
'uni2245': 8773,
'B': 66,
'uni25D6': 9686,
'iacute': 237,
'uni02E6': 742,
'uni02E7': 743,
'uni02E8': 744,
'uni02E9': 745,
'uni221D': 8733,
'uni221E': 8734,
'Ydieresis': 376,
'uni221C': 8732,
'uni22D7': 8919,
'uni221A': 8730,
'R': 82,
'uni24DC': 9436,
'uni033F': 831,
'uni033E': 830,
'uni033C': 828,
'uni033B': 827,
'uni033A': 826,
'b': 98,
'uni228A': 8842,
'uni22DB': 8923,
'uni2554': 9556,
'uni046B': 1131,
'uni046A': 1130,
'r': 114,
'uni24DB': 9435,
'Ccedilla': 199,
'minus': 8722,
'uni24DA': 9434,
'uni03F0': 1008,
'uni03F1': 1009,
'uni20AC': 8364,
'uni2276': 8822,
'uni24C0': 9408,
'uni0162': 354,
'uni0163': 355,
'uni011E': 286,
'uni011D': 285,
'uni011C': 284,
'uni011B': 283,
'uni0164': 356,
'uni0165': 357,
'Lslash': 321,
'uni0168': 360,
'uni0169': 361,
'uni25C9': 9673,
'uni02E5': 741,
'uni21C3': 8643,
'uni24C4': 9412,
'uni24E2': 9442,
'uni2277': 8823,
'uni013A': 314,
'uni2102': 8450,
'Uacute': 218,
'uni2317': 8983,
'uni2107': 8455,
'uni221F': 8735,
'yacute': 253,
'uni3012': 12306,
'Ucircumflex': 219,
'uni015D': 349,
'quotedbl': 34,
'uni25D9': 9689,
'uni2280': 8832,
'uni22AF': 8879,
'onehalf': 189,
'uni221B': 8731,
'Thorn': 222,
'uni2226': 8742,
'M': 77,
'uni25BA': 9658,
'uni2463': 9315,
'uni2336': 9014,
'eight': 56,
'uni2236': 8758,
'multiply': 215,
'uni210C': 8460,
'uni210A': 8458,
'uni21C9': 8649,
'grave': 96,
'uni210E': 8462,
'uni0117': 279,
'uni016C': 364,
'uni0115': 277,
'uni016A': 362,
'uni016F': 367,
'uni0112': 274,
'uni016D': 365,
'uni016E': 366,
'Ocircumflex': 212,
'uni2305': 8965,
'm': 109,
'uni24DF': 9439,
'uni0119': 281,
'uni0118': 280,
'uni20A3': 8355,
'uni20A4': 8356,
'uni20A7': 8359,
'uni2288': 8840,
'uni24C3': 9411,
'uni251C': 9500,
'uni228D': 8845,
'uni222F': 8751,
'uni222E': 8750,
'uni222D': 8749,
'uni222C': 8748,
'uni222B': 8747,
'uni222A': 8746,
'uni255B': 9563,
'Ugrave': 217,
'uni24DE': 9438,
'guilsinglright': 8250,
'uni250A': 9482,
'Ntilde': 209,
'uni0279': 633,
'questiondown': 191,
'uni256C': 9580,
'Atilde': 195,
'uni0272': 626,
'uni0273': 627,
'uni0270': 624,
'ccedilla': 231,
'uni0276': 630,
'uni0277': 631,
'uni0274': 628,
'uni0275': 629,
'uni2252': 8786,
'uni041F': 1055,
'uni2250': 8784,
'Z': 90,
'uni2256': 8790,
'uni2257': 8791,
'copyright': 169,
'uni2255': 8789,
'uni043D': 1085,
'uni043E': 1086,
'uni043F': 1087,
'yen': 165,
'uni041D': 1053,
'uni043B': 1083,
'uni043C': 1084,
'uni21B0': 8624,
'uni21B1': 8625,
'uni21B2': 8626,
'uni21B3': 8627,
'uni21B4': 8628,
'uni21B5': 8629,
'uni21B6': 8630,
'uni21B7': 8631,
'uni21B8': 8632,
'Eacute': 201,
'uni2311': 8977,
'uni2310': 8976,
'uni228F': 8847,
'uni25DB': 9691,
'uni21BA': 8634,
'uni21BB': 8635,
'uni21BC': 8636,
'uni2017': 8215,
'uni21BE': 8638,
'uni21BF': 8639,
'uni231C': 8988,
'H': 72,
'uni0293': 659,
'uni2202': 8706,
'uni22A4': 8868,
'uni231E': 8990,
'uni2232': 8754,
'uni225B': 8795,
'uni225C': 8796,
'uni24D9': 9433,
'uni225A': 8794,
'uni0438': 1080,
'uni0439': 1081,
'uni225D': 8797,
'uni225E': 8798,
'uni0434': 1076,
'X': 88,
'uni007F': 127,
'uni0437': 1079,
'Idieresis': 207,
'uni0431': 1073,
'uni0432': 1074,
'uni0433': 1075,
'uni22AC': 8876,
'uni22CD': 8909,
'uni25A3': 9635,
'bar': 124,
'uni24BB': 9403,
'uni037E': 894,
'uni027B': 635,
'h': 104,
'uni027A': 634,
'uni027F': 639,
'uni027D': 637,
'uni027E': 638,
'uni2227': 8743,
'uni2004': 8196,
'uni2225': 8741,
'uni2224': 8740,
'uni2223': 8739,
'uni2222': 8738,
'uni2221': 8737,
'uni2220': 8736,
'x': 120,
'uni2323': 8995,
'uni2559': 9561,
'uni2558': 9560,
'uni2229': 8745,
'uni2228': 8744,
'udieresis': 252,
'uni029D': 669,
'ordfeminine': 170,
'uni22CB': 8907,
'uni233D': 9021,
'uni0428': 1064,
'uni24C6': 9414,
'uni22DD': 8925,
'uni24C7': 9415,
'uni015C': 348,
'uni015B': 347,
'uni015A': 346,
'uni22AA': 8874,
'uni015F': 351,
'uni015E': 350,
'braceleft': 123,
'uni24C5': 9413,
'uni0410': 1040,
'uni03AA': 938,
'uni24C2': 9410,
'uni03AC': 940,
'uni03AB': 939,
'macron': 175,
'uni03AD': 941,
'uni03AF': 943,
'uni0294': 660,
'uni0295': 661,
'uni0296': 662,
'uni0297': 663,
'uni0290': 656,
'uni0291': 657,
'uni0292': 658,
'atilde': 227,
'Acircumflex': 194,
'uni2370': 9072,
'uni24C1': 9409,
'uni0298': 664,
'uni0299': 665,
'Oslash': 216,
'uni029E': 670,
'C': 67,
'quotedblleft': 8220,
'uni029B': 667,
'uni029C': 668,
'uni03A9': 937,
'uni03A8': 936,
'S': 83,
'uni24C9': 9417,
'uni03A1': 929,
'uni03A0': 928,
'exclam': 33,
'uni03A5': 933,
'uni03A4': 932,
'uni03A7': 935,
'Zcaron': 381,
'uni2133': 8499,
'uni2132': 8498,
'uni0159': 345,
'uni0158': 344,
'uni2137': 8503,
'uni2005': 8197,
'uni2135': 8501,
'uni2134': 8500,
'uni02BA': 698,
'uni2033': 8243,
'uni0151': 337,
'uni0150': 336,
'uni0157': 343,
'equal': 61,
'uni0155': 341,
'uni0154': 340,
's': 115,
'uni233F': 9023,
'eth': 240,
'uni24BE': 9406,
'uni21E9': 8681,
'uni2060': 8288,
'Egrave': 200,
'uni255D': 9565,
'uni24CD': 9421,
'uni21E1': 8673,
'uni21B9': 8633,
'hyphen': 45,
'uni01BE': 446,
'uni01BB': 443,
'period': 46,
'igrave': 236,
'uni01BA': 442,
'uni2296': 8854,
'uni2297': 8855,
'uni2294': 8852,
'uni2295': 8853,
'colon': 58,
'uni2293': 8851,
'uni2290': 8848,
'uni2291': 8849,
'uni032D': 813,
'uni032E': 814,
'uni032F': 815,
'uni032A': 810,
'uni032B': 811,
'uni032C': 812,
'uni231D': 8989,
'Ecircumflex': 202,
'uni24D7': 9431,
'uni25DD': 9693,
'trademark': 8482,
'Aacute': 193,
'cent': 162,
'uni0445': 1093,
'uni266E': 9838,
'uni266D': 9837,
'uni266B': 9835,
'uni03C9': 969,
'uni2003': 8195,
'uni2047': 8263,
'lslash': 322,
'uni03A6': 934,
'uni2043': 8259,
'uni250C': 9484,
'uni2040': 8256,
'uni255F': 9567,
'uni24CB': 9419,
'uni0472': 1138,
'uni0446': 1094,
'uni0474': 1140,
'uni0475': 1141,
'uni2508': 9480,
'uni2660': 9824,
'uni2506': 9478,
'uni2502': 9474,
'c': 99,
'uni2500': 9472,
'N': 78,
'uni22A6': 8870,
'uni21E7': 8679,
'uni2130': 8496,
'uni2002': 8194,
'breve': 728,
'uni0442': 1090,
'Oacute': 211,
'uni229F': 8863,
'uni25C7': 9671,
'uni229D': 8861,
'uni229E': 8862,
'guillemotleft': 171,
'uni0329': 809,
'uni24E5': 9445,
'uni011F': 287,
'uni0324': 804,
'uni0325': 805,
'uni0326': 806,
'uni0327': 807,
'uni0321': 801,
'uni0322': 802,
'n': 110,
'uni2032': 8242,
'uni2269': 8809,
'uni2268': 8808,
'uni0306': 774,
'uni226B': 8811,
'uni21EA': 8682,
'uni0166': 358,
'uni203B': 8251,
'uni01B5': 437,
'idieresis': 239,
'uni02BC': 700,
'uni01B0': 432,
'braceright': 125,
'seven': 55,
'uni02BB': 699,
'uni011A': 282,
'uni29FB': 10747,
'brokenbar': 166,
'uni2036': 8246,
'uni25C0': 9664,
'uni0156': 342,
'uni22D5': 8917,
'uni0258': 600,
'ugrave': 249,
'uni22D6': 8918,
'uni22D1': 8913,
'uni2034': 8244,
'uni22D3': 8915,
'uni22D2': 8914,
'uni203C': 8252,
'uni223E': 8766,
'uni02BF': 703,
'uni22D9': 8921,
'uni22D8': 8920,
'uni25BD': 9661,
'uni25BE': 9662,
'uni25BF': 9663,
'uni041B': 1051,
'periodcentered': 183,
'uni25BC': 9660,
'uni019E': 414,
'uni019B': 411,
'uni019A': 410,
'uni2007': 8199,
'uni0391': 913,
'uni0390': 912,
'uni0393': 915,
'uni0392': 914,
'uni0395': 917,
'uni0394': 916,
'uni0397': 919,
'uni0396': 918,
'uni0399': 921,
'uni0398': 920,
'uni25C8': 9672,
'uni2468': 9320,
'sterling': 163,
'uni22EB': 8939,
'uni039C': 924,
'uni039B': 923,
'uni039E': 926,
'uni039D': 925,
'uni039F': 927,
'I': 73,
'uni03E1': 993,
'uni03E0': 992,
'uni2319': 8985,
'uni228B': 8843,
'uni25B5': 9653,
'uni25B6': 9654,
'uni22EA': 8938,
'uni24B9': 9401,
'uni044E': 1102,
'uni0199': 409,
'uni2266': 8806,
'Y': 89,
'uni22A2': 8866,
'Eth': 208,
'uni266F': 9839,
'emdash': 8212,
'uni263B': 9787,
'uni24BD': 9405,
'uni22DE': 8926,
'uni0360': 864,
'uni2557': 9559,
'uni22DF': 8927,
'uni22DA': 8922,
'uni22DC': 8924,
'uni0361': 865,
'i': 105,
'uni24BF': 9407,
'uni0362': 866,
'uni263E': 9790,
'uni028D': 653,
'uni2259': 8793,
'uni0323': 803,
'uni2265': 8805,
'daggerdbl': 8225,
'y': 121,
'uni010A': 266,
'plusminus': 177,
'less': 60,
'uni21AE': 8622,
'uni0315': 789,
'uni230B': 8971,
'uni21AF': 8623,
'uni21AA': 8618,
'uni21AC': 8620,
'uni21AB': 8619,
'uni01FB': 507,
'uni01FC': 508,
'uni223A': 8762,
'uni01FA': 506,
'uni01FF': 511,
'uni01FD': 509,
'uni01FE': 510,
'uni2567': 9575,
'uni25E0': 9696,
'uni0104': 260,
'uni0105': 261,
'uni0106': 262,
'uni0107': 263,
'uni0100': 256,
'uni0101': 257,
'uni0102': 258,
'uni0103': 259,
'uni2038': 8248,
'uni2009': 8201,
'uni2008': 8200,
'uni0108': 264,
'uni0109': 265,
'uni02A1': 673,
'uni223B': 8763,
'uni226C': 8812,
'uni25AC': 9644,
'uni24D3': 9427,
'uni21E0': 8672,
'uni21E3': 8675,
'Udieresis': 220,
'uni21E2': 8674,
'D': 68,
'uni21E5': 8677,
'uni2621': 9761,
'uni21D1': 8657,
'uni203E': 8254,
'uni22C6': 8902,
'uni21E4': 8676,
'uni010D': 269,
'uni010E': 270,
'uni010F': 271,
'five': 53,
'T': 84,
'uni010B': 267,
'uni010C': 268,
'uni2605': 9733,
'uni2663': 9827,
'uni21E6': 8678,
'uni24B6': 9398,
'uni22C1': 8897,
'oslash': 248,
'acute': 180,
'uni01F0': 496,
'd': 100,
'OE': 338,
'uni22E3': 8931,
'Igrave': 204,
'uni2308': 8968,
'uni2309': 8969,
'uni21A9': 8617,
't': 116,
'uni2313': 8979,
'uni03A3': 931,
'uni21A4': 8612,
'uni21A7': 8615,
'uni21A6': 8614,
'uni21A1': 8609,
'uni21A0': 8608,
'uni21A3': 8611,
'uni21A2': 8610,
'parenright': 41,
'uni256A': 9578,
'uni25DC': 9692,
'uni24CE': 9422,
'uni042C': 1068,
'uni24E0': 9440,
'uni042B': 1067,
'uni0409': 1033,
'uni0408': 1032,
'uni24E7': 9447,
'uni25B4': 9652,
'uni042A': 1066,
'uni228E': 8846,
'uni0401': 1025,
'adieresis': 228,
'uni0403': 1027,
'quotesingle': 39,
'uni0405': 1029,
'uni0404': 1028,
'uni0407': 1031,
'uni0406': 1030,
'uni229C': 8860,
'uni2306': 8966,
'uni2253': 8787,
'twodotenleader': 8229,
'uni2131': 8497,
'uni21DA': 8666,
'uni2234': 8756,
'uni2235': 8757,
'uni01A5': 421,
'uni2237': 8759,
'uni2230': 8752,
'uni02CC': 716,
'slash': 47,
'uni01A0': 416,
'ellipsis': 8230,
'uni2299': 8857,
'uni2238': 8760,
'numbersign': 35,
'uni21A8': 8616,
'uni223D': 8765,
'uni01AF': 431,
'uni223F': 8767,
'uni01AD': 429,
'uni01AB': 427,
'odieresis': 246,
'uni223C': 8764,
'uni227D': 8829,
'uni0280': 640,
'O': 79,
'uni227E': 8830,
'uni21A5': 8613,
'uni22D4': 8916,
'uni25D4': 9684,
'uni227F': 8831,
'uni0435': 1077,
'uni2302': 8962,
'uni2669': 9833,
'uni24E3': 9443,
'uni2720': 10016,
'uni22A8': 8872,
'uni22A9': 8873,
'uni040A': 1034,
'uni22A7': 8871,
'oe': 339,
'uni040B': 1035,
'uni040E': 1038,
'uni22A3': 8867,
'o': 111,
'uni040F': 1039,
'Edieresis': 203,
'uni25D5': 9685,
'plus': 43,
'uni044D': 1101,
'uni263C': 9788,
'uni22E6': 8934,
'uni2283': 8835,
'uni258C': 9612,
'uni219E': 8606,
'uni24E4': 9444,
'uni2136': 8502,
'dagger': 8224,
'uni24B7': 9399,
'uni219B': 8603,
'uni22E5': 8933,
'three': 51,
'uni210B': 8459,
'uni2534': 9524,
'uni24B8': 9400,
'uni230A': 8970,
'hungarumlaut': 733,
'parenleft': 40,
'uni0148': 328,
'uni0149': 329,
'uni2124': 8484,
'uni2125': 8485,
'uni2126': 8486,
'uni2127': 8487,
'uni0140': 320,
'uni2129': 8489,
'uni25C5': 9669,
'uni0143': 323,
'uni0144': 324,
'uni0145': 325,
'uni0146': 326,
'uni0147': 327,
'uni210D': 8461,
'fraction': 8260,
'uni2031': 8241,
'uni2196': 8598,
'uni2035': 8245,
'uni24E6': 9446,
'uni016B': 363,
'uni24BA': 9402,
'uni266A': 9834,
'uni0116': 278,
'uni2115': 8469,
'registered': 174,
'J': 74,
'uni25DF': 9695,
'uni25CE': 9678,
'uni273D': 10045,
'dieresis': 168,
'uni212B': 8491,
'uni0114': 276,
'uni212D': 8493,
'uni212E': 8494,
'uni212F': 8495,
'uni014A': 330,
'uni014B': 331,
'uni014C': 332,
'uni014D': 333,
'uni014E': 334,
'uni014F': 335,
'uni025E': 606,
'uni24E8': 9448,
'uni0111': 273,
'uni24E9': 9449,
'Ograve': 210,
'j': 106,
'uni2195': 8597,
'uni2194': 8596,
'uni2197': 8599,
'uni2037': 8247,
'uni2191': 8593,
'uni2190': 8592,
'uni2193': 8595,
'uni2192': 8594,
'uni29FA': 10746,
'uni2713': 10003,
'z': 122,
'uni2199': 8601,
'uni2198': 8600,
'uni2667': 9831,
'ae': 230,
'uni0448': 1096,
'semicolon': 59,
'uni2666': 9830,
'uni038F': 911,
'uni0444': 1092,
'uni0447': 1095,
'uni038E': 910,
'uni0441': 1089,
'uni038C': 908,
'uni0443': 1091,
'uni038A': 906,
'uni0250': 592,
'uni0251': 593,
'uni0252': 594,
'uni0253': 595,
'uni0254': 596,
'at': 64,
'uni0256': 598,
'uni0257': 599,
'uni0167': 359,
'uni0259': 601,
'uni228C': 8844,
'uni2662': 9826,
'uni0319': 793,
'uni0318': 792,
'uni24BC': 9404,
'uni0402': 1026,
'uni22EF': 8943,
'Iacute': 205,
'uni22ED': 8941,
'uni22EE': 8942,
'uni0311': 785,
'uni0310': 784,
'uni21E8': 8680,
'uni0312': 786,
'percent': 37,
'uni0317': 791,
'uni0316': 790,
'uni21D6': 8662,
'uni21D7': 8663,
'uni21D4': 8660,
'uni21D5': 8661,
'uni21D2': 8658,
'uni21D3': 8659,
'uni21D0': 8656,
'uni2138': 8504,
'uni2270': 8816,
'uni2271': 8817,
'uni2272': 8818,
'uni2273': 8819,
'uni2274': 8820,
'uni2275': 8821,
'bracketright': 93,
'uni21D9': 8665,
'uni21DF': 8671,
'uni21DD': 8669,
'uni21DE': 8670,
'AE': 198,
'uni03AE': 942,
'uni227A': 8826,
'uni227B': 8827,
'uni227C': 8828,
'asterisk': 42,
'aacute': 225,
'uni226F': 8815,
'uni22E2': 8930,
'uni0386': 902,
'uni22E0': 8928,
'uni22E1': 8929,
'U': 85,
'uni22E7': 8935,
'uni22E4': 8932,
'uni0387': 903,
'uni031A': 794,
'eacute': 233,
'uni22E8': 8936,
'uni22E9': 8937,
'uni24D8': 9432,
'uni025A': 602,
'uni025B': 603,
'uni025C': 604,
'e': 101,
'uni0128': 296,
'uni025F': 607,
'uni2665': 9829,
'thorn': 254,
'uni0129': 297,
'uni253C': 9532,
'uni25D7': 9687,
'u': 117,
'uni0388': 904,
'uni0389': 905,
'uni0255': 597,
'uni0171': 369,
'uni0384': 900,
'uni0385': 901,
'uni044A': 1098,
'uni252C': 9516,
'uni044C': 1100,
'uni044B': 1099}
uni2type1 = dict([(v,k) for k,v in type12uni.items()])
tex2uni = {
'widehat': 0x0302,
'widetilde': 0x0303,
'langle': 0x27e8,
'rangle': 0x27e9,
'perp': 0x27c2,
'neq': 0x2260,
'Join': 0x2a1d,
'leqslant': 0x2a7d,
'geqslant': 0x2a7e,
'lessapprox': 0x2a85,
'gtrapprox': 0x2a86,
'lesseqqgtr': 0x2a8b,
'gtreqqless': 0x2a8c,
'triangleeq': 0x225c,
'eqslantless': 0x2a95,
'eqslantgtr': 0x2a96,
'backepsilon': 0x03f6,
'precapprox': 0x2ab7,
'succapprox': 0x2ab8,
'fallingdotseq': 0x2252,
'subseteqq': 0x2ac5,
'supseteqq': 0x2ac6,
'varpropto': 0x221d,
'precnapprox': 0x2ab9,
'succnapprox': 0x2aba,
'subsetneqq': 0x2acb,
'supsetneqq': 0x2acc,
'lnapprox': 0x2ab9,
'gnapprox': 0x2aba,
'longleftarrow': 0x27f5,
'longrightarrow': 0x27f6,
'longleftrightarrow': 0x27f7,
'Longleftarrow': 0x27f8,
'Longrightarrow': 0x27f9,
'Longleftrightarrow': 0x27fa,
'longmapsto': 0x27fc,
'leadsto': 0x21dd,
'dashleftarrow': 0x290e,
'dashrightarrow': 0x290f,
'circlearrowleft': 0x21ba,
'circlearrowright': 0x21bb,
'leftrightsquigarrow': 0x21ad,
'leftsquigarrow': 0x219c,
'rightsquigarrow': 0x219d,
'Game': 0x2141,
'hbar': 0x0127,
'hslash': 0x210f,
'ldots': 0x22ef,
'vdots': 0x22ee,
'doteqdot': 0x2251,
'doteq': 8784,
'partial': 8706,
'gg': 8811,
'asymp': 8781,
'blacktriangledown': 9662,
'otimes': 8855,
'nearrow': 8599,
'varpi': 982,
'vee': 8744,
'vec': 8407,
'smile': 8995,
'succnsim': 8937,
'gimel': 8503,
'vert': 124,
'|': 124,
'varrho': 1009,
'P': 182,
'approxident': 8779,
'Swarrow': 8665,
'textasciicircum': 94,
'imageof': 8887,
'ntriangleleft': 8938,
'nleq': 8816,
'div': 247,
'nparallel': 8742,
'Leftarrow': 8656,
'lll': 8920,
'oiint': 8751,
'ngeq': 8817,
'Theta': 920,
'origof': 8886,
'blacksquare': 9632,
'solbar': 9023,
'neg': 172,
'sum': 8721,
'Vdash': 8873,
'coloneq': 8788,
'degree': 176,
'bowtie': 8904,
'blacktriangleright': 9654,
'varsigma': 962,
'leq': 8804,
'ggg': 8921,
'lneqq': 8808,
'scurel': 8881,
'stareq': 8795,
'BbbN': 8469,
'nLeftarrow': 8653,
'nLeftrightarrow': 8654,
'k': 808,
'bot': 8869,
'BbbC': 8450,
'Lsh': 8624,
'leftleftarrows': 8647,
'BbbZ': 8484,
'digamma': 989,
'BbbR': 8477,
'BbbP': 8473,
'BbbQ': 8474,
'vartriangleright': 8883,
'succsim': 8831,
'wedge': 8743,
'lessgtr': 8822,
'veebar': 8891,
'mapsdown': 8615,
'Rsh': 8625,
'chi': 967,
'prec': 8826,
'nsubseteq': 8840,
'therefore': 8756,
'eqcirc': 8790,
'textexclamdown': 161,
'nRightarrow': 8655,
'flat': 9837,
'notin': 8713,
'llcorner': 8990,
'varepsilon': 949,
'bigtriangleup': 9651,
'aleph': 8501,
'dotminus': 8760,
'upsilon': 965,
'Lambda': 923,
'cap': 8745,
'barleftarrow': 8676,
'mu': 956,
'boxplus': 8862,
'mp': 8723,
'circledast': 8859,
'tau': 964,
'in': 8712,
'backslash': 92,
'varnothing': 8709,
'sharp': 9839,
'eqsim': 8770,
'gnsim': 8935,
'Searrow': 8664,
'updownarrows': 8645,
'heartsuit': 9825,
'trianglelefteq': 8884,
'ddag': 8225,
'sqsubseteq': 8849,
'mapsfrom': 8612,
'boxbar': 9707,
'sim': 8764,
'Nwarrow': 8662,
'nequiv': 8802,
'succ': 8827,
'vdash': 8866,
'Leftrightarrow': 8660,
'parallel': 8741,
'invnot': 8976,
'natural': 9838,
'ss': 223,
'uparrow': 8593,
'nsim': 8769,
'hookrightarrow': 8618,
'Equiv': 8803,
'approx': 8776,
'Vvdash': 8874,
'nsucc': 8833,
'leftrightharpoons': 8651,
'Re': 8476,
'boxminus': 8863,
'equiv': 8801,
'Lleftarrow': 8666,
'thinspace': 8201,
'll': 8810,
'Cup': 8915,
'measeq': 8798,
'upharpoonleft': 8639,
'lq': 8216,
'Upsilon': 933,
'subsetneq': 8842,
'greater': 62,
'supsetneq': 8843,
'Cap': 8914,
'L': 321,
'spadesuit': 9824,
'lrcorner': 8991,
'not': 824,
'bar': 772,
'rightharpoonaccent': 8401,
'boxdot': 8865,
'l': 322,
'leftharpoondown': 8637,
'bigcup': 8899,
'iint': 8748,
'bigwedge': 8896,
'downharpoonleft': 8643,
'textasciitilde': 126,
'subset': 8834,
'leqq': 8806,
'mapsup': 8613,
'nvDash': 8877,
'looparrowleft': 8619,
'nless': 8814,
'rightarrowbar': 8677,
'Vert': 8214,
'downdownarrows': 8650,
'uplus': 8846,
'simeq': 8771,
'napprox': 8777,
'ast': 8727,
'twoheaduparrow': 8607,
'doublebarwedge': 8966,
'Sigma': 931,
'leftharpoonaccent': 8400,
'ntrianglelefteq': 8940,
'nexists': 8708,
'times': 215,
'measuredangle': 8737,
'bumpeq': 8783,
'carriagereturn': 8629,
'adots': 8944,
'checkmark': 10003,
'lambda': 955,
'xi': 958,
'rbrace': 125,
'rbrack': 93,
'Nearrow': 8663,
'maltese': 10016,
'clubsuit': 9827,
'top': 8868,
'overarc': 785,
'varphi': 966,
'Delta': 916,
'iota': 953,
'nleftarrow': 8602,
'candra': 784,
'supset': 8835,
'triangleleft': 9665,
'gtreqless': 8923,
'ntrianglerighteq': 8941,
'quad': 8195,
'Xi': 926,
'gtrdot': 8919,
'leftthreetimes': 8907,
'minus': 8722,
'preccurlyeq': 8828,
'nleftrightarrow': 8622,
'lambdabar': 411,
'blacktriangle': 9652,
'kernelcontraction': 8763,
'Phi': 934,
'angle': 8736,
'spadesuitopen': 9828,
'eqless': 8924,
'mid': 8739,
'varkappa': 1008,
'Ldsh': 8626,
'updownarrow': 8597,
'beta': 946,
'textquotedblleft': 8220,
'rho': 961,
'alpha': 945,
'intercal': 8890,
'beth': 8502,
'grave': 768,
'acwopencirclearrow': 8634,
'nmid': 8740,
'nsupset': 8837,
'sigma': 963,
'dot': 775,
'Rightarrow': 8658,
'turnednot': 8985,
'backsimeq': 8909,
'leftarrowtail': 8610,
'approxeq': 8778,
'curlyeqsucc': 8927,
'rightarrowtail': 8611,
'Psi': 936,
'copyright': 169,
'yen': 165,
'vartriangleleft': 8882,
'rasp': 700,
'triangleright': 9655,
'precsim': 8830,
'infty': 8734,
'geq': 8805,
'updownarrowbar': 8616,
'precnsim': 8936,
'H': 779,
'ulcorner': 8988,
'looparrowright': 8620,
'ncong': 8775,
'downarrow': 8595,
'circeq': 8791,
'subseteq': 8838,
'bigstar': 9733,
'prime': 8242,
'lceil': 8968,
'Rrightarrow': 8667,
'oiiint': 8752,
'curlywedge': 8911,
'vDash': 8872,
'lfloor': 8970,
'ddots': 8945,
'exists': 8707,
'underbar': 817,
'Pi': 928,
'leftrightarrows': 8646,
'sphericalangle': 8738,
'coprod': 8720,
'circledcirc': 8858,
'gtrsim': 8819,
'gneqq': 8809,
'between': 8812,
'theta': 952,
'complement': 8705,
'arceq': 8792,
'nVdash': 8878,
'S': 167,
'wr': 8768,
'wp': 8472,
'backcong': 8780,
'lasp': 701,
'c': 807,
'nabla': 8711,
'dotplus': 8724,
'eta': 951,
'forall': 8704,
'eth': 240,
'colon': 58,
'sqcup': 8852,
'rightrightarrows': 8649,
'sqsupset': 8848,
'mapsto': 8614,
'bigtriangledown': 9661,
'sqsupseteq': 8850,
'propto': 8733,
'pi': 960,
'pm': 177,
'dots': 8230,
'nrightarrow': 8603,
'textasciiacute': 180,
'Doteq': 8785,
'breve': 774,
'sqcap': 8851,
'twoheadrightarrow': 8608,
'kappa': 954,
'vartriangle': 9653,
'diamondsuit': 9826,
'pitchfork': 8916,
'blacktriangleleft': 9664,
'nprec': 8832,
'vdots': 8942,
'curvearrowright': 8631,
'barwedge': 8892,
'multimap': 8888,
'textquestiondown': 191,
'cong': 8773,
'rtimes': 8906,
'rightzigzagarrow': 8669,
'rightarrow': 8594,
'leftarrow': 8592,
'__sqrt__': 8730,
'twoheaddownarrow': 8609,
'oint': 8750,
'bigvee': 8897,
'eqdef': 8797,
'sterling': 163,
'phi': 981,
'Updownarrow': 8661,
'backprime': 8245,
'emdash': 8212,
'Gamma': 915,
'i': 305,
'rceil': 8969,
'leftharpoonup': 8636,
'Im': 8465,
'curvearrowleft': 8630,
'wedgeq': 8793,
'fallingdotseq': 8786,
'curlyeqprec': 8926,
'questeq': 8799,
'less': 60,
'upuparrows': 8648,
'tilde': 771,
'textasciigrave': 96,
'smallsetminus': 8726,
'ell': 8467,
'cup': 8746,
'danger': 9761,
'nVDash': 8879,
'cdotp': 183,
'cdots': 8943,
'hat': 770,
'eqgtr': 8925,
'enspace': 8194,
'psi': 968,
'frown': 8994,
'acute': 769,
'downzigzagarrow': 8623,
'ntriangleright': 8939,
'cupdot': 8845,
'circleddash': 8861,
'oslash': 8856,
'mho': 8487,
'd': 803,
'sqsubset': 8847,
'cdot': 8901,
'Omega': 937,
'OE': 338,
'veeeq': 8794,
'Finv': 8498,
't': 865,
'leftrightarrow': 8596,
'swarrow': 8601,
'rightthreetimes': 8908,
'rightleftharpoons': 8652,
'lesssim': 8818,
'searrow': 8600,
'because': 8757,
'gtrless': 8823,
'star': 8902,
'nsubset': 8836,
'zeta': 950,
'dddot': 8411,
'bigcirc': 9675,
'Supset': 8913,
'circ': 8728,
'slash': 8725,
'ocirc': 778,
'prod': 8719,
'twoheadleftarrow': 8606,
'daleth': 8504,
'upharpoonright': 8638,
'odot': 8857,
'Uparrow': 8657,
'O': 216,
'hookleftarrow': 8617,
'trianglerighteq': 8885,
'nsime': 8772,
'oe': 339,
'nwarrow': 8598,
'o': 248,
'ddddot': 8412,
'downharpoonright': 8642,
'succcurlyeq': 8829,
'gamma': 947,
'scrR': 8475,
'dag': 8224,
'thickspace': 8197,
'frakZ': 8488,
'lessdot': 8918,
'triangledown': 9663,
'ltimes': 8905,
'scrB': 8492,
'endash': 8211,
'scrE': 8496,
'scrF': 8497,
'scrH': 8459,
'scrI': 8464,
'rightharpoondown': 8641,
'scrL': 8466,
'scrM': 8499,
'frakC': 8493,
'nsupseteq': 8841,
'circledR': 174,
'circledS': 9416,
'ngtr': 8815,
'bigcap': 8898,
'scre': 8495,
'Downarrow': 8659,
'scrg': 8458,
'overleftrightarrow': 8417,
'scro': 8500,
'lnsim': 8934,
'eqcolon': 8789,
'curlyvee': 8910,
'urcorner': 8989,
'lbrace': 123,
'Bumpeq': 8782,
'delta': 948,
'boxtimes': 8864,
'overleftarrow': 8406,
'prurel': 8880,
'clubsuitopen': 9831,
'cwopencirclearrow': 8635,
'geqq': 8807,
'rightleftarrows': 8644,
'ac': 8766,
'ae': 230,
'int': 8747,
'rfloor': 8971,
'risingdotseq': 8787,
'nvdash': 8876,
'diamond': 8900,
'ddot': 776,
'backsim': 8765,
'oplus': 8853,
'triangleq': 8796,
'check': 780,
'ni': 8715,
'iiint': 8749,
'ne': 8800,
'lesseqgtr': 8922,
'obar': 9021,
'supseteq': 8839,
'nu': 957,
'AA': 8491,
'AE': 198,
'models': 8871,
'ominus': 8854,
'dashv': 8867,
'omega': 969,
'rq': 8217,
'Subset': 8912,
'rightharpoonup': 8640,
'Rdsh': 8627,
'bullet': 8729,
'divideontimes': 8903,
'lbrack': 91,
'textquotedblright': 8221,
'Colon': 8759,
'%': 37,
'$': 36,
'{': 123,
'}': 125,
'_': 95,
'imath': 0x131,
'circumflexaccent' : 770,
'combiningbreve' : 774,
'combiningoverline' : 772,
'combininggraveaccent' : 768,
'combiningacuteaccent' : 769,
'combiningdiaeresis' : 776,
'combiningtilde' : 771,
'combiningrightarrowabove' : 8407,
'combiningdotabove' : 775,
'to': 8594,
'succeq': 8829,
'emptyset': 8709,
'leftparen': 40,
'rightparen': 41,
'bigoplus': 10753,
'leftangle': 10216,
'rightangle': 10217,
'leftbrace': 124,
'rightbrace': 125,
'jmath': 567,
'bigodot': 10752,
'preceq': 8828,
'biguplus': 10756,
'epsilon': 949,
'vartheta': 977,
'bigotimes': 10754
}
# Each element is a 4-tuple of the form:
# src_start, src_end, dst_font, dst_start
#
stix_virtual_fonts = {
'bb':
{
'rm':
[
(0x0030, 0x0039, 'rm', 0x1d7d8), # 0-9
(0x0041, 0x0042, 'rm', 0x1d538), # A-B
(0x0043, 0x0043, 'rm', 0x2102), # C
(0x0044, 0x0047, 'rm', 0x1d53b), # D-G
(0x0048, 0x0048, 'rm', 0x210d), # H
(0x0049, 0x004d, 'rm', 0x1d540), # I-M
(0x004e, 0x004e, 'rm', 0x2115), # N
(0x004f, 0x004f, 'rm', 0x1d546), # O
(0x0050, 0x0051, 'rm', 0x2119), # P-Q
(0x0052, 0x0052, 'rm', 0x211d), # R
(0x0053, 0x0059, 'rm', 0x1d54a), # S-Y
(0x005a, 0x005a, 'rm', 0x2124), # Z
(0x0061, 0x007a, 'rm', 0x1d552), # a-z
(0x0393, 0x0393, 'rm', 0x213e), # \Gamma
(0x03a0, 0x03a0, 'rm', 0x213f), # \Pi
(0x03a3, 0x03a3, 'rm', 0x2140), # \Sigma
(0x03b3, 0x03b3, 'rm', 0x213d), # \gamma
(0x03c0, 0x03c0, 'rm', 0x213c), # \pi
],
'it':
[
(0x0030, 0x0039, 'rm', 0x1d7d8), # 0-9
(0x0041, 0x0042, 'it', 0xe154), # A-B
(0x0043, 0x0043, 'it', 0x2102), # C (missing in beta STIX fonts)
(0x0044, 0x0044, 'it', 0x2145), # D
(0x0045, 0x0047, 'it', 0xe156), # E-G
(0x0048, 0x0048, 'it', 0x210d), # H (missing in beta STIX fonts)
(0x0049, 0x004d, 'it', 0xe159), # I-M
(0x004e, 0x004e, 'it', 0x2115), # N (missing in beta STIX fonts)
(0x004f, 0x004f, 'it', 0xe15e), # O
(0x0050, 0x0051, 'it', 0x2119), # P-Q (missing in beta STIX fonts)
(0x0052, 0x0052, 'it', 0x211d), # R (missing in beta STIX fonts)
(0x0053, 0x0059, 'it', 0xe15f), # S-Y
(0x005a, 0x005a, 'it', 0x2124), # Z (missing in beta STIX fonts)
(0x0061, 0x0063, 'it', 0xe166), # a-c
(0x0064, 0x0065, 'it', 0x2146), # d-e
(0x0066, 0x0068, 'it', 0xe169), # f-h
(0x0069, 0x006a, 'it', 0x2148), # i-j
(0x006b, 0x007a, 'it', 0xe16c), # k-z
(0x0393, 0x0393, 'it', 0x213e), # \Gamma (missing in beta STIX fonts)
(0x03a0, 0x03a0, 'it', 0x213f), # \Pi
(0x03a3, 0x03a3, 'it', 0x2140), # \Sigma (missing in beta STIX fonts)
(0x03b3, 0x03b3, 'it', 0x213d), # \gamma (missing in beta STIX fonts)
(0x03c0, 0x03c0, 'it', 0x213c), # \pi
],
'bf':
[
(0x0030, 0x0039, 'rm', 0x1d7d8), # 0-9
(0x0041, 0x005a, 'bf', 0xe38a), # A-Z
(0x0061, 0x007a, 'bf', 0xe39d), # a-z
(0x0393, 0x0393, 'bf', 0x213e), # \Gamma
(0x03a0, 0x03a0, 'bf', 0x213f), # \Pi
(0x03a3, 0x03a3, 'bf', 0x2140), # \Sigma
(0x03b3, 0x03b3, 'bf', 0x213d), # \gamma
(0x03c0, 0x03c0, 'bf', 0x213c), # \pi
],
},
'cal':
[
(0x0041, 0x005a, 'it', 0xe22d), # A-Z
],
'circled':
{
'rm':
[
(0x0030, 0x0030, 'rm', 0x24ea), # 0
(0x0031, 0x0039, 'rm', 0x2460), # 1-9
(0x0041, 0x005a, 'rm', 0x24b6), # A-Z
(0x0061, 0x007a, 'rm', 0x24d0) # a-z
],
'it':
[
(0x0030, 0x0030, 'rm', 0x24ea), # 0
(0x0031, 0x0039, 'rm', 0x2460), # 1-9
(0x0041, 0x005a, 'it', 0x24b6), # A-Z
(0x0061, 0x007a, 'it', 0x24d0) # a-z
],
'bf':
[
(0x0030, 0x0030, 'bf', 0x24ea), # 0
(0x0031, 0x0039, 'bf', 0x2460), # 1-9
(0x0041, 0x005a, 'bf', 0x24b6), # A-Z
(0x0061, 0x007a, 'bf', 0x24d0) # a-z
],
},
'frak':
{
'rm':
[
(0x0041, 0x0042, 'rm', 0x1d504), # A-B
(0x0043, 0x0043, 'rm', 0x212d), # C
(0x0044, 0x0047, 'rm', 0x1d507), # D-G
(0x0048, 0x0048, 'rm', 0x210c), # H
(0x0049, 0x0049, 'rm', 0x2111), # I
(0x004a, 0x0051, 'rm', 0x1d50d), # J-Q
(0x0052, 0x0052, 'rm', 0x211c), # R
(0x0053, 0x0059, 'rm', 0x1d516), # S-Y
(0x005a, 0x005a, 'rm', 0x2128), # Z
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
],
'it':
[
(0x0041, 0x0042, 'rm', 0x1d504), # A-B
(0x0043, 0x0043, 'rm', 0x212d), # C
(0x0044, 0x0047, 'rm', 0x1d507), # D-G
(0x0048, 0x0048, 'rm', 0x210c), # H
(0x0049, 0x0049, 'rm', 0x2111), # I
(0x004a, 0x0051, 'rm', 0x1d50d), # J-Q
(0x0052, 0x0052, 'rm', 0x211c), # R
(0x0053, 0x0059, 'rm', 0x1d516), # S-Y
(0x005a, 0x005a, 'rm', 0x2128), # Z
(0x0061, 0x007a, 'rm', 0x1d51e), # a-z
],
'bf':
[
(0x0041, 0x005a, 'bf', 0x1d56c), # A-Z
(0x0061, 0x007a, 'bf', 0x1d586), # a-z
],
},
'scr':
[
(0x0041, 0x0041, 'it', 0x1d49c), # A
(0x0042, 0x0042, 'it', 0x212c), # B
(0x0043, 0x0044, 'it', 0x1d49e), # C-D
(0x0045, 0x0046, 'it', 0x2130), # E-F
(0x0047, 0x0047, 'it', 0x1d4a2), # G
(0x0048, 0x0048, 'it', 0x210b), # H
(0x0049, 0x0049, 'it', 0x2110), # I
(0x004a, 0x004b, 'it', 0x1d4a5), # J-K
(0x004c, 0x004c, 'it', 0x2112), # L
(0x004d, 0x003d, 'it', 0x2113), # M
(0x004e, 0x0051, 'it', 0x1d4a9), # N-Q
(0x0052, 0x0052, 'it', 0x211b), # R
(0x0053, 0x005a, 'it', 0x1d4ae), # S-Z
(0x0061, 0x0064, 'it', 0x1d4b6), # a-d
(0x0065, 0x0065, 'it', 0x212f), # e
(0x0066, 0x0066, 'it', 0x1d4bb), # f
(0x0067, 0x0067, 'it', 0x210a), # g
(0x0068, 0x006e, 'it', 0x1d4bd), # h-n
(0x006f, 0x006f, 'it', 0x2134), # o
(0x0070, 0x007a, 'it', 0x1d4c5), # p-z
],
'sf':
{
'rm':
[
(0x0030, 0x0039, 'rm', 0x1d7e2), # 0-9
(0x0041, 0x005a, 'rm', 0x1d5a0), # A-Z
(0x0061, 0x007a, 'rm', 0x1d5ba), # a-z
(0x0391, 0x03a9, 'rm', 0xe17d), # \Alpha-\Omega
(0x03b1, 0x03c9, 'rm', 0xe196), # \alpha-\omega
(0x03d1, 0x03d1, 'rm', 0xe1b0), # theta variant
(0x03d5, 0x03d5, 'rm', 0xe1b1), # phi variant
(0x03d6, 0x03d6, 'rm', 0xe1b3), # pi variant
(0x03f1, 0x03f1, 'rm', 0xe1b2), # rho variant
(0x03f5, 0x03f5, 'rm', 0xe1af), # lunate epsilon
(0x2202, 0x2202, 'rm', 0xe17c), # partial differential
],
'it':
[
# These numerals are actually upright. We don't actually
# want italic numerals ever.
(0x0030, 0x0039, 'rm', 0x1d7e2), # 0-9
(0x0041, 0x005a, 'it', 0x1d608), # A-Z
(0x0061, 0x007a, 'it', 0x1d622), # a-z
(0x0391, 0x03a9, 'rm', 0xe17d), # \Alpha-\Omega
(0x03b1, 0x03c9, 'it', 0xe1d8), # \alpha-\omega
(0x03d1, 0x03d1, 'it', 0xe1f2), # theta variant
(0x03d5, 0x03d5, 'it', 0xe1f3), # phi variant
(0x03d6, 0x03d6, 'it', 0xe1f5), # pi variant
(0x03f1, 0x03f1, 'it', 0xe1f4), # rho variant
(0x03f5, 0x03f5, 'it', 0xe1f1), # lunate epsilon
],
'bf':
[
(0x0030, 0x0039, 'bf', 0x1d7ec), # 0-9
(0x0041, 0x005a, 'bf', 0x1d5d4), # A-Z
(0x0061, 0x007a, 'bf', 0x1d5ee), # a-z
(0x0391, 0x03a9, 'bf', 0x1d756), # \Alpha-\Omega
(0x03b1, 0x03c9, 'bf', 0x1d770), # \alpha-\omega
(0x03d1, 0x03d1, 'bf', 0x1d78b), # theta variant
(0x03d5, 0x03d5, 'bf', 0x1d78d), # phi variant
(0x03d6, 0x03d6, 'bf', 0x1d78f), # pi variant
(0x03f0, 0x03f0, 'bf', 0x1d78c), # kappa variant
(0x03f1, 0x03f1, 'bf', 0x1d78e), # rho variant
(0x03f5, 0x03f5, 'bf', 0x1d78a), # lunate epsilon
(0x2202, 0x2202, 'bf', 0x1d789), # partial differential
(0x2207, 0x2207, 'bf', 0x1d76f), # \Nabla
],
},
'tt':
[
(0x0030, 0x0039, 'rm', 0x1d7f6), # 0-9
(0x0041, 0x005a, 'rm', 0x1d670), # A-Z
(0x0061, 0x007a, 'rm', 0x1d68a) # a-z
],
}
|
gpl-3.0
|
[
624,
199,
4246,
666,
6716,
367,
2549,
466,
436,
282,
10886,
24189,
818,
11641,
26219,
199,
624,
199,
199,
3,
642,
1211,
9033,
5272,
1561,
370,
5023,
1247,
12,
14165,
1080,
14,
221,
4005,
664,
314,
199,
3,
14165,
1478,
687,
314,
4528,
1233,
12,
1265,
1172,
370,
675,
664,
63,
13391,
199,
624,
199,
504,
8027,
14,
856,
18,
4246,
492,
481,
52,
18,
6986,
199,
4246,
275,
481,
52,
18,
6986,
2336,
2647,
15,
1832,
15,
6251,
15,
16440,
15,
4400,
82,
709,
14,
32264,
358,
199,
1744,
275,
5023,
14,
362,
63,
13391,
1252,
1744,
342,
199,
1744,
14,
3191,
342,
199,
199,
509,
1495,
600,
12,
14165,
688,
315,
2974,
26,
272,
870,
1495,
600,
12,
14165,
688,
199,
624,
199,
199,
7572,
63,
475,
63,
66,
23564,
391,
275,
469,
272,
519,
1154,
79,
442,
7,
4483,
520,
661,
67,
278,
88,
709,
297,
221,
10416,
395,
272,
519,
1154,
5076,
364,
357,
7,
3777,
520,
661,
67,
278,
88,
709,
297,
221,
5238,
395,
272,
519,
1154,
5076,
411,
24879,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
12766,
395,
272,
519,
1154,
5076,
79,
4508,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
8155,
395,
272,
519,
1154,
1838,
7,
463,
520,
661,
67,
278,
88,
709,
297,
221,
8026,
395,
272,
519,
1154,
8788,
7,
4483,
520,
661,
67,
278,
88,
709,
297,
221,
5504,
395,
272,
519,
1154,
442,
7,
463,
520,
661,
67,
278,
88,
709,
297,
221,
12001,
395,
272,
519,
1154,
5076,
17500,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
7294,
395,
272,
519,
1154,
5076,
2874,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5212,
395,
272,
519,
1154,
5076,
384,
24879,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
4337,
395,
272,
519,
1154,
5076,
87,
5173,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
257,
841,
395,
272,
519,
1154,
5076,
432,
69,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
6877,
395,
272,
519,
1154,
331,
8788,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5685,
395,
272,
519,
1154,
363,
5079,
12217,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
9615,
395,
272,
519,
1154,
3039,
22359,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
7,
1445,
8540,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
1154,
1445,
7861,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
1154,
1019,
22359,
7,
3515,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
936,
7,
8540,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
1154,
6834,
7861,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
1154,
3039,
4593,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
15997,
395,
272,
519,
1154,
1019,
4593,
7,
3515,
520,
661,
67,
278,
88,
709,
297,
221,
5049,
395,
272,
519,
1154,
4159,
274,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
15997,
395,
272,
519,
1154,
82,
4593,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5049,
395,
272,
519,
1154,
13062,
8554,
7,
3777,
520,
661,
67,
278,
88,
709,
297,
221,
4114,
395,
272,
519,
1154,
13062,
16488,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
14589,
395,
339,
519,
1154,
23524,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
7349,
395,
272,
519,
1154,
3042,
1155,
8746,
7,
3515,
520,
661,
67,
596,
73,
709,
297,
221,
3388,
395,
272,
519,
1154,
1391,
9337,
7,
3322,
520,
661,
67,
596,
73,
709,
297,
221,
6928,
395,
272,
519,
1154,
1391,
10412,
7,
4519,
520,
661,
67,
596,
73,
709,
297,
221,
17017,
395,
272,
519,
1154,
1391,
9412,
7,
3322,
520,
661,
67,
596,
73,
709,
297,
221,
13385,
395,
272,
519,
1154,
1391,
10909,
7,
4519,
520,
661,
67,
596,
73,
709,
297,
257,
1227,
395,
272,
519,
1154,
21491,
273,
285,
555,
265,
384,
7,
755,
520,
661,
67,
596,
73,
709,
297,
24579,
395,
272,
519,
1154,
21491,
273,
285,
555,
265,
2110,
7,
258,
520,
661,
67,
596,
73,
709,
297,
221,
10851,
395,
272,
519,
1154,
31816,
273,
285,
555,
265,
384,
7,
420,
520,
661,
67,
596,
73,
709,
297,
26189,
395,
272,
519,
1154,
31816,
273,
285,
555,
265,
2110,
7,
259,
520,
661,
67,
596,
73,
709,
297,
221,
8375,
395,
272,
519,
1154,
21584,
1019,
7,
755,
520,
661,
67,
596,
73,
709,
297,
21334,
395,
272,
519,
1154,
21584,
3039,
7,
263,
520,
661,
67,
596,
73,
709,
297,
221,
17838,
395,
272,
519,
30484,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
8026,
395,
272,
519,
1673,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
10868,
395,
272,
519,
7601,
7,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
8806,
395,
272,
519,
29957,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
16096,
395,
272,
519,
7,
3524,
8540,
520,
661,
67,
596,
73,
709,
297,
23543,
395,
272,
519,
1154,
7088,
7,
4483,
520,
661,
67,
596,
73,
709,
297,
30542,
395,
272,
519,
1154,
15759,
7,
3777,
520,
661,
67,
596,
73,
709,
297,
221,
9137,
395,
272,
519,
1154,
609,
12868,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
5238,
395,
272,
519,
1154,
3300,
441,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
15997,
395,
272,
519,
1154,
70,
18406,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
13713,
395,
272,
519,
1154,
1697,
7,
463,
520,
661,
67,
596,
73,
709,
297,
12996,
395,
272,
519,
1154,
73,
3442,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
257,
1695,
395,
272,
519,
1154,
74,
3442,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
11738,
395,
272,
519,
1154,
14649,
7,
8295,
520,
661,
67,
596,
73,
709,
297,
221,
4329,
395,
272,
519,
1154,
4468,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
4944,
395,
272,
519,
1154,
5683
] |
[
199,
4246,
666,
6716,
367,
2549,
466,
436,
282,
10886,
24189,
818,
11641,
26219,
199,
624,
199,
199,
3,
642,
1211,
9033,
5272,
1561,
370,
5023,
1247,
12,
14165,
1080,
14,
221,
4005,
664,
314,
199,
3,
14165,
1478,
687,
314,
4528,
1233,
12,
1265,
1172,
370,
675,
664,
63,
13391,
199,
624,
199,
504,
8027,
14,
856,
18,
4246,
492,
481,
52,
18,
6986,
199,
4246,
275,
481,
52,
18,
6986,
2336,
2647,
15,
1832,
15,
6251,
15,
16440,
15,
4400,
82,
709,
14,
32264,
358,
199,
1744,
275,
5023,
14,
362,
63,
13391,
1252,
1744,
342,
199,
1744,
14,
3191,
342,
199,
199,
509,
1495,
600,
12,
14165,
688,
315,
2974,
26,
272,
870,
1495,
600,
12,
14165,
688,
199,
624,
199,
199,
7572,
63,
475,
63,
66,
23564,
391,
275,
469,
272,
519,
1154,
79,
442,
7,
4483,
520,
661,
67,
278,
88,
709,
297,
221,
10416,
395,
272,
519,
1154,
5076,
364,
357,
7,
3777,
520,
661,
67,
278,
88,
709,
297,
221,
5238,
395,
272,
519,
1154,
5076,
411,
24879,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
12766,
395,
272,
519,
1154,
5076,
79,
4508,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
8155,
395,
272,
519,
1154,
1838,
7,
463,
520,
661,
67,
278,
88,
709,
297,
221,
8026,
395,
272,
519,
1154,
8788,
7,
4483,
520,
661,
67,
278,
88,
709,
297,
221,
5504,
395,
272,
519,
1154,
442,
7,
463,
520,
661,
67,
278,
88,
709,
297,
221,
12001,
395,
272,
519,
1154,
5076,
17500,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
7294,
395,
272,
519,
1154,
5076,
2874,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5212,
395,
272,
519,
1154,
5076,
384,
24879,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
4337,
395,
272,
519,
1154,
5076,
87,
5173,
7,
3322,
520,
661,
67,
278,
88,
709,
297,
257,
841,
395,
272,
519,
1154,
5076,
432,
69,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
6877,
395,
272,
519,
1154,
331,
8788,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5685,
395,
272,
519,
1154,
363,
5079,
12217,
3322,
520,
661,
67,
278,
88,
709,
297,
221,
9615,
395,
272,
519,
1154,
3039,
22359,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
7,
1445,
8540,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
1154,
1445,
7861,
520,
661,
67,
278,
88,
709,
297,
221,
20140,
395,
272,
519,
1154,
1019,
22359,
7,
3515,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
936,
7,
8540,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
1154,
6834,
7861,
520,
661,
67,
278,
88,
709,
297,
21334,
395,
272,
519,
1154,
3039,
4593,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
15997,
395,
272,
519,
1154,
1019,
4593,
7,
3515,
520,
661,
67,
278,
88,
709,
297,
221,
5049,
395,
272,
519,
1154,
4159,
274,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
15997,
395,
272,
519,
1154,
82,
4593,
7,
4519,
520,
661,
67,
278,
88,
709,
297,
221,
5049,
395,
272,
519,
1154,
13062,
8554,
7,
3777,
520,
661,
67,
278,
88,
709,
297,
221,
4114,
395,
272,
519,
1154,
13062,
16488,
7,
3698,
520,
661,
67,
278,
88,
709,
297,
221,
14589,
395,
339,
519,
1154,
23524,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
7349,
395,
272,
519,
1154,
3042,
1155,
8746,
7,
3515,
520,
661,
67,
596,
73,
709,
297,
221,
3388,
395,
272,
519,
1154,
1391,
9337,
7,
3322,
520,
661,
67,
596,
73,
709,
297,
221,
6928,
395,
272,
519,
1154,
1391,
10412,
7,
4519,
520,
661,
67,
596,
73,
709,
297,
221,
17017,
395,
272,
519,
1154,
1391,
9412,
7,
3322,
520,
661,
67,
596,
73,
709,
297,
221,
13385,
395,
272,
519,
1154,
1391,
10909,
7,
4519,
520,
661,
67,
596,
73,
709,
297,
257,
1227,
395,
272,
519,
1154,
21491,
273,
285,
555,
265,
384,
7,
755,
520,
661,
67,
596,
73,
709,
297,
24579,
395,
272,
519,
1154,
21491,
273,
285,
555,
265,
2110,
7,
258,
520,
661,
67,
596,
73,
709,
297,
221,
10851,
395,
272,
519,
1154,
31816,
273,
285,
555,
265,
384,
7,
420,
520,
661,
67,
596,
73,
709,
297,
26189,
395,
272,
519,
1154,
31816,
273,
285,
555,
265,
2110,
7,
259,
520,
661,
67,
596,
73,
709,
297,
221,
8375,
395,
272,
519,
1154,
21584,
1019,
7,
755,
520,
661,
67,
596,
73,
709,
297,
21334,
395,
272,
519,
1154,
21584,
3039,
7,
263,
520,
661,
67,
596,
73,
709,
297,
221,
17838,
395,
272,
519,
30484,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
8026,
395,
272,
519,
1673,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
10868,
395,
272,
519,
7601,
7,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
8806,
395,
272,
519,
29957,
8540,
520,
661,
67,
596,
73,
709,
297,
221,
16096,
395,
272,
519,
7,
3524,
8540,
520,
661,
67,
596,
73,
709,
297,
23543,
395,
272,
519,
1154,
7088,
7,
4483,
520,
661,
67,
596,
73,
709,
297,
30542,
395,
272,
519,
1154,
15759,
7,
3777,
520,
661,
67,
596,
73,
709,
297,
221,
9137,
395,
272,
519,
1154,
609,
12868,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
5238,
395,
272,
519,
1154,
3300,
441,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
15997,
395,
272,
519,
1154,
70,
18406,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
13713,
395,
272,
519,
1154,
1697,
7,
463,
520,
661,
67,
596,
73,
709,
297,
12996,
395,
272,
519,
1154,
73,
3442,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
257,
1695,
395,
272,
519,
1154,
74,
3442,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
11738,
395,
272,
519,
1154,
14649,
7,
8295,
520,
661,
67,
596,
73,
709,
297,
221,
4329,
395,
272,
519,
1154,
4468,
7,
5185,
520,
661,
67,
596,
73,
709,
297,
221,
4944,
395,
272,
519,
1154,
5683,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mlperf/training_results_v0.5
|
v0.5.0/google/cloud_v2.8/resnet-tpuv2-8/code/resnet/model/tpu/models/official/retinanet/retinanet_segmentation_model.py
|
5
|
9530
|
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Model defination for the RetinaNet Model for segmentation.
Defines model_fn of RetinaNet for TF Estimator. The model_fn includes RetinaNet
model architecture, loss function, learning rate schedule, and evaluation
procedure.
T.-Y. Lin, P. Goyal, R. Girshick, K. He, and P. Dollar
Focal Loss for Dense Object Detection. arXiv:1708.02002
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import retinanet_architecture
import retinanet_model
def _segmentation_loss(logits, labels, params):
"""Compute segmentation loss. So far it's only for single scale.
Args:
logits: A tensor specifies the logits as returned from model function.
The tensor size is [batch_size, height_l, width_l, num_classes].
The height_l and width_l depends on the min_level feature resolution.
labels: A tensor specifies the groundtruth targets "cls_targets",
as returned from dataloader. The tensor has the same spatial resolution
as input image with size [batch_size, height, width, 1].
params: Dictionary including training parameters specified in
default_hparams function in this file.
Returns:
A float tensor representing total classification loss. The loss is
normalized by the total non-ignored pixels.
"""
# Downsample labels by the min_level feature stride.
stride = 2**params['min_level']
scaled_labels = labels[:, 0::stride, 0::stride]
scaled_labels = tf.cast(scaled_labels, tf.int32)
scaled_labels = scaled_labels[:, :, :, 0]
bit_mask = tf.not_equal(scaled_labels, params['ignore_label'])
# Assign ignore label to background to avoid error when computing
# Cross entropy loss.
scaled_labels = tf.where(bit_mask, scaled_labels,
tf.zeros_like(scaled_labels))
normalizer = tf.reduce_sum(tf.to_float(bit_mask))
cross_entropy_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
labels=scaled_labels, logits=logits)
cross_entropy_loss *= tf.to_float(bit_mask)
loss = tf.reduce_sum(cross_entropy_loss) / normalizer
return loss
def _model_fn(features, labels, mode, params, model, variable_filter_fn=None):
"""Model defination for the RetinaNet model based on ResNet-50.
Args:
features: The input images tensor with shape [batch_size, height, width, 3].
The height and width are fixed and equal.
labels: The input labels in a tensor with the same shape as input images.
mode: The mode of TPUEstimator including TRAIN, EVAL, and PREDICT.
params: The dictionary defines hyperparameters of model. The default
settings are in default_hparams function in this file.
model: The FPN segmentation model outputs class logits.
variable_filter_fn: the filter function that takes trainable_variables and
returns the variable list after applying the filter rule.
Returns:
tpu_spec: the TPUEstimatorSpec to run training, evaluation, or prediction.
"""
def _model_outputs():
return model(
features,
min_level=params['min_level'],
max_level=params['max_level'],
num_classes=params['num_classes'],
resnet_depth=params['resnet_depth'],
is_training_bn=params['is_training_bn'])
if params['use_bfloat16']:
with tf.contrib.tpu.bfloat16_scope():
cls_outputs = _model_outputs()
cls_outputs = tf.cast(cls_outputs, tf.float32)
else:
cls_outputs = _model_outputs()
# First check if it is in PREDICT mode.
if mode == tf.estimator.ModeKeys.PREDICT:
predictions = {
'image': features,
'cls_outputs': cls_outputs
}
return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
# Load pretrained model from checkpoint.
if params['resnet_checkpoint'] and mode == tf.estimator.ModeKeys.TRAIN:
def scaffold_fn():
"""Loads pretrained model through scaffold function."""
tf.train.init_from_checkpoint(params['resnet_checkpoint'], {
'/': 'resnet%s/' % params['resnet_depth'],
})
return tf.train.Scaffold()
else:
scaffold_fn = None
# Set up training loss and learning rate.
retinanet_model.update_learning_rate_schedule_parameters(params)
global_step = tf.train.get_global_step()
learning_rate = retinanet_model.learning_rate_schedule(
params['adjusted_learning_rate'], params['lr_warmup_init'],
params['lr_warmup_step'], params['first_lr_drop_step'],
params['second_lr_drop_step'], global_step)
cls_loss = _segmentation_loss(cls_outputs, labels, params)
weight_decay_loss = params['weight_decay'] * tf.add_n(
[tf.nn.l2_loss(v) for v in tf.trainable_variables()
if 'batch_normalization' not in v.name])
# Add L2 regularization loss
total_loss = cls_loss + weight_decay_loss
if mode == tf.estimator.ModeKeys.TRAIN:
optimizer = tf.train.MomentumOptimizer(
learning_rate, momentum=params['momentum'])
if params['use_tpu']:
optimizer = tf.contrib.tpu.CrossShardOptimizer(optimizer)
# Batch norm requires update_ops to be added as a train_op dependency.
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
var_list = variable_filter_fn(
tf.trainable_variables(),
params['resnet_depth']) if variable_filter_fn else None
with tf.control_dependencies(update_ops):
train_op = optimizer.minimize(total_loss, global_step,
var_list=var_list)
else:
train_op = None
# Evaluation only works on GPU/CPU host and batch_size=1
eval_metrics = None
if mode == tf.estimator.ModeKeys.EVAL:
batch_size = params['batch_size']
def metric_fn(**kwargs):
"""Creates metric_fn for TPUEstimatorSpec."""
cls_loss = tf.metrics.mean(kwargs['cls_loss_repeat'])
total_loss = tf.metrics.mean(kwargs['total_loss_repeat'])
logits = tf.image.resize_bilinear(kwargs['prediction'],
tf.shape(kwargs['labels'])[1:3],
align_corners=True)
predictions_with_shape = tf.argmax(logits, 3, output_type=tf.int32)
predictions = tf.reshape(predictions_with_shape, shape=[-1])
labels = tf.reshape(kwargs['labels'], shape=[-1])
# Background class is considered as a class. Not ignored.
weights = tf.to_float(tf.not_equal(labels, params['ignore_label']))
# Set ignore_label regions to label 0, because metrics.mean_iou requires
# range of labels = [0, dataset.num_classes).
# Note the ignore_lable regions are not evaluated since the corresponding
# regions contain weights = 0.
labels = tf.where(tf.equal(labels,
params['ignore_label']),
tf.zeros_like(labels),
labels)
return {
'total_loss': total_loss,
'cls_loss': cls_loss,
'miou':
tf.metrics.mean_iou(
predictions, labels, params['num_classes'], weights=weights),
}
cls_loss_repeat = tf.reshape(
tf.tile(tf.expand_dims(cls_loss, 0), [
batch_size,
]), [batch_size, 1])
total_loss_repeat = tf.reshape(
tf.tile(tf.expand_dims(total_loss, 0), [
batch_size,
]), [batch_size, 1])
metric_fn_inputs = {
'cls_loss_repeat': cls_loss_repeat,
'total_loss_repeat': total_loss_repeat,
'prediction': cls_outputs,
'labels': labels,
}
eval_metrics = (metric_fn, metric_fn_inputs)
return tf.contrib.tpu.TPUEstimatorSpec(
mode=mode,
loss=total_loss,
train_op=train_op,
eval_metrics=eval_metrics,
scaffold_fn=scaffold_fn,
)
def segmentation_model_fn(features, labels, mode, params):
"""RetinaNet model."""
return _model_fn(features, labels, mode, params,
model=retinanet_architecture.retinanet_segmentation,
variable_filter_fn=retinanet_architecture.remove_variables)
def default_hparams():
return tf.contrib.training.HParams(
image_size=513,
input_rand_hflip=True,
# dataset specific parameters
num_classes=21,
# model architecture
min_level=3,
max_level=5,
resnet_depth=101,
# is batchnorm training mode
is_training_bn=True,
# optimization
momentum=0.9,
learning_rate=0.02,
lr_warmup_init=0.002,
lr_warmup_epoch=1.0,
first_lr_drop_epoch=25.,
second_lr_drop_epoch=35.,
weight_decay=0.00001,
# classification loss
ignore_label=255,
loss_weight=1.0,
# resnet checkpoint
resnet_checkpoint=None,
train_scale_min=0.75,
train_scale_max=1.5,
# enable mixed-precision training (using bfloat16 on TPU)
use_bfloat16=True,
)
|
apache-2.0
|
[
3,
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1685,
347,
3155,
367,
314,
8747,
13765,
2480,
5822,
367,
27315,
14,
199,
199,
23891,
1402,
63,
2324,
402,
8747,
13765,
2480,
367,
21721,
28992,
14,
710,
1402,
63,
2324,
6952,
8747,
13765,
2480,
199,
1238,
15931,
12,
5621,
805,
12,
9328,
6634,
8732,
12,
436,
11735,
199,
21978,
14,
199,
199,
52,
23683,
57,
14,
29730,
12,
510,
14,
3971,
31876,
12,
820,
14,
598,
723,
609,
2000,
12,
1804,
14,
5311,
12,
436,
510,
14,
577,
25317,
199,
38,
24560,
3835,
385,
367,
20847,
6935,
1487,
5860,
14,
601,
56,
1003,
26,
1196,
2036,
14,
996,
7432,
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,
3228,
465,
2833,
199,
199,
646,
295,
1346,
290,
386,
63,
19134,
199,
646,
295,
1346,
290,
386,
63,
1238,
421,
199,
318,
485,
26926,
63,
4358,
8,
10492,
12,
3628,
12,
1862,
304,
523,
408,
8564,
27315,
5621,
14,
2002,
12474,
652,
1159,
1454,
367,
2849,
4666,
14,
819,
3033,
26,
272,
11051,
26,
437,
2345,
9314,
314,
11051,
465,
2138,
687,
1402,
805,
14,
489,
710,
2345,
1568,
365,
359,
2912,
63,
890,
12,
4569,
63,
76,
12,
3462,
63,
76,
12,
1967,
63,
2888,
1055,
489,
710,
4569,
63,
76,
436,
3462,
63,
76,
8350,
641,
314,
1748,
63,
1896,
3878,
12401,
14,
272,
3628,
26,
437,
2345,
9314,
314,
19252,
17167,
4545,
298,
1886,
63,
4684,
401,
489,
465,
2138,
687,
6394,
12201,
669,
14,
710,
2345,
965,
314,
2011,
11469,
12401,
489,
465,
1324,
1834,
543,
1568,
359,
2912,
63,
890,
12,
4569,
12,
3462,
12,
413,
1055,
272,
1862,
26,
11932,
5893,
6093,
2633,
2013,
315,
489,
849,
63,
72,
1162,
805,
315,
642,
570,
14,
523,
1803,
26,
272,
437,
2069,
2345,
6144,
3141,
12505,
5621,
14,
710,
5621,
365,
489,
9657,
701,
314,
3141,
2222,
13,
11996,
11094,
14,
523,
408,
523,
327,
577,
23311,
865,
3628,
701,
314,
1748,
63,
1896,
3878,
7345,
14,
523,
7345,
275,
499,
538,
1162,
459,
827,
63,
1896,
418,
523,
17923,
63,
3512,
275,
3628,
3981,
378,
447,
12318,
12,
378,
447,
12318,
61,
819,
17923,
63,
3512,
275,
2833,
14,
2931,
8,
15120,
63,
3512,
12,
2833,
14,
442,
708,
9,
523,
17923,
63,
3512,
275,
17923,
63,
3512,
3981,
13785,
13785,
378,
61,
523,
4546,
63,
2629,
275,
2833,
14,
1397,
63,
1452,
8,
15120,
63,
3512,
12,
1862,
459,
4247,
63,
1302,
1105,
523,
327,
16927,
3686,
1768,
370,
8020,
370,
5126,
1125,
1380,
17226,
523,
327,
28965,
19490,
5621,
14,
523,
17923,
63,
3512,
275,
2833,
14,
4509,
8,
2075,
63,
2629,
12,
17923,
63,
3512,
12,
2574,
2833,
14,
4250,
63,
2930,
8,
15120,
63,
3512,
430,
819,
26452,
275,
2833,
14,
5270,
63,
1838,
8,
3249,
14,
475,
63,
1609,
8,
2075,
63,
2629,
430,
523,
8059,
63,
10435,
63,
4358,
275,
2833,
14,
4411,
14,
4421,
63,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
489,
3628,
29,
15120,
63,
3512,
12,
11051,
29,
10492,
9,
523,
8059,
63,
10435,
63,
4358,
9000,
2833,
14,
475,
63,
1609,
8,
2075,
63,
2629,
9,
523,
5621,
275,
2833,
14,
5270,
63,
1838,
8,
7925,
63,
10435,
63,
4358,
9,
1182,
26452,
523,
372,
5621,
421,
199,
318,
485,
1238,
63,
2324,
8,
3179,
12,
3628,
12,
818,
12,
1862,
12,
1402,
12,
1750,
63,
1541,
63,
2324,
29,
403,
304,
523,
408,
1685,
347,
3155,
367,
314,
8747,
13765,
2480,
1402,
4079,
641,
3591,
2480,
13,
1400,
14,
819,
3033,
26,
272,
4534,
26,
710,
1324,
5935,
2345,
543,
2215,
359,
2912,
63,
890,
12,
4569,
12,
3462,
12,
650,
1055,
489,
710,
4569,
436,
3462,
787,
6317,
436,
4472,
14,
272,
3628,
26,
710,
1324,
3628,
315,
282,
2345,
543,
314,
2011,
2215,
465,
1324,
5935,
14,
272,
818,
26,
710,
818,
402,
24328,
4187,
270,
4841,
5893,
377,
21715,
12,
662,
3204,
12,
436,
510,
7387,
6196,
14,
272,
1862,
26,
710,
2600,
7890,
10342,
3214,
402,
1402,
14,
710,
849,
489,
2202,
787,
315,
849,
63,
72,
1162,
805,
315,
642,
570,
14,
272,
1402,
26,
710,
481,
9060,
27315,
1402,
4704,
1021,
11051,
14,
272,
1750,
63,
1541,
63,
2324,
26,
314,
2457,
805,
626,
6181,
17029,
63,
3669,
436,
489,
2529,
314,
1750,
769,
2410,
18876,
314,
2457,
2332,
14,
819,
1803,
26,
272,
307,
3165,
63,
1650,
26,
314,
24328,
4187,
270,
4841,
5307,
370,
1255,
6093,
12,
11735,
12,
503,
12044,
14,
523,
408,
523,
347,
485,
1238,
63,
4467,
837,
272,
372,
1402,
8,
267,
4534,
12,
267,
1748,
63,
1896,
29,
1162,
459,
827,
63,
1896,
995,
267,
1390,
63,
1896,
29,
1162,
459,
988,
63,
1896,
995,
267,
1967,
63,
2888,
29,
1162,
459,
1507,
63,
2888,
995,
267,
522,
846,
63,
4631,
29,
1162,
459,
28998,
63,
4631,
995,
267,
365,
63,
7588,
63,
10472,
29,
1162,
459,
374,
63,
7588,
63,
10472,
1105,
819,
340,
1862,
459,
1180,
63,
66,
1609,
975,
2565,
272,
543,
2833,
14,
2828,
14,
23186,
14,
66,
1609,
975,
63,
2645,
837,
489,
843,
63,
4467,
275,
485,
1238,
63,
4467,
342,
489,
843,
63,
4467,
275
] |
[
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1685,
347,
3155,
367,
314,
8747,
13765,
2480,
5822,
367,
27315,
14,
199,
199,
23891,
1402,
63,
2324,
402,
8747,
13765,
2480,
367,
21721,
28992,
14,
710,
1402,
63,
2324,
6952,
8747,
13765,
2480,
199,
1238,
15931,
12,
5621,
805,
12,
9328,
6634,
8732,
12,
436,
11735,
199,
21978,
14,
199,
199,
52,
23683,
57,
14,
29730,
12,
510,
14,
3971,
31876,
12,
820,
14,
598,
723,
609,
2000,
12,
1804,
14,
5311,
12,
436,
510,
14,
577,
25317,
199,
38,
24560,
3835,
385,
367,
20847,
6935,
1487,
5860,
14,
601,
56,
1003,
26,
1196,
2036,
14,
996,
7432,
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,
3228,
465,
2833,
199,
199,
646,
295,
1346,
290,
386,
63,
19134,
199,
646,
295,
1346,
290,
386,
63,
1238,
421,
199,
318,
485,
26926,
63,
4358,
8,
10492,
12,
3628,
12,
1862,
304,
523,
408,
8564,
27315,
5621,
14,
2002,
12474,
652,
1159,
1454,
367,
2849,
4666,
14,
819,
3033,
26,
272,
11051,
26,
437,
2345,
9314,
314,
11051,
465,
2138,
687,
1402,
805,
14,
489,
710,
2345,
1568,
365,
359,
2912,
63,
890,
12,
4569,
63,
76,
12,
3462,
63,
76,
12,
1967,
63,
2888,
1055,
489,
710,
4569,
63,
76,
436,
3462,
63,
76,
8350,
641,
314,
1748,
63,
1896,
3878,
12401,
14,
272,
3628,
26,
437,
2345,
9314,
314,
19252,
17167,
4545,
298,
1886,
63,
4684,
401,
489,
465,
2138,
687,
6394,
12201,
669,
14,
710,
2345,
965,
314,
2011,
11469,
12401,
489,
465,
1324,
1834,
543,
1568,
359,
2912,
63,
890,
12,
4569,
12,
3462,
12,
413,
1055,
272,
1862,
26,
11932,
5893,
6093,
2633,
2013,
315,
489,
849,
63,
72,
1162,
805,
315,
642,
570,
14,
523,
1803,
26,
272,
437,
2069,
2345,
6144,
3141,
12505,
5621,
14,
710,
5621,
365,
489,
9657,
701,
314,
3141,
2222,
13,
11996,
11094,
14,
523,
408,
523,
327,
577,
23311,
865,
3628,
701,
314,
1748,
63,
1896,
3878,
7345,
14,
523,
7345,
275,
499,
538,
1162,
459,
827,
63,
1896,
418,
523,
17923,
63,
3512,
275,
3628,
3981,
378,
447,
12318,
12,
378,
447,
12318,
61,
819,
17923,
63,
3512,
275,
2833,
14,
2931,
8,
15120,
63,
3512,
12,
2833,
14,
442,
708,
9,
523,
17923,
63,
3512,
275,
17923,
63,
3512,
3981,
13785,
13785,
378,
61,
523,
4546,
63,
2629,
275,
2833,
14,
1397,
63,
1452,
8,
15120,
63,
3512,
12,
1862,
459,
4247,
63,
1302,
1105,
523,
327,
16927,
3686,
1768,
370,
8020,
370,
5126,
1125,
1380,
17226,
523,
327,
28965,
19490,
5621,
14,
523,
17923,
63,
3512,
275,
2833,
14,
4509,
8,
2075,
63,
2629,
12,
17923,
63,
3512,
12,
2574,
2833,
14,
4250,
63,
2930,
8,
15120,
63,
3512,
430,
819,
26452,
275,
2833,
14,
5270,
63,
1838,
8,
3249,
14,
475,
63,
1609,
8,
2075,
63,
2629,
430,
523,
8059,
63,
10435,
63,
4358,
275,
2833,
14,
4411,
14,
4421,
63,
16395,
63,
7925,
63,
10435,
63,
1045,
63,
10492,
8,
489,
3628,
29,
15120,
63,
3512,
12,
11051,
29,
10492,
9,
523,
8059,
63,
10435,
63,
4358,
9000,
2833,
14,
475,
63,
1609,
8,
2075,
63,
2629,
9,
523,
5621,
275,
2833,
14,
5270,
63,
1838,
8,
7925,
63,
10435,
63,
4358,
9,
1182,
26452,
523,
372,
5621,
421,
199,
318,
485,
1238,
63,
2324,
8,
3179,
12,
3628,
12,
818,
12,
1862,
12,
1402,
12,
1750,
63,
1541,
63,
2324,
29,
403,
304,
523,
408,
1685,
347,
3155,
367,
314,
8747,
13765,
2480,
1402,
4079,
641,
3591,
2480,
13,
1400,
14,
819,
3033,
26,
272,
4534,
26,
710,
1324,
5935,
2345,
543,
2215,
359,
2912,
63,
890,
12,
4569,
12,
3462,
12,
650,
1055,
489,
710,
4569,
436,
3462,
787,
6317,
436,
4472,
14,
272,
3628,
26,
710,
1324,
3628,
315,
282,
2345,
543,
314,
2011,
2215,
465,
1324,
5935,
14,
272,
818,
26,
710,
818,
402,
24328,
4187,
270,
4841,
5893,
377,
21715,
12,
662,
3204,
12,
436,
510,
7387,
6196,
14,
272,
1862,
26,
710,
2600,
7890,
10342,
3214,
402,
1402,
14,
710,
849,
489,
2202,
787,
315,
849,
63,
72,
1162,
805,
315,
642,
570,
14,
272,
1402,
26,
710,
481,
9060,
27315,
1402,
4704,
1021,
11051,
14,
272,
1750,
63,
1541,
63,
2324,
26,
314,
2457,
805,
626,
6181,
17029,
63,
3669,
436,
489,
2529,
314,
1750,
769,
2410,
18876,
314,
2457,
2332,
14,
819,
1803,
26,
272,
307,
3165,
63,
1650,
26,
314,
24328,
4187,
270,
4841,
5307,
370,
1255,
6093,
12,
11735,
12,
503,
12044,
14,
523,
408,
523,
347,
485,
1238,
63,
4467,
837,
272,
372,
1402,
8,
267,
4534,
12,
267,
1748,
63,
1896,
29,
1162,
459,
827,
63,
1896,
995,
267,
1390,
63,
1896,
29,
1162,
459,
988,
63,
1896,
995,
267,
1967,
63,
2888,
29,
1162,
459,
1507,
63,
2888,
995,
267,
522,
846,
63,
4631,
29,
1162,
459,
28998,
63,
4631,
995,
267,
365,
63,
7588,
63,
10472,
29,
1162,
459,
374,
63,
7588,
63,
10472,
1105,
819,
340,
1862,
459,
1180,
63,
66,
1609,
975,
2565,
272,
543,
2833,
14,
2828,
14,
23186,
14,
66,
1609,
975,
63,
2645,
837,
489,
843,
63,
4467,
275,
485,
1238,
63,
4467,
342,
489,
843,
63,
4467,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
fly19890211/edx-platform
|
lms/djangoapps/mobile_api/video_outlines/tests.py
|
54
|
33406
|
# -*- coding: utf-8 -*-
"""
Tests for video outline API
"""
import ddt
import itertools
from uuid import uuid4
from collections import namedtuple
from edxval import api
from mobile_api.models import MobileApiConfig
from xmodule.modulestore.tests.factories import ItemFactory
from xmodule.video_module import transcripts_utils
from xmodule.modulestore.django import modulestore
from xmodule.partitions.partitions import Group, UserPartition
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup
from ..testutils import MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin
class TestVideoAPITestCase(MobileAPITestCase):
"""
Base test class for video related mobile APIs
"""
def setUp(self):
super(TestVideoAPITestCase, self).setUp()
self.section = ItemFactory.create(
parent=self.course,
category="chapter",
display_name=u"test factory section omega \u03a9",
)
self.sub_section = ItemFactory.create(
parent=self.section,
category="sequential",
display_name=u"test subsection omega \u03a9",
)
self.unit = ItemFactory.create(
parent=self.sub_section,
category="vertical",
metadata={'graded': True, 'format': 'Homework'},
display_name=u"test unit omega \u03a9",
)
self.other_unit = ItemFactory.create(
parent=self.sub_section,
category="vertical",
metadata={'graded': True, 'format': 'Homework'},
display_name=u"test unit omega 2 \u03a9",
)
self.nameless_unit = ItemFactory.create(
parent=self.sub_section,
category="vertical",
metadata={'graded': True, 'format': 'Homework'},
display_name=None,
)
self.edx_video_id = 'testing-123'
self.video_url = 'http://val.edx.org/val/video.mp4'
self.video_url_high = 'http://val.edx.org/val/video_high.mp4'
self.youtube_url = 'http://val.edx.org/val/youtube.mp4'
self.html5_video_url = 'http://video.edx.org/html5/video.mp4'
api.create_profile('youtube')
api.create_profile('mobile_high')
api.create_profile('mobile_low')
# create the video in VAL
api.create_video({
'edx_video_id': self.edx_video_id,
'status': 'test',
'client_video_id': u"test video omega \u03a9",
'duration': 12,
'courses': [unicode(self.course.id)],
'encoded_videos': [
{
'profile': 'youtube',
'url': 'xyz123',
'file_size': 0,
'bitrate': 1500
},
{
'profile': 'mobile_low',
'url': self.video_url,
'file_size': 12345,
'bitrate': 250
},
{
'profile': 'mobile_high',
'url': self.video_url_high,
'file_size': 99999,
'bitrate': 250
},
]})
# Set requested profiles
MobileApiConfig(video_profiles="mobile_low,mobile_high,youtube").save()
class TestVideoAPIMixin(object):
"""
Mixin class that provides helpers for testing video related mobile APIs
"""
def _create_video_with_subs(self, custom_subid=None):
"""
Creates and returns a video with stored subtitles.
"""
subid = custom_subid or uuid4().hex
transcripts_utils.save_subs_to_store(
{
'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500],
'text': [
'subs #1',
'subs #2',
'subs #3',
'subs #4',
'subs #5'
]
},
subid,
self.course)
return ItemFactory.create(
parent=self.unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test video omega \u03a9",
sub=subid
)
def _verify_paths(self, course_outline, path_list, outline_index=0):
"""
Takes a path_list and compares it against the course_outline
Attributes:
course_outline (list): A list of dictionaries that includes a 'path'
and 'named_path' field which we will be comparing path_list to
path_list (list): A list of the expected strings
outline_index (int): Index into the course_outline list for which the
path is being tested.
"""
path = course_outline[outline_index]['path']
self.assertEqual(len(path), len(path_list))
for i in range(len(path_list)):
self.assertEqual(path_list[i], path[i]['name'])
#named_path will be deprecated eventually
named_path = course_outline[outline_index]['named_path']
self.assertEqual(len(named_path), len(path_list))
for i in range(len(path_list)):
self.assertEqual(path_list[i], named_path[i])
def _setup_course_partitions(self, scheme_id='random', is_cohorted=False):
"""Helper method to configure the user partitions in the course."""
self.partition_id = 0 # pylint: disable=attribute-defined-outside-init
self.course.user_partitions = [
UserPartition(
self.partition_id, 'first_partition', 'First Partition',
[Group(0, 'alpha'), Group(1, 'beta')],
scheme=None, scheme_id=scheme_id
),
]
self.course.cohort_config = {'cohorted': is_cohorted}
self.store.update_item(self.course, self.user.id)
def _setup_group_access(self, xblock, partition_id, group_ids):
"""Helper method to configure the partition and group mapping for the given xblock."""
xblock.group_access = {partition_id: group_ids}
self.store.update_item(xblock, self.user.id)
def _setup_split_module(self, sub_block_category):
"""Helper method to configure a split_test unit with children of type sub_block_category."""
self._setup_course_partitions()
self.split_test = ItemFactory.create( # pylint: disable=attribute-defined-outside-init
parent=self.unit,
category="split_test",
display_name=u"split test unit",
user_partition_id=0,
)
sub_block_a = ItemFactory.create(
parent=self.split_test,
category=sub_block_category,
display_name=u"split test block a",
)
sub_block_b = ItemFactory.create(
parent=self.split_test,
category=sub_block_category,
display_name=u"split test block b",
)
self.split_test.group_id_to_child = {
str(index): url for index, url in enumerate([sub_block_a.location, sub_block_b.location])
}
self.store.update_item(self.split_test, self.user.id)
return sub_block_a, sub_block_b
class TestNonStandardCourseStructure(MobileAPITestCase, TestVideoAPIMixin):
"""
Tests /api/mobile/v0.5/video_outlines/courses/{course_id} with no course set
"""
REVERSE_INFO = {'name': 'video-summary-list', 'params': ['course_id']}
def setUp(self):
super(TestNonStandardCourseStructure, self).setUp()
self.chapter_under_course = ItemFactory.create(
parent=self.course,
category="chapter",
display_name=u"test factory chapter under course omega \u03a9",
)
self.section_under_course = ItemFactory.create(
parent=self.course,
category="sequential",
display_name=u"test factory section under course omega \u03a9",
)
self.section_under_chapter = ItemFactory.create(
parent=self.chapter_under_course,
category="sequential",
display_name=u"test factory section under chapter omega \u03a9",
)
self.vertical_under_course = ItemFactory.create(
parent=self.course,
category="vertical",
display_name=u"test factory vertical under course omega \u03a9",
)
self.vertical_under_section = ItemFactory.create(
parent=self.section_under_chapter,
category="vertical",
display_name=u"test factory vertical under section omega \u03a9",
)
def test_structure_course_video(self):
"""
Tests when there is a video without a vertical directly under course
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.course,
category="video",
display_name=u"test factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(section_url, r'courseware$')
self.assertEqual(section_url, unit_url)
self._verify_paths(course_outline, [])
def test_structure_course_vert_video(self):
"""
Tests when there is a video under vertical directly under course
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.vertical_under_course,
category="video",
display_name=u"test factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(
section_url,
r'courseware/test_factory_vertical_under_course_omega_%CE%A9/$'
)
self.assertEqual(section_url, unit_url)
self._verify_paths(
course_outline,
[
u'test factory vertical under course omega \u03a9'
]
)
def test_structure_course_chap_video(self):
"""
Tests when there is a video directly under chapter
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.chapter_under_course,
category="video",
display_name=u"test factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(
section_url,
r'courseware/test_factory_chapter_under_course_omega_%CE%A9/$'
)
self.assertEqual(section_url, unit_url)
self._verify_paths(
course_outline,
[
u'test factory chapter under course omega \u03a9',
]
)
def test_structure_course_section_video(self):
"""
Tests when chapter is none, and video under section under course
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.section_under_course,
category="video",
display_name=u"test factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(
section_url,
r'courseware/test_factory_section_under_course_omega_%CE%A9/$'
)
self.assertEqual(section_url, unit_url)
self._verify_paths(
course_outline,
[
u'test factory section under course omega \u03a9',
]
)
def test_structure_course_chap_section_video(self):
"""
Tests when chapter and sequential exists, with a video with no vertical.
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.section_under_chapter,
category="video",
display_name=u"meow factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(
section_url,
(
r'courseware/test_factory_chapter_under_course_omega_%CE%A9/' +
'test_factory_section_under_chapter_omega_%CE%A9/$'
)
)
self.assertEqual(section_url, unit_url)
self._verify_paths(
course_outline,
[
u'test factory chapter under course omega \u03a9',
u'test factory section under chapter omega \u03a9',
]
)
def test_structure_course_section_vert_video(self):
"""
Tests chapter->section->vertical->unit
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.vertical_under_section,
category="video",
display_name=u"test factory video omega \u03a9",
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertRegexpMatches(
section_url,
(
r'courseware/test_factory_chapter_under_course_omega_%CE%A9/' +
'test_factory_section_under_chapter_omega_%CE%A9/$'
)
)
self.assertRegexpMatches(
unit_url,
(
r'courseware/test_factory_chapter_under_course_omega_%CE%A9/' +
'test_factory_section_under_chapter_omega_%CE%A9/1$'
)
)
self._verify_paths(
course_outline,
[
u'test factory chapter under course omega \u03a9',
u'test factory section under chapter omega \u03a9',
u'test factory vertical under section omega \u03a9'
]
)
@ddt.ddt
class TestVideoSummaryList(
TestVideoAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin, TestVideoAPIMixin # pylint: disable=bad-continuation
):
"""
Tests for /api/mobile/v0.5/video_outlines/courses/{course_id}..
"""
REVERSE_INFO = {'name': 'video-summary-list', 'params': ['course_id']}
def test_only_on_web(self):
self.login_and_enroll()
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 0)
subid = uuid4().hex
transcripts_utils.save_subs_to_store(
{
'start': [100],
'end': [200],
'text': [
'subs #1',
]
},
subid,
self.course)
ItemFactory.create(
parent=self.unit,
category="video",
display_name=u"test video",
only_on_web=True,
subid=subid
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertIsNone(course_outline[0]["summary"]["video_url"])
self.assertIsNone(course_outline[0]["summary"]["video_thumbnail_url"])
self.assertEqual(course_outline[0]["summary"]["duration"], 0)
self.assertEqual(course_outline[0]["summary"]["size"], 0)
self.assertEqual(course_outline[0]["summary"]["name"], "test video")
self.assertEqual(course_outline[0]["summary"]["transcripts"], {})
self.assertIsNone(course_outline[0]["summary"]["language"])
self.assertEqual(course_outline[0]["summary"]["category"], "video")
self.assertTrue(course_outline[0]["summary"]["only_on_web"])
def test_mobile_api_config(self):
"""
Tests VideoSummaryList with different MobileApiConfig video_profiles
"""
self.login_and_enroll()
edx_video_id = "testing_mobile_high"
api.create_video({
'edx_video_id': edx_video_id,
'status': 'test',
'client_video_id': u"test video omega \u03a9",
'duration': 12,
'courses': [unicode(self.course.id)],
'encoded_videos': [
{
'profile': 'youtube',
'url': self.youtube_url,
'file_size': 2222,
'bitrate': 4444
},
{
'profile': 'mobile_high',
'url': self.video_url_high,
'file_size': 111,
'bitrate': 333
},
]})
ItemFactory.create(
parent=self.other_unit,
category="video",
display_name=u"testing mobile high video",
edx_video_id=edx_video_id,
)
expected_output = {
'category': u'video',
'video_thumbnail_url': None,
'language': u'en',
'name': u'testing mobile high video',
'video_url': self.video_url_high,
'duration': 12.0,
'transcripts': {
'en': 'http://testserver/api/mobile/v0.5/video_outlines/transcripts/{}/testing_mobile_high_video/en'.format(self.course.id) # pylint: disable=line-too-long
},
'only_on_web': False,
'encoded_videos': {
u'mobile_high': {
'url': self.video_url_high,
'file_size': 111
},
u'youtube': {
'url': self.youtube_url,
'file_size': 2222
}
},
'size': 111
}
# Testing when video_profiles='mobile_low,mobile_high,youtube'
course_outline = self.api_response().data
course_outline[0]['summary'].pop("id")
self.assertEqual(course_outline[0]['summary'], expected_output)
# Testing when there is no mobile_low, and that mobile_high doesn't show
MobileApiConfig(video_profiles="mobile_low,youtube").save()
course_outline = self.api_response().data
expected_output['encoded_videos'].pop('mobile_high')
expected_output['video_url'] = self.youtube_url
expected_output['size'] = 2222
course_outline[0]['summary'].pop("id")
self.assertEqual(course_outline[0]['summary'], expected_output)
# Testing where youtube is the default video over mobile_high
MobileApiConfig(video_profiles="youtube,mobile_high").save()
course_outline = self.api_response().data
expected_output['encoded_videos']['mobile_high'] = {
'url': self.video_url_high,
'file_size': 111
}
course_outline[0]['summary'].pop("id")
self.assertEqual(course_outline[0]['summary'], expected_output)
def test_video_not_in_val(self):
self.login_and_enroll()
self._create_video_with_subs()
ItemFactory.create(
parent=self.other_unit,
category="video",
edx_video_id="some_non_existent_id_in_val",
display_name=u"some non existent video in val",
html5_sources=[self.html5_video_url]
)
summary = self.api_response().data[1]['summary']
self.assertEqual(summary['name'], "some non existent video in val")
self.assertIsNone(summary['encoded_videos'])
self.assertIsNone(summary['duration'])
self.assertEqual(summary['size'], 0)
self.assertEqual(summary['video_url'], self.html5_video_url)
def test_course_list(self):
self.login_and_enroll()
self._create_video_with_subs()
ItemFactory.create(
parent=self.other_unit,
category="video",
display_name=u"test video omega 2 \u03a9",
html5_sources=[self.html5_video_url]
)
ItemFactory.create(
parent=self.other_unit,
category="video",
display_name=u"test video omega 3 \u03a9",
source=self.html5_video_url
)
ItemFactory.create(
parent=self.unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test draft video omega \u03a9",
visible_to_staff_only=True,
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 3)
vid = course_outline[0]
self.assertTrue('test_subsection_omega_%CE%A9' in vid['section_url'])
self.assertTrue('test_subsection_omega_%CE%A9/1' in vid['unit_url'])
self.assertTrue(u'test_video_omega_\u03a9' in vid['summary']['id'])
self.assertEqual(vid['summary']['video_url'], self.video_url)
self.assertEqual(vid['summary']['size'], 12345)
self.assertTrue('en' in vid['summary']['transcripts'])
self.assertFalse(vid['summary']['only_on_web'])
self.assertEqual(course_outline[1]['summary']['video_url'], self.html5_video_url)
self.assertEqual(course_outline[1]['summary']['size'], 0)
self.assertFalse(course_outline[1]['summary']['only_on_web'])
self.assertEqual(course_outline[1]['path'][2]['name'], self.other_unit.display_name)
self.assertEqual(course_outline[1]['path'][2]['id'], unicode(self.other_unit.location))
self.assertEqual(course_outline[2]['summary']['video_url'], self.html5_video_url)
self.assertEqual(course_outline[2]['summary']['size'], 0)
self.assertFalse(course_outline[2]['summary']['only_on_web'])
def test_with_nameless_unit(self):
self.login_and_enroll()
ItemFactory.create(
parent=self.nameless_unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test draft video omega 2 \u03a9"
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertEqual(course_outline[0]['path'][2]['name'], self.nameless_unit.location.block_id)
def test_with_video_in_sub_section(self):
"""
Tests a non standard xml format where a video is underneath a sequential
We are expecting to return the same unit and section url since there is
no unit vertical.
"""
self.login_and_enroll()
ItemFactory.create(
parent=self.sub_section,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"video in the sub section"
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertEqual(len(course_outline[0]['path']), 2)
section_url = course_outline[0]["section_url"]
unit_url = course_outline[0]["unit_url"]
self.assertIn(
u'courseware/test_factory_section_omega_%CE%A9/test_subsection_omega_%CE%A9',
section_url
)
self.assertTrue(section_url)
self.assertTrue(unit_url)
self.assertEqual(section_url, unit_url)
@ddt.data(
*itertools.product([True, False], ["video", "problem"])
)
@ddt.unpack
def test_with_split_block(self, is_user_staff, sub_block_category):
"""Test with split_module->sub_block_category and for both staff and non-staff users."""
self.login_and_enroll()
self.user.is_staff = is_user_staff
self.user.save()
self._setup_split_module(sub_block_category)
video_outline = self.api_response().data
num_video_blocks = 1 if sub_block_category == "video" else 0
self.assertEqual(len(video_outline), num_video_blocks)
for block_index in range(num_video_blocks):
self._verify_paths(
video_outline,
[
self.section.display_name,
self.sub_section.display_name,
self.unit.display_name,
self.split_test.display_name
],
block_index
)
self.assertIn(u"split test block", video_outline[block_index]["summary"]["name"])
def test_with_split_vertical(self):
"""Test with split_module->vertical->video structure."""
self.login_and_enroll()
split_vertical_a, split_vertical_b = self._setup_split_module("vertical")
ItemFactory.create(
parent=split_vertical_a,
category="video",
display_name=u"video in vertical a",
)
ItemFactory.create(
parent=split_vertical_b,
category="video",
display_name=u"video in vertical b",
)
video_outline = self.api_response().data
# user should see only one of the videos (a or b).
self.assertEqual(len(video_outline), 1)
self.assertIn(u"video in vertical", video_outline[0]["summary"]["name"])
a_or_b = video_outline[0]["summary"]["name"][-1:]
self._verify_paths(
video_outline,
[
self.section.display_name,
self.sub_section.display_name,
self.unit.display_name,
self.split_test.display_name,
u"split test block " + a_or_b
],
)
def _create_cohorted_video(self, group_id):
"""Creates a cohorted video block, giving access to only the given group_id."""
video_block = ItemFactory.create(
parent=self.unit,
category="video",
display_name=u"video for group " + unicode(group_id),
)
self._setup_group_access(video_block, self.partition_id, [group_id])
def _create_cohorted_vertical_with_video(self, group_id):
"""Creates a cohorted vertical with a child video block, giving access to only the given group_id."""
vertical_block = ItemFactory.create(
parent=self.sub_section,
category="vertical",
display_name=u"vertical for group " + unicode(group_id),
)
self._setup_group_access(vertical_block, self.partition_id, [group_id])
ItemFactory.create(
parent=vertical_block,
category="video",
display_name=u"video for group " + unicode(group_id),
)
@ddt.data("_create_cohorted_video", "_create_cohorted_vertical_with_video")
def test_with_cohorted_content(self, content_creator_method_name):
self.login_and_enroll()
self._setup_course_partitions(scheme_id='cohort', is_cohorted=True)
cohorts = []
for group_id in [0, 1]:
getattr(self, content_creator_method_name)(group_id)
cohorts.append(CohortFactory(course_id=self.course.id, name=u"Cohort " + unicode(group_id)))
link = CourseUserGroupPartitionGroup(
course_user_group=cohorts[group_id],
partition_id=self.partition_id,
group_id=group_id,
)
link.save()
for cohort_index in range(len(cohorts)):
# add user to this cohort
cohorts[cohort_index].users.add(self.user)
# should only see video for this cohort
video_outline = self.api_response().data
self.assertEqual(len(video_outline), 1)
self.assertEquals(
u"video for group " + unicode(cohort_index),
video_outline[0]["summary"]["name"]
)
# remove user from this cohort
cohorts[cohort_index].users.remove(self.user)
# un-cohorted user should see no videos
video_outline = self.api_response().data
self.assertEqual(len(video_outline), 0)
# staff user sees all videos
self.user.is_staff = True
self.user.save()
video_outline = self.api_response().data
self.assertEqual(len(video_outline), 2)
def test_with_hidden_blocks(self):
self.login_and_enroll()
hidden_subsection = ItemFactory.create(
parent=self.section,
category="sequential",
hide_from_toc=True,
)
unit_within_hidden_subsection = ItemFactory.create(
parent=hidden_subsection,
category="vertical",
)
hidden_unit = ItemFactory.create(
parent=self.sub_section,
category="vertical",
hide_from_toc=True,
)
ItemFactory.create(
parent=unit_within_hidden_subsection,
category="video",
edx_video_id=self.edx_video_id,
)
ItemFactory.create(
parent=hidden_unit,
category="video",
edx_video_id=self.edx_video_id,
)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 0)
def test_language(self):
self.login_and_enroll()
video = ItemFactory.create(
parent=self.nameless_unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test draft video omega 2 \u03a9"
)
language_case = namedtuple('language_case', ['transcripts', 'expected_language'])
language_cases = [
# defaults to english
language_case({}, "en"),
# supports english
language_case({"en": 1}, "en"),
# supports another language
language_case({"lang1": 1}, "lang1"),
# returns first alphabetically-sorted language
language_case({"lang1": 1, "en": 2}, "en"),
language_case({"lang1": 1, "lang2": 2}, "lang1"),
]
for case in language_cases:
video.transcripts = case.transcripts
modulestore().update_item(video, self.user.id)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertEqual(course_outline[0]['summary']['language'], case.expected_language)
def test_transcripts(self):
self.login_and_enroll()
video = ItemFactory.create(
parent=self.nameless_unit,
category="video",
edx_video_id=self.edx_video_id,
display_name=u"test draft video omega 2 \u03a9"
)
transcript_case = namedtuple('transcript_case', ['transcripts', 'english_subtitle', 'expected_transcripts'])
transcript_cases = [
# defaults to english
transcript_case({}, "", ["en"]),
transcript_case({}, "en-sub", ["en"]),
# supports english
transcript_case({"en": 1}, "", ["en"]),
transcript_case({"en": 1}, "en-sub", ["en"]),
# keeps both english and other languages
transcript_case({"lang1": 1, "en": 2}, "", ["lang1", "en"]),
transcript_case({"lang1": 1, "en": 2}, "en-sub", ["lang1", "en"]),
# adds english to list of languages only if english_subtitle is specified
transcript_case({"lang1": 1, "lang2": 2}, "", ["lang1", "lang2"]),
transcript_case({"lang1": 1, "lang2": 2}, "en-sub", ["lang1", "lang2", "en"]),
]
for case in transcript_cases:
video.transcripts = case.transcripts
video.sub = case.english_subtitle
modulestore().update_item(video, self.user.id)
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 1)
self.assertSetEqual(
set(course_outline[0]['summary']['transcripts'].keys()),
set(case.expected_transcripts)
)
class TestTranscriptsDetail(
TestVideoAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin, TestVideoAPIMixin # pylint: disable=bad-continuation
):
"""
Tests for /api/mobile/v0.5/video_outlines/transcripts/{course_id}..
"""
REVERSE_INFO = {'name': 'video-transcripts-detail', 'params': ['course_id']}
def setUp(self):
super(TestTranscriptsDetail, self).setUp()
self.video = self._create_video_with_subs()
def reverse_url(self, reverse_args=None, **kwargs):
reverse_args = reverse_args or {}
reverse_args.update({
'block_id': self.video.location.block_id,
'lang': kwargs.get('lang', 'en'),
})
return super(TestTranscriptsDetail, self).reverse_url(reverse_args, **kwargs)
def test_incorrect_language(self):
self.login_and_enroll()
self.api_response(expected_response_code=404, lang='pl')
def test_transcript_with_unicode_file_name(self):
self.video = self._create_video_with_subs(custom_subid=u'你好')
self.login_and_enroll()
self.api_response(expected_response_code=200, lang='en')
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
367,
3991,
17964,
3261,
199,
624,
199,
646,
366,
3583,
199,
646,
7975,
199,
504,
5377,
492,
5377,
20,
199,
504,
5055,
492,
12863,
199,
199,
504,
22435,
637,
492,
2986,
199,
504,
21305,
63,
1246,
14,
992,
492,
29724,
7394,
2028,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
19319,
199,
504,
9872,
14,
3722,
63,
578,
492,
7115,
6429,
63,
1208,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
12553,
14,
12553,
492,
5611,
12,
2876,
13068,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
2219,
14,
7546,
492,
1849,
7222,
2927,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
992,
492,
5531,
1899,
2448,
13068,
2448,
199,
199,
504,
2508,
396,
1208,
492,
29724,
2642,
27309,
12,
29724,
2817,
22060,
12,
29724,
6979,
3946,
22060,
421,
199,
533,
1379,
9166,
2642,
27309,
8,
27245,
2642,
27309,
304,
272,
408,
272,
3523,
511,
1021,
367,
3991,
4048,
21305,
15913,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
9166,
2642,
27309,
12,
291,
680,
5996,
342,
267,
291,
14,
2792,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
1972,
12,
288,
4637,
628,
11316,
401,
288,
2929,
63,
354,
29,
85,
2,
396,
6434,
3420,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
954,
63,
2792,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
2792,
12,
288,
4637,
628,
16211,
401,
288,
2929,
63,
354,
29,
85,
2,
396,
19876,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
398,
291,
14,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
85,
2,
396,
4137,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
1848,
63,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
85,
2,
396,
4137,
29566,
499,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
354,
2003,
63,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
403,
12,
267,
776,
398,
291,
14,
8268,
63,
3722,
63,
344,
275,
283,
4776,
13,
4288,
7,
267,
291,
14,
3722,
63,
633,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
3722,
14,
311,
20,
7,
267,
291,
14,
3722,
63,
633,
63,
6260,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
3722,
63,
6260,
14,
311,
20,
7,
267,
291,
14,
9788,
63,
633,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
9788,
14,
311,
20,
7,
267,
291,
14,
1360,
21,
63,
3722,
63,
633,
275,
283,
1014,
921,
3722,
14,
8268,
14,
1308,
15,
1360,
21,
15,
3722,
14,
311,
20,
7,
398,
2986,
14,
981,
63,
2913,
360,
9788,
358,
267,
2986,
14,
981,
63,
2913,
360,
11375,
63,
6260,
358,
267,
2986,
14,
981,
63,
2913,
360,
11375,
63,
674,
358,
398,
327,
1218,
314,
3991,
315,
8986,
267,
2986,
14,
981,
63,
3722,
2561,
288,
283,
8268,
63,
3722,
63,
344,
356,
291,
14,
8268,
63,
3722,
63,
344,
12,
288,
283,
1205,
356,
283,
396,
297,
288,
283,
1258,
63,
3722,
63,
344,
356,
399,
2,
396,
3991,
29566,
971,
85,
1644,
65,
25,
401,
288,
283,
5553,
356,
3144,
12,
288,
283,
11653,
356,
359,
2975,
8,
277,
14,
1972,
14,
344,
4360,
288,
283,
8167,
63,
11418,
356,
359,
355,
469,
490,
283,
2913,
356,
283,
9788,
297,
490,
283,
633,
356,
283,
8568,
4288,
297,
490,
283,
493,
63,
890,
356,
378,
12,
490,
283,
24484,
356,
24970,
355,
1660,
355,
469,
490,
283,
2913,
356,
283,
11375,
63,
674,
297,
490,
283,
633,
356,
291,
14,
3722,
63,
633,
12,
490,
283,
493,
63,
890,
356,
25538,
12,
490,
283,
24484,
356,
16074,
355,
1660,
355,
469,
490,
283,
2913,
356,
283,
11375,
63,
6260,
297,
490,
283,
633,
356,
291,
14,
3722,
63,
633,
63,
6260,
12,
490,
283,
493,
63,
890,
356,
221,
27055,
12,
490,
283,
24484,
356,
16074,
355,
1660,
953,
1622,
1552,
398,
327,
2494,
5839,
17390,
267,
29724,
7394,
2028,
8,
3722,
63,
11225,
628,
11375,
63,
674,
12,
11375,
63,
6260,
12,
9788,
3471,
2117,
342,
421,
199,
533,
1379,
9166,
1282,
1469,
3774,
8,
785,
304,
272,
408,
272,
28438,
1021,
626,
6571,
10897,
367,
5343,
3991,
4048,
21305,
15913,
272,
408,
272,
347,
485,
981,
63,
3722,
63,
1045,
63,
9841,
8,
277,
12,
3537,
63,
954,
344,
29,
403,
304,
267,
408,
267,
10560,
436,
2529,
282,
3991,
543,
5489,
19297,
14,
267,
408,
267,
1007,
344,
275,
3537,
63,
954,
344,
503,
5377,
20,
1252,
4097,
267,
7115,
6429,
63,
1208,
14,
2117,
63,
9841,
63,
475,
63,
1617,
8,
288,
469,
355,
283,
928,
356,
359,
1960,
12,
1926,
12,
21883,
12,
650,
2710,
12,
5198,
467,
355,
283,
500,
356,
359,
1840,
12,
21883,
12,
650,
1257,
12,
5198,
12,
24970,
467,
355,
283,
505,
356,
359,
490,
283,
9841,
327,
17,
297,
490,
283,
9841,
327,
18,
297,
490,
283,
9841,
327,
19,
297,
490,
283,
9841,
327,
20,
297,
490,
283,
9841,
327,
21,
7,
355,
1622,
288,
1660,
288,
1007,
344,
12,
288,
291,
14,
1972,
9,
267,
372,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
3248,
12,
288,
4637,
628,
3722,
401,
288,
22435,
63,
3722,
63,
344,
29,
277,
14,
8268,
63,
3722,
63,
344,
12,
288,
2929,
63,
354,
29,
85,
2,
396,
3991,
29566,
971,
85,
1644,
65,
25,
401
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
367,
3991,
17964,
3261,
199,
624,
199,
646,
366,
3583,
199,
646,
7975,
199,
504,
5377,
492,
5377,
20,
199,
504,
5055,
492,
12863,
199,
199,
504,
22435,
637,
492,
2986,
199,
504,
21305,
63,
1246,
14,
992,
492,
29724,
7394,
2028,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
19319,
199,
504,
9872,
14,
3722,
63,
578,
492,
7115,
6429,
63,
1208,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
12553,
14,
12553,
492,
5611,
12,
2876,
13068,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
2219,
14,
7546,
492,
1849,
7222,
2927,
199,
504,
22709,
14,
1018,
14,
16432,
14,
1972,
63,
2634,
14,
992,
492,
5531,
1899,
2448,
13068,
2448,
199,
199,
504,
2508,
396,
1208,
492,
29724,
2642,
27309,
12,
29724,
2817,
22060,
12,
29724,
6979,
3946,
22060,
421,
199,
533,
1379,
9166,
2642,
27309,
8,
27245,
2642,
27309,
304,
272,
408,
272,
3523,
511,
1021,
367,
3991,
4048,
21305,
15913,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
9166,
2642,
27309,
12,
291,
680,
5996,
342,
267,
291,
14,
2792,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
1972,
12,
288,
4637,
628,
11316,
401,
288,
2929,
63,
354,
29,
85,
2,
396,
6434,
3420,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
954,
63,
2792,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
2792,
12,
288,
4637,
628,
16211,
401,
288,
2929,
63,
354,
29,
85,
2,
396,
19876,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
398,
291,
14,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
85,
2,
396,
4137,
29566,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
1848,
63,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
85,
2,
396,
4137,
29566,
499,
971,
85,
1644,
65,
25,
401,
267,
776,
267,
291,
14,
354,
2003,
63,
3248,
275,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
954,
63,
2792,
12,
288,
4637,
628,
7870,
401,
288,
3341,
3713,
13688,
356,
715,
12,
283,
908,
356,
283,
12054,
800,
2267,
288,
2929,
63,
354,
29,
403,
12,
267,
776,
398,
291,
14,
8268,
63,
3722,
63,
344,
275,
283,
4776,
13,
4288,
7,
267,
291,
14,
3722,
63,
633,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
3722,
14,
311,
20,
7,
267,
291,
14,
3722,
63,
633,
63,
6260,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
3722,
63,
6260,
14,
311,
20,
7,
267,
291,
14,
9788,
63,
633,
275,
283,
1014,
921,
637,
14,
8268,
14,
1308,
15,
637,
15,
9788,
14,
311,
20,
7,
267,
291,
14,
1360,
21,
63,
3722,
63,
633,
275,
283,
1014,
921,
3722,
14,
8268,
14,
1308,
15,
1360,
21,
15,
3722,
14,
311,
20,
7,
398,
2986,
14,
981,
63,
2913,
360,
9788,
358,
267,
2986,
14,
981,
63,
2913,
360,
11375,
63,
6260,
358,
267,
2986,
14,
981,
63,
2913,
360,
11375,
63,
674,
358,
398,
327,
1218,
314,
3991,
315,
8986,
267,
2986,
14,
981,
63,
3722,
2561,
288,
283,
8268,
63,
3722,
63,
344,
356,
291,
14,
8268,
63,
3722,
63,
344,
12,
288,
283,
1205,
356,
283,
396,
297,
288,
283,
1258,
63,
3722,
63,
344,
356,
399,
2,
396,
3991,
29566,
971,
85,
1644,
65,
25,
401,
288,
283,
5553,
356,
3144,
12,
288,
283,
11653,
356,
359,
2975,
8,
277,
14,
1972,
14,
344,
4360,
288,
283,
8167,
63,
11418,
356,
359,
355,
469,
490,
283,
2913,
356,
283,
9788,
297,
490,
283,
633,
356,
283,
8568,
4288,
297,
490,
283,
493,
63,
890,
356,
378,
12,
490,
283,
24484,
356,
24970,
355,
1660,
355,
469,
490,
283,
2913,
356,
283,
11375,
63,
674,
297,
490,
283,
633,
356,
291,
14,
3722,
63,
633,
12,
490,
283,
493,
63,
890,
356,
25538,
12,
490,
283,
24484,
356,
16074,
355,
1660,
355,
469,
490,
283,
2913,
356,
283,
11375,
63,
6260,
297,
490,
283,
633,
356,
291,
14,
3722,
63,
633,
63,
6260,
12,
490,
283,
493,
63,
890,
356,
221,
27055,
12,
490,
283,
24484,
356,
16074,
355,
1660,
953,
1622,
1552,
398,
327,
2494,
5839,
17390,
267,
29724,
7394,
2028,
8,
3722,
63,
11225,
628,
11375,
63,
674,
12,
11375,
63,
6260,
12,
9788,
3471,
2117,
342,
421,
199,
533,
1379,
9166,
1282,
1469,
3774,
8,
785,
304,
272,
408,
272,
28438,
1021,
626,
6571,
10897,
367,
5343,
3991,
4048,
21305,
15913,
272,
408,
272,
347,
485,
981,
63,
3722,
63,
1045,
63,
9841,
8,
277,
12,
3537,
63,
954,
344,
29,
403,
304,
267,
408,
267,
10560,
436,
2529,
282,
3991,
543,
5489,
19297,
14,
267,
408,
267,
1007,
344,
275,
3537,
63,
954,
344,
503,
5377,
20,
1252,
4097,
267,
7115,
6429,
63,
1208,
14,
2117,
63,
9841,
63,
475,
63,
1617,
8,
288,
469,
355,
283,
928,
356,
359,
1960,
12,
1926,
12,
21883,
12,
650,
2710,
12,
5198,
467,
355,
283,
500,
356,
359,
1840,
12,
21883,
12,
650,
1257,
12,
5198,
12,
24970,
467,
355,
283,
505,
356,
359,
490,
283,
9841,
327,
17,
297,
490,
283,
9841,
327,
18,
297,
490,
283,
9841,
327,
19,
297,
490,
283,
9841,
327,
20,
297,
490,
283,
9841,
327,
21,
7,
355,
1622,
288,
1660,
288,
1007,
344,
12,
288,
291,
14,
1972,
9,
267,
372,
19319,
14,
981,
8,
288,
1676,
29,
277,
14,
3248,
12,
288,
4637,
628,
3722,
401,
288,
22435,
63,
3722,
63,
344,
29,
277,
14,
8268,
63,
3722,
63,
344,
12,
288,
2929,
63,
354,
29,
85,
2,
396,
3991,
29566,
971,
85,
1644,
65,
25,
401,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mdibaiee/servo
|
tests/wpt/css-tests/tools/html5lib/html5lib/tests/test_stream.py
|
446
|
6264
|
from __future__ import absolute_import, division, unicode_literals
from . import support # flake8: noqa
import unittest
import codecs
from io import BytesIO
from six.moves import http_client
from html5lib.inputstream import (BufferedStream, HTMLInputStream,
HTMLUnicodeInputStream, HTMLBinaryInputStream)
class BufferedStreamTest(unittest.TestCase):
def test_basic(self):
s = b"abc"
fp = BufferedStream(BytesIO(s))
read = fp.read(10)
assert read == s
def test_read_length(self):
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert read1 == b"a"
read2 = fp.read(2)
assert read2 == b"bc"
read3 = fp.read(3)
assert read3 == b"def"
read4 = fp.read(4)
assert read4 == b""
def test_tell(self):
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert fp.tell() == 1
read2 = fp.read(2)
assert fp.tell() == 3
read3 = fp.read(3)
assert fp.tell() == 6
read4 = fp.read(4)
assert fp.tell() == 6
def test_seek(self):
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert read1 == b"a"
fp.seek(0)
read2 = fp.read(1)
assert read2 == b"a"
read3 = fp.read(2)
assert read3 == b"bc"
fp.seek(2)
read4 = fp.read(2)
assert read4 == b"cd"
fp.seek(4)
read5 = fp.read(2)
assert read5 == b"ef"
def test_seek_tell(self):
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert fp.tell() == 1
fp.seek(0)
read2 = fp.read(1)
assert fp.tell() == 1
read3 = fp.read(2)
assert fp.tell() == 3
fp.seek(2)
read4 = fp.read(2)
assert fp.tell() == 4
fp.seek(4)
read5 = fp.read(2)
assert fp.tell() == 6
class HTMLUnicodeInputStreamShortChunk(HTMLUnicodeInputStream):
_defaultChunkSize = 2
class HTMLBinaryInputStreamShortChunk(HTMLBinaryInputStream):
_defaultChunkSize = 2
class HTMLInputStreamTest(unittest.TestCase):
def test_char_ascii(self):
stream = HTMLInputStream(b"'", encoding='ascii')
self.assertEqual(stream.charEncoding[0], 'ascii')
self.assertEqual(stream.char(), "'")
def test_char_utf8(self):
stream = HTMLInputStream('\u2018'.encode('utf-8'), encoding='utf-8')
self.assertEqual(stream.charEncoding[0], 'utf-8')
self.assertEqual(stream.char(), '\u2018')
def test_char_win1252(self):
stream = HTMLInputStream("\xa9\xf1\u2019".encode('windows-1252'))
self.assertEqual(stream.charEncoding[0], 'windows-1252')
self.assertEqual(stream.char(), "\xa9")
self.assertEqual(stream.char(), "\xf1")
self.assertEqual(stream.char(), "\u2019")
def test_bom(self):
stream = HTMLInputStream(codecs.BOM_UTF8 + b"'")
self.assertEqual(stream.charEncoding[0], 'utf-8')
self.assertEqual(stream.char(), "'")
def test_utf_16(self):
stream = HTMLInputStream((' ' * 1025).encode('utf-16'))
self.assertTrue(stream.charEncoding[0] in ['utf-16-le', 'utf-16-be'], stream.charEncoding)
self.assertEqual(len(stream.charsUntil(' ', True)), 1025)
def test_newlines(self):
stream = HTMLBinaryInputStreamShortChunk(codecs.BOM_UTF8 + b"a\nbb\r\nccc\rddddxe")
self.assertEqual(stream.position(), (1, 0))
self.assertEqual(stream.charsUntil('c'), "a\nbb\n")
self.assertEqual(stream.position(), (3, 0))
self.assertEqual(stream.charsUntil('x'), "ccc\ndddd")
self.assertEqual(stream.position(), (4, 4))
self.assertEqual(stream.charsUntil('e'), "x")
self.assertEqual(stream.position(), (4, 5))
def test_newlines2(self):
size = HTMLUnicodeInputStream._defaultChunkSize
stream = HTMLInputStream("\r" * size + "\n")
self.assertEqual(stream.charsUntil('x'), "\n" * size)
def test_position(self):
stream = HTMLBinaryInputStreamShortChunk(codecs.BOM_UTF8 + b"a\nbb\nccc\nddde\nf\ngh")
self.assertEqual(stream.position(), (1, 0))
self.assertEqual(stream.charsUntil('c'), "a\nbb\n")
self.assertEqual(stream.position(), (3, 0))
stream.unget("\n")
self.assertEqual(stream.position(), (2, 2))
self.assertEqual(stream.charsUntil('c'), "\n")
self.assertEqual(stream.position(), (3, 0))
stream.unget("\n")
self.assertEqual(stream.position(), (2, 2))
self.assertEqual(stream.char(), "\n")
self.assertEqual(stream.position(), (3, 0))
self.assertEqual(stream.charsUntil('e'), "ccc\nddd")
self.assertEqual(stream.position(), (4, 3))
self.assertEqual(stream.charsUntil('h'), "e\nf\ng")
self.assertEqual(stream.position(), (6, 1))
def test_position2(self):
stream = HTMLUnicodeInputStreamShortChunk("abc\nd")
self.assertEqual(stream.position(), (1, 0))
self.assertEqual(stream.char(), "a")
self.assertEqual(stream.position(), (1, 1))
self.assertEqual(stream.char(), "b")
self.assertEqual(stream.position(), (1, 2))
self.assertEqual(stream.char(), "c")
self.assertEqual(stream.position(), (1, 3))
self.assertEqual(stream.char(), "\n")
self.assertEqual(stream.position(), (2, 0))
self.assertEqual(stream.char(), "d")
self.assertEqual(stream.position(), (2, 1))
def test_python_issue_20007(self):
"""
Make sure we have a work-around for Python bug #20007
http://bugs.python.org/issue20007
"""
class FakeSocket(object):
def makefile(self, _mode, _bufsize=None):
return BytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")
source = http_client.HTTPResponse(FakeSocket())
source.begin()
stream = HTMLInputStream(source)
self.assertEqual(stream.charsUntil(" "), "Text")
def buildTestSuite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
def main():
buildTestSuite()
unittest.main()
if __name__ == '__main__':
main()
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
504,
1275,
492,
2291,
221,
327,
27510,
24,
26,
8151,
199,
646,
2882,
199,
646,
6010,
199,
504,
5890,
492,
11808,
199,
199,
504,
3816,
14,
4912,
492,
1455,
63,
1258,
199,
199,
504,
3517,
21,
773,
14,
1210,
1745,
492,
334,
23139,
3296,
12,
4163,
27611,
12,
3303,
4163,
7087,
27611,
12,
4163,
6636,
27611,
9,
199,
199,
533,
26832,
3296,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
308,
275,
330,
2,
3175,
2,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
83,
430,
267,
1586,
275,
4090,
14,
739,
8,
709,
9,
267,
702,
1586,
508,
308,
339,
347,
511,
63,
739,
63,
1267,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
17,
508,
330,
2,
65,
2,
267,
1586,
18,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
18,
508,
330,
2,
3776,
2,
267,
1586,
19,
275,
4090,
14,
739,
8,
19,
9,
267,
702,
1586,
19,
508,
330,
2,
318,
2,
267,
1586,
20,
275,
4090,
14,
739,
8,
20,
9,
267,
702,
1586,
20,
508,
330,
341,
339,
347,
511,
63,
9974,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
1586,
18,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
650,
267,
1586,
19,
275,
4090,
14,
739,
8,
19,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
267,
1586,
20,
275,
4090,
14,
739,
8,
20,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
339,
347,
511,
63,
5507,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
17,
508,
330,
2,
65,
2,
267,
4090,
14,
5507,
8,
16,
9,
267,
1586,
18,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
18,
508,
330,
2,
65,
2,
267,
1586,
19,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
19,
508,
330,
2,
3776,
2,
267,
4090,
14,
5507,
8,
18,
9,
267,
1586,
20,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
20,
508,
330,
2,
2866,
2,
267,
4090,
14,
5507,
8,
20,
9,
267,
1586,
21,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
21,
508,
330,
2,
2829,
2,
339,
347,
511,
63,
5507,
63,
9974,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
4090,
14,
5507,
8,
16,
9,
267,
1586,
18,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
1586,
19,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
650,
267,
4090,
14,
5507,
8,
18,
9,
267,
1586,
20,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
841,
267,
4090,
14,
5507,
8,
20,
9,
267,
1586,
21,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
421,
199,
533,
4163,
7087,
27611,
10039,
9856,
8,
4943,
7087,
27611,
304,
272,
485,
885,
9856,
2320,
275,
499,
421,
199,
533,
4163,
6636,
27611,
10039,
9856,
8,
4943,
6636,
27611,
304,
272,
485,
885,
9856,
2320,
275,
499,
421,
199,
533,
4163,
27611,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1560,
63,
4371,
8,
277,
304,
267,
2547,
275,
4163,
27611,
8,
66,
4507,
401,
2644,
534,
4371,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
4371,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
3546,
531,
339,
347,
511,
63,
1560,
63,
1624,
24,
8,
277,
304,
267,
2547,
275,
4163,
27611,
2258,
85,
12682,
1370,
2143,
360,
1624,
13,
24,
659,
2644,
534,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1557,
85,
12682,
358,
339,
347,
511,
63,
1560,
63,
2676,
19364,
8,
277,
304,
267,
2547,
275,
4163,
27611,
4582,
1800,
25,
60,
1949,
17,
60,
85,
14982,
1674,
2143,
360,
8258,
13,
19364,
1333,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
8258,
13,
19364,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
1800,
25,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
1949,
17,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
85,
14982,
531,
339,
347,
511,
63,
16302,
8,
277,
304,
267,
2547,
275,
4163,
27611,
8,
8933,
14,
19550,
63,
6610,
24,
435,
330,
4507,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
3546,
531,
339,
347,
511,
63,
1624,
63,
975,
8,
277,
304,
267,
2547,
275,
4163,
27611,
4725,
283,
627,
1616,
821,
680,
2143,
360,
1624,
13,
975,
1333,
267,
291,
14,
1815,
8,
1745,
14,
1560,
7630,
59,
16,
61,
315,
788,
1624,
13,
975,
13,
274,
297,
283,
1624,
13,
975,
13,
1235,
995,
2547,
14,
1560,
7630,
9,
267,
291,
14,
629,
8,
552,
8,
1745,
14,
6574,
18667,
360,
1656,
715,
1826,
1616,
821,
9,
339,
347,
511,
63,
13839,
8,
277,
304,
267,
2547,
275,
4163,
6636,
27611,
10039,
9856,
8,
8933,
14,
19550,
63,
6610,
24,
435,
330,
2,
65,
60,
78,
2501,
60,
82,
60,
78,
19504,
60,
82,
17472,
1845,
531,
267,
291,
14,
629,
8,
1745,
14,
3124,
1062,
334,
17,
12,
378,
430,
267,
291,
14,
629,
8,
1745,
14,
6574,
18667,
360,
67
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
504,
1275,
492,
2291,
221,
327,
27510,
24,
26,
8151,
199,
646,
2882,
199,
646,
6010,
199,
504,
5890,
492,
11808,
199,
199,
504,
3816,
14,
4912,
492,
1455,
63,
1258,
199,
199,
504,
3517,
21,
773,
14,
1210,
1745,
492,
334,
23139,
3296,
12,
4163,
27611,
12,
3303,
4163,
7087,
27611,
12,
4163,
6636,
27611,
9,
199,
199,
533,
26832,
3296,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
308,
275,
330,
2,
3175,
2,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
83,
430,
267,
1586,
275,
4090,
14,
739,
8,
709,
9,
267,
702,
1586,
508,
308,
339,
347,
511,
63,
739,
63,
1267,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
17,
508,
330,
2,
65,
2,
267,
1586,
18,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
18,
508,
330,
2,
3776,
2,
267,
1586,
19,
275,
4090,
14,
739,
8,
19,
9,
267,
702,
1586,
19,
508,
330,
2,
318,
2,
267,
1586,
20,
275,
4090,
14,
739,
8,
20,
9,
267,
702,
1586,
20,
508,
330,
341,
339,
347,
511,
63,
9974,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
1586,
18,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
650,
267,
1586,
19,
275,
4090,
14,
739,
8,
19,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
267,
1586,
20,
275,
4090,
14,
739,
8,
20,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
339,
347,
511,
63,
5507,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
17,
508,
330,
2,
65,
2,
267,
4090,
14,
5507,
8,
16,
9,
267,
1586,
18,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
1586,
18,
508,
330,
2,
65,
2,
267,
1586,
19,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
19,
508,
330,
2,
3776,
2,
267,
4090,
14,
5507,
8,
18,
9,
267,
1586,
20,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
20,
508,
330,
2,
2866,
2,
267,
4090,
14,
5507,
8,
20,
9,
267,
1586,
21,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
1586,
21,
508,
330,
2,
2829,
2,
339,
347,
511,
63,
5507,
63,
9974,
8,
277,
304,
267,
4090,
275,
26832,
3296,
8,
15466,
8,
66,
2,
10678,
2237,
267,
1586,
17,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
4090,
14,
5507,
8,
16,
9,
267,
1586,
18,
275,
4090,
14,
739,
8,
17,
9,
267,
702,
4090,
14,
9974,
342,
508,
413,
267,
1586,
19,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
650,
267,
4090,
14,
5507,
8,
18,
9,
267,
1586,
20,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
841,
267,
4090,
14,
5507,
8,
20,
9,
267,
1586,
21,
275,
4090,
14,
739,
8,
18,
9,
267,
702,
4090,
14,
9974,
342,
508,
1227,
421,
199,
533,
4163,
7087,
27611,
10039,
9856,
8,
4943,
7087,
27611,
304,
272,
485,
885,
9856,
2320,
275,
499,
421,
199,
533,
4163,
6636,
27611,
10039,
9856,
8,
4943,
6636,
27611,
304,
272,
485,
885,
9856,
2320,
275,
499,
421,
199,
533,
4163,
27611,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1560,
63,
4371,
8,
277,
304,
267,
2547,
275,
4163,
27611,
8,
66,
4507,
401,
2644,
534,
4371,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
4371,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
3546,
531,
339,
347,
511,
63,
1560,
63,
1624,
24,
8,
277,
304,
267,
2547,
275,
4163,
27611,
2258,
85,
12682,
1370,
2143,
360,
1624,
13,
24,
659,
2644,
534,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1557,
85,
12682,
358,
339,
347,
511,
63,
1560,
63,
2676,
19364,
8,
277,
304,
267,
2547,
275,
4163,
27611,
4582,
1800,
25,
60,
1949,
17,
60,
85,
14982,
1674,
2143,
360,
8258,
13,
19364,
1333,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
8258,
13,
19364,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
1800,
25,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
1949,
17,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
1867,
85,
14982,
531,
339,
347,
511,
63,
16302,
8,
277,
304,
267,
2547,
275,
4163,
27611,
8,
8933,
14,
19550,
63,
6610,
24,
435,
330,
4507,
531,
267,
291,
14,
629,
8,
1745,
14,
1560,
7630,
59,
16,
467,
283,
1624,
13,
24,
358,
267,
291,
14,
629,
8,
1745,
14,
1560,
1062,
3546,
531,
339,
347,
511,
63,
1624,
63,
975,
8,
277,
304,
267,
2547,
275,
4163,
27611,
4725,
283,
627,
1616,
821,
680,
2143,
360,
1624,
13,
975,
1333,
267,
291,
14,
1815,
8,
1745,
14,
1560,
7630,
59,
16,
61,
315,
788,
1624,
13,
975,
13,
274,
297,
283,
1624,
13,
975,
13,
1235,
995,
2547,
14,
1560,
7630,
9,
267,
291,
14,
629,
8,
552,
8,
1745,
14,
6574,
18667,
360,
1656,
715,
1826,
1616,
821,
9,
339,
347,
511,
63,
13839,
8,
277,
304,
267,
2547,
275,
4163,
6636,
27611,
10039,
9856,
8,
8933,
14,
19550,
63,
6610,
24,
435,
330,
2,
65,
60,
78,
2501,
60,
82,
60,
78,
19504,
60,
82,
17472,
1845,
531,
267,
291,
14,
629,
8,
1745,
14,
3124,
1062,
334,
17,
12,
378,
430,
267,
291,
14,
629,
8,
1745,
14,
6574,
18667,
360,
67,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
apeyser/nest-simulator
|
pynest/nest/__init__.py
|
5
|
7625
|
# -*- coding: utf-8 -*-
#
# __init__.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/>.
"""
Initializer of PyNEST.
"""
import sys
import os
# This is a workaround for readline import errors encountered with Anaconda
# Python running on Ubuntu, when invoked from the terminal
# "python -c 'import nest'"
if 'linux' in sys.platform and 'Anaconda' in sys.version:
import readline
# This is a workaround to avoid segmentation faults when importing
# scipy *after* nest. See https://github.com/numpy/numpy/issues/2521
try:
import scipy
except:
pass
# Make MPI-enabled NEST import properly. The underlying problem is that the
# shared object pynestkernel dynamically opens other libraries that open
# yet other libraries.
try:
# Python 3.3 and later has flags in os
sys.setdlopenflags(os.RTLD_NOW | os.RTLD_GLOBAL)
except AttributeError:
# Python 2.6 and 2.7 have flags in ctypes, but RTLD_NOW may only
# be available in dl or DLFCN and is required at least under
# Ubuntu 14.04. The latter two are not available under OSX,
# but OSX does not have and does not need RTLD_NOW. We therefore
# first try dl and DLFCN, then ctypes just for OSX.
try:
import dl
sys.setdlopenflags(dl.RTLD_GLOBAL | dl.RTLD_NOW)
except (ImportError, AttributeError):
try:
import DLFCN
sys.setdlopenflags(DLFCN.RTLD_GLOBAL | DLFCN.RTLD_NOW)
except (ImportError, AttributeError):
import ctypes
try:
sys.setdlopenflags(ctypes.RTLD_GLOBAL | ctypes.RTLD_NOW)
except AttributeError:
# We must test this last, since it is the only case without
# RTLD_NOW (OSX)
sys.setdlopenflags(ctypes.RTLD_GLOBAL)
from . import pynestkernel as _kernel # noqa
from .lib import hl_api_helper as hl_api # noqa
engine = _kernel.NESTEngine()
sli_push = hl_api.sps = engine.push
sli_pop = hl_api.spp = engine.pop
hl_api.pcd = engine.push_connection_datums
hl_api.kernel = _kernel
initialized = False
def catching_sli_run(cmd):
"""Send a command string to the NEST kernel to be executed, catch
SLI errors and re-raise them in Python.
Parameters
----------
cmd : str
The SLI command to be executed.
Raises
------
NESTError
SLI errors are bubbled to the Python API as NESTErrors.
"""
if sys.version_info >= (3, ):
def encode(s):
return s
def decode(s):
return s
else:
def encode(s):
return s.encode('utf-8')
def decode(s):
return s.decode('utf-8')
engine.run('{%s} runprotected' % decode(cmd))
if not sli_pop():
errorname = sli_pop()
message = sli_pop()
commandname = sli_pop()
engine.run('clear')
errorstring = '%s in %s%s' % (errorname, commandname, message)
raise _kernel.NESTError(encode(errorstring))
sli_run = hl_api.sr = catching_sli_run
def sli_func(s, *args, **kwargs):
"""Convenience function for executing an SLI command s with
arguments args.
This executes the SLI sequence:
``sli_push(args); sli_run(s); y=sli_pop()``
Parameters
----------
s : str
Function to call
*args
Arbitrary number of arguments to pass to the SLI function
**kwargs
namespace : str
The sli code is executed in the given SLI namespace.
litconv : bool
Convert string args beginning with / to literals.
Returns
-------
The function may have multiple return values. The number of return values
is determined by the SLI function that was called.
Examples
--------
r,q = sli_func('dup rollu add',2,3)
r = sli_func('add',2,3)
r = sli_func('add pop',2,3)
l = sli_func('CreateLayer', {...}, namespace='topology')
"""
# check for namespace
slifun = 'sli_func' # version not converting to literals
if 'namespace' in kwargs:
s = kwargs['namespace'] + ' using ' + s + ' endusing'
elif 'litconv' in kwargs:
if kwargs['litconv']:
slifun = 'sli_func_litconv'
elif len(kwargs) > 0:
_kernel.NESTError(
"'namespace' and 'litconv' are the only valid keyword arguments.")
sli_push(args) # push array of arguments on SLI stack
sli_push(s) # push command string
sli_run(slifun) # SLI support code to execute s on args
r = sli_pop() # return value is an array
if len(r) == 1: # 1 return value is no tuple
return r[0]
if len(r) != 0:
return r
hl_api.sli_func = sli_func
def init(argv):
"""Initializes NEST.
Parameters
----------
argv : list
Command line arguments, passed to the NEST kernel
Raises
------
_kernel.NESTError
"""
global initialized
if initialized:
raise _kernel.NESTError("NEST already initialized.")
return
quiet = False
# Some commandline arguments of NEST and Python have the same
# name, but different meaning. To avoid unintended behavior, we
# handle NEST's arguments here and pass it a modified copy, while
# we leave the original list unchanged for further use by the user
# or other modules.
nest_argv = argv[:]
if "--quiet" in nest_argv:
quiet = True
nest_argv.remove("--quiet")
if "--debug" in nest_argv:
nest_argv.remove("--debug")
if "--sli-debug" in nest_argv:
nest_argv.remove("--sli-debug")
nest_argv.append("--debug")
initialized = engine.init(nest_argv, __path__[0])
if initialized:
if not quiet:
engine.run("pywelcome")
# Dirty hack to get tab-completion for models in IPython.
try:
__IPYTHON__
except NameError:
pass
else:
try:
import keyword
keyword.kwlist += Models()
except ImportError:
pass
else:
_kernel.NESTError("Initiatization of NEST failed.")
def test():
"""Runs all PyNEST unit tests."""
from . import tests
import unittest
debug = hl_api.get_debug()
hl_api.set_debug(True)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(tests.suite())
hl_api.set_debug(debug)
from .pynestkernel import * # noqa
from .lib.hl_api_helper import * # noqa
# We search through the subdirectory "lib" of the "nest" module
# directory and import the content of all Python files therein into
# the global namespace. This makes the API functions of PyNEST itself
# and those of extra modules available to the user.
for name in os.listdir(os.path.join(os.path.dirname(__file__), "lib")):
if name.endswith(".py") and not name.startswith('__'):
exec("from .lib.{0} import *".format(name[:-3]))
if 'DELAY_PYNEST_INIT' not in os.environ:
init(sys.argv)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
636,
826,
4343,
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,
27742,
402,
1611,
46,
1719,
14,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
199,
3,
961,
365,
282,
18092,
367,
14441,
492,
2552,
14556,
543,
1626,
16928,
983,
199,
3,
2018,
3879,
641,
31631,
12,
1380,
10302,
687,
314,
11167,
199,
3,
298,
1548,
446,
67,
283,
646,
10715,
4065,
199,
692,
283,
5135,
7,
315,
984,
14,
3246,
436,
283,
2493,
16928,
983,
7,
315,
984,
14,
1023,
26,
272,
492,
14441,
199,
199,
3,
961,
365,
282,
18092,
370,
5126,
27315,
16898,
83,
1380,
16306,
199,
3,
7026,
627,
4399,
10,
10715,
14,
1666,
4178,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
10115,
15,
821,
2025,
199,
893,
26,
272,
492,
7026,
199,
2590,
26,
272,
986,
199,
199,
3,
4155,
26024,
13,
3827,
28878,
492,
7684,
14,
710,
8793,
5160,
365,
626,
314,
199,
3,
5709,
909,
1134,
15272,
4989,
18774,
30848,
1163,
8363,
626,
1551,
199,
3,
5966,
1163,
8363,
14,
199,
893,
26,
272,
327,
2018,
650,
14,
19,
436,
2945,
965,
3285,
315,
747,
272,
984,
14,
409,
68,
8329,
2469,
8,
736,
14,
11876,
6533,
63,
14283,
1204,
747,
14,
11876,
6533,
63,
13808,
9,
199,
2590,
4281,
26,
272,
327,
2018,
499,
14,
22,
436,
499,
14,
23,
1172,
3285,
315,
5577,
12,
1325,
24090,
6533,
63,
14283,
1443,
1454,
272,
327,
506,
2808,
315,
15396,
503,
577,
44,
4161,
46,
436,
365,
1415,
737,
5210,
1334,
272,
327,
31631,
4329,
14,
966,
14,
710,
19045,
2877,
787,
440,
2808,
1334,
32144,
12,
272,
327,
1325,
32144,
1630,
440,
1172,
436,
1630,
440,
1929,
24090,
6533,
63,
14283,
14,
2136,
16119,
272,
327,
1642,
862,
15396,
436,
577,
44,
4161,
46,
12,
2066,
5577,
2951,
367,
32144,
14,
272,
862,
26,
267,
492,
15396,
267,
984,
14,
409,
68,
8329,
2469,
8,
5030,
14,
11876,
6533,
63,
13808,
1204,
15396,
14,
11876,
6533,
63,
14283,
9,
272,
871,
334,
17825,
12,
4281,
304,
267,
862,
26,
288,
492,
577,
44,
4161,
46,
288,
984,
14,
409,
68,
8329,
2469,
8,
8045,
4161,
46,
14,
11876,
6533,
63,
13808,
1204,
577,
44,
4161,
46,
14,
11876,
6533,
63,
14283,
9,
267,
871,
334,
17825,
12,
4281,
304,
288,
492,
5577,
288,
862,
26,
355,
984,
14,
409,
68,
8329,
2469,
8,
9798,
14,
11876,
6533,
63,
13808,
1204,
5577,
14,
11876,
6533,
63,
14283,
9,
288,
871,
4281,
26,
355,
327,
2136,
1471,
511,
642,
2061,
12,
3967,
652,
365,
314,
1454,
1930,
1928,
355,
327,
24090,
6533,
63,
14283,
334,
25160,
9,
355,
984,
14,
409,
68,
8329,
2469,
8,
9798,
14,
11876,
6533,
63,
13808,
9,
199,
199,
504,
1275,
492,
1134,
15272,
4989,
465,
485,
4989,
420,
327,
8151,
199,
504,
1275,
773,
492,
27768,
63,
1246,
63,
3676,
465,
27768,
63,
1246,
257,
327,
8151,
199,
199,
3908,
275,
485,
4989,
14,
46,
1719,
8524,
342,
199,
199,
23766,
63,
5335,
275,
27768,
63,
1246,
14,
681,
83,
275,
6869,
14,
5335,
199,
23766,
63,
1935,
275,
27768,
63,
1246,
14,
681,
80,
275,
6869,
14,
1935,
199,
15544,
63,
1246,
14,
2352,
68,
275,
6869,
14,
5335,
63,
2105,
63,
18945,
83,
199,
15544,
63,
1246,
14,
4989,
275,
485,
4989,
199,
199,
12486,
275,
756,
421,
199,
318,
8579,
316,
63,
23766,
63,
1065,
8,
1760,
304,
272,
408,
6795,
282,
1414,
1059,
370,
314,
28878,
5114,
370,
506,
7934,
12,
8579,
272,
428,
2673,
2552,
436,
295,
13,
3730,
3062,
315,
2018,
14,
339,
3897,
272,
4143,
272,
2088,
520,
620,
267,
710,
428,
2673,
1414,
370,
506,
7934,
14,
272,
6218,
272,
21397,
272,
28878,
547,
267,
428,
2673,
2552,
787,
330,
21749,
68,
370,
314,
2018,
3261,
465,
28878,
9298,
14,
272,
408,
339,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
3461,
267,
347,
3752,
8,
83,
304,
288,
372,
308,
398,
347,
4849,
8,
83,
304,
288,
372,
308,
272,
587,
26,
267,
347,
3752,
8,
83,
304,
288,
372,
308,
14,
2143,
360,
1624,
13,
24,
358,
398,
347,
4849,
8,
83,
304,
288,
372,
308,
14,
2708,
360,
1624,
13,
24,
358,
339,
6869,
14,
1065,
24103,
83,
93,
1255,
6798,
7,
450,
4849,
8,
1760,
430,
272,
340,
440,
27498,
63,
1935,
837,
267,
1125,
354,
275,
27498,
63,
1935,
342,
267,
1245,
275,
27498,
63,
1935,
342,
267,
1414,
354,
275,
27498,
63,
1935,
342,
267,
6869,
14,
1065,
360,
3584,
358,
267,
1125,
875,
275,
1543,
83,
315,
450,
83,
5,
83,
7,
450,
334,
705,
354,
12,
1414,
354,
12,
1245,
9,
267,
746,
485,
4989,
14,
46,
1719,
547,
8,
2143,
8,
705,
875,
430,
199,
199,
23766,
63,
1065,
275,
27768,
63,
1246,
14,
5474,
275,
8579,
316,
63,
23766,
63,
1065,
421,
199,
318,
27498,
63,
1532,
8,
83,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
714,
23329,
805,
367,
14043,
376,
428,
2673,
1414,
308,
543,
272,
2368,
1249,
14,
339,
961,
24956,
314,
428
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
636,
826,
4343,
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,
27742,
402,
1611,
46,
1719,
14,
199,
624,
199,
199,
646,
984,
199,
646,
747,
199,
199,
3,
961,
365,
282,
18092,
367,
14441,
492,
2552,
14556,
543,
1626,
16928,
983,
199,
3,
2018,
3879,
641,
31631,
12,
1380,
10302,
687,
314,
11167,
199,
3,
298,
1548,
446,
67,
283,
646,
10715,
4065,
199,
692,
283,
5135,
7,
315,
984,
14,
3246,
436,
283,
2493,
16928,
983,
7,
315,
984,
14,
1023,
26,
272,
492,
14441,
199,
199,
3,
961,
365,
282,
18092,
370,
5126,
27315,
16898,
83,
1380,
16306,
199,
3,
7026,
627,
4399,
10,
10715,
14,
1666,
4178,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
10115,
15,
821,
2025,
199,
893,
26,
272,
492,
7026,
199,
2590,
26,
272,
986,
199,
199,
3,
4155,
26024,
13,
3827,
28878,
492,
7684,
14,
710,
8793,
5160,
365,
626,
314,
199,
3,
5709,
909,
1134,
15272,
4989,
18774,
30848,
1163,
8363,
626,
1551,
199,
3,
5966,
1163,
8363,
14,
199,
893,
26,
272,
327,
2018,
650,
14,
19,
436,
2945,
965,
3285,
315,
747,
272,
984,
14,
409,
68,
8329,
2469,
8,
736,
14,
11876,
6533,
63,
14283,
1204,
747,
14,
11876,
6533,
63,
13808,
9,
199,
2590,
4281,
26,
272,
327,
2018,
499,
14,
22,
436,
499,
14,
23,
1172,
3285,
315,
5577,
12,
1325,
24090,
6533,
63,
14283,
1443,
1454,
272,
327,
506,
2808,
315,
15396,
503,
577,
44,
4161,
46,
436,
365,
1415,
737,
5210,
1334,
272,
327,
31631,
4329,
14,
966,
14,
710,
19045,
2877,
787,
440,
2808,
1334,
32144,
12,
272,
327,
1325,
32144,
1630,
440,
1172,
436,
1630,
440,
1929,
24090,
6533,
63,
14283,
14,
2136,
16119,
272,
327,
1642,
862,
15396,
436,
577,
44,
4161,
46,
12,
2066,
5577,
2951,
367,
32144,
14,
272,
862,
26,
267,
492,
15396,
267,
984,
14,
409,
68,
8329,
2469,
8,
5030,
14,
11876,
6533,
63,
13808,
1204,
15396,
14,
11876,
6533,
63,
14283,
9,
272,
871,
334,
17825,
12,
4281,
304,
267,
862,
26,
288,
492,
577,
44,
4161,
46,
288,
984,
14,
409,
68,
8329,
2469,
8,
8045,
4161,
46,
14,
11876,
6533,
63,
13808,
1204,
577,
44,
4161,
46,
14,
11876,
6533,
63,
14283,
9,
267,
871,
334,
17825,
12,
4281,
304,
288,
492,
5577,
288,
862,
26,
355,
984,
14,
409,
68,
8329,
2469,
8,
9798,
14,
11876,
6533,
63,
13808,
1204,
5577,
14,
11876,
6533,
63,
14283,
9,
288,
871,
4281,
26,
355,
327,
2136,
1471,
511,
642,
2061,
12,
3967,
652,
365,
314,
1454,
1930,
1928,
355,
327,
24090,
6533,
63,
14283,
334,
25160,
9,
355,
984,
14,
409,
68,
8329,
2469,
8,
9798,
14,
11876,
6533,
63,
13808,
9,
199,
199,
504,
1275,
492,
1134,
15272,
4989,
465,
485,
4989,
420,
327,
8151,
199,
504,
1275,
773,
492,
27768,
63,
1246,
63,
3676,
465,
27768,
63,
1246,
257,
327,
8151,
199,
199,
3908,
275,
485,
4989,
14,
46,
1719,
8524,
342,
199,
199,
23766,
63,
5335,
275,
27768,
63,
1246,
14,
681,
83,
275,
6869,
14,
5335,
199,
23766,
63,
1935,
275,
27768,
63,
1246,
14,
681,
80,
275,
6869,
14,
1935,
199,
15544,
63,
1246,
14,
2352,
68,
275,
6869,
14,
5335,
63,
2105,
63,
18945,
83,
199,
15544,
63,
1246,
14,
4989,
275,
485,
4989,
199,
199,
12486,
275,
756,
421,
199,
318,
8579,
316,
63,
23766,
63,
1065,
8,
1760,
304,
272,
408,
6795,
282,
1414,
1059,
370,
314,
28878,
5114,
370,
506,
7934,
12,
8579,
272,
428,
2673,
2552,
436,
295,
13,
3730,
3062,
315,
2018,
14,
339,
3897,
272,
4143,
272,
2088,
520,
620,
267,
710,
428,
2673,
1414,
370,
506,
7934,
14,
272,
6218,
272,
21397,
272,
28878,
547,
267,
428,
2673,
2552,
787,
330,
21749,
68,
370,
314,
2018,
3261,
465,
28878,
9298,
14,
272,
408,
339,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
3461,
267,
347,
3752,
8,
83,
304,
288,
372,
308,
398,
347,
4849,
8,
83,
304,
288,
372,
308,
272,
587,
26,
267,
347,
3752,
8,
83,
304,
288,
372,
308,
14,
2143,
360,
1624,
13,
24,
358,
398,
347,
4849,
8,
83,
304,
288,
372,
308,
14,
2708,
360,
1624,
13,
24,
358,
339,
6869,
14,
1065,
24103,
83,
93,
1255,
6798,
7,
450,
4849,
8,
1760,
430,
272,
340,
440,
27498,
63,
1935,
837,
267,
1125,
354,
275,
27498,
63,
1935,
342,
267,
1245,
275,
27498,
63,
1935,
342,
267,
1414,
354,
275,
27498,
63,
1935,
342,
267,
6869,
14,
1065,
360,
3584,
358,
267,
1125,
875,
275,
1543,
83,
315,
450,
83,
5,
83,
7,
450,
334,
705,
354,
12,
1414,
354,
12,
1245,
9,
267,
746,
485,
4989,
14,
46,
1719,
547,
8,
2143,
8,
705,
875,
430,
199,
199,
23766,
63,
1065,
275,
27768,
63,
1246,
14,
5474,
275,
8579,
316,
63,
23766,
63,
1065,
421,
199,
318,
27498,
63,
1532,
8,
83,
12,
627,
589,
12,
1011,
958,
304,
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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
] |
supergentle/migueltutorial
|
flask/lib/python2.7/site-packages/werkzeug/wrappers.py
|
147
|
76919
|
# -*- coding: utf-8 -*-
"""
werkzeug.wrappers
~~~~~~~~~~~~~~~~~
The wrappers are simple request and response objects which you can
subclass to do whatever you want them to do. The request object contains
the information transmitted by the client (webbrowser) and the response
object contains all the information sent back to the browser.
An important detail is that the request object is created with the WSGI
environ and will act as high-level proxy whereas the response object is an
actual WSGI application.
Like everything else in Werkzeug these objects will work correctly with
unicode data. Incoming form data parsed by the response object will be
decoded into an unicode object if possible and if it makes sense.
:copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from functools import update_wrapper
from datetime import datetime, timedelta
from werkzeug.http import HTTP_STATUS_CODES, \
parse_accept_header, parse_cache_control_header, parse_etags, \
parse_date, generate_etag, is_resource_modified, unquote_etag, \
quote_etag, parse_set_header, parse_authorization_header, \
parse_www_authenticate_header, remove_entity_headers, \
parse_options_header, dump_options_header, http_date, \
parse_if_range_header, parse_cookie, dump_cookie, \
parse_range_header, parse_content_range_header, dump_header
from werkzeug.urls import url_decode, iri_to_uri, url_join
from werkzeug.formparser import FormDataParser, default_stream_factory
from werkzeug.utils import cached_property, environ_property, \
header_property, get_content_type
from werkzeug.wsgi import get_current_url, get_host, \
ClosingIterator, get_input_stream, get_content_length
from werkzeug.datastructures import MultiDict, CombinedMultiDict, Headers, \
EnvironHeaders, ImmutableMultiDict, ImmutableTypeConversionDict, \
ImmutableList, MIMEAccept, CharsetAccept, LanguageAccept, \
ResponseCacheControl, RequestCacheControl, CallbackDict, \
ContentRange, iter_multi_items
from werkzeug._internal import _get_environ
from werkzeug._compat import to_bytes, string_types, text_type, \
integer_types, wsgi_decoding_dance, wsgi_get_bytes, \
to_unicode, to_native, BytesIO
def _run_wsgi_app(*args):
"""This function replaces itself to ensure that the test module is not
imported unless required. DO NOT USE!
"""
global _run_wsgi_app
from werkzeug.test import run_wsgi_app as _run_wsgi_app
return _run_wsgi_app(*args)
def _warn_if_string(iterable):
"""Helper for the response objects to check if the iterable returned
to the WSGI server is not a string.
"""
if isinstance(iterable, string_types):
from warnings import warn
warn(Warning('response iterable was set to a string. This appears '
'to work but means that the server will send the '
'data to the client char, by char. This is almost '
'never intended behavior, use response.data to assign '
'strings to the response object.'), stacklevel=2)
def _assert_not_shallow(request):
if request.shallow:
raise RuntimeError('A shallow request tried to consume '
'form data. If you really want to do '
'that, set `shallow` to False.')
def _iter_encoded(iterable, charset):
for item in iterable:
if isinstance(item, text_type):
yield item.encode(charset)
else:
yield item
class BaseRequest(object):
"""Very basic request object. This does not implement advanced stuff like
entity tag parsing or cache controls. The request object is created with
the WSGI environment as first argument and will add itself to the WSGI
environment as ``'werkzeug.request'`` unless it's created with
`populate_request` set to False.
There are a couple of mixins available that add additional functionality
to the request object, there is also a class called `Request` which
subclasses `BaseRequest` and all the important mixins.
It's a good idea to create a custom subclass of the :class:`BaseRequest`
and add missing functionality either via mixins or direct implementation.
Here an example for such subclasses::
from werkzeug.wrappers import BaseRequest, ETagRequestMixin
class Request(BaseRequest, ETagRequestMixin):
pass
Request objects are **read only**. As of 0.5 modifications are not
allowed in any place. Unlike the lower level parsing functions the
request object will use immutable objects everywhere possible.
Per default the request object will assume all the text data is `utf-8`
encoded. Please refer to `the unicode chapter <unicode.txt>`_ for more
details about customizing the behavior.
Per default the request object will be added to the WSGI
environment as `werkzeug.request` to support the debugging system.
If you don't want that, set `populate_request` to `False`.
If `shallow` is `True` the environment is initialized as shallow
object around the environ. Every operation that would modify the
environ in any way (such as consuming form data) raises an exception
unless the `shallow` attribute is explicitly set to `False`. This
is useful for middlewares where you don't want to consume the form
data by accident. A shallow request is not populated to the WSGI
environment.
.. versionchanged:: 0.5
read-only mode was enforced by using immutables classes for all
data.
"""
#: the charset for the request, defaults to utf-8
charset = 'utf-8'
#: the error handling procedure for errors, defaults to 'replace'
encoding_errors = 'replace'
#: the maximum content length. This is forwarded to the form data
#: parsing function (:func:`parse_form_data`). When set and the
#: :attr:`form` or :attr:`files` attribute is accessed and the
#: parsing fails because more than the specified value is transmitted
#: a :exc:`~werkzeug.exceptions.RequestEntityTooLarge` exception is raised.
#:
#: Have a look at :ref:`dealing-with-request-data` for more details.
#:
#: .. versionadded:: 0.5
max_content_length = None
#: the maximum form field size. This is forwarded to the form data
#: parsing function (:func:`parse_form_data`). When set and the
#: :attr:`form` or :attr:`files` attribute is accessed and the
#: data in memory for post data is longer than the specified value a
#: :exc:`~werkzeug.exceptions.RequestEntityTooLarge` exception is raised.
#:
#: Have a look at :ref:`dealing-with-request-data` for more details.
#:
#: .. versionadded:: 0.5
max_form_memory_size = None
#: the class to use for `args` and `form`. The default is an
#: :class:`~werkzeug.datastructures.ImmutableMultiDict` which supports
#: multiple values per key. alternatively it makes sense to use an
#: :class:`~werkzeug.datastructures.ImmutableOrderedMultiDict` which
#: preserves order or a :class:`~werkzeug.datastructures.ImmutableDict`
#: which is the fastest but only remembers the last key. It is also
#: possible to use mutable structures, but this is not recommended.
#:
#: .. versionadded:: 0.6
parameter_storage_class = ImmutableMultiDict
#: the type to be used for list values from the incoming WSGI environment.
#: By default an :class:`~werkzeug.datastructures.ImmutableList` is used
#: (for example for :attr:`access_list`).
#:
#: .. versionadded:: 0.6
list_storage_class = ImmutableList
#: the type to be used for dict values from the incoming WSGI environment.
#: By default an
#: :class:`~werkzeug.datastructures.ImmutableTypeConversionDict` is used
#: (for example for :attr:`cookies`).
#:
#: .. versionadded:: 0.6
dict_storage_class = ImmutableTypeConversionDict
#: The form data parser that shoud be used. Can be replaced to customize
#: the form date parsing.
form_data_parser_class = FormDataParser
#: Optionally a list of hosts that is trusted by this request. By default
#: all hosts are trusted which means that whatever the client sends the
#: host is will be accepted.
#:
#: This is the recommended setup as a webserver should manually be set up
#: to only route correct hosts to the application, and remove the
#: `X-Forwarded-Host` header if it is not being used (see
#: :func:`werkzeug.wsgi.get_host`).
#:
#: .. versionadded:: 0.9
trusted_hosts = None
#: Indicates whether the data descriptor should be allowed to read and
#: buffer up the input stream. By default it's enabled.
#:
#: .. versionadded:: 0.9
disable_data_descriptor = False
def __init__(self, environ, populate_request=True, shallow=False):
self.environ = environ
if populate_request and not shallow:
self.environ['werkzeug.request'] = self
self.shallow = shallow
def __repr__(self):
# make sure the __repr__ even works if the request was created
# from an invalid WSGI environment. If we display the request
# in a debug session we don't want the repr to blow up.
args = []
try:
args.append("'%s'" % to_native(self.url, self.url_charset))
args.append('[%s]' % self.method)
except Exception:
args.append('(invalid WSGI environ)')
return '<%s %s>' % (
self.__class__.__name__,
' '.join(args)
)
@property
def url_charset(self):
"""The charset that is assumed for URLs. Defaults to the value
of :attr:`charset`.
.. versionadded:: 0.6
"""
return self.charset
@classmethod
def from_values(cls, *args, **kwargs):
"""Create a new request object based on the values provided. If
environ is given missing values are filled from there. This method is
useful for small scripts when you need to simulate a request from an URL.
Do not use this method for unittesting, there is a full featured client
object (:class:`Client`) that allows to create multipart requests,
support for cookies etc.
This accepts the same options as the
:class:`~werkzeug.test.EnvironBuilder`.
.. versionchanged:: 0.5
This method now accepts the same arguments as
:class:`~werkzeug.test.EnvironBuilder`. Because of this the
`environ` parameter is now called `environ_overrides`.
:return: request object
"""
from werkzeug.test import EnvironBuilder
charset = kwargs.pop('charset', cls.charset)
kwargs['charset'] = charset
builder = EnvironBuilder(*args, **kwargs)
try:
return builder.get_request(cls)
finally:
builder.close()
@classmethod
def application(cls, f):
"""Decorate a function as responder that accepts the request as first
argument. This works like the :func:`responder` decorator but the
function is passed the request object as first argument and the
request object will be closed automatically::
@Request.application
def my_wsgi_app(request):
return Response('Hello World!')
:param f: the WSGI callable to decorate
:return: a new WSGI callable
"""
#: return a callable that wraps the -2nd argument with the request
#: and calls the function with all the arguments up to that one and
#: the request. The return value is then called with the latest
#: two arguments. This makes it possible to use this decorator for
#: both methods and standalone WSGI functions.
def application(*args):
request = cls(args[-2])
with request:
return f(*args[:-2] + (request,))(*args[-2:])
return update_wrapper(application, f)
def _get_file_stream(self, total_content_length, content_type, filename=None,
content_length=None):
"""Called to get a stream for the file upload.
This must provide a file-like class with `read()`, `readline()`
and `seek()` methods that is both writeable and readable.
The default implementation returns a temporary file if the total
content length is higher than 500KB. Because many browsers do not
provide a content length for the files only the total content
length matters.
:param total_content_length: the total content length of all the
data in the request combined. This value
is guaranteed to be there.
:param content_type: the mimetype of the uploaded file.
:param filename: the filename of the uploaded file. May be `None`.
:param content_length: the length of this file. This value is usually
not provided because webbrowsers do not provide
this value.
"""
return default_stream_factory(total_content_length, content_type,
filename, content_length)
@property
def want_form_data_parsed(self):
"""Returns True if the request method carries content. As of
Werkzeug 0.9 this will be the case if a content type is transmitted.
.. versionadded:: 0.8
"""
return bool(self.environ.get('CONTENT_TYPE'))
def make_form_data_parser(self):
"""Creates the form data parser. Instanciates the
:attr:`form_data_parser_class` with some parameters.
.. versionadded:: 0.8
"""
return self.form_data_parser_class(self._get_file_stream,
self.charset,
self.encoding_errors,
self.max_form_memory_size,
self.max_content_length,
self.parameter_storage_class)
def _load_form_data(self):
"""Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this method to
force the parsing of the form data.
.. versionadded:: 0.8
"""
# abort early if we have already consumed the stream
if 'form' in self.__dict__:
return
_assert_not_shallow(self)
if self.want_form_data_parsed:
content_type = self.environ.get('CONTENT_TYPE', '')
content_length = get_content_length(self.environ)
mimetype, options = parse_options_header(content_type)
parser = self.make_form_data_parser()
data = parser.parse(self._get_stream_for_parsing(),
mimetype, content_length, options)
else:
data = (self.stream, self.parameter_storage_class(),
self.parameter_storage_class())
# inject the values into the instance dict so that we bypass
# our cached_property non-data descriptor.
d = self.__dict__
d['stream'], d['form'], d['files'] = data
def _get_stream_for_parsing(self):
"""This is the same as accessing :attr:`stream` with the difference
that if it finds cached data from calling :meth:`get_data` first it
will create a new stream out of the cached data.
.. versionadded:: 0.9.3
"""
cached_data = getattr(self, '_cached_data', None)
if cached_data is not None:
return BytesIO(cached_data)
return self.stream
def close(self):
"""Closes associated resources of this request object. This
closes all file handles explicitly. You can also use the request
object in a with statement with will automatically close it.
.. versionadded:: 0.9
"""
files = self.__dict__.get('files')
for key, value in iter_multi_items(files or ()):
value.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
self.close()
@cached_property
def stream(self):
"""The stream to read incoming data from. Unlike :attr:`input_stream`
this stream is properly guarded that you can't accidentally read past
the length of the input. Werkzeug will internally always refer to
this stream to read data which makes it possible to wrap this
object with a stream that does filtering.
.. versionchanged:: 0.9
This stream is now always available but might be consumed by the
form parser later on. Previously the stream was only set if no
parsing happened.
"""
_assert_not_shallow(self)
return get_input_stream(self.environ)
input_stream = environ_property('wsgi.input', 'The WSGI input stream.\n'
'In general it\'s a bad idea to use this one because you can easily '
'read past the boundary. Use the :attr:`stream` instead.')
@cached_property
def args(self):
"""The parsed URL parameters. By default an
:class:`~werkzeug.datastructures.ImmutableMultiDict`
is returned from this function. This can be changed by setting
:attr:`parameter_storage_class` to a different type. This might
be necessary if the order of the form data is important.
"""
return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')),
self.url_charset, errors=self.encoding_errors,
cls=self.parameter_storage_class)
@cached_property
def data(self):
if self.disable_data_descriptor:
raise AttributeError('data descriptor is disabled')
# XXX: this should eventually be deprecated.
# We trigger form data parsing first which means that the descriptor
# will not cache the data that would otherwise be .form or .files
# data. This restores the behavior that was there in Werkzeug
# before 0.9. New code should use :meth:`get_data` explicitly as
# this will make behavior explicit.
return self.get_data(parse_form_data=True)
def get_data(self, cache=True, as_text=False, parse_form_data=False):
"""This reads the buffered incoming data from the client into one
bytestring. By default this is cached but that behavior can be
changed by setting `cache` to `False`.
Usually it's a bad idea to call this method without checking the
content length first as a client could send dozens of megabytes or more
to cause memory problems on the server.
Note that if the form data was already parsed this method will not
return anything as form data parsing does not cache the data like
this method does. To implicitly invoke form data parsing function
set `parse_form_data` to `True`. When this is done the return value
of this method will be an empty string if the form parser handles
the data. This generally is not necessary as if the whole data is
cached (which is the default) the form parser will used the cached
data to parse the form data. Please be generally aware of checking
the content length first in any case before calling this method
to avoid exhausting server memory.
If `as_text` is set to `True` the return value will be a decoded
unicode string.
.. versionadded:: 0.9
"""
rv = getattr(self, '_cached_data', None)
if rv is None:
if parse_form_data:
self._load_form_data()
rv = self.stream.read()
if cache:
self._cached_data = rv
if as_text:
rv = rv.decode(self.charset, self.encoding_errors)
return rv
@cached_property
def form(self):
"""The form parameters. By default an
:class:`~werkzeug.datastructures.ImmutableMultiDict`
is returned from this function. This can be changed by setting
:attr:`parameter_storage_class` to a different type. This might
be necessary if the order of the form data is important.
"""
self._load_form_data()
return self.form
@cached_property
def values(self):
"""Combined multi dict for :attr:`args` and :attr:`form`."""
args = []
for d in self.args, self.form:
if not isinstance(d, MultiDict):
d = MultiDict(d)
args.append(d)
return CombinedMultiDict(args)
@cached_property
def files(self):
""":class:`~werkzeug.datastructures.MultiDict` object containing
all uploaded files. Each key in :attr:`files` is the name from the
``<input type="file" name="">``. Each value in :attr:`files` is a
Werkzeug :class:`~werkzeug.datastructures.FileStorage` object.
Note that :attr:`files` will only contain data if the request method was
POST, PUT or PATCH and the ``<form>`` that posted to the request had
``enctype="multipart/form-data"``. It will be empty otherwise.
See the :class:`~werkzeug.datastructures.MultiDict` /
:class:`~werkzeug.datastructures.FileStorage` documentation for
more details about the used data structure.
"""
self._load_form_data()
return self.files
@cached_property
def cookies(self):
"""Read only access to the retrieved cookie values as dictionary."""
return parse_cookie(self.environ, self.charset,
self.encoding_errors,
cls=self.dict_storage_class)
@cached_property
def headers(self):
"""The headers from the WSGI environ as immutable
:class:`~werkzeug.datastructures.EnvironHeaders`.
"""
return EnvironHeaders(self.environ)
@cached_property
def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(self.environ.get('PATH_INFO') or '',
self.charset, self.encoding_errors)
return '/' + raw_path.lstrip('/')
@cached_property
def full_path(self):
"""Requested path as unicode, including the query string."""
return self.path + u'?' + to_unicode(self.query_string, self.url_charset)
@cached_property
def script_root(self):
"""The root path of the script without the trailing slash."""
raw_path = wsgi_decoding_dance(self.environ.get('SCRIPT_NAME') or '',
self.charset, self.encoding_errors)
return raw_path.rstrip('/')
@cached_property
def url(self):
"""The reconstructed current URL as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ,
trusted_hosts=self.trusted_hosts)
@cached_property
def base_url(self):
"""Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, strip_querystring=True,
trusted_hosts=self.trusted_hosts)
@cached_property
def url_root(self):
"""The full URL root (with hostname), this is the application
root as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, True,
trusted_hosts=self.trusted_hosts)
@cached_property
def host_url(self):
"""Just the host with scheme as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, host_only=True,
trusted_hosts=self.trusted_hosts)
@cached_property
def host(self):
"""Just the host including the port if available.
See also: :attr:`trusted_hosts`.
"""
return get_host(self.environ, trusted_hosts=self.trusted_hosts)
query_string = environ_property('QUERY_STRING', '', read_only=True,
load_func=wsgi_get_bytes, doc=
'''The URL parameters as raw bytestring.''')
method = environ_property('REQUEST_METHOD', 'GET', read_only=True,
load_func=lambda x: x.upper(), doc=
'''The transmission method. (For example ``'GET'`` or ``'POST'``).''')
@cached_property
def access_route(self):
"""If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server.
"""
if 'HTTP_X_FORWARDED_FOR' in self.environ:
addr = self.environ['HTTP_X_FORWARDED_FOR'].split(',')
return self.list_storage_class([x.strip() for x in addr])
elif 'REMOTE_ADDR' in self.environ:
return self.list_storage_class([self.environ['REMOTE_ADDR']])
return self.list_storage_class()
@property
def remote_addr(self):
"""The remote address of the client."""
return self.environ.get('REMOTE_ADDR')
remote_user = environ_property('REMOTE_USER', doc='''
If the server supports user authentication, and the script is
protected, this attribute contains the username the user has
authenticated as.''')
scheme = environ_property('wsgi.url_scheme', doc='''
URL scheme (http or https).
.. versionadded:: 0.7''')
is_xhr = property(lambda x: x.environ.get('HTTP_X_REQUESTED_WITH', '')
.lower() == 'xmlhttprequest', doc='''
True if the request was triggered via a JavaScript XMLHttpRequest.
This only works with libraries that support the `X-Requested-With`
header and set it to "XMLHttpRequest". Libraries that do that are
prototype, jQuery and Mochikit and probably some more.''')
is_secure = property(lambda x: x.environ['wsgi.url_scheme'] == 'https',
doc='`True` if the request is secure.')
is_multithread = environ_property('wsgi.multithread', doc='''
boolean that is `True` if the application is served by
a multithreaded WSGI server.''')
is_multiprocess = environ_property('wsgi.multiprocess', doc='''
boolean that is `True` if the application is served by
a WSGI server that spawns multiple processes.''')
is_run_once = environ_property('wsgi.run_once', doc='''
boolean that is `True` if the application will be executed only
once in a process lifetime. This is the case for CGI for example,
but it's not guaranteed that the exeuction only happens one time.''')
class BaseResponse(object):
"""Base response class. The most important fact about a response object
is that it's a regular WSGI application. It's initialized with a couple
of response parameters (headers, body, status code etc.) and will start a
valid WSGI response when called with the environ and start response
callable.
Because it's a WSGI application itself processing usually ends before the
actual response is sent to the server. This helps debugging systems
because they can catch all the exceptions before responses are started.
Here a small example WSGI application that takes advantage of the
response objects::
from werkzeug.wrappers import BaseResponse as Response
def index():
return Response('Index page')
def application(environ, start_response):
path = environ.get('PATH_INFO') or '/'
if path == '/':
response = index()
else:
response = Response('Not Found', status=404)
return response(environ, start_response)
Like :class:`BaseRequest` which object is lacking a lot of functionality
implemented in mixins. This gives you a better control about the actual
API of your response objects, so you can create subclasses and add custom
functionality. A full featured response object is available as
:class:`Response` which implements a couple of useful mixins.
To enforce a new type of already existing responses you can use the
:meth:`force_type` method. This is useful if you're working with different
subclasses of response objects and you want to post process them with a
know interface.
Per default the request object will assume all the text data is `utf-8`
encoded. Please refer to `the unicode chapter <unicode.txt>`_ for more
details about customizing the behavior.
Response can be any kind of iterable or string. If it's a string it's
considered being an iterable with one item which is the string passed.
Headers can be a list of tuples or a
:class:`~werkzeug.datastructures.Headers` object.
Special note for `mimetype` and `content_type`: For most mime types
`mimetype` and `content_type` work the same, the difference affects
only 'text' mimetypes. If the mimetype passed with `mimetype` is a
mimetype starting with `text/`, the charset parameter of the response
object is appended to it. In contrast the `content_type` parameter is
always added as header unmodified.
.. versionchanged:: 0.5
the `direct_passthrough` parameter was added.
:param response: a string or response iterable.
:param status: a string with a status or an integer with the status code.
:param headers: a list of headers or a
:class:`~werkzeug.datastructures.Headers` object.
:param mimetype: the mimetype for the request. See notice above.
:param content_type: the content type for the request. See notice above.
:param direct_passthrough: if set to `True` :meth:`iter_encoded` is not
called before iteration which makes it
possible to pass special iterators though
unchanged (see :func:`wrap_file` for more
details.)
"""
#: the charset of the response.
charset = 'utf-8'
#: the default status if none is provided.
default_status = 200
#: the default mimetype if none is provided.
default_mimetype = 'text/plain'
#: if set to `False` accessing properties on the response object will
#: not try to consume the response iterator and convert it into a list.
#:
#: .. versionadded:: 0.6.2
#:
#: That attribute was previously called `implicit_seqence_conversion`.
#: (Notice the typo). If you did use this feature, you have to adapt
#: your code to the name change.
implicit_sequence_conversion = True
#: Should this response object correct the location header to be RFC
#: conformant? This is true by default.
#:
#: .. versionadded:: 0.8
autocorrect_location_header = True
#: Should this response object automatically set the content-length
#: header if possible? This is true by default.
#:
#: .. versionadded:: 0.8
automatically_set_content_length = True
def __init__(self, response=None, status=None, headers=None,
mimetype=None, content_type=None, direct_passthrough=False):
if isinstance(headers, Headers):
self.headers = headers
elif not headers:
self.headers = Headers()
else:
self.headers = Headers(headers)
if content_type is None:
if mimetype is None and 'content-type' not in self.headers:
mimetype = self.default_mimetype
if mimetype is not None:
mimetype = get_content_type(mimetype, self.charset)
content_type = mimetype
if content_type is not None:
self.headers['Content-Type'] = content_type
if status is None:
status = self.default_status
if isinstance(status, integer_types):
self.status_code = status
else:
self.status = status
self.direct_passthrough = direct_passthrough
self._on_close = []
# we set the response after the headers so that if a class changes
# the charset attribute, the data is set in the correct charset.
if response is None:
self.response = []
elif isinstance(response, (text_type, bytes, bytearray)):
self.set_data(response)
else:
self.response = response
def call_on_close(self, func):
"""Adds a function to the internal list of functions that should
be called as part of closing down the response. Since 0.7 this
function also returns the function that was passed so that this
can be used as a decorator.
.. versionadded:: 0.6
"""
self._on_close.append(func)
return func
def __repr__(self):
if self.is_sequence:
body_info = '%d bytes' % sum(map(len, self.iter_encoded()))
else:
body_info = self.is_streamed and 'streamed' or 'likely-streamed'
return '<%s %s [%s]>' % (
self.__class__.__name__,
body_info,
self.status
)
@classmethod
def force_type(cls, response, environ=None):
"""Enforce that the WSGI response is a response object of the current
type. Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions. If you call :meth:`get_response` on an
exception you will get back a regular :class:`BaseResponse` object, even
if you are using a custom subclass.
This method can enforce a given response type, and it will also
convert arbitrary WSGI callables into response objects if an environ
is provided::
# convert a Werkzeug response object into an instance of the
# MyResponseClass subclass.
response = MyResponseClass.force_type(response)
# convert any WSGI application into a response object
response = MyResponseClass.force_type(response, environ)
This is especially useful if you want to post-process responses in
the main dispatcher and use functionality provided by your subclass.
Keep in mind that this will modify response objects in place if
possible!
:param response: a response object or wsgi application.
:param environ: a WSGI environment object.
:return: a response object.
"""
if not isinstance(response, BaseResponse):
if environ is None:
raise TypeError('cannot convert WSGI application into '
'response objects without an environ')
response = BaseResponse(*_run_wsgi_app(response, environ))
response.__class__ = cls
return response
@classmethod
def from_app(cls, app, environ, buffered=False):
"""Create a new response object from an application output. This
works best if you pass it an application that returns a generator all
the time. Sometimes applications may use the `write()` callable
returned by the `start_response` function. This tries to resolve such
edge cases automatically. But if you don't get the expected output
you should set `buffered` to `True` which enforces buffering.
:param app: the WSGI application to execute.
:param environ: the WSGI environment to execute against.
:param buffered: set to `True` to enforce buffering.
:return: a response object.
"""
return cls(*_run_wsgi_app(app, environ, buffered))
def _get_status_code(self):
return self._status_code
def _set_status_code(self, code):
self._status_code = code
try:
self._status = '%d %s' % (code, HTTP_STATUS_CODES[code].upper())
except KeyError:
self._status = '%d UNKNOWN' % code
status_code = property(_get_status_code, _set_status_code,
doc='The HTTP Status code as number')
del _get_status_code, _set_status_code
def _get_status(self):
return self._status
def _set_status(self, value):
self._status = to_native(value)
try:
self._status_code = int(self._status.split(None, 1)[0])
except ValueError:
self._status_code = 0
self._status = '0 %s' % self._status
status = property(_get_status, _set_status, doc='The HTTP Status code')
del _get_status, _set_status
def get_data(self, as_text=False):
"""The string representation of the request body. Whenever you call
this property the request iterable is encoded and flattened. This
can lead to unwanted behavior if you stream big data.
This behavior can be disabled by setting
:attr:`implicit_sequence_conversion` to `False`.
If `as_text` is set to `True` the return value will be a decoded
unicode string.
.. versionadded:: 0.9
"""
self._ensure_sequence()
rv = b''.join(self.iter_encoded())
if as_text:
rv = rv.decode(self.charset)
return rv
def set_data(self, value):
"""Sets a new string as response. The value set must either by a
unicode or bytestring. If a unicode string is set it's encoded
automatically to the charset of the response (utf-8 by default).
.. versionadded:: 0.9
"""
# if an unicode string is set, it's encoded directly so that we
# can set the content length
if isinstance(value, text_type):
value = value.encode(self.charset)
else:
value = bytes(value)
self.response = [value]
if self.automatically_set_content_length:
self.headers['Content-Length'] = str(len(value))
data = property(get_data, set_data, doc='''
A descriptor that calls :meth:`get_data` and :meth:`set_data`. This
should not be used and will eventually get deprecated.
''')
def calculate_content_length(self):
"""Returns the content length if available or `None` otherwise."""
try:
self._ensure_sequence()
except RuntimeError:
return None
return sum(len(x) for x in self.response)
def _ensure_sequence(self, mutable=False):
"""This method can be called by methods that need a sequence. If
`mutable` is true, it will also ensure that the response sequence
is a standard Python list.
.. versionadded:: 0.6
"""
if self.is_sequence:
# if we need a mutable object, we ensure it's a list.
if mutable and not isinstance(self.response, list):
self.response = list(self.response)
return
if self.direct_passthrough:
raise RuntimeError('Attempted implicit sequence conversion '
'but the response object is in direct '
'passthrough mode.')
if not self.implicit_sequence_conversion:
raise RuntimeError('The response object required the iterable '
'to be a sequence, but the implicit '
'conversion was disabled. Call '
'make_sequence() yourself.')
self.make_sequence()
def make_sequence(self):
"""Converts the response iterator in a list. By default this happens
automatically if required. If `implicit_sequence_conversion` is
disabled, this method is not automatically called and some properties
might raise exceptions. This also encodes all the items.
.. versionadded:: 0.6
"""
if not self.is_sequence:
# if we consume an iterable we have to ensure that the close
# method of the iterable is called if available when we tear
# down the response
close = getattr(self.response, 'close', None)
self.response = list(self.iter_encoded())
if close is not None:
self.call_on_close(close)
def iter_encoded(self):
"""Iter the response encoded with the encoding of the response.
If the response object is invoked as WSGI application the return
value of this method is used as application iterator unless
:attr:`direct_passthrough` was activated.
"""
if __debug__:
_warn_if_string(self.response)
# Encode in a separate function so that self.response is fetched
# early. This allows us to wrap the response with the return
# value from get_app_iter or iter_encoded.
return _iter_encoded(self.response, self.charset)
def set_cookie(self, key, value='', max_age=None, expires=None,
path='/', domain=None, secure=None, httponly=False):
"""Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in the Python standard library but it accepts unicode data, too.
:param key: the key (name) of the cookie to be set.
:param value: the value of the cookie.
:param max_age: should be a number of seconds, or `None` (default) if
the cookie should last only as long as the client's
browser session.
:param expires: should be a `datetime` object or UNIX timestamp.
:param domain: if you want to set a cross-domain cookie. For example,
``domain=".example.com"`` will set a cookie that is
readable by the domain ``www.example.com``,
``foo.example.com`` etc. Otherwise, a cookie will only
be readable by the domain that set it.
:param path: limits the cookie to a given path, per default it will
span the whole domain.
"""
self.headers.add('Set-Cookie', dump_cookie(key, value, max_age,
expires, path, domain, secure, httponly,
self.charset))
def delete_cookie(self, key, path='/', domain=None):
"""Delete a cookie. Fails silently if key doesn't exist.
:param key: the key (name) of the cookie to be deleted.
:param path: if the cookie that should be deleted was limited to a
path, the path has to be defined here.
:param domain: if the cookie that should be deleted was limited to a
domain, that domain has to be defined here.
"""
self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)
@property
def is_streamed(self):
"""If the response is streamed (the response is not an iterable with
a length information) this property is `True`. In this case streamed
means that there is no information about the number of iterations.
This is usually `True` if a generator is passed to the response object.
This is useful for checking before applying some sort of post
filtering that should not take place for streamed responses.
"""
try:
len(self.response)
except (TypeError, AttributeError):
return True
return False
@property
def is_sequence(self):
"""If the iterator is buffered, this property will be `True`. A
response object will consider an iterator to be buffered if the
response attribute is a list or tuple.
.. versionadded:: 0.6
"""
return isinstance(self.response, (tuple, list))
def close(self):
"""Close the wrapped response if possible. You can also use the object
in a with statement which will automatically close it.
.. versionadded:: 0.9
Can now be used in a with statement.
"""
if hasattr(self.response, 'close'):
self.response.close()
for func in self._on_close:
func()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
self.close()
def freeze(self):
"""Call this method if you want to make your response object ready for
being pickled. This buffers the generator if there is one. It will
also set the `Content-Length` header to the length of the body.
.. versionchanged:: 0.6
The `Content-Length` header is now set.
"""
# we explicitly set the length to a list of the *encoded* response
# iterator. Even if the implicit sequence conversion is disabled.
self.response = list(self.iter_encoded())
self.headers['Content-Length'] = str(sum(map(len, self.response)))
def get_wsgi_headers(self, environ):
"""This is automatically called right before the response is started
and returns headers modified for the given environment. It returns a
copy of the headers from the response with some modifications applied
if necessary.
For example the location header (if present) is joined with the root
URL of the environment. Also the content length is automatically set
to zero here for certain status codes.
.. versionchanged:: 0.6
Previously that function was called `fix_headers` and modified
the response object in place. Also since 0.6, IRIs in location
and content-location headers are handled properly.
Also starting with 0.6, Werkzeug will attempt to set the content
length if it is able to figure it out on its own. This is the
case if all the strings in the response iterable are already
encoded and the iterable is buffered.
:param environ: the WSGI environment of the request.
:return: returns a new :class:`~werkzeug.datastructures.Headers`
object.
"""
headers = Headers(self.headers)
location = None
content_location = None
content_length = None
status = self.status_code
# iterate over the headers to find all values in one go. Because
# get_wsgi_headers is used each response that gives us a tiny
# speedup.
for key, value in headers:
ikey = key.lower()
if ikey == u'location':
location = value
elif ikey == u'content-location':
content_location = value
elif ikey == u'content-length':
content_length = value
# make sure the location header is an absolute URL
if location is not None:
old_location = location
if isinstance(location, text_type):
# Safe conversion is necessary here as we might redirect
# to a broken URI scheme (for instance itms-services).
location = iri_to_uri(location, safe_conversion=True)
if self.autocorrect_location_header:
current_url = get_current_url(environ, root_only=True)
if isinstance(current_url, text_type):
current_url = iri_to_uri(current_url)
location = url_join(current_url, location)
if location != old_location:
headers['Location'] = location
# make sure the content location is a URL
if content_location is not None and \
isinstance(content_location, text_type):
headers['Content-Location'] = iri_to_uri(content_location)
# remove entity headers and set content length to zero if needed.
# Also update content_length accordingly so that the automatic
# content length detection does not trigger in the following
# code.
if 100 <= status < 200 or status == 204:
headers['Content-Length'] = content_length = u'0'
elif status == 304:
remove_entity_headers(headers)
# if we can determine the content length automatically, we
# should try to do that. But only if this does not involve
# flattening the iterator or encoding of unicode strings in
# the response. We however should not do that if we have a 304
# response.
if self.automatically_set_content_length and \
self.is_sequence and content_length is None and status != 304:
try:
content_length = sum(len(to_bytes(x, 'ascii'))
for x in self.response)
except UnicodeError:
# aha, something non-bytestringy in there, too bad, we
# can't safely figure out the length of the response.
pass
else:
headers['Content-Length'] = str(content_length)
return headers
def get_app_iter(self, environ):
"""Returns the application iterator for the given environ. Depending
on the request method and the current status code the return value
might be an empty response rather than the one from the response.
If the request method is `HEAD` or the status code is in a range
where the HTTP specification requires an empty response, an empty
iterable is returned.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: a response iterable.
"""
status = self.status_code
if environ['REQUEST_METHOD'] == 'HEAD' or \
100 <= status < 200 or status in (204, 304):
iterable = ()
elif self.direct_passthrough:
if __debug__:
_warn_if_string(self.response)
return self.response
else:
iterable = self.iter_encoded()
return ClosingIterator(iterable, self.close)
def get_wsgi_response(self, environ):
"""Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the request
method in the WSGI environment is ``'HEAD'`` the response will
be empty and only the headers and status code will be present.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: an ``(app_iter, status, headers)`` tuple.
"""
headers = self.get_wsgi_headers(environ)
app_iter = self.get_app_iter(environ)
return app_iter, self.status, headers.to_wsgi_list()
def __call__(self, environ, start_response):
"""Process this response as WSGI application.
:param environ: the WSGI environment.
:param start_response: the response callable provided by the WSGI
server.
:return: an application iterator
"""
app_iter, status, headers = self.get_wsgi_response(environ)
start_response(status, headers)
return app_iter
class AcceptMixin(object):
"""A mixin for classes with an :attr:`~BaseResponse.environ` attribute
to get all the HTTP accept headers as
:class:`~werkzeug.datastructures.Accept` objects (or subclasses
thereof).
"""
@cached_property
def accept_mimetypes(self):
"""List of mimetypes this client supports as
:class:`~werkzeug.datastructures.MIMEAccept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT'), MIMEAccept)
@cached_property
def accept_charsets(self):
"""List of charsets this client supports as
:class:`~werkzeug.datastructures.CharsetAccept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_CHARSET'),
CharsetAccept)
@cached_property
def accept_encodings(self):
"""List of encodings this client accepts. Encodings in a HTTP term
are compression encodings such as gzip. For charsets have a look at
:attr:`accept_charset`.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_ENCODING'))
@cached_property
def accept_languages(self):
"""List of languages this client accepts as
:class:`~werkzeug.datastructures.LanguageAccept` object.
.. versionchanged 0.5
In previous versions this was a regular
:class:`~werkzeug.datastructures.Accept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_LANGUAGE'),
LanguageAccept)
class ETagRequestMixin(object):
"""Add entity tag and cache descriptors to a request object or object with
a WSGI environment available as :attr:`~BaseRequest.environ`. This not
only provides access to etags but also to the cache control header.
"""
@cached_property
def cache_control(self):
"""A :class:`~werkzeug.datastructures.RequestCacheControl` object
for the incoming cache control headers.
"""
cache_control = self.environ.get('HTTP_CACHE_CONTROL')
return parse_cache_control_header(cache_control, None,
RequestCacheControl)
@cached_property
def if_match(self):
"""An object containing all the etags in the `If-Match` header.
:rtype: :class:`~werkzeug.datastructures.ETags`
"""
return parse_etags(self.environ.get('HTTP_IF_MATCH'))
@cached_property
def if_none_match(self):
"""An object containing all the etags in the `If-None-Match` header.
:rtype: :class:`~werkzeug.datastructures.ETags`
"""
return parse_etags(self.environ.get('HTTP_IF_NONE_MATCH'))
@cached_property
def if_modified_since(self):
"""The parsed `If-Modified-Since` header as datetime object."""
return parse_date(self.environ.get('HTTP_IF_MODIFIED_SINCE'))
@cached_property
def if_unmodified_since(self):
"""The parsed `If-Unmodified-Since` header as datetime object."""
return parse_date(self.environ.get('HTTP_IF_UNMODIFIED_SINCE'))
@cached_property
def if_range(self):
"""The parsed `If-Range` header.
.. versionadded:: 0.7
:rtype: :class:`~werkzeug.datastructures.IfRange`
"""
return parse_if_range_header(self.environ.get('HTTP_IF_RANGE'))
@cached_property
def range(self):
"""The parsed `Range` header.
.. versionadded:: 0.7
:rtype: :class:`~werkzeug.datastructures.Range`
"""
return parse_range_header(self.environ.get('HTTP_RANGE'))
class UserAgentMixin(object):
"""Adds a `user_agent` attribute to the request object which contains the
parsed user agent of the browser that triggered the request as a
:class:`~werkzeug.useragents.UserAgent` object.
"""
@cached_property
def user_agent(self):
"""The current user agent."""
from werkzeug.useragents import UserAgent
return UserAgent(self.environ)
class AuthorizationMixin(object):
"""Adds an :attr:`authorization` property that represents the parsed
value of the `Authorization` header as
:class:`~werkzeug.datastructures.Authorization` object.
"""
@cached_property
def authorization(self):
"""The `Authorization` object in parsed form."""
header = self.environ.get('HTTP_AUTHORIZATION')
return parse_authorization_header(header)
class StreamOnlyMixin(object):
"""If mixed in before the request object this will change the bahavior
of it to disable handling of form parsing. This disables the
:attr:`files`, :attr:`form` attributes and will just provide a
:attr:`stream` attribute that however is always available.
.. versionadded:: 0.9
"""
disable_data_descriptor = True
want_form_data_parsed = False
class ETagResponseMixin(object):
"""Adds extra functionality to a response object for etag and cache
handling. This mixin requires an object with at least a `headers`
object that implements a dict like interface similar to
:class:`~werkzeug.datastructures.Headers`.
If you want the :meth:`freeze` method to automatically add an etag, you
have to mixin this method before the response base class. The default
response class does not do that.
"""
@property
def cache_control(self):
"""The Cache-Control general-header field is used to specify
directives that MUST be obeyed by all caching mechanisms along the
request/response chain.
"""
def on_update(cache_control):
if not cache_control and 'cache-control' in self.headers:
del self.headers['cache-control']
elif cache_control:
self.headers['Cache-Control'] = cache_control.to_header()
return parse_cache_control_header(self.headers.get('cache-control'),
on_update,
ResponseCacheControl)
def make_conditional(self, request_or_environ):
"""Make the response conditional to the request. This method works
best if an etag was defined for the response already. The `add_etag`
method can be used to do that. If called without etag just the date
header is set.
This does nothing if the request method in the request or environ is
anything but GET or HEAD.
It does not remove the body of the response because that's something
the :meth:`__call__` function does for us automatically.
Returns self so that you can do ``return resp.make_conditional(req)``
but modifies the object in-place.
:param request_or_environ: a request object or WSGI environment to be
used to make the response conditional
against.
"""
environ = _get_environ(request_or_environ)
if environ['REQUEST_METHOD'] in ('GET', 'HEAD'):
# if the date is not in the headers, add it now. We however
# will not override an already existing header. Unfortunately
# this header will be overriden by many WSGI servers including
# wsgiref.
if 'date' not in self.headers:
self.headers['Date'] = http_date()
if self.automatically_set_content_length and 'content-length' not in self.headers:
length = self.calculate_content_length()
if length is not None:
self.headers['Content-Length'] = length
if not is_resource_modified(environ, self.headers.get('etag'), None,
self.headers.get('last-modified')):
self.status_code = 304
return self
def add_etag(self, overwrite=False, weak=False):
"""Add an etag for the current response if there is none yet."""
if overwrite or 'etag' not in self.headers:
self.set_etag(generate_etag(self.get_data()), weak)
def set_etag(self, etag, weak=False):
"""Set the etag, and override the old one if there was one."""
self.headers['ETag'] = quote_etag(etag, weak)
def get_etag(self):
"""Return a tuple in the form ``(etag, is_weak)``. If there is no
ETag the return value is ``(None, None)``.
"""
return unquote_etag(self.headers.get('ETag'))
def freeze(self, no_etag=False):
"""Call this method if you want to make your response object ready for
pickeling. This buffers the generator if there is one. This also
sets the etag unless `no_etag` is set to `True`.
"""
if not no_etag:
self.add_etag()
super(ETagResponseMixin, self).freeze()
accept_ranges = header_property('Accept-Ranges', doc='''
The `Accept-Ranges` header. Even though the name would indicate
that multiple values are supported, it must be one string token only.
The values ``'bytes'`` and ``'none'`` are common.
.. versionadded:: 0.7''')
def _get_content_range(self):
def on_update(rng):
if not rng:
del self.headers['content-range']
else:
self.headers['Content-Range'] = rng.to_header()
rv = parse_content_range_header(self.headers.get('content-range'),
on_update)
# always provide a content range object to make the descriptor
# more user friendly. It provides an unset() method that can be
# used to remove the header quickly.
if rv is None:
rv = ContentRange(None, None, None, on_update=on_update)
return rv
def _set_content_range(self, value):
if not value:
del self.headers['content-range']
elif isinstance(value, string_types):
self.headers['Content-Range'] = value
else:
self.headers['Content-Range'] = value.to_header()
content_range = property(_get_content_range, _set_content_range, doc='''
The `Content-Range` header as
:class:`~werkzeug.datastructures.ContentRange` object. Even if the
header is not set it wil provide such an object for easier
manipulation.
.. versionadded:: 0.7''')
del _get_content_range, _set_content_range
class ResponseStream(object):
"""A file descriptor like object used by the :class:`ResponseStreamMixin` to
represent the body of the stream. It directly pushes into the response
iterable of the response object.
"""
mode = 'wb+'
def __init__(self, response):
self.response = response
self.closed = False
def write(self, value):
if self.closed:
raise ValueError('I/O operation on closed file')
self.response._ensure_sequence(mutable=True)
self.response.response.append(value)
self.response.headers.pop('Content-Length', None)
def writelines(self, seq):
for item in seq:
self.write(item)
def close(self):
self.closed = True
def flush(self):
if self.closed:
raise ValueError('I/O operation on closed file')
def isatty(self):
if self.closed:
raise ValueError('I/O operation on closed file')
return False
@property
def encoding(self):
return self.response.charset
class ResponseStreamMixin(object):
"""Mixin for :class:`BaseRequest` subclasses. Classes that inherit from
this mixin will automatically get a :attr:`stream` property that provides
a write-only interface to the response iterable.
"""
@cached_property
def stream(self):
"""The response iterable as write-only stream."""
return ResponseStream(self)
class CommonRequestDescriptorsMixin(object):
"""A mixin for :class:`BaseRequest` subclasses. Request objects that
mix this class in will automatically get descriptors for a couple of
HTTP headers with automatic type conversion.
.. versionadded:: 0.5
"""
content_type = environ_property('CONTENT_TYPE', doc='''
The Content-Type entity-header field indicates the media type of
the entity-body sent to the recipient or, in the case of the HEAD
method, the media type that would have been sent had the request
been a GET.''')
@cached_property
def content_length(self):
"""The Content-Length entity-header field indicates the size of the
entity-body in bytes or, in the case of the HEAD method, the size of
the entity-body that would have been sent had the request been a
GET.
"""
return get_content_length(self.environ)
content_encoding = environ_property('HTTP_CONTENT_ENCODING', doc='''
The Content-Encoding entity-header field is used as a modifier to the
media-type. When present, its value indicates what additional content
codings have been applied to the entity-body, and thus what decoding
mechanisms must be applied in order to obtain the media-type
referenced by the Content-Type header field.
.. versionadded:: 0.9''')
content_md5 = environ_property('HTTP_CONTENT_MD5', doc='''
The Content-MD5 entity-header field, as defined in RFC 1864, is an
MD5 digest of the entity-body for the purpose of providing an
end-to-end message integrity check (MIC) of the entity-body. (Note:
a MIC is good for detecting accidental modification of the
entity-body in transit, but is not proof against malicious attacks.)
.. versionadded:: 0.9''')
referrer = environ_property('HTTP_REFERER', doc='''
The Referer[sic] request-header field allows the client to specify,
for the server's benefit, the address (URI) of the resource from which
the Request-URI was obtained (the "referrer", although the header
field is misspelled).''')
date = environ_property('HTTP_DATE', None, parse_date, doc='''
The Date general-header field represents the date and time at which
the message was originated, having the same semantics as orig-date
in RFC 822.''')
max_forwards = environ_property('HTTP_MAX_FORWARDS', None, int, doc='''
The Max-Forwards request-header field provides a mechanism with the
TRACE and OPTIONS methods to limit the number of proxies or gateways
that can forward the request to the next inbound server.''')
def _parse_content_type(self):
if not hasattr(self, '_parsed_content_type'):
self._parsed_content_type = \
parse_options_header(self.environ.get('CONTENT_TYPE', ''))
@property
def mimetype(self):
"""Like :attr:`content_type` but without parameters (eg, without
charset, type etc.). For example if the content
type is ``text/html; charset=utf-8`` the mimetype would be
``'text/html'``.
"""
self._parse_content_type()
return self._parsed_content_type[0]
@property
def mimetype_params(self):
"""The mimetype parameters as dict. For example if the content
type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
"""
self._parse_content_type()
return self._parsed_content_type[1]
@cached_property
def pragma(self):
"""The Pragma general-header field is used to include
implementation-specific directives that might apply to any recipient
along the request/response chain. All pragma directives specify
optional behavior from the viewpoint of the protocol; however, some
systems MAY require that behavior be consistent with the directives.
"""
return parse_set_header(self.environ.get('HTTP_PRAGMA', ''))
class CommonResponseDescriptorsMixin(object):
"""A mixin for :class:`BaseResponse` subclasses. Response objects that
mix this class in will automatically get descriptors for a couple of
HTTP headers with automatic type conversion.
"""
def _get_mimetype(self):
ct = self.headers.get('content-type')
if ct:
return ct.split(';')[0].strip()
def _set_mimetype(self, value):
self.headers['Content-Type'] = get_content_type(value, self.charset)
def _get_mimetype_params(self):
def on_update(d):
self.headers['Content-Type'] = \
dump_options_header(self.mimetype, d)
d = parse_options_header(self.headers.get('content-type', ''))[1]
return CallbackDict(d, on_update)
mimetype = property(_get_mimetype, _set_mimetype, doc='''
The mimetype (content type without charset etc.)''')
mimetype_params = property(_get_mimetype_params, doc='''
The mimetype parameters as dict. For example if the content
type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
.. versionadded:: 0.5
''')
location = header_property('Location', doc='''
The Location response-header field is used to redirect the recipient
to a location other than the Request-URI for completion of the request
or identification of a new resource.''')
age = header_property('Age', None, parse_date, http_date, doc='''
The Age response-header field conveys the sender's estimate of the
amount of time since the response (or its revalidation) was
generated at the origin server.
Age values are non-negative decimal integers, representing time in
seconds.''')
content_type = header_property('Content-Type', doc='''
The Content-Type entity-header field indicates the media type of the
entity-body sent to the recipient or, in the case of the HEAD method,
the media type that would have been sent had the request been a GET.
''')
content_length = header_property('Content-Length', None, int, str, doc='''
The Content-Length entity-header field indicates the size of the
entity-body, in decimal number of OCTETs, sent to the recipient or,
in the case of the HEAD method, the size of the entity-body that would
have been sent had the request been a GET.''')
content_location = header_property('Content-Location', doc='''
The Content-Location entity-header field MAY be used to supply the
resource location for the entity enclosed in the message when that
entity is accessible from a location separate from the requested
resource's URI.''')
content_encoding = header_property('Content-Encoding', doc='''
The Content-Encoding entity-header field is used as a modifier to the
media-type. When present, its value indicates what additional content
codings have been applied to the entity-body, and thus what decoding
mechanisms must be applied in order to obtain the media-type
referenced by the Content-Type header field.''')
content_md5 = header_property('Content-MD5', doc='''
The Content-MD5 entity-header field, as defined in RFC 1864, is an
MD5 digest of the entity-body for the purpose of providing an
end-to-end message integrity check (MIC) of the entity-body. (Note:
a MIC is good for detecting accidental modification of the
entity-body in transit, but is not proof against malicious attacks.)
''')
date = header_property('Date', None, parse_date, http_date, doc='''
The Date general-header field represents the date and time at which
the message was originated, having the same semantics as orig-date
in RFC 822.''')
expires = header_property('Expires', None, parse_date, http_date, doc='''
The Expires entity-header field gives the date/time after which the
response is considered stale. A stale cache entry may not normally be
returned by a cache.''')
last_modified = header_property('Last-Modified', None, parse_date,
http_date, doc='''
The Last-Modified entity-header field indicates the date and time at
which the origin server believes the variant was last modified.''')
def _get_retry_after(self):
value = self.headers.get('retry-after')
if value is None:
return
elif value.isdigit():
return datetime.utcnow() + timedelta(seconds=int(value))
return parse_date(value)
def _set_retry_after(self, value):
if value is None:
if 'retry-after' in self.headers:
del self.headers['retry-after']
return
elif isinstance(value, datetime):
value = http_date(value)
else:
value = str(value)
self.headers['Retry-After'] = value
retry_after = property(_get_retry_after, _set_retry_after, doc='''
The Retry-After response-header field can be used with a 503 (Service
Unavailable) response to indicate how long the service is expected
to be unavailable to the requesting client.
Time in seconds until expiration or date.''')
def _set_property(name, doc=None):
def fget(self):
def on_update(header_set):
if not header_set and name in self.headers:
del self.headers[name]
elif header_set:
self.headers[name] = header_set.to_header()
return parse_set_header(self.headers.get(name), on_update)
def fset(self, value):
if not value:
del self.headers[name]
elif isinstance(value, string_types):
self.headers[name] = value
else:
self.headers[name] = dump_header(value)
return property(fget, fset, doc=doc)
vary = _set_property('Vary', doc='''
The Vary field value indicates the set of request-header fields that
fully determines, while the response is fresh, whether a cache is
permitted to use the response to reply to a subsequent request
without revalidation.''')
content_language = _set_property('Content-Language', doc='''
The Content-Language entity-header field describes the natural
language(s) of the intended audience for the enclosed entity. Note
that this might not be equivalent to all the languages used within
the entity-body.''')
allow = _set_property('Allow', doc='''
The Allow entity-header field lists the set of methods supported
by the resource identified by the Request-URI. The purpose of this
field is strictly to inform the recipient of valid methods
associated with the resource. An Allow header field MUST be
present in a 405 (Method Not Allowed) response.''')
del _set_property, _get_mimetype, _set_mimetype, _get_retry_after, \
_set_retry_after
class WWWAuthenticateMixin(object):
"""Adds a :attr:`www_authenticate` property to a response object."""
@property
def www_authenticate(self):
"""The `WWW-Authenticate` header in a parsed form."""
def on_update(www_auth):
if not www_auth and 'www-authenticate' in self.headers:
del self.headers['www-authenticate']
elif www_auth:
self.headers['WWW-Authenticate'] = www_auth.to_header()
header = self.headers.get('www-authenticate')
return parse_www_authenticate_header(header, on_update)
class Request(BaseRequest, AcceptMixin, ETagRequestMixin,
UserAgentMixin, AuthorizationMixin,
CommonRequestDescriptorsMixin):
"""Full featured request object implementing the following mixins:
- :class:`AcceptMixin` for accept header parsing
- :class:`ETagRequestMixin` for etag and cache control handling
- :class:`UserAgentMixin` for user agent introspection
- :class:`AuthorizationMixin` for http auth handling
- :class:`CommonRequestDescriptorsMixin` for common headers
"""
class PlainRequest(StreamOnlyMixin, Request):
"""A request object without special form parsing capabilities.
.. versionadded:: 0.9
"""
class Response(BaseResponse, ETagResponseMixin, ResponseStreamMixin,
CommonResponseDescriptorsMixin,
WWWAuthenticateMixin):
"""Full featured response object implementing the following mixins:
- :class:`ETagResponseMixin` for etag and cache control handling
- :class:`ResponseStreamMixin` to add support for the `stream` property
- :class:`CommonResponseDescriptorsMixin` for various HTTP descriptors
- :class:`WWWAuthenticateMixin` for HTTP authentication support
"""
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
21148,
272,
18294,
94,
339,
710,
17995,
787,
3486,
1056,
436,
1177,
2251,
1314,
1265,
883,
272,
5516,
370,
886,
15685,
1265,
2934,
3062,
370,
886,
14,
221,
710,
1056,
909,
3509,
272,
314,
2556,
29818,
701,
314,
1890,
334,
1129,
29063,
9,
436,
314,
1177,
272,
909,
3509,
1006,
314,
2556,
4847,
1771,
370,
314,
7042,
14,
339,
1626,
11012,
10093,
365,
626,
314,
1056,
909,
365,
2737,
543,
314,
9279,
272,
6160,
436,
911,
2454,
465,
4721,
13,
1896,
4566,
29781,
314,
1177,
909,
365,
376,
272,
3503,
9279,
4223,
14,
339,
16485,
8137,
587,
315,
22798,
3520,
2251,
911,
1736,
6657,
543,
272,
2649,
666,
14,
221,
1010,
7909,
1824,
666,
4565,
701,
314,
1177,
909,
911,
506,
272,
11203,
1901,
376,
2649,
909,
340,
3962,
436,
340,
652,
7704,
12249,
14,
2378,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
10380,
14,
1014,
492,
3101,
63,
6305,
63,
15639,
12,
971,
1362,
2198,
63,
5694,
63,
1291,
12,
2198,
63,
1637,
63,
2785,
63,
1291,
12,
2198,
63,
1841,
458,
12,
971,
1362,
2198,
63,
602,
12,
3550,
63,
11304,
12,
365,
63,
1927,
63,
5540,
12,
14342,
63,
11304,
12,
971,
1362,
6313,
63,
11304,
12,
2198,
63,
409,
63,
1291,
12,
2198,
63,
15846,
63,
1291,
12,
971,
1362,
2198,
63,
1544,
63,
13975,
63,
1291,
12,
2813,
63,
4502,
63,
2139,
12,
971,
1362,
2198,
63,
1419,
63,
1291,
12,
5461,
63,
1419,
63,
1291,
12,
1455,
63,
602,
12,
971,
1362,
2198,
63,
692,
63,
1842,
63,
1291,
12,
2198,
63,
5306,
12,
5461,
63,
5306,
12,
971,
1362,
2198,
63,
1842,
63,
1291,
12,
2198,
63,
1317,
63,
1842,
63,
1291,
12,
5461,
63,
1291,
199,
504,
10380,
14,
3603,
492,
1166,
63,
2708,
12,
24086,
63,
475,
63,
2302,
12,
1166,
63,
904,
199,
504,
10380,
14,
509,
311,
285,
332,
492,
8204,
1451,
2842,
12,
849,
63,
1745,
63,
3702,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
12,
6160,
63,
1829,
12,
971,
1362,
1406,
63,
1829,
12,
664,
63,
1317,
63,
466,
199,
504,
10380,
14,
6508,
492,
664,
63,
1818,
63,
633,
12,
664,
63,
1102,
12,
971,
1362,
5980,
1044,
3585,
12,
664,
63,
1210,
63,
1745,
12,
664,
63,
1317,
63,
1267,
199,
504,
10380,
14,
23004,
492,
29393,
12,
22170,
379,
21365,
12,
21391,
12,
971,
1362,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
12,
971,
1362,
25609,
1296,
12,
14735,
8422,
12,
29392,
8422,
12,
8466,
8422,
12,
971,
1362,
7232,
4437,
3717,
12,
4784,
4437,
3717,
12,
17555,
2141,
12,
971,
1362,
6646,
4709,
12,
2740,
63,
3029,
63,
1744,
199,
504,
10380,
423,
4672,
492,
485,
362,
63,
2314,
199,
504,
10380,
423,
5819,
492,
370,
63,
2394,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
1362,
3000,
63,
1313,
12,
12464,
63,
12796,
63,
20327,
12,
12464,
63,
362,
63,
2394,
12,
971,
1362,
370,
63,
2975,
12,
370,
63,
6106,
12,
11808,
421,
199,
318,
485,
1065,
63,
6508,
63,
571,
2031,
589,
304,
272,
408,
2765,
805,
19058,
6337,
370,
4868,
626,
314,
511,
859,
365,
440,
272,
8439,
7444,
1415,
14,
221,
3506,
2845,
4815,
1,
272,
408,
272,
2288,
485,
1065,
63,
6508,
63,
571,
272,
687,
10380,
14,
396,
492,
1255,
63,
6508,
63,
571,
465,
485,
1065,
63,
6508,
63,
571,
272,
372,
485,
1065,
63,
6508,
63,
571,
2031,
589,
9,
421,
199,
318,
485,
4050,
63,
692,
63,
875,
8,
8147,
304,
272,
408,
4433,
367,
314,
1177,
2251,
370,
1104,
340,
314,
6076,
2138,
272,
370,
314,
9279,
1654,
365,
440,
282,
1059,
14,
272,
408,
272,
340,
1228,
8,
8147,
12,
1059,
63,
1313,
304,
267,
687,
3598,
492,
7987,
267,
7987,
8,
3849,
360,
1310,
6076,
1990,
663,
370,
282,
1059,
14,
221,
961,
11337,
283,
2151,
283,
475,
1736,
1325,
4910,
626,
314,
1654,
911,
3222,
314,
283,
2151,
283,
576,
370,
314,
1890,
1495,
12,
701,
1495,
14,
221,
961,
365,
18871,
283,
2151,
283,
18178,
11619,
5953,
12,
675,
1177,
14,
576,
370,
5090,
283,
2151,
283,
5465,
370,
314,
1177,
909,
8038,
13232,
29,
18,
9,
421,
199,
318,
485,
479,
63,
1397,
63,
609,
3306,
8,
1069,
304,
272,
340,
1056,
14,
609,
3306,
26,
267,
746,
6064,
360,
33,
23834,
1056,
16416,
370,
9451,
283,
2574,
283,
964,
666,
14,
221,
982,
1265,
7710,
2934,
370,
886,
283,
2574,
283,
9099,
12,
663,
658,
609,
3306,
64,
370,
756,
2659,
421,
199,
318,
485,
1661,
63,
8167,
8,
8147,
12,
5960,
304,
272,
367,
1242,
315,
6076,
26,
267,
340,
1228,
8,
1053,
12,
1318,
63,
466,
304,
288,
1995,
1242,
14,
2143,
8,
6043,
9,
267,
587,
26,
288,
1995,
1242,
421,
199,
533,
3523,
2017,
8,
785,
304,
272,
408,
54,
994,
5678,
1056,
909,
14,
221,
961,
1630,
440,
5669,
19472,
8292,
2839,
272,
4642,
1947,
6057,
503,
2581,
13467,
14,
221,
710,
1056,
909,
365,
2737,
543,
272,
314,
9279,
3734,
465,
1642,
1423,
436,
911,
1050,
6337,
370,
314,
9279,
272,
3734,
465,
12692,
17719,
14,
1069,
14700,
7444,
652,
1159,
2737,
543,
272,
658,
13817,
63,
1069,
64,
663,
370,
756,
14,
339,
6006,
787,
282,
17535,
402,
13667,
3617,
2808,
626,
1050,
4722,
9330,
272,
370,
314,
1056,
909,
12,
2337,
365,
2597,
282,
1021,
2797,
658,
2017,
64,
1314,
272,
9180,
658,
1563,
2017,
64,
436,
1006,
314,
11012,
13667,
3617,
14,
339,
2779,
1159,
282,
6954,
16819,
370,
1218,
282,
3537,
5516,
402,
314,
520,
533,
1705,
1563,
2017,
64,
272,
436,
1050,
4124,
9330,
1902,
4799,
13667,
3617,
503,
4125,
4514,
14,
272,
11842,
376,
2893,
367,
4066,
9180,
447,
398,
687,
10380,
14,
21148,
492,
3523,
2017,
12,
662,
1931,
2017,
4256,
398,
1021
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
21148,
272,
18294,
94,
339,
710,
17995,
787,
3486,
1056,
436,
1177,
2251,
1314,
1265,
883,
272,
5516,
370,
886,
15685,
1265,
2934,
3062,
370,
886,
14,
221,
710,
1056,
909,
3509,
272,
314,
2556,
29818,
701,
314,
1890,
334,
1129,
29063,
9,
436,
314,
1177,
272,
909,
3509,
1006,
314,
2556,
4847,
1771,
370,
314,
7042,
14,
339,
1626,
11012,
10093,
365,
626,
314,
1056,
909,
365,
2737,
543,
314,
9279,
272,
6160,
436,
911,
2454,
465,
4721,
13,
1896,
4566,
29781,
314,
1177,
909,
365,
376,
272,
3503,
9279,
4223,
14,
339,
16485,
8137,
587,
315,
22798,
3520,
2251,
911,
1736,
6657,
543,
272,
2649,
666,
14,
221,
1010,
7909,
1824,
666,
4565,
701,
314,
1177,
909,
911,
506,
272,
11203,
1901,
376,
2649,
909,
340,
3962,
436,
340,
652,
7704,
12249,
14,
2378,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
10380,
14,
1014,
492,
3101,
63,
6305,
63,
15639,
12,
971,
1362,
2198,
63,
5694,
63,
1291,
12,
2198,
63,
1637,
63,
2785,
63,
1291,
12,
2198,
63,
1841,
458,
12,
971,
1362,
2198,
63,
602,
12,
3550,
63,
11304,
12,
365,
63,
1927,
63,
5540,
12,
14342,
63,
11304,
12,
971,
1362,
6313,
63,
11304,
12,
2198,
63,
409,
63,
1291,
12,
2198,
63,
15846,
63,
1291,
12,
971,
1362,
2198,
63,
1544,
63,
13975,
63,
1291,
12,
2813,
63,
4502,
63,
2139,
12,
971,
1362,
2198,
63,
1419,
63,
1291,
12,
5461,
63,
1419,
63,
1291,
12,
1455,
63,
602,
12,
971,
1362,
2198,
63,
692,
63,
1842,
63,
1291,
12,
2198,
63,
5306,
12,
5461,
63,
5306,
12,
971,
1362,
2198,
63,
1842,
63,
1291,
12,
2198,
63,
1317,
63,
1842,
63,
1291,
12,
5461,
63,
1291,
199,
504,
10380,
14,
3603,
492,
1166,
63,
2708,
12,
24086,
63,
475,
63,
2302,
12,
1166,
63,
904,
199,
504,
10380,
14,
509,
311,
285,
332,
492,
8204,
1451,
2842,
12,
849,
63,
1745,
63,
3702,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
12,
6160,
63,
1829,
12,
971,
1362,
1406,
63,
1829,
12,
664,
63,
1317,
63,
466,
199,
504,
10380,
14,
6508,
492,
664,
63,
1818,
63,
633,
12,
664,
63,
1102,
12,
971,
1362,
5980,
1044,
3585,
12,
664,
63,
1210,
63,
1745,
12,
664,
63,
1317,
63,
1267,
199,
504,
10380,
14,
23004,
492,
29393,
12,
22170,
379,
21365,
12,
21391,
12,
971,
1362,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
12,
971,
1362,
25609,
1296,
12,
14735,
8422,
12,
29392,
8422,
12,
8466,
8422,
12,
971,
1362,
7232,
4437,
3717,
12,
4784,
4437,
3717,
12,
17555,
2141,
12,
971,
1362,
6646,
4709,
12,
2740,
63,
3029,
63,
1744,
199,
504,
10380,
423,
4672,
492,
485,
362,
63,
2314,
199,
504,
10380,
423,
5819,
492,
370,
63,
2394,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
1362,
3000,
63,
1313,
12,
12464,
63,
12796,
63,
20327,
12,
12464,
63,
362,
63,
2394,
12,
971,
1362,
370,
63,
2975,
12,
370,
63,
6106,
12,
11808,
421,
199,
318,
485,
1065,
63,
6508,
63,
571,
2031,
589,
304,
272,
408,
2765,
805,
19058,
6337,
370,
4868,
626,
314,
511,
859,
365,
440,
272,
8439,
7444,
1415,
14,
221,
3506,
2845,
4815,
1,
272,
408,
272,
2288,
485,
1065,
63,
6508,
63,
571,
272,
687,
10380,
14,
396,
492,
1255,
63,
6508,
63,
571,
465,
485,
1065,
63,
6508,
63,
571,
272,
372,
485,
1065,
63,
6508,
63,
571,
2031,
589,
9,
421,
199,
318,
485,
4050,
63,
692,
63,
875,
8,
8147,
304,
272,
408,
4433,
367,
314,
1177,
2251,
370,
1104,
340,
314,
6076,
2138,
272,
370,
314,
9279,
1654,
365,
440,
282,
1059,
14,
272,
408,
272,
340,
1228,
8,
8147,
12,
1059,
63,
1313,
304,
267,
687,
3598,
492,
7987,
267,
7987,
8,
3849,
360,
1310,
6076,
1990,
663,
370,
282,
1059,
14,
221,
961,
11337,
283,
2151,
283,
475,
1736,
1325,
4910,
626,
314,
1654,
911,
3222,
314,
283,
2151,
283,
576,
370,
314,
1890,
1495,
12,
701,
1495,
14,
221,
961,
365,
18871,
283,
2151,
283,
18178,
11619,
5953,
12,
675,
1177,
14,
576,
370,
5090,
283,
2151,
283,
5465,
370,
314,
1177,
909,
8038,
13232,
29,
18,
9,
421,
199,
318,
485,
479,
63,
1397,
63,
609,
3306,
8,
1069,
304,
272,
340,
1056,
14,
609,
3306,
26,
267,
746,
6064,
360,
33,
23834,
1056,
16416,
370,
9451,
283,
2574,
283,
964,
666,
14,
221,
982,
1265,
7710,
2934,
370,
886,
283,
2574,
283,
9099,
12,
663,
658,
609,
3306,
64,
370,
756,
2659,
421,
199,
318,
485,
1661,
63,
8167,
8,
8147,
12,
5960,
304,
272,
367,
1242,
315,
6076,
26,
267,
340,
1228,
8,
1053,
12,
1318,
63,
466,
304,
288,
1995,
1242,
14,
2143,
8,
6043,
9,
267,
587,
26,
288,
1995,
1242,
421,
199,
533,
3523,
2017,
8,
785,
304,
272,
408,
54,
994,
5678,
1056,
909,
14,
221,
961,
1630,
440,
5669,
19472,
8292,
2839,
272,
4642,
1947,
6057,
503,
2581,
13467,
14,
221,
710,
1056,
909,
365,
2737,
543,
272,
314,
9279,
3734,
465,
1642,
1423,
436,
911,
1050,
6337,
370,
314,
9279,
272,
3734,
465,
12692,
17719,
14,
1069,
14700,
7444,
652,
1159,
2737,
543,
272,
658,
13817,
63,
1069,
64,
663,
370,
756,
14,
339,
6006,
787,
282,
17535,
402,
13667,
3617,
2808,
626,
1050,
4722,
9330,
272,
370,
314,
1056,
909,
12,
2337,
365,
2597,
282,
1021,
2797,
658,
2017,
64,
1314,
272,
9180,
658,
1563,
2017,
64,
436,
1006,
314,
11012,
13667,
3617,
14,
339,
2779,
1159,
282,
6954,
16819,
370,
1218,
282,
3537,
5516,
402,
314,
520,
533,
1705,
1563,
2017,
64,
272,
436,
1050,
4124,
9330,
1902,
4799,
13667,
3617,
503,
4125,
4514,
14,
272,
11842,
376,
2893,
367,
4066,
9180,
447,
398,
687,
10380,
14,
21148,
492,
3523,
2017,
12,
662,
1931,
2017,
4256,
398,
1021,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
siggame/server
|
game_utils.py
|
1
|
7951
|
import random
from functools import wraps
from heapq import heappop, heappush
from math import ceil
from os import listdir
from os.path import isfile, join
class Grid(object):
def __init__(self, game, type, dimensions = ('x', 'y')):
self.game = game
self.type = type
self.grid = {}
self.dimensions = dimensions
def generate(self, x, y):
for i in range(x):
for j in range(y):
values = {self.dimensions[0]: i,
self.dimensions[1]: j}
self.grid[i, j] = self.type(self.game, **values)
def populate(self):
objects = getattr(self.game, self.type._plural)
for i in objects:
coordinate = tuple(getattr(i, key) for key in self.dimensions)
self.grid[coordinate] = i
def __getitem__(self, key):
return self.grid.get(key, None)
class TileMapGenerator(object):
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
self.value = ' '
def __init__(self, game, width=20, height=20):
self.game = game
self.width = width
self.height = height
self.grid = {}
self.init_grid()
self.load_tiles()
def generate(self):
self.lay_tiles()
def init_grid(self):
for i in range(self.width):
for j in range(self.height):
self.grid[i, j] = self.Point(i, j)
def load_tiles(self):
#TODO: Load tiles
directory = join('plugins', self.game._name, 'config', 'tiles')
files = [ f for f in listdir(directory) if isfile(join(directory,f)) ]
self.tiles = []
for f in files:
map = open(join(directory, f)).readlines()
map = [[j for j in i[:len(map)]] for i in map]
self.tiles.append(map)
def lay_tiles(self):
#super deep loop go!
tile_size = len(self.tiles[0])
width = int(ceil(self.width / tile_size / 2))
height = int(ceil(self.height / tile_size))
for i in range(width):
for j in range(height):
t = random.choice(self.tiles)
#transform the tile for variety
#transpose
if random.randint(0, 1):
t = map(list, zip(*t))
#flip columns
if random.randint(0, 1):
t = reversed(t)
flip_rows = random.randint(0, 1)
for k, row in enumerate(t):
#flip rows
if flip_rows:
row = reversed(row)
for l, col in enumerate(row):
x = i * tile_size + k
y = j * tile_size + l
tile = self.grid[x, y]
other_tile = self.grid[self.width - x - 1, y]
tile.value = other_tile.value = col
def connect_map(self, connect = ' '):
while True:
tiles = [i for i in self.grid.values() if i.value in connect]
tile = random.choice(tiles)
c = self._find_connected(tile, connect)
if len(c) == len(tiles):
return
walls = [i for i in self.grid.values() if i.value not in connect]
wall = random.choice(walls)
other_wall = self.grid[self.width - wall.x - 1, wall.y]
wall.value = other_wall.value =connect[0]
def _find_connected(self, tile, connect):
open = [(tile.x, tile.y)]
connected = set()
while open:
t = open.pop()
x, y = t
for i, j in [ (x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
if 0 <= i < self.width and 0 <= j < self.height:
tile = self.grid[i, j]
if (i, j) not in connected and tile.value in connect:
connected.add((i, j))
open.append((i, j))
return connected
def sprinkle(self, num, value, onto=' ', max_x = None):
for i in range(num):
tiles = [i for i in self.grid.values() if i.value in onto]
if max_x is not None:
tiles = [i for i in tiles if i.x <= max_x]
if not tiles:
return
tile = random.choice(tiles)
other_tile = self.grid[self.width - tile.x - 1, tile.y]
tile.value = other_tile.value = value
def __repr__(self):
print self.width, self.height
val = ''
for y in range(self.height):
for x in range(self.width):
val += self.grid[x, y].value
val += '\n'
return val
def __iter__(self):
for y in range(self.height):
for x in range(self.width):
yield self.grid[x, y]
class PathFinder():
def h_score(self, current, dest):
return self.distance(current[0], current[1], dest[0], dest[1])
def get_adjacent(self, source):
return []
def find_path(self, source, dest):
closed = {source: None}
if source == dest:
return [source]
# 0 = f, 1 = current (x,y), 2 = g
open = [ (self.h_score(source, dest), source, 0) ]
while len(open) > 0:
h, point, g = heappop(open)
for neighbor in self.get_adjacent(point):
if neighbor in closed:
continue
closed[neighbor] = point
if neighbor == dest:
return self.make_path(closed, dest)
heappush(open, (g+1+self.hscore(neighbor, dest),
neighbor, g+1) )
return None
def make_path(self, closed, dest):
current = dest
path = [current]
while closed[current]:
current = closed[current]
path.append(current)
return reversed(path)
def distance(self, x1, y1, x2, y2):
return abs(x2-x1) + abs(y2-y1)
def takes(**types):
def inner(func):
@wraps(func)
def func_wrapper(self, **kwargs):
errors = []
for i, j in kwargs.items():
if i not in types:
errors.append("%s is an illegal parameter" % i)
continue
if callable(types[i]):
try:
j = types[i](j)
kwargs[i] = j
except ValueError:
errors.append("%s should be a %s, (received %s)" %
(i, types[i].__name__, j.__class__.__name__))
elif isinstance(types[i], basestring):
if types[i] not in self.game._object_types:
print("{} for argument {} of {} not found in game types".
format(types[i], i, func.__name__))
continue
if j not in self.game.objects:
errors.append("object {} for {} does not exist".format(j, i))
continue
j = self.game.objects[j]
if not isinstance(j, types[i]):
errors.append("object {} for {} does is not {}".
format(j, i, types[i]))
for i in types:
if i not in kwargs:
errors.append("%s expected but not received" % i)
if errors:
return {'type': 'failure',
'args': {
'message': '\n'.join(errors)
}
}
return func(self, **kwargs)
return func_wrapper
return inner
def success(**args):
return {'type': 'success', 'args': args}
def failure(**args):
return {'type': 'failure', 'args': args}
|
bsd-3-clause
|
[
646,
2196,
199,
199,
504,
9143,
492,
14018,
199,
504,
13295,
81,
492,
946,
571,
411,
12,
946,
571,
2084,
199,
504,
3473,
492,
30449,
199,
504,
747,
492,
27483,
199,
504,
747,
14,
515,
492,
29214,
12,
4263,
199,
199,
533,
16386,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
9219,
12,
730,
12,
7365,
275,
661,
88,
297,
283,
89,
8109,
267,
291,
14,
5097,
275,
9219,
267,
291,
14,
466,
275,
730,
267,
291,
14,
3825,
275,
1052,
267,
291,
14,
13320,
275,
7365,
339,
347,
3550,
8,
277,
12,
671,
12,
612,
304,
267,
367,
284,
315,
1425,
8,
88,
304,
288,
367,
1335,
315,
1425,
8,
89,
304,
355,
1338,
275,
469,
277,
14,
13320,
59,
16,
2189,
284,
12,
717,
291,
14,
13320,
59,
17,
2189,
1335,
93,
355,
291,
14,
3825,
59,
73,
12,
1335,
61,
275,
291,
14,
466,
8,
277,
14,
5097,
12,
1011,
1459,
9,
339,
347,
13904,
8,
277,
304,
267,
2251,
275,
2519,
8,
277,
14,
5097,
12,
291,
14,
466,
423,
10019,
9,
267,
367,
284,
315,
2251,
26,
288,
10021,
275,
2008,
8,
5675,
8,
73,
12,
790,
9,
367,
790,
315,
291,
14,
13320,
9,
288,
291,
14,
3825,
59,
20493,
61,
275,
284,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
14,
3825,
14,
362,
8,
498,
12,
488,
9,
199,
199,
533,
377,
441,
2956,
7599,
8,
785,
304,
272,
1021,
7584,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
671,
12,
612,
304,
288,
291,
14,
88,
275,
671,
288,
291,
14,
89,
275,
612,
288,
291,
14,
585,
275,
283,
283,
339,
347,
636,
826,
721,
277,
12,
9219,
12,
3462,
29,
1165,
12,
4569,
29,
1165,
304,
267,
291,
14,
5097,
275,
9219,
267,
291,
14,
2063,
275,
3462,
267,
291,
14,
3333,
275,
4569,
267,
291,
14,
3825,
275,
1052,
267,
291,
14,
826,
63,
3825,
342,
267,
291,
14,
912,
63,
18819,
342,
339,
347,
3550,
8,
277,
304,
267,
291,
14,
817,
63,
18819,
342,
339,
347,
4205,
63,
3825,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
277,
14,
2063,
304,
288,
367,
1335,
315,
1425,
8,
277,
14,
3333,
304,
355,
291,
14,
3825,
59,
73,
12,
1335,
61,
275,
291,
14,
3428,
8,
73,
12,
1335,
9,
2378,
347,
2248,
63,
18819,
8,
277,
304,
267,
327,
11768,
26,
7190,
30419,
267,
2082,
275,
4263,
360,
5265,
297,
291,
14,
5097,
423,
354,
12,
283,
888,
297,
283,
18819,
358,
267,
1584,
275,
359,
289,
367,
289,
315,
27483,
8,
3619,
9,
340,
29214,
8,
904,
8,
3619,
12,
70,
430,
1622,
267,
291,
14,
18819,
275,
942,
267,
367,
289,
315,
1584,
26,
288,
2341,
275,
1551,
8,
904,
8,
3619,
12,
289,
4992,
9684,
342,
288,
2341,
275,
3474,
74,
221,
367,
1335,
315,
284,
1491,
552,
8,
1130,
1874,
61,
367,
284,
315,
2341,
61,
288,
291,
14,
18819,
14,
740,
8,
1130,
9,
339,
347,
27305,
63,
18819,
8,
277,
304,
267,
327,
4792,
13217,
4438,
2621,
1,
267,
12835,
63,
890,
275,
822,
8,
277,
14,
18819,
59,
16,
566,
267,
3462,
275,
1109,
8,
14085,
8,
277,
14,
2063,
1182,
12835,
63,
890,
1182,
499,
430,
267,
4569,
275,
1109,
8,
14085,
8,
277,
14,
3333,
1182,
12835,
63,
890,
430,
267,
367,
284,
315,
1425,
8,
2063,
304,
288,
367,
1335,
315,
1425,
8,
3333,
304,
355,
307,
275,
2196,
14,
5095,
8,
277,
14,
18819,
9,
355,
327,
4711,
314,
12835,
367,
32246,
355,
327,
10483,
355,
340,
2196,
14,
8393,
8,
16,
12,
413,
304,
490,
307,
275,
2341,
8,
513,
12,
3482,
2031,
84,
430,
355,
327,
16114,
4362,
355,
340,
2196,
14,
8393,
8,
16,
12,
413,
304,
490,
307,
275,
10822,
8,
84,
9,
355,
18761,
63,
3838,
275,
2196,
14,
8393,
8,
16,
12,
413,
9,
355,
367,
1022,
12,
1962,
315,
3874,
8,
84,
304,
490,
327,
16114,
4730,
490,
340,
18761,
63,
3838,
26,
717,
1962,
275,
10822,
8,
1143,
9,
490,
367,
634,
12,
1048,
315,
3874,
8,
1143,
304,
717,
671,
275,
284,
627,
12835,
63,
890,
435,
1022,
717,
612,
275,
1335,
627,
12835,
63,
890,
435,
634,
717,
12835,
275,
291,
14,
3825,
59,
88,
12,
612,
61,
717,
1163,
63,
7172,
275,
291,
14,
3825,
59,
277,
14,
2063,
446,
671,
446,
413,
12,
612,
61,
717,
12835,
14,
585,
275,
1163,
63,
7172,
14,
585,
275,
1048,
339,
347,
4907,
63,
1130,
8,
277,
12,
4907,
275,
283,
18927,
267,
1830,
715,
26,
288,
30419,
275,
359,
73,
367,
284,
315,
291,
14,
3825,
14,
1459,
342,
340,
284,
14,
585,
315,
4907,
61,
288,
12835,
275,
2196,
14,
5095,
8,
18819,
9,
288,
286,
275,
291,
423,
1623,
63,
7113,
8,
7172,
12,
4907,
9,
288,
340,
822,
8,
67,
9,
508,
822,
8,
18819,
304,
355,
372,
288,
19882,
83,
275,
359,
73,
367,
284,
315,
291,
14,
3825,
14,
1459,
342,
340,
284,
14,
585,
440,
315,
4907,
61,
288,
19882,
275,
2196,
14,
5095,
8,
7567,
83,
9,
288,
1163,
63,
7567,
275,
291,
14,
3825,
59,
277,
14,
2063,
446,
19882,
14,
88,
446,
413,
12,
19882,
14,
89,
61,
288,
19882,
14,
585,
275,
1163,
63,
7567,
14,
585,
275,
2242,
59,
16,
61,
339,
347,
485,
1623,
63,
7113,
8,
277,
12,
12835,
12,
4907,
304,
267,
1551,
275,
3842,
7172,
14,
88,
12,
12835,
14,
89,
1874,
267,
8539,
275,
663,
342,
267,
1830,
1551,
26,
288,
307,
275,
1551,
14,
1935,
342,
288,
671,
12,
612,
275,
307,
288,
367,
284,
12,
1335,
315,
359,
334,
88,
13,
17,
12,
612,
395,
334,
88,
11,
17,
12,
612,
395,
334,
88,
12,
612,
13,
17,
395,
334,
88,
12,
612,
11,
17,
19532,
355,
340,
378,
2695,
284,
665,
291,
14,
2063,
436,
378,
2695,
1335,
665,
291,
14,
3333,
26,
490,
12835,
275,
291,
14,
3825,
59,
73,
12,
1335,
61,
490,
340,
334,
73,
12,
1335,
9,
440,
315,
8539,
436,
12835,
14,
585,
315,
4907,
26
] |
[
2196,
199,
199,
504,
9143,
492,
14018,
199,
504,
13295,
81,
492,
946,
571,
411,
12,
946,
571,
2084,
199,
504,
3473,
492,
30449,
199,
504,
747,
492,
27483,
199,
504,
747,
14,
515,
492,
29214,
12,
4263,
199,
199,
533,
16386,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
9219,
12,
730,
12,
7365,
275,
661,
88,
297,
283,
89,
8109,
267,
291,
14,
5097,
275,
9219,
267,
291,
14,
466,
275,
730,
267,
291,
14,
3825,
275,
1052,
267,
291,
14,
13320,
275,
7365,
339,
347,
3550,
8,
277,
12,
671,
12,
612,
304,
267,
367,
284,
315,
1425,
8,
88,
304,
288,
367,
1335,
315,
1425,
8,
89,
304,
355,
1338,
275,
469,
277,
14,
13320,
59,
16,
2189,
284,
12,
717,
291,
14,
13320,
59,
17,
2189,
1335,
93,
355,
291,
14,
3825,
59,
73,
12,
1335,
61,
275,
291,
14,
466,
8,
277,
14,
5097,
12,
1011,
1459,
9,
339,
347,
13904,
8,
277,
304,
267,
2251,
275,
2519,
8,
277,
14,
5097,
12,
291,
14,
466,
423,
10019,
9,
267,
367,
284,
315,
2251,
26,
288,
10021,
275,
2008,
8,
5675,
8,
73,
12,
790,
9,
367,
790,
315,
291,
14,
13320,
9,
288,
291,
14,
3825,
59,
20493,
61,
275,
284,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
14,
3825,
14,
362,
8,
498,
12,
488,
9,
199,
199,
533,
377,
441,
2956,
7599,
8,
785,
304,
272,
1021,
7584,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
671,
12,
612,
304,
288,
291,
14,
88,
275,
671,
288,
291,
14,
89,
275,
612,
288,
291,
14,
585,
275,
283,
283,
339,
347,
636,
826,
721,
277,
12,
9219,
12,
3462,
29,
1165,
12,
4569,
29,
1165,
304,
267,
291,
14,
5097,
275,
9219,
267,
291,
14,
2063,
275,
3462,
267,
291,
14,
3333,
275,
4569,
267,
291,
14,
3825,
275,
1052,
267,
291,
14,
826,
63,
3825,
342,
267,
291,
14,
912,
63,
18819,
342,
339,
347,
3550,
8,
277,
304,
267,
291,
14,
817,
63,
18819,
342,
339,
347,
4205,
63,
3825,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
277,
14,
2063,
304,
288,
367,
1335,
315,
1425,
8,
277,
14,
3333,
304,
355,
291,
14,
3825,
59,
73,
12,
1335,
61,
275,
291,
14,
3428,
8,
73,
12,
1335,
9,
2378,
347,
2248,
63,
18819,
8,
277,
304,
267,
327,
11768,
26,
7190,
30419,
267,
2082,
275,
4263,
360,
5265,
297,
291,
14,
5097,
423,
354,
12,
283,
888,
297,
283,
18819,
358,
267,
1584,
275,
359,
289,
367,
289,
315,
27483,
8,
3619,
9,
340,
29214,
8,
904,
8,
3619,
12,
70,
430,
1622,
267,
291,
14,
18819,
275,
942,
267,
367,
289,
315,
1584,
26,
288,
2341,
275,
1551,
8,
904,
8,
3619,
12,
289,
4992,
9684,
342,
288,
2341,
275,
3474,
74,
221,
367,
1335,
315,
284,
1491,
552,
8,
1130,
1874,
61,
367,
284,
315,
2341,
61,
288,
291,
14,
18819,
14,
740,
8,
1130,
9,
339,
347,
27305,
63,
18819,
8,
277,
304,
267,
327,
4792,
13217,
4438,
2621,
1,
267,
12835,
63,
890,
275,
822,
8,
277,
14,
18819,
59,
16,
566,
267,
3462,
275,
1109,
8,
14085,
8,
277,
14,
2063,
1182,
12835,
63,
890,
1182,
499,
430,
267,
4569,
275,
1109,
8,
14085,
8,
277,
14,
3333,
1182,
12835,
63,
890,
430,
267,
367,
284,
315,
1425,
8,
2063,
304,
288,
367,
1335,
315,
1425,
8,
3333,
304,
355,
307,
275,
2196,
14,
5095,
8,
277,
14,
18819,
9,
355,
327,
4711,
314,
12835,
367,
32246,
355,
327,
10483,
355,
340,
2196,
14,
8393,
8,
16,
12,
413,
304,
490,
307,
275,
2341,
8,
513,
12,
3482,
2031,
84,
430,
355,
327,
16114,
4362,
355,
340,
2196,
14,
8393,
8,
16,
12,
413,
304,
490,
307,
275,
10822,
8,
84,
9,
355,
18761,
63,
3838,
275,
2196,
14,
8393,
8,
16,
12,
413,
9,
355,
367,
1022,
12,
1962,
315,
3874,
8,
84,
304,
490,
327,
16114,
4730,
490,
340,
18761,
63,
3838,
26,
717,
1962,
275,
10822,
8,
1143,
9,
490,
367,
634,
12,
1048,
315,
3874,
8,
1143,
304,
717,
671,
275,
284,
627,
12835,
63,
890,
435,
1022,
717,
612,
275,
1335,
627,
12835,
63,
890,
435,
634,
717,
12835,
275,
291,
14,
3825,
59,
88,
12,
612,
61,
717,
1163,
63,
7172,
275,
291,
14,
3825,
59,
277,
14,
2063,
446,
671,
446,
413,
12,
612,
61,
717,
12835,
14,
585,
275,
1163,
63,
7172,
14,
585,
275,
1048,
339,
347,
4907,
63,
1130,
8,
277,
12,
4907,
275,
283,
18927,
267,
1830,
715,
26,
288,
30419,
275,
359,
73,
367,
284,
315,
291,
14,
3825,
14,
1459,
342,
340,
284,
14,
585,
315,
4907,
61,
288,
12835,
275,
2196,
14,
5095,
8,
18819,
9,
288,
286,
275,
291,
423,
1623,
63,
7113,
8,
7172,
12,
4907,
9,
288,
340,
822,
8,
67,
9,
508,
822,
8,
18819,
304,
355,
372,
288,
19882,
83,
275,
359,
73,
367,
284,
315,
291,
14,
3825,
14,
1459,
342,
340,
284,
14,
585,
440,
315,
4907,
61,
288,
19882,
275,
2196,
14,
5095,
8,
7567,
83,
9,
288,
1163,
63,
7567,
275,
291,
14,
3825,
59,
277,
14,
2063,
446,
19882,
14,
88,
446,
413,
12,
19882,
14,
89,
61,
288,
19882,
14,
585,
275,
1163,
63,
7567,
14,
585,
275,
2242,
59,
16,
61,
339,
347,
485,
1623,
63,
7113,
8,
277,
12,
12835,
12,
4907,
304,
267,
1551,
275,
3842,
7172,
14,
88,
12,
12835,
14,
89,
1874,
267,
8539,
275,
663,
342,
267,
1830,
1551,
26,
288,
307,
275,
1551,
14,
1935,
342,
288,
671,
12,
612,
275,
307,
288,
367,
284,
12,
1335,
315,
359,
334,
88,
13,
17,
12,
612,
395,
334,
88,
11,
17,
12,
612,
395,
334,
88,
12,
612,
13,
17,
395,
334,
88,
12,
612,
11,
17,
19532,
355,
340,
378,
2695,
284,
665,
291,
14,
2063,
436,
378,
2695,
1335,
665,
291,
14,
3333,
26,
490,
12835,
275,
291,
14,
3825,
59,
73,
12,
1335,
61,
490,
340,
334,
73,
12,
1335,
9,
440,
315,
8539,
436,
12835,
14,
585,
315,
4907,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bigswitch/horizon
|
openstack_dashboard/dashboards/admin/aggregates/tests.py
|
3
|
20839
|
# 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 mock
from django.core.urlresolvers import reverse
from django import http
from mox3.mox import IsA # noqa
from openstack_dashboard import api
from openstack_dashboard.dashboards.admin.aggregates import constants
from openstack_dashboard.dashboards.admin.aggregates import workflows
from openstack_dashboard.test import helpers as test
class BaseAggregateWorkflowTests(test.BaseAdminViewTests):
def _get_create_workflow_data(self, aggregate, hosts=None):
aggregate_info = {"name": aggregate.name,
"availability_zone": aggregate.availability_zone}
if hosts:
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
host_field_name = 'add_host_to_aggregate_role_member'
aggregate_info[host_field_name] = \
[h.host_name for h in compute_hosts]
return aggregate_info
def _get_manage_workflow_data(self, aggregate, hosts=None, ):
aggregate_info = {"id": aggregate.id}
if hosts:
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
host_field_name = 'add_host_to_aggregate_role_member'
aggregate_info[host_field_name] = \
[h.host_name for h in compute_hosts]
return aggregate_info
class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
@test.create_stubs({api.nova: ('host_list', ), })
def test_workflow_get(self):
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL)
res = self.client.get(url)
workflow = res.context['workflow']
self.assertTemplateUsed(res, constants.AGGREGATES_CREATE_VIEW_TEMPLATE)
self.assertEqual(workflow.name, workflows.CreateAggregateWorkflow.name)
self.assertQuerysetEqual(
workflow.steps,
['<SetAggregateInfoStep: set_aggregate_info>',
'<AddHostsToAggregateStep: add_host_to_aggregate>'])
@test.create_stubs({api.nova: ('host_list', 'aggregate_details_list',
'aggregate_create'), })
def _test_generic_create_aggregate(self, workflow_data, aggregate,
error_count=0,
expected_error_message=None):
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
api.nova.aggregate_details_list(IsA(http.HttpRequest)).AndReturn([])
if not expected_error_message:
api.nova.aggregate_create(
IsA(http.HttpRequest),
name=workflow_data['name'],
availability_zone=workflow_data['availability_zone'],
).AndReturn(aggregate)
self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL)
res = self.client.post(url, workflow_data)
if not expected_error_message:
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(
res, reverse(constants.AGGREGATES_INDEX_URL))
else:
self.assertFormErrors(res, error_count, expected_error_message)
def test_create_aggregate(self):
aggregate = self.aggregates.first()
workflow_data = self._get_create_workflow_data(aggregate)
self._test_generic_create_aggregate(workflow_data, aggregate)
def test_create_aggregate_fails_missing_fields(self):
aggregate = self.aggregates.first()
workflow_data = self._get_create_workflow_data(aggregate)
workflow_data['name'] = ''
workflow_data['availability_zone'] = ''
self._test_generic_create_aggregate(workflow_data, aggregate, 1,
u'This field is required')
@test.create_stubs({api.nova: ('host_list',
'aggregate_details_list',
'aggregate_create',
'add_host_to_aggregate'), })
def test_create_aggregate_with_hosts(self):
aggregate = self.aggregates.first()
hosts = self.hosts.list()
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
api.nova.aggregate_details_list(IsA(http.HttpRequest)).AndReturn([])
workflow_data = self._get_create_workflow_data(aggregate, hosts)
api.nova.aggregate_create(
IsA(http.HttpRequest),
name=workflow_data['name'],
availability_zone=workflow_data['availability_zone'],
).AndReturn(aggregate)
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
for host in compute_hosts:
api.nova.add_host_to_aggregate(
IsA(http.HttpRequest),
aggregate.id, host.host_name).InAnyOrder()
self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL)
res = self.client.post(url, workflow_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL))
@test.create_stubs({api.nova: ('host_list', 'aggregate_details_list', ), })
def test_host_list_nova_compute(self):
hosts = self.hosts.list()
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL)
res = self.client.get(url)
workflow = res.context['workflow']
step = workflow.get_step("add_host_to_aggregate")
field_name = step.get_member_field_name('member')
self.assertEqual(len(step.action.fields[field_name].choices),
len(compute_hosts))
class AggregatesViewTests(test.BaseAdminViewTests):
@mock.patch('openstack_dashboard.api.nova.extension_supported',
mock.Mock(return_value=False))
@test.create_stubs({api.nova: ('aggregate_details_list',
'availability_zone_list',
'tenant_absolute_limits',),
api.cinder: ('tenant_absolute_limits',),
api.neutron: ('list_extensions',),
api.network: ('tenant_floating_ip_list',
'security_group_list'),
api.keystone: ('tenant_list',)})
def test_panel_not_available(self):
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)). \
MultipleTimes().AndReturn(self.limits['absolute'])
api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)). \
MultipleTimes().AndReturn(self.cinder_limits['absolute'])
api.neutron.list_extensions(IsA(http.HttpRequest)). \
AndReturn(self.api_extensions.list())
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
.AndReturn(self.floating_ips.list())
api.network.security_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.security_groups.list())
api.keystone.tenant_list(IsA(http.HttpRequest)) \
.AndReturn(self.tenants.list())
self.mox.ReplayAll()
self.patchers['aggregates'].stop()
res = self.client.get(reverse('horizon:admin:overview:index'))
self.assertNotIn(b'Host Aggregates', res.content)
@test.create_stubs({api.nova: ('aggregate_details_list',
'availability_zone_list',)})
def test_index(self):
api.nova.aggregate_details_list(IsA(http.HttpRequest)) \
.AndReturn(self.aggregates.list())
api.nova.availability_zone_list(IsA(http.HttpRequest), detailed=True) \
.AndReturn(self.availability_zones.list())
self.mox.ReplayAll()
res = self.client.get(reverse(constants.AGGREGATES_INDEX_URL))
self.assertTemplateUsed(res, constants.AGGREGATES_INDEX_VIEW_TEMPLATE)
self.assertItemsEqual(res.context['host_aggregates_table'].data,
self.aggregates.list())
self.assertItemsEqual(res.context['availability_zones_table'].data,
self.availability_zones.list())
@test.create_stubs({api.nova: ('aggregate_update', 'aggregate_get',), })
def _test_generic_update_aggregate(self, form_data, aggregate,
error_count=0,
expected_error_message=None):
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id))\
.AndReturn(aggregate)
if not expected_error_message:
az = form_data['availability_zone']
aggregate_data = {'name': form_data['name'],
'availability_zone': az}
api.nova.aggregate_update(IsA(http.HttpRequest), str(aggregate.id),
aggregate_data)
self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_UPDATE_URL,
args=[aggregate.id]),
form_data)
if not expected_error_message:
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(
res, reverse(constants.AGGREGATES_INDEX_URL))
else:
self.assertFormErrors(res, error_count, expected_error_message)
def test_update_aggregate(self):
aggregate = self.aggregates.first()
form_data = {'id': aggregate.id,
'name': 'my_new_name',
'availability_zone': 'my_new_zone'}
self._test_generic_update_aggregate(form_data, aggregate)
def test_update_aggregate_fails_missing_fields(self):
aggregate = self.aggregates.first()
form_data = {'id': aggregate.id}
self._test_generic_update_aggregate(form_data, aggregate, 1,
u'This field is required')
class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'host_list')})
def test_manage_hosts(self):
aggregate = self.aggregates.first()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \
.AndReturn(self.hosts.list())
self.mox.ReplayAll()
res = self.client.get(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
args=[aggregate.id]))
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res,
constants.AGGREGATES_MANAGE_HOSTS_TEMPLATE)
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate',
'host_list')})
def test_manage_hosts_update_add_remove_not_empty_aggregate(self):
aggregate = self.aggregates.first()
aggregate.hosts = ['host1', 'host2']
host = self.hosts.list()[0]
form_data = {'manageaggregatehostsaction_role_member':
[host.host_name]}
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host2').InAnyOrder()
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host1').InAnyOrder()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \
.AndReturn(self.hosts.list())
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id), host.host_name)
self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
args=[aggregate.id]),
form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL))
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate',
'host_list')})
def test_manage_hosts_update_add_not_empty_aggregate_should_fail(self):
aggregate = self.aggregates.first()
aggregate.hosts = ['devstack001']
host1 = self.hosts.list()[0]
host3 = self.hosts.list()[2]
form_data = {'manageaggregatehostsaction_role_member':
[host1.host_name, host3.host_name]}
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.InAnyOrder().AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \
.InAnyOrder().AndReturn(self.hosts.list())
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.InAnyOrder().AndReturn(aggregate)
api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id), host3.host_name) \
.InAnyOrder().AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
args=[aggregate.id]),
form_data)
self.assertNoFormErrors(res)
self.assertMessageCount(error=2)
self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL))
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate',
'host_list')})
def test_manage_hosts_update_clean_not_empty_aggregate_should_fail(self):
aggregate = self.aggregates.first()
aggregate.hosts = ['host2']
form_data = {'manageaggregatehostsaction_role_member':
[]}
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host2')\
.AndRaise(self.exceptions.nova)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \
.AndReturn(self.hosts.list())
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
args=[aggregate.id]),
form_data)
self.assertNoFormErrors(res)
self.assertMessageCount(error=2)
self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL))
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate',
'host_list')})
def _test_manage_hosts_update(self,
host,
aggregate,
form_data,
addAggregate=False,
cleanAggregates=False):
if cleanAggregates:
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host3').InAnyOrder()
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host2').InAnyOrder()
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
'host1').InAnyOrder()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \
.AndReturn(self.hosts.list())
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate)
if addAggregate:
api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id),
host.host_name)
self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
args=[aggregate.id]),
form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL))
def test_manage_hosts_update_nothing_not_empty_aggregate(self):
aggregate = self.aggregates.first()
host = self.hosts.list()[0]
aggregate.hosts = [host.host_name]
form_data = {'manageaggregatehostsaction_role_member':
[host.host_name]}
self._test_manage_hosts_update(host,
aggregate,
form_data,
addAggregate=False)
def test_manage_hosts_update_nothing_empty_aggregate(self):
aggregate = self.aggregates.first()
aggregate.hosts = []
form_data = {'manageaggregatehostsaction_role_member':
[]}
self._test_manage_hosts_update(None,
aggregate,
form_data,
addAggregate=False)
def test_manage_hosts_update_add_empty_aggregate(self):
aggregate = self.aggregates.first()
aggregate.hosts = []
host = self.hosts.list()[0]
form_data = {'manageaggregatehostsaction_role_member':
[host.host_name]}
self._test_manage_hosts_update(host,
aggregate,
form_data,
addAggregate=True)
def test_manage_hosts_update_add_not_empty_aggregate(self):
aggregate = self.aggregates.first()
aggregate.hosts = ['devstack001']
host1 = self.hosts.list()[0]
host3 = self.hosts.list()[2]
form_data = {'manageaggregatehostsaction_role_member':
[host1.host_name, host3.host_name]}
self._test_manage_hosts_update(host3,
aggregate,
form_data,
addAggregate=True)
def test_manage_hosts_update_clean_not_empty_aggregate(self):
aggregate = self.aggregates.first()
aggregate.hosts = ['host1', 'host2', 'host3']
form_data = {'manageaggregatehostsaction_role_member':
[]}
self._test_manage_hosts_update(None,
aggregate,
form_data,
addAggregate=False,
cleanAggregates=True)
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
504,
18610,
19,
14,
6625,
492,
29719,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
21622,
492,
5262,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
21622,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
533,
3523,
10170,
17527,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
339,
347,
485,
362,
63,
981,
63,
8856,
63,
576,
8,
277,
12,
9531,
12,
7057,
29,
403,
304,
267,
9531,
63,
815,
275,
2420,
354,
582,
9531,
14,
354,
12,
2079,
298,
11856,
63,
2619,
582,
9531,
14,
11856,
63,
2619,
93,
398,
340,
7057,
26,
288,
4526,
63,
5146,
275,
942,
288,
367,
1591,
315,
7057,
26,
355,
340,
1591,
14,
1364,
508,
283,
3357,
356,
490,
4526,
63,
5146,
14,
740,
8,
1102,
9,
953,
1591,
63,
698,
63,
354,
275,
283,
525,
63,
1102,
63,
475,
63,
7516,
63,
3756,
63,
1114,
7,
288,
9531,
63,
815,
59,
1102,
63,
698,
63,
354,
61,
275,
971,
355,
359,
72,
14,
1102,
63,
354,
367,
394,
315,
4526,
63,
5146,
61,
398,
372,
9531,
63,
815,
339,
347,
485,
362,
63,
9053,
63,
8856,
63,
576,
8,
277,
12,
9531,
12,
7057,
29,
403,
12,
3461,
267,
9531,
63,
815,
275,
2420,
344,
582,
9531,
14,
344,
93,
398,
340,
7057,
26,
288,
4526,
63,
5146,
275,
942,
288,
367,
1591,
315,
7057,
26,
355,
340,
1591,
14,
1364,
508,
283,
3357,
356,
490,
4526,
63,
5146,
14,
740,
8,
1102,
9,
953,
1591,
63,
698,
63,
354,
275,
283,
525,
63,
1102,
63,
475,
63,
7516,
63,
3756,
63,
1114,
7,
288,
9531,
63,
815,
59,
1102,
63,
698,
63,
354,
61,
275,
971,
355,
359,
72,
14,
1102,
63,
354,
367,
394,
315,
4526,
63,
5146,
61,
398,
372,
9531,
63,
815,
421,
199,
533,
2790,
10170,
17527,
2925,
8,
1563,
10170,
17527,
2925,
304,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1102,
63,
513,
297,
2318,
3828,
272,
347,
511,
63,
8856,
63,
362,
8,
277,
304,
398,
2986,
14,
6765,
14,
1102,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
8,
277,
14,
5146,
14,
513,
1012,
267,
291,
14,
6625,
14,
12982,
342,
398,
1166,
275,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
8366,
63,
2632,
9,
267,
522,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
267,
10431,
275,
522,
14,
1100,
459,
8856,
418,
398,
291,
14,
19661,
8,
470,
12,
5262,
14,
14083,
5616,
16601,
63,
8366,
63,
12058,
63,
7433,
9,
267,
291,
14,
629,
8,
8856,
14,
354,
12,
10431,
83,
14,
2499,
10170,
17527,
14,
354,
9,
267,
291,
14,
7108,
8,
288,
10431,
14,
5895,
12,
288,
12329,
1084,
10170,
2354,
7801,
26,
663,
63,
7516,
63,
815,
4206,
1467,
2650,
1123,
19620,
1378,
10170,
7801,
26,
1050,
63,
1102,
63,
475,
63,
7516,
24782,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1102,
63,
513,
297,
283,
7516,
63,
5087,
63,
513,
297,
3521,
283,
7516,
63,
981,
659,
3828,
272,
347,
485,
396,
63,
6767,
63,
981,
63,
7516,
8,
277,
12,
10431,
63,
576,
12,
9531,
12,
4318,
1125,
63,
835,
29,
16,
12,
4318,
1420,
63,
705,
63,
1188,
29,
403,
304,
267,
2986,
14,
6765,
14,
1102,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
8,
277,
14,
5146,
14,
513,
1012,
267,
2986,
14,
6765,
14,
7516,
63,
5087,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
4157,
267,
340,
440,
1420,
63,
705,
63,
1188,
26,
288,
2986,
14,
6765,
14,
7516,
63,
981,
8,
355,
29719,
8,
1014,
14,
10441,
395,
355,
536,
29,
8856,
63,
576,
459,
354,
995,
355,
14962,
63,
2619,
29,
8856,
63,
576,
459,
11856,
63,
2619,
995,
288,
7092,
8572,
8,
7516,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1166,
275,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
8366,
63,
2632,
9,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
10431,
63,
576,
9,
398,
340,
440,
1420,
63,
705,
63,
1188,
26,
288,
291,
14,
22389,
2821,
9298,
8,
470,
9,
288,
291,
14,
17466,
1944,
18696,
8,
355,
522,
12,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
10215,
63,
2632,
430,
267,
587,
26,
288,
291,
14,
24577,
9298,
8,
470,
12,
1125,
63,
835,
12,
1420,
63,
705,
63,
1188,
9,
339,
347,
511,
63,
981,
63,
7516,
8,
277,
304,
267,
9531,
275,
291,
14,
21622,
14,
2246,
342,
267,
10431,
63,
576,
275,
291,
423,
362,
63,
981,
63,
8856,
63,
576,
8,
7516,
9,
267,
291,
423,
396,
63,
6767,
63,
981,
63,
7516,
8,
8856,
63,
576,
12,
9531,
9,
339,
347,
511,
63,
981,
63,
7516,
63,
15762,
63,
4752,
63,
955,
8,
277,
304,
267,
9531,
275,
291,
14,
21622,
14,
2246,
342,
267,
10431,
63,
576,
275,
291,
423,
362,
63,
981,
63,
8856,
63,
576,
8,
7516,
9,
267,
10431,
63,
576,
459,
354,
418,
275,
2125,
267,
10431,
63,
576
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
492,
1455,
199,
504,
18610,
19,
14,
6625,
492,
29719,
221,
327,
8151,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
21622,
492,
5262,
199,
504,
13869,
63,
9743,
14,
30424,
14,
2113,
14,
21622,
492,
10431,
83,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
533,
3523,
10170,
17527,
2925,
8,
396,
14,
1563,
4880,
2768,
2925,
304,
339,
347,
485,
362,
63,
981,
63,
8856,
63,
576,
8,
277,
12,
9531,
12,
7057,
29,
403,
304,
267,
9531,
63,
815,
275,
2420,
354,
582,
9531,
14,
354,
12,
2079,
298,
11856,
63,
2619,
582,
9531,
14,
11856,
63,
2619,
93,
398,
340,
7057,
26,
288,
4526,
63,
5146,
275,
942,
288,
367,
1591,
315,
7057,
26,
355,
340,
1591,
14,
1364,
508,
283,
3357,
356,
490,
4526,
63,
5146,
14,
740,
8,
1102,
9,
953,
1591,
63,
698,
63,
354,
275,
283,
525,
63,
1102,
63,
475,
63,
7516,
63,
3756,
63,
1114,
7,
288,
9531,
63,
815,
59,
1102,
63,
698,
63,
354,
61,
275,
971,
355,
359,
72,
14,
1102,
63,
354,
367,
394,
315,
4526,
63,
5146,
61,
398,
372,
9531,
63,
815,
339,
347,
485,
362,
63,
9053,
63,
8856,
63,
576,
8,
277,
12,
9531,
12,
7057,
29,
403,
12,
3461,
267,
9531,
63,
815,
275,
2420,
344,
582,
9531,
14,
344,
93,
398,
340,
7057,
26,
288,
4526,
63,
5146,
275,
942,
288,
367,
1591,
315,
7057,
26,
355,
340,
1591,
14,
1364,
508,
283,
3357,
356,
490,
4526,
63,
5146,
14,
740,
8,
1102,
9,
953,
1591,
63,
698,
63,
354,
275,
283,
525,
63,
1102,
63,
475,
63,
7516,
63,
3756,
63,
1114,
7,
288,
9531,
63,
815,
59,
1102,
63,
698,
63,
354,
61,
275,
971,
355,
359,
72,
14,
1102,
63,
354,
367,
394,
315,
4526,
63,
5146,
61,
398,
372,
9531,
63,
815,
421,
199,
533,
2790,
10170,
17527,
2925,
8,
1563,
10170,
17527,
2925,
304,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1102,
63,
513,
297,
2318,
3828,
272,
347,
511,
63,
8856,
63,
362,
8,
277,
304,
398,
2986,
14,
6765,
14,
1102,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
8,
277,
14,
5146,
14,
513,
1012,
267,
291,
14,
6625,
14,
12982,
342,
398,
1166,
275,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
8366,
63,
2632,
9,
267,
522,
275,
291,
14,
1258,
14,
362,
8,
633,
9,
267,
10431,
275,
522,
14,
1100,
459,
8856,
418,
398,
291,
14,
19661,
8,
470,
12,
5262,
14,
14083,
5616,
16601,
63,
8366,
63,
12058,
63,
7433,
9,
267,
291,
14,
629,
8,
8856,
14,
354,
12,
10431,
83,
14,
2499,
10170,
17527,
14,
354,
9,
267,
291,
14,
7108,
8,
288,
10431,
14,
5895,
12,
288,
12329,
1084,
10170,
2354,
7801,
26,
663,
63,
7516,
63,
815,
4206,
1467,
2650,
1123,
19620,
1378,
10170,
7801,
26,
1050,
63,
1102,
63,
475,
63,
7516,
24782,
339,
768,
396,
14,
981,
63,
8957,
2561,
1246,
14,
6765,
26,
661,
1102,
63,
513,
297,
283,
7516,
63,
5087,
63,
513,
297,
3521,
283,
7516,
63,
981,
659,
3828,
272,
347,
485,
396,
63,
6767,
63,
981,
63,
7516,
8,
277,
12,
10431,
63,
576,
12,
9531,
12,
4318,
1125,
63,
835,
29,
16,
12,
4318,
1420,
63,
705,
63,
1188,
29,
403,
304,
267,
2986,
14,
6765,
14,
1102,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
8,
277,
14,
5146,
14,
513,
1012,
267,
2986,
14,
6765,
14,
7516,
63,
5087,
63,
513,
8,
14104,
8,
1014,
14,
10441,
4992,
8572,
4157,
267,
340,
440,
1420,
63,
705,
63,
1188,
26,
288,
2986,
14,
6765,
14,
7516,
63,
981,
8,
355,
29719,
8,
1014,
14,
10441,
395,
355,
536,
29,
8856,
63,
576,
459,
354,
995,
355,
14962,
63,
2619,
29,
8856,
63,
576,
459,
11856,
63,
2619,
995,
288,
7092,
8572,
8,
7516,
9,
398,
291,
14,
6625,
14,
12982,
342,
398,
1166,
275,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
8366,
63,
2632,
9,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
10431,
63,
576,
9,
398,
340,
440,
1420,
63,
705,
63,
1188,
26,
288,
291,
14,
22389,
2821,
9298,
8,
470,
9,
288,
291,
14,
17466,
1944,
18696,
8,
355,
522,
12,
3837,
8,
5559,
14,
14083,
5616,
16601,
63,
10215,
63,
2632,
430,
267,
587,
26,
288,
291,
14,
24577,
9298,
8,
470,
12,
1125,
63,
835,
12,
1420,
63,
705,
63,
1188,
9,
339,
347,
511,
63,
981,
63,
7516,
8,
277,
304,
267,
9531,
275,
291,
14,
21622,
14,
2246,
342,
267,
10431,
63,
576,
275,
291,
423,
362,
63,
981,
63,
8856,
63,
576,
8,
7516,
9,
267,
291,
423,
396,
63,
6767,
63,
981,
63,
7516,
8,
8856,
63,
576,
12,
9531,
9,
339,
347,
511,
63,
981,
63,
7516,
63,
15762,
63,
4752,
63,
955,
8,
277,
304,
267,
9531,
275,
291,
14,
21622,
14,
2246,
342,
267,
10431,
63,
576,
275,
291,
423,
362,
63,
981,
63,
8856,
63,
576,
8,
7516,
9,
267,
10431,
63,
576,
459,
354,
418,
275,
2125,
267,
10431,
63,
576,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
youdar/work
|
work/FAB/test2.py
|
1
|
5768
|
from __future__ import division
from phenix.command_line import superpose_pdbs
from iotbx import pdb
from iotbx.pdb import fetch
from libtbx import easy_run
from libtbx.utils import Sorry
import shutil
import tempfile
import os,sys
def run(fn):
''' '''
# Test if FAB
# Devide to
pdb_hierarchy_var_H,pdb_hierarchy_const_H = get_pdb_protions(pdb_file_name='1bbd',chain_ID='H',limit=113)
pdb_hierarchy_var_L,pdb_hierarchy_const_L = get_pdb_protions(pdb_file_name='1bbd',chain_ID='L',limit=103)
sites_var_heavy,sites_const_heavy,selection_var_H,selection_const_H,pdb_hierarchy = get_sites_protions(pdb_file_name='1bbd',chain_ID='H',limit=113)
sites_var_light,sites_const_light,selection_var_L,selection_const_L,pdb_hierarchy = get_sites_protions(pdb_file_name='1bbd',chain_ID='L',limit=107)
def get_file(fn):
if not os.path.isfile(fn + '.pdb'):
sf_fn = fetch.get_pdb (fn,data_type='pdb',mirror='rcsb',log=sys.stdout)
def set_work_folder():
if sys.platform.startswith('win'):
wrokpath = r'C:\Phenix\Dev\Work\work\FAB'
else:
workpath = '~youval/Work/work/FAB'
os.chdir(wrokpath)
def check_pdb_file_name(file_name):
tmp = os.path.basename(file_name)
tmp = tmp.split('.')
assert len(tmp[0])==4
if len(tmp)==2 and tmp[1]=='pdb':
fn = file_name
else:
fn = tmp[0] + '.pdb'
return fn
def get_pdb_protions(pdb_file_name,chain_ID,limit):
'''(str,str,int) -> pdb_hierarchy,pdb_hierarchy
create a pdb_hierarchy from pdb_file_name, takes a chain,
with chain_ID, and devides it to two, at the limit position.
Example:
>>>pdb_heavy_var, pdb_heavy_const = get_pdb_protions(pdb_file_name='1bbd',chain_ID='H',limit=113)
Arguments:
----------
pdb_file_name : pdb file name
chain_ID : PDB chain ID
limit : the cutoff between the Variable and the Constant FAB domains
Returns:
--------
pdb_hierarchy_var : 0 to limit portion of the pdb_hierarchy
pdb_hierarchy_const : limit to end portion of the pdb_hierarchy
'''
fn = check_pdb_file_name(pdb_file_name)
pdb_hierarchy = pdb.hierarchy.input(file_name=fn).hierarchy
chains = pdb_hierarchy.models()[0].chains()
chain_names = [x.id for x in chains]
# check if correct name is given and find the correct chain
if chain_ID in chain_names:
# get the chain residue group, to check its length
indx = chain_names.index(chain_ID)
# get the chain with the chain_ID and index indx
chain_res = pdb_hierarchy.models()[0].chains()[indx].residue_groups()
chain_length = len(chain_res)
selection_var = 'chain {0} resseq {1}:{2}'.format(chain_ID,1,limit)
selection_const = 'chain {0} resseq {1}:{2}'.format(chain_ID,limit,chain_length)
pdb_hierarchy_var = pdb_hierarchy.atom_selection_cache().selection(selection_var)
pdb_hierarchy_const = pdb_hierarchy.atom_selection_cache().selection(selection_const)
else:
raise Sorry('The is not chain with {0} name in {1}'.format(chain_ID,fn))
return pdb_hierarchy_var,pdb_hierarchy_const
def get_sites_protions(pdb_file_name,chain_ID,limit):
'''(str,str,int) -> pdb_hierarchy,pdb_hierarchy
create a pdb_hierarchy from pdb_file_name, takes a chain,
with chain_ID, and devides it to two, at the limit position.
Example:
>>>pdb_heavy_var, pdb_heavy_const = get_pdb_protions(pdb_file_name='1bbd',chain_ID='H',limit=113)
Arguments:
----------
pdb_file_name : pdb file name
chain_ID : PDB chain ID
limit : the cutoff between the Variable and the Constant FAB domains
Returns:
--------
sites_var,sites_const
sites_var : atoms sites of 0 to limit portion of the pdb_hierarchy
sites_const : atoms sites of limit to end portion of the pdb_hierarchy
'''
fn = check_pdb_file_name(pdb_file_name)
pdb_inp = pdb.input(file_name=fn)
pdb_hierarchy = pdb_inp.construct_hierarchy()
xrs = pdb_inp.xray_structure_simple()
sites_cart_all = xrs.sites_cart()
chains = pdb_hierarchy.models()[0].chains()
chain_names = [x.id for x in chains]
# check if correct name is given and find the correct chain
if chain_ID in chain_names:
# get the chain residue group, to check its length
indx = chain_names.index(chain_ID)
# get the chain with the chain_ID and index indx
chain_res = pdb_hierarchy.models()[0].chains()[indx].residue_groups()
chain_length = len(chain_res)
selection_var = 'chain {0} resseq {1}:{2}'.format(chain_ID,1,limit)
selection_const = 'chain {0} resseq {1}:{2}'.format(chain_ID,limit,chain_length)
pdb_var_selection = pdb_hierarchy.atom_selection_cache().selection(string=selection_var)
pdb_const_selection = pdb_hierarchy.atom_selection_cache().selection(string=selection_const)
# get atoms
params = superpose_pdbs.master_params.extract()
x = superpose_pdbs.manager(
params,
log='log.txt',
pdb_hierarchy_moving=pdb_const_selection,
pdb_hierarchy_fixed=pdb_var_selection)
sites_var = sites_cart_all.select(pdb_var_selection)
sites_const = sites_cart_all.select(pdb_const_selection)
chain = chain_res = pdb_hierarchy.models()[0].chains()[indx]
x1 = superpose_pdbs.manager.extract_sequence_and_sites_chain(chain,'resseq 0:113')
x2 = superpose_pdbs.manager.extract_sequence_and_sites_chain(chain,'resseq 113:190')
else:
raise Sorry('The is not chain with {0} name in {1}'.format(chain_ID,fn))
return sites_var,sites_const,selection_var,selection_const
class FAB_elbow_angle(object):
def __init__(self,
file_nam,
chain_name_light,
chain_name_heavy,
limit_light=107,
limit_heavy=113):
'''Get elbow angle for Fragment antigen-binding (Fab)'''
if __name__=='__main__':
fn = '1bbd'
set_work_folder()
get_file(fn)
run(fn)
print 'Done'
|
mit
|
[
504,
636,
2443,
363,
492,
4629,
199,
504,
3945,
287,
1148,
14,
1531,
63,
604,
492,
1613,
4070,
63,
10511,
83,
199,
504,
284,
357,
13691,
492,
10543,
199,
504,
284,
357,
13691,
14,
10511,
492,
5267,
199,
504,
1973,
5842,
88,
492,
8837,
63,
1065,
199,
504,
1973,
5842,
88,
14,
1208,
492,
428,
21342,
199,
646,
5145,
199,
646,
5549,
199,
646,
747,
12,
1274,
199,
199,
318,
1255,
8,
2324,
304,
523,
1449,
1449,
523,
327,
1379,
340,
481,
1217,
819,
327,
1487,
5624,
370,
523,
10543,
63,
14861,
63,
1391,
63,
40,
12,
10511,
63,
14861,
63,
1297,
63,
40,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
523,
10543,
63,
14861,
63,
1391,
63,
44,
12,
10511,
63,
14861,
63,
1297,
63,
44,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
44,
297,
3097,
29,
8845,
9,
523,
15424,
63,
1391,
63,
426,
22421,
12,
8619,
63,
1297,
63,
426,
22421,
12,
5592,
63,
1391,
63,
40,
12,
5592,
63,
1297,
63,
40,
12,
10511,
63,
14861,
275,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
523,
15424,
63,
1391,
63,
4040,
12,
8619,
63,
1297,
63,
4040,
12,
5592,
63,
1391,
63,
44,
12,
5592,
63,
1297,
63,
44,
12,
10511,
63,
14861,
275,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
44,
297,
3097,
29,
7555,
9,
421,
199,
318,
664,
63,
493,
8,
2324,
304,
523,
340,
440,
747,
14,
515,
14,
6292,
8,
2324,
435,
1987,
10511,
735,
272,
13330,
63,
2324,
275,
5267,
14,
362,
63,
10511,
334,
2324,
12,
576,
63,
466,
534,
10511,
297,
12324,
534,
1195,
9264,
297,
793,
29,
1274,
14,
2703,
9,
421,
199,
318,
663,
63,
800,
63,
3741,
837,
523,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
336,
29275,
515,
275,
519,
7,
35,
3427,
5663,
287,
1148,
60,
12680,
60,
6517,
60,
800,
60,
38,
1217,
7,
523,
587,
26,
272,
1736,
515,
275,
17352,
13297,
637,
15,
6517,
15,
800,
15,
38,
1217,
7,
523,
747,
14,
8563,
8,
87,
29275,
515,
9,
199,
199,
318,
1104,
63,
10511,
63,
493,
63,
354,
8,
493,
63,
354,
304,
523,
3529,
275,
747,
14,
515,
14,
4846,
8,
493,
63,
354,
9,
523,
3529,
275,
3529,
14,
1294,
7563,
523,
702,
822,
8,
2791,
59,
16,
566,
389,
20,
523,
340,
822,
8,
2791,
12694,
18,
436,
3529,
59,
17,
22954,
10511,
356,
272,
4325,
275,
570,
63,
354,
523,
587,
26,
272,
4325,
275,
3529,
59,
16,
61,
435,
1987,
10511,
7,
523,
372,
4325,
199,
199,
318,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
12,
4429,
63,
998,
12,
3097,
304,
523,
1449,
8,
495,
12,
495,
12,
442,
9,
1035,
10543,
63,
14861,
12,
10511,
63,
14861,
523,
1218,
282,
10543,
63,
14861,
687,
10543,
63,
493,
63,
354,
12,
6181,
282,
6036,
12,
523,
543,
6036,
63,
998,
12,
436,
477,
9652,
652,
370,
2877,
12,
737,
314,
2304,
3421,
14,
8330,
5679,
26,
523,
1306,
10511,
63,
426,
22421,
63,
1391,
12,
10543,
63,
426,
22421,
63,
1297,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
819,
7628,
26,
523,
4143,
523,
10543,
63,
493,
63,
354,
520,
10543,
570,
536,
523,
6036,
63,
998,
520,
30280,
6036,
2870,
523,
2304,
520,
314,
17875,
3382,
314,
4905,
436,
314,
19991,
481,
1217,
14006,
819,
1803,
26,
523,
3001,
523,
10543,
63,
14861,
63,
1391,
520,
378,
370,
2304,
18046,
402,
314,
10543,
63,
14861,
523,
10543,
63,
14861,
63,
1297,
520,
2304,
370,
1284,
18046,
402,
314,
10543,
63,
14861,
523,
1449,
523,
4325,
275,
1104,
63,
10511,
63,
493,
63,
354,
8,
10511,
63,
493,
63,
354,
9,
523,
10543,
63,
14861,
275,
10543,
14,
14861,
14,
1210,
8,
493,
63,
354,
29,
2324,
680,
14861,
523,
30640,
275,
10543,
63,
14861,
14,
992,
3430,
16,
1055,
17419,
342,
523,
6036,
63,
1247,
275,
359,
88,
14,
344,
367,
671,
315,
30640,
61,
523,
327,
1104,
340,
3211,
536,
365,
1627,
436,
2342,
314,
3211,
6036,
523,
340,
6036,
63,
998,
315,
6036,
63,
1247,
26,
272,
327,
664,
314,
6036,
23185,
310,
1572,
12,
370,
1104,
2399,
2582,
272,
7654,
88,
275,
6036,
63,
1247,
14,
1080,
8,
4429,
63,
998,
9,
272,
327,
664,
314,
6036,
543,
314,
6036,
63,
998,
436,
1478,
7654,
88,
272,
6036,
63,
470,
275,
10543,
63,
14861,
14,
992,
3430,
16,
1055,
17419,
3430,
24922,
1055,
19581,
310,
63,
2634,
342,
272,
6036,
63,
1267,
275,
822,
8,
4429,
63,
470,
9,
272,
7267,
63,
1391,
275,
283,
4429,
469,
16,
93,
522,
3610,
469,
17,
16495,
18,
5285,
908,
8,
4429,
63,
998,
12,
17,
12,
3097,
9,
272,
7267,
63,
1297,
275,
283,
4429,
469,
16,
93,
522,
3610,
469,
17,
16495,
18,
5285,
908,
8,
4429,
63,
998,
12,
3097,
12,
4429,
63,
1267,
9,
272,
10543,
63,
14861,
63,
1391,
275,
10543,
63,
14861,
14,
4188,
63,
5592,
63,
1637,
1252,
5592,
8,
5592,
63,
1391,
9,
272,
10543,
63,
14861,
63,
1297,
275,
10543,
63,
14861,
14,
4188,
63,
5592,
63,
1637,
1252,
5592,
8,
5592,
63,
1297,
9,
523,
587,
26,
272,
746,
428,
21342,
360,
1918,
365,
440,
6036,
543,
469,
16,
93,
536,
315,
469,
17,
5285,
908,
8,
4429,
63,
998,
12,
2324,
430,
819,
372,
10543,
63,
14861,
63,
1391,
12,
10511,
63,
14861,
63,
1297,
199,
199,
318,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
12,
4429,
63,
998,
12,
3097,
304,
523,
1449,
8,
495,
12,
495,
12,
442,
9,
1035,
10543,
63,
14861,
12,
10511
] |
[
636,
2443,
363,
492,
4629,
199,
504,
3945,
287,
1148,
14,
1531,
63,
604,
492,
1613,
4070,
63,
10511,
83,
199,
504,
284,
357,
13691,
492,
10543,
199,
504,
284,
357,
13691,
14,
10511,
492,
5267,
199,
504,
1973,
5842,
88,
492,
8837,
63,
1065,
199,
504,
1973,
5842,
88,
14,
1208,
492,
428,
21342,
199,
646,
5145,
199,
646,
5549,
199,
646,
747,
12,
1274,
199,
199,
318,
1255,
8,
2324,
304,
523,
1449,
1449,
523,
327,
1379,
340,
481,
1217,
819,
327,
1487,
5624,
370,
523,
10543,
63,
14861,
63,
1391,
63,
40,
12,
10511,
63,
14861,
63,
1297,
63,
40,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
523,
10543,
63,
14861,
63,
1391,
63,
44,
12,
10511,
63,
14861,
63,
1297,
63,
44,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
44,
297,
3097,
29,
8845,
9,
523,
15424,
63,
1391,
63,
426,
22421,
12,
8619,
63,
1297,
63,
426,
22421,
12,
5592,
63,
1391,
63,
40,
12,
5592,
63,
1297,
63,
40,
12,
10511,
63,
14861,
275,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
523,
15424,
63,
1391,
63,
4040,
12,
8619,
63,
1297,
63,
4040,
12,
5592,
63,
1391,
63,
44,
12,
5592,
63,
1297,
63,
44,
12,
10511,
63,
14861,
275,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
44,
297,
3097,
29,
7555,
9,
421,
199,
318,
664,
63,
493,
8,
2324,
304,
523,
340,
440,
747,
14,
515,
14,
6292,
8,
2324,
435,
1987,
10511,
735,
272,
13330,
63,
2324,
275,
5267,
14,
362,
63,
10511,
334,
2324,
12,
576,
63,
466,
534,
10511,
297,
12324,
534,
1195,
9264,
297,
793,
29,
1274,
14,
2703,
9,
421,
199,
318,
663,
63,
800,
63,
3741,
837,
523,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
336,
29275,
515,
275,
519,
7,
35,
3427,
5663,
287,
1148,
60,
12680,
60,
6517,
60,
800,
60,
38,
1217,
7,
523,
587,
26,
272,
1736,
515,
275,
17352,
13297,
637,
15,
6517,
15,
800,
15,
38,
1217,
7,
523,
747,
14,
8563,
8,
87,
29275,
515,
9,
199,
199,
318,
1104,
63,
10511,
63,
493,
63,
354,
8,
493,
63,
354,
304,
523,
3529,
275,
747,
14,
515,
14,
4846,
8,
493,
63,
354,
9,
523,
3529,
275,
3529,
14,
1294,
7563,
523,
702,
822,
8,
2791,
59,
16,
566,
389,
20,
523,
340,
822,
8,
2791,
12694,
18,
436,
3529,
59,
17,
22954,
10511,
356,
272,
4325,
275,
570,
63,
354,
523,
587,
26,
272,
4325,
275,
3529,
59,
16,
61,
435,
1987,
10511,
7,
523,
372,
4325,
199,
199,
318,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
12,
4429,
63,
998,
12,
3097,
304,
523,
1449,
8,
495,
12,
495,
12,
442,
9,
1035,
10543,
63,
14861,
12,
10511,
63,
14861,
523,
1218,
282,
10543,
63,
14861,
687,
10543,
63,
493,
63,
354,
12,
6181,
282,
6036,
12,
523,
543,
6036,
63,
998,
12,
436,
477,
9652,
652,
370,
2877,
12,
737,
314,
2304,
3421,
14,
8330,
5679,
26,
523,
1306,
10511,
63,
426,
22421,
63,
1391,
12,
10543,
63,
426,
22421,
63,
1297,
275,
664,
63,
10511,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
534,
17,
32737,
297,
4429,
63,
998,
534,
40,
297,
3097,
29,
9225,
9,
819,
7628,
26,
523,
4143,
523,
10543,
63,
493,
63,
354,
520,
10543,
570,
536,
523,
6036,
63,
998,
520,
30280,
6036,
2870,
523,
2304,
520,
314,
17875,
3382,
314,
4905,
436,
314,
19991,
481,
1217,
14006,
819,
1803,
26,
523,
3001,
523,
10543,
63,
14861,
63,
1391,
520,
378,
370,
2304,
18046,
402,
314,
10543,
63,
14861,
523,
10543,
63,
14861,
63,
1297,
520,
2304,
370,
1284,
18046,
402,
314,
10543,
63,
14861,
523,
1449,
523,
4325,
275,
1104,
63,
10511,
63,
493,
63,
354,
8,
10511,
63,
493,
63,
354,
9,
523,
10543,
63,
14861,
275,
10543,
14,
14861,
14,
1210,
8,
493,
63,
354,
29,
2324,
680,
14861,
523,
30640,
275,
10543,
63,
14861,
14,
992,
3430,
16,
1055,
17419,
342,
523,
6036,
63,
1247,
275,
359,
88,
14,
344,
367,
671,
315,
30640,
61,
523,
327,
1104,
340,
3211,
536,
365,
1627,
436,
2342,
314,
3211,
6036,
523,
340,
6036,
63,
998,
315,
6036,
63,
1247,
26,
272,
327,
664,
314,
6036,
23185,
310,
1572,
12,
370,
1104,
2399,
2582,
272,
7654,
88,
275,
6036,
63,
1247,
14,
1080,
8,
4429,
63,
998,
9,
272,
327,
664,
314,
6036,
543,
314,
6036,
63,
998,
436,
1478,
7654,
88,
272,
6036,
63,
470,
275,
10543,
63,
14861,
14,
992,
3430,
16,
1055,
17419,
3430,
24922,
1055,
19581,
310,
63,
2634,
342,
272,
6036,
63,
1267,
275,
822,
8,
4429,
63,
470,
9,
272,
7267,
63,
1391,
275,
283,
4429,
469,
16,
93,
522,
3610,
469,
17,
16495,
18,
5285,
908,
8,
4429,
63,
998,
12,
17,
12,
3097,
9,
272,
7267,
63,
1297,
275,
283,
4429,
469,
16,
93,
522,
3610,
469,
17,
16495,
18,
5285,
908,
8,
4429,
63,
998,
12,
3097,
12,
4429,
63,
1267,
9,
272,
10543,
63,
14861,
63,
1391,
275,
10543,
63,
14861,
14,
4188,
63,
5592,
63,
1637,
1252,
5592,
8,
5592,
63,
1391,
9,
272,
10543,
63,
14861,
63,
1297,
275,
10543,
63,
14861,
14,
4188,
63,
5592,
63,
1637,
1252,
5592,
8,
5592,
63,
1297,
9,
523,
587,
26,
272,
746,
428,
21342,
360,
1918,
365,
440,
6036,
543,
469,
16,
93,
536,
315,
469,
17,
5285,
908,
8,
4429,
63,
998,
12,
2324,
430,
819,
372,
10543,
63,
14861,
63,
1391,
12,
10511,
63,
14861,
63,
1297,
199,
199,
318,
664,
63,
8619,
63,
496,
852,
8,
10511,
63,
493,
63,
354,
12,
4429,
63,
998,
12,
3097,
304,
523,
1449,
8,
495,
12,
495,
12,
442,
9,
1035,
10543,
63,
14861,
12,
10511,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
GPrathap/carbon-device-mgt-plugins
|
features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mindwavemobile/tests/MindwavePacketPayloadParserTest.py
|
6
|
4397
|
import unittest
from MindwavePacketPayloadParser import MindwavePacketPayloadParser
from MindwaveDataPoints import RawDataPoint, PoorSignalLevelDataPoint,\
MeditationDataPoint, AttentionDataPoint, EEGPowersDataPoint, BlinkDataPoint
class ParseRawValueTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
payload = [0x80, 0x02, 0x60, 0x0] # first raw value
payload.extend([0x80, 0x02, 0x13, 0x12]) # second raw value
payload.extend([0x2, 0x55]) # poor signal level value
payload.extend([0x4, 0x25]) # attention level value
payload.extend([0x5, 0x35]) # meditation level value
payload.extend([0x16, 0x15]) # blink level value
payload.extend([0x83, 0x18, 0x15, 0x13, 0x17, 0x12, 0x11, 0x10, 0x9, 0x8, 0x7]) # 3 eeg powers
payload.extend([0x14, 0x13, 0x17, 0x12, 0x11, 0x10, 0x9, 0x8, 0x5]) # 3 more eeg powers
payload.extend([0xaf, 0x13, 0xbf, 0x0, 0x1, 0x0]) # 2 more eeg powers
cls._payloadParser = MindwavePacketPayloadParser(payload)
cls._dataPoints = cls._payloadParser.parseDataPoints()
def testReadingRawValueCorrectly(self):
dataPoint = self._dataPoints[0]
self.readingValueCorrectly(dataPoint.__class__, dataPoint.rawValue, \
RawDataPoint, (0x60 << 8) | 0x0,\
"should parse correct first raw value")
def testReadingSecondRawValueCorrectly(self):
dataPoint = self._dataPoints[1]
self.readingValueCorrectly(dataPoint.__class__, dataPoint.rawValue, \
RawDataPoint, (0x13 << 8) | 0x12,\
"should parse correct second raw value")
def testReadingPoorSignalLevelCorrectly(self):
dataPoint = self._dataPoints[2];
self.readingValueCorrectly(dataPoint.__class__, dataPoint.amountOfNoise, \
PoorSignalLevelDataPoint, 0x55,\
"should parse correct noise level")
def testReadingAttentionLevelCorrectly(self):
dataPoint = self._dataPoints[3];
self.readingValueCorrectly(dataPoint.__class__, dataPoint.attentionValue, \
AttentionDataPoint, 0x25,\
"should parse correct attention level")
def testReadingMeditationLevelCorrectly(self):
dataPoint = self._dataPoints[4];
self.readingValueCorrectly(dataPoint.__class__, dataPoint.meditationValue, \
MeditationDataPoint, 0x35,\
"should parse correct meditation level")
def testReadingBlinkLevelCorrectly(self):
dataPoint = self._dataPoints[5];
self.readingValueCorrectly(dataPoint.__class__, dataPoint.blinkValue, \
BlinkDataPoint, 0x15,\
"should parse correct blink level")
def readingValueCorrectly(self, actualClass, actualValue, expectedClass, expectedValue, msg):
self.assertTrue(actualClass is expectedClass, msg)
self.assertEqual(actualValue, expectedValue, msg)
def testReadingEEGLevelsCorrectly(self):
dataPoint = self._dataPoints[6];
self.assertIs(dataPoint.__class__, EEGPowersDataPoint, "eeg powers should be parsed correctly")
self.assertEqual(dataPoint.delta, (0x15 << 16) | (0x13 << 8) | 0x17, "delta should be parsed correctly")
self.assertEqual(dataPoint.theta, (0x12 << 16) | (0x11 << 8) | 0x10, "theta should be parsed correctly")
self.assertEqual(dataPoint.lowAlpha, (0x9 << 16) | (0x8 << 8) | 0x7, "lowAlpha should be parsed correctly")
self.assertEqual(dataPoint.highAlpha, (0x14 << 16) | (0x13 << 8) | 0x17, "highAlpha should be parsed correctly")
self.assertEqual(dataPoint.lowBeta, (0x12 << 16) | (0x11 << 8) | 0x10, "lowBeta should be parsed correctly")
self.assertEqual(dataPoint.highBeta, (0x9 << 16) | (0x8 << 8) | 0x5, "highBeta should be parsed correctly")
self.assertEqual(dataPoint.lowGamma, (0xaf << 16) | (0x13 << 8) | 0xbf, "lowGamma should be parsed correctly")
self.assertEqual(dataPoint.midGamma, (0x0 << 16) | (0x1 << 8) | 0x0, "midGamma should be parsed correctly")
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
646,
2882,
199,
504,
603,
688,
10024,
2726,
17215,
2842,
492,
603,
688,
10024,
2726,
17215,
2842,
199,
504,
603,
688,
10024,
1451,
10225,
492,
13480,
1451,
3428,
12,
4376,
269,
11274,
4670,
1451,
3428,
4202,
272,
3194,
1741,
425,
1451,
3428,
12,
2854,
9553,
1451,
3428,
12,
662,
4680,
23432,
1192,
1451,
3428,
12,
699,
1073,
1451,
3428,
4388,
199,
533,
6077,
7963,
1110,
774,
8,
2796,
14,
1746,
304,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
4886,
275,
359,
16,
88,
1257,
12,
378,
88,
996,
12,
378,
88,
2259,
12,
378,
88,
16,
61,
327,
1642,
3066,
574,
267,
4886,
14,
2880,
779,
16,
88,
1257,
12,
378,
88,
996,
12,
378,
88,
969,
12,
378,
88,
713,
566,
327,
3499,
3066,
574,
267,
4886,
14,
2880,
779,
16,
88,
18,
12,
378,
88,
1229,
566,
327,
1115,
269,
4673,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
20,
12,
378,
88,
821,
566,
327,
22814,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
21,
12,
378,
88,
1276,
566,
327,
562,
1741,
425,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
975,
12,
378,
88,
1046,
566,
327,
330,
1073,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
2658,
12,
378,
88,
1085,
12,
378,
88,
1046,
12,
378,
88,
969,
12,
378,
88,
1196,
12,
378,
88,
713,
12,
378,
88,
845,
12,
378,
88,
709,
12,
378,
88,
25,
12,
378,
88,
24,
12,
378,
88,
23,
566,
327,
650,
325,
5902,
13131,
1192,
267,
4886,
14,
2880,
779,
16,
88,
1079,
12,
378,
88,
969,
12,
378,
88,
1196,
12,
378,
88,
713,
12,
378,
88,
845,
12,
378,
88,
709,
12,
378,
88,
25,
12,
378,
88,
24,
12,
378,
88,
21,
566,
327,
650,
1655,
325,
5902,
13131,
1192,
267,
4886,
14,
2880,
779,
16,
10850,
12,
378,
88,
969,
12,
378,
9566,
12,
378,
88,
16,
12,
378,
88,
17,
12,
378,
88,
16,
566,
327,
499,
1655,
325,
5902,
13131,
1192,
267,
843,
423,
4749,
2842,
275,
603,
688,
10024,
2726,
17215,
2842,
8,
4749,
9,
267,
843,
423,
576,
10225,
275,
843,
423,
4749,
2842,
14,
1122,
1451,
10225,
342,
2286,
347,
511,
20568,
7963,
1110,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
16,
61,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
1773,
1110,
12,
971,
3303,
13480,
1451,
3428,
12,
334,
16,
88,
2259,
5213,
1695,
9,
1204,
378,
88,
16,
4202,
3303,
298,
5626,
2198,
3211,
1642,
3066,
574,
531,
2286,
347,
511,
20568,
11906,
7963,
1110,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
17,
61,
18418,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
1773,
1110,
12,
971,
3303,
13480,
1451,
3428,
12,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
713,
4202,
3303,
298,
5626,
2198,
3211,
3499,
3066,
574,
531,
2286,
347,
511,
20568,
1575,
269,
11274,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
18,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
4606,
3466,
21446,
12,
971,
3303,
4376,
269,
11274,
4670,
1451,
3428,
12,
378,
88,
1229,
4202,
3303,
298,
5626,
2198,
3211,
11145,
2166,
531,
2286,
347,
511,
20568,
1271,
9553,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
19,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
22393,
1110,
12,
971,
3303,
2854,
9553,
1451,
3428,
12,
378,
88,
821,
4202,
3303,
298,
5626,
2198,
3211,
22814,
2166,
531,
2286,
347,
511,
20568,
1352,
1741,
425,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
20,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
278,
1741,
425,
1110,
12,
971,
3303,
3194,
1741,
425,
1451,
3428,
12,
378,
88,
1276,
4202,
3303,
298,
5626,
2198,
3211,
562,
1741,
425,
2166,
531,
2286,
347,
511,
20568,
34,
1073,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
21,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
24042,
1110,
12,
971,
3303,
699,
1073,
1451,
3428,
12,
378,
88,
1046,
4202,
3303,
298,
5626,
2198,
3211,
330,
1073,
2166,
531,
5493,
347,
7664,
1110,
19993,
590,
8,
277,
12,
3503,
2543,
12,
3503,
1110,
12,
1420,
2543,
12,
1420,
1110,
12,
1499,
304,
267,
291,
14,
1815,
8,
6514,
2543,
365,
1420,
2543,
12,
1499,
9,
267,
291,
14,
629,
8,
6514,
1110,
12,
1420,
1110,
12,
1499,
9,
2286,
347,
511,
20568,
8699,
2226,
69,
1090,
83,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
22,
11566,
267,
291,
14,
3436,
8,
576,
3428,
855,
533,
3108,
662,
4680,
23432,
1192,
1451,
3428,
12,
298,
1024,
71,
13131,
1192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
3136,
12,
334,
16,
88,
1046,
5213,
3193,
9,
1204,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
1196,
12,
298,
3136,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
9337,
12,
334,
16,
88,
713,
5213,
3193,
9,
1204,
334,
16,
88,
845,
5213,
1695,
9,
1204,
378,
88,
709,
12,
298,
9337,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
674,
16192,
12,
334,
16,
88,
25,
5213,
3193,
9,
1204,
334,
16,
88,
24,
5213,
1695,
9,
1204,
378,
88,
23,
12,
298,
674,
16192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
6260,
16192,
12,
334,
16,
88,
1079,
5213,
3193,
9,
1204,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
1196,
12,
298,
6260,
16192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
674,
21732
] |
[
2882,
199,
504,
603,
688,
10024,
2726,
17215,
2842,
492,
603,
688,
10024,
2726,
17215,
2842,
199,
504,
603,
688,
10024,
1451,
10225,
492,
13480,
1451,
3428,
12,
4376,
269,
11274,
4670,
1451,
3428,
4202,
272,
3194,
1741,
425,
1451,
3428,
12,
2854,
9553,
1451,
3428,
12,
662,
4680,
23432,
1192,
1451,
3428,
12,
699,
1073,
1451,
3428,
4388,
199,
533,
6077,
7963,
1110,
774,
8,
2796,
14,
1746,
304,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
4886,
275,
359,
16,
88,
1257,
12,
378,
88,
996,
12,
378,
88,
2259,
12,
378,
88,
16,
61,
327,
1642,
3066,
574,
267,
4886,
14,
2880,
779,
16,
88,
1257,
12,
378,
88,
996,
12,
378,
88,
969,
12,
378,
88,
713,
566,
327,
3499,
3066,
574,
267,
4886,
14,
2880,
779,
16,
88,
18,
12,
378,
88,
1229,
566,
327,
1115,
269,
4673,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
20,
12,
378,
88,
821,
566,
327,
22814,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
21,
12,
378,
88,
1276,
566,
327,
562,
1741,
425,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
975,
12,
378,
88,
1046,
566,
327,
330,
1073,
2166,
574,
267,
4886,
14,
2880,
779,
16,
88,
2658,
12,
378,
88,
1085,
12,
378,
88,
1046,
12,
378,
88,
969,
12,
378,
88,
1196,
12,
378,
88,
713,
12,
378,
88,
845,
12,
378,
88,
709,
12,
378,
88,
25,
12,
378,
88,
24,
12,
378,
88,
23,
566,
327,
650,
325,
5902,
13131,
1192,
267,
4886,
14,
2880,
779,
16,
88,
1079,
12,
378,
88,
969,
12,
378,
88,
1196,
12,
378,
88,
713,
12,
378,
88,
845,
12,
378,
88,
709,
12,
378,
88,
25,
12,
378,
88,
24,
12,
378,
88,
21,
566,
327,
650,
1655,
325,
5902,
13131,
1192,
267,
4886,
14,
2880,
779,
16,
10850,
12,
378,
88,
969,
12,
378,
9566,
12,
378,
88,
16,
12,
378,
88,
17,
12,
378,
88,
16,
566,
327,
499,
1655,
325,
5902,
13131,
1192,
267,
843,
423,
4749,
2842,
275,
603,
688,
10024,
2726,
17215,
2842,
8,
4749,
9,
267,
843,
423,
576,
10225,
275,
843,
423,
4749,
2842,
14,
1122,
1451,
10225,
342,
2286,
347,
511,
20568,
7963,
1110,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
16,
61,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
1773,
1110,
12,
971,
3303,
13480,
1451,
3428,
12,
334,
16,
88,
2259,
5213,
1695,
9,
1204,
378,
88,
16,
4202,
3303,
298,
5626,
2198,
3211,
1642,
3066,
574,
531,
2286,
347,
511,
20568,
11906,
7963,
1110,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
17,
61,
18418,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
1773,
1110,
12,
971,
3303,
13480,
1451,
3428,
12,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
713,
4202,
3303,
298,
5626,
2198,
3211,
3499,
3066,
574,
531,
2286,
347,
511,
20568,
1575,
269,
11274,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
18,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
4606,
3466,
21446,
12,
971,
3303,
4376,
269,
11274,
4670,
1451,
3428,
12,
378,
88,
1229,
4202,
3303,
298,
5626,
2198,
3211,
11145,
2166,
531,
2286,
347,
511,
20568,
1271,
9553,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
19,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
22393,
1110,
12,
971,
3303,
2854,
9553,
1451,
3428,
12,
378,
88,
821,
4202,
3303,
298,
5626,
2198,
3211,
22814,
2166,
531,
2286,
347,
511,
20568,
1352,
1741,
425,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
20,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
278,
1741,
425,
1110,
12,
971,
3303,
3194,
1741,
425,
1451,
3428,
12,
378,
88,
1276,
4202,
3303,
298,
5626,
2198,
3211,
562,
1741,
425,
2166,
531,
2286,
347,
511,
20568,
34,
1073,
4670,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
21,
11566,
267,
291,
14,
19332,
1110,
19993,
590,
8,
576,
3428,
855,
533,
3108,
666,
3428,
14,
24042,
1110,
12,
971,
3303,
699,
1073,
1451,
3428,
12,
378,
88,
1046,
4202,
3303,
298,
5626,
2198,
3211,
330,
1073,
2166,
531,
5493,
347,
7664,
1110,
19993,
590,
8,
277,
12,
3503,
2543,
12,
3503,
1110,
12,
1420,
2543,
12,
1420,
1110,
12,
1499,
304,
267,
291,
14,
1815,
8,
6514,
2543,
365,
1420,
2543,
12,
1499,
9,
267,
291,
14,
629,
8,
6514,
1110,
12,
1420,
1110,
12,
1499,
9,
2286,
347,
511,
20568,
8699,
2226,
69,
1090,
83,
19993,
590,
8,
277,
304,
267,
666,
3428,
275,
291,
423,
576,
10225,
59,
22,
11566,
267,
291,
14,
3436,
8,
576,
3428,
855,
533,
3108,
662,
4680,
23432,
1192,
1451,
3428,
12,
298,
1024,
71,
13131,
1192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
3136,
12,
334,
16,
88,
1046,
5213,
3193,
9,
1204,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
1196,
12,
298,
3136,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
9337,
12,
334,
16,
88,
713,
5213,
3193,
9,
1204,
334,
16,
88,
845,
5213,
1695,
9,
1204,
378,
88,
709,
12,
298,
9337,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
674,
16192,
12,
334,
16,
88,
25,
5213,
3193,
9,
1204,
334,
16,
88,
24,
5213,
1695,
9,
1204,
378,
88,
23,
12,
298,
674,
16192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
6260,
16192,
12,
334,
16,
88,
1079,
5213,
3193,
9,
1204,
334,
16,
88,
969,
5213,
1695,
9,
1204,
378,
88,
1196,
12,
298,
6260,
16192,
1077,
506,
4565,
6657,
531,
267,
291,
14,
629,
8,
576,
3428,
14,
674,
21732,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
feliperfranca/django-nonrel-example
|
django/contrib/gis/utils/wkt.py
|
419
|
1846
|
"""
Utilities for manipulating Geometry WKT.
"""
def precision_wkt(geom, prec):
"""
Returns WKT text of the geometry according to the given precision (an
integer or a string). If the precision is an integer, then the decimal
places of coordinates WKT will be truncated to that number:
>>> pnt = Point(5, 23)
>>> pnt.wkt
'POINT (5.0000000000000000 23.0000000000000000)'
>>> precision(geom, 1)
'POINT (5.0 23.0)'
If the precision is a string, it must be valid Python format string
(e.g., '%20.7f') -- thus, you should know what you're doing.
"""
if isinstance(prec, int):
num_fmt = '%%.%df' % prec
elif isinstance(prec, basestring):
num_fmt = prec
else:
raise TypeError
# TODO: Support 3D geometries.
coord_fmt = ' '.join([num_fmt, num_fmt])
def formatted_coords(coords):
return ','.join([coord_fmt % c[:2] for c in coords])
def formatted_poly(poly):
return ','.join(['(%s)' % formatted_coords(r) for r in poly])
def formatted_geom(g):
gtype = str(g.geom_type).upper()
yield '%s(' % gtype
if gtype == 'POINT':
yield formatted_coords((g.coords,))
elif gtype in ('LINESTRING', 'LINEARRING'):
yield formatted_coords(g.coords)
elif gtype in ('POLYGON', 'MULTILINESTRING'):
yield formatted_poly(g)
elif gtype == 'MULTIPOINT':
yield formatted_coords(g.coords)
elif gtype == 'MULTIPOLYGON':
yield ','.join(['(%s)' % formatted_poly(p) for p in g])
elif gtype == 'GEOMETRYCOLLECTION':
yield ','.join([''.join([wkt for wkt in formatted_geom(child)]) for child in g])
else:
raise TypeError
yield ')'
return ''.join([wkt for wkt in formatted_geom(geom)])
|
bsd-3-clause
|
[
624,
199,
738,
17933,
367,
13335,
20529,
10579,
22561,
14,
199,
624,
199,
199,
318,
7151,
63,
11412,
8,
6481,
12,
13826,
304,
272,
408,
272,
1803,
22561,
1318,
402,
314,
3400,
7182,
370,
314,
1627,
7151,
334,
290,
5591,
3000,
503,
282,
1059,
680,
221,
982,
314,
7151,
365,
376,
3000,
12,
2066,
314,
6107,
272,
9825,
402,
8983,
22561,
911,
506,
17661,
370,
626,
1329,
26,
10813,
1306,
19948,
275,
7584,
8,
21,
12,
6546,
9,
1362,
1306,
19948,
14,
11412,
1362,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
1362,
1306,
7151,
8,
6481,
12,
413,
9,
1362,
283,
7217,
334,
21,
14,
16,
6546,
14,
16,
3171,
339,
982,
314,
7151,
365,
282,
1059,
12,
652,
1471,
506,
1686,
2018,
1475,
1059,
5591,
334,
69,
14,
71,
2020,
1543,
1165,
14,
23,
70,
358,
1553,
12850,
12,
1265,
1077,
5715,
4052,
1265,
3984,
9689,
14,
272,
408,
272,
340,
1228,
8,
9218,
12,
1109,
304,
267,
1967,
63,
5045,
275,
23100,
4111,
1587,
7,
450,
13826,
272,
916,
1228,
8,
9218,
12,
7116,
304,
267,
1967,
63,
5045,
275,
13826,
272,
587,
26,
267,
746,
3146,
339,
327,
3254,
26,
12502,
650,
36,
24883,
14,
272,
11021,
63,
5045,
275,
283,
1987,
904,
779,
1507,
63,
5045,
12,
1967,
63,
5045,
566,
339,
347,
7871,
63,
8032,
8,
8032,
304,
267,
372,
12814,
904,
779,
7988,
63,
5045,
450,
286,
1491,
18,
61,
367,
286,
315,
13259,
566,
339,
347,
7871,
63,
6023,
8,
6023,
304,
267,
372,
12814,
904,
2941,
4042,
83,
3171,
450,
7871,
63,
8032,
8,
82,
9,
367,
519,
315,
8446,
566,
339,
347,
7871,
63,
6481,
8,
71,
304,
267,
486,
466,
275,
620,
8,
71,
14,
6481,
63,
466,
680,
4142,
342,
267,
1995,
1543,
83,
360,
450,
486,
466,
267,
340,
486,
466,
508,
283,
7217,
356,
288,
1995,
7871,
63,
8032,
1332,
71,
14,
8032,
4641,
267,
916,
486,
466,
315,
661,
6143,
29780,
297,
283,
6174,
1920,
1206,
735,
288,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
267,
916,
486,
466,
315,
661,
23602,
297,
283,
15635,
568,
29780,
735,
288,
1995,
7871,
63,
6023,
8,
71,
9,
267,
916,
486,
466,
508,
283,
21389,
7217,
356,
288,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
267,
916,
486,
466,
508,
283,
21389,
23602,
356,
288,
1995,
12814,
904,
2941,
4042,
83,
3171,
450,
7871,
63,
6023,
8,
80,
9,
367,
299,
315,
486,
566,
267,
916,
486,
466,
508,
283,
28472,
29374,
356,
288,
1995,
12814,
904,
2941,
1370,
904,
779,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
1739,
3948,
367,
1982,
315,
486,
566,
267,
587,
26,
288,
746,
3146,
267,
1995,
16107,
339,
372,
6522,
904,
779,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
6481,
3948,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
738,
17933,
367,
13335,
20529,
10579,
22561,
14,
199,
624,
199,
199,
318,
7151,
63,
11412,
8,
6481,
12,
13826,
304,
272,
408,
272,
1803,
22561,
1318,
402,
314,
3400,
7182,
370,
314,
1627,
7151,
334,
290,
5591,
3000,
503,
282,
1059,
680,
221,
982,
314,
7151,
365,
376,
3000,
12,
2066,
314,
6107,
272,
9825,
402,
8983,
22561,
911,
506,
17661,
370,
626,
1329,
26,
10813,
1306,
19948,
275,
7584,
8,
21,
12,
6546,
9,
1362,
1306,
19948,
14,
11412,
1362,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
1362,
1306,
7151,
8,
6481,
12,
413,
9,
1362,
283,
7217,
334,
21,
14,
16,
6546,
14,
16,
3171,
339,
982,
314,
7151,
365,
282,
1059,
12,
652,
1471,
506,
1686,
2018,
1475,
1059,
5591,
334,
69,
14,
71,
2020,
1543,
1165,
14,
23,
70,
358,
1553,
12850,
12,
1265,
1077,
5715,
4052,
1265,
3984,
9689,
14,
272,
408,
272,
340,
1228,
8,
9218,
12,
1109,
304,
267,
1967,
63,
5045,
275,
23100,
4111,
1587,
7,
450,
13826,
272,
916,
1228,
8,
9218,
12,
7116,
304,
267,
1967,
63,
5045,
275,
13826,
272,
587,
26,
267,
746,
3146,
339,
327,
3254,
26,
12502,
650,
36,
24883,
14,
272,
11021,
63,
5045,
275,
283,
1987,
904,
779,
1507,
63,
5045,
12,
1967,
63,
5045,
566,
339,
347,
7871,
63,
8032,
8,
8032,
304,
267,
372,
12814,
904,
779,
7988,
63,
5045,
450,
286,
1491,
18,
61,
367,
286,
315,
13259,
566,
339,
347,
7871,
63,
6023,
8,
6023,
304,
267,
372,
12814,
904,
2941,
4042,
83,
3171,
450,
7871,
63,
8032,
8,
82,
9,
367,
519,
315,
8446,
566,
339,
347,
7871,
63,
6481,
8,
71,
304,
267,
486,
466,
275,
620,
8,
71,
14,
6481,
63,
466,
680,
4142,
342,
267,
1995,
1543,
83,
360,
450,
486,
466,
267,
340,
486,
466,
508,
283,
7217,
356,
288,
1995,
7871,
63,
8032,
1332,
71,
14,
8032,
4641,
267,
916,
486,
466,
315,
661,
6143,
29780,
297,
283,
6174,
1920,
1206,
735,
288,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
267,
916,
486,
466,
315,
661,
23602,
297,
283,
15635,
568,
29780,
735,
288,
1995,
7871,
63,
6023,
8,
71,
9,
267,
916,
486,
466,
508,
283,
21389,
7217,
356,
288,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
267,
916,
486,
466,
508,
283,
21389,
23602,
356,
288,
1995,
12814,
904,
2941,
4042,
83,
3171,
450,
7871,
63,
6023,
8,
80,
9,
367,
299,
315,
486,
566,
267,
916,
486,
466,
508,
283,
28472,
29374,
356,
288,
1995,
12814,
904,
2941,
1370,
904,
779,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
1739,
3948,
367,
1982,
315,
486,
566,
267,
587,
26,
288,
746,
3146,
267,
1995,
16107,
339,
372,
6522,
904,
779,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
6481,
3948,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jackru/pybrain
|
pybrain/tests/unittests/structure/networks/custom/test_convolutional_nets.py
|
25
|
1916
|
"""
Let's build a convolutional network designed for board games:
>>> from pybrain.structure.networks.custom.convboard import ConvolutionalBoardNetwork
>>> from scipy import array, ravel, var
>>> N = ConvolutionalBoardNetwork(4, 3, 5)
>>> print(N.paramdim)
97
This is what a typical input would look like (on a 4x4 board)
>>> input = [[[0,0],[0,0],[0,0],[0,0]],\
[[0,0],[0,0],[0,0],[0,0]],\
[[0,0],[1,1],[0,0],[0,1]],\
[[0,0],[1,0],[1,1],[0,1]],\
]
We let the network process the input:
>>> res = N.activate(ravel(array(input)))
>>> res = res.reshape(4,4)
>>> inp = N['pad'].inputbuffer[0].reshape(6,6,2)[:,:,0]
The input of the first features (e.g. white stone presence) is in the middle, like we set it:
>>> print(inp[1:5,1:5])
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 1. 0. 0.]
[ 0. 1. 1. 0.]]
The rest of that array has been padded with an arbitrary, but identical bias weight:
>>> var(inp[0,:]) < 1e-20
True
>>> inp[0,0] != 0.0
True
On the output, all the values should be distinct, except for two in the middle above
because a cluster-size of 3x3 makes their input look identical.
The prior output was 0.0. Need to test this differently due to
print precision differences in 2 and 3.
>>> import sys
>>> res[0,1] - res[0,2] < sys.float_info.epsilon
True
>>> res[0,1] == res[0,3]
False
>>> res[1,1] == res[0,0]
False
>>> res[0,2] == res[3,2]
False
Now let's use the network, and play a game with it:
>>> from pybrain.rl.environments.twoplayergames import CaptureGameTask
>>> t = CaptureGameTask(4)
>>> tmp = t(N)
"""
__author__ = 'Tom Schaul, tom@idsia.ch'
from pybrain.tests import runModuleTestSuite
if __name__ == '__main__':
runModuleTestSuite(__import__('__main__'))
|
bsd-3-clause
|
[
624,
199,
199,
15314,
1159,
1900,
282,
17461,
279,
2784,
19829,
367,
13811,
9219,
83,
26,
272,
1306,
687,
1134,
22246,
14,
6976,
14,
7642,
14,
4229,
14,
5598,
3576,
492,
19140,
3347,
279,
18995,
4491,
272,
1306,
687,
7026,
492,
1625,
12,
660,
1090,
12,
2729,
272,
1306,
653,
275,
19140,
3347,
279,
18995,
4491,
8,
20,
12,
650,
12,
959,
9,
272,
1306,
870,
8,
46,
14,
635,
3572,
9,
272,
15997,
199,
199,
2765,
365,
4052,
282,
25780,
1324,
3955,
3648,
2839,
334,
265,
282,
841,
88,
20,
13811,
9,
339,
1306,
1324,
275,
19819,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
2365,
60,
326,
3474,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
2365,
60,
326,
3474,
16,
12,
16,
6922,
17,
12,
17,
6922,
16,
12,
16,
6922,
16,
12,
17,
2365,
60,
326,
3474,
16,
12,
16,
6922,
17,
12,
16,
6922,
17,
12,
17,
6922,
16,
12,
17,
2365,
60,
326,
1622,
199,
199,
6004,
4691,
314,
2784,
2112,
314,
1324,
26,
339,
1306,
522,
275,
653,
14,
8222,
8,
11186,
8,
1144,
8,
1210,
1724,
272,
1306,
522,
275,
522,
14,
5217,
8,
20,
12,
20,
9,
272,
1306,
10702,
275,
221,
653,
459,
6226,
2278,
1210,
2738,
59,
16,
1055,
5217,
8,
22,
12,
22,
12,
18,
24517,
11941,
16,
61,
199,
199,
1918,
1324,
402,
314,
1642,
4534,
334,
69,
14,
71,
14,
10424,
410,
368,
20024,
9,
365,
315,
314,
12180,
12,
2839,
781,
663,
652,
26,
339,
1306,
870,
8,
11416,
59,
17,
26,
21,
12,
17,
26,
21,
566,
272,
3474,
378,
14,
221,
378,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
378,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
413,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
413,
14,
221,
413,
14,
221,
378,
28132,
199,
199,
1918,
4618,
402,
626,
1625,
965,
2757,
21824,
543,
376,
9697,
12,
1325,
13130,
10671,
5401,
26,
339,
1306,
2729,
8,
11416,
59,
16,
12,
5728,
665,
413,
69,
13,
1165,
272,
715,
339,
1306,
10702,
59,
16,
12,
16,
61,
1137,
378,
14,
16,
272,
715,
199,
199,
3314,
314,
1072,
12,
1006,
314,
1338,
1077,
506,
15392,
12,
871,
367,
2877,
315,
314,
12180,
3432,
199,
20684,
282,
4350,
13,
890,
402,
650,
88,
19,
7704,
3932,
1324,
3648,
13130,
14,
339,
710,
6791,
1072,
1990,
378,
14,
16,
14,
14012,
370,
511,
642,
23142,
7037,
370,
272,
870,
7151,
15109,
315,
499,
436,
650,
14,
272,
1306,
492,
984,
272,
1306,
522,
59,
16,
12,
17,
61,
446,
522,
59,
16,
12,
18,
61,
665,
984,
14,
1609,
63,
815,
14,
15761,
272,
715,
339,
1306,
522,
59,
16,
12,
17,
61,
508,
522,
59,
16,
12,
19,
61,
272,
756,
339,
1306,
522,
59,
17,
12,
17,
61,
508,
522,
59,
16,
12,
16,
61,
272,
756,
339,
1306,
522,
59,
16,
12,
18,
61,
508,
522,
59,
19,
12,
18,
61,
272,
756,
199,
199,
14351,
4691,
1159,
675,
314,
2784,
12,
436,
5232,
282,
9219,
543,
652,
26,
339,
1306,
687,
1134,
22246,
14,
4308,
14,
26411,
14,
8122,
411,
1897,
28129,
492,
29828,
11454,
4476,
272,
1306,
307,
275,
29828,
11454,
4476,
8,
20,
9,
272,
1306,
3529,
275,
307,
8,
46,
9,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
52,
676,
428,
9518,
348,
12,
370,
77,
32,
344,
10971,
14,
335,
7,
199,
199,
504,
1134,
22246,
14,
2219,
492,
1255,
2377,
10591,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
2377,
10591,
3460,
646,
363,
10714,
973,
363,
1333,
6905,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
15314,
1159,
1900,
282,
17461,
279,
2784,
19829,
367,
13811,
9219,
83,
26,
272,
1306,
687,
1134,
22246,
14,
6976,
14,
7642,
14,
4229,
14,
5598,
3576,
492,
19140,
3347,
279,
18995,
4491,
272,
1306,
687,
7026,
492,
1625,
12,
660,
1090,
12,
2729,
272,
1306,
653,
275,
19140,
3347,
279,
18995,
4491,
8,
20,
12,
650,
12,
959,
9,
272,
1306,
870,
8,
46,
14,
635,
3572,
9,
272,
15997,
199,
199,
2765,
365,
4052,
282,
25780,
1324,
3955,
3648,
2839,
334,
265,
282,
841,
88,
20,
13811,
9,
339,
1306,
1324,
275,
19819,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
2365,
60,
326,
3474,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
6922,
16,
12,
16,
2365,
60,
326,
3474,
16,
12,
16,
6922,
17,
12,
17,
6922,
16,
12,
16,
6922,
16,
12,
17,
2365,
60,
326,
3474,
16,
12,
16,
6922,
17,
12,
16,
6922,
17,
12,
17,
6922,
16,
12,
17,
2365,
60,
326,
1622,
199,
199,
6004,
4691,
314,
2784,
2112,
314,
1324,
26,
339,
1306,
522,
275,
653,
14,
8222,
8,
11186,
8,
1144,
8,
1210,
1724,
272,
1306,
522,
275,
522,
14,
5217,
8,
20,
12,
20,
9,
272,
1306,
10702,
275,
221,
653,
459,
6226,
2278,
1210,
2738,
59,
16,
1055,
5217,
8,
22,
12,
22,
12,
18,
24517,
11941,
16,
61,
199,
199,
1918,
1324,
402,
314,
1642,
4534,
334,
69,
14,
71,
14,
10424,
410,
368,
20024,
9,
365,
315,
314,
12180,
12,
2839,
781,
663,
652,
26,
339,
1306,
870,
8,
11416,
59,
17,
26,
21,
12,
17,
26,
21,
566,
272,
3474,
378,
14,
221,
378,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
378,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
413,
14,
221,
378,
14,
221,
378,
19784,
1362,
359,
378,
14,
221,
413,
14,
221,
413,
14,
221,
378,
28132,
199,
199,
1918,
4618,
402,
626,
1625,
965,
2757,
21824,
543,
376,
9697,
12,
1325,
13130,
10671,
5401,
26,
339,
1306,
2729,
8,
11416,
59,
16,
12,
5728,
665,
413,
69,
13,
1165,
272,
715,
339,
1306,
10702,
59,
16,
12,
16,
61,
1137,
378,
14,
16,
272,
715,
199,
199,
3314,
314,
1072,
12,
1006,
314,
1338,
1077,
506,
15392,
12,
871,
367,
2877,
315,
314,
12180,
3432,
199,
20684,
282,
4350,
13,
890,
402,
650,
88,
19,
7704,
3932,
1324,
3648,
13130,
14,
339,
710,
6791,
1072,
1990,
378,
14,
16,
14,
14012,
370,
511,
642,
23142,
7037,
370,
272,
870,
7151,
15109,
315,
499,
436,
650,
14,
272,
1306,
492,
984,
272,
1306,
522,
59,
16,
12,
17,
61,
446,
522,
59,
16,
12,
18,
61,
665,
984,
14,
1609,
63,
815,
14,
15761,
272,
715,
339,
1306,
522,
59,
16,
12,
17,
61,
508,
522,
59,
16,
12,
19,
61,
272,
756,
339,
1306,
522,
59,
17,
12,
17,
61,
508,
522,
59,
16,
12,
16,
61,
272,
756,
339,
1306,
522,
59,
16,
12,
18,
61,
508,
522,
59,
19,
12,
18,
61,
272,
756,
199,
199,
14351,
4691,
1159,
675,
314,
2784,
12,
436,
5232,
282,
9219,
543,
652,
26,
339,
1306,
687,
1134,
22246,
14,
4308,
14,
26411,
14,
8122,
411,
1897,
28129,
492,
29828,
11454,
4476,
272,
1306,
307,
275,
29828,
11454,
4476,
8,
20,
9,
272,
1306,
3529,
275,
307,
8,
46,
9,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
52,
676,
428,
9518,
348,
12,
370,
77,
32,
344,
10971,
14,
335,
7,
199,
199,
504,
1134,
22246,
14,
2219,
492,
1255,
2377,
10591,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
2377,
10591,
3460,
646,
363,
10714,
973,
363,
1333,
6905,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ombre5733/weos
|
src/_cmsis_rtos/test/runAllTests.py
|
1
|
1953
|
# -*- coding: utf-8 -*-
"""
*******************************************************************************
WEOS - Wrapper for embedded operating systems
Copyright (c) 2013, Manuel Freiberger
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
"""
from subprocess import call
import os
import fnmatch
STFLASH = "/opt/stlink/st-flash"
binaries = []
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.bin'):
binaries.append(os.path.join(root, filename))
for binary in binaries:
print("Download {0}".format(binary))
call([STFLASH, "write", binary, "0x8000000"])
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
14355,
1116,
9153,
523,
644,
37,
3100,
446,
21947,
367,
12169,
17406,
10460,
819,
1898,
334,
67,
9,
6171,
12,
4688,
13086,
481,
264,
73,
605,
836,
523,
2900,
4481,
4644,
14,
819,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
523,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
819,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
272,
769,
402,
3704,
436,
314,
2569,
6450,
14,
523,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
272,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
272,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
819,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
523,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
523,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
523,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
523,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
523,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
523,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
523,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
523,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
523,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
523,
9726,
1634,
9712,
9784,
14,
199,
14355,
1116,
9153,
199,
624,
199,
199,
504,
3873,
492,
1240,
199,
646,
747,
199,
646,
15951,
199,
199,
840,
3143,
8100,
275,
3286,
2992,
15,
270,
1073,
15,
270,
13,
11331,
2,
199,
199,
27542,
275,
942,
199,
199,
509,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
26461,
523,
367,
1788,
315,
15951,
14,
1541,
8,
10309,
12,
11937,
1393,
735,
489,
21984,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
1788,
430,
199,
199,
509,
3366,
315,
21984,
26,
272,
870,
480,
11950,
469,
16,
5469,
908,
8,
3008,
430,
272,
1240,
779,
840,
3143,
8100,
12,
298,
952,
401,
3366,
12,
298,
16,
88,
24,
3273,
3135,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
14355,
1116,
9153,
523,
644,
37,
3100,
446,
21947,
367,
12169,
17406,
10460,
819,
1898,
334,
67,
9,
6171,
12,
4688,
13086,
481,
264,
73,
605,
836,
523,
2900,
4481,
4644,
14,
819,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
523,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
819,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
272,
769,
402,
3704,
436,
314,
2569,
6450,
14,
523,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
272,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
272,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
819,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
523,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
523,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
523,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
523,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
523,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
523,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
523,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
523,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
523,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
523,
9726,
1634,
9712,
9784,
14,
199,
14355,
1116,
9153,
199,
624,
199,
199,
504,
3873,
492,
1240,
199,
646,
747,
199,
646,
15951,
199,
199,
840,
3143,
8100,
275,
3286,
2992,
15,
270,
1073,
15,
270,
13,
11331,
2,
199,
199,
27542,
275,
942,
199,
199,
509,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
26461,
523,
367,
1788,
315,
15951,
14,
1541,
8,
10309,
12,
11937,
1393,
735,
489,
21984,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
1788,
430,
199,
199,
509,
3366,
315,
21984,
26,
272,
870,
480,
11950,
469,
16,
5469,
908,
8,
3008,
430,
272,
1240,
779,
840,
3143,
8100,
12,
298,
952,
401,
3366,
12,
298,
16,
88,
24,
3273,
3135,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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