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
|
|---|---|---|---|---|---|---|---|---|
irzaip/chippy
|
scripts/robot/puma560akb.py
|
1
|
2841
|
'''
PUMA560AKB Load kinematic and dynamic data for a Puma 560 manipulator
from robot.puma560akb import *
Defines the object 'p560m' in current workspace which describes the
kinematic and dynamic characterstics of a Unimation Puma 560 manipulator
modified DH conventions and using the data and conventions of:
Armstrong, Khatib and Burdick 1986.
"The Explicit Dynamic Model and Inertial Parameters of the Puma 560 Arm"
Also define the vector qz which corresponds to the zero joint
angle configuration, qr which is the vertical 'READY' configuration,
and qstretch in which the arm is stretched out in the X direction.
@see: robot, puma560, stanford, twolink
Python implementation by: Luis Fernando Lara Tobar and Peter Corke.
Based on original Robotics Toolbox for Matlab code by Peter Corke.
Permission to use and copy is granted provided that acknowledgement of
the authors is made.
@author: Luis Fernando Lara Tobar and Peter Corke
'''
from numpy import *
from Link import *
from Robot import *
L = []
L.append(Link(alpha=0, A=0, theta=0, D=0, sigma=0, convention=2))
L.append(Link(alpha=-pi/2, A=0, theta=0, D=0.2435, sigma=0, convention=2))
L.append(Link(alpha=0, A=0.4318, theta=0, D=-0.0934, sigma=0, convention=2))
L.append(Link(alpha=pi/2, A=-0.0203, theta=0, D=.4331, sigma=0, convention=2))
L.append(Link(alpha=-pi/2, A=0, theta=0, D=0, sigma=0, convention=2))
L.append(Link(alpha=pi/2, A=0, theta=0, D=0, sigma=0, convention=2))
L[0].m = 0;
L[1].m = 17.4;
L[2].m = 4.8;
L[3].m = 0.82;
L[4].m = 0.34;
L[5].m = .09;
# rx ry rz
L[0].r = mat([0, 0, 0 ])
L[1].r = mat([0.068, 0.006, -0.016])
L[2].r = mat([0, -0.070, 0.014 ])
L[3].r = mat([0, 0, -0.019])
L[4].r = mat([0, 0, 0 ])
L[5].r = mat([0, 0, .032 ])
# Ixx Iyy Izz Ixy Iyz Ixz
L[0].I = mat([0, 0, 0.35, 0, 0, 0])
L[1].I = mat([.13, .524, .539, 0, 0, 0])
L[2].I = mat([.066, .0125, .066, 0, 0, 0])
L[3].I = mat([1.8e-3, 1.8e-3, 1.3e-3, 0, 0, 0])
L[4].I = mat([.3e-3, .3e-3, .4e-3, 0, 0, 0])
L[5].I = mat([.15e-3, .15e-3, .04e-3, 0, 0, 0])
L[0].Jm = 291e-6;
L[1].Jm = 409e-6;
L[2].Jm = 299e-6;
L[3].Jm = 35e-6;
L[4].Jm = 35e-6;
L[5].Jm = 35e-6;
L[0].G = -62.6111;
L[1].G = 107.815;
L[2].G = -53.7063;
L[3].G = 76.0364;
L[4].G = 71.923;
L[5].G = 76.686;
# viscous friction (motor referenced)
# unknown
# Coulomb friction (motor referenced)
# unknown
#
# some useful poses
#
qz = [0,0,0,0,0,0]; # zero angles, L shaped pose
qr = [0,-pi/2,pi/2,0,0,0]; # ready pose, arm up
qstretch = [0,0,pi/2,0,0,0]; # horizontal along x-axis
p560m = Robot(L, name='Puma560-AKB', manuf='Unimation', comment='AK&B')
|
lgpl-3.0
|
[
2344,
199,
6903,
2054,
15789,
7872,
34,
7190,
1022,
1132,
3889,
436,
8336,
666,
367,
282,
510,
85,
391,
959,
2259,
13335,
6109,
421,
198,
504,
14544,
14,
3165,
391,
15789,
1151,
66,
492,
627,
199,
199,
23891,
314,
909,
283,
80,
15789,
77,
7,
315,
1453,
14466,
1314,
23369,
314,
221,
199,
75,
1132,
3889,
436,
8336,
4528,
8323,
402,
282,
1910,
8182,
510,
85,
391,
959,
2259,
13335,
6109,
221,
199,
5540,
23427,
8758,
852,
436,
1808,
314,
666,
436,
8758,
852,
402,
26,
421,
198,
1596,
77,
9370,
12,
1804,
72,
2159,
66,
436,
699,
300,
328,
346,
5851,
1184,
14,
199,
198,
2,
1918,
23872,
21907,
5822,
436,
1010,
281,
1009,
3897,
402,
314,
510,
85,
391,
959,
2259,
1952,
77,
2,
199,
199,
31892,
5627,
314,
5477,
1894,
90,
1314,
13718,
370,
314,
4697,
22211,
199,
4593,
2897,
12,
29757,
1314,
365,
314,
13763,
283,
22579,
7,
2897,
12,
199,
460,
1894,
31593,
315,
1314,
314,
30701,
365,
410,
3292,
1809,
734,
315,
314,
1323,
7581,
14,
199,
199,
32,
3239,
26,
14544,
12,
18848,
391,
15789,
12,
410,
290,
18090,
12,
8900,
393,
2292,
199,
199,
4718,
4514,
701,
26,
30936,
374,
481,
27569,
22066,
491,
17956,
4005,
1700,
436,
22912,
7499,
415,
14,
199,
20409,
641,
3379,
6848,
656,
7769,
15650,
1977,
367,
18619,
5561,
1233,
701,
22912,
7499,
415,
14,
199,
7980,
370,
675,
436,
1331,
365,
10009,
2741,
626,
19807,
23504,
434,
402,
199,
1589,
11462,
365,
6326,
14,
199,
199,
32,
2502,
26,
30936,
374,
481,
27569,
22066,
491,
17956,
4005,
1700,
436,
22912,
7499,
415,
199,
2344,
199,
199,
504,
2680,
492,
627,
199,
504,
10967,
492,
627,
199,
504,
820,
17800,
492,
627,
199,
199,
44,
275,
942,
421,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
16,
12,
258,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
4022,
1038,
15,
18,
12,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
14,
1194,
1276,
12,
221,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
16,
12,
258,
437,
29,
16,
14,
2824,
1085,
12,
221,
12724,
29,
16,
12,
577,
4022,
16,
14,
1643,
1082,
12,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
1038,
15,
18,
12,
221,
437,
4022,
16,
14,
996,
1644,
12,
12724,
29,
16,
12,
577,
15856,
20,
15638,
12,
257,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
4022,
1038,
15,
18,
12,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
1038,
15,
18,
12,
221,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
199,
44,
59,
16,
1055,
77,
275,
378,
27,
199,
44,
59,
17,
1055,
77,
275,
5557,
14,
20,
27,
199,
44,
59,
18,
1055,
77,
275,
841,
14,
24,
27,
199,
44,
59,
19,
1055,
77,
275,
378,
14,
2564,
27,
199,
44,
59,
20,
1055,
77,
275,
378,
14,
1082,
27,
199,
44,
59,
21,
1055,
77,
275,
1275,
1643,
27,
199,
199,
3,
260,
12951,
420,
519,
89,
420,
519,
90,
199,
44,
59,
16,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
378,
198,
566,
199,
44,
59,
17,
1055,
82,
275,
2530,
779,
16,
14,
19846,
12,
257,
378,
14,
8010,
12,
257,
446,
16,
14,
10882,
566,
199,
44,
59,
18,
1055,
82,
275,
2530,
779,
16,
12,
257,
446,
16,
14,
19235,
12,
221,
378,
14,
10752,
4794,
199,
44,
59,
19,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
446,
16,
14,
12512,
566,
199,
44,
59,
20,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
378,
198,
566,
199,
44,
59,
21,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
1275,
21683,
198,
566,
199,
199,
3,
3322,
473,
2154,
263,
473,
7566,
263,
473,
4348,
420,
473,
1702,
259,
473,
19873,
258,
473,
19196,
199,
44,
59,
16,
1055,
41,
275,
2530,
779,
16,
12,
260,
378,
12,
198,
221,
378,
14,
1276,
12,
420,
378,
12,
198,
259,
378,
12,
198,
259,
378,
566,
199,
44,
59,
17,
1055,
41,
275,
2530,
779,
14,
969,
12,
420,
1275,
26419,
12,
258,
1275,
25391,
12,
420,
378,
12,
198,
259,
378,
12,
198,
259,
378,
566,
199,
44,
59,
18,
1055,
41,
275,
2530,
779,
14,
14045,
12,
258,
1275,
614,
821,
12,
259,
1275,
14045,
12,
420,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
19,
1055,
41,
275,
2530,
779,
17,
14,
24,
69,
13,
19,
12,
221,
413,
14,
24,
69,
13,
19,
12,
257,
413,
14,
19,
69,
13,
19,
12,
258,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
20,
1055,
41,
275,
2530,
779,
14,
19,
69,
13,
19,
12,
259,
1275,
19,
69,
13,
19,
12,
259,
1275,
20,
69,
13,
19,
12,
258,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
21,
1055,
41,
275,
2530,
779,
14,
1046,
69,
13,
19,
12,
257,
1275,
1046,
69,
13,
19,
12,
257,
1275,
966,
69,
13,
19,
12,
259,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
199,
44,
59,
16,
1055,
42,
77,
275,
221,
499,
3328,
69,
13,
22,
27,
199,
44,
59,
17,
1055,
42,
77,
275,
221,
21292,
69,
13,
22,
27,
199,
44,
59,
18,
1055,
42,
77,
275,
221,
32730,
69,
13,
22,
27,
199,
44,
59,
19,
1055,
42,
77,
275,
221,
8685,
69,
13,
22,
27,
199,
44,
59,
20,
1055,
42,
77,
275,
221,
8685,
69,
13,
22,
27,
199,
44,
59,
21,
1055,
42
] |
[
199,
6903,
2054,
15789,
7872,
34,
7190,
1022,
1132,
3889,
436,
8336,
666,
367,
282,
510,
85,
391,
959,
2259,
13335,
6109,
421,
198,
504,
14544,
14,
3165,
391,
15789,
1151,
66,
492,
627,
199,
199,
23891,
314,
909,
283,
80,
15789,
77,
7,
315,
1453,
14466,
1314,
23369,
314,
221,
199,
75,
1132,
3889,
436,
8336,
4528,
8323,
402,
282,
1910,
8182,
510,
85,
391,
959,
2259,
13335,
6109,
221,
199,
5540,
23427,
8758,
852,
436,
1808,
314,
666,
436,
8758,
852,
402,
26,
421,
198,
1596,
77,
9370,
12,
1804,
72,
2159,
66,
436,
699,
300,
328,
346,
5851,
1184,
14,
199,
198,
2,
1918,
23872,
21907,
5822,
436,
1010,
281,
1009,
3897,
402,
314,
510,
85,
391,
959,
2259,
1952,
77,
2,
199,
199,
31892,
5627,
314,
5477,
1894,
90,
1314,
13718,
370,
314,
4697,
22211,
199,
4593,
2897,
12,
29757,
1314,
365,
314,
13763,
283,
22579,
7,
2897,
12,
199,
460,
1894,
31593,
315,
1314,
314,
30701,
365,
410,
3292,
1809,
734,
315,
314,
1323,
7581,
14,
199,
199,
32,
3239,
26,
14544,
12,
18848,
391,
15789,
12,
410,
290,
18090,
12,
8900,
393,
2292,
199,
199,
4718,
4514,
701,
26,
30936,
374,
481,
27569,
22066,
491,
17956,
4005,
1700,
436,
22912,
7499,
415,
14,
199,
20409,
641,
3379,
6848,
656,
7769,
15650,
1977,
367,
18619,
5561,
1233,
701,
22912,
7499,
415,
14,
199,
7980,
370,
675,
436,
1331,
365,
10009,
2741,
626,
19807,
23504,
434,
402,
199,
1589,
11462,
365,
6326,
14,
199,
199,
32,
2502,
26,
30936,
374,
481,
27569,
22066,
491,
17956,
4005,
1700,
436,
22912,
7499,
415,
199,
2344,
199,
199,
504,
2680,
492,
627,
199,
504,
10967,
492,
627,
199,
504,
820,
17800,
492,
627,
199,
199,
44,
275,
942,
421,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
16,
12,
258,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
4022,
1038,
15,
18,
12,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
14,
1194,
1276,
12,
221,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
16,
12,
258,
437,
29,
16,
14,
2824,
1085,
12,
221,
12724,
29,
16,
12,
577,
4022,
16,
14,
1643,
1082,
12,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
1038,
15,
18,
12,
221,
437,
4022,
16,
14,
996,
1644,
12,
12724,
29,
16,
12,
577,
15856,
20,
15638,
12,
257,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
4022,
1038,
15,
18,
12,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
44,
14,
740,
8,
3834,
8,
4468,
29,
1038,
15,
18,
12,
221,
437,
29,
16,
12,
755,
12724,
29,
16,
12,
577,
29,
16,
12,
755,
10819,
29,
16,
12,
16129,
29,
18,
430,
199,
199,
44,
59,
16,
1055,
77,
275,
378,
27,
199,
44,
59,
17,
1055,
77,
275,
5557,
14,
20,
27,
199,
44,
59,
18,
1055,
77,
275,
841,
14,
24,
27,
199,
44,
59,
19,
1055,
77,
275,
378,
14,
2564,
27,
199,
44,
59,
20,
1055,
77,
275,
378,
14,
1082,
27,
199,
44,
59,
21,
1055,
77,
275,
1275,
1643,
27,
199,
199,
3,
260,
12951,
420,
519,
89,
420,
519,
90,
199,
44,
59,
16,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
378,
198,
566,
199,
44,
59,
17,
1055,
82,
275,
2530,
779,
16,
14,
19846,
12,
257,
378,
14,
8010,
12,
257,
446,
16,
14,
10882,
566,
199,
44,
59,
18,
1055,
82,
275,
2530,
779,
16,
12,
257,
446,
16,
14,
19235,
12,
221,
378,
14,
10752,
4794,
199,
44,
59,
19,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
446,
16,
14,
12512,
566,
199,
44,
59,
20,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
378,
198,
566,
199,
44,
59,
21,
1055,
82,
275,
2530,
779,
16,
12,
257,
378,
12,
198,
221,
1275,
21683,
198,
566,
199,
199,
3,
3322,
473,
2154,
263,
473,
7566,
263,
473,
4348,
420,
473,
1702,
259,
473,
19873,
258,
473,
19196,
199,
44,
59,
16,
1055,
41,
275,
2530,
779,
16,
12,
260,
378,
12,
198,
221,
378,
14,
1276,
12,
420,
378,
12,
198,
259,
378,
12,
198,
259,
378,
566,
199,
44,
59,
17,
1055,
41,
275,
2530,
779,
14,
969,
12,
420,
1275,
26419,
12,
258,
1275,
25391,
12,
420,
378,
12,
198,
259,
378,
12,
198,
259,
378,
566,
199,
44,
59,
18,
1055,
41,
275,
2530,
779,
14,
14045,
12,
258,
1275,
614,
821,
12,
259,
1275,
14045,
12,
420,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
19,
1055,
41,
275,
2530,
779,
17,
14,
24,
69,
13,
19,
12,
221,
413,
14,
24,
69,
13,
19,
12,
257,
413,
14,
19,
69,
13,
19,
12,
258,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
20,
1055,
41,
275,
2530,
779,
14,
19,
69,
13,
19,
12,
259,
1275,
19,
69,
13,
19,
12,
259,
1275,
20,
69,
13,
19,
12,
258,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
44,
59,
21,
1055,
41,
275,
2530,
779,
14,
1046,
69,
13,
19,
12,
257,
1275,
1046,
69,
13,
19,
12,
257,
1275,
966,
69,
13,
19,
12,
259,
378,
12,
258,
378,
12,
198,
259,
378,
566,
199,
199,
44,
59,
16,
1055,
42,
77,
275,
221,
499,
3328,
69,
13,
22,
27,
199,
44,
59,
17,
1055,
42,
77,
275,
221,
21292,
69,
13,
22,
27,
199,
44,
59,
18,
1055,
42,
77,
275,
221,
32730,
69,
13,
22,
27,
199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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
doismellburning/django
|
django/views/generic/detail.py
|
29
|
6696
|
from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.http import Http404
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateResponseMixin, ContextMixin, View
class SingleObjectMixin(ContextMixin):
"""
Provides the ability to retrieve a single object for further manipulation.
"""
model = None
queryset = None
slug_field = 'slug'
context_object_name = None
slug_url_kwarg = 'slug'
pk_url_kwarg = 'pk'
query_pk_and_slug = False
def get_object(self, queryset=None):
"""
Returns the object the view is displaying.
By default this requires `self.queryset` and a `pk` or `slug` argument
in the URLconf, but subclasses can override this to return any object.
"""
# Use a custom queryset if provided; this is required for subclasses
# like DateDetailView
if queryset is None:
queryset = self.get_queryset()
# Next, try looking up by primary key.
pk = self.kwargs.get(self.pk_url_kwarg, None)
slug = self.kwargs.get(self.slug_url_kwarg, None)
if pk is not None:
queryset = queryset.filter(pk=pk)
# Next, try looking up by slug.
if slug is not None and (pk is None or self.query_pk_and_slug):
slug_field = self.get_slug_field()
queryset = queryset.filter(**{slug_field: slug})
# If none of those are defined, it's an error.
if pk is None and slug is None:
raise AttributeError("Generic detail view %s must be called with "
"either an object pk or a slug."
% self.__class__.__name__)
try:
# Get the single item from the filtered queryset
obj = queryset.get()
except queryset.model.DoesNotExist:
raise Http404(_("No %(verbose_name)s found matching the query") %
{'verbose_name': queryset.model._meta.verbose_name})
return obj
def get_queryset(self):
"""
Return the `QuerySet` that will be used to look up the object.
Note that this method is called by the default implementation of
`get_object` and may not be called if `get_object` is overridden.
"""
if self.queryset is None:
if self.model:
return self.model._default_manager.all()
else:
raise ImproperlyConfigured(
"%(cls)s is missing a QuerySet. Define "
"%(cls)s.model, %(cls)s.queryset, or override "
"%(cls)s.get_queryset()." % {
'cls': self.__class__.__name__
}
)
return self.queryset.all()
def get_slug_field(self):
"""
Get the name of a slug field to be used to look up by slug.
"""
return self.slug_field
def get_context_object_name(self, obj):
"""
Get the name to use for the object.
"""
if self.context_object_name:
return self.context_object_name
elif isinstance(obj, models.Model):
return obj._meta.model_name
else:
return None
def get_context_data(self, **kwargs):
"""
Insert the single object into the context dict.
"""
context = {}
if self.object:
context['object'] = self.object
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
context[context_object_name] = self.object
context.update(kwargs)
return super(SingleObjectMixin, self).get_context_data(**context)
class BaseDetailView(SingleObjectMixin, View):
"""
A base view for displaying a single object
"""
def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_field = None
template_name_suffix = '_detail'
def get_template_names(self):
"""
Return a list of template names to be used for the request. May not be
called if render_to_response is overridden. Returns the following list:
* the value of ``template_name`` on the view (if provided)
* the contents of the ``template_name_field`` field on the
object instance that the view is operating upon (if available)
* ``<app_label>/<model_name><template_name_suffix>.html``
"""
try:
names = super(SingleObjectTemplateResponseMixin, self).get_template_names()
except ImproperlyConfigured:
# If template_name isn't specified, it's not a problem --
# we just start with an empty list.
names = []
# If self.template_name_field is set, grab the value of the field
# of that name from the object; this is the most specific template
# name, if given.
if self.object and self.template_name_field:
name = getattr(self.object, self.template_name_field, None)
if name:
names.insert(0, name)
# The least-specific option is the default <app>/<model>_detail.html;
# only use this if the object in question is a model.
if isinstance(self.object, models.Model):
names.append("%s/%s%s.html" % (
self.object._meta.app_label,
self.object._meta.model_name,
self.template_name_suffix
))
elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model):
names.append("%s/%s%s.html" % (
self.model._meta.app_label,
self.model._meta.model_name,
self.template_name_suffix
))
# If we still haven't managed to find any template names, we should
# re-raise the ImproperlyConfigured to alert the user.
if not names:
raise
return names
class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView):
"""
Render a "detail" view of an object.
By default this is a model instance looked up from `self.queryset`, but the
view will support display of *any* object by overriding `self.get_object()`.
"""
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
29264,
4256,
12,
9470,
4256,
12,
10935,
421,
199,
533,
13050,
1692,
4256,
8,
2998,
4256,
304,
272,
408,
272,
21552,
314,
21255,
370,
8044,
282,
2849,
909,
367,
9848,
26212,
14,
272,
408,
272,
1402,
275,
488,
272,
7594,
275,
488,
272,
8889,
63,
698,
275,
283,
5464,
7,
272,
1067,
63,
785,
63,
354,
275,
488,
272,
8889,
63,
633,
63,
12745,
275,
283,
5464,
7,
272,
3803,
63,
633,
63,
12745,
275,
283,
2051,
7,
272,
1827,
63,
2051,
63,
460,
63,
5464,
275,
756,
339,
347,
664,
63,
785,
8,
277,
12,
7594,
29,
403,
304,
267,
408,
267,
1803,
314,
909,
314,
2455,
365,
20589,
14,
398,
4885,
849,
642,
5074,
658,
277,
14,
7924,
64,
436,
282,
658,
2051,
64,
503,
658,
5464,
64,
1423,
267,
315,
314,
2851,
2190,
12,
1325,
9180,
883,
4278,
642,
370,
372,
1263,
909,
14,
267,
408,
267,
327,
3645,
282,
3537,
7594,
340,
2741,
27,
642,
365,
1415,
367,
9180,
267,
327,
2839,
6148,
28539,
267,
340,
7594,
365,
488,
26,
288,
7594,
275,
291,
14,
362,
63,
7924,
342,
398,
327,
16840,
12,
862,
10023,
1536,
701,
5062,
790,
14,
267,
3803,
275,
291,
14,
958,
14,
362,
8,
277,
14,
2051,
63,
633,
63,
12745,
12,
488,
9,
267,
8889,
275,
291,
14,
958,
14,
362,
8,
277,
14,
5464,
63,
633,
63,
12745,
12,
488,
9,
267,
340,
3803,
365,
440,
488,
26,
288,
7594,
275,
7594,
14,
1541,
8,
2051,
29,
2051,
9,
398,
327,
16840,
12,
862,
10023,
1536,
701,
8889,
14,
267,
340,
8889,
365,
440,
488,
436,
334,
2051,
365,
488,
503,
291,
14,
1131,
63,
2051,
63,
460,
63,
5464,
304,
288,
8889,
63,
698,
275,
291,
14,
362,
63,
5464,
63,
698,
342,
288,
7594,
275,
7594,
14,
1541,
25679,
5464,
63,
698,
26,
8889,
1552,
398,
327,
982,
7179,
402,
5204,
787,
3247,
12,
652,
1159,
376,
1125,
14,
267,
340,
3803,
365,
488,
436,
8889,
365,
488,
26,
288,
746,
4281,
480,
9417,
10093,
2455,
450,
83,
1471,
506,
2797,
543,
298,
639,
298,
22051,
376,
909,
3803,
503,
282,
8889,
2122,
639,
450,
291,
855,
533,
4914,
354,
3368,
398,
862,
26,
288,
327,
2372,
314,
2849,
1242,
687,
314,
9806,
7594,
288,
1559,
275,
7594,
14,
362,
342,
267,
871,
7594,
14,
1238,
14,
7400,
26,
288,
746,
4760,
5188,
6115,
1944,
2818,
3832,
63,
354,
9,
83,
1911,
4877,
314,
1827,
531,
450,
2079,
791,
3832,
63,
354,
356,
7594,
14,
1238,
423,
2024,
14,
3832,
63,
354,
1552,
267,
372,
1559,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
408,
267,
1432,
314,
658,
13689,
64,
626,
911,
506,
1202,
370,
3648,
1536,
314,
909,
14,
398,
3390,
626,
642,
1083,
365,
2797,
701,
314,
849,
4514,
402,
267,
658,
362,
63,
785,
64,
436,
1443,
440,
506,
2797,
340,
658,
362,
63,
785,
64,
365,
10087,
14,
267,
408,
267,
340,
291,
14,
7924,
365,
488,
26,
288,
340,
291,
14,
1238,
26,
355,
372,
291,
14,
1238,
423,
885,
63,
2609,
14,
452,
342,
288,
587,
26,
355,
746,
11897,
8,
490,
11792,
1886,
9,
83,
365,
4124,
282,
18397,
14,
13930,
298,
490,
11792,
1886,
9,
83,
14,
1238,
12,
2818,
1886,
9,
83,
14,
7924,
12,
503,
4278,
298,
490,
11792,
1886,
9,
83,
14,
362,
63,
7924,
1252,
2,
450,
469,
717,
283,
1886,
356,
291,
855,
533,
4914,
354,
363,
490,
789,
355,
776,
267,
372,
291,
14,
7924,
14,
452,
342,
339,
347,
664,
63,
5464,
63,
698,
8,
277,
304,
267,
408,
267,
2372,
314,
536,
402,
282,
8889,
901,
370,
506,
1202,
370,
3648,
1536,
701,
8889,
14,
267,
408,
267,
372,
291,
14,
5464,
63,
698,
339,
347,
664,
63,
1100,
63,
785,
63,
354,
8,
277,
12,
1559,
304,
267,
408,
267,
2372,
314,
536,
370,
675,
367,
314,
909,
14,
267,
408,
267,
340,
291,
14,
1100,
63,
785,
63,
354,
26,
288,
372,
291,
14,
1100,
63,
785,
63,
354,
267,
916,
1228,
8,
1113,
12,
1709,
14,
1685,
304,
288,
372,
1559,
423,
2024,
14,
1238,
63,
354,
267,
587,
26,
288,
372,
488,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
15496,
314,
2849,
909,
1901,
314,
1067,
1211,
14,
267,
408,
267,
1067,
275,
1052,
267,
340,
291,
14,
785,
26,
288,
1067,
459,
785,
418,
275,
291,
14,
785,
288,
1067,
63,
785,
63,
354,
275,
291,
14,
362,
63,
1100,
63,
785,
63,
354,
8,
277,
14,
785,
9,
288,
340,
1067,
63,
785,
63,
354,
26,
355,
1067,
59,
1100,
63,
785,
63,
354,
61,
275,
291,
14,
785,
267,
1067,
14,
873,
8,
958,
9,
267,
372,
1613,
8,
7200,
1692,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
1100,
9,
421,
199,
533,
3523,
28539,
8,
7200,
1692,
4256,
12,
10935,
304,
272,
408,
272,
437,
1300,
2455,
367,
20589,
282,
2849,
909,
272,
408,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
785,
275,
291,
14,
362,
63,
785,
342,
267,
1067,
275,
291,
14,
362,
63,
1100,
63,
576,
8,
785,
29,
277,
14,
785,
9,
267,
372,
291,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
421,
199,
533,
13050,
1692,
31036,
4256,
8,
31036,
4256,
304,
272,
1978,
63,
354,
63,
698,
275,
488,
272,
1978,
63,
354,
63,
4511,
275,
2513,
5506,
7,
339,
347,
664,
63,
1160,
63,
1247,
8,
277,
304,
267,
408,
267,
1432,
282,
769,
402,
1978,
1561,
370,
506,
1202,
367,
314,
1056,
14,
10162,
440,
506,
267,
2797,
340,
3795,
63,
475,
63,
1310,
365,
10087,
14,
1803,
314,
2569,
769,
26,
398,
627,
314,
574,
402,
1124,
1160
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
29264,
4256,
12,
9470,
4256,
12,
10935,
421,
199,
533,
13050,
1692,
4256,
8,
2998,
4256,
304,
272,
408,
272,
21552,
314,
21255,
370,
8044,
282,
2849,
909,
367,
9848,
26212,
14,
272,
408,
272,
1402,
275,
488,
272,
7594,
275,
488,
272,
8889,
63,
698,
275,
283,
5464,
7,
272,
1067,
63,
785,
63,
354,
275,
488,
272,
8889,
63,
633,
63,
12745,
275,
283,
5464,
7,
272,
3803,
63,
633,
63,
12745,
275,
283,
2051,
7,
272,
1827,
63,
2051,
63,
460,
63,
5464,
275,
756,
339,
347,
664,
63,
785,
8,
277,
12,
7594,
29,
403,
304,
267,
408,
267,
1803,
314,
909,
314,
2455,
365,
20589,
14,
398,
4885,
849,
642,
5074,
658,
277,
14,
7924,
64,
436,
282,
658,
2051,
64,
503,
658,
5464,
64,
1423,
267,
315,
314,
2851,
2190,
12,
1325,
9180,
883,
4278,
642,
370,
372,
1263,
909,
14,
267,
408,
267,
327,
3645,
282,
3537,
7594,
340,
2741,
27,
642,
365,
1415,
367,
9180,
267,
327,
2839,
6148,
28539,
267,
340,
7594,
365,
488,
26,
288,
7594,
275,
291,
14,
362,
63,
7924,
342,
398,
327,
16840,
12,
862,
10023,
1536,
701,
5062,
790,
14,
267,
3803,
275,
291,
14,
958,
14,
362,
8,
277,
14,
2051,
63,
633,
63,
12745,
12,
488,
9,
267,
8889,
275,
291,
14,
958,
14,
362,
8,
277,
14,
5464,
63,
633,
63,
12745,
12,
488,
9,
267,
340,
3803,
365,
440,
488,
26,
288,
7594,
275,
7594,
14,
1541,
8,
2051,
29,
2051,
9,
398,
327,
16840,
12,
862,
10023,
1536,
701,
8889,
14,
267,
340,
8889,
365,
440,
488,
436,
334,
2051,
365,
488,
503,
291,
14,
1131,
63,
2051,
63,
460,
63,
5464,
304,
288,
8889,
63,
698,
275,
291,
14,
362,
63,
5464,
63,
698,
342,
288,
7594,
275,
7594,
14,
1541,
25679,
5464,
63,
698,
26,
8889,
1552,
398,
327,
982,
7179,
402,
5204,
787,
3247,
12,
652,
1159,
376,
1125,
14,
267,
340,
3803,
365,
488,
436,
8889,
365,
488,
26,
288,
746,
4281,
480,
9417,
10093,
2455,
450,
83,
1471,
506,
2797,
543,
298,
639,
298,
22051,
376,
909,
3803,
503,
282,
8889,
2122,
639,
450,
291,
855,
533,
4914,
354,
3368,
398,
862,
26,
288,
327,
2372,
314,
2849,
1242,
687,
314,
9806,
7594,
288,
1559,
275,
7594,
14,
362,
342,
267,
871,
7594,
14,
1238,
14,
7400,
26,
288,
746,
4760,
5188,
6115,
1944,
2818,
3832,
63,
354,
9,
83,
1911,
4877,
314,
1827,
531,
450,
2079,
791,
3832,
63,
354,
356,
7594,
14,
1238,
423,
2024,
14,
3832,
63,
354,
1552,
267,
372,
1559,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
408,
267,
1432,
314,
658,
13689,
64,
626,
911,
506,
1202,
370,
3648,
1536,
314,
909,
14,
398,
3390,
626,
642,
1083,
365,
2797,
701,
314,
849,
4514,
402,
267,
658,
362,
63,
785,
64,
436,
1443,
440,
506,
2797,
340,
658,
362,
63,
785,
64,
365,
10087,
14,
267,
408,
267,
340,
291,
14,
7924,
365,
488,
26,
288,
340,
291,
14,
1238,
26,
355,
372,
291,
14,
1238,
423,
885,
63,
2609,
14,
452,
342,
288,
587,
26,
355,
746,
11897,
8,
490,
11792,
1886,
9,
83,
365,
4124,
282,
18397,
14,
13930,
298,
490,
11792,
1886,
9,
83,
14,
1238,
12,
2818,
1886,
9,
83,
14,
7924,
12,
503,
4278,
298,
490,
11792,
1886,
9,
83,
14,
362,
63,
7924,
1252,
2,
450,
469,
717,
283,
1886,
356,
291,
855,
533,
4914,
354,
363,
490,
789,
355,
776,
267,
372,
291,
14,
7924,
14,
452,
342,
339,
347,
664,
63,
5464,
63,
698,
8,
277,
304,
267,
408,
267,
2372,
314,
536,
402,
282,
8889,
901,
370,
506,
1202,
370,
3648,
1536,
701,
8889,
14,
267,
408,
267,
372,
291,
14,
5464,
63,
698,
339,
347,
664,
63,
1100,
63,
785,
63,
354,
8,
277,
12,
1559,
304,
267,
408,
267,
2372,
314,
536,
370,
675,
367,
314,
909,
14,
267,
408,
267,
340,
291,
14,
1100,
63,
785,
63,
354,
26,
288,
372,
291,
14,
1100,
63,
785,
63,
354,
267,
916,
1228,
8,
1113,
12,
1709,
14,
1685,
304,
288,
372,
1559,
423,
2024,
14,
1238,
63,
354,
267,
587,
26,
288,
372,
488,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
15496,
314,
2849,
909,
1901,
314,
1067,
1211,
14,
267,
408,
267,
1067,
275,
1052,
267,
340,
291,
14,
785,
26,
288,
1067,
459,
785,
418,
275,
291,
14,
785,
288,
1067,
63,
785,
63,
354,
275,
291,
14,
362,
63,
1100,
63,
785,
63,
354,
8,
277,
14,
785,
9,
288,
340,
1067,
63,
785,
63,
354,
26,
355,
1067,
59,
1100,
63,
785,
63,
354,
61,
275,
291,
14,
785,
267,
1067,
14,
873,
8,
958,
9,
267,
372,
1613,
8,
7200,
1692,
4256,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
1100,
9,
421,
199,
533,
3523,
28539,
8,
7200,
1692,
4256,
12,
10935,
304,
272,
408,
272,
437,
1300,
2455,
367,
20589,
282,
2849,
909,
272,
408,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
785,
275,
291,
14,
362,
63,
785,
342,
267,
1067,
275,
291,
14,
362,
63,
1100,
63,
576,
8,
785,
29,
277,
14,
785,
9,
267,
372,
291,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
421,
199,
533,
13050,
1692,
31036,
4256,
8,
31036,
4256,
304,
272,
1978,
63,
354,
63,
698,
275,
488,
272,
1978,
63,
354,
63,
4511,
275,
2513,
5506,
7,
339,
347,
664,
63,
1160,
63,
1247,
8,
277,
304,
267,
408,
267,
1432,
282,
769,
402,
1978,
1561,
370,
506,
1202,
367,
314,
1056,
14,
10162,
440,
506,
267,
2797,
340,
3795,
63,
475,
63,
1310,
365,
10087,
14,
1803,
314,
2569,
769,
26,
398,
627,
314,
574,
402,
1124,
1160,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sony/nnabla
|
python/test/function/test_top_k_grad.py
|
1
|
2808
|
# Copyright 2018,2019,2020,2021 Sony Corporation.
# Copyright 2021 Sony Group 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.
import pytest
import numpy as np
import nnabla.functions as F
from nbla_test_utils import list_context, function_tester
ctxs = list_context('TopKGrad')
def ref_top_k_grad(k, abs, base_axis, grad):
outer_dim = np.prod(grad.shape[:base_axis], dtype=int)
inner_dim = np.prod(grad.shape[base_axis:], dtype=int)
gg = grad.reshape(outer_dim, inner_dim).copy()
ix = np.argsort(np.abs(gg) if abs else gg)[:, -k:]
dx = np.zeros((outer_dim, inner_dim))
for idx, row in enumerate(ix):
dx[idx, row] = gg[idx, row]
dx = dx.squeeze(axis=0) if base_axis == 0 else dx
return dx.reshape(grad.shape)
def ref_top_k_grad_fw(x, k, abs, base_axis):
return x
def ref_top_k_grad_bw(x, g, k, abs, base_axis, **kw):
return ref_top_k_grad(k, abs, base_axis, g).flatten()
@pytest.mark.parametrize("ctx, fname", ctxs)
@pytest.mark.parametrize("seed", [313])
@pytest.mark.parametrize("abs", [False, True])
@pytest.mark.parametrize("ishape, k, base_axis", [
((4, 5, 6), 1, 0), ((4, 5, 6), 1, 1), ((4, 5, 6), 1, 2), ((4, 5, 6), 1, -2),
((4, 5, 6), 5, 0), ((4, 5, 6), 5, 1), ((4, 5, 6), 5, 2), ((4, 5, 6), 5, -1),
((1, 1000), 10, 1), ((1, 100000), 1024, 1), ((
1, 100000), 1025, 1), ((1, 100000), 1025, -2)
])
def test_forward_backward(seed, ishape, k, abs, base_axis, ctx, fname):
rng = np.random.RandomState(seed)
inputs = [rng.randn(*ishape).astype(np.float32)]
if fname.endswith('Cuda'):
# TopKGradCuda backward use unstable sort, so the result will change each run.
disable_clear_no_need_grad_test = True
else:
disable_clear_no_need_grad_test = False
function_tester(rng, F.top_k_grad, ref_top_k_grad_fw, inputs, ctx=ctx,
func_name=fname, ref_grad=ref_top_k_grad_bw,
func_args=[k, abs, base_axis],
disable_half_test=k > 10,
disable_clear_no_need_grad_test=disable_clear_no_need_grad_test)
# Note: FP16 has too many duplicate value for larger K to get the
# same sort order as FP32 and this makes the function tester fail
# when comparing FP16 to FP32 results of gradient computation.
|
apache-2.0
|
[
3,
1898,
14894,
12,
14982,
12,
13934,
12,
22150,
428,
5220,
11098,
14,
199,
3,
1898,
499,
15385,
428,
5220,
5611,
11098,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
4613,
199,
646,
2680,
465,
980,
199,
646,
11542,
371,
416,
14,
5777,
465,
481,
199,
504,
8526,
416,
63,
396,
63,
1208,
492,
769,
63,
1100,
12,
805,
63,
8234,
199,
199,
3799,
83,
275,
769,
63,
1100,
360,
6105,
43,
14812,
358,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
8,
75,
12,
2853,
12,
1300,
63,
3127,
12,
7659,
304,
272,
6890,
63,
3572,
275,
980,
14,
8788,
8,
6017,
14,
1392,
1491,
1095,
63,
3127,
467,
2152,
29,
442,
9,
272,
6506,
63,
3572,
275,
980,
14,
8788,
8,
6017,
14,
1392,
59,
1095,
63,
3127,
8429,
2152,
29,
442,
9,
272,
486,
71,
275,
7659,
14,
5217,
8,
7837,
63,
3572,
12,
6506,
63,
3572,
680,
1574,
342,
272,
20593,
275,
980,
14,
20188,
8,
1590,
14,
2101,
8,
2721,
9,
340,
2853,
587,
486,
71,
24517,
446,
75,
2938,
272,
11868,
275,
980,
14,
4250,
1332,
7837,
63,
3572,
12,
6506,
63,
3572,
430,
272,
367,
4280,
12,
1962,
315,
3874,
8,
1148,
304,
267,
11868,
59,
2996,
12,
1962,
61,
275,
486,
71,
59,
2996,
12,
1962,
61,
272,
11868,
275,
11868,
14,
16597,
8,
3127,
29,
16,
9,
340,
1300,
63,
3127,
508,
378,
587,
11868,
272,
372,
11868,
14,
5217,
8,
6017,
14,
1392,
9,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
63,
8835,
8,
88,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
304,
272,
372,
671,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
63,
12415,
8,
88,
12,
486,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
12,
1011,
829,
304,
272,
372,
2984,
63,
2119,
63,
75,
63,
6017,
8,
75,
12,
2853,
12,
1300,
63,
3127,
12,
486,
680,
8487,
342,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
3799,
12,
6748,
401,
4027,
83,
9,
199,
32,
4462,
14,
1657,
14,
10396,
480,
5176,
401,
359,
19455,
566,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2101,
401,
359,
797,
12,
715,
566,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2453,
924,
12,
1022,
12,
1300,
63,
3127,
401,
359,
272,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
378,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
413,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
499,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
446,
18,
395,
272,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
378,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
413,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
499,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
446,
17,
395,
272,
3666,
17,
12,
5198,
395,
1616,
12,
413,
395,
3666,
17,
12,
25761,
395,
6619,
12,
413,
395,
3666,
267,
413,
12,
25761,
395,
1616,
821,
12,
413,
395,
3666,
17,
12,
25761,
395,
1616,
821,
12,
446,
18,
9,
199,
566,
199,
318,
511,
63,
6688,
63,
15457,
8,
5176,
12,
365,
15221,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
12,
4027,
12,
6748,
304,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
5176,
9,
272,
4153,
275,
359,
12686,
14,
10843,
2031,
2453,
924,
680,
6041,
8,
1590,
14,
1609,
708,
1874,
272,
340,
6748,
14,
4130,
360,
35,
6727,
735,
267,
327,
14132,
43,
14812,
35,
6727,
13388,
675,
625,
11989,
4069,
12,
880,
314,
754,
911,
1570,
1924,
1255,
14,
267,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
275,
715,
272,
587,
26,
267,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
275,
756,
272,
805,
63,
8234,
8,
12686,
12,
481,
14,
2119,
63,
75,
63,
6017,
12,
2984,
63,
2119,
63,
75,
63,
6017,
63,
8835,
12,
4153,
12,
4027,
29,
3799,
12,
490,
2562,
63,
354,
29,
5252,
12,
2984,
63,
6017,
29,
1121,
63,
2119,
63,
75,
63,
6017,
63,
12415,
12,
490,
2562,
63,
589,
1524,
75,
12,
2853,
12,
1300,
63,
3127,
467,
490,
3507,
63,
10220,
63,
396,
29,
75,
690,
1616,
12,
490,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
29,
5993,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
9,
339,
327,
3390,
26,
481,
48,
975,
965,
4634,
5002,
9250,
574,
367,
12142,
1804,
370,
664,
314,
272,
327,
2011,
4069,
1865,
465,
481,
48,
708,
436,
642,
7704,
314,
805,
17570,
2449,
272,
327,
1380,
20234,
481,
48,
975,
370,
481,
48,
708,
2058,
402,
6709,
14009,
14,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
14894,
12,
14982,
12,
13934,
12,
22150,
428,
5220,
11098,
14,
199,
3,
1898,
499,
15385,
428,
5220,
5611,
11098,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
4613,
199,
646,
2680,
465,
980,
199,
646,
11542,
371,
416,
14,
5777,
465,
481,
199,
504,
8526,
416,
63,
396,
63,
1208,
492,
769,
63,
1100,
12,
805,
63,
8234,
199,
199,
3799,
83,
275,
769,
63,
1100,
360,
6105,
43,
14812,
358,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
8,
75,
12,
2853,
12,
1300,
63,
3127,
12,
7659,
304,
272,
6890,
63,
3572,
275,
980,
14,
8788,
8,
6017,
14,
1392,
1491,
1095,
63,
3127,
467,
2152,
29,
442,
9,
272,
6506,
63,
3572,
275,
980,
14,
8788,
8,
6017,
14,
1392,
59,
1095,
63,
3127,
8429,
2152,
29,
442,
9,
272,
486,
71,
275,
7659,
14,
5217,
8,
7837,
63,
3572,
12,
6506,
63,
3572,
680,
1574,
342,
272,
20593,
275,
980,
14,
20188,
8,
1590,
14,
2101,
8,
2721,
9,
340,
2853,
587,
486,
71,
24517,
446,
75,
2938,
272,
11868,
275,
980,
14,
4250,
1332,
7837,
63,
3572,
12,
6506,
63,
3572,
430,
272,
367,
4280,
12,
1962,
315,
3874,
8,
1148,
304,
267,
11868,
59,
2996,
12,
1962,
61,
275,
486,
71,
59,
2996,
12,
1962,
61,
272,
11868,
275,
11868,
14,
16597,
8,
3127,
29,
16,
9,
340,
1300,
63,
3127,
508,
378,
587,
11868,
272,
372,
11868,
14,
5217,
8,
6017,
14,
1392,
9,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
63,
8835,
8,
88,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
304,
272,
372,
671,
421,
199,
318,
2984,
63,
2119,
63,
75,
63,
6017,
63,
12415,
8,
88,
12,
486,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
12,
1011,
829,
304,
272,
372,
2984,
63,
2119,
63,
75,
63,
6017,
8,
75,
12,
2853,
12,
1300,
63,
3127,
12,
486,
680,
8487,
342,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
3799,
12,
6748,
401,
4027,
83,
9,
199,
32,
4462,
14,
1657,
14,
10396,
480,
5176,
401,
359,
19455,
566,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2101,
401,
359,
797,
12,
715,
566,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2453,
924,
12,
1022,
12,
1300,
63,
3127,
401,
359,
272,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
378,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
413,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
499,
395,
3666,
20,
12,
959,
12,
1227,
395,
413,
12,
446,
18,
395,
272,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
378,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
413,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
499,
395,
3666,
20,
12,
959,
12,
1227,
395,
959,
12,
446,
17,
395,
272,
3666,
17,
12,
5198,
395,
1616,
12,
413,
395,
3666,
17,
12,
25761,
395,
6619,
12,
413,
395,
3666,
267,
413,
12,
25761,
395,
1616,
821,
12,
413,
395,
3666,
17,
12,
25761,
395,
1616,
821,
12,
446,
18,
9,
199,
566,
199,
318,
511,
63,
6688,
63,
15457,
8,
5176,
12,
365,
15221,
12,
1022,
12,
2853,
12,
1300,
63,
3127,
12,
4027,
12,
6748,
304,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
5176,
9,
272,
4153,
275,
359,
12686,
14,
10843,
2031,
2453,
924,
680,
6041,
8,
1590,
14,
1609,
708,
1874,
272,
340,
6748,
14,
4130,
360,
35,
6727,
735,
267,
327,
14132,
43,
14812,
35,
6727,
13388,
675,
625,
11989,
4069,
12,
880,
314,
754,
911,
1570,
1924,
1255,
14,
267,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
275,
715,
272,
587,
26,
267,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
275,
756,
272,
805,
63,
8234,
8,
12686,
12,
481,
14,
2119,
63,
75,
63,
6017,
12,
2984,
63,
2119,
63,
75,
63,
6017,
63,
8835,
12,
4153,
12,
4027,
29,
3799,
12,
490,
2562,
63,
354,
29,
5252,
12,
2984,
63,
6017,
29,
1121,
63,
2119,
63,
75,
63,
6017,
63,
12415,
12,
490,
2562,
63,
589,
1524,
75,
12,
2853,
12,
1300,
63,
3127,
467,
490,
3507,
63,
10220,
63,
396,
29,
75,
690,
1616,
12,
490,
3507,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
29,
5993,
63,
3584,
63,
889,
63,
9321,
63,
6017,
63,
396,
9,
339,
327,
3390,
26,
481,
48,
975,
965,
4634,
5002,
9250,
574,
367,
12142,
1804,
370,
664,
314,
272,
327,
2011,
4069,
1865,
465,
481,
48,
708,
436,
642,
7704,
314,
805,
17570,
2449,
272,
327,
1380,
20234,
481,
48,
975,
370,
481,
48,
708,
2058,
402,
6709,
14009,
14,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
freakboy3742/django
|
django/template/base.py
|
2
|
39107
|
"""
This is the Django template system.
How it works:
The Lexer.tokenize() method converts a template string (i.e., a string
containing markup with custom template tags) to tokens, which can be either
plain text (TokenType.TEXT), variables (TokenType.VAR), or block statements
(TokenType.BLOCK).
The Parser() class takes a list of tokens in its constructor, and its parse()
method returns a compiled template -- which is, under the hood, a list of
Node objects.
Each Node is responsible for creating some sort of output -- e.g. simple text
(TextNode), variable values in a given context (VariableNode), results of basic
logic (IfNode), results of looping (ForNode), or anything else. The core Node
types are TextNode, VariableNode, IfNode and ForNode, but plugin modules can
define their own custom node types.
Each Node has a render() method, which takes a Context and returns a string of
the rendered node. For example, the render() method of a Variable Node returns
the variable's value as a string. The render() method of a ForNode returns the
rendered output of whatever was inside the loop, recursively.
The Template class is a convenient wrapper that takes care of template
compilation and rendering.
Usage:
The only thing you should ever use directly in this file is the Template class.
Create a compiled template object with a template_string, then call render()
with a context. In the compilation stage, the TemplateSyntaxError exception
will be raised if the template doesn't have proper syntax.
Sample code:
>>> from django import template
>>> s = '<html>{% if test %}<h1>{{ varvalue }}</h1>{% endif %}</html>'
>>> t = template.Template(s)
(t is now a compiled template, and its render() method can be called multiple
times with multiple contexts)
>>> c = template.Context({'test':True, 'varvalue': 'Hello'})
>>> t.render(c)
'<html><h1>Hello</h1></html>'
>>> c = template.Context({'test':False, 'varvalue': 'Hello'})
>>> t.render(c)
'<html></html>'
"""
import inspect
import logging
import re
from enum import Enum
from django.template.context import BaseContext
from django.utils.formats import localize
from django.utils.html import conditional_escape, escape
from django.utils.regex_helper import _lazy_re_compile
from django.utils.safestring import SafeData, SafeString, mark_safe
from django.utils.text import (
get_text_list, smart_split, unescape_string_literal,
)
from django.utils.timezone import template_localtime
from django.utils.translation import gettext_lazy, pgettext_lazy
from .exceptions import TemplateSyntaxError
# template syntax constants
FILTER_SEPARATOR = '|'
FILTER_ARGUMENT_SEPARATOR = ':'
VARIABLE_ATTRIBUTE_SEPARATOR = '.'
BLOCK_TAG_START = '{%'
BLOCK_TAG_END = '%}'
VARIABLE_TAG_START = '{{'
VARIABLE_TAG_END = '}}'
COMMENT_TAG_START = '{#'
COMMENT_TAG_END = '#}'
TRANSLATOR_COMMENT_MARK = 'Translators'
SINGLE_BRACE_START = '{'
SINGLE_BRACE_END = '}'
# what to report as the origin for templates that come from non-loader sources
# (e.g. strings)
UNKNOWN_SOURCE = '<unknown source>'
# match a variable or block tag and capture the entire tag, including start/end
# delimiters
tag_re = (_lazy_re_compile('(%s.*?%s|%s.*?%s|%s.*?%s)' %
(re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END),
re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END),
re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END))))
logger = logging.getLogger('django.template')
class TokenType(Enum):
TEXT = 0
VAR = 1
BLOCK = 2
COMMENT = 3
class VariableDoesNotExist(Exception):
def __init__(self, msg, params=()):
self.msg = msg
self.params = params
def __str__(self):
return self.msg % self.params
class Origin:
def __init__(self, name, template_name=None, loader=None):
self.name = name
self.template_name = template_name
self.loader = loader
def __str__(self):
return self.name
def __repr__(self):
return '<%s name=%r>' % (self.__class__.__qualname__, self.name)
def __eq__(self, other):
return (
isinstance(other, Origin) and
self.name == other.name and
self.loader == other.loader
)
@property
def loader_name(self):
if self.loader:
return '%s.%s' % (
self.loader.__module__, self.loader.__class__.__name__,
)
class Template:
def __init__(self, template_string, origin=None, name=None, engine=None):
# If Template is instantiated directly rather than from an Engine and
# exactly one Django template engine is configured, use that engine.
# This is required to preserve backwards-compatibility for direct use
# e.g. Template('...').render(Context({...}))
if engine is None:
from .engine import Engine
engine = Engine.get_default()
if origin is None:
origin = Origin(UNKNOWN_SOURCE)
self.name = name
self.origin = origin
self.engine = engine
self.source = str(template_string) # May be lazy.
self.nodelist = self.compile_nodelist()
def __iter__(self):
for node in self.nodelist:
yield from node
def __repr__(self):
return '<%s template_string="%s...">' % (
self.__class__.__qualname__,
self.source[:20].replace('\n', ''),
)
def _render(self, context):
return self.nodelist.render(context)
def render(self, context):
"Display stage -- can be called many times"
with context.render_context.push_state(self):
if context.template is None:
with context.bind_template(self):
context.template_name = self.name
return self._render(context)
else:
return self._render(context)
def compile_nodelist(self):
"""
Parse and compile the template source into a nodelist. If debug
is True and an exception occurs during parsing, the exception is
annotated with contextual line information where it occurred in the
template source.
"""
if self.engine.debug:
lexer = DebugLexer(self.source)
else:
lexer = Lexer(self.source)
tokens = lexer.tokenize()
parser = Parser(
tokens, self.engine.template_libraries, self.engine.template_builtins,
self.origin,
)
try:
return parser.parse()
except Exception as e:
if self.engine.debug:
e.template_debug = self.get_exception_info(e, e.token)
raise
def get_exception_info(self, exception, token):
"""
Return a dictionary containing contextual line information of where
the exception occurred in the template. The following information is
provided:
message
The message of the exception raised.
source_lines
The lines before, after, and including the line the exception
occurred on.
line
The line number the exception occurred on.
before, during, after
The line the exception occurred on split into three parts:
1. The content before the token that raised the error.
2. The token that raised the error.
3. The content after the token that raised the error.
total
The number of lines in source_lines.
top
The line number where source_lines starts.
bottom
The line number where source_lines ends.
start
The start position of the token in the template source.
end
The end position of the token in the template source.
"""
start, end = token.position
context_lines = 10
line = 0
upto = 0
source_lines = []
before = during = after = ""
for num, next in enumerate(linebreak_iter(self.source)):
if start >= upto and end <= next:
line = num
before = escape(self.source[upto:start])
during = escape(self.source[start:end])
after = escape(self.source[end:next])
source_lines.append((num, escape(self.source[upto:next])))
upto = next
total = len(source_lines)
top = max(1, line - context_lines)
bottom = min(total, line + 1 + context_lines)
# In some rare cases exc_value.args can be empty or an invalid
# string.
try:
message = str(exception.args[0])
except (IndexError, UnicodeDecodeError):
message = '(Could not get exception message)'
return {
'message': message,
'source_lines': source_lines[top:bottom],
'before': before,
'during': during,
'after': after,
'top': top,
'bottom': bottom,
'total': total,
'line': line,
'name': self.origin.name,
'start': start,
'end': end,
}
def linebreak_iter(template_source):
yield 0
p = template_source.find('\n')
while p >= 0:
yield p + 1
p = template_source.find('\n', p + 1)
yield len(template_source) + 1
class Token:
def __init__(self, token_type, contents, position=None, lineno=None):
"""
A token representing a string from the template.
token_type
A TokenType, either .TEXT, .VAR, .BLOCK, or .COMMENT.
contents
The token source string.
position
An optional tuple containing the start and end index of the token
in the template source. This is used for traceback information
when debug is on.
lineno
The line number the token appears on in the template source.
This is used for traceback information and gettext files.
"""
self.token_type, self.contents = token_type, contents
self.lineno = lineno
self.position = position
def __repr__(self):
token_name = self.token_type.name.capitalize()
return ('<%s token: "%s...">' %
(token_name, self.contents[:20].replace('\n', '')))
def split_contents(self):
split = []
bits = smart_split(self.contents)
for bit in bits:
# Handle translation-marked template pieces
if bit.startswith(('_("', "_('")):
sentinel = bit[2] + ')'
trans_bit = [bit]
while not bit.endswith(sentinel):
bit = next(bits)
trans_bit.append(bit)
bit = ' '.join(trans_bit)
split.append(bit)
return split
class Lexer:
def __init__(self, template_string):
self.template_string = template_string
self.verbatim = False
def __repr__(self):
return '<%s template_string="%s...", verbatim=%s>' % (
self.__class__.__qualname__,
self.template_string[:20].replace('\n', ''),
self.verbatim,
)
def tokenize(self):
"""
Return a list of tokens from a given template_string.
"""
in_tag = False
lineno = 1
result = []
for bit in tag_re.split(self.template_string):
if bit:
result.append(self.create_token(bit, None, lineno, in_tag))
in_tag = not in_tag
lineno += bit.count('\n')
return result
def create_token(self, token_string, position, lineno, in_tag):
"""
Convert the given token string into a new Token object and return it.
If in_tag is True, we are processing something that matched a tag,
otherwise it should be treated as a literal string.
"""
if in_tag and token_string.startswith(BLOCK_TAG_START):
# The [2:-2] ranges below strip off *_TAG_START and *_TAG_END.
# We could do len(BLOCK_TAG_START) to be more "correct", but we've
# hard-coded the 2s here for performance. And it's not like
# the TAG_START values are going to change anytime, anyway.
block_content = token_string[2:-2].strip()
if self.verbatim and block_content == self.verbatim:
self.verbatim = False
if in_tag and not self.verbatim:
if token_string.startswith(VARIABLE_TAG_START):
return Token(TokenType.VAR, token_string[2:-2].strip(), position, lineno)
elif token_string.startswith(BLOCK_TAG_START):
if block_content[:9] in ('verbatim', 'verbatim '):
self.verbatim = 'end%s' % block_content
return Token(TokenType.BLOCK, block_content, position, lineno)
elif token_string.startswith(COMMENT_TAG_START):
content = ''
if token_string.find(TRANSLATOR_COMMENT_MARK):
content = token_string[2:-2].strip()
return Token(TokenType.COMMENT, content, position, lineno)
else:
return Token(TokenType.TEXT, token_string, position, lineno)
class DebugLexer(Lexer):
def tokenize(self):
"""
Split a template string into tokens and annotates each token with its
start and end position in the source. This is slower than the default
lexer so only use it when debug is True.
"""
lineno = 1
result = []
upto = 0
for match in tag_re.finditer(self.template_string):
start, end = match.span()
if start > upto:
token_string = self.template_string[upto:start]
result.append(self.create_token(token_string, (upto, start), lineno, in_tag=False))
lineno += token_string.count('\n')
token_string = self.template_string[start:end]
result.append(self.create_token(token_string, (start, end), lineno, in_tag=True))
lineno += token_string.count('\n')
upto = end
last_bit = self.template_string[upto:]
if last_bit:
result.append(self.create_token(last_bit, (upto, upto + len(last_bit)), lineno, in_tag=False))
return result
class Parser:
def __init__(self, tokens, libraries=None, builtins=None, origin=None):
# Reverse the tokens so delete_first_token(), prepend_token(), and
# next_token() can operate at the end of the list in constant time.
self.tokens = list(reversed(tokens))
self.tags = {}
self.filters = {}
self.command_stack = []
if libraries is None:
libraries = {}
if builtins is None:
builtins = []
self.libraries = libraries
for builtin in builtins:
self.add_library(builtin)
self.origin = origin
def __repr__(self):
return '<%s tokens=%r>' % (self.__class__.__qualname__, self.tokens)
def parse(self, parse_until=None):
"""
Iterate through the parser tokens and compiles each one into a node.
If parse_until is provided, parsing will stop once one of the
specified tokens has been reached. This is formatted as a list of
tokens, e.g. ['elif', 'else', 'endif']. If no matching token is
reached, raise an exception with the unclosed block tag details.
"""
if parse_until is None:
parse_until = []
nodelist = NodeList()
while self.tokens:
token = self.next_token()
# Use the raw values here for TokenType.* for a tiny performance boost.
if token.token_type.value == 0: # TokenType.TEXT
self.extend_nodelist(nodelist, TextNode(token.contents), token)
elif token.token_type.value == 1: # TokenType.VAR
if not token.contents:
raise self.error(token, 'Empty variable tag on line %d' % token.lineno)
try:
filter_expression = self.compile_filter(token.contents)
except TemplateSyntaxError as e:
raise self.error(token, e)
var_node = VariableNode(filter_expression)
self.extend_nodelist(nodelist, var_node, token)
elif token.token_type.value == 2: # TokenType.BLOCK
try:
command = token.contents.split()[0]
except IndexError:
raise self.error(token, 'Empty block tag on line %d' % token.lineno)
if command in parse_until:
# A matching token has been reached. Return control to
# the caller. Put the token back on the token list so the
# caller knows where it terminated.
self.prepend_token(token)
return nodelist
# Add the token to the command stack. This is used for error
# messages if further parsing fails due to an unclosed block
# tag.
self.command_stack.append((command, token))
# Get the tag callback function from the ones registered with
# the parser.
try:
compile_func = self.tags[command]
except KeyError:
self.invalid_block_tag(token, command, parse_until)
# Compile the callback into a node object and add it to
# the node list.
try:
compiled_result = compile_func(self, token)
except Exception as e:
raise self.error(token, e)
self.extend_nodelist(nodelist, compiled_result, token)
# Compile success. Remove the token from the command stack.
self.command_stack.pop()
if parse_until:
self.unclosed_block_tag(parse_until)
return nodelist
def skip_past(self, endtag):
while self.tokens:
token = self.next_token()
if token.token_type == TokenType.BLOCK and token.contents == endtag:
return
self.unclosed_block_tag([endtag])
def extend_nodelist(self, nodelist, node, token):
# Check that non-text nodes don't appear before an extends tag.
if node.must_be_first and nodelist.contains_nontext:
raise self.error(
token, '%r must be the first tag in the template.' % node,
)
if isinstance(nodelist, NodeList) and not isinstance(node, TextNode):
nodelist.contains_nontext = True
# Set origin and token here since we can't modify the node __init__()
# method.
node.token = token
node.origin = self.origin
nodelist.append(node)
def error(self, token, e):
"""
Return an exception annotated with the originating token. Since the
parser can be called recursively, check if a token is already set. This
ensures the innermost token is highlighted if an exception occurs,
e.g. a compile error within the body of an if statement.
"""
if not isinstance(e, Exception):
e = TemplateSyntaxError(e)
if not hasattr(e, 'token'):
e.token = token
return e
def invalid_block_tag(self, token, command, parse_until=None):
if parse_until:
raise self.error(
token,
"Invalid block tag on line %d: '%s', expected %s. Did you "
"forget to register or load this tag?" % (
token.lineno,
command,
get_text_list(["'%s'" % p for p in parse_until], 'or'),
),
)
raise self.error(
token,
"Invalid block tag on line %d: '%s'. Did you forget to register "
"or load this tag?" % (token.lineno, command)
)
def unclosed_block_tag(self, parse_until):
command, token = self.command_stack.pop()
msg = "Unclosed tag on line %d: '%s'. Looking for one of: %s." % (
token.lineno,
command,
', '.join(parse_until),
)
raise self.error(token, msg)
def next_token(self):
return self.tokens.pop()
def prepend_token(self, token):
self.tokens.append(token)
def delete_first_token(self):
del self.tokens[-1]
def add_library(self, lib):
self.tags.update(lib.tags)
self.filters.update(lib.filters)
def compile_filter(self, token):
"""
Convenient wrapper for FilterExpression
"""
return FilterExpression(token, self)
def find_filter(self, filter_name):
if filter_name in self.filters:
return self.filters[filter_name]
else:
raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name)
# This only matches constant *strings* (things in quotes or marked for
# translation). Numbers are treated as variables for implementation reasons
# (so that they retain their type when passed to filters).
constant_string = r"""
(?:%(i18n_open)s%(strdq)s%(i18n_close)s|
%(i18n_open)s%(strsq)s%(i18n_close)s|
%(strdq)s|
%(strsq)s)
""" % {
'strdq': r'"[^"\\]*(?:\\.[^"\\]*)*"', # double-quoted string
'strsq': r"'[^'\\]*(?:\\.[^'\\]*)*'", # single-quoted string
'i18n_open': re.escape("_("),
'i18n_close': re.escape(")"),
}
constant_string = constant_string.replace("\n", "")
filter_raw_string = r"""
^(?P<constant>%(constant)s)|
^(?P<var>[%(var_chars)s]+|%(num)s)|
(?:\s*%(filter_sep)s\s*
(?P<filter_name>\w+)
(?:%(arg_sep)s
(?:
(?P<constant_arg>%(constant)s)|
(?P<var_arg>[%(var_chars)s]+|%(num)s)
)
)?
)""" % {
'constant': constant_string,
'num': r'[-+\.]?\d[\d\.e]*',
'var_chars': r'\w\.',
'filter_sep': re.escape(FILTER_SEPARATOR),
'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR),
}
filter_re = _lazy_re_compile(filter_raw_string, re.VERBOSE)
class FilterExpression:
"""
Parse a variable token and its optional filters (all as a single string),
and return a list of tuples of the filter name and arguments.
Sample::
>>> token = 'variable|default:"Default value"|date:"Y-m-d"'
>>> p = Parser('')
>>> fe = FilterExpression(token, p)
>>> len(fe.filters)
2
>>> fe.var
<Variable: 'variable'>
"""
def __init__(self, token, parser):
self.token = token
matches = filter_re.finditer(token)
var_obj = None
filters = []
upto = 0
for match in matches:
start = match.start()
if upto != start:
raise TemplateSyntaxError("Could not parse some characters: "
"%s|%s|%s" %
(token[:upto], token[upto:start],
token[start:]))
if var_obj is None:
var, constant = match['var'], match['constant']
if constant:
try:
var_obj = Variable(constant).resolve({})
except VariableDoesNotExist:
var_obj = None
elif var is None:
raise TemplateSyntaxError("Could not find variable at "
"start of %s." % token)
else:
var_obj = Variable(var)
else:
filter_name = match['filter_name']
args = []
constant_arg, var_arg = match['constant_arg'], match['var_arg']
if constant_arg:
args.append((False, Variable(constant_arg).resolve({})))
elif var_arg:
args.append((True, Variable(var_arg)))
filter_func = parser.find_filter(filter_name)
self.args_check(filter_name, filter_func, args)
filters.append((filter_func, args))
upto = match.end()
if upto != len(token):
raise TemplateSyntaxError("Could not parse the remainder: '%s' "
"from '%s'" % (token[upto:], token))
self.filters = filters
self.var = var_obj
def resolve(self, context, ignore_failures=False):
if isinstance(self.var, Variable):
try:
obj = self.var.resolve(context)
except VariableDoesNotExist:
if ignore_failures:
obj = None
else:
string_if_invalid = context.template.engine.string_if_invalid
if string_if_invalid:
if '%s' in string_if_invalid:
return string_if_invalid % self.var
else:
return string_if_invalid
else:
obj = string_if_invalid
else:
obj = self.var
for func, args in self.filters:
arg_vals = []
for lookup, arg in args:
if not lookup:
arg_vals.append(mark_safe(arg))
else:
arg_vals.append(arg.resolve(context))
if getattr(func, 'expects_localtime', False):
obj = template_localtime(obj, context.use_tz)
if getattr(func, 'needs_autoescape', False):
new_obj = func(obj, autoescape=context.autoescape, *arg_vals)
else:
new_obj = func(obj, *arg_vals)
if getattr(func, 'is_safe', False) and isinstance(obj, SafeData):
obj = mark_safe(new_obj)
else:
obj = new_obj
return obj
def args_check(name, func, provided):
provided = list(provided)
# First argument, filter input, is implied.
plen = len(provided) + 1
# Check to see if a decorator is providing the real function.
func = inspect.unwrap(func)
args, _, _, defaults, _, _, _ = inspect.getfullargspec(func)
alen = len(args)
dlen = len(defaults or [])
# Not enough OR Too many
if plen < (alen - dlen) or plen > alen:
raise TemplateSyntaxError("%s requires %d arguments, %d provided" %
(name, alen - dlen, plen))
return True
args_check = staticmethod(args_check)
def __str__(self):
return self.token
def __repr__(self):
return "<%s %r>" % (self.__class__.__qualname__, self.token)
class Variable:
"""
A template variable, resolvable against a given context. The variable may
be a hard-coded string (if it begins and ends with single or double quote
marks)::
>>> c = {'article': {'section':'News'}}
>>> Variable('article.section').resolve(c)
'News'
>>> Variable('article').resolve(c)
{'section': 'News'}
>>> class AClass: pass
>>> c = AClass()
>>> c.article = AClass()
>>> c.article.section = 'News'
(The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
"""
def __init__(self, var):
self.var = var
self.literal = None
self.lookups = None
self.translate = False
self.message_context = None
if not isinstance(var, str):
raise TypeError(
"Variable must be a string or number, got %s" % type(var))
try:
# First try to treat this variable as a number.
#
# Note that this could cause an OverflowError here that we're not
# catching. Since this should only happen at compile time, that's
# probably OK.
# Try to interpret values containing a period or an 'e'/'E'
# (possibly scientific notation) as a float; otherwise, try int.
if '.' in var or 'e' in var.lower():
self.literal = float(var)
# "2." is invalid
if var.endswith('.'):
raise ValueError
else:
self.literal = int(var)
except ValueError:
# A ValueError means that the variable isn't a number.
if var.startswith('_(') and var.endswith(')'):
# The result of the lookup should be translated at rendering
# time.
self.translate = True
var = var[2:-1]
# If it's wrapped with quotes (single or double), then
# we're also dealing with a literal.
try:
self.literal = mark_safe(unescape_string_literal(var))
except ValueError:
# Otherwise we'll set self.lookups so that resolve() knows we're
# dealing with a bonafide variable
if var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_':
raise TemplateSyntaxError("Variables and attributes may "
"not begin with underscores: '%s'" %
var)
self.lookups = tuple(var.split(VARIABLE_ATTRIBUTE_SEPARATOR))
def resolve(self, context):
"""Resolve this variable against a given context."""
if self.lookups is not None:
# We're dealing with a variable that needs to be resolved
value = self._resolve_lookup(context)
else:
# We're dealing with a literal, so it's already been "resolved"
value = self.literal
if self.translate:
is_safe = isinstance(value, SafeData)
msgid = value.replace('%', '%%')
msgid = mark_safe(msgid) if is_safe else msgid
if self.message_context:
return pgettext_lazy(self.message_context, msgid)
else:
return gettext_lazy(msgid)
return value
def __repr__(self):
return "<%s: %r>" % (self.__class__.__name__, self.var)
def __str__(self):
return self.var
def _resolve_lookup(self, context):
"""
Perform resolution of a real variable (i.e. not a literal) against the
given context.
As indicated by the method's name, this method is an implementation
detail and shouldn't be called by external code. Use Variable.resolve()
instead.
"""
current = context
try: # catch-all for silent variable failures
for bit in self.lookups:
try: # dictionary lookup
current = current[bit]
# ValueError/IndexError are for numpy.array lookup on
# numpy < 1.9 and 1.9+ respectively
except (TypeError, AttributeError, KeyError, ValueError, IndexError):
try: # attribute lookup
# Don't return class attributes if the class is the context:
if isinstance(current, BaseContext) and getattr(type(current), bit):
raise AttributeError
current = getattr(current, bit)
except (TypeError, AttributeError):
# Reraise if the exception was raised by a @property
if not isinstance(current, BaseContext) and bit in dir(current):
raise
try: # list-index lookup
current = current[int(bit)]
except (IndexError, # list index out of range
ValueError, # invalid literal for int()
KeyError, # current is a dict without `int(bit)` key
TypeError): # unsubscriptable object
raise VariableDoesNotExist("Failed lookup for key "
"[%s] in %r",
(bit, current)) # missing attribute
if callable(current):
if getattr(current, 'do_not_call_in_templates', False):
pass
elif getattr(current, 'alters_data', False):
current = context.template.engine.string_if_invalid
else:
try: # method call (assuming no args required)
current = current()
except TypeError:
signature = inspect.signature(current)
try:
signature.bind()
except TypeError: # arguments *were* required
current = context.template.engine.string_if_invalid # invalid method call
else:
raise
except Exception as e:
template_name = getattr(context, 'template_name', None) or 'unknown'
logger.debug(
"Exception while resolving variable '%s' in template '%s'.",
bit,
template_name,
exc_info=True,
)
if getattr(e, 'silent_variable_failure', False):
current = context.template.engine.string_if_invalid
else:
raise
return current
class Node:
# Set this to True for nodes that must be first in the template (although
# they can be preceded by text nodes.
must_be_first = False
child_nodelists = ('nodelist',)
token = None
def render(self, context):
"""
Return the node rendered as a string.
"""
pass
def render_annotated(self, context):
"""
Render the node. If debug is True and an exception occurs during
rendering, the exception is annotated with contextual line information
where it occurred in the template. For internal usage this method is
preferred over using the render method directly.
"""
try:
return self.render(context)
except Exception as e:
if context.template.engine.debug and not hasattr(e, 'template_debug'):
e.template_debug = context.render_context.template.get_exception_info(e, self.token)
raise
def __iter__(self):
yield self
def get_nodes_by_type(self, nodetype):
"""
Return a list of all nodes (within this node and its nodelist)
of the given type
"""
nodes = []
if isinstance(self, nodetype):
nodes.append(self)
for attr in self.child_nodelists:
nodelist = getattr(self, attr, None)
if nodelist:
nodes.extend(nodelist.get_nodes_by_type(nodetype))
return nodes
class NodeList(list):
# Set to True the first time a non-TextNode is inserted by
# extend_nodelist().
contains_nontext = False
def render(self, context):
return SafeString(''.join([
node.render_annotated(context) for node in self
]))
def get_nodes_by_type(self, nodetype):
"Return a list of all nodes of the given type"
nodes = []
for node in self:
nodes.extend(node.get_nodes_by_type(nodetype))
return nodes
class TextNode(Node):
def __init__(self, s):
self.s = s
def __repr__(self):
return "<%s: %r>" % (self.__class__.__name__, self.s[:25])
def render(self, context):
return self.s
def render_annotated(self, context):
"""
Return the given value.
The default implementation of this method handles exceptions raised
during rendering, which is not necessary for text nodes.
"""
return self.s
def render_value_in_context(value, context):
"""
Convert any value to a string to become part of a rendered template. This
means escaping, if required, and conversion to a string. If value is a
string, it's expected to already be translated.
"""
value = template_localtime(value, use_tz=context.use_tz)
value = localize(value, use_l10n=context.use_l10n)
if context.autoescape:
if not issubclass(type(value), str):
value = str(value)
return conditional_escape(value)
else:
return str(value)
class VariableNode(Node):
def __init__(self, filter_expression):
self.filter_expression = filter_expression
def __repr__(self):
return "<Variable Node: %s>" % self.filter_expression
def render(self, context):
try:
output = self.filter_expression.resolve(context)
except UnicodeDecodeError:
# Unicode conversion can fail sometimes for reasons out of our
# control (e.g. exception rendering). In that case, we fail
# quietly.
return ''
return render_value_in_context(output, context)
# Regex for token keyword arguments
kwarg_re = _lazy_re_compile(r"(?:(\w+)=)?(.+)")
def token_kwargs(bits, parser, support_legacy=False):
"""
Parse token keyword arguments and return a dictionary of the arguments
retrieved from the ``bits`` token list.
`bits` is a list containing the remainder of the token (split by spaces)
that is to be checked for arguments. Valid arguments are removed from this
list.
`support_legacy` - if True, the legacy format ``1 as foo`` is accepted.
Otherwise, only the standard ``foo=1`` format is allowed.
There is no requirement for all remaining token ``bits`` to be keyword
arguments, so return the dictionary as soon as an invalid argument format
is reached.
"""
if not bits:
return {}
match = kwarg_re.match(bits[0])
kwarg_format = match and match[1]
if not kwarg_format:
if not support_legacy:
return {}
if len(bits) < 3 or bits[1] != 'as':
return {}
kwargs = {}
while bits:
if kwarg_format:
match = kwarg_re.match(bits[0])
if not match or not match[1]:
return kwargs
key, value = match.groups()
del bits[:1]
else:
if len(bits) < 3 or bits[1] != 'as':
return kwargs
key, value = bits[2], bits[0]
del bits[:3]
kwargs[key] = parser.compile_filter(value)
if bits and not kwarg_format:
if bits[0] != 'and':
return kwargs
del bits[:1]
return kwargs
|
bsd-3-clause
|
[
624,
199,
2765,
365,
314,
5634,
1978,
2656,
14,
199,
199,
18335,
652,
5419,
26,
199,
199,
1918,
21125,
14,
15246,
342,
1083,
15373,
282,
1978,
1059,
334,
73,
14,
69,
2020,
282,
1059,
199,
16133,
9189,
543,
3537,
1978,
3762,
9,
370,
4645,
12,
1314,
883,
506,
1902,
199,
6104,
1318,
334,
3264,
804,
14,
3876,
395,
2860,
334,
3264,
804,
14,
5568,
395,
503,
1853,
9834,
199,
8,
3264,
804,
14,
8475,
680,
199,
199,
1918,
10191,
342,
1021,
6181,
282,
769,
402,
4645,
315,
2399,
3787,
12,
436,
2399,
2198,
342,
199,
765,
2529,
282,
10311,
1978,
1553,
1314,
365,
12,
1334,
314,
2636,
364,
12,
282,
769,
402,
199,
1716,
2251,
14,
199,
199,
22321,
5013,
365,
17845,
367,
6425,
2005,
4069,
402,
1072,
1553,
325,
14,
71,
14,
3486,
1318,
199,
8,
32540,
395,
1750,
1338,
315,
282,
1627,
1067,
334,
2773,
1716,
395,
2058,
402,
5678,
199,
15370,
334,
3917,
1716,
395,
2058,
402,
4438,
316,
334,
1858,
1716,
395,
503,
7003,
587,
14,
710,
6170,
5013,
199,
1313,
787,
4516,
1716,
12,
4905,
1716,
12,
982,
1716,
436,
2104,
1716,
12,
1325,
3589,
4621,
883,
199,
4640,
3932,
5705,
3537,
1031,
2943,
14,
199,
199,
22321,
5013,
965,
282,
3795,
342,
1083,
12,
1314,
6181,
282,
9470,
436,
2529,
282,
1059,
402,
199,
1589,
8018,
1031,
14,
2104,
2893,
12,
314,
3795,
342,
1083,
402,
282,
4905,
5013,
2529,
199,
1589,
1750,
1159,
574,
465,
282,
1059,
14,
710,
3795,
342,
1083,
402,
282,
2104,
1716,
2529,
314,
199,
16841,
1072,
402,
15685,
1990,
6272,
314,
4438,
12,
15035,
14,
199,
199,
1918,
5458,
1021,
365,
282,
22700,
4975,
626,
6181,
10296,
402,
1978,
199,
863,
13696,
436,
14066,
14,
199,
199,
7692,
26,
199,
199,
1918,
1454,
8377,
1265,
1077,
14433,
675,
5370,
315,
642,
570,
365,
314,
5458,
1021,
14,
199,
2499,
282,
10311,
1978,
909,
543,
282,
1978,
63,
875,
12,
2066,
1240,
3795,
342,
199,
1045,
282,
1067,
14,
1010,
314,
18653,
9546,
12,
314,
17762,
1919,
199,
14117,
506,
4915,
340,
314,
1978,
3181,
1133,
1172,
5576,
6302,
14,
199,
199,
8176,
1233,
26,
199,
199,
6071,
687,
1639,
492,
1978,
199,
6071,
308,
275,
2650,
1360,
30,
3996,
340,
511,
3674,
28,
72,
17,
19386,
2729,
585,
18519,
72,
17,
30,
3996,
14454,
3674,
1108,
1360,
3524,
199,
6071,
307,
275,
1978,
14,
4231,
8,
83,
9,
199,
199,
8,
84,
365,
3063,
282,
10311,
1978,
12,
436,
2399,
3795,
342,
1083,
883,
506,
2797,
3663,
199,
4508,
543,
3663,
18191,
9,
199,
199,
6071,
286,
275,
1978,
14,
2998,
3252,
396,
356,
549,
12,
283,
1391,
585,
356,
283,
6257,
3071,
199,
6071,
307,
14,
3352,
8,
67,
9,
199,
7601,
1360,
2535,
72,
17,
30,
6257,
1108,
72,
17,
2957,
1360,
3524,
199,
6071,
286,
275,
1978,
14,
2998,
3252,
396,
356,
797,
12,
283,
1391,
585,
356,
283,
6257,
3071,
199,
6071,
307,
14,
3352,
8,
67,
9,
199,
7601,
1360,
2957,
1360,
3524,
199,
624,
199,
199,
646,
6485,
199,
646,
2050,
199,
646,
295,
199,
504,
4952,
492,
11305,
199,
199,
504,
1639,
14,
1160,
14,
1100,
492,
3523,
2998,
199,
504,
1639,
14,
1208,
14,
6321,
492,
2257,
794,
199,
504,
1639,
14,
1208,
14,
1360,
492,
12303,
63,
3765,
12,
4772,
199,
504,
1639,
14,
1208,
14,
3821,
63,
3676,
492,
485,
6395,
63,
264,
63,
2014,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
14969,
1558,
12,
2216,
63,
3489,
199,
504,
1639,
14,
1208,
14,
505,
492,
334,
272,
664,
63,
505,
63,
513,
12,
11179,
63,
1294,
12,
22221,
63,
875,
63,
8939,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
7145,
492,
1978,
63,
15198,
199,
504,
1639,
14,
1208,
14,
6893,
492,
9796,
63,
6395,
12,
23815,
63,
6395,
199,
199,
504,
1275,
3924,
492,
17762,
199,
199,
3,
1978,
6302,
5262,
199,
9905,
63,
15828,
275,
24628,
199,
9905,
63,
24165,
63,
15828,
275,
10871,
199,
23129,
63,
17075,
63,
15828,
275,
7815,
199,
8475,
63,
6967,
63,
7363,
275,
12100,
7,
199,
8475,
63,
6967,
63,
3902,
275,
1543,
6834,
199,
23129,
63,
6967,
63,
7363,
275,
5041,
1445,
199,
23129,
63,
6967,
63,
3902,
275,
283,
4863,
7,
199,
10973,
63,
6967,
63,
7363,
275,
5041,
19367,
199,
10973,
63,
6967,
63,
3902,
275,
3943,
6834,
199,
26376,
6467,
63,
10973,
63,
10520,
275,
283,
3188,
20830,
7,
199,
16425,
63,
29246,
63,
7363,
275,
26109,
199,
16425,
63,
29246,
63,
3902,
275,
23618,
199,
199,
3,
4052,
370,
3622,
465,
314,
6330,
367,
7009,
626,
11492,
687,
2222,
13,
3422,
5274,
199,
3,
334,
69,
14,
71,
14,
3326,
9,
199,
11588,
63,
10187,
275,
2650,
5187,
1350,
3524,
199,
199,
3,
1336,
282,
1750,
503,
1853,
1947,
436,
12296,
314,
8039,
1947,
12,
5893,
1343,
15,
500,
199,
3,
26968,
199,
1450,
63,
264,
275,
6110,
6395,
63,
264,
63,
2014,
360,
4042,
83,
6697,
5,
83,
15287,
83,
6697,
5,
83,
15287,
83,
6697,
5,
83,
3171,
450,
881,
334,
264,
14,
3765,
8,
8475,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
8475,
63,
6967,
63,
3902,
395,
1779,
295,
14,
3765,
8,
23129,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
23129,
63,
6967,
63,
3902,
395,
1779,
295,
14,
3765,
8,
10973,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
10973,
63,
6967,
63,
3902,
7845,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1160,
358,
421,
199,
533,
8767,
804,
8,
5081,
304,
272,
11951,
275,
378,
272,
16013,
275,
413,
272,
8068,
275,
499,
272,
25071,
275,
650,
421,
199,
533,
4905,
7400,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1862,
23603,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
1162,
275,
1862,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1328,
450,
291,
14,
1162,
421,
199,
533,
31534,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1978,
63,
354,
29,
403,
12,
5077,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1160
] |
[
199,
2765,
365,
314,
5634,
1978,
2656,
14,
199,
199,
18335,
652,
5419,
26,
199,
199,
1918,
21125,
14,
15246,
342,
1083,
15373,
282,
1978,
1059,
334,
73,
14,
69,
2020,
282,
1059,
199,
16133,
9189,
543,
3537,
1978,
3762,
9,
370,
4645,
12,
1314,
883,
506,
1902,
199,
6104,
1318,
334,
3264,
804,
14,
3876,
395,
2860,
334,
3264,
804,
14,
5568,
395,
503,
1853,
9834,
199,
8,
3264,
804,
14,
8475,
680,
199,
199,
1918,
10191,
342,
1021,
6181,
282,
769,
402,
4645,
315,
2399,
3787,
12,
436,
2399,
2198,
342,
199,
765,
2529,
282,
10311,
1978,
1553,
1314,
365,
12,
1334,
314,
2636,
364,
12,
282,
769,
402,
199,
1716,
2251,
14,
199,
199,
22321,
5013,
365,
17845,
367,
6425,
2005,
4069,
402,
1072,
1553,
325,
14,
71,
14,
3486,
1318,
199,
8,
32540,
395,
1750,
1338,
315,
282,
1627,
1067,
334,
2773,
1716,
395,
2058,
402,
5678,
199,
15370,
334,
3917,
1716,
395,
2058,
402,
4438,
316,
334,
1858,
1716,
395,
503,
7003,
587,
14,
710,
6170,
5013,
199,
1313,
787,
4516,
1716,
12,
4905,
1716,
12,
982,
1716,
436,
2104,
1716,
12,
1325,
3589,
4621,
883,
199,
4640,
3932,
5705,
3537,
1031,
2943,
14,
199,
199,
22321,
5013,
965,
282,
3795,
342,
1083,
12,
1314,
6181,
282,
9470,
436,
2529,
282,
1059,
402,
199,
1589,
8018,
1031,
14,
2104,
2893,
12,
314,
3795,
342,
1083,
402,
282,
4905,
5013,
2529,
199,
1589,
1750,
1159,
574,
465,
282,
1059,
14,
710,
3795,
342,
1083,
402,
282,
2104,
1716,
2529,
314,
199,
16841,
1072,
402,
15685,
1990,
6272,
314,
4438,
12,
15035,
14,
199,
199,
1918,
5458,
1021,
365,
282,
22700,
4975,
626,
6181,
10296,
402,
1978,
199,
863,
13696,
436,
14066,
14,
199,
199,
7692,
26,
199,
199,
1918,
1454,
8377,
1265,
1077,
14433,
675,
5370,
315,
642,
570,
365,
314,
5458,
1021,
14,
199,
2499,
282,
10311,
1978,
909,
543,
282,
1978,
63,
875,
12,
2066,
1240,
3795,
342,
199,
1045,
282,
1067,
14,
1010,
314,
18653,
9546,
12,
314,
17762,
1919,
199,
14117,
506,
4915,
340,
314,
1978,
3181,
1133,
1172,
5576,
6302,
14,
199,
199,
8176,
1233,
26,
199,
199,
6071,
687,
1639,
492,
1978,
199,
6071,
308,
275,
2650,
1360,
30,
3996,
340,
511,
3674,
28,
72,
17,
19386,
2729,
585,
18519,
72,
17,
30,
3996,
14454,
3674,
1108,
1360,
3524,
199,
6071,
307,
275,
1978,
14,
4231,
8,
83,
9,
199,
199,
8,
84,
365,
3063,
282,
10311,
1978,
12,
436,
2399,
3795,
342,
1083,
883,
506,
2797,
3663,
199,
4508,
543,
3663,
18191,
9,
199,
199,
6071,
286,
275,
1978,
14,
2998,
3252,
396,
356,
549,
12,
283,
1391,
585,
356,
283,
6257,
3071,
199,
6071,
307,
14,
3352,
8,
67,
9,
199,
7601,
1360,
2535,
72,
17,
30,
6257,
1108,
72,
17,
2957,
1360,
3524,
199,
6071,
286,
275,
1978,
14,
2998,
3252,
396,
356,
797,
12,
283,
1391,
585,
356,
283,
6257,
3071,
199,
6071,
307,
14,
3352,
8,
67,
9,
199,
7601,
1360,
2957,
1360,
3524,
199,
624,
199,
199,
646,
6485,
199,
646,
2050,
199,
646,
295,
199,
504,
4952,
492,
11305,
199,
199,
504,
1639,
14,
1160,
14,
1100,
492,
3523,
2998,
199,
504,
1639,
14,
1208,
14,
6321,
492,
2257,
794,
199,
504,
1639,
14,
1208,
14,
1360,
492,
12303,
63,
3765,
12,
4772,
199,
504,
1639,
14,
1208,
14,
3821,
63,
3676,
492,
485,
6395,
63,
264,
63,
2014,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
14969,
1558,
12,
2216,
63,
3489,
199,
504,
1639,
14,
1208,
14,
505,
492,
334,
272,
664,
63,
505,
63,
513,
12,
11179,
63,
1294,
12,
22221,
63,
875,
63,
8939,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
7145,
492,
1978,
63,
15198,
199,
504,
1639,
14,
1208,
14,
6893,
492,
9796,
63,
6395,
12,
23815,
63,
6395,
199,
199,
504,
1275,
3924,
492,
17762,
199,
199,
3,
1978,
6302,
5262,
199,
9905,
63,
15828,
275,
24628,
199,
9905,
63,
24165,
63,
15828,
275,
10871,
199,
23129,
63,
17075,
63,
15828,
275,
7815,
199,
8475,
63,
6967,
63,
7363,
275,
12100,
7,
199,
8475,
63,
6967,
63,
3902,
275,
1543,
6834,
199,
23129,
63,
6967,
63,
7363,
275,
5041,
1445,
199,
23129,
63,
6967,
63,
3902,
275,
283,
4863,
7,
199,
10973,
63,
6967,
63,
7363,
275,
5041,
19367,
199,
10973,
63,
6967,
63,
3902,
275,
3943,
6834,
199,
26376,
6467,
63,
10973,
63,
10520,
275,
283,
3188,
20830,
7,
199,
16425,
63,
29246,
63,
7363,
275,
26109,
199,
16425,
63,
29246,
63,
3902,
275,
23618,
199,
199,
3,
4052,
370,
3622,
465,
314,
6330,
367,
7009,
626,
11492,
687,
2222,
13,
3422,
5274,
199,
3,
334,
69,
14,
71,
14,
3326,
9,
199,
11588,
63,
10187,
275,
2650,
5187,
1350,
3524,
199,
199,
3,
1336,
282,
1750,
503,
1853,
1947,
436,
12296,
314,
8039,
1947,
12,
5893,
1343,
15,
500,
199,
3,
26968,
199,
1450,
63,
264,
275,
6110,
6395,
63,
264,
63,
2014,
360,
4042,
83,
6697,
5,
83,
15287,
83,
6697,
5,
83,
15287,
83,
6697,
5,
83,
3171,
450,
881,
334,
264,
14,
3765,
8,
8475,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
8475,
63,
6967,
63,
3902,
395,
1779,
295,
14,
3765,
8,
23129,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
23129,
63,
6967,
63,
3902,
395,
1779,
295,
14,
3765,
8,
10973,
63,
6967,
63,
7363,
395,
295,
14,
3765,
8,
10973,
63,
6967,
63,
3902,
7845,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1160,
358,
421,
199,
533,
8767,
804,
8,
5081,
304,
272,
11951,
275,
378,
272,
16013,
275,
413,
272,
8068,
275,
499,
272,
25071,
275,
650,
421,
199,
533,
4905,
7400,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1862,
23603,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
1162,
275,
1862,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1328,
450,
291,
14,
1162,
421,
199,
533,
31534,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1978,
63,
354,
29,
403,
12,
5077,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1160,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
oleksa-pavlenko/gae-django-project-template
|
django/contrib/gis/geos/libgeos.py
|
90
|
5287
|
"""
This module houses the ctypes initialization procedures, as well
as the notice and error handler function callbacks (get called
when an error occurs in GEOS).
This module also houses GEOS Pointer utilities, including
get_pointer_arr(), and GEOM_PTR.
"""
import logging
import os
import re
from ctypes import c_char_p, Structure, CDLL, CFUNCTYPE, POINTER
from ctypes.util import find_library
from django.contrib.gis.geos.error import GEOSException
from django.core.exceptions import ImproperlyConfigured
logger = logging.getLogger('django.contrib.gis')
# Custom library path set?
try:
from django.conf import settings
lib_path = settings.GEOS_LIBRARY_PATH
except (AttributeError, EnvironmentError,
ImportError, ImproperlyConfigured):
lib_path = None
# Setting the appropriate names for the GEOS-C library.
if lib_path:
lib_names = None
elif os.name == 'nt':
# Windows NT libraries
lib_names = ['geos_c', 'libgeos_c-1']
elif os.name == 'posix':
# *NIX libraries
lib_names = ['geos_c', 'GEOS']
else:
raise ImportError('Unsupported OS "%s"' % os.name)
# Using the ctypes `find_library` utility to find the path to the GEOS
# shared library. This is better than manually specifying each library name
# and extension (e.g., libgeos_c.[so|so.1|dylib].).
if lib_names:
for lib_name in lib_names:
lib_path = find_library(lib_name)
if lib_path is not None:
break
# No GEOS library could be found.
if lib_path is None:
raise ImportError(
'Could not find the GEOS library (tried "%s"). '
'Try setting GEOS_LIBRARY_PATH in your settings.' %
'", "'.join(lib_names)
)
# Getting the GEOS C library. The C interface (CDLL) is used for
# both *NIX and Windows.
# See the GEOS C API source code for more details on the library function calls:
# http://geos.refractions.net/ro/doxygen_docs/html/geos__c_8h-source.html
lgeos = CDLL(lib_path)
# The notice and error handler C function callback definitions.
# Supposed to mimic the GEOS message handler (C below):
# typedef void (*GEOSMessageHandler)(const char *fmt, ...);
NOTICEFUNC = CFUNCTYPE(None, c_char_p, c_char_p)
def notice_h(fmt, lst):
fmt, lst = fmt.decode(), lst.decode()
try:
warn_msg = fmt % lst
except TypeError:
warn_msg = fmt
logger.warning('GEOS_NOTICE: %s\n' % warn_msg)
notice_h = NOTICEFUNC(notice_h)
ERRORFUNC = CFUNCTYPE(None, c_char_p, c_char_p)
def error_h(fmt, lst):
fmt, lst = fmt.decode(), lst.decode()
try:
err_msg = fmt % lst
except TypeError:
err_msg = fmt
logger.error('GEOS_ERROR: %s\n' % err_msg)
error_h = ERRORFUNC(error_h)
#### GEOS Geometry C data structures, and utility functions. ####
# Opaque GEOS geometry structures, used for GEOM_PTR and CS_PTR
class GEOSGeom_t(Structure):
pass
class GEOSPrepGeom_t(Structure):
pass
class GEOSCoordSeq_t(Structure):
pass
class GEOSContextHandle_t(Structure):
pass
# Pointers to opaque GEOS geometry structures.
GEOM_PTR = POINTER(GEOSGeom_t)
PREPGEOM_PTR = POINTER(GEOSPrepGeom_t)
CS_PTR = POINTER(GEOSCoordSeq_t)
CONTEXT_PTR = POINTER(GEOSContextHandle_t)
# Used specifically by the GEOSGeom_createPolygon and GEOSGeom_createCollection
# GEOS routines
def get_pointer_arr(n):
"Gets a ctypes pointer array (of length `n`) for GEOSGeom_t opaque pointer."
GeomArr = GEOM_PTR * n
return GeomArr()
# Returns the string version of the GEOS library. Have to set the restype
# explicitly to c_char_p to ensure compatibility across 32 and 64-bit platforms.
geos_version = lgeos.GEOSversion
geos_version.argtypes = None
geos_version.restype = c_char_p
# Regular expression should be able to parse version strings such as
# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1', '3.4.0dev-CAPI-1.8.0' or '3.4.0dev-CAPI-1.8.0 r0'
version_regex = re.compile(
r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))'
r'((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$'
)
def geos_version_info():
"""
Returns a dictionary containing the various version metadata parsed from
the GEOS version string, including the version number, whether the version
is a release candidate (and what number release candidate), and the C API
version.
"""
ver = geos_version().decode()
m = version_regex.match(ver)
if not m:
raise GEOSException('Could not parse version info string "%s"' % ver)
return dict((key, m.group(key)) for key in (
'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))
# Version numbers and whether or not prepared geometry support is available.
_verinfo = geos_version_info()
GEOS_MAJOR_VERSION = int(_verinfo['major'])
GEOS_MINOR_VERSION = int(_verinfo['minor'])
GEOS_SUBMINOR_VERSION = int(_verinfo['subminor'])
del _verinfo
GEOS_VERSION = (GEOS_MAJOR_VERSION, GEOS_MINOR_VERSION, GEOS_SUBMINOR_VERSION)
# Here we set up the prototypes for the initGEOS_r and finishGEOS_r
# routines. These functions aren't actually called until they are
# attached to a GEOS context handle -- this actually occurs in
# geos/prototypes/threadsafe.py.
lgeos.initGEOS_r.restype = CONTEXT_PTR
lgeos.finishGEOS_r.argtypes = [CONTEXT_PTR]
|
mit
|
[
624,
199,
961,
859,
394,
810,
874,
314,
5577,
11097,
557,
6867,
1482,
12,
465,
5521,
199,
465,
314,
4245,
436,
1125,
3016,
805,
13484,
334,
362,
2797,
199,
1380,
376,
1125,
11058,
315,
11920,
680,
421,
961,
859,
2597,
394,
810,
874,
11920,
28833,
15841,
12,
5893,
199,
664,
63,
3929,
63,
5250,
1062,
436,
8991,
7474,
63,
14528,
14,
199,
624,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
504,
5577,
492,
286,
63,
1560,
63,
80,
12,
21730,
12,
445,
15982,
12,
11093,
12,
6569,
199,
504,
5577,
14,
1974,
492,
2342,
63,
4342,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
705,
492,
21390,
21686,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
2828,
14,
5668,
358,
199,
199,
3,
8388,
3555,
931,
663,
31,
199,
893,
26,
272,
687,
1639,
14,
2190,
492,
2202,
272,
1973,
63,
515,
275,
2202,
14,
14151,
63,
16983,
63,
3243,
199,
2590,
334,
10227,
12,
25139,
12,
267,
3545,
12,
11897,
304,
272,
1973,
63,
515,
275,
488,
199,
199,
3,
13510,
314,
5827,
1561,
367,
314,
11920,
13,
35,
3555,
14,
199,
692,
1973,
63,
515,
26,
272,
1973,
63,
1247,
275,
488,
199,
4164,
747,
14,
354,
508,
283,
343,
356,
272,
327,
5417,
23350,
8363,
272,
1973,
63,
1247,
275,
788,
12151,
63,
67,
297,
283,
773,
12151,
63,
67,
13,
17,
418,
199,
4164,
747,
14,
354,
508,
283,
9228,
356,
272,
327,
627,
46,
3867,
8363,
272,
1973,
63,
1247,
275,
788,
12151,
63,
67,
297,
283,
14151,
418,
199,
2836,
26,
272,
746,
3545,
360,
12647,
4403,
2071,
83,
4507,
450,
747,
14,
354,
9,
199,
199,
3,
11719,
314,
5577,
658,
1623,
63,
4342,
64,
11420,
370,
2342,
314,
931,
370,
314,
11920,
199,
3,
5709,
3555,
14,
221,
961,
365,
8034,
2419,
10250,
9176,
1924,
3555,
536,
199,
3,
436,
3329,
334,
69,
14,
71,
2020,
1973,
12151,
63,
67,
24097,
1152,
92,
1152,
14,
17,
92,
22305,
1055,
680,
199,
692,
1973,
63,
1247,
26,
272,
367,
1973,
63,
354,
315,
1973,
63,
1247,
26,
267,
1973,
63,
515,
275,
2342,
63,
4342,
8,
773,
63,
354,
9,
267,
340,
1973,
63,
515,
365,
440,
488,
26,
288,
2059,
199,
199,
3,
3091,
11920,
3555,
4293,
506,
1911,
14,
199,
692,
1973,
63,
515,
365,
488,
26,
272,
746,
3545,
8,
267,
283,
6531,
440,
2342,
314,
11920,
3555,
334,
599,
379,
2071,
83,
3471,
283,
267,
283,
12357,
4260,
11920,
63,
16983,
63,
3243,
315,
2195,
2202,
3530,
450,
267,
283,
401,
298,
1370,
904,
8,
773,
63,
1247,
9,
272,
776,
199,
199,
3,
20703,
314,
11920,
445,
3555,
14,
221,
710,
445,
3217,
334,
7695,
4464,
9,
365,
1202,
367,
199,
3,
3865,
627,
46,
3867,
436,
5417,
14,
199,
3,
1666,
314,
11920,
445,
3261,
1350,
1233,
367,
1655,
2436,
641,
314,
3555,
805,
4882,
26,
199,
3,
221,
1455,
921,
12151,
14,
1121,
345,
2452,
14,
846,
15,
293,
15,
1117,
20515,
63,
4757,
15,
1360,
15,
12151,
363,
67,
63,
24,
72,
13,
1365,
14,
1360,
199,
76,
12151,
275,
445,
15982,
8,
773,
63,
515,
9,
199,
199,
3,
710,
4245,
436,
1125,
3016,
445,
805,
3233,
10269,
14,
199,
3,
6820,
5824,
370,
24102,
530,
314,
11920,
1245,
3016,
334,
35,
5084,
304,
199,
3,
221,
22037,
2309,
19943,
14151,
2209,
2461,
5130,
1297,
1495,
627,
5045,
12,
2263,
2736,
199,
4609,
4047,
19587,
275,
11093,
8,
403,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1560,
63,
80,
9,
421,
199,
318,
4245,
63,
72,
8,
5045,
12,
9877,
304,
272,
7104,
12,
9877,
275,
7104,
14,
2708,
1062,
9877,
14,
2708,
342,
272,
862,
26,
267,
7987,
63,
1328,
275,
7104,
450,
9877,
272,
871,
3146,
26,
267,
7987,
63,
1328,
275,
7104,
272,
2512,
14,
3764,
360,
14151,
63,
4609,
4047,
26,
450,
83,
60,
78,
7,
450,
7987,
63,
1328,
9,
199,
20556,
63,
72,
275,
12840,
19587,
8,
20556,
63,
72,
9,
199,
199,
3170,
19587,
275,
11093,
8,
403,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1560,
63,
80,
9,
421,
199,
318,
1125,
63,
72,
8,
5045,
12,
9877,
304,
272,
7104,
12,
9877,
275,
7104,
14,
2708,
1062,
9877,
14,
2708,
342,
272,
862,
26,
267,
2329,
63,
1328,
275,
7104,
450,
9877,
272,
871,
3146,
26,
267,
2329,
63,
1328,
275,
7104,
272,
2512,
14,
705,
360,
14151,
63,
3170,
26,
450,
83,
60,
78,
7,
450,
2329,
63,
1328,
9,
199,
705,
63,
72,
275,
12539,
19587,
8,
705,
63,
72,
9,
199,
199,
381,
11920,
10579,
445,
666,
13955,
12,
436,
11420,
3423,
14,
14055,
421,
199,
3,
593,
10578,
11920,
3400,
13955,
12,
1202,
367,
8991,
7474,
63,
14528,
436,
17447,
63,
14528,
199,
533,
11920,
13427,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
24001,
13427,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
14957,
11205,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
2998,
5940,
63,
84,
8,
10766,
304,
272,
986,
199,
199,
3,
4376,
11005,
370,
15058,
11920,
3400,
13955,
14,
199,
31080,
63,
14528,
275,
6569,
8,
14151,
13427,
63,
84,
9,
199,
4225,
48,
31080,
63,
14528,
275,
6569,
8,
14151,
24001,
13427,
63,
84,
9,
199,
3298,
63,
14528,
275,
6569,
8,
14151,
14957,
11205,
63,
84,
9,
199,
9059,
63,
14528,
275,
6569,
8,
14151,
2998,
5940,
63,
84,
9,
421,
199,
3,
8051,
22543,
701,
314,
11920,
13427,
63,
981,
12367,
436,
11920,
13427,
63,
981,
7768,
199,
3,
221,
11920,
14975,
199,
318,
664,
63,
3929,
63,
5250,
8,
78,
304,
272,
298,
14426,
282,
5577,
7849,
1625,
334,
1618,
2582,
658,
78,
10522,
367,
11920,
13427,
63,
84,
15058,
7849,
2122,
272,
5346,
676,
22011,
275,
8991,
7474,
63,
14528,
627,
302,
272,
372,
5346,
676,
22011,
342,
199,
199,
3,
1803,
314,
1059,
1015,
402,
314,
11920,
3555,
14,
26858,
370,
663,
314,
4618,
514,
199,
3,
7662,
370,
286,
63,
1560,
63,
80
] |
[
199,
961,
859,
394,
810,
874,
314,
5577,
11097,
557,
6867,
1482,
12,
465,
5521,
199,
465,
314,
4245,
436,
1125,
3016,
805,
13484,
334,
362,
2797,
199,
1380,
376,
1125,
11058,
315,
11920,
680,
421,
961,
859,
2597,
394,
810,
874,
11920,
28833,
15841,
12,
5893,
199,
664,
63,
3929,
63,
5250,
1062,
436,
8991,
7474,
63,
14528,
14,
199,
624,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
504,
5577,
492,
286,
63,
1560,
63,
80,
12,
21730,
12,
445,
15982,
12,
11093,
12,
6569,
199,
504,
5577,
14,
1974,
492,
2342,
63,
4342,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
705,
492,
21390,
21686,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
2828,
14,
5668,
358,
199,
199,
3,
8388,
3555,
931,
663,
31,
199,
893,
26,
272,
687,
1639,
14,
2190,
492,
2202,
272,
1973,
63,
515,
275,
2202,
14,
14151,
63,
16983,
63,
3243,
199,
2590,
334,
10227,
12,
25139,
12,
267,
3545,
12,
11897,
304,
272,
1973,
63,
515,
275,
488,
199,
199,
3,
13510,
314,
5827,
1561,
367,
314,
11920,
13,
35,
3555,
14,
199,
692,
1973,
63,
515,
26,
272,
1973,
63,
1247,
275,
488,
199,
4164,
747,
14,
354,
508,
283,
343,
356,
272,
327,
5417,
23350,
8363,
272,
1973,
63,
1247,
275,
788,
12151,
63,
67,
297,
283,
773,
12151,
63,
67,
13,
17,
418,
199,
4164,
747,
14,
354,
508,
283,
9228,
356,
272,
327,
627,
46,
3867,
8363,
272,
1973,
63,
1247,
275,
788,
12151,
63,
67,
297,
283,
14151,
418,
199,
2836,
26,
272,
746,
3545,
360,
12647,
4403,
2071,
83,
4507,
450,
747,
14,
354,
9,
199,
199,
3,
11719,
314,
5577,
658,
1623,
63,
4342,
64,
11420,
370,
2342,
314,
931,
370,
314,
11920,
199,
3,
5709,
3555,
14,
221,
961,
365,
8034,
2419,
10250,
9176,
1924,
3555,
536,
199,
3,
436,
3329,
334,
69,
14,
71,
2020,
1973,
12151,
63,
67,
24097,
1152,
92,
1152,
14,
17,
92,
22305,
1055,
680,
199,
692,
1973,
63,
1247,
26,
272,
367,
1973,
63,
354,
315,
1973,
63,
1247,
26,
267,
1973,
63,
515,
275,
2342,
63,
4342,
8,
773,
63,
354,
9,
267,
340,
1973,
63,
515,
365,
440,
488,
26,
288,
2059,
199,
199,
3,
3091,
11920,
3555,
4293,
506,
1911,
14,
199,
692,
1973,
63,
515,
365,
488,
26,
272,
746,
3545,
8,
267,
283,
6531,
440,
2342,
314,
11920,
3555,
334,
599,
379,
2071,
83,
3471,
283,
267,
283,
12357,
4260,
11920,
63,
16983,
63,
3243,
315,
2195,
2202,
3530,
450,
267,
283,
401,
298,
1370,
904,
8,
773,
63,
1247,
9,
272,
776,
199,
199,
3,
20703,
314,
11920,
445,
3555,
14,
221,
710,
445,
3217,
334,
7695,
4464,
9,
365,
1202,
367,
199,
3,
3865,
627,
46,
3867,
436,
5417,
14,
199,
3,
1666,
314,
11920,
445,
3261,
1350,
1233,
367,
1655,
2436,
641,
314,
3555,
805,
4882,
26,
199,
3,
221,
1455,
921,
12151,
14,
1121,
345,
2452,
14,
846,
15,
293,
15,
1117,
20515,
63,
4757,
15,
1360,
15,
12151,
363,
67,
63,
24,
72,
13,
1365,
14,
1360,
199,
76,
12151,
275,
445,
15982,
8,
773,
63,
515,
9,
199,
199,
3,
710,
4245,
436,
1125,
3016,
445,
805,
3233,
10269,
14,
199,
3,
6820,
5824,
370,
24102,
530,
314,
11920,
1245,
3016,
334,
35,
5084,
304,
199,
3,
221,
22037,
2309,
19943,
14151,
2209,
2461,
5130,
1297,
1495,
627,
5045,
12,
2263,
2736,
199,
4609,
4047,
19587,
275,
11093,
8,
403,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1560,
63,
80,
9,
421,
199,
318,
4245,
63,
72,
8,
5045,
12,
9877,
304,
272,
7104,
12,
9877,
275,
7104,
14,
2708,
1062,
9877,
14,
2708,
342,
272,
862,
26,
267,
7987,
63,
1328,
275,
7104,
450,
9877,
272,
871,
3146,
26,
267,
7987,
63,
1328,
275,
7104,
272,
2512,
14,
3764,
360,
14151,
63,
4609,
4047,
26,
450,
83,
60,
78,
7,
450,
7987,
63,
1328,
9,
199,
20556,
63,
72,
275,
12840,
19587,
8,
20556,
63,
72,
9,
199,
199,
3170,
19587,
275,
11093,
8,
403,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1560,
63,
80,
9,
421,
199,
318,
1125,
63,
72,
8,
5045,
12,
9877,
304,
272,
7104,
12,
9877,
275,
7104,
14,
2708,
1062,
9877,
14,
2708,
342,
272,
862,
26,
267,
2329,
63,
1328,
275,
7104,
450,
9877,
272,
871,
3146,
26,
267,
2329,
63,
1328,
275,
7104,
272,
2512,
14,
705,
360,
14151,
63,
3170,
26,
450,
83,
60,
78,
7,
450,
2329,
63,
1328,
9,
199,
705,
63,
72,
275,
12539,
19587,
8,
705,
63,
72,
9,
199,
199,
381,
11920,
10579,
445,
666,
13955,
12,
436,
11420,
3423,
14,
14055,
421,
199,
3,
593,
10578,
11920,
3400,
13955,
12,
1202,
367,
8991,
7474,
63,
14528,
436,
17447,
63,
14528,
199,
533,
11920,
13427,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
24001,
13427,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
14957,
11205,
63,
84,
8,
10766,
304,
272,
986,
421,
199,
533,
11920,
2998,
5940,
63,
84,
8,
10766,
304,
272,
986,
199,
199,
3,
4376,
11005,
370,
15058,
11920,
3400,
13955,
14,
199,
31080,
63,
14528,
275,
6569,
8,
14151,
13427,
63,
84,
9,
199,
4225,
48,
31080,
63,
14528,
275,
6569,
8,
14151,
24001,
13427,
63,
84,
9,
199,
3298,
63,
14528,
275,
6569,
8,
14151,
14957,
11205,
63,
84,
9,
199,
9059,
63,
14528,
275,
6569,
8,
14151,
2998,
5940,
63,
84,
9,
421,
199,
3,
8051,
22543,
701,
314,
11920,
13427,
63,
981,
12367,
436,
11920,
13427,
63,
981,
7768,
199,
3,
221,
11920,
14975,
199,
318,
664,
63,
3929,
63,
5250,
8,
78,
304,
272,
298,
14426,
282,
5577,
7849,
1625,
334,
1618,
2582,
658,
78,
10522,
367,
11920,
13427,
63,
84,
15058,
7849,
2122,
272,
5346,
676,
22011,
275,
8991,
7474,
63,
14528,
627,
302,
272,
372,
5346,
676,
22011,
342,
199,
199,
3,
1803,
314,
1059,
1015,
402,
314,
11920,
3555,
14,
26858,
370,
663,
314,
4618,
514,
199,
3,
7662,
370,
286,
63,
1560,
63,
80,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eduOS/anki
|
anki/hooks.py
|
23
|
1819
|
# -*- coding: utf-8 -*-
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""\
Hooks - hook management and tools for extending Anki
==============================================================================
To find available hooks, grep for runHook and runFilter in the source code.
Instrumenting allows you to modify functions that don't have hooks available.
If you call wrap() with pos='around', the original function will not be called
automatically but can be called with _old().
"""
# Hooks
##############################################################################
_hooks = {}
def runHook(hook, *args):
"Run all functions on hook."
hook = _hooks.get(hook, None)
if hook:
for func in hook:
func(*args)
def runFilter(hook, arg, *args):
hook = _hooks.get(hook, None)
if hook:
for func in hook:
arg = func(arg, *args)
return arg
def addHook(hook, func):
"Add a function to hook. Ignore if already on hook."
if not _hooks.get(hook, None):
_hooks[hook] = []
if func not in _hooks[hook]:
_hooks[hook].append(func)
def remHook(hook, func):
"Remove a function if is on hook."
hook = _hooks.get(hook, [])
if func in hook:
hook.remove(func)
# Instrumenting
##############################################################################
def wrap(old, new, pos="after"):
"Override an existing function."
def repl(*args, **kwargs):
if pos == "after":
old(*args, **kwargs)
return new(*args, **kwargs)
elif pos == "before":
new(*args, **kwargs)
return old(*args, **kwargs)
else:
return new(_old=old, *args, **kwargs)
return repl
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
26,
577,
13496,
287,
13096,
6415,
665,
3580,
73,
32,
1158,
73,
18,
14,
846,
30,
199,
3,
844,
26,
1664,
437,
12006,
12,
1015,
650,
503,
2945,
27,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
199,
199,
19659,
199,
8481,
83,
446,
5759,
10041,
436,
7249,
367,
2178,
1098,
1626,
8810,
199,
5695,
17224,
199,
199,
1378,
2342,
2808,
12604,
12,
20595,
367,
1255,
8481,
436,
1255,
4131,
315,
314,
1350,
1233,
14,
199,
199,
14915,
316,
6127,
1265,
370,
2811,
3423,
626,
2793,
1133,
1172,
12604,
2808,
14,
199,
3917,
1265,
1240,
4816,
342,
543,
2086,
534,
11659,
297,
314,
3379,
805,
911,
440,
506,
2797,
199,
2495,
17174,
1325,
883,
506,
2797,
543,
485,
1753,
1252,
199,
624,
199,
199,
3,
24837,
83,
199,
4605,
199,
199,
63,
7922,
275,
1052,
199,
199,
318,
1255,
8481,
8,
3664,
12,
627,
589,
304,
272,
298,
2540,
1006,
3423,
641,
5759,
2122,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
488,
9,
272,
340,
5759,
26,
267,
367,
2562,
315,
5759,
26,
288,
2562,
2031,
589,
9,
199,
199,
318,
1255,
4131,
8,
3664,
12,
1680,
12,
627,
589,
304,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
488,
9,
272,
340,
5759,
26,
267,
367,
2562,
315,
5759,
26,
288,
1680,
275,
2562,
8,
1273,
12,
627,
589,
9,
272,
372,
1680,
199,
199,
318,
1050,
8481,
8,
3664,
12,
2562,
304,
272,
298,
1123,
282,
805,
370,
5759,
14,
14092,
340,
2575,
641,
5759,
2122,
272,
340,
440,
485,
7922,
14,
362,
8,
3664,
12,
488,
304,
267,
485,
7922,
59,
3664,
61,
275,
942,
272,
340,
2562,
440,
315,
485,
7922,
59,
3664,
2189,
267,
485,
7922,
59,
3664,
1055,
740,
8,
1532,
9,
199,
199,
318,
18798,
8481,
8,
3664,
12,
2562,
304,
272,
298,
5587,
282,
805,
340,
365,
641,
5759,
2122,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
3073,
272,
340,
2562,
315,
5759,
26,
267,
5759,
14,
2168,
8,
1532,
9,
199,
199,
3,
25767,
316,
199,
4605,
199,
199,
318,
4816,
8,
1753,
12,
892,
12,
2086,
628,
4399,
2349,
272,
298,
11954,
376,
3411,
805,
2122,
272,
347,
20265,
2031,
589,
12,
1011,
958,
304,
267,
340,
2086,
508,
298,
4399,
582,
288,
2269,
2031,
589,
12,
1011,
958,
9,
288,
372,
892,
2031,
589,
12,
1011,
958,
9,
267,
916,
2086,
508,
298,
5182,
582,
288,
892,
2031,
589,
12,
1011,
958,
9,
288,
372,
2269,
2031,
589,
12,
1011,
958,
9,
267,
587,
26,
288,
372,
892,
1547,
1753,
29,
1753,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
20265,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
26,
577,
13496,
287,
13096,
6415,
665,
3580,
73,
32,
1158,
73,
18,
14,
846,
30,
199,
3,
844,
26,
1664,
437,
12006,
12,
1015,
650,
503,
2945,
27,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
199,
199,
19659,
199,
8481,
83,
446,
5759,
10041,
436,
7249,
367,
2178,
1098,
1626,
8810,
199,
5695,
17224,
199,
199,
1378,
2342,
2808,
12604,
12,
20595,
367,
1255,
8481,
436,
1255,
4131,
315,
314,
1350,
1233,
14,
199,
199,
14915,
316,
6127,
1265,
370,
2811,
3423,
626,
2793,
1133,
1172,
12604,
2808,
14,
199,
3917,
1265,
1240,
4816,
342,
543,
2086,
534,
11659,
297,
314,
3379,
805,
911,
440,
506,
2797,
199,
2495,
17174,
1325,
883,
506,
2797,
543,
485,
1753,
1252,
199,
624,
199,
199,
3,
24837,
83,
199,
4605,
199,
199,
63,
7922,
275,
1052,
199,
199,
318,
1255,
8481,
8,
3664,
12,
627,
589,
304,
272,
298,
2540,
1006,
3423,
641,
5759,
2122,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
488,
9,
272,
340,
5759,
26,
267,
367,
2562,
315,
5759,
26,
288,
2562,
2031,
589,
9,
199,
199,
318,
1255,
4131,
8,
3664,
12,
1680,
12,
627,
589,
304,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
488,
9,
272,
340,
5759,
26,
267,
367,
2562,
315,
5759,
26,
288,
1680,
275,
2562,
8,
1273,
12,
627,
589,
9,
272,
372,
1680,
199,
199,
318,
1050,
8481,
8,
3664,
12,
2562,
304,
272,
298,
1123,
282,
805,
370,
5759,
14,
14092,
340,
2575,
641,
5759,
2122,
272,
340,
440,
485,
7922,
14,
362,
8,
3664,
12,
488,
304,
267,
485,
7922,
59,
3664,
61,
275,
942,
272,
340,
2562,
440,
315,
485,
7922,
59,
3664,
2189,
267,
485,
7922,
59,
3664,
1055,
740,
8,
1532,
9,
199,
199,
318,
18798,
8481,
8,
3664,
12,
2562,
304,
272,
298,
5587,
282,
805,
340,
365,
641,
5759,
2122,
272,
5759,
275,
485,
7922,
14,
362,
8,
3664,
12,
3073,
272,
340,
2562,
315,
5759,
26,
267,
5759,
14,
2168,
8,
1532,
9,
199,
199,
3,
25767,
316,
199,
4605,
199,
199,
318,
4816,
8,
1753,
12,
892,
12,
2086,
628,
4399,
2349,
272,
298,
11954,
376,
3411,
805,
2122,
272,
347,
20265,
2031,
589,
12,
1011,
958,
304,
267,
340,
2086,
508,
298,
4399,
582,
288,
2269,
2031,
589,
12,
1011,
958,
9,
288,
372,
892,
2031,
589,
12,
1011,
958,
9,
267,
916,
2086,
508,
298,
5182,
582,
288,
892,
2031,
589,
12,
1011,
958,
9,
288,
372,
2269,
2031,
589,
12,
1011,
958,
9,
267,
587,
26,
288,
372,
892,
1547,
1753,
29,
1753,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
20265,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
hkhamm/django_rest_tutorial_2
|
env/lib/python2.7/site-packages/django/conf/locale/tr/formats.py
|
118
|
1142
|
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
from __future__ import unicode_literals
# The *_FORMAT strings use the Django date format syntax,
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = 'd F Y'
TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'd F Y H:i:s'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'd F'
SHORT_DATE_FORMAT = 'd M Y'
SHORT_DATETIME_FORMAT = 'd M Y H:i:s'
FIRST_DAY_OF_WEEK = 1 # Pazartesi
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = (
'%d/%m/%Y', '%d/%m/%y', # '25/10/2006', '25/10/06'
'%y-%m-%d', # '06-10-25'
# '%d %B %Y', '%d %b. %Y', # '25 Ekim 2006', '25 Eki. 2006'
)
DATETIME_INPUT_FORMATS = (
'%d/%m/%Y %H:%M:%S', # '25/10/2006 14:30:59'
'%d/%m/%Y %H:%M:%S.%f', # '25/10/2006 14:30:59.000200'
'%d/%m/%Y %H:%M', # '25/10/2006 14:30'
'%d/%m/%Y', # '25/10/2006'
)
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '.'
NUMBER_GROUPING = 3
|
mit
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
68,
481,
1488,
869,
26,
73,
26,
83,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
68,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
603,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
603,
1488,
869,
26,
73,
26,
83,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
327,
510,
4651,
285,
266,
338,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
3149,
77,
3149,
57,
297,
1543,
68,
3149,
77,
3149,
89,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
297,
283,
821,
15,
709,
15,
1690,
7,
272,
1543,
89,
3295,
77,
3295,
68,
297,
463,
327,
283,
1690,
13,
709,
13,
821,
7,
272,
327,
1543,
68,
450,
34,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
662,
75,
1017,
8315,
297,
283,
821,
662,
8810,
14,
8315,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
297,
259,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
297,
755,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3149,
77,
3149,
57,
297,
3777,
327,
283,
821,
15,
709,
15,
7968,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
26,
83,
7,
199,
12488,
63,
4807,
275,
283,
68,
481,
1488,
869,
26,
73,
26,
83,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
68,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
603,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
603,
1488,
869,
26,
73,
26,
83,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
327,
510,
4651,
285,
266,
338,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
3149,
77,
3149,
57,
297,
1543,
68,
3149,
77,
3149,
89,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
297,
283,
821,
15,
709,
15,
1690,
7,
272,
1543,
89,
3295,
77,
3295,
68,
297,
463,
327,
283,
1690,
13,
709,
13,
821,
7,
272,
327,
1543,
68,
450,
34,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
662,
75,
1017,
8315,
297,
283,
821,
662,
8810,
14,
8315,
7,
199,
9,
199,
12488,
63,
7321,
63,
14019,
275,
334,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
297,
259,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
297,
755,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3149,
77,
3149,
57,
297,
3777,
327,
283,
821,
15,
709,
15,
7968,
7,
199,
9,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
317070/kaggle-heart
|
configurations/j2_crps2.py
|
1
|
6318
|
from deep_learning_layers import ConvolutionOver2DAxisLayer, MaxPoolOverAxisLayer, MaxPoolOver2DAxisLayer, \
MaxPoolOver3DAxisLayer, ConvolutionOver3DAxisLayer, ConvolutionOverAxisLayer
from default import *
import theano.tensor as T
from layers import MuLogSigmaErfLayer, CumSumLayer
import objectives
from lasagne.layers import InputLayer, reshape, DenseLayer, DenseLayer, batch_norm
from postprocess import upsample_segmentation
from volume_estimation_layers import GaussianApproximationVolumeLayer
import theano_printer
from updates import build_adam_updates
validate_every = 10
validate_train_set = False
save_every = 10
restart_from_save = False
batches_per_chunk = 2
batch_size = 8
sunny_batch_size = 4
num_epochs_train = 200
image_size = 64
learning_rate_schedule = {
0: 0.0001,
}
from postprocess import postprocess_onehot, postprocess
from preprocess import preprocess, preprocess_with_augmentation
preprocess_train = preprocess_with_augmentation # with augmentation
preprocess_validation = preprocess # no augmentation
preprocess_test = preprocess_with_augmentation # no augmentation
test_time_augmentations = 10
build_updates = build_adam_updates
postprocess = postprocess
data_sizes = {
"sliced:data:ax": (batch_size, 30, 15, image_size, image_size), # 30 time steps, 20 mri_slices, 100 px wide, 100 px high,
"sliced:data:ax:noswitch": (batch_size, 15, 30, image_size, image_size), # 30 time steps, 20 mri_slices, 100 px wide, 100 px high,
"sliced:data:shape": (batch_size, 2,),
"sunny": (sunny_batch_size, 1, image_size, image_size)
# TBC with the metadata
}
augmentation_params = {
"rotation": (0, 360),
"shear": (-1, 1),
"translation": (-1, 1),
}
def build_model():
#################
# Regular model #
#################
data_size = data_sizes["sliced:data:ax:noswitch"]
l0 = InputLayer(data_size)
l0r = batch_norm(reshape(l0, (-1, 1, ) + data_size[1:]))
# (batch, channel, axis, time, x, y)
# convolve over time
l1 = batch_norm(ConvolutionOverAxisLayer(l0r, num_filters=4, filter_size=(3,), axis=(3,), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.0),
))
l1m = batch_norm(MaxPoolOverAxisLayer(l1, pool_size=(4,), axis=(3,)))
# convolve over x and y
l2a = batch_norm(ConvolutionOver2DAxisLayer(l1m, num_filters=8, filter_size=(3, 3),
axis=(4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.0),
))
l2b = batch_norm(ConvolutionOver2DAxisLayer(l2a, num_filters=8, filter_size=(3, 3),
axis=(4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.0),
))
l2m = batch_norm(MaxPoolOver2DAxisLayer(l2b, pool_size=(2, 2), axis=(4,5)))
# convolve over x, y, time
l3a = batch_norm(ConvolutionOver3DAxisLayer(l2m, num_filters=32, filter_size=(3, 3, 3),
axis=(3,4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
))
l3b = batch_norm(ConvolutionOver2DAxisLayer(l3a, num_filters=32, filter_size=(3, 3),
axis=(4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
))
l3m = batch_norm(MaxPoolOver2DAxisLayer(l3b, pool_size=(2, 2), axis=(4,5)))
# convolve over time
l4 = batch_norm(ConvolutionOverAxisLayer(l3m, num_filters=32, filter_size=(3,), axis=(3,), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
))
l4m = batch_norm(MaxPoolOverAxisLayer(l4, pool_size=(2,), axis=(2,)))
# maxpool over axis
l5 = batch_norm(MaxPoolOverAxisLayer(l3m, pool_size=(4,), axis=(2,)))
# convolve over x and y
l6a = batch_norm(ConvolutionOver2DAxisLayer(l5, num_filters=128, filter_size=(3, 3),
axis=(4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
))
l6b = batch_norm(ConvolutionOver2DAxisLayer(l6a, num_filters=128, filter_size=(3, 3),
axis=(4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
))
l6m = batch_norm(MaxPoolOver2DAxisLayer(l6b, pool_size=(2, 2), axis=(4,5)))
# convolve over time and x,y
l7 = ConvolutionOver3DAxisLayer(l6m, num_filters=128, filter_size=(3,3,3), axis=(3,4,5), channel=1,
W=lasagne.init.Orthogonal(),
b=lasagne.init.Constant(0.1),
)
l8 = lasagne.layers.DropoutLayer(l7, p=0.5)
l_systole = CumSumLayer(lasagne.layers.DenseLayer(l8,
num_units=600,
nonlinearity=lasagne.nonlinearities.softmax))
l_diastole = CumSumLayer(lasagne.layers.DenseLayer(l8,
num_units=600,
nonlinearity=lasagne.nonlinearities.softmax))
return {
"inputs":{
"sliced:data:ax:noswitch": l0
},
"outputs": {
"systole": l_systole,
"diastole": l_diastole,
},
"regularizable": {
}
}
def build_objective(interface_layers):
l2_penalty = 0#lasagne.regularization.regularize_layer_params_weighted(interface_layers["regularizable"], lasagne.regularization.l2)
return objectives.KaggleObjective(interface_layers["outputs"], penalty=l2_penalty)
|
mit
|
[
504,
13217,
63,
10546,
63,
4359,
492,
19140,
3347,
5674,
18,
8980,
7291,
5003,
12,
8228,
5453,
5674,
11220,
5003,
12,
8228,
5453,
5674,
18,
8980,
7291,
5003,
12,
971,
272,
8228,
5453,
5674,
19,
8980,
7291,
5003,
12,
19140,
3347,
5674,
19,
8980,
7291,
5003,
12,
19140,
3347,
5674,
11220,
5003,
199,
504,
849,
492,
627,
199,
199,
646,
14377,
14,
3128,
465,
377,
199,
504,
9393,
492,
28919,
2445,
23394,
539,
70,
5003,
12,
445,
453,
6959,
5003,
199,
646,
1559,
825,
7301,
199,
504,
23325,
29575,
14,
4359,
492,
6924,
5003,
12,
21460,
12,
20847,
5003,
12,
20847,
5003,
12,
3522,
63,
4791,
199,
504,
2963,
1412,
492,
1536,
3271,
63,
26926,
199,
504,
3301,
63,
597,
8182,
63,
4359,
492,
17131,
25923,
20030,
6464,
5003,
199,
646,
14377,
63,
11835,
199,
504,
7029,
492,
1900,
63,
27679,
63,
7618,
199,
199,
3502,
63,
14287,
275,
1616,
199,
3502,
63,
2834,
63,
409,
275,
756,
199,
2117,
63,
14287,
275,
1616,
199,
10506,
63,
504,
63,
2117,
275,
756,
199,
199,
14896,
63,
529,
63,
4604,
275,
499,
199,
199,
2912,
63,
890,
275,
1695,
199,
11846,
9745,
63,
2912,
63,
890,
275,
841,
199,
1507,
63,
13161,
63,
2834,
275,
1926,
199,
199,
1569,
63,
890,
275,
5049,
199,
199,
10546,
63,
1866,
63,
7211,
275,
469,
272,
378,
26,
258,
378,
14,
4183,
12,
199,
93,
199,
199,
504,
2963,
1412,
492,
2963,
1412,
63,
368,
8885,
12,
2963,
1412,
199,
504,
23351,
492,
23351,
12,
23351,
63,
1045,
63,
20669,
3117,
199,
17677,
63,
2834,
275,
23351,
63,
1045,
63,
20669,
3117,
221,
327,
543,
18336,
3117,
199,
17677,
63,
6136,
275,
23351,
221,
327,
949,
18336,
3117,
199,
17677,
63,
396,
275,
23351,
63,
1045,
63,
20669,
3117,
221,
327,
949,
18336,
3117,
199,
396,
63,
521,
63,
20669,
434,
1298,
275,
1616,
199,
199,
1506,
63,
7618,
275,
1900,
63,
27679,
63,
7618,
199,
32238,
275,
2963,
1412,
199,
199,
576,
63,
7723,
275,
469,
272,
298,
5224,
68,
26,
576,
26,
1219,
582,
334,
2912,
63,
890,
12,
4233,
12,
4114,
12,
1834,
63,
890,
12,
1834,
63,
890,
395,
327,
4233,
900,
7124,
12,
3388,
333,
322,
63,
14865,
12,
2948,
21162,
20239,
12,
2948,
21162,
4721,
12,
272,
298,
5224,
68,
26,
576,
26,
1219,
26,
12712,
3111,
582,
334,
2912,
63,
890,
12,
4114,
12,
4233,
12,
1834,
63,
890,
12,
1834,
63,
890,
395,
327,
4233,
900,
7124,
12,
3388,
333,
322,
63,
14865,
12,
2948,
21162,
20239,
12,
2948,
21162,
4721,
12,
272,
298,
5224,
68,
26,
576,
26,
1392,
582,
334,
2912,
63,
890,
12,
499,
4706,
272,
298,
11846,
9745,
582,
334,
11846,
9745,
63,
2912,
63,
890,
12,
413,
12,
1834,
63,
890,
12,
1834,
63,
890,
9,
272,
327,
377,
6265,
543,
314,
3341,
199,
93,
199,
199,
20669,
3117,
63,
1162,
275,
469,
272,
298,
15362,
582,
334,
16,
12,
19434,
395,
272,
298,
19195,
285,
582,
5868,
17,
12,
413,
395,
272,
298,
6893,
582,
5868,
17,
12,
413,
395,
199,
93,
199,
199,
318,
1900,
63,
1238,
837,
339,
21905,
3,
272,
327,
18528,
1402,
327,
272,
21905,
3,
272,
666,
63,
890,
275,
666,
63,
7723,
905,
5224,
68,
26,
576,
26,
1219,
26,
12712,
3111,
937,
339,
634,
16,
275,
6924,
5003,
8,
576,
63,
890,
9,
272,
634,
16,
82,
275,
3522,
63,
4791,
8,
5217,
8,
76,
16,
12,
5868,
17,
12,
413,
12,
776,
435,
666,
63,
890,
59,
17,
16720,
339,
327,
334,
2912,
12,
3623,
12,
3114,
12,
900,
12,
671,
12,
612,
9,
339,
327,
8260,
3344,
1806,
900,
272,
634,
17,
275,
3522,
63,
4791,
8,
27394,
5674,
11220,
5003,
8,
76,
16,
82,
12,
1967,
63,
4273,
29,
20,
12,
2457,
63,
890,
2687,
19,
4706,
3114,
2687,
19,
4706,
3623,
29,
17,
12,
3521,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3521,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3521,
5082,
272,
634,
17,
77,
275,
3522,
63,
4791,
8,
29883,
5674,
11220,
5003,
8,
76,
17,
12,
4203,
63,
890,
2687,
20,
4706,
3114,
2687,
19,
20097,
339,
327,
8260,
3344,
1806,
671,
436,
612,
272,
634,
18,
65,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
17,
77,
12,
1967,
63,
4273,
29,
24,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3660,
5082,
272,
634,
18,
66,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
18,
65,
12,
1967,
63,
4273,
29,
24,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3660,
5082,
272,
634,
18,
77,
275,
3522,
63,
4791,
8,
29883,
5674,
18,
8980,
7291,
5003,
8,
76,
18,
66,
12,
4203,
63,
890,
2687,
18,
12,
499,
395,
3114,
2687,
20,
12,
21,
1724,
2378,
327,
8260,
3344,
1806,
671,
12,
612,
12,
900,
272,
634,
19,
65,
275,
3522,
63,
4791,
8,
27394,
5674,
19,
8980,
7291,
5003,
8,
76,
18,
77,
12,
1967,
63,
4273,
29,
708,
12,
2457,
63,
890,
2687,
19,
12,
650,
12,
650,
395,
3660,
3114,
2687,
19,
12,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
17,
395,
3660,
5082,
339,
634,
19,
66,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
19,
65,
12,
1967,
63,
4273,
29,
708,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536
] |
[
13217,
63,
10546,
63,
4359,
492,
19140,
3347,
5674,
18,
8980,
7291,
5003,
12,
8228,
5453,
5674,
11220,
5003,
12,
8228,
5453,
5674,
18,
8980,
7291,
5003,
12,
971,
272,
8228,
5453,
5674,
19,
8980,
7291,
5003,
12,
19140,
3347,
5674,
19,
8980,
7291,
5003,
12,
19140,
3347,
5674,
11220,
5003,
199,
504,
849,
492,
627,
199,
199,
646,
14377,
14,
3128,
465,
377,
199,
504,
9393,
492,
28919,
2445,
23394,
539,
70,
5003,
12,
445,
453,
6959,
5003,
199,
646,
1559,
825,
7301,
199,
504,
23325,
29575,
14,
4359,
492,
6924,
5003,
12,
21460,
12,
20847,
5003,
12,
20847,
5003,
12,
3522,
63,
4791,
199,
504,
2963,
1412,
492,
1536,
3271,
63,
26926,
199,
504,
3301,
63,
597,
8182,
63,
4359,
492,
17131,
25923,
20030,
6464,
5003,
199,
646,
14377,
63,
11835,
199,
504,
7029,
492,
1900,
63,
27679,
63,
7618,
199,
199,
3502,
63,
14287,
275,
1616,
199,
3502,
63,
2834,
63,
409,
275,
756,
199,
2117,
63,
14287,
275,
1616,
199,
10506,
63,
504,
63,
2117,
275,
756,
199,
199,
14896,
63,
529,
63,
4604,
275,
499,
199,
199,
2912,
63,
890,
275,
1695,
199,
11846,
9745,
63,
2912,
63,
890,
275,
841,
199,
1507,
63,
13161,
63,
2834,
275,
1926,
199,
199,
1569,
63,
890,
275,
5049,
199,
199,
10546,
63,
1866,
63,
7211,
275,
469,
272,
378,
26,
258,
378,
14,
4183,
12,
199,
93,
199,
199,
504,
2963,
1412,
492,
2963,
1412,
63,
368,
8885,
12,
2963,
1412,
199,
504,
23351,
492,
23351,
12,
23351,
63,
1045,
63,
20669,
3117,
199,
17677,
63,
2834,
275,
23351,
63,
1045,
63,
20669,
3117,
221,
327,
543,
18336,
3117,
199,
17677,
63,
6136,
275,
23351,
221,
327,
949,
18336,
3117,
199,
17677,
63,
396,
275,
23351,
63,
1045,
63,
20669,
3117,
221,
327,
949,
18336,
3117,
199,
396,
63,
521,
63,
20669,
434,
1298,
275,
1616,
199,
199,
1506,
63,
7618,
275,
1900,
63,
27679,
63,
7618,
199,
32238,
275,
2963,
1412,
199,
199,
576,
63,
7723,
275,
469,
272,
298,
5224,
68,
26,
576,
26,
1219,
582,
334,
2912,
63,
890,
12,
4233,
12,
4114,
12,
1834,
63,
890,
12,
1834,
63,
890,
395,
327,
4233,
900,
7124,
12,
3388,
333,
322,
63,
14865,
12,
2948,
21162,
20239,
12,
2948,
21162,
4721,
12,
272,
298,
5224,
68,
26,
576,
26,
1219,
26,
12712,
3111,
582,
334,
2912,
63,
890,
12,
4114,
12,
4233,
12,
1834,
63,
890,
12,
1834,
63,
890,
395,
327,
4233,
900,
7124,
12,
3388,
333,
322,
63,
14865,
12,
2948,
21162,
20239,
12,
2948,
21162,
4721,
12,
272,
298,
5224,
68,
26,
576,
26,
1392,
582,
334,
2912,
63,
890,
12,
499,
4706,
272,
298,
11846,
9745,
582,
334,
11846,
9745,
63,
2912,
63,
890,
12,
413,
12,
1834,
63,
890,
12,
1834,
63,
890,
9,
272,
327,
377,
6265,
543,
314,
3341,
199,
93,
199,
199,
20669,
3117,
63,
1162,
275,
469,
272,
298,
15362,
582,
334,
16,
12,
19434,
395,
272,
298,
19195,
285,
582,
5868,
17,
12,
413,
395,
272,
298,
6893,
582,
5868,
17,
12,
413,
395,
199,
93,
199,
199,
318,
1900,
63,
1238,
837,
339,
21905,
3,
272,
327,
18528,
1402,
327,
272,
21905,
3,
272,
666,
63,
890,
275,
666,
63,
7723,
905,
5224,
68,
26,
576,
26,
1219,
26,
12712,
3111,
937,
339,
634,
16,
275,
6924,
5003,
8,
576,
63,
890,
9,
272,
634,
16,
82,
275,
3522,
63,
4791,
8,
5217,
8,
76,
16,
12,
5868,
17,
12,
413,
12,
776,
435,
666,
63,
890,
59,
17,
16720,
339,
327,
334,
2912,
12,
3623,
12,
3114,
12,
900,
12,
671,
12,
612,
9,
339,
327,
8260,
3344,
1806,
900,
272,
634,
17,
275,
3522,
63,
4791,
8,
27394,
5674,
11220,
5003,
8,
76,
16,
82,
12,
1967,
63,
4273,
29,
20,
12,
2457,
63,
890,
2687,
19,
4706,
3114,
2687,
19,
4706,
3623,
29,
17,
12,
3521,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3521,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3521,
5082,
272,
634,
17,
77,
275,
3522,
63,
4791,
8,
29883,
5674,
11220,
5003,
8,
76,
17,
12,
4203,
63,
890,
2687,
20,
4706,
3114,
2687,
19,
20097,
339,
327,
8260,
3344,
1806,
671,
436,
612,
272,
634,
18,
65,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
17,
77,
12,
1967,
63,
4273,
29,
24,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3660,
5082,
272,
634,
18,
66,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
18,
65,
12,
1967,
63,
4273,
29,
24,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
16,
395,
3660,
5082,
272,
634,
18,
77,
275,
3522,
63,
4791,
8,
29883,
5674,
18,
8980,
7291,
5003,
8,
76,
18,
66,
12,
4203,
63,
890,
2687,
18,
12,
499,
395,
3114,
2687,
20,
12,
21,
1724,
2378,
327,
8260,
3344,
1806,
671,
12,
612,
12,
900,
272,
634,
19,
65,
275,
3522,
63,
4791,
8,
27394,
5674,
19,
8980,
7291,
5003,
8,
76,
18,
77,
12,
1967,
63,
4273,
29,
708,
12,
2457,
63,
890,
2687,
19,
12,
650,
12,
650,
395,
3660,
3114,
2687,
19,
12,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
29575,
14,
826,
14,
2844,
273,
19133,
1062,
3660,
330,
29,
12536,
29575,
14,
826,
14,
9737,
8,
16,
14,
17,
395,
3660,
5082,
339,
634,
19,
66,
275,
3522,
63,
4791,
8,
27394,
5674,
18,
8980,
7291,
5003,
8,
76,
19,
65,
12,
1967,
63,
4273,
29,
708,
12,
2457,
63,
890,
2687,
19,
12,
650,
395,
3660,
3114,
2687,
20,
12,
21,
395,
3623,
29,
17,
12,
3660,
644,
29,
12536,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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redirect.py
|
15
|
4291
|
from six.moves.urllib.parse import urljoin
from scrapy import log
from scrapy.http import HtmlResponse
from scrapy.utils.response import get_meta_refresh
from scrapy.exceptions import IgnoreRequest, NotConfigured
class BaseRedirectMiddleware(object):
enabled_setting = 'REDIRECT_ENABLED'
def __init__(self, settings):
if not settings.getbool(self.enabled_setting):
raise NotConfigured
self.max_redirect_times = settings.getint('REDIRECT_MAX_TIMES')
self.priority_adjust = settings.getint('REDIRECT_PRIORITY_ADJUST')
@classmethod
def from_crawler(cls, crawler):
return cls(crawler.settings)
def _redirect(self, redirected, request, spider, reason):
ttl = request.meta.setdefault('redirect_ttl', self.max_redirect_times)
redirects = request.meta.get('redirect_times', 0) + 1
if ttl and redirects <= self.max_redirect_times:
redirected.meta['redirect_times'] = redirects
redirected.meta['redirect_ttl'] = ttl - 1
redirected.meta['redirect_urls'] = request.meta.get('redirect_urls', []) + \
[request.url]
redirected.dont_filter = request.dont_filter
redirected.priority = request.priority + self.priority_adjust
log.msg(format="Redirecting (%(reason)s) to %(redirected)s from %(request)s",
level=log.DEBUG, spider=spider, request=request,
redirected=redirected, reason=reason)
return redirected
else:
log.msg(format="Discarding %(request)s: max redirections reached",
level=log.DEBUG, spider=spider, request=request)
raise IgnoreRequest("max redirections reached")
def _redirect_request_using_get(self, request, redirect_url):
redirected = request.replace(url=redirect_url, method='GET', body='')
redirected.headers.pop('Content-Type', None)
redirected.headers.pop('Content-Length', None)
return redirected
class RedirectMiddleware(BaseRedirectMiddleware):
"""Handle redirection of requests based on response status and meta-refresh html tag"""
def process_response(self, request, response, spider):
if request.meta.get('dont_redirect', False):
return response
if request.method == 'HEAD':
if response.status in [301, 302, 303, 307] and 'Location' in response.headers:
redirected_url = urljoin(request.url, response.headers['location'])
redirected = request.replace(url=redirected_url)
return self._redirect(redirected, request, spider, response.status)
else:
return response
if response.status in [302, 303] and 'Location' in response.headers:
redirected_url = urljoin(request.url, response.headers['location'])
redirected = self._redirect_request_using_get(request, redirected_url)
return self._redirect(redirected, request, spider, response.status)
if response.status in [301, 307] and 'Location' in response.headers:
redirected_url = urljoin(request.url, response.headers['location'])
redirected = request.replace(url=redirected_url)
return self._redirect(redirected, request, spider, response.status)
return response
class MetaRefreshMiddleware(BaseRedirectMiddleware):
enabled_setting = 'METAREFRESH_ENABLED'
def __init__(self, settings):
super(MetaRefreshMiddleware, self).__init__(settings)
self._maxdelay = settings.getint('REDIRECT_MAX_METAREFRESH_DELAY',
settings.getint('METAREFRESH_MAXDELAY'))
def process_response(self, request, response, spider):
if request.meta.get('dont_redirect', False) or request.method == 'HEAD' or \
not isinstance(response, HtmlResponse):
return response
if isinstance(response, HtmlResponse):
interval, url = get_meta_refresh(response)
if url and interval < self._maxdelay:
redirected = self._redirect_request_using_get(request, url)
return self._redirect(redirected, request, spider, 'meta refresh')
return response
|
bsd-3-clause
|
[
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
199,
504,
18918,
492,
943,
199,
504,
18918,
14,
1014,
492,
20880,
2364,
199,
504,
18918,
14,
1208,
14,
1310,
492,
664,
63,
2024,
63,
6635,
199,
504,
18918,
14,
3924,
492,
14092,
2017,
12,
2832,
9902,
421,
199,
533,
3523,
7071,
6608,
8,
785,
304,
339,
5223,
63,
6031,
275,
283,
19747,
63,
15704,
7,
339,
347,
636,
826,
721,
277,
12,
2202,
304,
267,
340,
440,
2202,
14,
362,
2245,
8,
277,
14,
3827,
63,
6031,
304,
288,
746,
2832,
9902,
398,
291,
14,
988,
63,
4876,
63,
4508,
275,
2202,
14,
26627,
360,
19747,
63,
4283,
63,
11342,
654,
358,
267,
291,
14,
6693,
63,
10917,
275,
2202,
14,
26627,
360,
19747,
63,
25144,
63,
1554,
42,
7698,
358,
339,
768,
3744,
272,
347,
687,
63,
23972,
8,
1886,
12,
29550,
304,
267,
372,
843,
8,
23972,
14,
1751,
9,
339,
347,
485,
4876,
8,
277,
12,
20884,
12,
1056,
12,
18094,
12,
4499,
304,
267,
14856,
275,
1056,
14,
2024,
14,
5486,
360,
4876,
63,
12130,
297,
291,
14,
988,
63,
4876,
63,
4508,
9,
267,
17784,
275,
1056,
14,
2024,
14,
362,
360,
4876,
63,
4508,
297,
378,
9,
435,
413,
398,
340,
14856,
436,
17784,
2695,
291,
14,
988,
63,
4876,
63,
4508,
26,
288,
20884,
14,
2024,
459,
4876,
63,
4508,
418,
275,
17784,
288,
20884,
14,
2024,
459,
4876,
63,
12130,
418,
275,
14856,
446,
413,
288,
20884,
14,
2024,
459,
4876,
63,
3603,
418,
275,
1056,
14,
2024,
14,
362,
360,
4876,
63,
3603,
297,
3073,
435,
971,
355,
359,
1069,
14,
633,
61,
288,
20884,
14,
18671,
63,
1541,
275,
1056,
14,
18671,
63,
1541,
288,
20884,
14,
6693,
275,
1056,
14,
6693,
435,
291,
14,
6693,
63,
10917,
288,
943,
14,
1328,
8,
908,
628,
7071,
316,
17753,
5764,
9,
83,
9,
370,
2818,
264,
12080,
9,
83,
687,
2818,
1069,
9,
83,
401,
490,
2166,
29,
793,
14,
5287,
12,
18094,
29,
12856,
12,
1056,
29,
1069,
12,
490,
20884,
29,
264,
12080,
12,
4499,
29,
5764,
9,
288,
372,
20884,
267,
587,
26,
288,
943,
14,
1328,
8,
908,
628,
2825,
5841,
316,
2818,
1069,
9,
83,
26,
1390,
295,
27917,
13075,
401,
490,
2166,
29,
793,
14,
5287,
12,
18094,
29,
12856,
12,
1056,
29,
1069,
9,
288,
746,
14092,
2017,
480,
988,
295,
27917,
13075,
531,
339,
347,
485,
4876,
63,
1069,
63,
4941,
63,
362,
8,
277,
12,
1056,
12,
4660,
63,
633,
304,
267,
20884,
275,
1056,
14,
1814,
8,
633,
29,
4876,
63,
633,
12,
1083,
534,
2970,
297,
2396,
13275,
267,
20884,
14,
2139,
14,
1935,
360,
2714,
13,
804,
297,
488,
9,
267,
20884,
14,
2139,
14,
1935,
360,
2714,
13,
4625,
297,
488,
9,
267,
372,
20884,
421,
199,
533,
18532,
6608,
8,
1563,
7071,
6608,
304,
272,
408,
5940,
23713,
402,
4145,
4079,
641,
1177,
2004,
436,
3404,
13,
6635,
3517,
1947,
624,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
12,
18094,
304,
267,
340,
1056,
14,
2024,
14,
362,
360,
18671,
63,
4876,
297,
756,
304,
288,
372,
1177,
398,
340,
1056,
14,
765,
508,
283,
5211,
356,
288,
340,
1177,
14,
1205,
315,
359,
8507,
12,
11485,
12,
25989,
12,
26959,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
355,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
355,
20884,
275,
1056,
14,
1814,
8,
633,
29,
264,
12080,
63,
633,
9,
355,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
288,
587,
26,
355,
372,
1177,
398,
340,
1177,
14,
1205,
315,
359,
8551,
12,
25989,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
288,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
288,
20884,
275,
291,
423,
4876,
63,
1069,
63,
4941,
63,
362,
8,
1069,
12,
20884,
63,
633,
9,
288,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
398,
340,
1177,
14,
1205,
315,
359,
8507,
12,
26959,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
288,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
288,
20884,
275,
1056,
14,
1814,
8,
633,
29,
264,
12080,
63,
633,
9,
288,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
398,
372,
1177,
421,
199,
533,
6288,
18730,
6608,
8,
1563,
7071,
6608,
304,
339,
5223,
63,
6031,
275,
283,
3940,
8693,
38,
15098,
63,
15704,
7,
339,
347,
636,
826,
721,
277,
12,
2202,
304,
267,
1613,
8,
3396,
18730,
6608,
12,
291,
2843,
826,
721,
1751,
9,
267,
291,
423,
988,
5814,
275,
2202,
14,
26627,
360,
19747,
63,
4283,
63,
3940,
8693,
38,
15098,
63,
18616,
297,
1460,
2202,
14,
26627,
360,
3940,
8693,
38,
15098,
63,
4283,
18616,
1333,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
12,
18094,
304,
267,
340,
1056,
14,
2024,
14,
362,
360,
18671,
63,
4876,
297,
756,
9,
503,
1056,
14,
765,
508,
283,
5211,
7,
503,
971,
355,
440,
1228,
8,
1310,
12,
20880,
2364,
304,
288,
372,
1177,
398,
340,
1228,
8,
1310,
12,
20880,
2364,
304,
288,
6252,
12,
1166,
275,
664,
63,
2024,
63,
6635,
8,
1310,
9,
288,
340,
1166,
436,
6252,
665,
291,
423,
988,
5814,
26,
355,
20884,
275,
291,
423,
4876,
63,
1069,
63,
4941,
63,
362,
8,
1069,
12,
1166,
9,
355,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
283,
2024,
9236,
358,
398,
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
] |
[
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
199,
504,
18918,
492,
943,
199,
504,
18918,
14,
1014,
492,
20880,
2364,
199,
504,
18918,
14,
1208,
14,
1310,
492,
664,
63,
2024,
63,
6635,
199,
504,
18918,
14,
3924,
492,
14092,
2017,
12,
2832,
9902,
421,
199,
533,
3523,
7071,
6608,
8,
785,
304,
339,
5223,
63,
6031,
275,
283,
19747,
63,
15704,
7,
339,
347,
636,
826,
721,
277,
12,
2202,
304,
267,
340,
440,
2202,
14,
362,
2245,
8,
277,
14,
3827,
63,
6031,
304,
288,
746,
2832,
9902,
398,
291,
14,
988,
63,
4876,
63,
4508,
275,
2202,
14,
26627,
360,
19747,
63,
4283,
63,
11342,
654,
358,
267,
291,
14,
6693,
63,
10917,
275,
2202,
14,
26627,
360,
19747,
63,
25144,
63,
1554,
42,
7698,
358,
339,
768,
3744,
272,
347,
687,
63,
23972,
8,
1886,
12,
29550,
304,
267,
372,
843,
8,
23972,
14,
1751,
9,
339,
347,
485,
4876,
8,
277,
12,
20884,
12,
1056,
12,
18094,
12,
4499,
304,
267,
14856,
275,
1056,
14,
2024,
14,
5486,
360,
4876,
63,
12130,
297,
291,
14,
988,
63,
4876,
63,
4508,
9,
267,
17784,
275,
1056,
14,
2024,
14,
362,
360,
4876,
63,
4508,
297,
378,
9,
435,
413,
398,
340,
14856,
436,
17784,
2695,
291,
14,
988,
63,
4876,
63,
4508,
26,
288,
20884,
14,
2024,
459,
4876,
63,
4508,
418,
275,
17784,
288,
20884,
14,
2024,
459,
4876,
63,
12130,
418,
275,
14856,
446,
413,
288,
20884,
14,
2024,
459,
4876,
63,
3603,
418,
275,
1056,
14,
2024,
14,
362,
360,
4876,
63,
3603,
297,
3073,
435,
971,
355,
359,
1069,
14,
633,
61,
288,
20884,
14,
18671,
63,
1541,
275,
1056,
14,
18671,
63,
1541,
288,
20884,
14,
6693,
275,
1056,
14,
6693,
435,
291,
14,
6693,
63,
10917,
288,
943,
14,
1328,
8,
908,
628,
7071,
316,
17753,
5764,
9,
83,
9,
370,
2818,
264,
12080,
9,
83,
687,
2818,
1069,
9,
83,
401,
490,
2166,
29,
793,
14,
5287,
12,
18094,
29,
12856,
12,
1056,
29,
1069,
12,
490,
20884,
29,
264,
12080,
12,
4499,
29,
5764,
9,
288,
372,
20884,
267,
587,
26,
288,
943,
14,
1328,
8,
908,
628,
2825,
5841,
316,
2818,
1069,
9,
83,
26,
1390,
295,
27917,
13075,
401,
490,
2166,
29,
793,
14,
5287,
12,
18094,
29,
12856,
12,
1056,
29,
1069,
9,
288,
746,
14092,
2017,
480,
988,
295,
27917,
13075,
531,
339,
347,
485,
4876,
63,
1069,
63,
4941,
63,
362,
8,
277,
12,
1056,
12,
4660,
63,
633,
304,
267,
20884,
275,
1056,
14,
1814,
8,
633,
29,
4876,
63,
633,
12,
1083,
534,
2970,
297,
2396,
13275,
267,
20884,
14,
2139,
14,
1935,
360,
2714,
13,
804,
297,
488,
9,
267,
20884,
14,
2139,
14,
1935,
360,
2714,
13,
4625,
297,
488,
9,
267,
372,
20884,
421,
199,
533,
18532,
6608,
8,
1563,
7071,
6608,
304,
272,
408,
5940,
23713,
402,
4145,
4079,
641,
1177,
2004,
436,
3404,
13,
6635,
3517,
1947,
624,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
12,
18094,
304,
267,
340,
1056,
14,
2024,
14,
362,
360,
18671,
63,
4876,
297,
756,
304,
288,
372,
1177,
398,
340,
1056,
14,
765,
508,
283,
5211,
356,
288,
340,
1177,
14,
1205,
315,
359,
8507,
12,
11485,
12,
25989,
12,
26959,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
355,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
355,
20884,
275,
1056,
14,
1814,
8,
633,
29,
264,
12080,
63,
633,
9,
355,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
288,
587,
26,
355,
372,
1177,
398,
340,
1177,
14,
1205,
315,
359,
8551,
12,
25989,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
288,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
288,
20884,
275,
291,
423,
4876,
63,
1069,
63,
4941,
63,
362,
8,
1069,
12,
20884,
63,
633,
9,
288,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
398,
340,
1177,
14,
1205,
315,
359,
8507,
12,
26959,
61,
436,
283,
6592,
7,
315,
1177,
14,
2139,
26,
288,
20884,
63,
633,
275,
20818,
8,
1069,
14,
633,
12,
1177,
14,
2139,
459,
1985,
1105,
288,
20884,
275,
1056,
14,
1814,
8,
633,
29,
264,
12080,
63,
633,
9,
288,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
1177,
14,
1205,
9,
398,
372,
1177,
421,
199,
533,
6288,
18730,
6608,
8,
1563,
7071,
6608,
304,
339,
5223,
63,
6031,
275,
283,
3940,
8693,
38,
15098,
63,
15704,
7,
339,
347,
636,
826,
721,
277,
12,
2202,
304,
267,
1613,
8,
3396,
18730,
6608,
12,
291,
2843,
826,
721,
1751,
9,
267,
291,
423,
988,
5814,
275,
2202,
14,
26627,
360,
19747,
63,
4283,
63,
3940,
8693,
38,
15098,
63,
18616,
297,
1460,
2202,
14,
26627,
360,
3940,
8693,
38,
15098,
63,
4283,
18616,
1333,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
12,
18094,
304,
267,
340,
1056,
14,
2024,
14,
362,
360,
18671,
63,
4876,
297,
756,
9,
503,
1056,
14,
765,
508,
283,
5211,
7,
503,
971,
355,
440,
1228,
8,
1310,
12,
20880,
2364,
304,
288,
372,
1177,
398,
340,
1228,
8,
1310,
12,
20880,
2364,
304,
288,
6252,
12,
1166,
275,
664,
63,
2024,
63,
6635,
8,
1310,
9,
288,
340,
1166,
436,
6252,
665,
291,
423,
988,
5814,
26,
355,
20884,
275,
291,
423,
4876,
63,
1069,
63,
4941,
63,
362,
8,
1069,
12,
1166,
9,
355,
372,
291,
423,
4876,
8,
264,
12080,
12,
1056,
12,
18094,
12,
283,
2024,
9236,
358,
398,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hiikezoe/android_kernel_asus_tf300t
|
tools/perf/scripts/python/syscall-counts.py
|
11181
|
1522
|
# system call counts
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts.py [comm]\n";
for_comm = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
print "%-40s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kaiweifan/vse-lbaas-plugin-poc
|
quantum/tests/unit/linuxbridge/test_linuxbridge_plugin.py
|
5
|
2464
|
# Copyright (c) 2012 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from quantum.extensions import portbindings
from quantum.tests.unit import _test_extension_portbindings as test_bindings
from quantum.tests.unit import test_db_plugin as test_plugin
from quantum.tests.unit import test_security_groups_rpc as test_sg_rpc
PLUGIN_NAME = ('quantum.plugins.linuxbridge.'
'lb_quantum_plugin.LinuxBridgePluginV2')
class LinuxBridgePluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase):
_plugin_name = PLUGIN_NAME
def setUp(self):
super(LinuxBridgePluginV2TestCase, self).setUp(PLUGIN_NAME)
self.port_create_status = 'DOWN'
class TestLinuxBridgeBasicGet(test_plugin.TestBasicGet,
LinuxBridgePluginV2TestCase):
pass
class TestLinuxBridgeV2HTTPResponse(test_plugin.TestV2HTTPResponse,
LinuxBridgePluginV2TestCase):
pass
class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
LinuxBridgePluginV2TestCase):
pass
class TestLinuxBridgePortsV2(test_plugin.TestPortsV2,
LinuxBridgePluginV2TestCase):
def test_update_port_status_build(self):
with self.port() as port:
self.assertEqual(port['port']['status'], 'DOWN')
self.assertEqual(self.port_create_status, 'DOWN')
class TestLinuxBridgePortBinding(LinuxBridgePluginV2TestCase,
test_bindings.PortBindingsTestCase):
VIF_TYPE = portbindings.VIF_TYPE_BRIDGE
HAS_PORT_FILTER = True
FIREWALL_DRIVER = test_sg_rpc.FIREWALL_IPTABLES_DRIVER
def setUp(self):
test_sg_rpc.set_firewall_driver(self.FIREWALL_DRIVER)
super(TestLinuxBridgePortBinding, self).setUp()
class TestLinuxBridgePortBindingNoSG(TestLinuxBridgePortBinding):
HAS_PORT_FILTER = False
FIREWALL_DRIVER = test_sg_rpc.FIREWALL_NOOP_DRIVER
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6029,
14260,
2752,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
15381,
453,
14,
5359,
492,
1844,
10880,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
485,
396,
63,
3435,
63,
719,
10880,
465,
511,
63,
10880,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
511,
63,
697,
63,
2718,
465,
511,
63,
2718,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
511,
63,
4416,
63,
2634,
63,
4354,
465,
511,
63,
1226,
63,
4354,
421,
199,
19108,
63,
2339,
275,
661,
25999,
14,
5265,
14,
472,
85,
1774,
5562,
3530,
2049,
283,
6374,
63,
25999,
63,
2718,
14,
14091,
14491,
5061,
54,
18,
358,
421,
199,
533,
10130,
14491,
5061,
54,
18,
1746,
8,
396,
63,
2718,
14,
2371,
867,
453,
8882,
5061,
54,
18,
1746,
304,
272,
485,
2718,
63,
354,
275,
10092,
10134,
568,
63,
2339,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14091,
14491,
5061,
54,
18,
1746,
12,
291,
680,
5996,
8,
19108,
63,
2339,
9,
267,
291,
14,
719,
63,
981,
63,
1205,
275,
283,
8819,
7,
421,
199,
533,
1379,
14091,
14491,
6845,
1002,
8,
396,
63,
2718,
14,
774,
6845,
1002,
12,
2892,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
54,
18,
27068,
8,
396,
63,
2718,
14,
774,
54,
18,
27068,
12,
2511,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
30551,
54,
18,
8,
396,
63,
2718,
14,
774,
30551,
54,
18,
12,
1816,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
25573,
54,
18,
8,
396,
63,
2718,
14,
774,
25573,
54,
18,
12,
2490,
10130,
14491,
5061,
54,
18,
1746,
304,
339,
347,
511,
63,
873,
63,
719,
63,
1205,
63,
1506,
8,
277,
304,
267,
543,
291,
14,
719,
342,
465,
1844,
26,
288,
291,
14,
629,
8,
719,
459,
719,
2545,
1205,
995,
283,
8819,
358,
288,
291,
14,
629,
8,
277,
14,
719,
63,
981,
63,
1205,
12,
283,
8819,
358,
421,
199,
533,
1379,
14091,
14491,
4313,
17490,
8,
14091,
14491,
5061,
54,
18,
1746,
12,
639,
511,
63,
10880,
14,
4313,
8198,
780,
1746,
304,
272,
812,
4656,
63,
2711,
275,
1844,
10880,
14,
27890,
63,
2711,
63,
7184,
998,
4962,
272,
7509,
63,
3657,
63,
9905,
275,
715,
272,
15435,
907,
55,
1761,
63,
23401,
275,
511,
63,
1226,
63,
4354,
14,
1976,
907,
55,
1761,
63,
4385,
17041,
63,
23401,
339,
347,
3613,
8,
277,
304,
267,
511,
63,
1226,
63,
4354,
14,
409,
63,
10794,
63,
3090,
8,
277,
14,
1976,
907,
55,
1761,
63,
23401,
9,
267,
1613,
8,
774,
14091,
14491,
4313,
17490,
12,
291,
680,
5996,
342,
421,
199,
533,
1379,
14091,
14491,
4313,
17490,
1944,
4254,
8,
774,
14091,
14491,
4313,
17490,
304,
272,
7509,
63,
3657,
63,
9905,
275,
756,
272,
15435,
907,
55,
1761,
63,
23401,
275,
511,
63,
1226,
63,
4354,
14,
1976,
907,
55,
1761,
63,
2826,
1938,
63,
23401,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6029,
14260,
2752,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
15381,
453,
14,
5359,
492,
1844,
10880,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
485,
396,
63,
3435,
63,
719,
10880,
465,
511,
63,
10880,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
511,
63,
697,
63,
2718,
465,
511,
63,
2718,
199,
504,
15381,
453,
14,
2219,
14,
3248,
492,
511,
63,
4416,
63,
2634,
63,
4354,
465,
511,
63,
1226,
63,
4354,
421,
199,
19108,
63,
2339,
275,
661,
25999,
14,
5265,
14,
472,
85,
1774,
5562,
3530,
2049,
283,
6374,
63,
25999,
63,
2718,
14,
14091,
14491,
5061,
54,
18,
358,
421,
199,
533,
10130,
14491,
5061,
54,
18,
1746,
8,
396,
63,
2718,
14,
2371,
867,
453,
8882,
5061,
54,
18,
1746,
304,
272,
485,
2718,
63,
354,
275,
10092,
10134,
568,
63,
2339,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14091,
14491,
5061,
54,
18,
1746,
12,
291,
680,
5996,
8,
19108,
63,
2339,
9,
267,
291,
14,
719,
63,
981,
63,
1205,
275,
283,
8819,
7,
421,
199,
533,
1379,
14091,
14491,
6845,
1002,
8,
396,
63,
2718,
14,
774,
6845,
1002,
12,
2892,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
54,
18,
27068,
8,
396,
63,
2718,
14,
774,
54,
18,
27068,
12,
2511,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
30551,
54,
18,
8,
396,
63,
2718,
14,
774,
30551,
54,
18,
12,
1816,
10130,
14491,
5061,
54,
18,
1746,
304,
272,
986,
421,
199,
533,
1379,
14091,
14491,
25573,
54,
18,
8,
396,
63,
2718,
14,
774,
25573,
54,
18,
12,
2490,
10130,
14491,
5061,
54,
18,
1746,
304,
339,
347,
511,
63,
873,
63,
719,
63,
1205,
63,
1506,
8,
277,
304,
267,
543,
291,
14,
719,
342,
465,
1844,
26,
288,
291,
14,
629,
8,
719,
459,
719,
2545,
1205,
995,
283,
8819,
358,
288,
291,
14,
629,
8,
277,
14,
719,
63,
981,
63,
1205,
12,
283,
8819,
358,
421,
199,
533,
1379,
14091,
14491,
4313,
17490,
8,
14091,
14491,
5061,
54,
18,
1746,
12,
639,
511,
63,
10880,
14,
4313,
8198,
780,
1746,
304,
272,
812,
4656,
63,
2711,
275,
1844,
10880,
14,
27890,
63,
2711,
63,
7184,
998,
4962,
272,
7509,
63,
3657,
63,
9905,
275,
715,
272,
15435,
907,
55,
1761,
63,
23401,
275,
511,
63,
1226,
63,
4354,
14,
1976,
907,
55,
1761,
63,
4385,
17041,
63,
23401,
339,
347,
3613,
8,
277,
304,
267,
511,
63,
1226,
63,
4354,
14,
409,
63,
10794,
63,
3090,
8,
277,
14,
1976,
907,
55,
1761,
63,
23401,
9,
267,
1613,
8,
774,
14091,
14491,
4313,
17490,
12,
291,
680,
5996,
342,
421,
199,
533,
1379,
14091,
14491,
4313,
17490,
1944,
4254,
8,
774,
14091,
14491,
4313,
17490,
304,
272,
7509,
63,
3657,
63,
9905,
275,
756,
272,
15435,
907,
55,
1761,
63,
23401,
275,
511,
63,
1226,
63,
4354,
14,
1976,
907,
55,
1761,
63,
2826,
1938,
63,
23401,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
Ryanglambert/pybrain
|
pybrain/tests/unittests/structure/modules/test_simple_mdlstm.py
|
25
|
2009
|
"""
Build a simple mdlstm network with peepholes:
>>> n = buildSimpleMDLSTMNetwork(True)
>>> print(n)
simpleMDLstmNet
Modules:
[<BiasUnit 'bias'>, <LinearLayer 'i'>, <MDLSTMLayer 'MDlstm'>, <LinearLayer 'o'>]
Connections:
[<FullConnection 'f1': 'i' -> 'MDlstm'>, <FullConnection 'f2': 'bias' -> 'MDlstm'>, <FullConnection 'f3': 'MDlstm' -> 'o'>]
Recurrent Connections:
[<FullConnection 'r1': 'MDlstm' -> 'MDlstm'>, <IdentityConnection 'rstate': 'MDlstm' -> 'MDlstm'>]
Check its gradient:
>>> from pybrain.tests import gradientCheck
>>> gradientCheck(n)
Perfect gradient
True
Try writing it to an xml file, reread it and determine if it looks the same:
>>> from pybrain.tests import xmlInvariance
>>> xmlInvariance(n)
Same representation
Same function
Same class
"""
__author__ = 'Tom Schaul, tom@idsia.ch'
from pybrain.structure.networks.recurrent import RecurrentNetwork
from pybrain import LinearLayer, FullConnection, MDLSTMLayer, BiasUnit, IdentityConnection
from pybrain.tests import runModuleTestSuite
def buildSimpleMDLSTMNetwork(peepholes = False):
N = RecurrentNetwork('simpleMDLstmNet')
i = LinearLayer(1, name = 'i')
dim = 1
h = MDLSTMLayer(dim, peepholes = peepholes, name = 'MDlstm')
o = LinearLayer(1, name = 'o')
b = BiasUnit('bias')
N.addModule(b)
N.addOutputModule(o)
N.addInputModule(i)
N.addModule(h)
N.addConnection(FullConnection(i, h, outSliceTo = 4*dim, name = 'f1'))
N.addConnection(FullConnection(b, h, outSliceTo = 4*dim, name = 'f2'))
N.addRecurrentConnection(FullConnection(h, h, inSliceTo = dim, outSliceTo = 4*dim, name = 'r1'))
N.addRecurrentConnection(IdentityConnection(h, h, inSliceFrom = dim, outSliceFrom = 4*dim, name = 'rstate'))
N.addConnection(FullConnection(h, o, inSliceTo = dim, name = 'f3'))
N.sortModules()
return N
if __name__ == "__main__":
runModuleTestSuite(__import__('__main__'))
|
bsd-3-clause
|
[
624,
199,
199,
3425,
282,
3486,
333,
5030,
270,
77,
2784,
543,
299,
7840,
31110,
26,
272,
1306,
302,
275,
1900,
3184,
5127,
28576,
4491,
8,
549,
9,
272,
1306,
870,
8,
78,
9,
272,
3486,
5127,
30525,
77,
2480,
2126,
18167,
26,
267,
24936,
34,
2241,
5072,
283,
8160,
7,
6244,
665,
10608,
5003,
283,
73,
7,
6244,
665,
5127,
29805,
1698,
1187,
281,
283,
5127,
26652,
7,
6244,
665,
10608,
5003,
283,
79,
8423,
61,
2126,
8113,
83,
26,
267,
24936,
9042,
3225,
283,
70,
17,
356,
283,
73,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
9042,
3225,
283,
70,
18,
356,
283,
8160,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
9042,
3225,
283,
70,
19,
356,
283,
5127,
26652,
7,
1035,
283,
79,
8423,
61,
2126,
799,
1818,
8113,
83,
26,
267,
24936,
9042,
3225,
283,
82,
17,
356,
283,
5127,
26652,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
10193,
3225,
283,
82,
929,
356,
283,
5127,
26652,
7,
1035,
283,
5127,
26652,
8423,
61,
199,
199,
1799,
2399,
6709,
26,
339,
1306,
687,
1134,
22246,
14,
2219,
492,
6709,
1799,
272,
1306,
6709,
1799,
8,
78,
9,
272,
31778,
449,
6709,
272,
715,
199,
199,
12357,
3575,
652,
370,
376,
2748,
570,
12,
295,
739,
652,
436,
6705,
340,
652,
10734,
314,
2011,
26,
339,
1306,
687,
1134,
22246,
14,
2219,
492,
2748,
607,
6221,
272,
1306,
2748,
607,
6221,
8,
78,
9,
272,
14766,
6025,
272,
14766,
805,
272,
14766,
1021,
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,
6976,
14,
7642,
14,
31897,
492,
799,
1818,
4491,
199,
504,
1134,
22246,
492,
12489,
5003,
12,
16579,
3225,
12,
603,
8045,
840,
1698,
1187,
281,
12,
699,
2241,
5072,
12,
22034,
3225,
199,
504,
1134,
22246,
14,
2219,
492,
1255,
2377,
10591,
421,
199,
318,
1900,
3184,
5127,
28576,
4491,
8,
321,
1545,
31110,
275,
756,
304,
272,
653,
275,
799,
1818,
4491,
360,
4129,
5127,
30525,
77,
2480,
358,
272,
284,
275,
12489,
5003,
8,
17,
12,
536,
275,
283,
73,
358,
272,
8134,
275,
413,
272,
394,
275,
603,
8045,
840,
1698,
1187,
281,
8,
3572,
12,
299,
7840,
31110,
275,
299,
7840,
31110,
12,
536,
275,
283,
5127,
26652,
358,
272,
312,
275,
12489,
5003,
8,
17,
12,
536,
275,
283,
79,
358,
272,
330,
275,
699,
2241,
5072,
360,
8160,
358,
272,
653,
14,
525,
2377,
8,
66,
9,
272,
653,
14,
525,
2959,
2377,
8,
79,
9,
272,
653,
14,
525,
3205,
2377,
8,
73,
9,
272,
653,
14,
525,
2377,
8,
72,
9,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
73,
12,
394,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
70,
17,
1333,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
66,
12,
394,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
70,
18,
1333,
272,
653,
14,
525,
497,
1818,
3225,
8,
9042,
3225,
8,
72,
12,
394,
12,
315,
14034,
1378,
275,
8134,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
82,
17,
1333,
272,
653,
14,
525,
497,
1818,
3225,
8,
10193,
3225,
8,
72,
12,
394,
12,
315,
14034,
2532,
275,
8134,
12,
734,
14034,
2532,
275,
841,
10,
3572,
12,
536,
275,
283,
82,
929,
1333,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
72,
12,
312,
12,
315,
14034,
1378,
275,
8134,
12,
536,
275,
283,
70,
19,
1333,
272,
653,
14,
3191,
17981,
342,
272,
372,
653,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
2377,
10591,
3460,
646,
363,
10714,
973,
363,
1333,
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
] |
[
199,
199,
3425,
282,
3486,
333,
5030,
270,
77,
2784,
543,
299,
7840,
31110,
26,
272,
1306,
302,
275,
1900,
3184,
5127,
28576,
4491,
8,
549,
9,
272,
1306,
870,
8,
78,
9,
272,
3486,
5127,
30525,
77,
2480,
2126,
18167,
26,
267,
24936,
34,
2241,
5072,
283,
8160,
7,
6244,
665,
10608,
5003,
283,
73,
7,
6244,
665,
5127,
29805,
1698,
1187,
281,
283,
5127,
26652,
7,
6244,
665,
10608,
5003,
283,
79,
8423,
61,
2126,
8113,
83,
26,
267,
24936,
9042,
3225,
283,
70,
17,
356,
283,
73,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
9042,
3225,
283,
70,
18,
356,
283,
8160,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
9042,
3225,
283,
70,
19,
356,
283,
5127,
26652,
7,
1035,
283,
79,
8423,
61,
2126,
799,
1818,
8113,
83,
26,
267,
24936,
9042,
3225,
283,
82,
17,
356,
283,
5127,
26652,
7,
1035,
283,
5127,
26652,
7,
6244,
665,
10193,
3225,
283,
82,
929,
356,
283,
5127,
26652,
7,
1035,
283,
5127,
26652,
8423,
61,
199,
199,
1799,
2399,
6709,
26,
339,
1306,
687,
1134,
22246,
14,
2219,
492,
6709,
1799,
272,
1306,
6709,
1799,
8,
78,
9,
272,
31778,
449,
6709,
272,
715,
199,
199,
12357,
3575,
652,
370,
376,
2748,
570,
12,
295,
739,
652,
436,
6705,
340,
652,
10734,
314,
2011,
26,
339,
1306,
687,
1134,
22246,
14,
2219,
492,
2748,
607,
6221,
272,
1306,
2748,
607,
6221,
8,
78,
9,
272,
14766,
6025,
272,
14766,
805,
272,
14766,
1021,
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,
6976,
14,
7642,
14,
31897,
492,
799,
1818,
4491,
199,
504,
1134,
22246,
492,
12489,
5003,
12,
16579,
3225,
12,
603,
8045,
840,
1698,
1187,
281,
12,
699,
2241,
5072,
12,
22034,
3225,
199,
504,
1134,
22246,
14,
2219,
492,
1255,
2377,
10591,
421,
199,
318,
1900,
3184,
5127,
28576,
4491,
8,
321,
1545,
31110,
275,
756,
304,
272,
653,
275,
799,
1818,
4491,
360,
4129,
5127,
30525,
77,
2480,
358,
272,
284,
275,
12489,
5003,
8,
17,
12,
536,
275,
283,
73,
358,
272,
8134,
275,
413,
272,
394,
275,
603,
8045,
840,
1698,
1187,
281,
8,
3572,
12,
299,
7840,
31110,
275,
299,
7840,
31110,
12,
536,
275,
283,
5127,
26652,
358,
272,
312,
275,
12489,
5003,
8,
17,
12,
536,
275,
283,
79,
358,
272,
330,
275,
699,
2241,
5072,
360,
8160,
358,
272,
653,
14,
525,
2377,
8,
66,
9,
272,
653,
14,
525,
2959,
2377,
8,
79,
9,
272,
653,
14,
525,
3205,
2377,
8,
73,
9,
272,
653,
14,
525,
2377,
8,
72,
9,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
73,
12,
394,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
70,
17,
1333,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
66,
12,
394,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
70,
18,
1333,
272,
653,
14,
525,
497,
1818,
3225,
8,
9042,
3225,
8,
72,
12,
394,
12,
315,
14034,
1378,
275,
8134,
12,
734,
14034,
1378,
275,
841,
10,
3572,
12,
536,
275,
283,
82,
17,
1333,
272,
653,
14,
525,
497,
1818,
3225,
8,
10193,
3225,
8,
72,
12,
394,
12,
315,
14034,
2532,
275,
8134,
12,
734,
14034,
2532,
275,
841,
10,
3572,
12,
536,
275,
283,
82,
929,
1333,
272,
653,
14,
525,
3225,
8,
9042,
3225,
8,
72,
12,
312,
12,
315,
14034,
1378,
275,
8134,
12,
536,
275,
283,
70,
19,
1333,
272,
653,
14,
3191,
17981,
342,
272,
372,
653,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
2377,
10591,
3460,
646,
363,
10714,
973,
363,
1333,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import shutil
import fixtures
from tempest.cmd import init
from tempest.tests.lib import base
class TestTempestInit(base.TestCase):
def test_generate_testr_conf(self):
# Create fake conf dir
conf_dir = self.useFixture(fixtures.TempDir())
init_cmd = init.TempestInit(None, None)
init_cmd.generate_testr_conf(conf_dir.path)
# Generate expected file contents
top_level_path = os.path.dirname(os.path.dirname(init.__file__))
discover_path = os.path.join(top_level_path, 'test_discover')
testr_conf_file = init.TESTR_CONF % (top_level_path, discover_path)
conf_path = conf_dir.join('.testr.conf')
with open(conf_path, 'r') as conf_file:
self.assertEqual(conf_file.read(), testr_conf_file)
def test_generate_sample_config(self):
local_dir = self.useFixture(fixtures.TempDir())
etc_dir_path = os.path.join(local_dir.path, 'etc/')
os.mkdir(etc_dir_path)
tmp_dir = self.useFixture(fixtures.TempDir())
config_dir = os.path.join(tmp_dir.path, 'config/')
shutil.copytree('etc/', config_dir)
init_cmd = init.TempestInit(None, None)
local_sample_conf_file = os.path.join(etc_dir_path,
'tempest.conf.sample')
# Verify no sample config file exist
self.assertFalse(os.path.isfile(local_sample_conf_file))
init_cmd.generate_sample_config(local_dir.path, config_dir)
# Verify sample config file exist with some content
self.assertTrue(os.path.isfile(local_sample_conf_file))
self.assertGreater(os.path.getsize(local_sample_conf_file), 0)
def test_create_working_dir_with_existing_local_dir_non_empty(self):
fake_local_dir = self.useFixture(fixtures.TempDir())
fake_local_conf_dir = self.useFixture(fixtures.TempDir())
open("%s/foo" % fake_local_dir.path, 'w').close()
_init = init.TempestInit(None, None)
self.assertRaises(OSError,
_init.create_working_dir,
fake_local_dir.path,
fake_local_conf_dir.path)
def test_create_working_dir(self):
fake_local_dir = self.useFixture(fixtures.TempDir())
fake_local_conf_dir = self.useFixture(fixtures.TempDir())
os.rmdir(fake_local_dir.path)
# Create a fake conf file
fake_file = fake_local_conf_dir.join('conf_file.conf')
open(fake_file, 'w').close()
init_cmd = init.TempestInit(None, None)
init_cmd.create_working_dir(fake_local_dir.path,
fake_local_conf_dir.path)
# Assert directories are created
lock_path = os.path.join(fake_local_dir.path, 'tempest_lock')
etc_dir = os.path.join(fake_local_dir.path, 'etc')
log_dir = os.path.join(fake_local_dir.path, 'logs')
testr_dir = os.path.join(fake_local_dir.path, '.testrepository')
self.assertTrue(os.path.isdir(lock_path))
self.assertTrue(os.path.isdir(etc_dir))
self.assertTrue(os.path.isdir(log_dir))
self.assertTrue(os.path.isdir(testr_dir))
# Assert file creation
fake_file_moved = os.path.join(etc_dir, 'conf_file.conf')
local_conf_file = os.path.join(etc_dir, 'tempest.conf')
local_testr_conf = os.path.join(fake_local_dir.path, '.testr.conf')
self.assertTrue(os.path.isfile(fake_file_moved))
self.assertTrue(os.path.isfile(local_conf_file))
self.assertTrue(os.path.isfile(local_testr_conf))
|
apache-2.0
|
[
3,
1898,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
5145,
199,
199,
646,
15188,
199,
199,
504,
24076,
14,
1760,
492,
4205,
199,
504,
24076,
14,
2219,
14,
773,
492,
1300,
421,
199,
533,
1379,
6530,
597,
9346,
8,
1095,
14,
1746,
304,
339,
347,
511,
63,
4208,
63,
28792,
63,
2190,
8,
277,
304,
267,
327,
2790,
4026,
3743,
2935,
267,
3743,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
398,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
4205,
63,
1760,
14,
4208,
63,
28792,
63,
2190,
8,
2190,
63,
694,
14,
515,
9,
398,
327,
7958,
1420,
570,
4072,
267,
2746,
63,
1896,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
826,
855,
493,
8964,
267,
20131,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2119,
63,
1896,
63,
515,
12,
283,
396,
63,
18861,
358,
267,
511,
82,
63,
2190,
63,
493,
275,
4205,
14,
2864,
50,
63,
3103,
450,
334,
2119,
63,
1896,
63,
515,
12,
20131,
63,
515,
9,
398,
3743,
63,
515,
275,
3743,
63,
694,
14,
904,
5175,
28792,
14,
2190,
358,
267,
543,
1551,
8,
2190,
63,
515,
12,
283,
82,
358,
465,
3743,
63,
493,
26,
288,
291,
14,
629,
8,
2190,
63,
493,
14,
739,
1062,
511,
82,
63,
2190,
63,
493,
9,
339,
347,
511,
63,
4208,
63,
3271,
63,
888,
8,
277,
304,
267,
2257,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
5423,
63,
694,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1832,
63,
694,
14,
515,
12,
283,
6839,
6217,
267,
747,
14,
8215,
8,
6839,
63,
694,
63,
515,
9,
267,
3529,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
1101,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
14,
515,
12,
283,
888,
6217,
267,
5145,
14,
29296,
360,
6839,
3678,
1101,
63,
694,
9,
267,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
2257,
63,
3271,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
6839,
63,
694,
63,
515,
12,
6343,
283,
808,
597,
14,
2190,
14,
3271,
358,
267,
327,
7635,
949,
2690,
1101,
570,
2187,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
6292,
8,
1832,
63,
3271,
63,
2190,
63,
493,
430,
267,
4205,
63,
1760,
14,
4208,
63,
3271,
63,
888,
8,
1832,
63,
694,
14,
515,
12,
1101,
63,
694,
9,
398,
327,
7635,
2690,
1101,
570,
2187,
543,
2005,
1564,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
6292,
8,
1832,
63,
3271,
63,
2190,
63,
493,
430,
267,
291,
14,
15070,
8,
736,
14,
515,
14,
20733,
8,
1832,
63,
3271,
63,
2190,
63,
493,
395,
378,
9,
339,
347,
511,
63,
981,
63,
9818,
63,
694,
63,
1045,
63,
5952,
63,
1832,
63,
694,
63,
2865,
63,
1667,
8,
277,
304,
267,
4026,
63,
1832,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
4026,
63,
1832,
63,
2190,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
1551,
3647,
83,
15,
1421,
2,
450,
4026,
63,
1832,
63,
694,
14,
515,
12,
283,
87,
1959,
1600,
342,
398,
485,
826,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
291,
14,
1855,
8,
16719,
12,
2079,
485,
826,
14,
981,
63,
9818,
63,
694,
12,
2079,
4026,
63,
1832,
63,
694,
14,
515,
12,
2079,
4026,
63,
1832,
63,
2190,
63,
694,
14,
515,
9,
339,
347,
511,
63,
981,
63,
9818,
63,
694,
8,
277,
304,
267,
4026,
63,
1832,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
4026,
63,
1832,
63,
2190,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
747,
14,
19405,
8,
3183,
63,
1832,
63,
694,
14,
515,
9,
267,
327,
2790,
282,
4026,
3743,
570,
267,
4026,
63,
493,
275,
4026,
63,
1832,
63,
2190,
63,
694,
14,
904,
360,
2190,
63,
493,
14,
2190,
358,
267,
1551,
8,
3183,
63,
493,
12,
283,
87,
1959,
1600,
342,
267,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
4205,
63,
1760,
14,
981,
63,
9818,
63,
694,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
2511,
4026,
63,
1832,
63,
2190,
63,
694,
14,
515,
9,
267,
327,
10716,
6602,
787,
2737,
267,
4650,
63,
515,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
808,
597,
63,
831,
358,
267,
5423,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
6839,
358,
267,
943,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
7270,
358,
267,
511,
82,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
1987,
396,
8421,
358,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
6027,
8,
831,
63,
515,
430,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
6027,
8,
6839,
63,
694,
430,
267,
291,
14,
1815,
8,
736,
14
] |
[
1898,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
5145,
199,
199,
646,
15188,
199,
199,
504,
24076,
14,
1760,
492,
4205,
199,
504,
24076,
14,
2219,
14,
773,
492,
1300,
421,
199,
533,
1379,
6530,
597,
9346,
8,
1095,
14,
1746,
304,
339,
347,
511,
63,
4208,
63,
28792,
63,
2190,
8,
277,
304,
267,
327,
2790,
4026,
3743,
2935,
267,
3743,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
398,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
4205,
63,
1760,
14,
4208,
63,
28792,
63,
2190,
8,
2190,
63,
694,
14,
515,
9,
398,
327,
7958,
1420,
570,
4072,
267,
2746,
63,
1896,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
826,
855,
493,
8964,
267,
20131,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2119,
63,
1896,
63,
515,
12,
283,
396,
63,
18861,
358,
267,
511,
82,
63,
2190,
63,
493,
275,
4205,
14,
2864,
50,
63,
3103,
450,
334,
2119,
63,
1896,
63,
515,
12,
20131,
63,
515,
9,
398,
3743,
63,
515,
275,
3743,
63,
694,
14,
904,
5175,
28792,
14,
2190,
358,
267,
543,
1551,
8,
2190,
63,
515,
12,
283,
82,
358,
465,
3743,
63,
493,
26,
288,
291,
14,
629,
8,
2190,
63,
493,
14,
739,
1062,
511,
82,
63,
2190,
63,
493,
9,
339,
347,
511,
63,
4208,
63,
3271,
63,
888,
8,
277,
304,
267,
2257,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
5423,
63,
694,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1832,
63,
694,
14,
515,
12,
283,
6839,
6217,
267,
747,
14,
8215,
8,
6839,
63,
694,
63,
515,
9,
267,
3529,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
1101,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2791,
63,
694,
14,
515,
12,
283,
888,
6217,
267,
5145,
14,
29296,
360,
6839,
3678,
1101,
63,
694,
9,
267,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
2257,
63,
3271,
63,
2190,
63,
493,
275,
747,
14,
515,
14,
904,
8,
6839,
63,
694,
63,
515,
12,
6343,
283,
808,
597,
14,
2190,
14,
3271,
358,
267,
327,
7635,
949,
2690,
1101,
570,
2187,
267,
291,
14,
3334,
8,
736,
14,
515,
14,
6292,
8,
1832,
63,
3271,
63,
2190,
63,
493,
430,
267,
4205,
63,
1760,
14,
4208,
63,
3271,
63,
888,
8,
1832,
63,
694,
14,
515,
12,
1101,
63,
694,
9,
398,
327,
7635,
2690,
1101,
570,
2187,
543,
2005,
1564,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
6292,
8,
1832,
63,
3271,
63,
2190,
63,
493,
430,
267,
291,
14,
15070,
8,
736,
14,
515,
14,
20733,
8,
1832,
63,
3271,
63,
2190,
63,
493,
395,
378,
9,
339,
347,
511,
63,
981,
63,
9818,
63,
694,
63,
1045,
63,
5952,
63,
1832,
63,
694,
63,
2865,
63,
1667,
8,
277,
304,
267,
4026,
63,
1832,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
4026,
63,
1832,
63,
2190,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
1551,
3647,
83,
15,
1421,
2,
450,
4026,
63,
1832,
63,
694,
14,
515,
12,
283,
87,
1959,
1600,
342,
398,
485,
826,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
291,
14,
1855,
8,
16719,
12,
2079,
485,
826,
14,
981,
63,
9818,
63,
694,
12,
2079,
4026,
63,
1832,
63,
694,
14,
515,
12,
2079,
4026,
63,
1832,
63,
2190,
63,
694,
14,
515,
9,
339,
347,
511,
63,
981,
63,
9818,
63,
694,
8,
277,
304,
267,
4026,
63,
1832,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
4026,
63,
1832,
63,
2190,
63,
694,
275,
291,
14,
31015,
8,
8769,
14,
29008,
1012,
267,
747,
14,
19405,
8,
3183,
63,
1832,
63,
694,
14,
515,
9,
267,
327,
2790,
282,
4026,
3743,
570,
267,
4026,
63,
493,
275,
4026,
63,
1832,
63,
2190,
63,
694,
14,
904,
360,
2190,
63,
493,
14,
2190,
358,
267,
1551,
8,
3183,
63,
493,
12,
283,
87,
1959,
1600,
342,
267,
4205,
63,
1760,
275,
4205,
14,
6530,
597,
9346,
8,
403,
12,
488,
9,
267,
4205,
63,
1760,
14,
981,
63,
9818,
63,
694,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
2511,
4026,
63,
1832,
63,
2190,
63,
694,
14,
515,
9,
267,
327,
10716,
6602,
787,
2737,
267,
4650,
63,
515,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
808,
597,
63,
831,
358,
267,
5423,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
6839,
358,
267,
943,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3183,
63,
1832,
63,
694,
14,
515,
12,
283,
7270,
358,
267,
511,
82,
63,
694,
275,
747,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
zihua/scikit-learn
|
sklearn/model_selection/tests/test_validation.py
|
6
|
30876
|
"""Test the validation module"""
from __future__ import division
import sys
import warnings
import tempfile
import os
from time import sleep
import numpy as np
from scipy.sparse import coo_matrix, csr_matrix
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_false
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_raise_message
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import assert_less
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_warns
from sklearn.utils.mocking import CheckingClassifier, MockDataFrame
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_val_predict
from sklearn.model_selection import permutation_test_score
from sklearn.model_selection import KFold
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import LeaveOneOut
from sklearn.model_selection import LeaveOneGroupOut
from sklearn.model_selection import LeavePGroupsOut
from sklearn.model_selection import GroupKFold
from sklearn.model_selection import GroupShuffleSplit
from sklearn.model_selection import learning_curve
from sklearn.model_selection import validation_curve
from sklearn.model_selection._validation import _check_is_permutation
from sklearn.datasets import make_regression
from sklearn.datasets import load_boston
from sklearn.datasets import load_iris
from sklearn.metrics import explained_variance_score
from sklearn.metrics import make_scorer
from sklearn.metrics import precision_score
from sklearn.linear_model import Ridge, LogisticRegression
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.cluster import KMeans
from sklearn.preprocessing import Imputer
from sklearn.pipeline import Pipeline
from sklearn.externals.six.moves import cStringIO as StringIO
from sklearn.base import BaseEstimator
from sklearn.multiclass import OneVsRestClassifier
from sklearn.utils import shuffle
from sklearn.datasets import make_classification
from sklearn.datasets import make_multilabel_classification
from sklearn.model_selection.tests.test_split import MockClassifier
try:
WindowsError
except NameError:
WindowsError = None
class MockImprovingEstimator(BaseEstimator):
"""Dummy classifier to test the learning curve"""
def __init__(self, n_max_train_sizes):
self.n_max_train_sizes = n_max_train_sizes
self.train_sizes = 0
self.X_subset = None
def fit(self, X_subset, y_subset=None):
self.X_subset = X_subset
self.train_sizes = X_subset.shape[0]
return self
def predict(self, X):
raise NotImplementedError
def score(self, X=None, Y=None):
# training score becomes worse (2 -> 1), test error better (0 -> 1)
if self._is_training_data(X):
return 2. - float(self.train_sizes) / self.n_max_train_sizes
else:
return float(self.train_sizes) / self.n_max_train_sizes
def _is_training_data(self, X):
return X is self.X_subset
class MockIncrementalImprovingEstimator(MockImprovingEstimator):
"""Dummy classifier that provides partial_fit"""
def __init__(self, n_max_train_sizes):
super(MockIncrementalImprovingEstimator,
self).__init__(n_max_train_sizes)
self.x = None
def _is_training_data(self, X):
return self.x in X
def partial_fit(self, X, y=None, **params):
self.train_sizes += X.shape[0]
self.x = X[0]
class MockEstimatorWithParameter(BaseEstimator):
"""Dummy classifier to test the validation curve"""
def __init__(self, param=0.5):
self.X_subset = None
self.param = param
def fit(self, X_subset, y_subset):
self.X_subset = X_subset
self.train_sizes = X_subset.shape[0]
return self
def predict(self, X):
raise NotImplementedError
def score(self, X=None, y=None):
return self.param if self._is_training_data(X) else 1 - self.param
def _is_training_data(self, X):
return X is self.X_subset
# XXX: use 2D array, since 1D X is being detected as a single sample in
# check_consistent_length
X = np.ones((10, 2))
X_sparse = coo_matrix(X)
y = np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4])
# The number of samples per class needs to be > n_splits,
# for StratifiedKFold(n_splits=3)
y2 = np.array([1, 1, 1, 2, 2, 2, 3, 3, 3, 3])
def test_cross_val_score():
clf = MockClassifier()
for a in range(-10, 10):
clf.a = a
# Smoke test
scores = cross_val_score(clf, X, y2)
assert_array_equal(scores, clf.score(X, y2))
# test with multioutput y
multioutput_y = np.column_stack([y2, y2[::-1]])
scores = cross_val_score(clf, X_sparse, multioutput_y)
assert_array_equal(scores, clf.score(X_sparse, multioutput_y))
scores = cross_val_score(clf, X_sparse, y2)
assert_array_equal(scores, clf.score(X_sparse, y2))
# test with multioutput y
scores = cross_val_score(clf, X_sparse, multioutput_y)
assert_array_equal(scores, clf.score(X_sparse, multioutput_y))
# test with X and y as list
list_check = lambda x: isinstance(x, list)
clf = CheckingClassifier(check_X=list_check)
scores = cross_val_score(clf, X.tolist(), y2.tolist())
clf = CheckingClassifier(check_y=list_check)
scores = cross_val_score(clf, X, y2.tolist())
assert_raises(ValueError, cross_val_score, clf, X, y2, scoring="sklearn")
# test with 3d X and
X_3d = X[:, :, np.newaxis]
clf = MockClassifier(allow_nd=True)
scores = cross_val_score(clf, X_3d, y2)
clf = MockClassifier(allow_nd=False)
assert_raises(ValueError, cross_val_score, clf, X_3d, y2)
def test_cross_val_score_predict_groups():
# Check if ValueError (when groups is None) propagates to cross_val_score
# and cross_val_predict
# And also check if groups is correctly passed to the cv object
X, y = make_classification(n_samples=20, n_classes=2, random_state=0)
clf = SVC(kernel="linear")
group_cvs = [LeaveOneGroupOut(), LeavePGroupsOut(2), GroupKFold(),
GroupShuffleSplit()]
for cv in group_cvs:
assert_raise_message(ValueError,
"The groups parameter should not be None",
cross_val_score, estimator=clf, X=X, y=y, cv=cv)
assert_raise_message(ValueError,
"The groups parameter should not be None",
cross_val_predict, estimator=clf, X=X, y=y, cv=cv)
def test_cross_val_score_pandas():
# check cross_val_score doesn't destroy pandas dataframe
types = [(MockDataFrame, MockDataFrame)]
try:
from pandas import Series, DataFrame
types.append((Series, DataFrame))
except ImportError:
pass
for TargetType, InputFeatureType in types:
# X dataframe, y series
# 3 fold cross val is used so we need atleast 3 samples per class
X_df, y_ser = InputFeatureType(X), TargetType(y2)
check_df = lambda x: isinstance(x, InputFeatureType)
check_series = lambda x: isinstance(x, TargetType)
clf = CheckingClassifier(check_X=check_df, check_y=check_series)
cross_val_score(clf, X_df, y_ser)
def test_cross_val_score_mask():
# test that cross_val_score works with boolean masks
svm = SVC(kernel="linear")
iris = load_iris()
X, y = iris.data, iris.target
kfold = KFold(5)
scores_indices = cross_val_score(svm, X, y, cv=kfold)
kfold = KFold(5)
cv_masks = []
for train, test in kfold.split(X, y):
mask_train = np.zeros(len(y), dtype=np.bool)
mask_test = np.zeros(len(y), dtype=np.bool)
mask_train[train] = 1
mask_test[test] = 1
cv_masks.append((train, test))
scores_masks = cross_val_score(svm, X, y, cv=cv_masks)
assert_array_equal(scores_indices, scores_masks)
def test_cross_val_score_precomputed():
# test for svm with precomputed kernel
svm = SVC(kernel="precomputed")
iris = load_iris()
X, y = iris.data, iris.target
linear_kernel = np.dot(X, X.T)
score_precomputed = cross_val_score(svm, linear_kernel, y)
svm = SVC(kernel="linear")
score_linear = cross_val_score(svm, X, y)
assert_array_equal(score_precomputed, score_linear)
# Error raised for non-square X
svm = SVC(kernel="precomputed")
assert_raises(ValueError, cross_val_score, svm, X, y)
# test error is raised when the precomputed kernel is not array-like
# or sparse
assert_raises(ValueError, cross_val_score, svm,
linear_kernel.tolist(), y)
def test_cross_val_score_fit_params():
clf = MockClassifier()
n_samples = X.shape[0]
n_classes = len(np.unique(y))
W_sparse = coo_matrix((np.array([1]), (np.array([1]), np.array([0]))),
shape=(10, 1))
P_sparse = coo_matrix(np.eye(5))
DUMMY_INT = 42
DUMMY_STR = '42'
DUMMY_OBJ = object()
def assert_fit_params(clf):
# Function to test that the values are passed correctly to the
# classifier arguments for non-array type
assert_equal(clf.dummy_int, DUMMY_INT)
assert_equal(clf.dummy_str, DUMMY_STR)
assert_equal(clf.dummy_obj, DUMMY_OBJ)
fit_params = {'sample_weight': np.ones(n_samples),
'class_prior': np.ones(n_classes) / n_classes,
'sparse_sample_weight': W_sparse,
'sparse_param': P_sparse,
'dummy_int': DUMMY_INT,
'dummy_str': DUMMY_STR,
'dummy_obj': DUMMY_OBJ,
'callback': assert_fit_params}
cross_val_score(clf, X, y, fit_params=fit_params)
def test_cross_val_score_score_func():
clf = MockClassifier()
_score_func_args = []
def score_func(y_test, y_predict):
_score_func_args.append((y_test, y_predict))
return 1.0
with warnings.catch_warnings(record=True):
scoring = make_scorer(score_func)
score = cross_val_score(clf, X, y, scoring=scoring)
assert_array_equal(score, [1.0, 1.0, 1.0])
assert len(_score_func_args) == 3
def test_cross_val_score_errors():
class BrokenEstimator:
pass
assert_raises(TypeError, cross_val_score, BrokenEstimator(), X)
def test_cross_val_score_with_score_func_classification():
iris = load_iris()
clf = SVC(kernel='linear')
# Default score (should be the accuracy score)
scores = cross_val_score(clf, iris.data, iris.target, cv=5)
assert_array_almost_equal(scores, [0.97, 1., 0.97, 0.97, 1.], 2)
# Correct classification score (aka. zero / one score) - should be the
# same as the default estimator score
zo_scores = cross_val_score(clf, iris.data, iris.target,
scoring="accuracy", cv=5)
assert_array_almost_equal(zo_scores, [0.97, 1., 0.97, 0.97, 1.], 2)
# F1 score (class are balanced so f1_score should be equal to zero/one
# score
f1_scores = cross_val_score(clf, iris.data, iris.target,
scoring="f1_weighted", cv=5)
assert_array_almost_equal(f1_scores, [0.97, 1., 0.97, 0.97, 1.], 2)
def test_cross_val_score_with_score_func_regression():
X, y = make_regression(n_samples=30, n_features=20, n_informative=5,
random_state=0)
reg = Ridge()
# Default score of the Ridge regression estimator
scores = cross_val_score(reg, X, y, cv=5)
assert_array_almost_equal(scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)
# R2 score (aka. determination coefficient) - should be the
# same as the default estimator score
r2_scores = cross_val_score(reg, X, y, scoring="r2", cv=5)
assert_array_almost_equal(r2_scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)
# Mean squared error; this is a loss function, so "scores" are negative
neg_mse_scores = cross_val_score(reg, X, y, cv=5,
scoring="neg_mean_squared_error")
expected_neg_mse = np.array([-763.07, -553.16, -274.38, -273.26, -1681.99])
assert_array_almost_equal(neg_mse_scores, expected_neg_mse, 2)
# Explained variance
scoring = make_scorer(explained_variance_score)
ev_scores = cross_val_score(reg, X, y, cv=5, scoring=scoring)
assert_array_almost_equal(ev_scores, [0.94, 0.97, 0.97, 0.99, 0.92], 2)
def test_permutation_score():
iris = load_iris()
X = iris.data
X_sparse = coo_matrix(X)
y = iris.target
svm = SVC(kernel='linear')
cv = StratifiedKFold(2)
score, scores, pvalue = permutation_test_score(
svm, X, y, n_permutations=30, cv=cv, scoring="accuracy")
assert_greater(score, 0.9)
assert_almost_equal(pvalue, 0.0, 1)
score_group, _, pvalue_group = permutation_test_score(
svm, X, y, n_permutations=30, cv=cv, scoring="accuracy",
groups=np.ones(y.size), random_state=0)
assert_true(score_group == score)
assert_true(pvalue_group == pvalue)
# check that we obtain the same results with a sparse representation
svm_sparse = SVC(kernel='linear')
cv_sparse = StratifiedKFold(2)
score_group, _, pvalue_group = permutation_test_score(
svm_sparse, X_sparse, y, n_permutations=30, cv=cv_sparse,
scoring="accuracy", groups=np.ones(y.size), random_state=0)
assert_true(score_group == score)
assert_true(pvalue_group == pvalue)
# test with custom scoring object
def custom_score(y_true, y_pred):
return (((y_true == y_pred).sum() - (y_true != y_pred).sum()) /
y_true.shape[0])
scorer = make_scorer(custom_score)
score, _, pvalue = permutation_test_score(
svm, X, y, n_permutations=100, scoring=scorer, cv=cv, random_state=0)
assert_almost_equal(score, .93, 2)
assert_almost_equal(pvalue, 0.01, 3)
# set random y
y = np.mod(np.arange(len(y)), 3)
score, scores, pvalue = permutation_test_score(
svm, X, y, n_permutations=30, cv=cv, scoring="accuracy")
assert_less(score, 0.5)
assert_greater(pvalue, 0.2)
def test_permutation_test_score_allow_nans():
# Check that permutation_test_score allows input data with NaNs
X = np.arange(200, dtype=np.float64).reshape(10, -1)
X[2, :] = np.nan
y = np.repeat([0, 1], X.shape[0] / 2)
p = Pipeline([
('imputer', Imputer(strategy='mean', missing_values='NaN')),
('classifier', MockClassifier()),
])
permutation_test_score(p, X, y, cv=5)
def test_cross_val_score_allow_nans():
# Check that cross_val_score allows input data with NaNs
X = np.arange(200, dtype=np.float64).reshape(10, -1)
X[2, :] = np.nan
y = np.repeat([0, 1], X.shape[0] / 2)
p = Pipeline([
('imputer', Imputer(strategy='mean', missing_values='NaN')),
('classifier', MockClassifier()),
])
cross_val_score(p, X, y, cv=5)
def test_cross_val_score_multilabel():
X = np.array([[-3, 4], [2, 4], [3, 3], [0, 2], [-3, 1],
[-2, 1], [0, 0], [-2, -1], [-1, -2], [1, -2]])
y = np.array([[1, 1], [0, 1], [0, 1], [0, 1], [1, 1],
[0, 1], [1, 0], [1, 1], [1, 0], [0, 0]])
clf = KNeighborsClassifier(n_neighbors=1)
scoring_micro = make_scorer(precision_score, average='micro')
scoring_macro = make_scorer(precision_score, average='macro')
scoring_samples = make_scorer(precision_score, average='samples')
score_micro = cross_val_score(clf, X, y, scoring=scoring_micro, cv=5)
score_macro = cross_val_score(clf, X, y, scoring=scoring_macro, cv=5)
score_samples = cross_val_score(clf, X, y, scoring=scoring_samples, cv=5)
assert_almost_equal(score_micro, [1, 1 / 2, 3 / 4, 1 / 2, 1 / 3])
assert_almost_equal(score_macro, [1, 1 / 2, 3 / 4, 1 / 2, 1 / 4])
assert_almost_equal(score_samples, [1, 1 / 2, 3 / 4, 1 / 2, 1 / 4])
def test_cross_val_predict():
boston = load_boston()
X, y = boston.data, boston.target
cv = KFold()
est = Ridge()
# Naive loop (should be same as cross_val_predict):
preds2 = np.zeros_like(y)
for train, test in cv.split(X, y):
est.fit(X[train], y[train])
preds2[test] = est.predict(X[test])
preds = cross_val_predict(est, X, y, cv=cv)
assert_array_almost_equal(preds, preds2)
preds = cross_val_predict(est, X, y)
assert_equal(len(preds), len(y))
cv = LeaveOneOut()
preds = cross_val_predict(est, X, y, cv=cv)
assert_equal(len(preds), len(y))
Xsp = X.copy()
Xsp *= (Xsp > np.median(Xsp))
Xsp = coo_matrix(Xsp)
preds = cross_val_predict(est, Xsp, y)
assert_array_almost_equal(len(preds), len(y))
preds = cross_val_predict(KMeans(), X)
assert_equal(len(preds), len(y))
class BadCV():
def split(self, X, y=None, groups=None):
for i in range(4):
yield np.array([0, 1, 2, 3]), np.array([4, 5, 6, 7, 8])
assert_raises(ValueError, cross_val_predict, est, X, y, cv=BadCV())
def test_cross_val_predict_input_types():
iris = load_iris()
X, y = iris.data, iris.target
X_sparse = coo_matrix(X)
multioutput_y = np.column_stack([y, y[::-1]])
clf = Ridge(fit_intercept=False, random_state=0)
# 3 fold cv is used --> atleast 3 samples per class
# Smoke test
predictions = cross_val_predict(clf, X, y)
assert_equal(predictions.shape, (150,))
# test with multioutput y
predictions = cross_val_predict(clf, X_sparse, multioutput_y)
assert_equal(predictions.shape, (150, 2))
predictions = cross_val_predict(clf, X_sparse, y)
assert_array_equal(predictions.shape, (150,))
# test with multioutput y
predictions = cross_val_predict(clf, X_sparse, multioutput_y)
assert_array_equal(predictions.shape, (150, 2))
# test with X and y as list
list_check = lambda x: isinstance(x, list)
clf = CheckingClassifier(check_X=list_check)
predictions = cross_val_predict(clf, X.tolist(), y.tolist())
clf = CheckingClassifier(check_y=list_check)
predictions = cross_val_predict(clf, X, y.tolist())
# test with 3d X and
X_3d = X[:, :, np.newaxis]
check_3d = lambda x: x.ndim == 3
clf = CheckingClassifier(check_X=check_3d)
predictions = cross_val_predict(clf, X_3d, y)
assert_array_equal(predictions.shape, (150,))
def test_cross_val_predict_pandas():
# check cross_val_score doesn't destroy pandas dataframe
types = [(MockDataFrame, MockDataFrame)]
try:
from pandas import Series, DataFrame
types.append((Series, DataFrame))
except ImportError:
pass
for TargetType, InputFeatureType in types:
# X dataframe, y series
X_df, y_ser = InputFeatureType(X), TargetType(y2)
check_df = lambda x: isinstance(x, InputFeatureType)
check_series = lambda x: isinstance(x, TargetType)
clf = CheckingClassifier(check_X=check_df, check_y=check_series)
cross_val_predict(clf, X_df, y_ser)
def test_cross_val_score_sparse_fit_params():
iris = load_iris()
X, y = iris.data, iris.target
clf = MockClassifier()
fit_params = {'sparse_sample_weight': coo_matrix(np.eye(X.shape[0]))}
a = cross_val_score(clf, X, y, fit_params=fit_params)
assert_array_equal(a, np.ones(3))
def test_learning_curve():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(20)
with warnings.catch_warnings(record=True) as w:
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=3, train_sizes=np.linspace(0.1, 1.0, 10))
if len(w) > 0:
raise RuntimeError("Unexpected warning: %r" % w[0].message)
assert_equal(train_scores.shape, (10, 3))
assert_equal(test_scores.shape, (10, 3))
assert_array_equal(train_sizes, np.linspace(2, 20, 10))
assert_array_almost_equal(train_scores.mean(axis=1),
np.linspace(1.9, 1.0, 10))
assert_array_almost_equal(test_scores.mean(axis=1),
np.linspace(0.1, 1.0, 10))
def test_learning_curve_unsupervised():
X, _ = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(20)
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y=None, cv=3, train_sizes=np.linspace(0.1, 1.0, 10))
assert_array_equal(train_sizes, np.linspace(2, 20, 10))
assert_array_almost_equal(train_scores.mean(axis=1),
np.linspace(1.9, 1.0, 10))
assert_array_almost_equal(test_scores.mean(axis=1),
np.linspace(0.1, 1.0, 10))
def test_learning_curve_verbose():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(20)
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
train_sizes, train_scores, test_scores = \
learning_curve(estimator, X, y, cv=3, verbose=1)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert("[learning_curve]" in out)
def test_learning_curve_incremental_learning_not_possible():
X, y = make_classification(n_samples=2, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
# The mockup does not have partial_fit()
estimator = MockImprovingEstimator(1)
assert_raises(ValueError, learning_curve, estimator, X, y,
exploit_incremental_learning=True)
def test_learning_curve_incremental_learning():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockIncrementalImprovingEstimator(20)
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=3, exploit_incremental_learning=True,
train_sizes=np.linspace(0.1, 1.0, 10))
assert_array_equal(train_sizes, np.linspace(2, 20, 10))
assert_array_almost_equal(train_scores.mean(axis=1),
np.linspace(1.9, 1.0, 10))
assert_array_almost_equal(test_scores.mean(axis=1),
np.linspace(0.1, 1.0, 10))
def test_learning_curve_incremental_learning_unsupervised():
X, _ = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockIncrementalImprovingEstimator(20)
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y=None, cv=3, exploit_incremental_learning=True,
train_sizes=np.linspace(0.1, 1.0, 10))
assert_array_equal(train_sizes, np.linspace(2, 20, 10))
assert_array_almost_equal(train_scores.mean(axis=1),
np.linspace(1.9, 1.0, 10))
assert_array_almost_equal(test_scores.mean(axis=1),
np.linspace(0.1, 1.0, 10))
def test_learning_curve_batch_and_incremental_learning_are_equal():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
train_sizes = np.linspace(0.2, 1.0, 5)
estimator = PassiveAggressiveClassifier(n_iter=1, shuffle=False)
train_sizes_inc, train_scores_inc, test_scores_inc = \
learning_curve(
estimator, X, y, train_sizes=train_sizes,
cv=3, exploit_incremental_learning=True)
train_sizes_batch, train_scores_batch, test_scores_batch = \
learning_curve(
estimator, X, y, cv=3, train_sizes=train_sizes,
exploit_incremental_learning=False)
assert_array_equal(train_sizes_inc, train_sizes_batch)
assert_array_almost_equal(train_scores_inc.mean(axis=1),
train_scores_batch.mean(axis=1))
assert_array_almost_equal(test_scores_inc.mean(axis=1),
test_scores_batch.mean(axis=1))
def test_learning_curve_n_sample_range_out_of_bounds():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(20)
assert_raises(ValueError, learning_curve, estimator, X, y, cv=3,
train_sizes=[0, 1])
assert_raises(ValueError, learning_curve, estimator, X, y, cv=3,
train_sizes=[0.0, 1.0])
assert_raises(ValueError, learning_curve, estimator, X, y, cv=3,
train_sizes=[0.1, 1.1])
assert_raises(ValueError, learning_curve, estimator, X, y, cv=3,
train_sizes=[0, 20])
assert_raises(ValueError, learning_curve, estimator, X, y, cv=3,
train_sizes=[1, 21])
def test_learning_curve_remove_duplicate_sample_sizes():
X, y = make_classification(n_samples=3, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(2)
train_sizes, _, _ = assert_warns(
RuntimeWarning, learning_curve, estimator, X, y, cv=3,
train_sizes=np.linspace(0.33, 1.0, 3))
assert_array_equal(train_sizes, [1, 2])
def test_learning_curve_with_boolean_indices():
X, y = make_classification(n_samples=30, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
estimator = MockImprovingEstimator(20)
cv = KFold(n_splits=3)
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=cv, train_sizes=np.linspace(0.1, 1.0, 10))
assert_array_equal(train_sizes, np.linspace(2, 20, 10))
assert_array_almost_equal(train_scores.mean(axis=1),
np.linspace(1.9, 1.0, 10))
assert_array_almost_equal(test_scores.mean(axis=1),
np.linspace(0.1, 1.0, 10))
def test_validation_curve():
X, y = make_classification(n_samples=2, n_features=1, n_informative=1,
n_redundant=0, n_classes=2,
n_clusters_per_class=1, random_state=0)
param_range = np.linspace(0, 1, 10)
with warnings.catch_warnings(record=True) as w:
train_scores, test_scores = validation_curve(
MockEstimatorWithParameter(), X, y, param_name="param",
param_range=param_range, cv=2
)
if len(w) > 0:
raise RuntimeError("Unexpected warning: %r" % w[0].message)
assert_array_almost_equal(train_scores.mean(axis=1), param_range)
assert_array_almost_equal(test_scores.mean(axis=1), 1 - param_range)
def test_check_is_permutation():
rng = np.random.RandomState(0)
p = np.arange(100)
rng.shuffle(p)
assert_true(_check_is_permutation(p, 100))
assert_false(_check_is_permutation(np.delete(p, 23), 100))
p[0] = 23
assert_false(_check_is_permutation(p, 100))
# Check if the additional duplicate indices are caught
assert_false(_check_is_permutation(np.hstack((p, 0)), 100))
def test_cross_val_predict_sparse_prediction():
# check that cross_val_predict gives same result for sparse and dense input
X, y = make_multilabel_classification(n_classes=2, n_labels=1,
allow_unlabeled=False,
return_indicator=True,
random_state=1)
X_sparse = csr_matrix(X)
y_sparse = csr_matrix(y)
classif = OneVsRestClassifier(SVC(kernel='linear'))
preds = cross_val_predict(classif, X, y, cv=10)
preds_sparse = cross_val_predict(classif, X_sparse, y_sparse, cv=10)
preds_sparse = preds_sparse.toarray()
assert_array_almost_equal(preds_sparse, preds)
def test_cross_val_predict_with_method():
iris = load_iris()
X, y = iris.data, iris.target
X, y = shuffle(X, y, random_state=0)
classes = len(set(y))
kfold = KFold(len(iris.target))
methods = ['decision_function', 'predict_proba', 'predict_log_proba']
for method in methods:
est = LogisticRegression()
predictions = cross_val_predict(est, X, y, method=method)
assert_equal(len(predictions), len(y))
expected_predictions = np.zeros([len(y), classes])
func = getattr(est, method)
# Naive loop (should be same as cross_val_predict):
for train, test in kfold.split(X, y):
est.fit(X[train], y[train])
expected_predictions[test] = func(X[test])
predictions = cross_val_predict(est, X, y, method=method,
cv=kfold)
assert_array_almost_equal(expected_predictions, predictions)
def test_score_memmap():
# Ensure a scalar score of memmap type is accepted
iris = load_iris()
X, y = iris.data, iris.target
clf = MockClassifier()
tf = tempfile.NamedTemporaryFile(mode='wb', delete=False)
tf.write(b'Hello world!!!!!')
tf.close()
scores = np.memmap(tf.name, dtype=np.float64)
score = np.memmap(tf.name, shape=(), mode='r', dtype=np.float64)
try:
cross_val_score(clf, X, y, scoring=lambda est, X, y: score)
# non-scalar should still fail
assert_raises(ValueError, cross_val_score, clf, X, y,
scoring=lambda est, X, y: scores)
finally:
# Best effort to release the mmap file handles before deleting the
# backing file under Windows
scores, score = None, None
for _ in range(3):
try:
os.unlink(tf.name)
break
except WindowsError:
sleep(1.)
|
bsd-3-clause
|
[
624,
774,
314,
6411,
859,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
984,
199,
646,
3598,
199,
646,
5549,
199,
646,
747,
199,
504,
900,
492,
9435,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
12,
22258,
63,
3642,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3910,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
1805,
316,
492,
25109,
8508,
12,
4420,
9205,
199,
199,
504,
6357,
14,
1238,
63,
5592,
492,
8059,
63,
637,
63,
3397,
199,
504,
6357,
14,
1238,
63,
5592,
492,
8059,
63,
637,
63,
6892,
199,
504,
6357,
14,
1238,
63,
5592,
492,
22966,
63,
396,
63,
3397,
199,
504,
6357,
14,
1238,
63,
5592,
492,
1804,
27985,
199,
504,
6357,
14,
1238,
63,
5592,
492,
428,
1239,
8981,
17706,
1753,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
4395,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
4395,
2448,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
48,
10177,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
5611,
17706,
1753,
199,
504,
6357,
14,
1238,
63,
5592,
492,
5611,
19779,
8862,
199,
504,
6357,
14,
1238,
63,
5592,
492,
9328,
63,
11895,
199,
504,
6357,
14,
1238,
63,
5592,
492,
6411,
63,
11895,
199,
504,
6357,
14,
1238,
63,
5592,
423,
6136,
492,
485,
1074,
63,
374,
63,
23832,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
12513,
199,
504,
6357,
14,
12281,
492,
2248,
63,
28275,
199,
504,
6357,
14,
12281,
492,
2248,
63,
11885,
199,
504,
6357,
14,
6759,
492,
1437,
23918,
63,
6221,
63,
3397,
199,
504,
6357,
14,
6759,
492,
1852,
63,
22135,
199,
504,
6357,
14,
6759,
492,
7151,
63,
3397,
199,
199,
504,
6357,
14,
6676,
63,
1238,
492,
31196,
12,
27903,
199,
504,
6357,
14,
6676,
63,
1238,
492,
510,
13202,
7248,
470,
3398,
8508,
199,
504,
6357,
14,
11113,
492,
1804,
20011,
8508,
199,
504,
6357,
14,
16820,
492,
428,
9454,
199,
504,
6357,
14,
4201,
492,
1804,
21190,
199,
199,
504,
6357,
14,
21402,
492,
8362,
2699,
199,
504,
6357,
14,
7379,
492,
19090,
199,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
15073,
465,
5228,
199,
504,
6357,
14,
1095,
492,
3523,
13183,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
13726,
8508,
199,
504,
6357,
14,
1208,
492,
13031,
199,
504,
6357,
14,
12281,
492,
1852,
63,
14368,
199,
504,
6357,
14,
12281,
492,
1852,
63,
3029,
1302,
63,
14368,
199,
199,
504,
6357,
14,
1238,
63,
5592,
14,
2219,
14,
396,
63,
1294,
492,
4420,
8508,
421,
199,
893,
26,
272,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
488,
421,
199,
533,
4420,
8499,
293,
4007,
13183,
8,
1563,
13183,
304,
272,
408,
11324,
12429,
370,
511,
314,
9328,
15318,
624,
272,
347,
636,
826,
721,
277,
12,
302,
63,
988,
63,
2834,
63,
7723,
304,
267,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
275,
302,
63,
988,
63,
2834,
63,
7723,
267,
291,
14,
2834,
63,
7723,
275,
378,
267,
291,
14,
56,
63,
9401,
275,
488,
339,
347,
5542,
8,
277,
12,
1323,
63,
9401,
12,
612,
63,
9401,
29,
403,
304,
267,
291,
14,
56,
63,
9401,
275,
1323,
63,
9401,
267,
291,
14,
2834,
63,
7723,
275,
1323,
63,
9401,
14,
1392,
59,
16,
61,
267,
372,
291,
339,
347,
12610,
8,
277,
12,
1323,
304,
267,
746,
4279,
339,
347,
5396,
8,
277,
12,
1323,
29,
403,
12,
1488,
29,
403,
304,
267,
327,
6093,
5396,
15410,
1319,
261,
334,
18,
1035,
413,
395,
511,
1125,
8034,
334,
16,
1035,
413,
9,
267,
340,
291,
423,
374,
63,
7588,
63,
576,
8,
56,
304,
288,
372,
499,
14,
446,
2069,
8,
277,
14,
2834,
63,
7723,
9,
1182,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
267,
587,
26,
288,
372,
2069,
8,
277,
14,
2834,
63,
7723,
9,
1182,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
339,
347,
485,
374,
63,
7588,
63,
576,
8,
277,
12,
1323,
304,
267,
372,
1323,
365,
291,
14,
56,
63,
9401,
421,
199,
533,
4420,
10287,
8499,
293,
4007,
13183,
8,
3346,
8499,
293,
4007,
13183,
304,
272,
408,
11324,
12429,
626,
6571,
7417,
63,
3269,
624,
272,
347,
636,
826,
721,
277,
12,
302,
63,
988,
63,
2834,
63,
7723,
304,
267,
1613,
8,
3346,
10287,
8499,
293,
4007,
13183,
12,
1598,
291,
2843,
826,
721,
78,
63,
988,
63,
2834,
63,
7723,
9,
267,
291,
14,
88,
275,
488,
339,
347,
485,
374,
63,
7588,
63,
576,
8,
277,
12,
1323,
304,
267,
372,
291,
14,
88,
315,
1323,
339,
347,
7417,
63,
3269,
8,
277,
12,
1323,
12,
612,
29,
403,
12,
1011,
1162,
304,
267,
291,
14,
2834,
63,
7723,
847,
1323,
14,
1392,
59,
16,
61,
267,
291,
14,
88,
275,
1323,
59,
16,
61,
421,
199,
533,
4420,
13183,
3007,
4720,
8,
1563,
13183,
304,
272,
408,
11324,
12429,
370,
511,
314,
6411,
15318,
624,
272,
347,
636,
826,
721,
277,
12,
1215,
29,
16,
14,
21,
304,
267,
291,
14,
56,
63,
9401,
275,
488,
267,
291,
14,
635,
275,
1215,
339,
347,
5542,
8,
277,
12,
1323,
63,
9401,
12,
612,
63,
9401,
304,
267,
291,
14,
56,
63,
9401,
275,
1323,
63,
9401,
267,
291,
14,
2834,
63,
7723,
275,
1323,
63,
9401,
14,
1392
] |
[
774,
314,
6411,
859,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
984,
199,
646,
3598,
199,
646,
5549,
199,
646,
747,
199,
504,
900,
492,
9435,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
12,
22258,
63,
3642,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3910,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
1805,
316,
492,
25109,
8508,
12,
4420,
9205,
199,
199,
504,
6357,
14,
1238,
63,
5592,
492,
8059,
63,
637,
63,
3397,
199,
504,
6357,
14,
1238,
63,
5592,
492,
8059,
63,
637,
63,
6892,
199,
504,
6357,
14,
1238,
63,
5592,
492,
22966,
63,
396,
63,
3397,
199,
504,
6357,
14,
1238,
63,
5592,
492,
1804,
27985,
199,
504,
6357,
14,
1238,
63,
5592,
492,
428,
1239,
8981,
17706,
1753,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
4395,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
4395,
2448,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
28015,
48,
10177,
2204,
199,
504,
6357,
14,
1238,
63,
5592,
492,
5611,
17706,
1753,
199,
504,
6357,
14,
1238,
63,
5592,
492,
5611,
19779,
8862,
199,
504,
6357,
14,
1238,
63,
5592,
492,
9328,
63,
11895,
199,
504,
6357,
14,
1238,
63,
5592,
492,
6411,
63,
11895,
199,
504,
6357,
14,
1238,
63,
5592,
423,
6136,
492,
485,
1074,
63,
374,
63,
23832,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
12513,
199,
504,
6357,
14,
12281,
492,
2248,
63,
28275,
199,
504,
6357,
14,
12281,
492,
2248,
63,
11885,
199,
504,
6357,
14,
6759,
492,
1437,
23918,
63,
6221,
63,
3397,
199,
504,
6357,
14,
6759,
492,
1852,
63,
22135,
199,
504,
6357,
14,
6759,
492,
7151,
63,
3397,
199,
199,
504,
6357,
14,
6676,
63,
1238,
492,
31196,
12,
27903,
199,
504,
6357,
14,
6676,
63,
1238,
492,
510,
13202,
7248,
470,
3398,
8508,
199,
504,
6357,
14,
11113,
492,
1804,
20011,
8508,
199,
504,
6357,
14,
16820,
492,
428,
9454,
199,
504,
6357,
14,
4201,
492,
1804,
21190,
199,
199,
504,
6357,
14,
21402,
492,
8362,
2699,
199,
504,
6357,
14,
7379,
492,
19090,
199,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
15073,
465,
5228,
199,
504,
6357,
14,
1095,
492,
3523,
13183,
199,
504,
6357,
14,
30016,
492,
7309,
20343,
13726,
8508,
199,
504,
6357,
14,
1208,
492,
13031,
199,
504,
6357,
14,
12281,
492,
1852,
63,
14368,
199,
504,
6357,
14,
12281,
492,
1852,
63,
3029,
1302,
63,
14368,
199,
199,
504,
6357,
14,
1238,
63,
5592,
14,
2219,
14,
396,
63,
1294,
492,
4420,
8508,
421,
199,
893,
26,
272,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
488,
421,
199,
533,
4420,
8499,
293,
4007,
13183,
8,
1563,
13183,
304,
272,
408,
11324,
12429,
370,
511,
314,
9328,
15318,
624,
272,
347,
636,
826,
721,
277,
12,
302,
63,
988,
63,
2834,
63,
7723,
304,
267,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
275,
302,
63,
988,
63,
2834,
63,
7723,
267,
291,
14,
2834,
63,
7723,
275,
378,
267,
291,
14,
56,
63,
9401,
275,
488,
339,
347,
5542,
8,
277,
12,
1323,
63,
9401,
12,
612,
63,
9401,
29,
403,
304,
267,
291,
14,
56,
63,
9401,
275,
1323,
63,
9401,
267,
291,
14,
2834,
63,
7723,
275,
1323,
63,
9401,
14,
1392,
59,
16,
61,
267,
372,
291,
339,
347,
12610,
8,
277,
12,
1323,
304,
267,
746,
4279,
339,
347,
5396,
8,
277,
12,
1323,
29,
403,
12,
1488,
29,
403,
304,
267,
327,
6093,
5396,
15410,
1319,
261,
334,
18,
1035,
413,
395,
511,
1125,
8034,
334,
16,
1035,
413,
9,
267,
340,
291,
423,
374,
63,
7588,
63,
576,
8,
56,
304,
288,
372,
499,
14,
446,
2069,
8,
277,
14,
2834,
63,
7723,
9,
1182,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
267,
587,
26,
288,
372,
2069,
8,
277,
14,
2834,
63,
7723,
9,
1182,
291,
14,
78,
63,
988,
63,
2834,
63,
7723,
339,
347,
485,
374,
63,
7588,
63,
576,
8,
277,
12,
1323,
304,
267,
372,
1323,
365,
291,
14,
56,
63,
9401,
421,
199,
533,
4420,
10287,
8499,
293,
4007,
13183,
8,
3346,
8499,
293,
4007,
13183,
304,
272,
408,
11324,
12429,
626,
6571,
7417,
63,
3269,
624,
272,
347,
636,
826,
721,
277,
12,
302,
63,
988,
63,
2834,
63,
7723,
304,
267,
1613,
8,
3346,
10287,
8499,
293,
4007,
13183,
12,
1598,
291,
2843,
826,
721,
78,
63,
988,
63,
2834,
63,
7723,
9,
267,
291,
14,
88,
275,
488,
339,
347,
485,
374,
63,
7588,
63,
576,
8,
277,
12,
1323,
304,
267,
372,
291,
14,
88,
315,
1323,
339,
347,
7417,
63,
3269,
8,
277,
12,
1323,
12,
612,
29,
403,
12,
1011,
1162,
304,
267,
291,
14,
2834,
63,
7723,
847,
1323,
14,
1392,
59,
16,
61,
267,
291,
14,
88,
275,
1323,
59,
16,
61,
421,
199,
533,
4420,
13183,
3007,
4720,
8,
1563,
13183,
304,
272,
408,
11324,
12429,
370,
511,
314,
6411,
15318,
624,
272,
347,
636,
826,
721,
277,
12,
1215,
29,
16,
14,
21,
304,
267,
291,
14,
56,
63,
9401,
275,
488,
267,
291,
14,
635,
275,
1215,
339,
347,
5542,
8,
277,
12,
1323,
63,
9401,
12,
612,
63,
9401,
304,
267,
291,
14,
56,
63,
9401,
275,
1323,
63,
9401,
267,
291,
14,
2834,
63,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kriswuollett/grpc
|
tools/buildgen/plugins/expand_filegroups.py
|
13
|
5473
|
# Copyright 2015, 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.
"""Buildgen expand filegroups plugin.
This takes the list of libs from our yaml dictionary,
and expands any and all filegroup.
"""
def excluded(filename, exclude_res):
for r in exclude_res:
if r.search(filename):
return True
return False
def uniquify(lst):
out = []
for el in lst:
if el not in out:
out.append(el)
return out
FILEGROUP_LISTS = ['src', 'headers', 'public_headers', 'deps']
FILEGROUP_DEFAULTS = {
'language': 'c',
'boringssl': False,
'zlib': False,
'ares': False,
}
def mako_plugin(dictionary):
"""The exported plugin code for expand_filegroups.
The list of libs in the build.yaml file can contain "filegroups" tags.
These refer to the filegroups in the root object. We will expand and
merge filegroups on the src, headers and public_headers properties.
"""
libs = dictionary.get('libs')
targets = dictionary.get('targets')
filegroups_list = dictionary.get('filegroups')
filegroups = {}
for fg in filegroups_list:
for lst in FILEGROUP_LISTS:
fg[lst] = fg.get(lst, [])
fg['own_%s' % lst] = list(fg[lst])
for attr, val in FILEGROUP_DEFAULTS.iteritems():
if attr not in fg:
fg[attr] = val
todo = list(filegroups_list)
skips = 0
while todo:
assert skips != len(todo), "infinite loop in filegroup uses clauses: %r" % [t['name'] for t in todo]
# take the first element of the todo list
cur = todo[0]
todo = todo[1:]
# check all uses filegroups are present (if no, skip and come back later)
skip = False
for uses in cur.get('uses', []):
if uses not in filegroups:
skip = True
if skip:
skips += 1
todo.append(cur)
else:
skips = 0
assert 'plugins' not in cur
plugins = []
for uses in cur.get('uses', []):
for plugin in filegroups[uses]['plugins']:
if plugin not in plugins:
plugins.append(plugin)
for lst in FILEGROUP_LISTS:
vals = cur.get(lst, [])
vals.extend(filegroups[uses].get(lst, []))
cur[lst] = vals
cur_plugin_name = cur.get('plugin')
if cur_plugin_name:
plugins.append(cur_plugin_name)
cur['plugins'] = plugins
filegroups[cur['name']] = cur
# build reverse dependency map
things = {}
for thing in dictionary['libs'] + dictionary['targets'] + dictionary['filegroups']:
things[thing['name']] = thing
thing['used_by'] = []
thing_deps = lambda t: t.get('uses', []) + t.get('filegroups', []) + t.get('deps', [])
for thing in things.itervalues():
done = set()
todo = thing_deps(thing)
while todo:
cur = todo[0]
todo = todo[1:]
if cur in done: continue
things[cur]['used_by'].append(thing['name'])
todo.extend(thing_deps(things[cur]))
done.add(cur)
# the above expansion can introduce duplicate filenames: contract them here
for fg in filegroups.itervalues():
for lst in FILEGROUP_LISTS:
fg[lst] = uniquify(fg.get(lst, []))
for tgt in dictionary['targets']:
for lst in FILEGROUP_LISTS:
tgt[lst] = tgt.get(lst, [])
tgt['own_%s' % lst] = list(tgt[lst])
for lib in libs + targets:
assert 'plugins' not in lib
plugins = []
for lst in FILEGROUP_LISTS:
vals = lib.get(lst, [])
lib[lst] = list(vals)
lib['own_%s' % lst] = list(vals)
for fg_name in lib.get('filegroups', []):
fg = filegroups[fg_name]
for plugin in fg['plugins']:
if plugin not in plugins:
plugins.append(plugin)
for lst in FILEGROUP_LISTS:
vals = lib.get(lst, [])
vals.extend(fg.get(lst, []))
lib[lst] = vals
lib['plugins'] = plugins
if lib.get('generate_plugin_registry', False):
lib['src'].append('src/core/plugin_registry/%s_plugin_registry.c' %
lib['name'])
for lst in FILEGROUP_LISTS:
lib[lst] = uniquify(lib.get(lst, []))
|
bsd-3-clause
|
[
3,
1898,
6900,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
3425,
2268,
6544,
570,
2634,
3589,
14,
199,
199,
2765,
6181,
314,
769,
402,
20314,
687,
4154,
8864,
2600,
12,
199,
460,
1437,
5915,
1263,
436,
1006,
570,
923,
14,
199,
199,
624,
421,
199,
318,
8789,
8,
1501,
12,
5760,
63,
470,
304,
523,
367,
519,
315,
5760,
63,
470,
26,
272,
340,
519,
14,
1733,
8,
1501,
304,
489,
372,
715,
523,
372,
756,
421,
199,
318,
15439,
392,
2021,
8,
6916,
304,
523,
734,
275,
942,
523,
367,
579,
315,
9877,
26,
272,
340,
579,
440,
315,
734,
26,
489,
734,
14,
740,
8,
352,
9,
523,
372,
734,
421,
199,
3817,
7823,
63,
4924,
51,
275,
788,
2164,
297,
283,
2139,
297,
283,
3455,
63,
2139,
297,
283,
5846,
418,
421,
199,
3817,
7823,
63,
30773,
275,
469,
523,
283,
3671,
356,
283,
67,
297,
523,
283,
66,
6854,
4266,
356,
756,
12,
523,
283,
15371,
356,
756,
12,
523,
283,
11044,
356,
756,
12,
199,
93,
421,
199,
318,
26834,
63,
2718,
8,
9086,
304,
523,
408,
1918,
16629,
3589,
1233,
367,
6544,
63,
493,
2634,
14,
819,
710,
769,
402,
20314,
315,
314,
1900,
14,
5963,
570,
883,
1395,
298,
493,
2634,
2,
3762,
14,
523,
5723,
10618,
370,
314,
570,
2634,
315,
314,
1738,
909,
14,
2136,
911,
6544,
436,
523,
5389,
570,
2634,
641,
314,
2928,
12,
2323,
436,
4575,
63,
2139,
4382,
14,
819,
408,
523,
20314,
275,
2600,
14,
362,
360,
8450,
358,
523,
4545,
275,
2600,
14,
362,
360,
4684,
358,
523,
570,
2634,
63,
513,
275,
2600,
14,
362,
360,
493,
2634,
358,
523,
570,
2634,
275,
1052,
819,
367,
16587,
315,
570,
2634,
63,
513,
26,
272,
367,
9877,
315,
13024,
7823,
63,
4924,
51,
26,
489,
16587,
59,
6916,
61,
275,
16587,
14,
362,
8,
6916,
12,
3073,
489,
16587,
459,
944,
4970,
83,
7,
450,
9877,
61,
275,
769,
8,
9681,
59,
6916,
566,
272,
367,
1921,
12,
1139,
315,
13024,
7823,
63,
30773,
14,
4611,
837,
489,
340,
1921,
440,
315,
16587,
26,
267,
16587,
59,
962,
61,
275,
1139,
819,
11386,
275,
769,
8,
493,
2634,
63,
513,
9,
523,
30505,
275,
378,
819,
1830,
11386,
26,
272,
702,
30505,
1137,
822,
8,
11396,
395,
298,
30757,
4438,
315,
570,
923,
4440,
25089,
26,
450,
82,
2,
450,
359,
84,
459,
354,
418,
367,
307,
315,
11386,
61,
272,
327,
5452,
314,
1642,
1819,
402,
314,
11386,
769,
272,
1094,
275,
11386,
59,
16,
61,
272,
11386,
275,
11386,
59,
17,
2938,
272,
327,
1104,
1006,
4440,
570,
2634,
787,
3451,
334,
692,
949,
12,
3372,
436,
11492,
1771,
2945,
9,
272,
3372,
275,
756,
272,
367,
4440,
315,
1094,
14,
362,
360,
5589,
297,
12319,
489,
340,
4440,
440,
315,
570,
2634,
26,
267,
3372,
275,
715,
272,
340,
3372,
26,
489,
30505,
847,
413,
489,
11386,
14,
740,
8,
895,
9,
272,
587,
26,
489,
30505,
275,
378,
489,
702,
283,
5265,
7,
440,
315,
1094,
489,
8963,
275,
942,
489,
367,
4440,
315,
1094,
14,
362,
360,
5589,
297,
12319,
267,
367,
3589,
315,
570,
2634,
59,
5589,
2733,
5265,
2565,
881,
340,
3589,
440,
315,
8963,
26,
288,
8963,
14,
740,
8,
2718,
9,
267,
367,
9877,
315,
13024,
7823,
63,
4924,
51,
26,
881,
5322,
275,
1094,
14,
362,
8,
6916,
12,
3073,
881,
5322,
14,
2880,
8,
493,
2634,
59,
5589,
1055,
362,
8,
6916,
12,
15927,
881,
1094,
59,
6916,
61,
275,
5322,
489,
1094,
63,
2718,
63,
354,
275,
1094,
14,
362,
360,
2718,
358,
489,
340,
1094,
63,
2718,
63,
354,
26,
267,
8963,
14,
740,
8,
895,
63,
2718,
63,
354,
9,
489,
1094,
459,
5265,
418,
275,
8963,
489,
570,
2634,
59,
895,
459,
354,
6538,
275,
1094,
819,
327,
1900,
3837,
5936,
2341,
523,
7645,
275,
1052,
523,
367,
8377,
315,
2600,
459,
8450,
418,
435,
2600,
459,
4684,
418,
435,
2600,
459,
493,
2634,
2565,
272,
7645,
59,
2127,
459,
354,
6538,
275,
8377,
272,
8377,
459,
2972,
63,
991,
418,
275,
942,
523,
8377,
63,
5846,
275,
2400,
307,
26,
307,
14,
362,
360,
5589,
297,
3073,
435,
307,
14,
362,
360,
493,
2634,
297,
3073,
435,
307,
14,
362
] |
[
1898,
6900,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
3425,
2268,
6544,
570,
2634,
3589,
14,
199,
199,
2765,
6181,
314,
769,
402,
20314,
687,
4154,
8864,
2600,
12,
199,
460,
1437,
5915,
1263,
436,
1006,
570,
923,
14,
199,
199,
624,
421,
199,
318,
8789,
8,
1501,
12,
5760,
63,
470,
304,
523,
367,
519,
315,
5760,
63,
470,
26,
272,
340,
519,
14,
1733,
8,
1501,
304,
489,
372,
715,
523,
372,
756,
421,
199,
318,
15439,
392,
2021,
8,
6916,
304,
523,
734,
275,
942,
523,
367,
579,
315,
9877,
26,
272,
340,
579,
440,
315,
734,
26,
489,
734,
14,
740,
8,
352,
9,
523,
372,
734,
421,
199,
3817,
7823,
63,
4924,
51,
275,
788,
2164,
297,
283,
2139,
297,
283,
3455,
63,
2139,
297,
283,
5846,
418,
421,
199,
3817,
7823,
63,
30773,
275,
469,
523,
283,
3671,
356,
283,
67,
297,
523,
283,
66,
6854,
4266,
356,
756,
12,
523,
283,
15371,
356,
756,
12,
523,
283,
11044,
356,
756,
12,
199,
93,
421,
199,
318,
26834,
63,
2718,
8,
9086,
304,
523,
408,
1918,
16629,
3589,
1233,
367,
6544,
63,
493,
2634,
14,
819,
710,
769,
402,
20314,
315,
314,
1900,
14,
5963,
570,
883,
1395,
298,
493,
2634,
2,
3762,
14,
523,
5723,
10618,
370,
314,
570,
2634,
315,
314,
1738,
909,
14,
2136,
911,
6544,
436,
523,
5389,
570,
2634,
641,
314,
2928,
12,
2323,
436,
4575,
63,
2139,
4382,
14,
819,
408,
523,
20314,
275,
2600,
14,
362,
360,
8450,
358,
523,
4545,
275,
2600,
14,
362,
360,
4684,
358,
523,
570,
2634,
63,
513,
275,
2600,
14,
362,
360,
493,
2634,
358,
523,
570,
2634,
275,
1052,
819,
367,
16587,
315,
570,
2634,
63,
513,
26,
272,
367,
9877,
315,
13024,
7823,
63,
4924,
51,
26,
489,
16587,
59,
6916,
61,
275,
16587,
14,
362,
8,
6916,
12,
3073,
489,
16587,
459,
944,
4970,
83,
7,
450,
9877,
61,
275,
769,
8,
9681,
59,
6916,
566,
272,
367,
1921,
12,
1139,
315,
13024,
7823,
63,
30773,
14,
4611,
837,
489,
340,
1921,
440,
315,
16587,
26,
267,
16587,
59,
962,
61,
275,
1139,
819,
11386,
275,
769,
8,
493,
2634,
63,
513,
9,
523,
30505,
275,
378,
819,
1830,
11386,
26,
272,
702,
30505,
1137,
822,
8,
11396,
395,
298,
30757,
4438,
315,
570,
923,
4440,
25089,
26,
450,
82,
2,
450,
359,
84,
459,
354,
418,
367,
307,
315,
11386,
61,
272,
327,
5452,
314,
1642,
1819,
402,
314,
11386,
769,
272,
1094,
275,
11386,
59,
16,
61,
272,
11386,
275,
11386,
59,
17,
2938,
272,
327,
1104,
1006,
4440,
570,
2634,
787,
3451,
334,
692,
949,
12,
3372,
436,
11492,
1771,
2945,
9,
272,
3372,
275,
756,
272,
367,
4440,
315,
1094,
14,
362,
360,
5589,
297,
12319,
489,
340,
4440,
440,
315,
570,
2634,
26,
267,
3372,
275,
715,
272,
340,
3372,
26,
489,
30505,
847,
413,
489,
11386,
14,
740,
8,
895,
9,
272,
587,
26,
489,
30505,
275,
378,
489,
702,
283,
5265,
7,
440,
315,
1094,
489,
8963,
275,
942,
489,
367,
4440,
315,
1094,
14,
362,
360,
5589,
297,
12319,
267,
367,
3589,
315,
570,
2634,
59,
5589,
2733,
5265,
2565,
881,
340,
3589,
440,
315,
8963,
26,
288,
8963,
14,
740,
8,
2718,
9,
267,
367,
9877,
315,
13024,
7823,
63,
4924,
51,
26,
881,
5322,
275,
1094,
14,
362,
8,
6916,
12,
3073,
881,
5322,
14,
2880,
8,
493,
2634,
59,
5589,
1055,
362,
8,
6916,
12,
15927,
881,
1094,
59,
6916,
61,
275,
5322,
489,
1094,
63,
2718,
63,
354,
275,
1094,
14,
362,
360,
2718,
358,
489,
340,
1094,
63,
2718,
63,
354,
26,
267,
8963,
14,
740,
8,
895,
63,
2718,
63,
354,
9,
489,
1094,
459,
5265,
418,
275,
8963,
489,
570,
2634,
59,
895,
459,
354,
6538,
275,
1094,
819,
327,
1900,
3837,
5936,
2341,
523,
7645,
275,
1052,
523,
367,
8377,
315,
2600,
459,
8450,
418,
435,
2600,
459,
4684,
418,
435,
2600,
459,
493,
2634,
2565,
272,
7645,
59,
2127,
459,
354,
6538,
275,
8377,
272,
8377,
459,
2972,
63,
991,
418,
275,
942,
523,
8377,
63,
5846,
275,
2400,
307,
26,
307,
14,
362,
360,
5589,
297,
3073,
435,
307,
14,
362,
360,
493,
2634,
297,
3073,
435,
307,
14,
362,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
freedomtan/tensorflow
|
tensorflow/python/data/ops/optional_ops.py
|
5
|
8971
|
# 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.
# ==============================================================================
"""A type for representing values that may or may not exist."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import abc
import six
from tensorflow.python.data.util import structure
from tensorflow.python.framework import composite_tensor
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_spec
from tensorflow.python.framework import type_spec
from tensorflow.python.ops import gen_dataset_ops
from tensorflow.python.util import deprecation
from tensorflow.python.util.tf_export import tf_export
@tf_export("experimental.Optional", "data.experimental.Optional")
@deprecation.deprecated_endpoints("data.experimental.Optional")
@six.add_metaclass(abc.ABCMeta)
class Optional(composite_tensor.CompositeTensor):
"""Represents a value that may or may not be present.
A `tf.experimental.Optional` can represent the result of an operation that may
fail as a value, rather than raising an exception and halting execution. For
example, `tf.data.Iterator.get_next_as_optional()` returns a
`tf.experimental.Optional` that either contains the next element of an
iterator if one exists, or an "empty" value that indicates the end of the
sequence has been reached.
`tf.experimental.Optional` can only be used with values that are convertible
to `tf.Tensor` or `tf.CompositeTensor`.
One can create a `tf.experimental.Optional` from a value using the
`from_value()` method:
>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.has_value())
tf.Tensor(True, shape=(), dtype=bool)
>>> print(optional.get_value())
tf.Tensor(42, shape=(), dtype=int32)
or without a value using the `empty()` method:
>>> optional = tf.experimental.Optional.empty(
... tf.TensorSpec(shape=(), dtype=tf.int32, name=None))
>>> print(optional.has_value())
tf.Tensor(False, shape=(), dtype=bool)
"""
@abc.abstractmethod
def has_value(self, name=None):
"""Returns a tensor that evaluates to `True` if this optional has a value.
>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.has_value())
tf.Tensor(True, shape=(), dtype=bool)
Args:
name: (Optional.) A name for the created operation.
Returns:
A scalar `tf.Tensor` of type `tf.bool`.
"""
raise NotImplementedError("Optional.has_value()")
@abc.abstractmethod
def get_value(self, name=None):
"""Returns the value wrapped by this optional.
If this optional does not have a value (i.e. `self.has_value()` evaluates to
`False`), this operation will raise `tf.errors.InvalidArgumentError` at
runtime.
>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.get_value())
tf.Tensor(42, shape=(), dtype=int32)
Args:
name: (Optional.) A name for the created operation.
Returns:
The wrapped value.
"""
raise NotImplementedError("Optional.get_value()")
@abc.abstractproperty
def element_spec(self):
"""The type specification of an element of this optional.
>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.element_spec)
tf.TensorSpec(shape=(), dtype=tf.int32, name=None)
Returns:
A nested structure of `tf.TypeSpec` objects matching the structure of an
element of this optional, specifying the type of individual components.
"""
raise NotImplementedError("Optional.element_spec")
@staticmethod
def empty(element_spec):
"""Returns an `Optional` that has no value.
NOTE: This method takes an argument that defines the structure of the value
that would be contained in the returned `Optional` if it had a value.
>>> optional = tf.experimental.Optional.empty(
... tf.TensorSpec(shape=(), dtype=tf.int32, name=None))
>>> print(optional.has_value())
tf.Tensor(False, shape=(), dtype=bool)
Args:
element_spec: A nested structure of `tf.TypeSpec` objects matching the
structure of an element of this optional.
Returns:
A `tf.experimental.Optional` with no value.
"""
return _OptionalImpl(gen_dataset_ops.optional_none(), element_spec)
@staticmethod
def from_value(value):
"""Returns a `tf.experimental.Optional` that wraps the given value.
>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.has_value())
tf.Tensor(True, shape=(), dtype=bool)
>>> print(optional.get_value())
tf.Tensor(42, shape=(), dtype=int32)
Args:
value: A value to wrap. The value must be convertible to `tf.Tensor` or
`tf.CompositeTensor`.
Returns:
A `tf.experimental.Optional` that wraps `value`.
"""
with ops.name_scope("optional") as scope:
with ops.name_scope("value"):
element_spec = structure.type_spec_from_value(value)
encoded_value = structure.to_tensor_list(element_spec, value)
return _OptionalImpl(
gen_dataset_ops.optional_from_value(encoded_value, name=scope),
element_spec)
class _OptionalImpl(Optional):
"""Concrete implementation of `tf.experimental.Optional`.
NOTE(mrry): This implementation is kept private, to avoid defining
`Optional.__init__()` in the public API.
"""
def __init__(self, variant_tensor, element_spec):
self._variant_tensor = variant_tensor
self._element_spec = element_spec
def has_value(self, name=None):
with ops.colocate_with(self._variant_tensor):
return gen_dataset_ops.optional_has_value(self._variant_tensor, name=name)
def get_value(self, name=None):
# TODO(b/110122868): Consolidate the restructuring logic with similar logic
# in `Iterator.get_next()` and `StructuredFunctionWrapper`.
with ops.name_scope(name, "OptionalGetValue",
[self._variant_tensor]) as scope:
with ops.colocate_with(self._variant_tensor):
result = gen_dataset_ops.optional_get_value(
self._variant_tensor,
name=scope,
output_types=structure.get_flat_tensor_types(self._element_spec),
output_shapes=structure.get_flat_tensor_shapes(self._element_spec))
# NOTE: We do not colocate the deserialization of composite tensors
# because not all ops are guaranteed to have non-GPU kernels.
return structure.from_tensor_list(self._element_spec, result)
@property
def element_spec(self):
return self._element_spec
@property
def _type_spec(self):
return OptionalSpec.from_value(self)
@tf_export(
"OptionalSpec", v1=["OptionalSpec", "data.experimental.OptionalStructure"])
class OptionalSpec(type_spec.TypeSpec):
"""Type specification for `tf.experimental.Optional`.
For instance, `tf.OptionalSpec` can be used to define a tf.function that takes
`tf.experimental.Optional` as an input argument:
>>> @tf.function(input_signature=[tf.OptionalSpec(
... tf.TensorSpec(shape=(), dtype=tf.int32, name=None))])
... def maybe_square(optional):
... if optional.has_value():
... x = optional.get_value()
... return x * x
... return -1
>>> optional = tf.experimental.Optional.from_value(5)
>>> print(maybe_square(optional))
tf.Tensor(25, shape=(), dtype=int32)
Attributes:
element_spec: A nested structure of `TypeSpec` objects that represents the
type specification of the optional element.
"""
__slots__ = ["_element_spec"]
def __init__(self, element_spec):
self._element_spec = element_spec
@property
def value_type(self):
return _OptionalImpl
def _serialize(self):
return (self._element_spec,)
@property
def _component_specs(self):
return [tensor_spec.TensorSpec((), dtypes.variant)]
def _to_components(self, value):
return [value._variant_tensor] # pylint: disable=protected-access
def _from_components(self, flat_value):
# pylint: disable=protected-access
return _OptionalImpl(flat_value[0], self._element_spec)
@staticmethod
def from_value(value):
return OptionalSpec(value.element_spec)
def _to_legacy_output_types(self):
return self
def _to_legacy_output_shapes(self):
return self
def _to_legacy_output_classes(self):
return self
|
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,
33,
730,
367,
6144,
1338,
626,
1443,
503,
1443,
440,
2187,
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,
13022,
199,
199,
646,
3816,
199,
199,
504,
3228,
14,
1548,
14,
576,
14,
1974,
492,
5523,
199,
504,
3228,
14,
1548,
14,
4857,
492,
19306,
63,
3128,
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,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
4857,
492,
730,
63,
1650,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3805,
63,
5214,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
2833,
63,
3790,
421,
199,
32,
3249,
63,
3790,
480,
18924,
14,
7012,
401,
298,
576,
14,
18924,
14,
7012,
531,
199,
32,
15383,
14,
6667,
63,
14461,
480,
576,
14,
18924,
14,
7012,
531,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
4879,
8,
16907,
63,
3128,
14,
24039,
3861,
304,
523,
408,
18089,
282,
574,
626,
1443,
503,
1443,
440,
506,
3451,
14,
819,
437,
658,
3249,
14,
18924,
14,
7012,
64,
883,
2954,
314,
754,
402,
376,
3439,
626,
1443,
523,
2449,
465,
282,
574,
12,
7830,
2419,
17026,
376,
1919,
436,
22939,
1337,
6451,
14,
2104,
523,
2893,
12,
658,
3249,
14,
576,
14,
3585,
14,
362,
63,
2184,
63,
305,
63,
4144,
11995,
2529,
282,
523,
658,
3249,
14,
18924,
14,
7012,
64,
626,
1902,
3509,
314,
2163,
1819,
402,
376,
523,
6122,
340,
1373,
3495,
12,
503,
376,
298,
1667,
2,
574,
626,
9126,
314,
1284,
402,
314,
523,
3414,
965,
2757,
13075,
14,
819,
658,
3249,
14,
18924,
14,
7012,
64,
883,
1454,
506,
1202,
543,
1338,
626,
787,
3818,
21602,
523,
370,
658,
3249,
14,
3861,
64,
503,
658,
3249,
14,
24039,
3861,
2313,
819,
7309,
883,
1218,
282,
658,
3249,
14,
18924,
14,
7012,
64,
687,
282,
574,
1808,
314,
523,
658,
504,
63,
585,
11995,
1083,
26,
819,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
523,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
523,
2833,
14,
3861,
8,
549,
12,
2215,
16729,
2152,
29,
2245,
9,
523,
1306,
870,
8,
4144,
14,
362,
63,
585,
1012,
523,
2833,
14,
3861,
8,
2260,
12,
2215,
16729,
2152,
29,
442,
708,
9,
819,
503,
1928,
282,
574,
1808,
314,
658,
1667,
11995,
1083,
26,
819,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
1667,
8,
523,
2263,
257,
2833,
14,
3861,
5307,
8,
1392,
16729,
2152,
29,
3249,
14,
442,
708,
12,
536,
29,
403,
430,
523,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
523,
2833,
14,
3861,
8,
797,
12,
2215,
16729,
2152,
29,
2245,
9,
523,
408,
819,
768,
3175,
14,
10315,
523,
347,
965,
63,
585,
8,
277,
12,
536,
29,
403,
304,
272,
408,
3407,
282,
2345,
626,
22014,
370,
658,
549,
64,
340,
642,
2716,
965,
282,
574,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
272,
2833,
14,
3861,
8,
549,
12,
2215,
16729,
2152,
29,
2245,
9,
339,
3033,
26,
489,
536,
26,
334,
7012,
4959,
437,
536,
367,
314,
2737,
3439,
14,
339,
1803,
26,
489,
437,
6917,
658,
3249,
14,
3861,
64,
402,
730,
658,
3249,
14,
2245,
2313,
272,
408,
272,
746,
4279,
480,
7012,
14,
1989,
63,
585,
16060,
819,
768,
3175,
14,
10315,
523,
347,
664,
63,
585,
8,
277,
12,
536,
29,
403,
304,
272,
408,
3407,
314,
574,
8072,
701,
642,
2716,
14,
339,
982,
642,
2716,
1630,
440,
1172,
282,
574,
334,
73,
14,
69,
14,
658,
277,
14,
1989,
63,
585,
11995,
22014,
370,
272,
658,
797,
29984,
642,
3439,
911,
746,
658,
3249,
14,
2550,
14,
32116,
64,
737,
272,
8836,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
362,
63,
585,
1012,
272,
2833,
14,
3861,
8,
2260,
12,
2215,
16729,
2152,
29,
442,
708,
9,
339,
3033,
26,
489,
536,
26,
334,
7012,
4959,
437,
536,
367,
314,
2737,
3439,
14,
339,
1803,
26,
489,
710,
8072,
574,
14,
272,
408,
272,
746,
4279,
480,
7012,
14,
362,
63,
585,
16060,
819,
768,
3175,
14,
6198,
1829,
523,
347,
1819,
63,
1650,
8,
277,
304,
272,
408,
1918,
730,
8929,
402,
376,
1819,
402,
642,
2716,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
2108,
63,
1650,
9,
272,
2833,
14,
3861,
5307,
8,
1392,
16729,
2152,
29,
3249,
14,
442,
708,
12,
536,
29,
403,
9,
339,
1803,
26,
489,
437,
6032,
5523,
402,
658,
3249,
14,
804,
5307,
64,
2251,
4877,
314,
5523,
402,
376,
489,
1819,
402,
642,
2716,
12,
9176,
314,
730,
402,
8212,
7323,
14,
272,
408,
272,
746,
4279,
480,
7012,
14,
2108,
63
] |
[
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,
33,
730,
367,
6144,
1338,
626,
1443,
503,
1443,
440,
2187,
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,
13022,
199,
199,
646,
3816,
199,
199,
504,
3228,
14,
1548,
14,
576,
14,
1974,
492,
5523,
199,
504,
3228,
14,
1548,
14,
4857,
492,
19306,
63,
3128,
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,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
4857,
492,
730,
63,
1650,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3805,
63,
5214,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
199,
504,
3228,
14,
1548,
14,
1974,
14,
3249,
63,
3790,
492,
2833,
63,
3790,
421,
199,
32,
3249,
63,
3790,
480,
18924,
14,
7012,
401,
298,
576,
14,
18924,
14,
7012,
531,
199,
32,
15383,
14,
6667,
63,
14461,
480,
576,
14,
18924,
14,
7012,
531,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
4879,
8,
16907,
63,
3128,
14,
24039,
3861,
304,
523,
408,
18089,
282,
574,
626,
1443,
503,
1443,
440,
506,
3451,
14,
819,
437,
658,
3249,
14,
18924,
14,
7012,
64,
883,
2954,
314,
754,
402,
376,
3439,
626,
1443,
523,
2449,
465,
282,
574,
12,
7830,
2419,
17026,
376,
1919,
436,
22939,
1337,
6451,
14,
2104,
523,
2893,
12,
658,
3249,
14,
576,
14,
3585,
14,
362,
63,
2184,
63,
305,
63,
4144,
11995,
2529,
282,
523,
658,
3249,
14,
18924,
14,
7012,
64,
626,
1902,
3509,
314,
2163,
1819,
402,
376,
523,
6122,
340,
1373,
3495,
12,
503,
376,
298,
1667,
2,
574,
626,
9126,
314,
1284,
402,
314,
523,
3414,
965,
2757,
13075,
14,
819,
658,
3249,
14,
18924,
14,
7012,
64,
883,
1454,
506,
1202,
543,
1338,
626,
787,
3818,
21602,
523,
370,
658,
3249,
14,
3861,
64,
503,
658,
3249,
14,
24039,
3861,
2313,
819,
7309,
883,
1218,
282,
658,
3249,
14,
18924,
14,
7012,
64,
687,
282,
574,
1808,
314,
523,
658,
504,
63,
585,
11995,
1083,
26,
819,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
523,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
523,
2833,
14,
3861,
8,
549,
12,
2215,
16729,
2152,
29,
2245,
9,
523,
1306,
870,
8,
4144,
14,
362,
63,
585,
1012,
523,
2833,
14,
3861,
8,
2260,
12,
2215,
16729,
2152,
29,
442,
708,
9,
819,
503,
1928,
282,
574,
1808,
314,
658,
1667,
11995,
1083,
26,
819,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
1667,
8,
523,
2263,
257,
2833,
14,
3861,
5307,
8,
1392,
16729,
2152,
29,
3249,
14,
442,
708,
12,
536,
29,
403,
430,
523,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
523,
2833,
14,
3861,
8,
797,
12,
2215,
16729,
2152,
29,
2245,
9,
523,
408,
819,
768,
3175,
14,
10315,
523,
347,
965,
63,
585,
8,
277,
12,
536,
29,
403,
304,
272,
408,
3407,
282,
2345,
626,
22014,
370,
658,
549,
64,
340,
642,
2716,
965,
282,
574,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
1989,
63,
585,
1012,
272,
2833,
14,
3861,
8,
549,
12,
2215,
16729,
2152,
29,
2245,
9,
339,
3033,
26,
489,
536,
26,
334,
7012,
4959,
437,
536,
367,
314,
2737,
3439,
14,
339,
1803,
26,
489,
437,
6917,
658,
3249,
14,
3861,
64,
402,
730,
658,
3249,
14,
2245,
2313,
272,
408,
272,
746,
4279,
480,
7012,
14,
1989,
63,
585,
16060,
819,
768,
3175,
14,
10315,
523,
347,
664,
63,
585,
8,
277,
12,
536,
29,
403,
304,
272,
408,
3407,
314,
574,
8072,
701,
642,
2716,
14,
339,
982,
642,
2716,
1630,
440,
1172,
282,
574,
334,
73,
14,
69,
14,
658,
277,
14,
1989,
63,
585,
11995,
22014,
370,
272,
658,
797,
29984,
642,
3439,
911,
746,
658,
3249,
14,
2550,
14,
32116,
64,
737,
272,
8836,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
362,
63,
585,
1012,
272,
2833,
14,
3861,
8,
2260,
12,
2215,
16729,
2152,
29,
442,
708,
9,
339,
3033,
26,
489,
536,
26,
334,
7012,
4959,
437,
536,
367,
314,
2737,
3439,
14,
339,
1803,
26,
489,
710,
8072,
574,
14,
272,
408,
272,
746,
4279,
480,
7012,
14,
362,
63,
585,
16060,
819,
768,
3175,
14,
6198,
1829,
523,
347,
1819,
63,
1650,
8,
277,
304,
272,
408,
1918,
730,
8929,
402,
376,
1819,
402,
642,
2716,
14,
339,
1306,
2716,
275,
2833,
14,
18924,
14,
7012,
14,
504,
63,
585,
8,
2260,
9,
272,
1306,
870,
8,
4144,
14,
2108,
63,
1650,
9,
272,
2833,
14,
3861,
5307,
8,
1392,
16729,
2152,
29,
3249,
14,
442,
708,
12,
536,
29,
403,
9,
339,
1803,
26,
489,
437,
6032,
5523,
402,
658,
3249,
14,
804,
5307,
64,
2251,
4877,
314,
5523,
402,
376,
489,
1819,
402,
642,
2716,
12,
9176,
314,
730,
402,
8212,
7323,
14,
272,
408,
272,
746,
4279,
480,
7012,
14,
2108,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
kbrebanov/ansible
|
lib/ansible/modules/network/avi/avi_microservicegroup.py
|
3
|
3753
|
#!/usr/bin/python
#
# Created on Aug 25, 2016
# @author: Gaurav Rastogi (grastogi@avinetworks.com)
# Eric Anderson (eanderson@avinetworks.com)
# module_check: supported
#
#
# 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': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: avi_microservicegroup
author: Gaurav Rastogi (grastogi@avinetworks.com)
short_description: Module for setup of MicroServiceGroup Avi RESTful Object
description:
- This module is used to configure MicroServiceGroup object
- more examples at U(https://github.com/avinetworks/devops)
requirements: [ avisdk ]
version_added: "2.4"
options:
state:
description:
- The state that should be applied on the entity.
default: present
choices: ["absent","present"]
created_by:
description:
- Creator name.
description:
description:
- User defined description for the object.
name:
description:
- Name of the microservice group.
required: true
service_refs:
description:
- Configure microservice(es).
- It is a reference to an object of type microservice.
tenant_ref:
description:
- It is a reference to an object of type tenant.
url:
description:
- Avi controller URL of the object.
uuid:
description:
- Uuid of the microservice group.
extends_documentation_fragment:
- avi
'''
EXAMPLES = '''
- name: Create a Microservice Group that can be used for setting up Network security policy
avi_microservicegroup:
controller: ''
username: ''
password: ''
description: Group created by my Secure My App UI.
name: vs-msg-marketing
tenant_ref: admin
'''
RETURN = '''
obj:
description: MicroServiceGroup (api/microservicegroup) object
returned: success, changed
type: dict
'''
from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.network.avi.avi import (
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
except ImportError:
HAS_AVI = False
def main():
argument_specs = dict(
state=dict(default='present',
choices=['absent', 'present']),
created_by=dict(type='str',),
description=dict(type='str',),
name=dict(type='str', required=True),
service_refs=dict(type='list',),
tenant_ref=dict(type='str',),
url=dict(type='str',),
uuid=dict(type='str',),
)
argument_specs.update(avi_common_argument_spec())
module = AnsibleModule(
argument_spec=argument_specs, supports_check_mode=True)
if not HAS_AVI:
return module.fail_json(msg=(
'Avi python API SDK (avisdk>=17.1) is not installed. '
'For more details visit https://github.com/avinetworks/sdk.'))
return avi_ansible_api(module, 'microservicegroup',
set([]))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
18208,
641,
25298,
5661,
12,
7800,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21661,
63,
6453,
29409,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
27022,
3167,
2448,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
27022,
3167,
2448,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
2266,
1881,
937,
272,
2737,
63,
991,
26,
267,
1369,
26,
288,
446,
9750,
707,
536,
14,
272,
1369,
26,
267,
1369,
26,
288,
446,
2876,
3247,
1369,
367,
314,
909,
14,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
9967,
1364,
1572,
14,
267,
1415,
26,
2549,
272,
2435,
63,
7655,
26,
267,
1369,
26,
288,
446,
15453,
9967,
1364,
8,
397,
680,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
9967,
1364,
14,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
738,
1535,
402,
314,
9967,
1364,
1572,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
421,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
282,
27022,
1364,
5611,
626,
883,
506,
1202,
367,
4260,
1536,
7220,
6391,
4592,
272,
21661,
63,
6453,
29409,
26,
489,
7614,
26,
2125,
489,
3434,
26,
2125,
489,
2505,
26,
2125,
489,
1369,
26,
5611,
2737,
701,
3002,
30894,
4932,
4693,
14041,
14,
489,
536,
26,
8118,
13,
1328,
13,
1657,
13800,
489,
8261,
63,
1121,
26,
4628,
199,
2344,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
27022,
3167,
2448,
334,
1246,
15,
6453,
29409,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
7509,
63,
32636,
12,
21661,
63,
4853,
63,
1246,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2737,
63,
991,
29,
807,
8,
466,
534,
495,
5529,
267,
1369,
29,
807,
8,
466,
534,
495,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
2435,
63,
7655,
29,
807,
8,
466,
534,
513,
5529,
267,
8261,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
1166,
29,
807,
8,
466,
534,
495,
5529,
267,
5377,
29,
807,
8,
466,
534,
495,
5529,
272,
776,
272,
1423,
63,
7273,
14,
873,
8,
7194,
63,
2330,
63,
2094,
63,
1650,
1012,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
7273,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
272,
340,
440,
7509,
63,
32636,
26,
267,
372,
859,
14,
1633,
63,
1001,
8,
1328,
2687,
288,
283,
33,
433,
2366,
3261,
15610,
334,
1214,
374,
6341,
8119,
1196,
14,
17,
9,
365,
440,
4903,
14,
283,
288,
283,
1858,
1655,
2436,
5684,
4178,
921,
5031,
14,
957,
15,
31808,
15,
9277,
12459,
272,
372,
21661,
63,
4853,
63,
1246,
8,
578,
12,
283,
6453,
29409,
297,
2574,
663,
26064,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
18208,
641,
25298,
5661,
12,
7800,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21661,
63,
6453,
29409,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
27022,
3167,
2448,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
27022,
3167,
2448,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
2266,
1881,
937,
272,
2737,
63,
991,
26,
267,
1369,
26,
288,
446,
9750,
707,
536,
14,
272,
1369,
26,
267,
1369,
26,
288,
446,
2876,
3247,
1369,
367,
314,
909,
14,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
9967,
1364,
1572,
14,
267,
1415,
26,
2549,
272,
2435,
63,
7655,
26,
267,
1369,
26,
288,
446,
15453,
9967,
1364,
8,
397,
680,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
9967,
1364,
14,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
738,
1535,
402,
314,
9967,
1364,
1572,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
421,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
282,
27022,
1364,
5611,
626,
883,
506,
1202,
367,
4260,
1536,
7220,
6391,
4592,
272,
21661,
63,
6453,
29409,
26,
489,
7614,
26,
2125,
489,
3434,
26,
2125,
489,
2505,
26,
2125,
489,
1369,
26,
5611,
2737,
701,
3002,
30894,
4932,
4693,
14041,
14,
489,
536,
26,
8118,
13,
1328,
13,
1657,
13800,
489,
8261,
63,
1121,
26,
4628,
199,
2344,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
27022,
3167,
2448,
334,
1246,
15,
6453,
29409,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
7509,
63,
32636,
12,
21661,
63,
4853,
63,
1246,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2737,
63,
991,
29,
807,
8,
466,
534,
495,
5529,
267,
1369,
29,
807,
8,
466,
534,
495,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
267,
2435,
63,
7655,
29,
807,
8,
466,
534,
513,
5529,
267,
8261,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
1166,
29,
807,
8,
466,
534,
495,
5529,
267,
5377,
29,
807,
8,
466,
534,
495,
5529,
272,
776,
272,
1423,
63,
7273,
14,
873,
8,
7194,
63,
2330,
63,
2094,
63,
1650,
1012,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
2094,
63,
7273,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
272,
340,
440,
7509,
63,
32636,
26,
267,
372,
859,
14,
1633,
63,
1001,
8,
1328,
2687,
288,
283,
33,
433,
2366,
3261,
15610,
334,
1214,
374,
6341,
8119,
1196,
14,
17,
9,
365,
440,
4903,
14,
283,
288,
283,
1858,
1655,
2436,
5684,
4178,
921,
5031,
14,
957,
15,
31808,
15,
9277,
12459,
272,
372,
21661,
63,
4853,
63,
1246,
8,
578,
12,
283,
6453,
29409,
297,
2574,
663,
26064,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
acerix/doge-millionaire
|
pycoin/tx/script/der.py
|
14
|
4582
|
# -*- coding: utf-8 -*-
"""
Deal with DER encoding and decoding.
Adapted from python-ecdsa at https://github.com/warner/python-ecdsa
Copyright (c) 2010 Brian Warner
Portions written in 2005 by Peter Pearson and placed in the public domain.
The MIT License (MIT)
Copyright (c) 2013 by Richard Kiss
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import binascii
bytes_from_int = chr if bytes == str else lambda x: bytes([x])
class UnexpectedDER(Exception):
pass
def encode_integer(r):
assert r >= 0 # can't support negative numbers yet
h = "%x" % r
if len(h)%2:
h = "0" + h
s = binascii.unhexlify(h.encode("utf8"))
if ord(s[:1]) <= 0x7f:
return b"\x02" + bytes_from_int(len(s)) + s
else:
# DER integers are two's complement, so if the first byte is
# 0x80-0xff then we need an extra 0x00 byte to prevent it from
# looking negative.
return b"\x02" + bytes_from_int(len(s)+1) + b"\x00" + s
def encode_sequence(*encoded_pieces):
total_len = sum([len(p) for p in encoded_pieces])
return b"\x30" + encode_length(total_len) + b"".join(encoded_pieces)
def remove_sequence(string):
if not string.startswith(b"\x30"):
raise UnexpectedDER(
"wanted sequence (0x30), got string length %d %s" % (
len(string), binascii.hexlify(string[:10])))
length, lengthlength = read_length(string[1:])
endseq = 1+lengthlength+length
return string[1+lengthlength:endseq], string[endseq:]
def remove_integer(string, use_broken_open_ssl_mechanism=False):
# OpenSSL treats DER-encoded negative integers (that have their most significant
# bit set) as positive integers. Some apps depend upon this bug.
if not string.startswith(b"\x02"):
raise UnexpectedDER("wanted integer (0x02), got 0x%02x" %
ord(string[:1]))
length, llen = read_length(string[1:])
if len(string) < 1+llen+length:
raise UnexpectedDER("ran out of integer bytes")
numberbytes = string[1+llen:1+llen+length]
rest = string[1+llen+length:]
v = int(binascii.hexlify(numberbytes), 16)
if ord(numberbytes[:1]) >= 0x80:
if not use_broken_open_ssl_mechanism:
v -= (1<<(8*length))
return v, rest
def encode_length(l):
assert l >= 0
if l < 0x80:
return bytes_from_int(l)
s = "%x" % l
if len(s)%2:
s = "0"+s
s = binascii.unhexlify(s)
llen = len(s)
return bytes_from_int(0x80|llen) + s
def read_length(string):
s0 = ord(string[:1])
if not (s0 & 0x80):
# short form
return (s0 & 0x7f), 1
# else long-form: b0&0x7f is number of additional base256 length bytes,
# big-endian
llen = s0 & 0x7f
if llen > len(string)-1:
raise UnexpectedDER("ran out of length bytes")
return int(binascii.hexlify(string[1:1+llen]), 16), 1+llen
def sigencode_der(r, s):
return encode_sequence(encode_integer(r), encode_integer(s))
def sigdecode_der(sig_der, use_broken_open_ssl_mechanism=False):
rs_strings, empty = remove_sequence(sig_der)
if empty != b"":
raise UnexpectedDER("trailing junk after DER sig: %s" %
binascii.hexlify(empty))
r, rest = remove_integer(rs_strings, use_broken_open_ssl_mechanism=use_broken_open_ssl_mechanism)
s, empty = remove_integer(rest, use_broken_open_ssl_mechanism=use_broken_open_ssl_mechanism)
if empty != b"":
raise UnexpectedDER("trailing junk after DER numbers: %s" %
binascii.hexlify(empty))
return r, s
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
872,
279,
543,
577,
540,
2644,
436,
15952,
14,
199,
199,
2767,
18309,
687,
2366,
13,
825,
24760,
737,
4178,
921,
5031,
14,
957,
15,
4050,
281,
15,
1548,
13,
825,
24760,
199,
7384,
334,
67,
9,
7129,
699,
18429,
644,
1060,
281,
199,
48,
18434,
5313,
315,
11811,
701,
22912,
510,
2210,
834,
436,
15090,
315,
314,
4575,
2881,
14,
421,
199,
1918,
10697,
844,
334,
13965,
9,
199,
199,
7384,
334,
67,
9,
6171,
701,
30846,
1005,
1804,
19857,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
199,
646,
14755,
199,
199,
2394,
63,
504,
63,
442,
275,
8678,
340,
2783,
508,
620,
587,
2400,
671,
26,
2783,
779,
88,
566,
199,
199,
533,
25345,
11733,
8,
1726,
304,
272,
986,
199,
199,
318,
3752,
63,
4115,
8,
82,
304,
272,
702,
519,
2356,
378,
327,
883,
1133,
2291,
6946,
5579,
5966,
272,
394,
275,
2071,
88,
2,
450,
519,
272,
340,
822,
8,
72,
19656,
18,
26,
267,
394,
275,
298,
16,
2,
435,
394,
272,
308,
275,
14755,
14,
324,
20677,
8,
72,
14,
2143,
480,
1624,
24,
2237,
272,
340,
6206,
8,
83,
1491,
17,
566,
2695,
378,
88,
23,
70,
26,
267,
372,
330,
3212,
88,
996,
2,
435,
2783,
63,
504,
63,
442,
8,
552,
8,
83,
430,
435,
308,
272,
587,
26,
267,
327,
577,
540,
9446,
787,
2877,
1159,
2831,
434,
12,
880,
340,
314,
1642,
3696,
365,
267,
327,
378,
88,
1257,
13,
16,
3581,
2066,
781,
1929,
376,
2402,
378,
88,
383,
3696,
370,
7981,
652,
687,
267,
327,
10023,
6946,
14,
267,
372,
330,
3212,
88,
996,
2,
435,
2783,
63,
504,
63,
442,
8,
552,
8,
83,
6393,
17,
9,
435,
330,
3212,
88,
383,
2,
435,
308,
199,
199,
318,
3752,
63,
4041,
2031,
8167,
63,
15655,
304,
272,
3141,
63,
552,
275,
3089,
779,
552,
8,
80,
9,
367,
299,
315,
5737,
63,
15655,
566,
272,
372,
330,
3212,
88,
1216,
2,
435,
3752,
63,
1267,
8,
2923,
63,
552,
9,
435,
330,
25148,
904,
8,
8167,
63,
15655,
9,
199,
199,
318,
2813,
63,
4041,
8,
875,
304,
272,
340,
440,
1059,
14,
2460,
8,
66,
3212,
88,
1216,
2349,
267,
746,
25345,
11733,
8,
288,
298,
19361,
3414,
334,
16,
88,
1216,
395,
4788,
1059,
2582,
450,
68,
450,
83,
2,
450,
334,
355,
822,
8,
875,
395,
14755,
14,
20677,
8,
875,
1491,
709,
11845,
272,
2582,
12,
2582,
1267,
275,
1586,
63,
1267,
8,
875,
59,
17,
5728,
272,
1284,
3610,
275,
413,
11,
1267,
1267,
11,
1267,
272,
372,
1059,
59,
17,
11,
1267,
1267,
26,
500,
3610,
467,
1059,
59,
500,
3610,
2938,
199,
199,
318,
2813,
63,
4115,
8,
875,
12,
675,
63,
15697,
63,
1490,
63,
4266,
63,
278,
11993,
29,
797,
304,
272,
327,
14296,
20991,
1956,
577,
540,
13,
8167,
6946,
9446,
334,
9099,
1172,
3932,
4750,
16474,
272,
327,
4546,
663,
9,
465,
7317,
9446,
14,
6601,
8686,
11687,
12188,
642,
6519,
14,
272,
340,
440,
1059,
14,
2460,
8,
66,
3212,
88,
996,
2349,
267,
746,
25345,
11733,
480,
19361,
3000,
334,
16,
88,
996,
395,
4788,
378,
88,
5,
996,
88,
2,
450,
1169,
6206,
8,
875,
1491,
17,
2459,
272,
2582,
12,
634,
552,
275,
1586,
63,
1267,
8,
875,
59,
17,
5728,
272,
340,
822,
8,
875,
9,
665,
413,
11,
76,
552,
11,
1267,
26,
267,
746,
25345,
11733,
480,
1312,
734,
402,
3000,
2783,
531,
272,
1329,
2394,
275,
1059,
59,
17,
11,
76,
552,
26,
17,
11,
76,
552,
11,
1267,
61,
272,
4618,
275,
1059,
59,
17,
11,
76,
552,
11,
1267,
2938,
272,
373,
275,
1109,
8,
27460,
14,
20677,
8,
1955,
2394,
395,
3193,
9,
272,
340,
6206,
8,
1955,
2394,
1491,
17,
566,
2356,
378,
88,
1257,
26,
267,
340,
440,
675,
63,
15697,
63,
1490,
63,
4266,
63,
278,
11993,
26,
288,
373,
4862,
334,
17,
8999,
8,
24,
10,
1267,
430,
272,
372,
373,
12,
4618,
199,
199,
318,
3752,
63,
1267,
8,
76,
304,
272,
702,
634,
2356,
378,
272,
340,
634,
665,
378,
88,
1257,
26,
267,
372,
2783,
63,
504,
63,
442,
8,
76,
9,
272,
308,
275,
2071,
88,
2,
450,
634,
272,
340,
822,
8,
83,
19656,
18,
26,
267,
308,
275,
298,
16,
7709,
83,
272,
308,
275,
14755,
14,
324,
20677,
8,
83,
9,
272,
634,
552,
275,
822,
8,
83,
9,
272,
372,
2783,
63,
504,
63,
442,
8,
16,
88,
1257,
92,
76,
552,
9,
435,
308,
199,
199,
318,
1586,
63,
1267,
8,
875,
304,
272,
308,
16,
275,
6206,
8,
875,
1491,
17,
566,
272,
340,
440,
334,
83,
16,
1253,
378,
88,
1257,
304,
267,
327,
3974,
1824,
267,
372,
334,
83,
16,
1253,
378,
88,
23,
70,
395,
413,
272
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
872,
279,
543,
577,
540,
2644,
436,
15952,
14,
199,
199,
2767,
18309,
687,
2366,
13,
825,
24760,
737,
4178,
921,
5031,
14,
957,
15,
4050,
281,
15,
1548,
13,
825,
24760,
199,
7384,
334,
67,
9,
7129,
699,
18429,
644,
1060,
281,
199,
48,
18434,
5313,
315,
11811,
701,
22912,
510,
2210,
834,
436,
15090,
315,
314,
4575,
2881,
14,
421,
199,
1918,
10697,
844,
334,
13965,
9,
199,
199,
7384,
334,
67,
9,
6171,
701,
30846,
1005,
1804,
19857,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
199,
646,
14755,
199,
199,
2394,
63,
504,
63,
442,
275,
8678,
340,
2783,
508,
620,
587,
2400,
671,
26,
2783,
779,
88,
566,
199,
199,
533,
25345,
11733,
8,
1726,
304,
272,
986,
199,
199,
318,
3752,
63,
4115,
8,
82,
304,
272,
702,
519,
2356,
378,
327,
883,
1133,
2291,
6946,
5579,
5966,
272,
394,
275,
2071,
88,
2,
450,
519,
272,
340,
822,
8,
72,
19656,
18,
26,
267,
394,
275,
298,
16,
2,
435,
394,
272,
308,
275,
14755,
14,
324,
20677,
8,
72,
14,
2143,
480,
1624,
24,
2237,
272,
340,
6206,
8,
83,
1491,
17,
566,
2695,
378,
88,
23,
70,
26,
267,
372,
330,
3212,
88,
996,
2,
435,
2783,
63,
504,
63,
442,
8,
552,
8,
83,
430,
435,
308,
272,
587,
26,
267,
327,
577,
540,
9446,
787,
2877,
1159,
2831,
434,
12,
880,
340,
314,
1642,
3696,
365,
267,
327,
378,
88,
1257,
13,
16,
3581,
2066,
781,
1929,
376,
2402,
378,
88,
383,
3696,
370,
7981,
652,
687,
267,
327,
10023,
6946,
14,
267,
372,
330,
3212,
88,
996,
2,
435,
2783,
63,
504,
63,
442,
8,
552,
8,
83,
6393,
17,
9,
435,
330,
3212,
88,
383,
2,
435,
308,
199,
199,
318,
3752,
63,
4041,
2031,
8167,
63,
15655,
304,
272,
3141,
63,
552,
275,
3089,
779,
552,
8,
80,
9,
367,
299,
315,
5737,
63,
15655,
566,
272,
372,
330,
3212,
88,
1216,
2,
435,
3752,
63,
1267,
8,
2923,
63,
552,
9,
435,
330,
25148,
904,
8,
8167,
63,
15655,
9,
199,
199,
318,
2813,
63,
4041,
8,
875,
304,
272,
340,
440,
1059,
14,
2460,
8,
66,
3212,
88,
1216,
2349,
267,
746,
25345,
11733,
8,
288,
298,
19361,
3414,
334,
16,
88,
1216,
395,
4788,
1059,
2582,
450,
68,
450,
83,
2,
450,
334,
355,
822,
8,
875,
395,
14755,
14,
20677,
8,
875,
1491,
709,
11845,
272,
2582,
12,
2582,
1267,
275,
1586,
63,
1267,
8,
875,
59,
17,
5728,
272,
1284,
3610,
275,
413,
11,
1267,
1267,
11,
1267,
272,
372,
1059,
59,
17,
11,
1267,
1267,
26,
500,
3610,
467,
1059,
59,
500,
3610,
2938,
199,
199,
318,
2813,
63,
4115,
8,
875,
12,
675,
63,
15697,
63,
1490,
63,
4266,
63,
278,
11993,
29,
797,
304,
272,
327,
14296,
20991,
1956,
577,
540,
13,
8167,
6946,
9446,
334,
9099,
1172,
3932,
4750,
16474,
272,
327,
4546,
663,
9,
465,
7317,
9446,
14,
6601,
8686,
11687,
12188,
642,
6519,
14,
272,
340,
440,
1059,
14,
2460,
8,
66,
3212,
88,
996,
2349,
267,
746,
25345,
11733,
480,
19361,
3000,
334,
16,
88,
996,
395,
4788,
378,
88,
5,
996,
88,
2,
450,
1169,
6206,
8,
875,
1491,
17,
2459,
272,
2582,
12,
634,
552,
275,
1586,
63,
1267,
8,
875,
59,
17,
5728,
272,
340,
822,
8,
875,
9,
665,
413,
11,
76,
552,
11,
1267,
26,
267,
746,
25345,
11733,
480,
1312,
734,
402,
3000,
2783,
531,
272,
1329,
2394,
275,
1059,
59,
17,
11,
76,
552,
26,
17,
11,
76,
552,
11,
1267,
61,
272,
4618,
275,
1059,
59,
17,
11,
76,
552,
11,
1267,
2938,
272,
373,
275,
1109,
8,
27460,
14,
20677,
8,
1955,
2394,
395,
3193,
9,
272,
340,
6206,
8,
1955,
2394,
1491,
17,
566,
2356,
378,
88,
1257,
26,
267,
340,
440,
675,
63,
15697,
63,
1490,
63,
4266,
63,
278,
11993,
26,
288,
373,
4862,
334,
17,
8999,
8,
24,
10,
1267,
430,
272,
372,
373,
12,
4618,
199,
199,
318,
3752,
63,
1267,
8,
76,
304,
272,
702,
634,
2356,
378,
272,
340,
634,
665,
378,
88,
1257,
26,
267,
372,
2783,
63,
504,
63,
442,
8,
76,
9,
272,
308,
275,
2071,
88,
2,
450,
634,
272,
340,
822,
8,
83,
19656,
18,
26,
267,
308,
275,
298,
16,
7709,
83,
272,
308,
275,
14755,
14,
324,
20677,
8,
83,
9,
272,
634,
552,
275,
822,
8,
83,
9,
272,
372,
2783,
63,
504,
63,
442,
8,
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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
] |
mmeeks/bootchart
|
pybootchartgui/process_tree.py
|
4
|
12259
|
# This file is part of pybootchartgui.
# pybootchartgui 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.
# pybootchartgui 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 pybootchartgui. If not, see <http://www.gnu.org/licenses/>.
class ProcessTree:
"""ProcessTree encapsulates a process tree. The tree is built from log files
retrieved during the boot process. When building the process tree, it is
pruned and merged in order to be able to visualize it in a comprehensible
manner.
The following pruning techniques are used:
* idle processes that keep running during the last process sample
(which is a heuristic for a background processes) are removed,
* short-lived processes (i.e. processes that only live for the
duration of two samples or less) are removed,
* the processes used by the boot logger are removed,
* exploders (i.e. processes that are known to spawn huge meaningless
process subtrees) have their subtrees merged together,
* siblings (i.e. processes with the same command line living
concurrently -- thread heuristic) are merged together,
* process runs (unary trees with processes sharing the command line)
are merged together.
"""
LOGGER_PROC = 'bootchartd'
EXPLODER_PROCESSES = set(['hwup'])
def __init__(self, writer, kernel, psstats, sample_period,
monitoredApp, prune, idle, taskstats,
accurate_parentage, for_testing = False):
self.writer = writer
self.process_tree = []
self.taskstats = taskstats
if psstats is None:
process_list = kernel
elif kernel is None:
process_list = psstats.process_map.values()
else:
process_list = list(kernel) + list(psstats.process_map.values())
self.process_list = sorted(process_list, key = lambda p: p.pid)
self.sample_period = sample_period
self.build()
if not accurate_parentage:
self.update_ppids_for_daemons(self.process_list)
self.start_time = self.get_start_time(self.process_tree)
self.end_time = self.get_end_time(self.process_tree)
self.duration = self.end_time - self.start_time
self.idle = idle
if for_testing:
return
removed = self.merge_logger(self.process_tree, self.LOGGER_PROC, monitoredApp, False)
writer.status("merged %i logger processes" % removed)
if prune:
p_processes = self.prune(self.process_tree, None)
p_exploders = self.merge_exploders(self.process_tree, self.EXPLODER_PROCESSES)
p_threads = self.merge_siblings(self.process_tree)
p_runs = self.merge_runs(self.process_tree)
writer.status("pruned %i process, %i exploders, %i threads, and %i runs" % (p_processes, p_exploders, p_threads, p_runs))
self.sort(self.process_tree)
self.start_time = self.get_start_time(self.process_tree)
self.end_time = self.get_end_time(self.process_tree)
self.duration = self.end_time - self.start_time
self.num_proc = self.num_nodes(self.process_tree)
def build(self):
"""Build the process tree from the list of top samples."""
self.process_tree = []
for proc in self.process_list:
if not proc.parent:
self.process_tree.append(proc)
else:
proc.parent.child_list.append(proc)
def sort(self, process_subtree):
"""Sort process tree."""
for p in process_subtree:
p.child_list.sort(key = lambda p: p.pid)
self.sort(p.child_list)
def num_nodes(self, process_list):
"Counts the number of nodes in the specified process tree."""
nodes = 0
for proc in process_list:
nodes = nodes + self.num_nodes(proc.child_list)
return nodes + len(process_list)
def get_start_time(self, process_subtree):
"""Returns the start time of the process subtree. This is the start
time of the earliest process.
"""
if not process_subtree:
return 100000000
return min( [min(proc.start_time, self.get_start_time(proc.child_list)) for proc in process_subtree] )
def get_end_time(self, process_subtree):
"""Returns the end time of the process subtree. This is the end time
of the last collected sample.
"""
if not process_subtree:
return -100000000
return max( [max(proc.start_time + proc.duration, self.get_end_time(proc.child_list)) for proc in process_subtree] )
def get_max_pid(self, process_subtree):
"""Returns the max PID found in the process tree."""
if not process_subtree:
return -100000000
return max( [max(proc.pid, self.get_max_pid(proc.child_list)) for proc in process_subtree] )
def update_ppids_for_daemons(self, process_list):
"""Fedora hack: when loading the system services from rc, runuser(1)
is used. This sets the PPID of all daemons to 1, skewing
the process tree. Try to detect this and set the PPID of
these processes the PID of rc.
"""
rcstartpid = -1
rcendpid = -1
rcproc = None
for p in process_list:
if p.cmd == "rc" and p.ppid // 1000 == 1:
rcproc = p
rcstartpid = p.pid
rcendpid = self.get_max_pid(p.child_list)
if rcstartpid != -1 and rcendpid != -1:
for p in process_list:
if p.pid > rcstartpid and p.pid < rcendpid and p.ppid // 1000 == 1:
p.ppid = rcstartpid
p.parent = rcproc
for p in process_list:
p.child_list = []
self.build()
def prune(self, process_subtree, parent):
"""Prunes the process tree by removing idle processes and processes
that only live for the duration of a single top sample. Sibling
processes with the same command line (i.e. threads) are merged
together. This filters out sleepy background processes, short-lived
processes and bootcharts' analysis tools.
"""
def is_idle_background_process_without_children(p):
process_end = p.start_time + p.duration
return not p.active and \
process_end >= self.start_time + self.duration and \
p.start_time > self.start_time and \
p.duration > 0.9 * self.duration and \
self.num_nodes(p.child_list) == 0
num_removed = 0
idx = 0
while idx < len(process_subtree):
p = process_subtree[idx]
if parent != None or len(p.child_list) == 0:
prune = False
if is_idle_background_process_without_children(p):
prune = True
elif p.duration <= 2 * self.sample_period:
# short-lived process
prune = True
if prune:
process_subtree.pop(idx)
for c in p.child_list:
process_subtree.insert(idx, c)
num_removed += 1
continue
else:
num_removed += self.prune(p.child_list, p)
else:
num_removed += self.prune(p.child_list, p)
idx += 1
return num_removed
def filter_subtree(self, tree, filter_fn):
"""
Filter a tree depending on filter function that takes the process as
argument.
"""
processes = []
for p in tree:
if filter_fn(p):
processes.append(p)
if p.child_list:
processes += self.filter_subtree(p.child_list, filter_fn)
return processes
def merge_logger(self, process_subtree, logger_proc, monitored_app, app_tree):
"""Merges the logger's process subtree. The logger will typically
spawn lots of sleep and cat processes, thus polluting the
process tree.
"""
num_removed = 0
loggers = self.filter_subtree(process_subtree, lambda x: x.cmd == logger_proc)
for p in loggers:
for child in p.child_list:
if monitored_app and child.cmd == monitored_app:
continue
self.merge_processes(p, child)
p.child_list.remove(child)
num_removed += 1
return num_removed
def merge_exploders(self, process_subtree, processes):
"""Merges specific process subtrees (used for processes which usually
spawn huge meaningless process trees).
"""
num_removed = 0
for p in process_subtree:
if processes in processes and len(p.child_list) > 0:
subtreemap = self.getProcessMap(p.child_list)
for child in subtreemap.values():
self.merge_processes(p, child)
num_removed += len(subtreemap)
p.child_list = []
p.cmd += " (+)"
else:
num_removed += self.merge_exploders(p.child_list, processes)
return num_removed
def merge_siblings(self, process_subtree):
"""Merges thread processes. Sibling processes with the same command
line are merged together.
"""
num_removed = 0
idx = 0
while idx < len(process_subtree)-1:
p = process_subtree[idx]
nextp = process_subtree[idx+1]
if nextp.cmd == p.cmd:
process_subtree.pop(idx+1)
idx -= 1
num_removed += 1
p.child_list.extend(nextp.child_list)
self.merge_processes(p, nextp)
num_removed += self.merge_siblings(p.child_list)
idx += 1
if len(process_subtree) > 0:
p = process_subtree[-1]
num_removed += self.merge_siblings(p.child_list)
return num_removed
def merge_runs(self, process_subtree):
"""Merges process runs. Single child processes which share the same
command line with the parent are merged.
"""
num_removed = 0
idx = 0
while idx < len(process_subtree):
p = process_subtree[idx]
if len(p.child_list) == 1 and p.child_list[0].cmd == p.cmd:
child = p.child_list[0]
p.child_list = list(child.child_list)
self.merge_processes(p, child)
num_removed += 1
continue
num_removed += self.merge_runs(p.child_list)
idx += 1
return num_removed
def merge_processes(self, p1, p2):
"""Merges two process' samples."""
p1.samples.extend(p2.samples)
p1.samples.sort( key = lambda p: p.time )
p1time = p1.start_time
p2time = p2.start_time
p1.start_time = min(p1time, p2time)
pendtime = max(p1time + p1.duration, p2time + p2.duration)
p1.duration = pendtime - p1.start_time
def _dump_tree(self, process_subtree, shift=0):
"""Get a tree printed throught the writer, helpful when debugging."""
idx = 0
while idx < len(process_subtree):
p = process_subtree[idx]
self._dump_tree(p.child_list, shift + 4)
idx += 1
self.writer.status("%s%s %d %s" % (" " * shift, p.cmd, p.pid // 1000, "(collector)" if p.cmd == self.LOGGER_PROC or (p.parent and p.parent.cmd == self.LOGGER_PROC) else ""))
|
gpl-2.0
|
[
3,
221,
961,
570,
365,
1777,
402,
1134,
4930,
9019,
5885,
14,
199,
199,
3,
221,
1134,
4930,
9019,
5885,
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,
199,
3,
221,
1134,
4930,
9019,
5885,
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,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
1134,
4930,
9019,
5885,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
533,
7132,
3987,
26,
272,
408,
3498,
3987,
22667,
15409,
282,
2112,
3123,
14,
221,
710,
3123,
365,
6137,
687,
943,
1584,
2126,
12396,
5309,
314,
8498,
2112,
14,
221,
3979,
10015,
314,
2112,
3123,
12,
652,
365,
2126,
29501,
379,
436,
9545,
315,
1865,
370,
506,
7688,
370,
13104,
794,
652,
315,
282,
1013,
22868,
1164,
2126,
30800,
14,
10817,
710,
2569,
29501,
316,
32414,
83,
787,
1202,
26,
398,
627,
15072,
10358,
626,
4215,
3879,
5309,
314,
2061,
2112,
2690,
881,
334,
6777,
365,
282,
25332,
367,
282,
8020,
10358,
9,
787,
4829,
12,
267,
627,
3974,
13,
317,
1354,
10358,
334,
73,
14,
69,
14,
10358,
626,
1454,
12166,
367,
314,
881,
7373,
402,
2877,
5845,
503,
6656,
9,
787,
4829,
12,
267,
627,
314,
10358,
1202,
701,
314,
8498,
2512,
787,
4829,
12,
267,
627,
15868,
7735,
334,
73,
14,
69,
14,
10358,
626,
787,
6040,
370,
15187,
27791,
11150,
2003,
881,
2112,
1007,
14635,
9,
1172,
3932,
1007,
14635,
9545,
10451,
12,
267,
627,
31871,
334,
73,
14,
69,
14,
10358,
543,
314,
2011,
1414,
1004,
1212,
4007,
881,
406,
19767,
1553,
2462,
25332,
9,
787,
9545,
10451,
12,
267,
627,
2112,
7858,
334,
13124,
14416,
543,
10358,
26994,
314,
1414,
1004,
9,
881,
787,
9545,
10451,
14,
339,
408,
272,
20184,
63,
6072,
275,
283,
4930,
9019,
68,
7,
272,
3651,
48,
1484,
11733,
63,
10494,
654,
275,
663,
2941,
8090,
384,
1105,
339,
347,
636,
826,
721,
277,
12,
7060,
12,
5114,
12,
7347,
3200,
12,
2690,
63,
5191,
12,
326,
23821,
2640,
12,
27619,
12,
15072,
12,
2120,
3200,
12,
326,
23189,
63,
1708,
474,
12,
367,
63,
4776,
275,
756,
304,
267,
291,
14,
5491,
275,
7060,
267,
291,
14,
1412,
63,
2350,
275,
942,
267,
291,
14,
1765,
3200,
275,
2120,
3200,
267,
340,
7347,
3200,
365,
488,
26,
288,
2112,
63,
513,
275,
5114,
267,
916,
5114,
365,
488,
26,
288,
2112,
63,
513,
275,
7347,
3200,
14,
1412,
63,
1130,
14,
1459,
342,
267,
587,
26,
288,
2112,
63,
513,
275,
769,
8,
4989,
9,
435,
769,
8,
1190,
3200,
14,
1412,
63,
1130,
14,
1459,
1012,
267,
291,
14,
1412,
63,
513,
275,
3355,
8,
1412,
63,
513,
12,
790,
275,
2400,
299,
26,
299,
14,
3150,
9,
267,
291,
14,
3271,
63,
5191,
275,
2690,
63,
5191,
398,
291,
14,
1506,
342,
267,
340,
440,
23189,
63,
1708,
474,
26,
288,
291,
14,
873,
63,
802,
1580,
63,
509,
63,
10824,
83,
8,
277,
14,
1412,
63,
513,
9,
398,
291,
14,
928,
63,
521,
275,
291,
14,
362,
63,
928,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
500,
63,
521,
275,
291,
14,
362,
63,
500,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
5553,
275,
291,
14,
500,
63,
521,
446,
291,
14,
928,
63,
521,
267,
291,
14,
12000,
275,
15072,
398,
340,
367,
63,
4776,
26,
288,
372,
398,
4829,
275,
291,
14,
5628,
63,
2921,
8,
277,
14,
1412,
63,
2350,
12,
291,
14,
10186,
63,
6072,
12,
23821,
2640,
12,
756,
9,
267,
7060,
14,
1205,
480,
15269,
450,
73,
2512,
10358,
2,
450,
4829,
9,
398,
340,
27619,
26,
288,
299,
63,
11816,
275,
291,
14,
22268,
8,
277,
14,
1412,
63,
2350,
12,
488,
9,
288,
299,
63,
16971,
7735,
275,
291,
14,
5628,
63,
16971,
7735,
8,
277,
14,
1412,
63,
2350,
12,
291,
14,
11992,
1484,
11733,
63,
10494,
654,
9,
288,
299,
63,
6962,
275,
291,
14,
5628,
63,
338,
3345,
780,
8,
277,
14,
1412,
63,
2350,
9,
288,
299,
63,
10802,
275,
291,
14,
5628,
63,
10802,
8,
277,
14,
1412,
63,
2350,
9,
288,
7060,
14,
1205,
480,
28461,
379,
450,
73,
2112,
12,
450,
73,
15868,
7735,
12,
450,
73,
7183,
12,
436,
450,
73,
7858,
2,
450,
334,
80,
63,
11816,
12,
299,
63,
16971,
7735,
12,
299,
63,
6962,
12,
299,
63,
10802,
430,
398,
291,
14,
3191,
8,
277,
14,
1412,
63,
2350,
9,
398,
291,
14,
928,
63,
521,
275,
291,
14,
362,
63,
928,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
500,
63,
521,
275,
291,
14,
362,
63,
500,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
5553,
275,
291,
14,
500,
63,
521,
446,
291,
14,
928,
63,
521,
398,
291,
14,
1507,
63,
4687,
275,
291,
14,
1507,
63,
2415,
8,
277,
14,
1412,
63,
2350,
9,
339,
347,
1900,
8,
277,
304,
267,
408,
3425,
314,
2112,
3123,
687,
314,
769,
402,
2746,
5845,
1041,
267,
291,
14,
1412,
63,
2350,
275,
942,
267,
367,
6499,
315,
291,
14,
1412,
63,
513,
26,
288,
340,
440,
6499,
14,
1708,
26,
355,
291,
14,
1412,
63,
2350,
14,
740,
8,
4687,
9,
288,
587,
26,
355,
6499,
14,
1708,
14,
1739,
63,
513,
14,
740,
8,
4687,
9,
339,
347,
4069,
8,
277,
12,
2112,
63,
26043,
304,
267,
408,
14376,
2112,
3123,
1041,
267,
367,
299,
315,
2112,
63,
26043,
26
] |
[
221,
961,
570,
365,
1777,
402,
1134,
4930,
9019,
5885,
14,
199,
199,
3,
221,
1134,
4930,
9019,
5885,
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,
199,
3,
221,
1134,
4930,
9019,
5885,
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,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
1134,
4930,
9019,
5885,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
533,
7132,
3987,
26,
272,
408,
3498,
3987,
22667,
15409,
282,
2112,
3123,
14,
221,
710,
3123,
365,
6137,
687,
943,
1584,
2126,
12396,
5309,
314,
8498,
2112,
14,
221,
3979,
10015,
314,
2112,
3123,
12,
652,
365,
2126,
29501,
379,
436,
9545,
315,
1865,
370,
506,
7688,
370,
13104,
794,
652,
315,
282,
1013,
22868,
1164,
2126,
30800,
14,
10817,
710,
2569,
29501,
316,
32414,
83,
787,
1202,
26,
398,
627,
15072,
10358,
626,
4215,
3879,
5309,
314,
2061,
2112,
2690,
881,
334,
6777,
365,
282,
25332,
367,
282,
8020,
10358,
9,
787,
4829,
12,
267,
627,
3974,
13,
317,
1354,
10358,
334,
73,
14,
69,
14,
10358,
626,
1454,
12166,
367,
314,
881,
7373,
402,
2877,
5845,
503,
6656,
9,
787,
4829,
12,
267,
627,
314,
10358,
1202,
701,
314,
8498,
2512,
787,
4829,
12,
267,
627,
15868,
7735,
334,
73,
14,
69,
14,
10358,
626,
787,
6040,
370,
15187,
27791,
11150,
2003,
881,
2112,
1007,
14635,
9,
1172,
3932,
1007,
14635,
9545,
10451,
12,
267,
627,
31871,
334,
73,
14,
69,
14,
10358,
543,
314,
2011,
1414,
1004,
1212,
4007,
881,
406,
19767,
1553,
2462,
25332,
9,
787,
9545,
10451,
12,
267,
627,
2112,
7858,
334,
13124,
14416,
543,
10358,
26994,
314,
1414,
1004,
9,
881,
787,
9545,
10451,
14,
339,
408,
272,
20184,
63,
6072,
275,
283,
4930,
9019,
68,
7,
272,
3651,
48,
1484,
11733,
63,
10494,
654,
275,
663,
2941,
8090,
384,
1105,
339,
347,
636,
826,
721,
277,
12,
7060,
12,
5114,
12,
7347,
3200,
12,
2690,
63,
5191,
12,
326,
23821,
2640,
12,
27619,
12,
15072,
12,
2120,
3200,
12,
326,
23189,
63,
1708,
474,
12,
367,
63,
4776,
275,
756,
304,
267,
291,
14,
5491,
275,
7060,
267,
291,
14,
1412,
63,
2350,
275,
942,
267,
291,
14,
1765,
3200,
275,
2120,
3200,
267,
340,
7347,
3200,
365,
488,
26,
288,
2112,
63,
513,
275,
5114,
267,
916,
5114,
365,
488,
26,
288,
2112,
63,
513,
275,
7347,
3200,
14,
1412,
63,
1130,
14,
1459,
342,
267,
587,
26,
288,
2112,
63,
513,
275,
769,
8,
4989,
9,
435,
769,
8,
1190,
3200,
14,
1412,
63,
1130,
14,
1459,
1012,
267,
291,
14,
1412,
63,
513,
275,
3355,
8,
1412,
63,
513,
12,
790,
275,
2400,
299,
26,
299,
14,
3150,
9,
267,
291,
14,
3271,
63,
5191,
275,
2690,
63,
5191,
398,
291,
14,
1506,
342,
267,
340,
440,
23189,
63,
1708,
474,
26,
288,
291,
14,
873,
63,
802,
1580,
63,
509,
63,
10824,
83,
8,
277,
14,
1412,
63,
513,
9,
398,
291,
14,
928,
63,
521,
275,
291,
14,
362,
63,
928,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
500,
63,
521,
275,
291,
14,
362,
63,
500,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
5553,
275,
291,
14,
500,
63,
521,
446,
291,
14,
928,
63,
521,
267,
291,
14,
12000,
275,
15072,
398,
340,
367,
63,
4776,
26,
288,
372,
398,
4829,
275,
291,
14,
5628,
63,
2921,
8,
277,
14,
1412,
63,
2350,
12,
291,
14,
10186,
63,
6072,
12,
23821,
2640,
12,
756,
9,
267,
7060,
14,
1205,
480,
15269,
450,
73,
2512,
10358,
2,
450,
4829,
9,
398,
340,
27619,
26,
288,
299,
63,
11816,
275,
291,
14,
22268,
8,
277,
14,
1412,
63,
2350,
12,
488,
9,
288,
299,
63,
16971,
7735,
275,
291,
14,
5628,
63,
16971,
7735,
8,
277,
14,
1412,
63,
2350,
12,
291,
14,
11992,
1484,
11733,
63,
10494,
654,
9,
288,
299,
63,
6962,
275,
291,
14,
5628,
63,
338,
3345,
780,
8,
277,
14,
1412,
63,
2350,
9,
288,
299,
63,
10802,
275,
291,
14,
5628,
63,
10802,
8,
277,
14,
1412,
63,
2350,
9,
288,
7060,
14,
1205,
480,
28461,
379,
450,
73,
2112,
12,
450,
73,
15868,
7735,
12,
450,
73,
7183,
12,
436,
450,
73,
7858,
2,
450,
334,
80,
63,
11816,
12,
299,
63,
16971,
7735,
12,
299,
63,
6962,
12,
299,
63,
10802,
430,
398,
291,
14,
3191,
8,
277,
14,
1412,
63,
2350,
9,
398,
291,
14,
928,
63,
521,
275,
291,
14,
362,
63,
928,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
500,
63,
521,
275,
291,
14,
362,
63,
500,
63,
521,
8,
277,
14,
1412,
63,
2350,
9,
267,
291,
14,
5553,
275,
291,
14,
500,
63,
521,
446,
291,
14,
928,
63,
521,
398,
291,
14,
1507,
63,
4687,
275,
291,
14,
1507,
63,
2415,
8,
277,
14,
1412,
63,
2350,
9,
339,
347,
1900,
8,
277,
304,
267,
408,
3425,
314,
2112,
3123,
687,
314,
769,
402,
2746,
5845,
1041,
267,
291,
14,
1412,
63,
2350,
275,
942,
267,
367,
6499,
315,
291,
14,
1412,
63,
513,
26,
288,
340,
440,
6499,
14,
1708,
26,
355,
291,
14,
1412,
63,
2350,
14,
740,
8,
4687,
9,
288,
587,
26,
355,
6499,
14,
1708,
14,
1739,
63,
513,
14,
740,
8,
4687,
9,
339,
347,
4069,
8,
277,
12,
2112,
63,
26043,
304,
267,
408,
14376,
2112,
3123,
1041,
267,
367,
299,
315,
2112,
63,
26043,
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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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
] |
jawed123/django-stripe-payments
|
payments/admin.py
|
8
|
6461
|
from django.contrib import admin
from django.db.models.fields import FieldDoesNotExist
from .models import (
Charge,
CurrentSubscription,
Customer,
Event,
EventProcessingException,
Invoice,
InvoiceItem,
Transfer
)
from .utils import get_user_model
def user_search_fields():
User = get_user_model()
USERNAME_FIELD = getattr(User, "USERNAME_FIELD", None)
fields = []
if USERNAME_FIELD is not None:
# Using a Django 1.5+ User model
fields = [
"user__{0}".format(USERNAME_FIELD)
]
try:
# get_field_by_name throws FieldDoesNotExist if the field is not
# present on the model
# pylint: disable=W0212,E1103
User._meta.get_field_by_name("email")
fields += ["user__email"]
except FieldDoesNotExist:
pass
else:
# Using a pre-Django 1.5 User model
fields = [
"user__username",
"user__email"
]
return fields
def customer_search_fields():
return [
"customer__{0}".format(field)
for field in user_search_fields()
]
class CustomerHasCardListFilter(admin.SimpleListFilter):
title = "card presence"
parameter_name = "has_card"
def lookups(self, request, model_admin):
return [
["yes", "Has Card"],
["no", "Does Not Have a Card"]
]
def queryset(self, request, queryset):
if self.value() == "yes":
return queryset.exclude(card_fingerprint="")
if self.value() == "no":
return queryset.filter(card_fingerprint="")
class InvoiceCustomerHasCardListFilter(admin.SimpleListFilter):
title = "card presence"
parameter_name = "has_card"
def lookups(self, request, model_admin):
return [
["yes", "Has Card"],
["no", "Does Not Have a Card"]
]
def queryset(self, request, queryset):
if self.value() == "yes":
return queryset.exclude(customer__card_fingerprint="")
if self.value() == "no":
return queryset.filter(customer__card_fingerprint="")
class CustomerSubscriptionStatusListFilter(admin.SimpleListFilter):
title = "subscription status"
parameter_name = "sub_status"
def lookups(self, request, model_admin):
statuses = [
[x, x.replace("_", " ").title()]
for x in CurrentSubscription.objects.all().values_list(
"status",
flat=True
).distinct()
]
statuses.append(["none", "No Subscription"])
return statuses
def queryset(self, request, queryset):
if self.value() is None:
return queryset.all()
else:
return queryset.filter(current_subscription__status=self.value())
admin.site.register(
Charge,
list_display=[
"stripe_id",
"customer",
"amount",
"description",
"paid",
"disputed",
"refunded",
"fee",
"receipt_sent",
"created_at"
],
search_fields=[
"stripe_id",
"customer__stripe_id",
"card_last_4",
"invoice__stripe_id"
] + customer_search_fields(),
list_filter=[
"paid",
"disputed",
"refunded",
"card_kind",
"created_at"
],
raw_id_fields=[
"customer",
"invoice"
],
)
admin.site.register(
EventProcessingException,
list_display=[
"message",
"event",
"created_at"
],
search_fields=[
"message",
"traceback",
"data"
],
raw_id_fields=[
"event"
],
)
admin.site.register(
Event,
raw_id_fields=["customer"],
list_display=[
"stripe_id",
"kind",
"livemode",
"valid",
"processed",
"created_at"
],
list_filter=[
"kind",
"created_at",
"valid",
"processed"
],
search_fields=[
"stripe_id",
"customer__stripe_id",
"validated_message"
] + customer_search_fields(),
)
class CurrentSubscriptionInline(admin.TabularInline):
model = CurrentSubscription
def subscription_status(obj):
return obj.current_subscription.status
subscription_status.short_description = "Subscription Status"
admin.site.register(
Customer,
raw_id_fields=["user"],
list_display=[
"stripe_id",
"user",
"card_kind",
"card_last_4",
subscription_status
],
list_filter=[
"card_kind",
CustomerHasCardListFilter,
CustomerSubscriptionStatusListFilter
],
search_fields=[
"stripe_id",
] + user_search_fields(),
inlines=[CurrentSubscriptionInline]
)
class InvoiceItemInline(admin.TabularInline):
model = InvoiceItem
def customer_has_card(obj):
return obj.customer.card_fingerprint != ""
customer_has_card.short_description = "Customer Has Card"
def customer_user(obj):
User = get_user_model()
if hasattr(User, "USERNAME_FIELD"):
# Using a Django 1.5+ User model
username = getattr(obj.customer.user, "USERNAME_FIELD")
else:
# Using a pre-Django 1.5 User model
username = obj.customer.user.username
# In Django 1.5+ a User is not guaranteed to have an email field
email = getattr(obj, "email", "")
return "{0} <{1}>".format(
username,
email
)
customer_user.short_description = "Customer"
admin.site.register(
Invoice,
raw_id_fields=["customer"],
list_display=[
"stripe_id",
"paid",
"closed",
customer_user,
customer_has_card,
"period_start",
"period_end",
"subtotal",
"total"
],
search_fields=[
"stripe_id",
"customer__stripe_id",
] + customer_search_fields(),
list_filter=[
InvoiceCustomerHasCardListFilter,
"paid",
"closed",
"attempted",
"attempts",
"created_at",
"date",
"period_end",
"total"
],
inlines=[InvoiceItemInline]
)
admin.site.register(
Transfer,
raw_id_fields=["event"],
list_display=[
"stripe_id",
"amount",
"status",
"date",
"description"
],
search_fields=[
"stripe_id",
"event__stripe_id"
]
)
|
mit
|
[
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
29994,
199,
199,
504,
1275,
992,
492,
334,
272,
2799,
4430,
12,
272,
9338,
19120,
12,
272,
22397,
12,
272,
6763,
12,
272,
6763,
9589,
1726,
12,
272,
19868,
12,
272,
19868,
2081,
12,
272,
27507,
199,
9,
199,
504,
1275,
1208,
492,
664,
63,
751,
63,
1238,
421,
199,
318,
922,
63,
1733,
63,
955,
837,
272,
2876,
275,
664,
63,
751,
63,
1238,
342,
272,
13044,
2339,
63,
8609,
275,
2519,
8,
1899,
12,
298,
11958,
63,
8609,
401,
488,
9,
272,
1504,
275,
942,
272,
340,
13044,
2339,
63,
8609,
365,
440,
488,
26,
267,
327,
11719,
282,
5634,
413,
14,
21,
11,
2876,
1402,
267,
1504,
275,
359,
288,
298,
751,
363,
91,
16,
5469,
908,
8,
11958,
63,
8609,
9,
267,
1622,
398,
862,
26,
288,
327,
664,
63,
698,
63,
991,
63,
354,
24266,
29994,
340,
314,
901,
365,
440,
288,
327,
3451,
641,
314,
1402,
288,
327,
4287,
26,
3507,
29,
55,
996,
713,
12,
37,
6019,
19,
288,
2876,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
480,
2123,
531,
288,
1504,
847,
2097,
751,
363,
2123,
937,
267,
871,
29994,
26,
288,
986,
272,
587,
26,
267,
327,
11719,
282,
876,
13,
9323,
413,
14,
21,
2876,
1402,
267,
1504,
275,
359,
288,
298,
751,
363,
2473,
401,
288,
298,
751,
363,
2123,
2,
267,
1622,
272,
372,
1504,
421,
199,
318,
15229,
63,
1733,
63,
955,
837,
272,
372,
359,
267,
298,
10178,
363,
91,
16,
5469,
908,
8,
698,
9,
267,
367,
901,
315,
922,
63,
1733,
63,
955,
342,
272,
1622,
421,
199,
533,
22397,
6362,
13832,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
5841,
20024,
2,
272,
2725,
63,
354,
275,
298,
1989,
63,
5841,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
372,
359,
288,
2097,
5066,
401,
298,
6362,
445,
1005,
2255,
288,
2097,
889,
401,
298,
6586,
2832,
26858,
282,
445,
1005,
937,
267,
1622,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
508,
298,
5066,
582,
288,
372,
7594,
14,
5473,
8,
5841,
63,
15077,
18413,
267,
340,
291,
14,
585,
342,
508,
298,
889,
582,
288,
372,
7594,
14,
1541,
8,
5841,
63,
15077,
18413,
421,
199,
533,
19868,
17025,
6362,
13832,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
5841,
20024,
2,
272,
2725,
63,
354,
275,
298,
1989,
63,
5841,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
372,
359,
288,
2097,
5066,
401,
298,
6362,
445,
1005,
2255,
288,
2097,
889,
401,
298,
6586,
2832,
26858,
282,
445,
1005,
937,
267,
1622,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
508,
298,
5066,
582,
288,
372,
7594,
14,
5473,
8,
10178,
363,
5841,
63,
15077,
18413,
267,
340,
291,
14,
585,
342,
508,
298,
889,
582,
288,
372,
7594,
14,
1541,
8,
10178,
363,
5841,
63,
15077,
18413,
421,
199,
533,
22397,
19120,
3694,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
6645,
2004,
2,
272,
2725,
63,
354,
275,
298,
954,
63,
1205,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
24498,
275,
359,
288,
359,
88,
12,
671,
14,
1814,
11008,
401,
298,
298,
680,
1213,
5106,
288,
367,
671,
315,
9338,
19120,
14,
1462,
14,
452,
1252,
1459,
63,
513,
8,
355,
298,
1205,
401,
355,
6829,
29,
549,
288,
7092,
12926,
342,
267,
1622,
267,
24498,
14,
740,
5234,
3592,
401,
298,
1944,
29763,
3135,
267,
372,
24498,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
365,
488,
26,
288,
372,
7594,
14,
452,
342,
267,
587,
26,
288,
372,
7594,
14,
1541,
8,
1818,
63,
6645,
363,
1205,
29,
277,
14,
585,
1012,
421,
199,
2113,
14,
2124,
14,
2683,
8,
272,
2799,
4430,
12,
272,
769,
63,
2918,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
401,
267,
298,
4606,
401,
267,
298,
1802,
401,
267,
298,
16555,
401,
267,
298,
13654,
4241,
401,
267,
298,
1121,
4585,
401,
267,
298,
11195,
401,
267,
298,
18905,
63,
1150,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
363,
19025,
63,
344,
401,
267,
298,
5841,
63,
2019,
63,
20,
401,
267,
298,
5404,
363,
19025,
63,
344,
2,
272,
1622,
435,
15229,
63,
1733,
63,
955,
1062,
272,
769,
63,
1541,
1524,
267,
298,
16555,
401,
267,
298,
13654,
4241,
401,
267,
298,
1121,
4585,
401,
267,
298,
5841,
63,
5091,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
3066,
63,
344,
63,
955,
1524,
267,
298,
10178,
401,
267,
298,
5404,
2,
272,
2156,
199,
9,
199,
199,
2113,
14,
2124,
14,
2683,
8,
272,
6763,
9589,
1726,
12,
272,
769,
63,
2918,
1524,
267,
298,
1188,
401,
267,
298,
1430,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
1188,
401,
267,
298,
6894,
401,
267,
298,
576,
2,
272,
2156,
272,
3066,
63,
344,
63,
955,
1524,
267,
298,
1430,
2,
272,
2156,
199,
9,
199,
199,
2113,
14,
2124,
14,
2683,
8,
272,
6763,
12,
272,
3066,
63,
344,
63,
955,
6270,
10178,
2255,
272,
769,
63,
2918,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
5091,
401,
267,
298,
6442,
632,
401,
267,
298,
1078,
401,
267,
298,
7292,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
769,
63,
1541,
1524,
267,
298,
5091,
401,
267,
298,
3966,
63,
292,
401,
267,
298,
1078,
401,
267,
298,
7292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
363,
19025,
63,
344,
401,
267,
298,
24372,
63,
1188,
2,
272,
1622,
435,
15229,
63,
1733,
63,
955,
1062,
199,
9,
421,
199,
533,
9338,
19120,
10307,
8
] |
[
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
29994,
199,
199,
504,
1275,
992,
492,
334,
272,
2799,
4430,
12,
272,
9338,
19120,
12,
272,
22397,
12,
272,
6763,
12,
272,
6763,
9589,
1726,
12,
272,
19868,
12,
272,
19868,
2081,
12,
272,
27507,
199,
9,
199,
504,
1275,
1208,
492,
664,
63,
751,
63,
1238,
421,
199,
318,
922,
63,
1733,
63,
955,
837,
272,
2876,
275,
664,
63,
751,
63,
1238,
342,
272,
13044,
2339,
63,
8609,
275,
2519,
8,
1899,
12,
298,
11958,
63,
8609,
401,
488,
9,
272,
1504,
275,
942,
272,
340,
13044,
2339,
63,
8609,
365,
440,
488,
26,
267,
327,
11719,
282,
5634,
413,
14,
21,
11,
2876,
1402,
267,
1504,
275,
359,
288,
298,
751,
363,
91,
16,
5469,
908,
8,
11958,
63,
8609,
9,
267,
1622,
398,
862,
26,
288,
327,
664,
63,
698,
63,
991,
63,
354,
24266,
29994,
340,
314,
901,
365,
440,
288,
327,
3451,
641,
314,
1402,
288,
327,
4287,
26,
3507,
29,
55,
996,
713,
12,
37,
6019,
19,
288,
2876,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
480,
2123,
531,
288,
1504,
847,
2097,
751,
363,
2123,
937,
267,
871,
29994,
26,
288,
986,
272,
587,
26,
267,
327,
11719,
282,
876,
13,
9323,
413,
14,
21,
2876,
1402,
267,
1504,
275,
359,
288,
298,
751,
363,
2473,
401,
288,
298,
751,
363,
2123,
2,
267,
1622,
272,
372,
1504,
421,
199,
318,
15229,
63,
1733,
63,
955,
837,
272,
372,
359,
267,
298,
10178,
363,
91,
16,
5469,
908,
8,
698,
9,
267,
367,
901,
315,
922,
63,
1733,
63,
955,
342,
272,
1622,
421,
199,
533,
22397,
6362,
13832,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
5841,
20024,
2,
272,
2725,
63,
354,
275,
298,
1989,
63,
5841,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
372,
359,
288,
2097,
5066,
401,
298,
6362,
445,
1005,
2255,
288,
2097,
889,
401,
298,
6586,
2832,
26858,
282,
445,
1005,
937,
267,
1622,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
508,
298,
5066,
582,
288,
372,
7594,
14,
5473,
8,
5841,
63,
15077,
18413,
267,
340,
291,
14,
585,
342,
508,
298,
889,
582,
288,
372,
7594,
14,
1541,
8,
5841,
63,
15077,
18413,
421,
199,
533,
19868,
17025,
6362,
13832,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
5841,
20024,
2,
272,
2725,
63,
354,
275,
298,
1989,
63,
5841,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
372,
359,
288,
2097,
5066,
401,
298,
6362,
445,
1005,
2255,
288,
2097,
889,
401,
298,
6586,
2832,
26858,
282,
445,
1005,
937,
267,
1622,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
508,
298,
5066,
582,
288,
372,
7594,
14,
5473,
8,
10178,
363,
5841,
63,
15077,
18413,
267,
340,
291,
14,
585,
342,
508,
298,
889,
582,
288,
372,
7594,
14,
1541,
8,
10178,
363,
5841,
63,
15077,
18413,
421,
199,
533,
22397,
19120,
3694,
24703,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
298,
6645,
2004,
2,
272,
2725,
63,
354,
275,
298,
954,
63,
1205,
2,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
24498,
275,
359,
288,
359,
88,
12,
671,
14,
1814,
11008,
401,
298,
298,
680,
1213,
5106,
288,
367,
671,
315,
9338,
19120,
14,
1462,
14,
452,
1252,
1459,
63,
513,
8,
355,
298,
1205,
401,
355,
6829,
29,
549,
288,
7092,
12926,
342,
267,
1622,
267,
24498,
14,
740,
5234,
3592,
401,
298,
1944,
29763,
3135,
267,
372,
24498,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
365,
488,
26,
288,
372,
7594,
14,
452,
342,
267,
587,
26,
288,
372,
7594,
14,
1541,
8,
1818,
63,
6645,
363,
1205,
29,
277,
14,
585,
1012,
421,
199,
2113,
14,
2124,
14,
2683,
8,
272,
2799,
4430,
12,
272,
769,
63,
2918,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
401,
267,
298,
4606,
401,
267,
298,
1802,
401,
267,
298,
16555,
401,
267,
298,
13654,
4241,
401,
267,
298,
1121,
4585,
401,
267,
298,
11195,
401,
267,
298,
18905,
63,
1150,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
363,
19025,
63,
344,
401,
267,
298,
5841,
63,
2019,
63,
20,
401,
267,
298,
5404,
363,
19025,
63,
344,
2,
272,
1622,
435,
15229,
63,
1733,
63,
955,
1062,
272,
769,
63,
1541,
1524,
267,
298,
16555,
401,
267,
298,
13654,
4241,
401,
267,
298,
1121,
4585,
401,
267,
298,
5841,
63,
5091,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
3066,
63,
344,
63,
955,
1524,
267,
298,
10178,
401,
267,
298,
5404,
2,
272,
2156,
199,
9,
199,
199,
2113,
14,
2124,
14,
2683,
8,
272,
6763,
9589,
1726,
12,
272,
769,
63,
2918,
1524,
267,
298,
1188,
401,
267,
298,
1430,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
1188,
401,
267,
298,
6894,
401,
267,
298,
576,
2,
272,
2156,
272,
3066,
63,
344,
63,
955,
1524,
267,
298,
1430,
2,
272,
2156,
199,
9,
199,
199,
2113,
14,
2124,
14,
2683,
8,
272,
6763,
12,
272,
3066,
63,
344,
63,
955,
6270,
10178,
2255,
272,
769,
63,
2918,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
5091,
401,
267,
298,
6442,
632,
401,
267,
298,
1078,
401,
267,
298,
7292,
401,
267,
298,
3966,
63,
292,
2,
272,
2156,
272,
769,
63,
1541,
1524,
267,
298,
5091,
401,
267,
298,
3966,
63,
292,
401,
267,
298,
1078,
401,
267,
298,
7292,
2,
272,
2156,
272,
2754,
63,
955,
1524,
267,
298,
19025,
63,
344,
401,
267,
298,
10178,
363,
19025,
63,
344,
401,
267,
298,
24372,
63,
1188,
2,
272,
1622,
435,
15229,
63,
1733,
63,
955,
1062,
199,
9,
421,
199,
533,
9338,
19120,
10307,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
dimdung/boto
|
tests/integration/ec2/elb/__init__.py
|
454
|
1103
|
# Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
|
mit
|
[
3,
1898,
334,
67,
9,
8315,
13,
8128,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8315,
13,
8128,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
johndpope/tensorflow
|
tensorflow/contrib/learn/python/learn/estimators/dynamic_rnn_estimator_test.py
|
9
|
30828
|
# 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 learn.estimators.dynamic_rnn_estimator."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tempfile
import numpy as np
from tensorflow.contrib import rnn
from tensorflow.contrib.layers.python.layers import feature_column
from tensorflow.contrib.layers.python.layers import target_column as target_column_lib
from tensorflow.contrib.learn.python.learn.estimators import constants
from tensorflow.contrib.learn.python.learn.estimators import dynamic_rnn_estimator
from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib
from tensorflow.contrib.learn.python.learn.estimators import prediction_key
from tensorflow.contrib.learn.python.learn.estimators import rnn_common
from tensorflow.contrib.learn.python.learn.estimators import run_config
from tensorflow.contrib.rnn.python.ops import core_rnn_cell_impl
from tensorflow.python.client import session
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import random_seed
from tensorflow.python.framework import sparse_tensor
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import functional_ops
from tensorflow.python.ops import lookup_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
class IdentityRNNCell(rnn.RNNCell):
def __init__(self, state_size, output_size):
self._state_size = state_size
self._output_size = output_size
@property
def state_size(self):
return self._state_size
@property
def output_size(self):
return self._output_size
def __call__(self, inputs, state):
return array_ops.identity(inputs), array_ops.ones(
[array_ops.shape(inputs)[0], self.state_size])
class MockTargetColumn(object):
def __init__(self, num_label_columns=None):
self._num_label_columns = num_label_columns
def get_eval_ops(self, features, activations, labels, metrics):
raise NotImplementedError(
'MockTargetColumn.get_eval_ops called unexpectedly.')
def logits_to_predictions(self, flattened_activations, proba=False):
raise NotImplementedError(
'MockTargetColumn.logits_to_predictions called unexpectedly.')
def loss(self, activations, labels, features):
raise NotImplementedError('MockTargetColumn.loss called unexpectedly.')
@property
def num_label_columns(self):
if self._num_label_columns is None:
raise ValueError('MockTargetColumn.num_label_columns has not been set.')
return self._num_label_columns
def set_num_label_columns(self, n):
self._num_label_columns = n
def sequence_length_mask(values, lengths):
masked = values
for i, length in enumerate(lengths):
masked[i, length:, :] = np.zeros_like(masked[i, length:, :])
return masked
class DynamicRnnEstimatorTest(test.TestCase):
NUM_RNN_CELL_UNITS = 8
NUM_LABEL_COLUMNS = 6
INPUTS_COLUMN = feature_column.real_valued_column(
'inputs', dimension=NUM_LABEL_COLUMNS)
def setUp(self):
super(DynamicRnnEstimatorTest, self).setUp()
self.rnn_cell = core_rnn_cell_impl.BasicRNNCell(self.NUM_RNN_CELL_UNITS)
self.mock_target_column = MockTargetColumn(
num_label_columns=self.NUM_LABEL_COLUMNS)
location = feature_column.sparse_column_with_keys(
'location', keys=['west_side', 'east_side', 'nyc'])
location_onehot = feature_column.one_hot_column(location)
self.context_feature_columns = [location_onehot]
wire_cast = feature_column.sparse_column_with_keys(
'wire_cast', ['marlo', 'omar', 'stringer'])
wire_cast_embedded = feature_column.embedding_column(wire_cast, dimension=8)
measurements = feature_column.real_valued_column(
'measurements', dimension=2)
self.sequence_feature_columns = [measurements, wire_cast_embedded]
def GetColumnsToTensors(self):
"""Get columns_to_tensors matching setUp(), in the current default graph."""
return {
'location':
sparse_tensor.SparseTensor(
indices=[[0, 0], [1, 0], [2, 0]],
values=['west_side', 'west_side', 'nyc'],
dense_shape=[3, 1]),
'wire_cast':
sparse_tensor.SparseTensor(
indices=[[0, 0, 0], [0, 1, 0],
[1, 0, 0], [1, 1, 0], [1, 1, 1],
[2, 0, 0]],
values=[b'marlo', b'stringer',
b'omar', b'stringer', b'marlo',
b'marlo'],
dense_shape=[3, 2, 2]),
'measurements':
random_ops.random_uniform(
[3, 2, 2], seed=4711)
}
def GetClassificationTargetsOrNone(self, mode):
"""Get targets matching setUp() and mode, in the current default graph."""
return (random_ops.random_uniform(
[3, 2, 1], 0, 2, dtype=dtypes.int64, seed=1412) if
mode != model_fn_lib.ModeKeys.INFER else None)
def testBuildSequenceInputInput(self):
sequence_input = dynamic_rnn_estimator.build_sequence_input(
self.GetColumnsToTensors(), self.sequence_feature_columns,
self.context_feature_columns)
with self.test_session() as sess:
sess.run(variables.global_variables_initializer())
sess.run(lookup_ops.tables_initializer())
sequence_input_val = sess.run(sequence_input)
expected_shape = np.array([
3, # expected batch size
2, # padded sequence length
3 + 8 + 2 # location keys + embedding dim + measurement dimension
])
self.assertAllEqual(expected_shape, sequence_input_val.shape)
def testConstructRNN(self):
initial_state = None
sequence_input = dynamic_rnn_estimator.build_sequence_input(
self.GetColumnsToTensors(), self.sequence_feature_columns,
self.context_feature_columns)
activations_t, final_state_t = dynamic_rnn_estimator.construct_rnn(
initial_state, sequence_input, self.rnn_cell,
self.mock_target_column.num_label_columns)
# Obtain values of activations and final state.
with session.Session() as sess:
sess.run(variables.global_variables_initializer())
sess.run(lookup_ops.tables_initializer())
activations, final_state = sess.run([activations_t, final_state_t])
expected_activations_shape = np.array([3, 2, self.NUM_LABEL_COLUMNS])
self.assertAllEqual(expected_activations_shape, activations.shape)
expected_state_shape = np.array([3, self.NUM_RNN_CELL_UNITS])
self.assertAllEqual(expected_state_shape, final_state.shape)
def testGetOutputAlternatives(self):
test_cases = (
(rnn_common.PredictionType.SINGLE_VALUE,
constants.ProblemType.CLASSIFICATION,
{prediction_key.PredictionKey.CLASSES: True,
prediction_key.PredictionKey.PROBABILITIES: True,
dynamic_rnn_estimator._get_state_name(0): True},
{'dynamic_rnn_output':
(constants.ProblemType.CLASSIFICATION,
{prediction_key.PredictionKey.CLASSES: True,
prediction_key.PredictionKey.PROBABILITIES: True})}),
(rnn_common.PredictionType.SINGLE_VALUE,
constants.ProblemType.LINEAR_REGRESSION,
{prediction_key.PredictionKey.SCORES: True,
dynamic_rnn_estimator._get_state_name(0): True,
dynamic_rnn_estimator._get_state_name(1): True},
{'dynamic_rnn_output':
(constants.ProblemType.LINEAR_REGRESSION,
{prediction_key.PredictionKey.SCORES: True})}),
(rnn_common.PredictionType.MULTIPLE_VALUE,
constants.ProblemType.CLASSIFICATION,
{prediction_key.PredictionKey.CLASSES: True,
prediction_key.PredictionKey.PROBABILITIES: True,
dynamic_rnn_estimator._get_state_name(0): True},
None))
for pred_type, prob_type, pred_dict, expected_alternatives in test_cases:
actual_alternatives = dynamic_rnn_estimator._get_output_alternatives(
pred_type, prob_type, pred_dict)
self.assertEqual(expected_alternatives, actual_alternatives)
# testGetDynamicRnnModelFn{Train,Eval,Infer}() test which fields
# of ModelFnOps are set depending on mode.
def testGetDynamicRnnModelFnTrain(self):
model_fn_ops = self._GetModelFnOpsForMode(model_fn_lib.ModeKeys.TRAIN)
self.assertIsNotNone(model_fn_ops.predictions)
self.assertIsNotNone(model_fn_ops.loss)
self.assertIsNotNone(model_fn_ops.train_op)
# None may get normalized to {}; we accept neither.
self.assertNotEqual(len(model_fn_ops.eval_metric_ops), 0)
def testGetDynamicRnnModelFnEval(self):
model_fn_ops = self._GetModelFnOpsForMode(model_fn_lib.ModeKeys.EVAL)
self.assertIsNotNone(model_fn_ops.predictions)
self.assertIsNotNone(model_fn_ops.loss)
self.assertIsNone(model_fn_ops.train_op)
# None may get normalized to {}; we accept neither.
self.assertNotEqual(len(model_fn_ops.eval_metric_ops), 0)
def testGetDynamicRnnModelFnInfer(self):
model_fn_ops = self._GetModelFnOpsForMode(model_fn_lib.ModeKeys.INFER)
self.assertIsNotNone(model_fn_ops.predictions)
self.assertIsNone(model_fn_ops.loss)
self.assertIsNone(model_fn_ops.train_op)
# None may get normalized to {}; we accept both.
self.assertFalse(model_fn_ops.eval_metric_ops)
def _GetModelFnOpsForMode(self, mode):
"""Helper for testGetDynamicRnnModelFn{Train,Eval,Infer}()."""
model_fn = dynamic_rnn_estimator._get_dynamic_rnn_model_fn(
cell_type='basic_rnn',
num_units=[10],
target_column=target_column_lib.multi_class_target(n_classes=2),
# Only CLASSIFICATION yields eval metrics to test for.
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
optimizer='SGD',
sequence_feature_columns=self.sequence_feature_columns,
context_feature_columns=self.context_feature_columns,
learning_rate=0.1)
labels = self.GetClassificationTargetsOrNone(mode)
model_fn_ops = model_fn(
features=self.GetColumnsToTensors(), labels=labels, mode=mode)
return model_fn_ops
def testExport(self):
input_feature_key = 'magic_input_feature_key'
def get_input_fn(mode):
def input_fn():
features = self.GetColumnsToTensors()
if mode == model_fn_lib.ModeKeys.INFER:
input_examples = array_ops.placeholder(dtypes.string)
features[input_feature_key] = input_examples
# Real code would now parse features out of input_examples,
# but this test can just stick to the constants above.
return features, self.GetClassificationTargetsOrNone(mode)
return input_fn
model_dir = tempfile.mkdtemp()
def estimator_fn():
return dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
num_classes=2,
num_units=self.NUM_RNN_CELL_UNITS,
sequence_feature_columns=self.sequence_feature_columns,
context_feature_columns=self.context_feature_columns,
predict_probabilities=True,
model_dir=model_dir)
# Train a bit to create an exportable checkpoint.
estimator_fn().fit(input_fn=get_input_fn(model_fn_lib.ModeKeys.TRAIN),
steps=100)
# Now export, but from a fresh estimator instance, like you would
# in an export binary. That means .export() has to work without
# .fit() being called on the same object.
export_dir = tempfile.mkdtemp()
print('Exporting to', export_dir)
estimator_fn().export(
export_dir,
input_fn=get_input_fn(model_fn_lib.ModeKeys.INFER),
use_deprecated_input_fn=False,
input_feature_key=input_feature_key)
def testStateTupleDictConversion(self):
"""Test `state_tuple_to_dict` and `dict_to_state_tuple`."""
cell_sizes = [5, 3, 7]
# A MultiRNNCell of LSTMCells is both a common choice and an interesting
# test case, because it has two levels of nesting, with an inner class that
# is not a plain tuple.
cell = core_rnn_cell_impl.MultiRNNCell(
[core_rnn_cell_impl.LSTMCell(i) for i in cell_sizes])
state_dict = {
dynamic_rnn_estimator._get_state_name(i):
array_ops.expand_dims(math_ops.range(cell_size), 0)
for i, cell_size in enumerate([5, 5, 3, 3, 7, 7])
}
expected_state = (core_rnn_cell_impl.LSTMStateTuple(
np.reshape(np.arange(5), [1, -1]), np.reshape(np.arange(5), [1, -1])),
core_rnn_cell_impl.LSTMStateTuple(
np.reshape(np.arange(3), [1, -1]),
np.reshape(np.arange(3), [1, -1])),
core_rnn_cell_impl.LSTMStateTuple(
np.reshape(np.arange(7), [1, -1]),
np.reshape(np.arange(7), [1, -1])))
actual_state = dynamic_rnn_estimator.dict_to_state_tuple(state_dict, cell)
flattened_state = dynamic_rnn_estimator.state_tuple_to_dict(actual_state)
with self.test_session() as sess:
(state_dict_val, actual_state_val, flattened_state_val) = sess.run(
[state_dict, actual_state, flattened_state])
def _recursive_assert_equal(x, y):
self.assertEqual(type(x), type(y))
if isinstance(x, (list, tuple)):
self.assertEqual(len(x), len(y))
for i, _ in enumerate(x):
_recursive_assert_equal(x[i], y[i])
elif isinstance(x, np.ndarray):
np.testing.assert_array_equal(x, y)
else:
self.fail('Unexpected type: {}'.format(type(x)))
for k in state_dict_val.keys():
np.testing.assert_array_almost_equal(
state_dict_val[k],
flattened_state_val[k],
err_msg='Wrong value for state component {}.'.format(k))
_recursive_assert_equal(expected_state, actual_state_val)
def testMultiRNNState(self):
"""Test that state flattening/reconstruction works for `MultiRNNCell`."""
batch_size = 11
sequence_length = 16
train_steps = 5
cell_sizes = [4, 8, 7]
learning_rate = 0.1
def get_shift_input_fn(batch_size, sequence_length, seed=None):
def input_fn():
random_sequence = random_ops.random_uniform(
[batch_size, sequence_length + 1],
0,
2,
dtype=dtypes.int32,
seed=seed)
labels = array_ops.slice(random_sequence, [0, 0],
[batch_size, sequence_length])
inputs = array_ops.expand_dims(
math_ops.to_float(
array_ops.slice(random_sequence, [0, 1],
[batch_size, sequence_length])), 2)
input_dict = {
dynamic_rnn_estimator._get_state_name(i): random_ops.random_uniform(
[batch_size, cell_size], seed=((i + 1) * seed))
for i, cell_size in enumerate([4, 4, 8, 8, 7, 7])
}
input_dict['inputs'] = inputs
return input_dict, labels
return input_fn
seq_columns = [feature_column.real_valued_column('inputs', dimension=1)]
config = run_config.RunConfig(tf_random_seed=21212)
cell_type = 'lstm'
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
num_classes=2,
num_units=cell_sizes,
sequence_feature_columns=seq_columns,
cell_type=cell_type,
learning_rate=learning_rate,
config=config,
predict_probabilities=True)
train_input_fn = get_shift_input_fn(batch_size, sequence_length, seed=12321)
eval_input_fn = get_shift_input_fn(batch_size, sequence_length, seed=32123)
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
prediction_dict = sequence_estimator.predict(
input_fn=eval_input_fn, as_iterable=False)
for i, state_size in enumerate([4, 4, 8, 8, 7, 7]):
state_piece = prediction_dict[dynamic_rnn_estimator._get_state_name(i)]
self.assertListEqual(list(state_piece.shape), [batch_size, state_size])
def testMultipleRuns(self):
"""Tests resuming training by feeding state."""
cell_sizes = [4, 7]
batch_size = 11
learning_rate = 0.1
train_sequence_length = 21
train_steps = 121
dropout_keep_probabilities = [0.5, 0.5, 0.5]
prediction_steps = [3, 2, 5, 11, 6]
def get_input_fn(batch_size, sequence_length, state_dict, starting_step=0):
def input_fn():
sequence = constant_op.constant(
[[(starting_step + i + j) % 2 for j in range(sequence_length + 1)]
for i in range(batch_size)],
dtype=dtypes.int32)
labels = array_ops.slice(sequence, [0, 0],
[batch_size, sequence_length])
inputs = array_ops.expand_dims(
math_ops.to_float(
array_ops.slice(sequence, [0, 1], [batch_size, sequence_length
])), 2)
input_dict = state_dict
input_dict['inputs'] = inputs
return input_dict, labels
return input_fn
seq_columns = [feature_column.real_valued_column('inputs', dimension=1)]
config = run_config.RunConfig(tf_random_seed=21212)
model_dir = tempfile.mkdtemp()
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
num_classes=2,
sequence_feature_columns=seq_columns,
num_units=cell_sizes,
cell_type='lstm',
dropout_keep_probabilities=dropout_keep_probabilities,
learning_rate=learning_rate,
config=config,
model_dir=model_dir)
train_input_fn = get_input_fn(
batch_size, train_sequence_length, state_dict={})
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
def incremental_predict(estimator, increments):
"""Run `estimator.predict` for `i` steps for `i` in `increments`."""
step = 0
incremental_state_dict = {}
for increment in increments:
input_fn = get_input_fn(
batch_size,
increment,
state_dict=incremental_state_dict,
starting_step=step)
prediction_dict = estimator.predict(
input_fn=input_fn, as_iterable=False)
step += increment
incremental_state_dict = {
k: v
for (k, v) in prediction_dict.items()
if k.startswith(rnn_common.RNNKeys.STATE_PREFIX)
}
return prediction_dict
pred_all_at_once = incremental_predict(sequence_estimator,
[sum(prediction_steps)])
pred_step_by_step = incremental_predict(sequence_estimator,
prediction_steps)
# Check that the last `prediction_steps[-1]` steps give the same
# predictions.
np.testing.assert_array_equal(
pred_all_at_once[prediction_key.PredictionKey.CLASSES]
[:, -1 * prediction_steps[-1]:],
pred_step_by_step[prediction_key.PredictionKey.CLASSES],
err_msg='Mismatch on last {} predictions.'.format(prediction_steps[-1]))
# Check that final states are identical.
for k, v in pred_all_at_once.items():
if k.startswith(rnn_common.RNNKeys.STATE_PREFIX):
np.testing.assert_array_equal(
v, pred_step_by_step[k], err_msg='Mismatch on state {}.'.format(k))
# TODO(jamieas): move all tests below to a benchmark test.
class DynamicRNNEstimatorLearningTest(test.TestCase):
"""Learning tests for dynamic RNN Estimators."""
def testLearnSineFunction(self):
"""Tests learning a sine function."""
batch_size = 8
sequence_length = 64
train_steps = 200
eval_steps = 20
cell_size = [4]
learning_rate = 0.1
loss_threshold = 0.02
def get_sin_input_fn(batch_size, sequence_length, increment, seed=None):
def _sin_fn(x):
ranger = math_ops.linspace(
array_ops.reshape(x[0], []), (sequence_length - 1) * increment,
sequence_length + 1)
return math_ops.sin(ranger)
def input_fn():
starts = random_ops.random_uniform(
[batch_size], maxval=(2 * np.pi), seed=seed)
sin_curves = functional_ops.map_fn(
_sin_fn, (starts,), dtype=dtypes.float32)
inputs = array_ops.expand_dims(
array_ops.slice(sin_curves, [0, 0], [batch_size, sequence_length]),
2)
labels = array_ops.slice(sin_curves, [0, 1],
[batch_size, sequence_length])
return {'inputs': inputs}, labels
return input_fn
seq_columns = [
feature_column.real_valued_column(
'inputs', dimension=cell_size[0])
]
config = run_config.RunConfig(tf_random_seed=1234)
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.LINEAR_REGRESSION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
num_units=cell_size,
sequence_feature_columns=seq_columns,
learning_rate=learning_rate,
dropout_keep_probabilities=[0.9, 0.9],
config=config)
train_input_fn = get_sin_input_fn(
batch_size, sequence_length, np.pi / 32, seed=1234)
eval_input_fn = get_sin_input_fn(
batch_size, sequence_length, np.pi / 32, seed=4321)
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
loss = sequence_estimator.evaluate(
input_fn=eval_input_fn, steps=eval_steps)['loss']
self.assertLess(loss, loss_threshold,
'Loss should be less than {}; got {}'.format(loss_threshold,
loss))
def testLearnShiftByOne(self):
"""Tests that learning a 'shift-by-one' example.
Each label sequence consists of the input sequence 'shifted' by one place.
The RNN must learn to 'remember' the previous input.
"""
batch_size = 16
sequence_length = 32
train_steps = 200
eval_steps = 20
cell_size = 4
learning_rate = 0.3
accuracy_threshold = 0.9
def get_shift_input_fn(batch_size, sequence_length, seed=None):
def input_fn():
random_sequence = random_ops.random_uniform(
[batch_size, sequence_length + 1],
0,
2,
dtype=dtypes.int32,
seed=seed)
labels = array_ops.slice(random_sequence, [0, 0],
[batch_size, sequence_length])
inputs = array_ops.expand_dims(
math_ops.to_float(
array_ops.slice(random_sequence, [0, 1],
[batch_size, sequence_length])), 2)
return {'inputs': inputs}, labels
return input_fn
seq_columns = [
feature_column.real_valued_column(
'inputs', dimension=cell_size)
]
config = run_config.RunConfig(tf_random_seed=21212)
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.MULTIPLE_VALUE,
num_classes=2,
num_units=cell_size,
sequence_feature_columns=seq_columns,
learning_rate=learning_rate,
config=config,
predict_probabilities=True)
train_input_fn = get_shift_input_fn(batch_size, sequence_length, seed=12321)
eval_input_fn = get_shift_input_fn(batch_size, sequence_length, seed=32123)
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
evaluation = sequence_estimator.evaluate(
input_fn=eval_input_fn, steps=eval_steps)
accuracy = evaluation['accuracy']
self.assertGreater(accuracy, accuracy_threshold,
'Accuracy should be higher than {}; got {}'.format(
accuracy_threshold, accuracy))
# Testing `predict` when `predict_probabilities=True`.
prediction_dict = sequence_estimator.predict(
input_fn=eval_input_fn, as_iterable=False)
self.assertListEqual(
sorted(list(prediction_dict.keys())),
sorted([
prediction_key.PredictionKey.CLASSES,
prediction_key.PredictionKey.PROBABILITIES,
dynamic_rnn_estimator._get_state_name(0)
]))
predictions = prediction_dict[prediction_key.PredictionKey.CLASSES]
probabilities = prediction_dict[
prediction_key.PredictionKey.PROBABILITIES]
self.assertListEqual(list(predictions.shape), [batch_size, sequence_length])
self.assertListEqual(
list(probabilities.shape), [batch_size, sequence_length, 2])
def testLearnMean(self):
"""Test learning to calculate a mean."""
batch_size = 16
sequence_length = 3
train_steps = 200
eval_steps = 20
cell_type = 'basic_rnn'
cell_size = 8
optimizer_type = 'Momentum'
learning_rate = 0.1
momentum = 0.9
loss_threshold = 0.1
def get_mean_input_fn(batch_size, sequence_length, seed=None):
def input_fn():
# Create examples by choosing 'centers' and adding uniform noise.
centers = math_ops.matmul(
random_ops.random_uniform(
[batch_size, 1], -0.75, 0.75, dtype=dtypes.float32, seed=seed),
array_ops.ones([1, sequence_length]))
noise = random_ops.random_uniform(
[batch_size, sequence_length],
-0.25,
0.25,
dtype=dtypes.float32,
seed=seed)
sequences = centers + noise
inputs = array_ops.expand_dims(sequences, 2)
labels = math_ops.reduce_mean(sequences, reduction_indices=[1])
return {'inputs': inputs}, labels
return input_fn
seq_columns = [
feature_column.real_valued_column(
'inputs', dimension=cell_size)
]
config = run_config.RunConfig(tf_random_seed=6)
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.LINEAR_REGRESSION,
prediction_type=rnn_common.PredictionType.SINGLE_VALUE,
num_units=cell_size,
sequence_feature_columns=seq_columns,
cell_type=cell_type,
optimizer=optimizer_type,
learning_rate=learning_rate,
momentum=momentum,
config=config)
train_input_fn = get_mean_input_fn(batch_size, sequence_length, 121)
eval_input_fn = get_mean_input_fn(batch_size, sequence_length, 212)
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
evaluation = sequence_estimator.evaluate(
input_fn=eval_input_fn, steps=eval_steps)
loss = evaluation['loss']
self.assertLess(loss, loss_threshold,
'Loss should be less than {}; got {}'.format(loss_threshold,
loss))
def testLearnMajority(self):
"""Test learning the 'majority' function."""
batch_size = 16
sequence_length = 7
train_steps = 200
eval_steps = 20
cell_type = 'lstm'
cell_size = 4
optimizer_type = 'Momentum'
learning_rate = 2.0
momentum = 0.9
accuracy_threshold = 0.9
def get_majority_input_fn(batch_size, sequence_length, seed=None):
random_seed.set_random_seed(seed)
def input_fn():
random_sequence = random_ops.random_uniform(
[batch_size, sequence_length], 0, 2, dtype=dtypes.int32, seed=seed)
inputs = array_ops.expand_dims(math_ops.to_float(random_sequence), 2)
labels = math_ops.to_int32(
array_ops.squeeze(
math_ops.reduce_sum(
inputs, reduction_indices=[1]) > (sequence_length / 2.0)))
return {'inputs': inputs}, labels
return input_fn
seq_columns = [
feature_column.real_valued_column(
'inputs', dimension=cell_size)
]
config = run_config.RunConfig(tf_random_seed=77)
sequence_estimator = dynamic_rnn_estimator.DynamicRnnEstimator(
problem_type=constants.ProblemType.CLASSIFICATION,
prediction_type=rnn_common.PredictionType.SINGLE_VALUE,
num_classes=2,
num_units=cell_size,
sequence_feature_columns=seq_columns,
cell_type=cell_type,
optimizer=optimizer_type,
learning_rate=learning_rate,
momentum=momentum,
config=config,
predict_probabilities=True)
train_input_fn = get_majority_input_fn(batch_size, sequence_length, 1111)
eval_input_fn = get_majority_input_fn(batch_size, sequence_length, 2222)
sequence_estimator.fit(input_fn=train_input_fn, steps=train_steps)
evaluation = sequence_estimator.evaluate(
input_fn=eval_input_fn, steps=eval_steps)
accuracy = evaluation['accuracy']
self.assertGreater(accuracy, accuracy_threshold,
'Accuracy should be higher than {}; got {}'.format(
accuracy_threshold, accuracy))
# Testing `predict` when `predict_probabilities=True`.
prediction_dict = sequence_estimator.predict(
input_fn=eval_input_fn, as_iterable=False)
self.assertListEqual(
sorted(list(prediction_dict.keys())),
sorted([
prediction_key.PredictionKey.CLASSES,
prediction_key.PredictionKey.PROBABILITIES,
dynamic_rnn_estimator._get_state_name(0),
dynamic_rnn_estimator._get_state_name(1)
]))
predictions = prediction_dict[prediction_key.PredictionKey.CLASSES]
probabilities = prediction_dict[
prediction_key.PredictionKey.PROBABILITIES]
self.assertListEqual(list(predictions.shape), [batch_size])
self.assertListEqual(list(probabilities.shape), [batch_size, 2])
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,
12537,
14,
10646,
14,
7764,
63,
12845,
63,
8627,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
5549,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
492,
19433,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
3878,
63,
2301,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
1347,
63,
2301,
465,
1347,
63,
2301,
63,
773,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
5262,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
8336,
63,
12845,
63,
8627,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
1402,
63,
2324,
465,
1402,
63,
2324,
63,
773,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
12044,
63,
498,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
19433,
63,
2330,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
1255,
63,
888,
199,
504,
3228,
14,
2828,
14,
12845,
14,
1548,
14,
1483,
492,
6170,
63,
12845,
63,
3890,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
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,
2196,
63,
5176,
199,
504,
3228,
14,
1548,
14,
4857,
492,
5178,
63,
3128,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
22380,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4237,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
22034,
32675,
8,
12845,
14,
32675,
304,
819,
347,
636,
826,
721,
277,
12,
1174,
63,
890,
12,
1072,
63,
890,
304,
272,
291,
423,
929,
63,
890,
275,
1174,
63,
890,
272,
291,
423,
1199,
63,
890,
275,
1072,
63,
890,
819,
768,
1829,
523,
347,
1174,
63,
890,
8,
277,
304,
272,
372,
291,
423,
929,
63,
890,
819,
768,
1829,
523,
347,
1072,
63,
890,
8,
277,
304,
272,
372,
291,
423,
1199,
63,
890,
819,
347,
636,
1250,
721,
277,
12,
4153,
12,
1174,
304,
272,
372,
1625,
63,
1483,
14,
5582,
8,
3711,
395,
1625,
63,
1483,
14,
4548,
8,
267,
359,
1144,
63,
1483,
14,
1392,
8,
3711,
2788,
16,
467,
291,
14,
929,
63,
890,
566,
421,
199,
533,
4420,
4277,
4547,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1967,
63,
1302,
63,
3406,
29,
403,
304,
272,
291,
423,
1507,
63,
1302,
63,
3406,
275,
1967,
63,
1302,
63,
3406,
819,
347,
664,
63,
2579,
63,
1483,
8,
277,
12,
4534,
12,
32038,
12,
3628,
12,
7186,
304,
272,
746,
4279,
8,
267,
283,
3346,
4277,
4547,
14,
362,
63,
2579,
63,
1483,
2797,
10537,
590,
2659,
819,
347,
11051,
63,
475,
63,
9869,
8,
277,
12,
18767,
63,
31117,
12,
557,
2470,
29,
797,
304,
272,
746,
4279,
8,
267,
283,
3346,
4277,
4547,
14,
10492,
63,
475,
63,
9869,
2797,
10537,
590,
2659,
819,
347,
5621,
8,
277,
12,
32038,
12,
3628,
12,
4534,
304,
272,
746,
4279,
360,
3346,
4277,
4547,
14,
4358,
2797,
10537,
590,
2659,
819,
768,
1829,
523,
347,
1967,
63,
1302,
63,
3406,
8,
277,
304,
272,
340,
291,
423,
1507,
63,
1302,
63,
3406,
365,
488,
26,
489,
746,
1722,
360,
3346,
4277,
4547,
14,
1507,
63,
1302,
63,
3406,
965,
440,
2757,
663,
2659,
272,
372,
291,
423,
1507,
63,
1302,
63,
3406,
819,
347,
663,
63,
1507,
63,
1302,
63,
3406,
8,
277,
12,
302,
304,
272,
291,
423,
1507,
63,
1302,
63,
3406,
275,
302,
421,
199,
318,
3414,
63,
1267,
63,
2629,
8,
1459,
12,
17464,
304,
523,
9742,
275,
1338,
523,
367,
284,
12,
2582,
315,
3874,
8,
14563,
304,
272,
9742,
59,
73,
12,
2582,
11941,
12228,
275,
980,
14,
4250,
63,
2930,
8,
11018,
59,
73,
12,
2582,
11941,
520,
566,
523,
372,
9742,
421,
199,
533,
21907,
50,
4411,
13183,
774,
8,
396,
14,
1746,
304,
819,
11576,
63,
24124,
63,
26474,
63,
27522,
275,
1695,
523,
11576,
63,
13837,
63,
28427,
275,
1227,
523,
21955,
51,
63,
21436,
275,
3878,
63,
2301,
14,
3093,
63,
16611,
63,
2301,
8,
489,
283,
3711,
297,
6240,
29,
7125,
63,
13837,
63,
28427,
9,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
14451,
50,
4411,
13183,
774,
12,
291,
680,
5996,
342,
272,
291,
14,
12845,
63,
3890,
275,
6170,
63,
12845,
63,
3890,
63,
5472,
14,
6845,
32675,
8,
277,
14,
7125,
63,
24124,
63,
26474,
63,
27522,
9,
272,
291,
14,
1805,
63,
1375,
63,
2301,
275,
4420,
4277,
4547,
8,
267,
1967,
63,
1302,
63,
3406,
29,
277,
14,
7125,
63,
13837,
63,
28427,
9,
339,
2909,
275,
3878,
63,
2301,
14
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
12537,
14,
10646,
14,
7764,
63,
12845,
63,
8627,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
5549,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
2828,
492,
19433,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
3878,
63,
2301,
199,
504,
3228,
14,
2828,
14,
4359,
14,
1548,
14,
4359,
492,
1347,
63,
2301,
465,
1347,
63,
2301,
63,
773,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
5262,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
8336,
63,
12845,
63,
8627,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
1402,
63,
2324,
465,
1402,
63,
2324,
63,
773,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
12044,
63,
498,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
19433,
63,
2330,
199,
504,
3228,
14,
2828,
14,
4643,
14,
1548,
14,
4643,
14,
10646,
492,
1255,
63,
888,
199,
504,
3228,
14,
2828,
14,
12845,
14,
1548,
14,
1483,
492,
6170,
63,
12845,
63,
3890,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
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,
2196,
63,
5176,
199,
504,
3228,
14,
1548,
14,
4857,
492,
5178,
63,
3128,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
22380,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4237,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
22034,
32675,
8,
12845,
14,
32675,
304,
819,
347,
636,
826,
721,
277,
12,
1174,
63,
890,
12,
1072,
63,
890,
304,
272,
291,
423,
929,
63,
890,
275,
1174,
63,
890,
272,
291,
423,
1199,
63,
890,
275,
1072,
63,
890,
819,
768,
1829,
523,
347,
1174,
63,
890,
8,
277,
304,
272,
372,
291,
423,
929,
63,
890,
819,
768,
1829,
523,
347,
1072,
63,
890,
8,
277,
304,
272,
372,
291,
423,
1199,
63,
890,
819,
347,
636,
1250,
721,
277,
12,
4153,
12,
1174,
304,
272,
372,
1625,
63,
1483,
14,
5582,
8,
3711,
395,
1625,
63,
1483,
14,
4548,
8,
267,
359,
1144,
63,
1483,
14,
1392,
8,
3711,
2788,
16,
467,
291,
14,
929,
63,
890,
566,
421,
199,
533,
4420,
4277,
4547,
8,
785,
304,
819,
347,
636,
826,
721,
277,
12,
1967,
63,
1302,
63,
3406,
29,
403,
304,
272,
291,
423,
1507,
63,
1302,
63,
3406,
275,
1967,
63,
1302,
63,
3406,
819,
347,
664,
63,
2579,
63,
1483,
8,
277,
12,
4534,
12,
32038,
12,
3628,
12,
7186,
304,
272,
746,
4279,
8,
267,
283,
3346,
4277,
4547,
14,
362,
63,
2579,
63,
1483,
2797,
10537,
590,
2659,
819,
347,
11051,
63,
475,
63,
9869,
8,
277,
12,
18767,
63,
31117,
12,
557,
2470,
29,
797,
304,
272,
746,
4279,
8,
267,
283,
3346,
4277,
4547,
14,
10492,
63,
475,
63,
9869,
2797,
10537,
590,
2659,
819,
347,
5621,
8,
277,
12,
32038,
12,
3628,
12,
4534,
304,
272,
746,
4279,
360,
3346,
4277,
4547,
14,
4358,
2797,
10537,
590,
2659,
819,
768,
1829,
523,
347,
1967,
63,
1302,
63,
3406,
8,
277,
304,
272,
340,
291,
423,
1507,
63,
1302,
63,
3406,
365,
488,
26,
489,
746,
1722,
360,
3346,
4277,
4547,
14,
1507,
63,
1302,
63,
3406,
965,
440,
2757,
663,
2659,
272,
372,
291,
423,
1507,
63,
1302,
63,
3406,
819,
347,
663,
63,
1507,
63,
1302,
63,
3406,
8,
277,
12,
302,
304,
272,
291,
423,
1507,
63,
1302,
63,
3406,
275,
302,
421,
199,
318,
3414,
63,
1267,
63,
2629,
8,
1459,
12,
17464,
304,
523,
9742,
275,
1338,
523,
367,
284,
12,
2582,
315,
3874,
8,
14563,
304,
272,
9742,
59,
73,
12,
2582,
11941,
12228,
275,
980,
14,
4250,
63,
2930,
8,
11018,
59,
73,
12,
2582,
11941,
520,
566,
523,
372,
9742,
421,
199,
533,
21907,
50,
4411,
13183,
774,
8,
396,
14,
1746,
304,
819,
11576,
63,
24124,
63,
26474,
63,
27522,
275,
1695,
523,
11576,
63,
13837,
63,
28427,
275,
1227,
523,
21955,
51,
63,
21436,
275,
3878,
63,
2301,
14,
3093,
63,
16611,
63,
2301,
8,
489,
283,
3711,
297,
6240,
29,
7125,
63,
13837,
63,
28427,
9,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
14451,
50,
4411,
13183,
774,
12,
291,
680,
5996,
342,
272,
291,
14,
12845,
63,
3890,
275,
6170,
63,
12845,
63,
3890,
63,
5472,
14,
6845,
32675,
8,
277,
14,
7125,
63,
24124,
63,
26474,
63,
27522,
9,
272,
291,
14,
1805,
63,
1375,
63,
2301,
275,
4420,
4277,
4547,
8,
267,
1967,
63,
1302,
63,
3406,
29,
277,
14,
7125,
63,
13837,
63,
28427,
9,
339,
2909,
275,
3878,
63,
2301,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
grupoprog3/proyecto_final
|
Entrega Final/flask/Lib/site-packages/pip/_vendor/requests/packages/chardet/langgreekmodel.py
|
2763
|
12628
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# 255: Control characters that usually does not exist in any text
# 254: Carriage/Return
# 253: symbol (punctuation) that does not belong to word
# 252: 0 - 9
# Character Mapping Table:
Latin7_CharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 82,100,104, 94, 98,101,116,102,111,187,117, 92, 88,113, 85, # 40
79,118,105, 83, 67,114,119, 95, 99,109,188,253,253,253,253,253, # 50
253, 72, 70, 80, 81, 60, 96, 93, 89, 68,120, 97, 77, 86, 69, 55, # 60
78,115, 65, 66, 58, 76,106,103, 87,107,112,253,253,253,253,253, # 70
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 80
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 90
253,233, 90,253,253,253,253,253,253,253,253,253,253, 74,253,253, # a0
253,253,253,253,247,248, 61, 36, 46, 71, 73,253, 54,253,108,123, # b0
110, 31, 51, 43, 41, 34, 91, 40, 52, 47, 44, 53, 38, 49, 59, 39, # c0
35, 48,250, 37, 33, 45, 56, 50, 84, 57,120,121, 17, 18, 22, 15, # d0
124, 1, 29, 20, 21, 3, 32, 13, 25, 5, 11, 16, 10, 6, 30, 4, # e0
9, 8, 14, 7, 2, 12, 28, 23, 42, 24, 64, 75, 19, 26, 27,253, # f0
)
win1253_CharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 82,100,104, 94, 98,101,116,102,111,187,117, 92, 88,113, 85, # 40
79,118,105, 83, 67,114,119, 95, 99,109,188,253,253,253,253,253, # 50
253, 72, 70, 80, 81, 60, 96, 93, 89, 68,120, 97, 77, 86, 69, 55, # 60
78,115, 65, 66, 58, 76,106,103, 87,107,112,253,253,253,253,253, # 70
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 80
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 90
253,233, 61,253,253,253,253,253,253,253,253,253,253, 74,253,253, # a0
253,253,253,253,247,253,253, 36, 46, 71, 73,253, 54,253,108,123, # b0
110, 31, 51, 43, 41, 34, 91, 40, 52, 47, 44, 53, 38, 49, 59, 39, # c0
35, 48,250, 37, 33, 45, 56, 50, 84, 57,120,121, 17, 18, 22, 15, # d0
124, 1, 29, 20, 21, 3, 32, 13, 25, 5, 11, 16, 10, 6, 30, 4, # e0
9, 8, 14, 7, 2, 12, 28, 23, 42, 24, 64, 75, 19, 26, 27,253, # f0
)
# Model Table:
# total sequences: 100%
# first 512 sequences: 98.2851%
# first 1024 sequences:1.7001%
# rest sequences: 0.0359%
# negative sequences: 0.0148%
GreekLangModel = (
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,3,2,2,3,3,3,3,3,3,3,3,1,3,3,3,0,2,2,3,3,0,3,0,3,2,0,3,3,3,0,
3,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,3,3,3,3,3,0,3,3,0,3,2,3,3,0,3,2,3,3,3,0,0,3,0,3,0,3,3,2,0,0,0,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,
0,2,3,2,2,3,3,3,3,3,3,3,3,0,3,3,3,3,0,2,3,3,0,3,3,3,3,2,3,3,3,0,
2,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,0,0,0,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2,0,0,0,
0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,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,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,2,0,2,0,0,0,
0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,2,0,0,0,1,2,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
)
Latin7GreekModel = {
'charToOrderMap': Latin7_CharToOrderMap,
'precedenceMatrix': GreekLangModel,
'mTypicalPositiveRatio': 0.982851,
'keepEnglishLetter': False,
'charsetName': "ISO-8859-7"
}
Win1253GreekModel = {
'charToOrderMap': win1253_CharToOrderMap,
'precedenceMatrix': GreekLangModel,
'mTypicalPositiveRatio': 0.982851,
'keepEnglishLetter': False,
'charsetName': "windows-1253"
}
# flake8: noqa
|
apache-2.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
199,
3,
27210,
26,
378,
446,
1749,
199,
199,
3,
17660,
12340,
6957,
26,
199,
27317,
23,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
199,
3781,
12,
18051,
12,
1960,
12,
6785,
12,
18729,
12,
16096,
12,
4893,
12,
7524,
12,
7759,
12,
6673,
12,
11775,
12,
7362,
12,
20140,
12,
10523,
12,
9225,
12,
16412,
12,
221,
327,
6335,
199,
13734,
12,
7906,
12,
7320,
12,
20582,
12,
13296,
12,
7636,
12,
7119,
12,
16102,
12,
8806,
12,
6996,
12,
11501,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
15323,
12,
10045,
12,
5939,
12,
19071,
12,
5212,
12,
15580,
12,
18969,
12,
17838,
12,
10851,
12,
6708,
12,
15997,
12,
8375,
12,
10300,
12,
14610,
12,
12766,
12,
221,
327,
5212,
199,
14679,
12,
7680,
12,
11738,
12,
14157,
12,
13713,
12,
14646,
12,
7357,
12,
8845,
12,
10513,
12,
7555,
12,
6094,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
5939,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
9137,
199,
3781,
12,
10034,
12,
9137,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
9720,
12,
3781,
12,
3781,
12,
221,
327,
282,
16,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
11717,
12,
11242,
12,
17017,
12,
8780,
12,
12426,
12,
17245,
12,
18525,
12,
3781,
12,
13470,
12,
3781,
12,
8079,
12,
4288,
12,
221,
327,
330,
16,
199,
6019,
12,
7105,
12,
8026,
12,
11851,
12,
13385,
12,
8177,
12,
21358,
12,
6335,
12,
14589,
12,
10954,
12,
10868,
12,
13564,
12,
10448,
12,
12260,
12,
8155,
12,
10551,
12,
221,
327,
286,
16,
199,
8685,
12,
9615,
12,
7991,
12,
6877,
12,
9404,
12,
10416,
12,
12001,
12,
5238,
12,
8264,
12,
12699,
12,
6708,
12,
10753,
12,
5557,
12,
6155,
12,
6928,
12,
4114,
12,
221,
327,
366,
16,
199,
7214,
12,
221,
413,
12,
7349,
12,
3388,
12,
7829,
12,
221,
650,
12,
4337,
12,
4944,
12,
5661,
12,
221,
959,
12,
4119,
12,
3193,
12,
1616,
12,
221,
1227,
12,
4233,
12,
221,
841,
12,
221,
327,
325,
16,
523,
1749,
12,
221,
1695,
12,
4329,
12,
221,
1520,
12,
221,
499,
12,
3144,
12,
7294,
12,
6546,
12,
5685,
12,
5504,
12,
5049,
12,
13098,
12,
5851,
12,
7875,
12,
8087,
12,
3781,
12,
221,
327,
289,
16,
199,
9,
199,
199,
2676,
28452,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
199,
3,
27210,
26,
378,
446,
1749,
199,
199,
3,
17660,
12340,
6957,
26,
199,
27317,
23,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
199,
3781,
12,
18051,
12,
1960,
12,
6785,
12,
18729,
12,
16096,
12,
4893,
12,
7524,
12,
7759,
12,
6673,
12,
11775,
12,
7362,
12,
20140,
12,
10523,
12,
9225,
12,
16412,
12,
221,
327,
6335,
199,
13734,
12,
7906,
12,
7320,
12,
20582,
12,
13296,
12,
7636,
12,
7119,
12,
16102,
12,
8806,
12,
6996,
12,
11501,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
15323,
12,
10045,
12,
5939,
12,
19071,
12,
5212,
12,
15580,
12,
18969,
12,
17838,
12,
10851,
12,
6708,
12,
15997,
12,
8375,
12,
10300,
12,
14610,
12,
12766,
12,
221,
327,
5212,
199,
14679,
12,
7680,
12,
11738,
12,
14157,
12,
13713,
12,
14646,
12,
7357,
12,
8845,
12,
10513,
12,
7555,
12,
6094,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
5939,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
9137,
199,
3781,
12,
10034,
12,
9137,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
9720,
12,
3781,
12,
3781,
12,
221,
327,
282,
16,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
11717,
12,
11242,
12,
17017,
12,
8780,
12,
12426,
12,
17245,
12,
18525,
12,
3781,
12,
13470,
12,
3781,
12,
8079,
12,
4288,
12,
221,
327,
330,
16,
199,
6019,
12,
7105,
12,
8026,
12,
11851,
12,
13385,
12,
8177,
12,
21358,
12,
6335,
12,
14589,
12,
10954,
12,
10868,
12,
13564,
12,
10448,
12,
12260,
12,
8155,
12,
10551,
12,
221,
327,
286,
16,
199,
8685,
12,
9615,
12,
7991,
12,
6877,
12,
9404,
12,
10416,
12,
12001,
12,
5238,
12,
8264,
12,
12699,
12,
6708,
12,
10753,
12,
5557,
12,
6155,
12,
6928,
12,
4114,
12,
221,
327,
366,
16,
199,
7214,
12,
221,
413,
12,
7349,
12,
3388,
12,
7829,
12,
221,
650,
12,
4337,
12,
4944,
12,
5661,
12,
221,
959,
12,
4119,
12,
3193,
12,
1616,
12,
221,
1227,
12,
4233,
12,
221,
841,
12,
221,
327,
325,
16,
523,
1749,
12,
221,
1695,
12,
4329,
12,
221,
1520,
12,
221,
499,
12,
3144,
12,
7294,
12,
6546,
12,
5685,
12,
5504,
12,
5049,
12,
13098,
12,
5851,
12,
7875,
12,
8087,
12,
3781,
12,
221,
327,
289,
16,
199,
9,
199,
199,
2676,
28452,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
meabsence/python-for-android
|
python-build/python-libs/gdata/tests/gdata_tests/docs/service_test.py
|
87
|
17205
|
#!/usr/bin/python
#
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = ('api.jfisher (Jeff Fisher), '
'api.eric@google.com (Eric Bidelman)')
import os
import re
import getpass
import StringIO
import unittest
import gdata.docs.service
import gdata.spreadsheet.service
username = ''
password = ''
class DocumentListQueryTest(unittest.TestCase):
def setUp(self):
self.doclist = client
self.feed = self.doclist.GetDocumentListFeed()
def testGetDocumentsListFeed(self):
self.assert_(isinstance(self.feed, gdata.docs.DocumentListFeed))
uri = 'http://docs.google.com/feeds/documents/private/full/?max-results=1'
# Query using GetDocumentListFeed()
feed = self.doclist.GetDocumentListFeed(uri)
self.assert_(isinstance(feed, gdata.docs.DocumentListFeed))
self.assertEqual(len(feed.entry), 1)
self.assertEqual(self.feed.entry[0].id.text, feed.entry[0].id.text)
self.assertEqual(self.feed.entry[0].title.text, feed.entry[0].title.text)
# Query using QueryDocumentListFeed()
feed2 = self.doclist.QueryDocumentListFeed(uri)
self.assertEqual(len(feed2.entry), 1)
self.assertEqual(self.feed.entry[0].id.text, feed2.entry[0].id.text)
self.assertEqual(self.feed.entry[0].title.text, feed2.entry[0].title.text)
def testGetDocumentsListEntry(self):
self_link = self.feed.entry[0].GetSelfLink().href
entry = self.doclist.GetDocumentListEntry(self_link)
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.assertEqual(self.feed.entry[0].id.text, entry.id.text)
self.assertEqual(self.feed.entry[0].title.text, entry.title.text)
self.assert_(self.feed.entry[0].resourceId.text is not None)
self.assert_(self.feed.entry[0].lastModifiedBy is not None)
self.assert_(self.feed.entry[0].lastViewed is not None)
def testGetDocumentsListAclFeed(self):
uri = ('http://docs.google.com/feeds/documents/private/full/'
'-/mine?max-results=1')
feed = self.doclist.GetDocumentListFeed(uri)
feed_link = feed.entry[0].GetAclLink().href
acl_feed = self.doclist.GetDocumentListAclFeed(feed_link)
self.assert_(isinstance(acl_feed, gdata.docs.DocumentListAclFeed))
self.assert_(isinstance(acl_feed.entry[0], gdata.docs.DocumentListAclEntry))
self.assert_(acl_feed.entry[0].scope is not None)
self.assert_(acl_feed.entry[0].role is not None)
class DocumentListAclTest(unittest.TestCase):
def setUp(self):
self.doclist = client
uri = ('http://docs.google.com/feeds/documents/private/full'
'/-/mine?max-results=1')
self.feed = self.doclist.GetDocumentListFeed(uri)
self.EMAIL = 'x@example.com'
self.SCOPE_TYPE = 'user'
self.ROLE_VALUE = 'reader'
def testCreateAndUpdateAndDeleteAcl(self):
# Add new ACL
scope = gdata.docs.Scope(value=self.EMAIL, type=self.SCOPE_TYPE)
role = gdata.docs.Role(value=self.ROLE_VALUE)
acl_entry = self.doclist.Post(
gdata.docs.DocumentListAclEntry(scope=scope, role=role),
self.feed.entry[0].GetAclLink().href,
converter=gdata.docs.DocumentListAclEntryFromString)
self.assert_(isinstance(acl_entry, gdata.docs.DocumentListAclEntry))
self.assertEqual(acl_entry.scope.value, self.EMAIL)
self.assertEqual(acl_entry.scope.type, self.SCOPE_TYPE)
self.assertEqual(acl_entry.role.value, self.ROLE_VALUE)
# Update the user's role
ROLE_VALUE = 'writer'
acl_entry.role.value = ROLE_VALUE
updated_acl_entry = self.doclist.Put(
acl_entry, acl_entry.GetEditLink().href,
converter=gdata.docs.DocumentListAclEntryFromString)
self.assertEqual(updated_acl_entry.scope.value, self.EMAIL)
self.assertEqual(updated_acl_entry.scope.type, self.SCOPE_TYPE)
self.assertEqual(updated_acl_entry.role.value, ROLE_VALUE)
# Delete the ACL
self.doclist.Delete(updated_acl_entry.GetEditLink().href)
# Make sure entry was actually deleted
acl_feed = self.doclist.GetDocumentListAclFeed(
self.feed.entry[0].GetAclLink().href)
for acl_entry in acl_feed.entry:
self.assert_(acl_entry.scope.value != self.EMAIL)
class DocumentListCreateAndDeleteTest(unittest.TestCase):
def setUp(self):
self.doclist = client
self.TITLE = 'Test title'
self.new_entry = gdata.docs.DocumentListEntry()
category = gdata.atom.Category(scheme=gdata.docs.service.DATA_KIND_SCHEME,
term=gdata.docs.service.DOCUMENT_KIND_TERM,
label='document')
self.new_entry.category.append(category)
def testCreateAndDeleteEmptyDocumentSlugHeaderTitle(self):
created_entry = self.doclist.Post(self.new_entry,
'/feeds/documents/private/full',
extra_headers={'Slug': self.TITLE})
self.doclist.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'document')
def testCreateAndDeleteEmptyDocumentAtomTitle(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
created_entry = self.doclist.Post(self.new_entry,
'/feeds/documents/private/full')
self.doclist.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'document')
def testCreateAndDeleteEmptySpreadsheet(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
self.new_entry.category[0].term = gdata.docs.service.SPREADSHEET_KIND_TERM
self.new_entry.category[0].label = 'spreadsheet'
created_entry = self.doclist.Post(self.new_entry,
'/feeds/documents/private/full')
self.doclist.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'spreadsheet')
def testCreateAndDeleteEmptyPresentation(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
self.new_entry.category[0].term = gdata.docs.service.PRESENTATION_KIND_TERM
self.new_entry.category[0].label = 'presentation'
created_entry = self.doclist.Post(self.new_entry,
'/feeds/documents/private/full')
self.doclist.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'presentation')
def testCreateAndDeleteFolder(self):
folder_name = 'TestFolder'
folder = self.doclist.CreateFolder(folder_name)
self.assertEqual(folder.title.text, folder_name)
self.doclist.Delete(folder.GetEditLink().href)
def testCreateAndDeleteFolderInFolder(self):
DEST_FOLDER_NAME = 'TestFolder'
CREATED_FOLDER_NAME = 'TestFolder2'
dest_folder = self.doclist.CreateFolder(DEST_FOLDER_NAME)
new_folder = self.doclist.CreateFolder(CREATED_FOLDER_NAME, dest_folder)
for category in new_folder.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(new_folder.category[0].label, DEST_FOLDER_NAME)
break
# delete the folders we created
dest_folder = self.doclist.Get(dest_folder.GetSelfLink().href)
self.doclist.Delete(dest_folder.GetEditLink().href)
uri = 'http://docs.google.com/feeds/documents/private/full'
uri += '/-/folder?q=%s&showfolders=true' % (CREATED_FOLDER_NAME,)
folders = self.doclist.GetDocumentListFeed(uri)
self.doclist.Delete(folders.entry[0].GetEditLink().href)
class DocumentListMoveInAndOutOfFolderTest(unittest.TestCase):
def setUp(self):
self.doclist = client
self.folder_name = 'TestFolder'
self.folder = self.doclist.CreateFolder(self.folder_name)
self.doc_title = 'TestDoc'
self.ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
def tearDown(self):
folder = self.doclist.Get(self.folder.GetSelfLink().href)
self.doclist.Delete(folder.GetEditLink().href)
def testUploadDocumentToFolder(self):
created_entry = self.doclist.UploadDocument(self.ms, self.doc_title,
self.folder)
for category in created_entry.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(category.label, self.folder_name)
break
# delete the doc we created
created_entry = self.doclist.Get(created_entry.GetSelfLink().href)
match = re.search('\/(document%3A[^\/]*)\/?.*?\/(.*)$',
created_entry.GetEditLink().href)
edit_uri = 'http://docs.google.com/feeds/documents/private/full/'
edit_uri += '%s/%s' % (match.group(1), match.group(2))
self.doclist.Delete(edit_uri)
def testMoveDocumentInAndOutOfFolder(self):
created_entry = self.doclist.UploadDocument(self.ms, self.doc_title)
moved_entry = self.doclist.MoveDocumentIntoFolder(created_entry,
self.folder)
for category in moved_entry.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(category.label, self.folder_name)
break
self.doclist.MoveOutOfFolder(moved_entry)
moved_entry = self.doclist.Get(moved_entry.GetSelfLink().href)
for category in moved_entry.category:
starts_with_folder__prefix = category.scheme.startswith(
gdata.docs.service.FOLDERS_SCHEME_PREFIX)
self.assert_(not starts_with_folder__prefix)
created_entry = self.doclist.Get(created_entry.GetSelfLink().href)
self.doclist.Delete(created_entry.GetEditLink().href)
def testMoveFolderIntoFolder(self):
dest_folder_name = 'DestFolderName'
dest_folder = self.doclist.CreateFolder(dest_folder_name)
self.doclist.MoveFolderIntoFolder(self.folder, dest_folder)
self.folder = self.doclist.Get(self.folder.GetSelfLink().href)
folder_was_moved = False
for category in self.folder.category:
if category.term == dest_folder_name:
folder_was_moved = True
break
self.assert_(folder_was_moved)
#cleanup
dest_folder = self.doclist.Get(dest_folder.GetSelfLink().href)
self.doclist.Delete(dest_folder.GetEditLink().href)
class DocumentListUploadTest(unittest.TestCase):
def setUp(self):
self.doclist = client
def testUploadAndDeleteDocument(self):
ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
entry = self.doclist.UploadDocument(ms, 'test doc')
self.assertEqual(entry.title.text, 'test doc')
self.assertEqual(entry.category[0].label, 'document')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.doclist.Delete(entry.GetEditLink().href)
def testUploadAndDeletePresentation(self):
ms = gdata.MediaSource(file_path='test.ppt',
content_type='application/vnd.ms-powerpoint')
entry = self.doclist.UploadPresentation(ms, 'test preso')
self.assertEqual(entry.title.text, 'test preso')
self.assertEqual(entry.category[0].label, 'presentation')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.doclist.Delete(entry.GetEditLink().href)
def testUploadAndDeleteSpreadsheet(self):
ms = gdata.MediaSource(file_path='test.csv',
content_type='text/csv')
entry = self.doclist.UploadSpreadsheet(ms, 'test spreadsheet')
self.assert_(entry.title.text == 'test spreadsheet')
self.assertEqual(entry.category[0].label, 'spreadsheet')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.doclist.Delete(entry.GetEditLink().href)
class DocumentListUpdateTest(unittest.TestCase):
def setUp(self):
self.doclist = client
self.TITLE = 'CreatedTestDoc'
new_entry = gdata.docs.DocumentListEntry()
new_entry.title = gdata.atom.Title(text=self.TITLE)
new_entry.category.append(
gdata.atom.Category(scheme=gdata.docs.service.DATA_KIND_SCHEME,
term=gdata.docs.service.DOCUMENT_KIND_TERM,
label='document'))
self.created_entry = self.doclist.Post(new_entry,
'/feeds/documents/private/full')
def tearDown(self):
# Delete the test doc we created
self_link = self.created_entry.GetSelfLink().href
entry = self.doclist.GetDocumentListEntry(self_link)
self.doclist.Delete(entry.GetEditLink().href)
def testUpdateDocumentMetadataAndContent(self):
title = 'UpdatedTestDoc'
# Update metadata
self.created_entry.title.text = title
updated_entry = self.doclist.Put(self.created_entry,
self.created_entry.GetEditLink().href)
self.assertEqual(updated_entry.title.text, title)
# Update document's content
ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
uri = updated_entry.GetEditMediaLink().href
updated_entry = self.doclist.Put(ms, uri)
self.assertEqual(updated_entry.title.text, title)
# Append content to document
data = 'data to append'
ms = gdata.MediaSource(file_handle=StringIO.StringIO(data),
content_type='text/plain',
content_length=len(data))
uri = updated_entry.GetEditMediaLink().href + '?append=true'
updated_entry = self.doclist.Put(ms, uri)
class DocumentListExportTest(unittest.TestCase):
def setUp(self):
self.doclist = client
self.spreadsheets = spreadsheets
def testExportDocument(self):
query = ('http://docs.google.com/feeds/documents/private/full'
'/-/document?max-results=1')
feed = self.doclist.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.doc', './downloadedTest.html',
'./downloadedTest.odt', './downloadedTest.pdf',
'./downloadedTest.png', './downloadedTest.rtf',
'./downloadedTest.txt', './downloadedTest.zip']
for path in file_paths:
self.doclist.DownloadDocument(feed.entry[0], path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path))
os.remove(path)
def testExportPresentation(self):
query = ('http://docs.google.com/feeds/documents/private/full'
'/-/presentation?max-results=1')
feed = self.doclist.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.pdf', './downloadedTest.ppt',
'./downloadedTest.swf', './downloadedTest.txt']
for path in file_paths:
self.doclist.DownloadPresentation(feed.entry[0].resourceId.text, path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path))
os.remove(path)
def testExportSpreadsheet(self):
query = ('http://docs.google.com/feeds/documents/private/full'
'/-/spreadsheet?max-results=1')
feed = self.doclist.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.xls', './downloadedTest.csv',
'./downloadedTest.pdf', './downloadedTest.ods',
'./downloadedTest.tsv', './downloadedTest.html']
docs_token = self.doclist.GetClientLoginToken()
self.doclist.SetClientLoginToken(self.spreadsheets.GetClientLoginToken())
for path in file_paths:
self.doclist.DownloadSpreadsheet(feed.entry[0], path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path))
os.remove(path)
self.doclist.SetClientLoginToken(docs_token)
def testExportNonExistentDocument(self):
path = './ned.txt'
exception_raised = False
try:
self.doclist.DownloadDocument('non_existent_doc', path)
except Exception, e: # expected
exception_raised = True
self.assert_(exception_raised)
self.assert_(not os.path.exists(path))
if __name__ == '__main__':
print ('DocList API Tests\nNOTE: Please run these tests only with a test '
'account. The tests may delete or update your data.')
username = raw_input('Please enter your username: ')
password = getpass.getpass()
client = gdata.docs.service.DocsService()
spreadsheets = gdata.spreadsheet.service.SpreadsheetsService()
client.ClientLogin(username, password,
source='Document List Client Unit Tests')
spreadsheets.ClientLogin(username, password,
source='Document List Client Unit Tests')
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
74,
16056,
281,
334,
42,
3609,
481,
2453,
281,
395,
283,
1598,
283,
1246,
14,
281,
530,
32,
3098,
14,
957,
334,
37,
1567,
31012,
2264,
1237,
5942,
199,
199,
646,
747,
199,
646,
295,
199,
646,
18354,
199,
646,
5228,
199,
646,
2882,
199,
646,
11006,
14,
4757,
14,
1364,
199,
646,
11006,
14,
19930,
14,
1364,
199,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
421,
199,
533,
7543,
1296,
3227,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1301,
513,
275,
1890,
272,
291,
14,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
342,
819,
347,
19970,
26872,
1296,
7658,
8,
277,
304,
272,
291,
14,
479,
2531,
6074,
8,
277,
14,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
5108,
275,
283,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
10197,
988,
13,
2604,
29,
17,
7,
339,
327,
8133,
1808,
2372,
5564,
1296,
7658,
342,
272,
4733,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
479,
2531,
6074,
8,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
291,
14,
629,
8,
552,
8,
3871,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
339,
327,
8133,
1808,
8133,
5564,
1296,
7658,
342,
272,
4733,
18,
275,
291,
14,
1301,
513,
14,
3227,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
629,
8,
552,
8,
3871,
18,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
819,
347,
19970,
26872,
16934,
8,
277,
304,
272,
291,
63,
1073,
275,
291,
14,
3871,
14,
2373,
59,
16,
1055,
1002,
12887,
3834,
1252,
6399,
272,
2397,
275,
291,
14,
1301,
513,
14,
1002,
5564,
16934,
8,
277,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
2373,
12,
11006,
14,
4757,
14,
5564,
16934,
430,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
2397,
14,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
2397,
14,
1213,
14,
505,
9,
339,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1927,
1304,
14,
505,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
11911,
2175,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
2768,
379,
365,
440,
488,
9,
819,
347,
19970,
26872,
1296,
23937,
7658,
8,
277,
304,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
4805,
1779,
2475,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
4733,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
4733,
63,
1073,
275,
4733,
14,
2373,
59,
16,
1055,
1002,
23937,
3834,
1252,
6399,
272,
15316,
63,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
23937,
7658,
8,
3871,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
23937,
7658,
430,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
14,
2373,
59,
16,
467,
11006,
14,
4757,
14,
5564,
1296,
23937,
3900,
430,
272,
291,
14,
479,
2531,
5853,
63,
3871,
14,
2373,
59,
16,
1055,
2645,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
5853,
63,
3871,
14,
2373,
59,
16,
1055,
3756,
365,
440,
488,
9,
421,
199,
533,
7543,
1296,
23937,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1301,
513,
275,
1890,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
7,
1779,
1994,
13,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
291,
14,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
339,
291,
14,
10089,
275,
283,
88,
32,
2694,
14,
957,
7,
272,
291,
14,
17998,
63,
2711,
275,
283,
751,
7,
272,
291,
14,
15468,
63,
7041,
275,
283,
5503,
7,
819,
347,
511,
2499,
3325,
4152,
3325,
5392,
23937,
8,
277,
304,
272,
327,
2654,
892,
16543,
272,
4194,
275,
11006,
14,
4757,
14,
7812,
8,
585,
29,
277,
14,
10089,
12,
730,
29,
277,
14,
17998,
63,
2711,
9,
272,
4719,
275,
11006,
14,
4757,
14,
7422,
8,
585,
29,
277,
14,
15468,
63,
7041,
9,
339
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
74,
16056,
281,
334,
42,
3609,
481,
2453,
281,
395,
283,
1598,
283,
1246,
14,
281,
530,
32,
3098,
14,
957,
334,
37,
1567,
31012,
2264,
1237,
5942,
199,
199,
646,
747,
199,
646,
295,
199,
646,
18354,
199,
646,
5228,
199,
646,
2882,
199,
646,
11006,
14,
4757,
14,
1364,
199,
646,
11006,
14,
19930,
14,
1364,
199,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
421,
199,
533,
7543,
1296,
3227,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1301,
513,
275,
1890,
272,
291,
14,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
342,
819,
347,
19970,
26872,
1296,
7658,
8,
277,
304,
272,
291,
14,
479,
2531,
6074,
8,
277,
14,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
5108,
275,
283,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
10197,
988,
13,
2604,
29,
17,
7,
339,
327,
8133,
1808,
2372,
5564,
1296,
7658,
342,
272,
4733,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
479,
2531,
6074,
8,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
291,
14,
629,
8,
552,
8,
3871,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
339,
327,
8133,
1808,
8133,
5564,
1296,
7658,
342,
272,
4733,
18,
275,
291,
14,
1301,
513,
14,
3227,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
629,
8,
552,
8,
3871,
18,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
819,
347,
19970,
26872,
16934,
8,
277,
304,
272,
291,
63,
1073,
275,
291,
14,
3871,
14,
2373,
59,
16,
1055,
1002,
12887,
3834,
1252,
6399,
272,
2397,
275,
291,
14,
1301,
513,
14,
1002,
5564,
16934,
8,
277,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
2373,
12,
11006,
14,
4757,
14,
5564,
16934,
430,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
2397,
14,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
2397,
14,
1213,
14,
505,
9,
339,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1927,
1304,
14,
505,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
11911,
2175,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
2768,
379,
365,
440,
488,
9,
819,
347,
19970,
26872,
1296,
23937,
7658,
8,
277,
304,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
4805,
1779,
2475,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
4733,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
4733,
63,
1073,
275,
4733,
14,
2373,
59,
16,
1055,
1002,
23937,
3834,
1252,
6399,
272,
15316,
63,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
23937,
7658,
8,
3871,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
23937,
7658,
430,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
14,
2373,
59,
16,
467,
11006,
14,
4757,
14,
5564,
1296,
23937,
3900,
430,
272,
291,
14,
479,
2531,
5853,
63,
3871,
14,
2373,
59,
16,
1055,
2645,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
5853,
63,
3871,
14,
2373,
59,
16,
1055,
3756,
365,
440,
488,
9,
421,
199,
533,
7543,
1296,
23937,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
1301,
513,
275,
1890,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
7,
1779,
1994,
13,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
291,
14,
3871,
275,
291,
14,
1301,
513,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
339,
291,
14,
10089,
275,
283,
88,
32,
2694,
14,
957,
7,
272,
291,
14,
17998,
63,
2711,
275,
283,
751,
7,
272,
291,
14,
15468,
63,
7041,
275,
283,
5503,
7,
819,
347,
511,
2499,
3325,
4152,
3325,
5392,
23937,
8,
277,
304,
272,
327,
2654,
892,
16543,
272,
4194,
275,
11006,
14,
4757,
14,
7812,
8,
585,
29,
277,
14,
10089,
12,
730,
29,
277,
14,
17998,
63,
2711,
9,
272,
4719,
275,
11006,
14,
4757,
14,
7422,
8,
585,
29,
277,
14,
15468,
63,
7041,
9,
339,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gavinengel/gavinengel.github.io
|
aeonx/node_modules/harp/node_modules/terraform/node_modules/node-sass/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py
|
1355
|
44604
|
# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""cmake output module
This module is under development and should be considered experimental.
This module produces cmake (2.8.8+) input as its output. One CMakeLists.txt is
created for each configuration.
This module's original purpose was to support editing in IDEs like KDevelop
which use CMake for project management. It is also possible to use CMake to
generate projects for other IDEs such as eclipse cdt and code::blocks. QtCreator
will convert the CMakeLists.txt to a code::blocks cbp for the editor to read,
but build using CMake. As a result QtCreator editor is unaware of compiler
defines. The generated CMakeLists.txt can also be used to build on Linux. There
is currently no support for building on platforms other than Linux.
The generated CMakeLists.txt should properly compile all projects. However,
there is a mismatch between gyp and cmake with regard to linking. All attempts
are made to work around this, but CMake sometimes sees -Wl,--start-group as a
library and incorrectly repeats it. As a result the output of this generator
should not be relied on for building.
When using with kdevelop, use version 4.4+. Previous versions of kdevelop will
not be able to find the header file directories described in the generated
CMakeLists.txt file.
"""
import multiprocessing
import os
import signal
import string
import subprocess
import gyp.common
generator_default_variables = {
'EXECUTABLE_PREFIX': '',
'EXECUTABLE_SUFFIX': '',
'STATIC_LIB_PREFIX': 'lib',
'STATIC_LIB_SUFFIX': '.a',
'SHARED_LIB_PREFIX': 'lib',
'SHARED_LIB_SUFFIX': '.so',
'SHARED_LIB_DIR': '${builddir}/lib.${TOOLSET}',
'LIB_DIR': '${obj}.${TOOLSET}',
'INTERMEDIATE_DIR': '${obj}.${TOOLSET}/${TARGET}/geni',
'SHARED_INTERMEDIATE_DIR': '${obj}/gen',
'PRODUCT_DIR': '${builddir}',
'RULE_INPUT_PATH': '${RULE_INPUT_PATH}',
'RULE_INPUT_DIRNAME': '${RULE_INPUT_DIRNAME}',
'RULE_INPUT_NAME': '${RULE_INPUT_NAME}',
'RULE_INPUT_ROOT': '${RULE_INPUT_ROOT}',
'RULE_INPUT_EXT': '${RULE_INPUT_EXT}',
'CONFIGURATION_NAME': '${configuration}',
}
FULL_PATH_VARS = ('${CMAKE_CURRENT_LIST_DIR}', '${builddir}', '${obj}')
generator_supports_multiple_toolsets = True
generator_wants_static_library_dependencies_adjusted = True
COMPILABLE_EXTENSIONS = {
'.c': 'cc',
'.cc': 'cxx',
'.cpp': 'cxx',
'.cxx': 'cxx',
'.s': 's', # cc
'.S': 's', # cc
}
def RemovePrefix(a, prefix):
"""Returns 'a' without 'prefix' if it starts with 'prefix'."""
return a[len(prefix):] if a.startswith(prefix) else a
def CalculateVariables(default_variables, params):
"""Calculate additional variables for use in the build (called by gyp)."""
default_variables.setdefault('OS', gyp.common.GetFlavor(params))
def Compilable(filename):
"""Return true if the file is compilable (should be in OBJS)."""
return any(filename.endswith(e) for e in COMPILABLE_EXTENSIONS)
def Linkable(filename):
"""Return true if the file is linkable (should be on the link line)."""
return filename.endswith('.o')
def NormjoinPathForceCMakeSource(base_path, rel_path):
"""Resolves rel_path against base_path and returns the result.
If rel_path is an absolute path it is returned unchanged.
Otherwise it is resolved against base_path and normalized.
If the result is a relative path, it is forced to be relative to the
CMakeLists.txt.
"""
if os.path.isabs(rel_path):
return rel_path
if any([rel_path.startswith(var) for var in FULL_PATH_VARS]):
return rel_path
# TODO: do we need to check base_path for absolute variables as well?
return os.path.join('${CMAKE_CURRENT_LIST_DIR}',
os.path.normpath(os.path.join(base_path, rel_path)))
def NormjoinPath(base_path, rel_path):
"""Resolves rel_path against base_path and returns the result.
TODO: what is this really used for?
If rel_path begins with '$' it is returned unchanged.
Otherwise it is resolved against base_path if relative, then normalized.
"""
if rel_path.startswith('$') and not rel_path.startswith('${configuration}'):
return rel_path
return os.path.normpath(os.path.join(base_path, rel_path))
def CMakeStringEscape(a):
"""Escapes the string 'a' for use inside a CMake string.
This means escaping
'\' otherwise it may be seen as modifying the next character
'"' otherwise it will end the string
';' otherwise the string becomes a list
The following do not need to be escaped
'#' when the lexer is in string state, this does not start a comment
The following are yet unknown
'$' generator variables (like ${obj}) must not be escaped,
but text $ should be escaped
what is wanted is to know which $ come from generator variables
"""
return a.replace('\\', '\\\\').replace(';', '\\;').replace('"', '\\"')
def SetFileProperty(output, source_name, property_name, values, sep):
"""Given a set of source file, sets the given property on them."""
output.write('set_source_files_properties(')
output.write(source_name)
output.write(' PROPERTIES ')
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetFilesProperty(output, variable, property_name, values, sep):
"""Given a set of source files, sets the given property on them."""
output.write('set_source_files_properties(')
WriteVariable(output, variable)
output.write(' PROPERTIES ')
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetTargetProperty(output, target_name, property_name, values, sep=''):
"""Given a target, sets the given property."""
output.write('set_target_properties(')
output.write(target_name)
output.write(' PROPERTIES ')
output.write(property_name)
output.write(' "')
for value in values:
output.write(CMakeStringEscape(value))
output.write(sep)
output.write('")\n')
def SetVariable(output, variable_name, value):
"""Sets a CMake variable."""
output.write('set(')
output.write(variable_name)
output.write(' "')
output.write(CMakeStringEscape(value))
output.write('")\n')
def SetVariableList(output, variable_name, values):
"""Sets a CMake variable to a list."""
if not values:
return SetVariable(output, variable_name, "")
if len(values) == 1:
return SetVariable(output, variable_name, values[0])
output.write('list(APPEND ')
output.write(variable_name)
output.write('\n "')
output.write('"\n "'.join([CMakeStringEscape(value) for value in values]))
output.write('")\n')
def UnsetVariable(output, variable_name):
"""Unsets a CMake variable."""
output.write('unset(')
output.write(variable_name)
output.write(')\n')
def WriteVariable(output, variable_name, prepend=None):
if prepend:
output.write(prepend)
output.write('${')
output.write(variable_name)
output.write('}')
class CMakeTargetType(object):
def __init__(self, command, modifier, property_modifier):
self.command = command
self.modifier = modifier
self.property_modifier = property_modifier
cmake_target_type_from_gyp_target_type = {
'executable': CMakeTargetType('add_executable', None, 'RUNTIME'),
'static_library': CMakeTargetType('add_library', 'STATIC', 'ARCHIVE'),
'shared_library': CMakeTargetType('add_library', 'SHARED', 'LIBRARY'),
'loadable_module': CMakeTargetType('add_library', 'MODULE', 'LIBRARY'),
'none': CMakeTargetType('add_custom_target', 'SOURCES', None),
}
def StringToCMakeTargetName(a):
"""Converts the given string 'a' to a valid CMake target name.
All invalid characters are replaced by '_'.
Invalid for cmake: ' ', '/', '(', ')', '"'
Invalid for make: ':'
Invalid for unknown reasons but cause failures: '.'
"""
return a.translate(string.maketrans(' /():."', '_______'))
def WriteActions(target_name, actions, extra_sources, extra_deps,
path_to_gyp, output):
"""Write CMake for the 'actions' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_sources: [(<cmake_src>, <src>)] to append with generated source files.
extra_deps: [<cmake_taget>] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
for action in actions:
action_name = StringToCMakeTargetName(action['action_name'])
action_target_name = '%s__%s' % (target_name, action_name)
inputs = action['inputs']
inputs_name = action_target_name + '__input'
SetVariableList(output, inputs_name,
[NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs])
outputs = action['outputs']
cmake_outputs = [NormjoinPathForceCMakeSource(path_to_gyp, out)
for out in outputs]
outputs_name = action_target_name + '__output'
SetVariableList(output, outputs_name, cmake_outputs)
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = set(dir for dir in (os.path.dirname(o) for o in outputs) if dir)
if int(action.get('process_outputs_as_sources', False)):
extra_sources.extend(zip(cmake_outputs, outputs))
# add_custom_command
output.write('add_custom_command(OUTPUT ')
WriteVariable(output, outputs_name)
output.write('\n')
if len(dirs) > 0:
for directory in dirs:
output.write(' COMMAND ${CMAKE_COMMAND} -E make_directory ')
output.write(directory)
output.write('\n')
output.write(' COMMAND ')
output.write(gyp.common.EncodePOSIXShellList(action['action']))
output.write('\n')
output.write(' DEPENDS ')
WriteVariable(output, inputs_name)
output.write('\n')
output.write(' WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')
output.write(' COMMENT ')
if 'message' in action:
output.write(action['message'])
else:
output.write(action_target_name)
output.write('\n')
output.write(' VERBATIM\n')
output.write(')\n')
# add_custom_target
output.write('add_custom_target(')
output.write(action_target_name)
output.write('\n DEPENDS ')
WriteVariable(output, outputs_name)
output.write('\n SOURCES ')
WriteVariable(output, inputs_name)
output.write('\n)\n')
extra_deps.append(action_target_name)
def NormjoinRulePathForceCMakeSource(base_path, rel_path, rule_source):
if rel_path.startswith(("${RULE_INPUT_PATH}","${RULE_INPUT_DIRNAME}")):
if any([rule_source.startswith(var) for var in FULL_PATH_VARS]):
return rel_path
return NormjoinPathForceCMakeSource(base_path, rel_path)
def WriteRules(target_name, rules, extra_sources, extra_deps,
path_to_gyp, output):
"""Write CMake for the 'rules' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_sources: [(<cmake_src>, <src>)] to append with generated source files.
extra_deps: [<cmake_taget>] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
for rule in rules:
rule_name = StringToCMakeTargetName(target_name + '__' + rule['rule_name'])
inputs = rule.get('inputs', [])
inputs_name = rule_name + '__input'
SetVariableList(output, inputs_name,
[NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs])
outputs = rule['outputs']
var_outputs = []
for count, rule_source in enumerate(rule.get('rule_sources', [])):
action_name = rule_name + '_' + str(count)
rule_source_dirname, rule_source_basename = os.path.split(rule_source)
rule_source_root, rule_source_ext = os.path.splitext(rule_source_basename)
SetVariable(output, 'RULE_INPUT_PATH', rule_source)
SetVariable(output, 'RULE_INPUT_DIRNAME', rule_source_dirname)
SetVariable(output, 'RULE_INPUT_NAME', rule_source_basename)
SetVariable(output, 'RULE_INPUT_ROOT', rule_source_root)
SetVariable(output, 'RULE_INPUT_EXT', rule_source_ext)
# Build up a list of outputs.
# Collect the output dirs we'll need.
dirs = set(dir for dir in (os.path.dirname(o) for o in outputs) if dir)
# Create variables for the output, as 'local' variable will be unset.
these_outputs = []
for output_index, out in enumerate(outputs):
output_name = action_name + '_' + str(output_index)
SetVariable(output, output_name,
NormjoinRulePathForceCMakeSource(path_to_gyp, out,
rule_source))
if int(rule.get('process_outputs_as_sources', False)):
extra_sources.append(('${' + output_name + '}', out))
these_outputs.append('${' + output_name + '}')
var_outputs.append('${' + output_name + '}')
# add_custom_command
output.write('add_custom_command(OUTPUT\n')
for out in these_outputs:
output.write(' ')
output.write(out)
output.write('\n')
for directory in dirs:
output.write(' COMMAND ${CMAKE_COMMAND} -E make_directory ')
output.write(directory)
output.write('\n')
output.write(' COMMAND ')
output.write(gyp.common.EncodePOSIXShellList(rule['action']))
output.write('\n')
output.write(' DEPENDS ')
WriteVariable(output, inputs_name)
output.write(' ')
output.write(NormjoinPath(path_to_gyp, rule_source))
output.write('\n')
# CMAKE_CURRENT_LIST_DIR is where the CMakeLists.txt lives.
# The cwd is the current build directory.
output.write(' WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')
output.write(' COMMENT ')
if 'message' in rule:
output.write(rule['message'])
else:
output.write(action_name)
output.write('\n')
output.write(' VERBATIM\n')
output.write(')\n')
UnsetVariable(output, 'RULE_INPUT_PATH')
UnsetVariable(output, 'RULE_INPUT_DIRNAME')
UnsetVariable(output, 'RULE_INPUT_NAME')
UnsetVariable(output, 'RULE_INPUT_ROOT')
UnsetVariable(output, 'RULE_INPUT_EXT')
# add_custom_target
output.write('add_custom_target(')
output.write(rule_name)
output.write(' DEPENDS\n')
for out in var_outputs:
output.write(' ')
output.write(out)
output.write('\n')
output.write('SOURCES ')
WriteVariable(output, inputs_name)
output.write('\n')
for rule_source in rule.get('rule_sources', []):
output.write(' ')
output.write(NormjoinPath(path_to_gyp, rule_source))
output.write('\n')
output.write(')\n')
extra_deps.append(rule_name)
def WriteCopies(target_name, copies, extra_deps, path_to_gyp, output):
"""Write CMake for the 'copies' in the target.
Args:
target_name: the name of the CMake target being generated.
actions: the Gyp 'actions' dict for this target.
extra_deps: [<cmake_taget>] to append with generated targets.
path_to_gyp: relative path from CMakeLists.txt being generated to
the Gyp file in which the target being generated is defined.
"""
copy_name = target_name + '__copies'
# CMake gets upset with custom targets with OUTPUT which specify no output.
have_copies = any(copy['files'] for copy in copies)
if not have_copies:
output.write('add_custom_target(')
output.write(copy_name)
output.write(')\n')
extra_deps.append(copy_name)
return
class Copy(object):
def __init__(self, ext, command):
self.cmake_inputs = []
self.cmake_outputs = []
self.gyp_inputs = []
self.gyp_outputs = []
self.ext = ext
self.inputs_name = None
self.outputs_name = None
self.command = command
file_copy = Copy('', 'copy')
dir_copy = Copy('_dirs', 'copy_directory')
for copy in copies:
files = copy['files']
destination = copy['destination']
for src in files:
path = os.path.normpath(src)
basename = os.path.split(path)[1]
dst = os.path.join(destination, basename)
copy = file_copy if os.path.basename(src) else dir_copy
copy.cmake_inputs.append(NormjoinPathForceCMakeSource(path_to_gyp, src))
copy.cmake_outputs.append(NormjoinPathForceCMakeSource(path_to_gyp, dst))
copy.gyp_inputs.append(src)
copy.gyp_outputs.append(dst)
for copy in (file_copy, dir_copy):
if copy.cmake_inputs:
copy.inputs_name = copy_name + '__input' + copy.ext
SetVariableList(output, copy.inputs_name, copy.cmake_inputs)
copy.outputs_name = copy_name + '__output' + copy.ext
SetVariableList(output, copy.outputs_name, copy.cmake_outputs)
# add_custom_command
output.write('add_custom_command(\n')
output.write('OUTPUT')
for copy in (file_copy, dir_copy):
if copy.outputs_name:
WriteVariable(output, copy.outputs_name, ' ')
output.write('\n')
for copy in (file_copy, dir_copy):
for src, dst in zip(copy.gyp_inputs, copy.gyp_outputs):
# 'cmake -E copy src dst' will create the 'dst' directory if needed.
output.write('COMMAND ${CMAKE_COMMAND} -E %s ' % copy.command)
output.write(src)
output.write(' ')
output.write(dst)
output.write("\n")
output.write('DEPENDS')
for copy in (file_copy, dir_copy):
if copy.inputs_name:
WriteVariable(output, copy.inputs_name, ' ')
output.write('\n')
output.write('WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
output.write(path_to_gyp)
output.write('\n')
output.write('COMMENT Copying for ')
output.write(target_name)
output.write('\n')
output.write('VERBATIM\n')
output.write(')\n')
# add_custom_target
output.write('add_custom_target(')
output.write(copy_name)
output.write('\n DEPENDS')
for copy in (file_copy, dir_copy):
if copy.outputs_name:
WriteVariable(output, copy.outputs_name, ' ')
output.write('\n SOURCES')
if file_copy.inputs_name:
WriteVariable(output, file_copy.inputs_name, ' ')
output.write('\n)\n')
extra_deps.append(copy_name)
def CreateCMakeTargetBaseName(qualified_target):
"""This is the name we would like the target to have."""
_, gyp_target_name, gyp_target_toolset = (
gyp.common.ParseQualifiedTarget(qualified_target))
cmake_target_base_name = gyp_target_name
if gyp_target_toolset and gyp_target_toolset != 'target':
cmake_target_base_name += '_' + gyp_target_toolset
return StringToCMakeTargetName(cmake_target_base_name)
def CreateCMakeTargetFullName(qualified_target):
"""An unambiguous name for the target."""
gyp_file, gyp_target_name, gyp_target_toolset = (
gyp.common.ParseQualifiedTarget(qualified_target))
cmake_target_full_name = gyp_file + ':' + gyp_target_name
if gyp_target_toolset and gyp_target_toolset != 'target':
cmake_target_full_name += '_' + gyp_target_toolset
return StringToCMakeTargetName(cmake_target_full_name)
class CMakeNamer(object):
"""Converts Gyp target names into CMake target names.
CMake requires that target names be globally unique. One way to ensure
this is to fully qualify the names of the targets. Unfortunatly, this
ends up with all targets looking like "chrome_chrome_gyp_chrome" instead
of just "chrome". If this generator were only interested in building, it
would be possible to fully qualify all target names, then create
unqualified target names which depend on all qualified targets which
should have had that name. This is more or less what the 'make' generator
does with aliases. However, one goal of this generator is to create CMake
files for use with IDEs, and fully qualified names are not as user
friendly.
Since target name collision is rare, we do the above only when required.
Toolset variants are always qualified from the base, as this is required for
building. However, it also makes sense for an IDE, as it is possible for
defines to be different.
"""
def __init__(self, target_list):
self.cmake_target_base_names_conficting = set()
cmake_target_base_names_seen = set()
for qualified_target in target_list:
cmake_target_base_name = CreateCMakeTargetBaseName(qualified_target)
if cmake_target_base_name not in cmake_target_base_names_seen:
cmake_target_base_names_seen.add(cmake_target_base_name)
else:
self.cmake_target_base_names_conficting.add(cmake_target_base_name)
def CreateCMakeTargetName(self, qualified_target):
base_name = CreateCMakeTargetBaseName(qualified_target)
if base_name in self.cmake_target_base_names_conficting:
return CreateCMakeTargetFullName(qualified_target)
return base_name
def WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use,
options, generator_flags, all_qualified_targets, output):
# The make generator does this always.
# TODO: It would be nice to be able to tell CMake all dependencies.
circular_libs = generator_flags.get('circular', True)
if not generator_flags.get('standalone', False):
output.write('\n#')
output.write(qualified_target)
output.write('\n')
gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
rel_gyp_file = gyp.common.RelativePath(gyp_file, options.toplevel_dir)
rel_gyp_dir = os.path.dirname(rel_gyp_file)
# Relative path from build dir to top dir.
build_to_top = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
# Relative path from build dir to gyp dir.
build_to_gyp = os.path.join(build_to_top, rel_gyp_dir)
path_from_cmakelists_to_gyp = build_to_gyp
spec = target_dicts.get(qualified_target, {})
config = spec.get('configurations', {}).get(config_to_use, {})
target_name = spec.get('target_name', '<missing target name>')
target_type = spec.get('type', '<missing target type>')
target_toolset = spec.get('toolset')
cmake_target_type = cmake_target_type_from_gyp_target_type.get(target_type)
if cmake_target_type is None:
print ('Target %s has unknown target type %s, skipping.' %
( target_name, target_type ) )
return
SetVariable(output, 'TARGET', target_name)
SetVariable(output, 'TOOLSET', target_toolset)
cmake_target_name = namer.CreateCMakeTargetName(qualified_target)
extra_sources = []
extra_deps = []
# Actions must come first, since they can generate more OBJs for use below.
if 'actions' in spec:
WriteActions(cmake_target_name, spec['actions'], extra_sources, extra_deps,
path_from_cmakelists_to_gyp, output)
# Rules must be early like actions.
if 'rules' in spec:
WriteRules(cmake_target_name, spec['rules'], extra_sources, extra_deps,
path_from_cmakelists_to_gyp, output)
# Copies
if 'copies' in spec:
WriteCopies(cmake_target_name, spec['copies'], extra_deps,
path_from_cmakelists_to_gyp, output)
# Target and sources
srcs = spec.get('sources', [])
# Gyp separates the sheep from the goats based on file extensions.
# A full separation is done here because of flag handing (see below).
s_sources = []
c_sources = []
cxx_sources = []
linkable_sources = []
other_sources = []
for src in srcs:
_, ext = os.path.splitext(src)
src_type = COMPILABLE_EXTENSIONS.get(ext, None)
src_norm_path = NormjoinPath(path_from_cmakelists_to_gyp, src);
if src_type == 's':
s_sources.append(src_norm_path)
elif src_type == 'cc':
c_sources.append(src_norm_path)
elif src_type == 'cxx':
cxx_sources.append(src_norm_path)
elif Linkable(ext):
linkable_sources.append(src_norm_path)
else:
other_sources.append(src_norm_path)
for extra_source in extra_sources:
src, real_source = extra_source
_, ext = os.path.splitext(real_source)
src_type = COMPILABLE_EXTENSIONS.get(ext, None)
if src_type == 's':
s_sources.append(src)
elif src_type == 'cc':
c_sources.append(src)
elif src_type == 'cxx':
cxx_sources.append(src)
elif Linkable(ext):
linkable_sources.append(src)
else:
other_sources.append(src)
s_sources_name = None
if s_sources:
s_sources_name = cmake_target_name + '__asm_srcs'
SetVariableList(output, s_sources_name, s_sources)
c_sources_name = None
if c_sources:
c_sources_name = cmake_target_name + '__c_srcs'
SetVariableList(output, c_sources_name, c_sources)
cxx_sources_name = None
if cxx_sources:
cxx_sources_name = cmake_target_name + '__cxx_srcs'
SetVariableList(output, cxx_sources_name, cxx_sources)
linkable_sources_name = None
if linkable_sources:
linkable_sources_name = cmake_target_name + '__linkable_srcs'
SetVariableList(output, linkable_sources_name, linkable_sources)
other_sources_name = None
if other_sources:
other_sources_name = cmake_target_name + '__other_srcs'
SetVariableList(output, other_sources_name, other_sources)
# CMake gets upset when executable targets provide no sources.
# http://www.cmake.org/pipermail/cmake/2010-July/038461.html
dummy_sources_name = None
has_sources = (s_sources_name or
c_sources_name or
cxx_sources_name or
linkable_sources_name or
other_sources_name)
if target_type == 'executable' and not has_sources:
dummy_sources_name = cmake_target_name + '__dummy_srcs'
SetVariable(output, dummy_sources_name,
"${obj}.${TOOLSET}/${TARGET}/genc/dummy.c")
output.write('if(NOT EXISTS "')
WriteVariable(output, dummy_sources_name)
output.write('")\n')
output.write(' file(WRITE "')
WriteVariable(output, dummy_sources_name)
output.write('" "")\n')
output.write("endif()\n")
# CMake is opposed to setting linker directories and considers the practice
# of setting linker directories dangerous. Instead, it favors the use of
# find_library and passing absolute paths to target_link_libraries.
# However, CMake does provide the command link_directories, which adds
# link directories to targets defined after it is called.
# As a result, link_directories must come before the target definition.
# CMake unfortunately has no means of removing entries from LINK_DIRECTORIES.
library_dirs = config.get('library_dirs')
if library_dirs is not None:
output.write('link_directories(')
for library_dir in library_dirs:
output.write(' ')
output.write(NormjoinPath(path_from_cmakelists_to_gyp, library_dir))
output.write('\n')
output.write(')\n')
output.write(cmake_target_type.command)
output.write('(')
output.write(cmake_target_name)
if cmake_target_type.modifier is not None:
output.write(' ')
output.write(cmake_target_type.modifier)
if s_sources_name:
WriteVariable(output, s_sources_name, ' ')
if c_sources_name:
WriteVariable(output, c_sources_name, ' ')
if cxx_sources_name:
WriteVariable(output, cxx_sources_name, ' ')
if linkable_sources_name:
WriteVariable(output, linkable_sources_name, ' ')
if other_sources_name:
WriteVariable(output, other_sources_name, ' ')
if dummy_sources_name:
WriteVariable(output, dummy_sources_name, ' ')
output.write(')\n')
# Let CMake know if the 'all' target should depend on this target.
exclude_from_all = ('TRUE' if qualified_target not in all_qualified_targets
else 'FALSE')
SetTargetProperty(output, cmake_target_name,
'EXCLUDE_FROM_ALL', exclude_from_all)
for extra_target_name in extra_deps:
SetTargetProperty(output, extra_target_name,
'EXCLUDE_FROM_ALL', exclude_from_all)
# Output name and location.
if target_type != 'none':
# Link as 'C' if there are no other files
if not c_sources and not cxx_sources:
SetTargetProperty(output, cmake_target_name, 'LINKER_LANGUAGE', ['C'])
# Mark uncompiled sources as uncompiled.
if other_sources_name:
output.write('set_source_files_properties(')
WriteVariable(output, other_sources_name, '')
output.write(' PROPERTIES HEADER_FILE_ONLY "TRUE")\n')
# Mark object sources as linkable.
if linkable_sources_name:
output.write('set_source_files_properties(')
WriteVariable(output, other_sources_name, '')
output.write(' PROPERTIES EXTERNAL_OBJECT "TRUE")\n')
# Output directory
target_output_directory = spec.get('product_dir')
if target_output_directory is None:
if target_type in ('executable', 'loadable_module'):
target_output_directory = generator_default_variables['PRODUCT_DIR']
elif target_type == 'shared_library':
target_output_directory = '${builddir}/lib.${TOOLSET}'
elif spec.get('standalone_static_library', False):
target_output_directory = generator_default_variables['PRODUCT_DIR']
else:
base_path = gyp.common.RelativePath(os.path.dirname(gyp_file),
options.toplevel_dir)
target_output_directory = '${obj}.${TOOLSET}'
target_output_directory = (
os.path.join(target_output_directory, base_path))
cmake_target_output_directory = NormjoinPathForceCMakeSource(
path_from_cmakelists_to_gyp,
target_output_directory)
SetTargetProperty(output,
cmake_target_name,
cmake_target_type.property_modifier + '_OUTPUT_DIRECTORY',
cmake_target_output_directory)
# Output name
default_product_prefix = ''
default_product_name = target_name
default_product_ext = ''
if target_type == 'static_library':
static_library_prefix = generator_default_variables['STATIC_LIB_PREFIX']
default_product_name = RemovePrefix(default_product_name,
static_library_prefix)
default_product_prefix = static_library_prefix
default_product_ext = generator_default_variables['STATIC_LIB_SUFFIX']
elif target_type in ('loadable_module', 'shared_library'):
shared_library_prefix = generator_default_variables['SHARED_LIB_PREFIX']
default_product_name = RemovePrefix(default_product_name,
shared_library_prefix)
default_product_prefix = shared_library_prefix
default_product_ext = generator_default_variables['SHARED_LIB_SUFFIX']
elif target_type != 'executable':
print ('ERROR: What output file should be generated?',
'type', target_type, 'target', target_name)
product_prefix = spec.get('product_prefix', default_product_prefix)
product_name = spec.get('product_name', default_product_name)
product_ext = spec.get('product_extension')
if product_ext:
product_ext = '.' + product_ext
else:
product_ext = default_product_ext
SetTargetProperty(output, cmake_target_name, 'PREFIX', product_prefix)
SetTargetProperty(output, cmake_target_name,
cmake_target_type.property_modifier + '_OUTPUT_NAME',
product_name)
SetTargetProperty(output, cmake_target_name, 'SUFFIX', product_ext)
# Make the output of this target referenceable as a source.
cmake_target_output_basename = product_prefix + product_name + product_ext
cmake_target_output = os.path.join(cmake_target_output_directory,
cmake_target_output_basename)
SetFileProperty(output, cmake_target_output, 'GENERATED', ['TRUE'], '')
# Includes
includes = config.get('include_dirs')
if includes:
# This (target include directories) is what requires CMake 2.8.8
includes_name = cmake_target_name + '__include_dirs'
SetVariableList(output, includes_name,
[NormjoinPathForceCMakeSource(path_from_cmakelists_to_gyp, include)
for include in includes])
output.write('set_property(TARGET ')
output.write(cmake_target_name)
output.write(' APPEND PROPERTY INCLUDE_DIRECTORIES ')
WriteVariable(output, includes_name, '')
output.write(')\n')
# Defines
defines = config.get('defines')
if defines is not None:
SetTargetProperty(output,
cmake_target_name,
'COMPILE_DEFINITIONS',
defines,
';')
# Compile Flags - http://www.cmake.org/Bug/view.php?id=6493
# CMake currently does not have target C and CXX flags.
# So, instead of doing...
# cflags_c = config.get('cflags_c')
# if cflags_c is not None:
# SetTargetProperty(output, cmake_target_name,
# 'C_COMPILE_FLAGS', cflags_c, ' ')
# cflags_cc = config.get('cflags_cc')
# if cflags_cc is not None:
# SetTargetProperty(output, cmake_target_name,
# 'CXX_COMPILE_FLAGS', cflags_cc, ' ')
# Instead we must...
cflags = config.get('cflags', [])
cflags_c = config.get('cflags_c', [])
cflags_cxx = config.get('cflags_cc', [])
if (not cflags_c or not c_sources) and (not cflags_cxx or not cxx_sources):
SetTargetProperty(output, cmake_target_name, 'COMPILE_FLAGS', cflags, ' ')
elif c_sources and not (s_sources or cxx_sources):
flags = []
flags.extend(cflags)
flags.extend(cflags_c)
SetTargetProperty(output, cmake_target_name, 'COMPILE_FLAGS', flags, ' ')
elif cxx_sources and not (s_sources or c_sources):
flags = []
flags.extend(cflags)
flags.extend(cflags_cxx)
SetTargetProperty(output, cmake_target_name, 'COMPILE_FLAGS', flags, ' ')
else:
# TODO: This is broken, one cannot generally set properties on files,
# as other targets may require different properties on the same files.
if s_sources and cflags:
SetFilesProperty(output, s_sources_name, 'COMPILE_FLAGS', cflags, ' ')
if c_sources and (cflags or cflags_c):
flags = []
flags.extend(cflags)
flags.extend(cflags_c)
SetFilesProperty(output, c_sources_name, 'COMPILE_FLAGS', flags, ' ')
if cxx_sources and (cflags or cflags_cxx):
flags = []
flags.extend(cflags)
flags.extend(cflags_cxx)
SetFilesProperty(output, cxx_sources_name, 'COMPILE_FLAGS', flags, ' ')
# Linker flags
ldflags = config.get('ldflags')
if ldflags is not None:
SetTargetProperty(output, cmake_target_name, 'LINK_FLAGS', ldflags, ' ')
# Note on Dependencies and Libraries:
# CMake wants to handle link order, resolving the link line up front.
# Gyp does not retain or enforce specifying enough information to do so.
# So do as other gyp generators and use --start-group and --end-group.
# Give CMake as little information as possible so that it doesn't mess it up.
# Dependencies
rawDeps = spec.get('dependencies', [])
static_deps = []
shared_deps = []
other_deps = []
for rawDep in rawDeps:
dep_cmake_name = namer.CreateCMakeTargetName(rawDep)
dep_spec = target_dicts.get(rawDep, {})
dep_target_type = dep_spec.get('type', None)
if dep_target_type == 'static_library':
static_deps.append(dep_cmake_name)
elif dep_target_type == 'shared_library':
shared_deps.append(dep_cmake_name)
else:
other_deps.append(dep_cmake_name)
# ensure all external dependencies are complete before internal dependencies
# extra_deps currently only depend on their own deps, so otherwise run early
if static_deps or shared_deps or other_deps:
for extra_dep in extra_deps:
output.write('add_dependencies(')
output.write(extra_dep)
output.write('\n')
for deps in (static_deps, shared_deps, other_deps):
for dep in gyp.common.uniquer(deps):
output.write(' ')
output.write(dep)
output.write('\n')
output.write(')\n')
linkable = target_type in ('executable', 'loadable_module', 'shared_library')
other_deps.extend(extra_deps)
if other_deps or (not linkable and (static_deps or shared_deps)):
output.write('add_dependencies(')
output.write(cmake_target_name)
output.write('\n')
for dep in gyp.common.uniquer(other_deps):
output.write(' ')
output.write(dep)
output.write('\n')
if not linkable:
for deps in (static_deps, shared_deps):
for lib_dep in gyp.common.uniquer(deps):
output.write(' ')
output.write(lib_dep)
output.write('\n')
output.write(')\n')
# Libraries
if linkable:
external_libs = [lib for lib in spec.get('libraries', []) if len(lib) > 0]
if external_libs or static_deps or shared_deps:
output.write('target_link_libraries(')
output.write(cmake_target_name)
output.write('\n')
if static_deps:
write_group = circular_libs and len(static_deps) > 1
if write_group:
output.write('-Wl,--start-group\n')
for dep in gyp.common.uniquer(static_deps):
output.write(' ')
output.write(dep)
output.write('\n')
if write_group:
output.write('-Wl,--end-group\n')
if shared_deps:
for dep in gyp.common.uniquer(shared_deps):
output.write(' ')
output.write(dep)
output.write('\n')
if external_libs:
for lib in gyp.common.uniquer(external_libs):
output.write(' ')
output.write(lib)
output.write('\n')
output.write(')\n')
UnsetVariable(output, 'TOOLSET')
UnsetVariable(output, 'TARGET')
def GenerateOutputForConfig(target_list, target_dicts, data,
params, config_to_use):
options = params['options']
generator_flags = params['generator_flags']
# generator_dir: relative path from pwd to where make puts build files.
# Makes migrating from make to cmake easier, cmake doesn't put anything here.
# Each Gyp configuration creates a different CMakeLists.txt file
# to avoid incompatibilities between Gyp and CMake configurations.
generator_dir = os.path.relpath(options.generator_output or '.')
# output_dir: relative path from generator_dir to the build directory.
output_dir = generator_flags.get('output_dir', 'out')
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.normpath(os.path.join(generator_dir,
output_dir,
config_to_use))
toplevel_build = os.path.join(options.toplevel_dir, build_dir)
output_file = os.path.join(toplevel_build, 'CMakeLists.txt')
gyp.common.EnsureDirExists(output_file)
output = open(output_file, 'w')
output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n')
output.write('cmake_policy(VERSION 2.8.8)\n')
gyp_file, project_target, _ = gyp.common.ParseQualifiedTarget(target_list[-1])
output.write('project(')
output.write(project_target)
output.write(')\n')
SetVariable(output, 'configuration', config_to_use)
ar = None
cc = None
cxx = None
make_global_settings = data[gyp_file].get('make_global_settings', [])
build_to_top = gyp.common.InvertRelativePath(build_dir,
options.toplevel_dir)
for key, value in make_global_settings:
if key == 'AR':
ar = os.path.join(build_to_top, value)
if key == 'CC':
cc = os.path.join(build_to_top, value)
if key == 'CXX':
cxx = os.path.join(build_to_top, value)
ar = gyp.common.GetEnvironFallback(['AR_target', 'AR'], ar)
cc = gyp.common.GetEnvironFallback(['CC_target', 'CC'], cc)
cxx = gyp.common.GetEnvironFallback(['CXX_target', 'CXX'], cxx)
if ar:
SetVariable(output, 'CMAKE_AR', ar)
if cc:
SetVariable(output, 'CMAKE_C_COMPILER', cc)
if cxx:
SetVariable(output, 'CMAKE_CXX_COMPILER', cxx)
# The following appears to be as-yet undocumented.
# http://public.kitware.com/Bug/view.php?id=8392
output.write('enable_language(ASM)\n')
# ASM-ATT does not support .S files.
# output.write('enable_language(ASM-ATT)\n')
if cc:
SetVariable(output, 'CMAKE_ASM_COMPILER', cc)
SetVariable(output, 'builddir', '${CMAKE_CURRENT_BINARY_DIR}')
SetVariable(output, 'obj', '${builddir}/obj')
output.write('\n')
# TODO: Undocumented/unsupported (the CMake Java generator depends on it).
# CMake by default names the object resulting from foo.c to be foo.c.o.
# Gyp traditionally names the object resulting from foo.c foo.o.
# This should be irrelevant, but some targets extract .o files from .a
# and depend on the name of the extracted .o files.
output.write('set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)\n')
output.write('set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)\n')
output.write('\n')
# Force ninja to use rsp files. Otherwise link and ar lines can get too long,
# resulting in 'Argument list too long' errors.
output.write('set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1)\n')
output.write('\n')
namer = CMakeNamer(target_list)
# The list of targets upon which the 'all' target should depend.
# CMake has it's own implicit 'all' target, one is not created explicitly.
all_qualified_targets = set()
for build_file in params['build_files']:
for qualified_target in gyp.common.AllTargets(target_list,
target_dicts,
os.path.normpath(build_file)):
all_qualified_targets.add(qualified_target)
for qualified_target in target_list:
WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use,
options, generator_flags, all_qualified_targets, output)
output.close()
def PerformBuild(data, configurations, params):
options = params['options']
generator_flags = params['generator_flags']
# generator_dir: relative path from pwd to where make puts build files.
# Makes migrating from make to cmake easier, cmake doesn't put anything here.
generator_dir = os.path.relpath(options.generator_output or '.')
# output_dir: relative path from generator_dir to the build directory.
output_dir = generator_flags.get('output_dir', 'out')
for config_name in configurations:
# build_dir: relative path from source root to our output files.
# e.g. "out/Debug"
build_dir = os.path.normpath(os.path.join(generator_dir,
output_dir,
config_name))
arguments = ['cmake', '-G', 'Ninja']
print 'Generating [%s]: %s' % (config_name, arguments)
subprocess.check_call(arguments, cwd=build_dir)
arguments = ['ninja', '-C', build_dir]
print 'Building [%s]: %s' % (config_name, arguments)
subprocess.check_call(arguments)
def CallGenerateOutputForConfig(arglist):
# Ignore the interrupt signal so that the parent process catches it and
# kills all multiprocessing children.
signal.signal(signal.SIGINT, signal.SIG_IGN)
target_list, target_dicts, data, params, config_name = arglist
GenerateOutputForConfig(target_list, target_dicts, data, params, config_name)
def GenerateOutput(target_list, target_dicts, data, params):
user_config = params.get('generator_flags', {}).get('config', None)
if user_config:
GenerateOutputForConfig(target_list, target_dicts, data,
params, user_config)
else:
config_names = target_dicts[target_list[0]]['configurations'].keys()
if params['parallel']:
try:
pool = multiprocessing.Pool(len(config_names))
arglists = []
for config_name in config_names:
arglists.append((target_list, target_dicts, data,
params, config_name))
pool.map(CallGenerateOutputForConfig, arglists)
except KeyboardInterrupt, e:
pool.terminate()
raise e
else:
for config_name in config_names:
GenerateOutputForConfig(target_list, target_dicts, data,
params, config_name)
|
mit
|
[
3,
1898,
334,
67,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
16472,
1072,
859,
199,
199,
2765,
859,
365,
1334,
16367,
436,
1077,
506,
8652,
22820,
14,
199,
199,
2765,
859,
16904,
19773,
334,
18,
14,
24,
14,
24,
8771,
1324,
465,
2399,
1072,
14,
7309,
21355,
15116,
14,
2424,
365,
199,
3966,
367,
1924,
2897,
14,
199,
199,
2765,
859,
1159,
3379,
12016,
1990,
370,
2291,
20401,
315,
473,
1093,
83,
2839,
1804,
872,
7549,
199,
6777,
675,
21355,
367,
2199,
10041,
14,
2779,
365,
2597,
3962,
370,
675,
21355,
370,
199,
4208,
11336,
367,
1163,
473,
1093,
83,
4066,
465,
325,
7548,
261,
286,
3583,
436,
1233,
447,
4166,
14,
3959,
17523,
199,
14117,
3957,
314,
21355,
15116,
14,
2424,
370,
282,
1233,
447,
4166,
7434,
80,
367,
314,
8823,
370,
1586,
12,
199,
7911,
1900,
1808,
21355,
14,
3709,
282,
754,
3959,
17523,
8823,
365,
625,
14600,
402,
6365,
199,
14334,
14,
710,
4046,
21355,
15116,
14,
2424,
883,
2597,
506,
1202,
370,
1900,
641,
10130,
14,
6006,
199,
374,
5544,
949,
2291,
367,
10015,
641,
10677,
1163,
2419,
10130,
14,
199,
199,
1918,
4046,
21355,
15116,
14,
2424,
1077,
7684,
6555,
1006,
11336,
14,
9738,
12,
199,
16990,
365,
282,
15015,
3382,
4902,
436,
19773,
543,
8794,
370,
25833,
14,
2900,
12454,
199,
1530,
6326,
370,
1736,
6818,
642,
12,
1325,
21355,
15026,
542,
397,
446,
16239,
28925,
928,
13,
923,
465,
282,
199,
4342,
436,
22743,
28908,
652,
14,
3709,
282,
754,
314,
1072,
402,
642,
4306,
199,
5626,
440,
506,
295,
1857,
641,
367,
10015,
14,
199,
199,
11423,
1808,
543,
1022,
32176,
12,
675,
1015,
841,
14,
20,
26240,
26902,
5459,
402,
1022,
32176,
911,
199,
1397,
506,
7688,
370,
2342,
314,
1406,
570,
6602,
11736,
315,
314,
4046,
199,
27984,
15116,
14,
2424,
570,
14,
199,
624,
199,
199,
646,
12866,
199,
646,
747,
199,
646,
4673,
199,
646,
1059,
199,
646,
3873,
199,
646,
4902,
14,
2330,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
1152,
297,
523,
283,
13772,
63,
5617,
63,
3022,
356,
20044,
21728,
5995,
773,
14,
10545,
16892,
7293,
523,
283,
5617,
63,
3022,
356,
20044,
1113,
5565,
10545,
16892,
7293,
523,
283,
23227,
63,
3022,
356,
20044,
1113,
5565,
10545,
16892,
5995,
10545,
9268,
5995,
2268,
73,
297,
523,
283,
13772,
63,
23227,
63,
3022,
356,
20044,
1113,
5995,
2268,
297,
523,
283,
14853,
63,
3022,
356,
20044,
21728,
7293,
523,
283,
13578,
63,
7321,
63,
3243,
356,
20044,
13578,
63,
7321,
63,
3243,
7293,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
20044,
13578,
63,
7321,
63,
3022,
2339,
7293,
523,
283,
13578,
63,
7321,
63,
2339,
356,
20044,
13578,
63,
7321,
63,
2339,
7293,
523,
283,
13578,
63,
7321,
63,
5441,
356,
20044,
13578,
63,
7321,
63,
5441,
7293,
523,
283,
13578,
63,
7321,
63,
2472,
356,
20044,
13578,
63,
7321,
63,
2472,
7293,
523,
283,
22212,
63,
2339,
356,
20044,
4758,
7293,
199,
93,
199,
199,
14742,
63,
3243,
63,
21367,
275,
661,
10545,
30250,
63,
14211,
63,
4924,
63,
3022,
7293,
20044,
21728,
7293,
20044,
1113,
12216,
199,
199,
4679,
63,
9823,
63,
6048,
63,
30116,
275,
715,
199,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
715,
199,
199,
6790,
1193,
2617,
63,
18451,
275,
469,
523,
1987,
67,
356,
283,
2055,
297,
523,
1987,
2055,
356,
283,
9634,
297,
523,
1987,
5910,
356,
283,
9634,
297,
523,
1987,
9634,
356,
283,
9634,
297,
523,
1987,
83,
356,
283,
83,
297,
327,
7429,
523,
1987,
51,
356,
283,
83,
297,
327,
7429,
199,
93,
421,
199,
318,
5852,
4793,
8,
65,
12,
2403,
304,
523,
408,
3407,
283,
65,
7,
1928,
283,
1861,
7,
340,
652,
9174,
543,
283,
1861,
23690,
523,
372,
282,
59,
552,
8,
1861,
15405,
340,
282,
14,
2460,
8,
1861,
9,
587,
282,
421,
199,
318,
12707,
11458,
8,
885,
63,
3669,
12,
1862,
304,
523,
408,
14860,
4722,
2860,
367,
675,
315,
314,
1900,
334,
3527,
701,
4902,
10477,
523,
849,
63,
3669,
14,
5486,
360,
3100,
297,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
430,
421,
199,
318,
3599,
382,
461,
8,
1501,
304,
523,
408,
1767,
2549,
340,
314,
570,
365,
1013,
382,
461,
334,
5626,
506,
315,
28652,
11378,
10477,
523,
372,
1263,
8,
1501,
14,
4130,
8,
69,
9,
367,
325,
315,
16503,
1193,
2617,
63,
18451,
9,
421,
199,
318,
10967,
461,
8,
1501,
304,
523,
408,
1767,
2549,
340,
314,
570,
365,
30258,
334,
5626,
506,
641,
314,
2142,
1004,
10477,
523,
372,
1788,
14,
4130,
5175,
79,
358,
421,
199,
318,
20800,
904,
2042,
13606,
27984,
2980,
8,
1095,
63,
515,
12,
4668,
63,
515,
304,
523,
408,
1322,
393,
2310,
4668,
63,
515,
6169,
1300,
63,
515,
436,
2529,
314,
754,
14,
819,
982,
4668,
63,
515,
365,
376,
3679,
931,
652,
365,
2138,
14874,
14,
523,
6630,
652,
365,
12152,
6169,
1300,
63,
515,
436,
9657,
14,
523,
982,
314,
754,
365,
282,
3847,
931,
12,
652,
365,
19565,
370,
506,
3847,
370,
314,
523,
21355,
15116,
14,
2424,
14,
523,
408,
523,
340,
747,
14,
515,
14,
17896,
8,
3369,
63,
515,
304,
272,
372,
4668,
63,
515,
523,
340,
1263,
779,
3369,
63,
515,
14,
2460,
8,
1391,
9,
367,
2729,
315,
18530,
63,
3243,
63,
21367,
4682,
272,
372,
4668,
63,
515,
523,
327,
3254,
26,
886,
781,
1929,
370,
1104,
1300,
63,
515,
367,
3679,
2860,
465,
5521,
31,
523,
372,
747,
14,
515,
14,
904,
360,
10545,
30250,
63,
14211,
63,
4924,
63,
3022,
7293,
1993,
747,
14,
515,
14,
9267
] |
[
1898,
334,
67,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
16472,
1072,
859,
199,
199,
2765,
859,
365,
1334,
16367,
436,
1077,
506,
8652,
22820,
14,
199,
199,
2765,
859,
16904,
19773,
334,
18,
14,
24,
14,
24,
8771,
1324,
465,
2399,
1072,
14,
7309,
21355,
15116,
14,
2424,
365,
199,
3966,
367,
1924,
2897,
14,
199,
199,
2765,
859,
1159,
3379,
12016,
1990,
370,
2291,
20401,
315,
473,
1093,
83,
2839,
1804,
872,
7549,
199,
6777,
675,
21355,
367,
2199,
10041,
14,
2779,
365,
2597,
3962,
370,
675,
21355,
370,
199,
4208,
11336,
367,
1163,
473,
1093,
83,
4066,
465,
325,
7548,
261,
286,
3583,
436,
1233,
447,
4166,
14,
3959,
17523,
199,
14117,
3957,
314,
21355,
15116,
14,
2424,
370,
282,
1233,
447,
4166,
7434,
80,
367,
314,
8823,
370,
1586,
12,
199,
7911,
1900,
1808,
21355,
14,
3709,
282,
754,
3959,
17523,
8823,
365,
625,
14600,
402,
6365,
199,
14334,
14,
710,
4046,
21355,
15116,
14,
2424,
883,
2597,
506,
1202,
370,
1900,
641,
10130,
14,
6006,
199,
374,
5544,
949,
2291,
367,
10015,
641,
10677,
1163,
2419,
10130,
14,
199,
199,
1918,
4046,
21355,
15116,
14,
2424,
1077,
7684,
6555,
1006,
11336,
14,
9738,
12,
199,
16990,
365,
282,
15015,
3382,
4902,
436,
19773,
543,
8794,
370,
25833,
14,
2900,
12454,
199,
1530,
6326,
370,
1736,
6818,
642,
12,
1325,
21355,
15026,
542,
397,
446,
16239,
28925,
928,
13,
923,
465,
282,
199,
4342,
436,
22743,
28908,
652,
14,
3709,
282,
754,
314,
1072,
402,
642,
4306,
199,
5626,
440,
506,
295,
1857,
641,
367,
10015,
14,
199,
199,
11423,
1808,
543,
1022,
32176,
12,
675,
1015,
841,
14,
20,
26240,
26902,
5459,
402,
1022,
32176,
911,
199,
1397,
506,
7688,
370,
2342,
314,
1406,
570,
6602,
11736,
315,
314,
4046,
199,
27984,
15116,
14,
2424,
570,
14,
199,
624,
199,
199,
646,
12866,
199,
646,
747,
199,
646,
4673,
199,
646,
1059,
199,
646,
3873,
199,
646,
4902,
14,
2330,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
523,
283,
21623,
63,
6351,
356,
3260,
523,
283,
21623,
63,
12273,
356,
3260,
523,
283,
10449,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
65,
297,
523,
283,
13772,
63,
5617,
63,
6351,
356,
283,
773,
297,
523,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
1152,
297,
523,
283,
13772,
63,
5617,
63,
3022,
356,
20044,
21728,
5995,
773,
14,
10545,
16892,
7293,
523,
283,
5617,
63,
3022,
356,
20044,
1113,
5565,
10545,
16892,
7293,
523,
283,
23227,
63,
3022,
356,
20044,
1113,
5565,
10545,
16892,
5995,
10545,
9268,
5995,
2268,
73,
297,
523,
283,
13772,
63,
23227,
63,
3022,
356,
20044,
1113,
5995,
2268,
297,
523,
283,
14853,
63,
3022,
356,
20044,
21728,
7293,
523,
283,
13578,
63,
7321,
63,
3243,
356,
20044,
13578,
63,
7321,
63,
3243,
7293,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
20044,
13578,
63,
7321,
63,
3022,
2339,
7293,
523,
283,
13578,
63,
7321,
63,
2339,
356,
20044,
13578,
63,
7321,
63,
2339,
7293,
523,
283,
13578,
63,
7321,
63,
5441,
356,
20044,
13578,
63,
7321,
63,
5441,
7293,
523,
283,
13578,
63,
7321,
63,
2472,
356,
20044,
13578,
63,
7321,
63,
2472,
7293,
523,
283,
22212,
63,
2339,
356,
20044,
4758,
7293,
199,
93,
199,
199,
14742,
63,
3243,
63,
21367,
275,
661,
10545,
30250,
63,
14211,
63,
4924,
63,
3022,
7293,
20044,
21728,
7293,
20044,
1113,
12216,
199,
199,
4679,
63,
9823,
63,
6048,
63,
30116,
275,
715,
199,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
275,
715,
199,
199,
6790,
1193,
2617,
63,
18451,
275,
469,
523,
1987,
67,
356,
283,
2055,
297,
523,
1987,
2055,
356,
283,
9634,
297,
523,
1987,
5910,
356,
283,
9634,
297,
523,
1987,
9634,
356,
283,
9634,
297,
523,
1987,
83,
356,
283,
83,
297,
327,
7429,
523,
1987,
51,
356,
283,
83,
297,
327,
7429,
199,
93,
421,
199,
318,
5852,
4793,
8,
65,
12,
2403,
304,
523,
408,
3407,
283,
65,
7,
1928,
283,
1861,
7,
340,
652,
9174,
543,
283,
1861,
23690,
523,
372,
282,
59,
552,
8,
1861,
15405,
340,
282,
14,
2460,
8,
1861,
9,
587,
282,
421,
199,
318,
12707,
11458,
8,
885,
63,
3669,
12,
1862,
304,
523,
408,
14860,
4722,
2860,
367,
675,
315,
314,
1900,
334,
3527,
701,
4902,
10477,
523,
849,
63,
3669,
14,
5486,
360,
3100,
297,
4902,
14,
2330,
14,
1002,
16739,
8,
1162,
430,
421,
199,
318,
3599,
382,
461,
8,
1501,
304,
523,
408,
1767,
2549,
340,
314,
570,
365,
1013,
382,
461,
334,
5626,
506,
315,
28652,
11378,
10477,
523,
372,
1263,
8,
1501,
14,
4130,
8,
69,
9,
367,
325,
315,
16503,
1193,
2617,
63,
18451,
9,
421,
199,
318,
10967,
461,
8,
1501,
304,
523,
408,
1767,
2549,
340,
314,
570,
365,
30258,
334,
5626,
506,
641,
314,
2142,
1004,
10477,
523,
372,
1788,
14,
4130,
5175,
79,
358,
421,
199,
318,
20800,
904,
2042,
13606,
27984,
2980,
8,
1095,
63,
515,
12,
4668,
63,
515,
304,
523,
408,
1322,
393,
2310,
4668,
63,
515,
6169,
1300,
63,
515,
436,
2529,
314,
754,
14,
819,
982,
4668,
63,
515,
365,
376,
3679,
931,
652,
365,
2138,
14874,
14,
523,
6630,
652,
365,
12152,
6169,
1300,
63,
515,
436,
9657,
14,
523,
982,
314,
754,
365,
282,
3847,
931,
12,
652,
365,
19565,
370,
506,
3847,
370,
314,
523,
21355,
15116,
14,
2424,
14,
523,
408,
523,
340,
747,
14,
515,
14,
17896,
8,
3369,
63,
515,
304,
272,
372,
4668,
63,
515,
523,
340,
1263,
779,
3369,
63,
515,
14,
2460,
8,
1391,
9,
367,
2729,
315,
18530,
63,
3243,
63,
21367,
4682,
272,
372,
4668,
63,
515,
523,
327,
3254,
26,
886,
781,
1929,
370,
1104,
1300,
63,
515,
367,
3679,
2860,
465,
5521,
31,
523,
372,
747,
14,
515,
14,
904,
360,
10545,
30250,
63,
14211,
63,
4924,
63,
3022,
7293,
1993,
747,
14,
515,
14,
9267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lukeiwanski/tensorflow
|
tensorflow/contrib/distributions/python/ops/bijectors/square.py
|
35
|
2857
|
# 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.
# ==============================================================================
"""Square bijector."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops.distributions import bijector
from tensorflow.python.util import deprecation
__all__ = [
"Square",
]
class Square(bijector.Bijector):
"""Compute `g(X) = X^2`; X is a positive real number.
g is a bijection between the non-negative real numbers (R_+) and the
non-negative real numbers.
#### Examples
```python
bijector.Square().forward(x=[[1., 0], [2, 1]])
# Result: [[1., 0], [4, 1]], i.e., x^2
bijector.Square().inverse(y=[[1., 4], [9, 1]])
# Result: [[1., 2], [3, 1]], i.e., sqrt(y).
```
"""
@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, validate_args=False, name="square"):
"""Instantiates the `Square` bijector.
Args:
validate_args: Python `bool` indicating whether arguments should be
checked for correctness.
name: Python `str` name given to ops managed by this object.
"""
self._name = name
super(Square, self).__init__(
forward_min_event_ndims=0,
validate_args=validate_args,
name=name)
def _forward(self, x):
x = self._maybe_assert_valid(x)
return math_ops.square(x)
def _inverse(self, y):
y = self._maybe_assert_valid(y)
return math_ops.sqrt(y)
def _forward_log_det_jacobian(self, x):
x = self._maybe_assert_valid(x)
return np.log(2.) + math_ops.log(x)
def _maybe_assert_valid(self, t):
if not self.validate_args:
return t
is_valid = check_ops.assert_non_negative(
t, message="All elements must be non-negative.")
return control_flow_ops.with_dependencies([is_valid], t)
|
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,
23373,
12111,
19625,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
12111,
19625,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
421,
199,
363,
452,
363,
275,
359,
272,
298,
23373,
401,
199,
61,
421,
199,
533,
428,
5937,
8,
4492,
19625,
14,
17975,
19625,
304,
523,
408,
8564,
658,
71,
8,
56,
9,
275,
1323,
62,
18,
64,
27,
1323,
365,
282,
7317,
3363,
1329,
14,
819,
486,
365,
282,
12111,
8923,
3382,
314,
2222,
13,
7371,
3363,
5579,
334,
50,
63,
8771,
436,
314,
523,
2222,
13,
7371,
3363,
5579,
14,
819,
14055,
6058,
819,
10841,
1548,
523,
12111,
19625,
14,
23373,
1252,
6688,
8,
88,
16025,
17,
2020,
378,
467,
359,
18,
12,
413,
3934,
523,
327,
10695,
26,
3474,
17,
2020,
378,
467,
359,
20,
12,
413,
2365,
284,
14,
69,
2020,
671,
62,
18,
819,
12111,
19625,
14,
23373,
1252,
11668,
8,
89,
16025,
17,
2020,
841,
467,
359,
25,
12,
413,
3934,
523,
327,
10695,
26,
3474,
17,
2020,
499,
467,
359,
19,
12,
413,
2365,
284,
14,
69,
2020,
7452,
8,
89,
680,
523,
10841,
819,
408,
819,
768,
15383,
14,
6667,
8,
489,
298,
12682,
13,
709,
13,
614,
401,
489,
298,
1918,
9134,
577,
5414,
852,
3555,
965,
12155,
370,
298,
489,
298,
26998,
22770,
3616,
298,
489,
7340,
2859,
921,
5031,
14,
957,
15,
16008,
15,
17210,
680,
2047,
298,
489,
298,
5626,
1678,
1006,
6941,
370,
675,
658,
3249,
80,
14,
5613,
64,
298,
489,
298,
23145,
402,
658,
3249,
14,
2828,
14,
5613,
2313,
401,
489,
7987,
63,
5089,
29,
549,
9,
523,
347,
636,
826,
721,
277,
12,
4107,
63,
589,
29,
797,
12,
536,
628,
9646,
2349,
272,
408,
10083,
4466,
2335,
314,
658,
23373,
64,
12111,
19625,
14,
339,
3033,
26,
489,
4107,
63,
589,
26,
2018,
658,
2245,
64,
9297,
3775,
2368,
1077,
506,
267,
7923,
367,
29102,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
1627,
370,
4156,
12883,
701,
642,
909,
14,
272,
408,
272,
291,
423,
354,
275,
536,
272,
1613,
8,
23373,
12,
291,
2843,
826,
721,
267,
7568,
63,
827,
63,
1430,
63,
13575,
29,
16,
12,
267,
4107,
63,
589,
29,
3502,
63,
589,
12,
267,
536,
29,
354,
9,
819,
347,
485,
6688,
8,
277,
12,
671,
304,
272,
671,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
88,
9,
272,
372,
3473,
63,
1483,
14,
9646,
8,
88,
9,
819,
347,
485,
11668,
8,
277,
12,
612,
304,
272,
612,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
89,
9,
272,
372,
3473,
63,
1483,
14,
5079,
8,
89,
9,
819,
347,
485,
6688,
63,
793,
63,
9886,
63,
27342,
8,
277,
12,
671,
304,
272,
671,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
88,
9,
272,
372,
980,
14,
793,
8,
18,
4959,
435,
3473,
63,
1483,
14,
793,
8,
88,
9,
819,
347,
485,
11853,
63,
479,
63,
1078,
8,
277,
12,
307,
304,
272,
340,
440,
291,
14,
3502,
63,
589,
26,
489,
372,
307,
272,
365,
63,
1078,
275,
1104,
63,
1483,
14,
479,
63,
2865,
63,
7371,
8,
267,
307,
12,
1245,
628,
2422,
4008,
1471,
506,
2222,
13,
7371,
2685,
272,
372,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
779,
374,
63,
1078,
467,
307,
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
] |
[
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,
23373,
12111,
19625,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
12111,
19625,
199,
504,
3228,
14,
1548,
14,
1974,
492,
17831,
421,
199,
363,
452,
363,
275,
359,
272,
298,
23373,
401,
199,
61,
421,
199,
533,
428,
5937,
8,
4492,
19625,
14,
17975,
19625,
304,
523,
408,
8564,
658,
71,
8,
56,
9,
275,
1323,
62,
18,
64,
27,
1323,
365,
282,
7317,
3363,
1329,
14,
819,
486,
365,
282,
12111,
8923,
3382,
314,
2222,
13,
7371,
3363,
5579,
334,
50,
63,
8771,
436,
314,
523,
2222,
13,
7371,
3363,
5579,
14,
819,
14055,
6058,
819,
10841,
1548,
523,
12111,
19625,
14,
23373,
1252,
6688,
8,
88,
16025,
17,
2020,
378,
467,
359,
18,
12,
413,
3934,
523,
327,
10695,
26,
3474,
17,
2020,
378,
467,
359,
20,
12,
413,
2365,
284,
14,
69,
2020,
671,
62,
18,
819,
12111,
19625,
14,
23373,
1252,
11668,
8,
89,
16025,
17,
2020,
841,
467,
359,
25,
12,
413,
3934,
523,
327,
10695,
26,
3474,
17,
2020,
499,
467,
359,
19,
12,
413,
2365,
284,
14,
69,
2020,
7452,
8,
89,
680,
523,
10841,
819,
408,
819,
768,
15383,
14,
6667,
8,
489,
298,
12682,
13,
709,
13,
614,
401,
489,
298,
1918,
9134,
577,
5414,
852,
3555,
965,
12155,
370,
298,
489,
298,
26998,
22770,
3616,
298,
489,
7340,
2859,
921,
5031,
14,
957,
15,
16008,
15,
17210,
680,
2047,
298,
489,
298,
5626,
1678,
1006,
6941,
370,
675,
658,
3249,
80,
14,
5613,
64,
298,
489,
298,
23145,
402,
658,
3249,
14,
2828,
14,
5613,
2313,
401,
489,
7987,
63,
5089,
29,
549,
9,
523,
347,
636,
826,
721,
277,
12,
4107,
63,
589,
29,
797,
12,
536,
628,
9646,
2349,
272,
408,
10083,
4466,
2335,
314,
658,
23373,
64,
12111,
19625,
14,
339,
3033,
26,
489,
4107,
63,
589,
26,
2018,
658,
2245,
64,
9297,
3775,
2368,
1077,
506,
267,
7923,
367,
29102,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
1627,
370,
4156,
12883,
701,
642,
909,
14,
272,
408,
272,
291,
423,
354,
275,
536,
272,
1613,
8,
23373,
12,
291,
2843,
826,
721,
267,
7568,
63,
827,
63,
1430,
63,
13575,
29,
16,
12,
267,
4107,
63,
589,
29,
3502,
63,
589,
12,
267,
536,
29,
354,
9,
819,
347,
485,
6688,
8,
277,
12,
671,
304,
272,
671,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
88,
9,
272,
372,
3473,
63,
1483,
14,
9646,
8,
88,
9,
819,
347,
485,
11668,
8,
277,
12,
612,
304,
272,
612,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
89,
9,
272,
372,
3473,
63,
1483,
14,
5079,
8,
89,
9,
819,
347,
485,
6688,
63,
793,
63,
9886,
63,
27342,
8,
277,
12,
671,
304,
272,
671,
275,
291,
423,
11853,
63,
479,
63,
1078,
8,
88,
9,
272,
372,
980,
14,
793,
8,
18,
4959,
435,
3473,
63,
1483,
14,
793,
8,
88,
9,
819,
347,
485,
11853,
63,
479,
63,
1078,
8,
277,
12,
307,
304,
272,
340,
440,
291,
14,
3502,
63,
589,
26,
489,
372,
307,
272,
365,
63,
1078,
275,
1104,
63,
1483,
14,
479,
63,
2865,
63,
7371,
8,
267,
307,
12,
1245,
628,
2422,
4008,
1471,
506,
2222,
13,
7371,
2685,
272,
372,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
779,
374,
63,
1078,
467,
307,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OSU-CS-325/Project_Two_Coin_Change
|
nbmerge.py
|
2
|
1055
|
#!/usr/bin/python3
# Note, updated version of
# https://github.com/ipython/ipython-in-depth/blob/master/tools/nbmerge.py
"""
usage:
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb
"""
import io
import os
import sys
import nbformat
def merge_notebooks(filenames):
merged = None
for fname in filenames:
with io.open(fname, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)
if merged is None:
merged = nb
else:
# TODO: add an optional marker between joined notebooks
# like an horizontal rule, for example, or some other arbitrary
# (user specified) markdown cell)
merged.cells.extend(nb.cells)
if not hasattr(merged.metadata, 'name'):
merged.metadata.name = ''
merged.metadata.name += "_merged"
print(nbformat.writes(merged))
if __name__ == '__main__':
notebooks = sys.argv[1:]
if not notebooks:
print(__doc__, file=sys.stderr)
sys.exit(1)
merge_notebooks(notebooks)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
3390,
12,
4588,
1015,
402,
221,
199,
3,
4178,
921,
5031,
14,
957,
15,
22691,
15,
22691,
13,
262,
13,
4631,
15,
6582,
15,
4133,
15,
2537,
15,
4994,
5628,
14,
647,
199,
624,
199,
3807,
26,
199,
1548,
8526,
5628,
14,
647,
437,
14,
73,
647,
4994,
699,
14,
73,
647,
4994,
445,
14,
73,
647,
4994,
690,
9545,
14,
73,
647,
4994,
199,
624,
199,
199,
646,
5890,
199,
646,
747,
199,
646,
984,
199,
199,
646,
8526,
908,
199,
199,
318,
5389,
63,
4610,
8858,
8,
10309,
304,
272,
9545,
275,
488,
272,
367,
6748,
315,
6203,
26,
267,
543,
5890,
14,
1490,
8,
5252,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
288,
8526,
275,
8526,
908,
14,
739,
8,
70,
12,
465,
63,
1023,
29,
20,
9,
267,
340,
9545,
365,
488,
26,
288,
9545,
275,
8526,
267,
587,
26,
288,
327,
3254,
26,
1050,
376,
2716,
3608,
3382,
16538,
5317,
8858,
288,
327,
2839,
376,
17528,
2332,
12,
367,
2893,
12,
503,
2005,
1163,
9697,
288,
327,
334,
751,
2013,
9,
18502,
4917,
9,
288,
9545,
14,
9041,
14,
2880,
8,
4994,
14,
9041,
9,
272,
340,
440,
2688,
8,
15269,
14,
2343,
12,
283,
354,
735,
267,
9545,
14,
2343,
14,
354,
275,
2125,
272,
9545,
14,
2343,
14,
354,
847,
2668,
15269,
2,
272,
870,
8,
4994,
908,
14,
16334,
8,
15269,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
5317,
8858,
275,
984,
14,
3020,
59,
17,
2938,
272,
340,
440,
5317,
8858,
26,
267,
870,
3460,
1301,
3108,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2224,
8,
17,
9,
5493,
5389,
63,
4610,
8858,
8,
4610,
8858,
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
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
3390,
12,
4588,
1015,
402,
221,
199,
3,
4178,
921,
5031,
14,
957,
15,
22691,
15,
22691,
13,
262,
13,
4631,
15,
6582,
15,
4133,
15,
2537,
15,
4994,
5628,
14,
647,
199,
624,
199,
3807,
26,
199,
1548,
8526,
5628,
14,
647,
437,
14,
73,
647,
4994,
699,
14,
73,
647,
4994,
445,
14,
73,
647,
4994,
690,
9545,
14,
73,
647,
4994,
199,
624,
199,
199,
646,
5890,
199,
646,
747,
199,
646,
984,
199,
199,
646,
8526,
908,
199,
199,
318,
5389,
63,
4610,
8858,
8,
10309,
304,
272,
9545,
275,
488,
272,
367,
6748,
315,
6203,
26,
267,
543,
5890,
14,
1490,
8,
5252,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
288,
8526,
275,
8526,
908,
14,
739,
8,
70,
12,
465,
63,
1023,
29,
20,
9,
267,
340,
9545,
365,
488,
26,
288,
9545,
275,
8526,
267,
587,
26,
288,
327,
3254,
26,
1050,
376,
2716,
3608,
3382,
16538,
5317,
8858,
288,
327,
2839,
376,
17528,
2332,
12,
367,
2893,
12,
503,
2005,
1163,
9697,
288,
327,
334,
751,
2013,
9,
18502,
4917,
9,
288,
9545,
14,
9041,
14,
2880,
8,
4994,
14,
9041,
9,
272,
340,
440,
2688,
8,
15269,
14,
2343,
12,
283,
354,
735,
267,
9545,
14,
2343,
14,
354,
275,
2125,
272,
9545,
14,
2343,
14,
354,
847,
2668,
15269,
2,
272,
870,
8,
4994,
908,
14,
16334,
8,
15269,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
5317,
8858,
275,
984,
14,
3020,
59,
17,
2938,
272,
340,
440,
5317,
8858,
26,
267,
870,
3460,
1301,
3108,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2224,
8,
17,
9,
5493,
5389,
63,
4610,
8858,
8,
4610,
8858,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shackspace/inkcut_dmpl
|
app/bin/serial/serialposix.py
|
2
|
24213
|
#!/usr/bin/env python
#
# Python Serial Port Extension for Win32, Linux, BSD, Jython
# module for serial IO for POSIX compatible systems, like Linux
# see __init__.py
#
# (C) 2001-2010 Chris Liechti <cliechti@gmx.net>
# this is distributed under a free software license, see license.txt
#
# parts based on code from Grant B. Edwards <grante@visi.com>:
# ftp://ftp.visi.com/users/grante/python/PosixSerial.py
#
# references: http://www.easysw.com/~mike/serial/serial.html
import sys, os, fcntl, termios, struct, select, errno, time
from serialutil import *
# Do check the Python version as some constants have moved.
if (sys.hexversion < 0x020100f0):
import TERMIOS
else:
TERMIOS = termios
if (sys.hexversion < 0x020200f0):
import FCNTL
else:
FCNTL = fcntl
# try to detect the OS so that a device can be selected...
# this code block should supply a device() and set_special_baudrate() function
# for the platform
plat = sys.platform.lower()
if plat[:5] == 'linux': # Linux (confirmed)
def device(port):
return '/dev/ttyS%d' % port
ASYNC_SPD_MASK = 0x1030
ASYNC_SPD_CUST = 0x0030
def set_special_baudrate(port, baudrate):
import array
buf = array.array('i', [0] * 32)
# get serial_struct
FCNTL.ioctl(port.fd, TERMIOS.TIOCGSERIAL, buf)
# set custom divisor
buf[6] = buf[7] / baudrate
# update flags
buf[4] &= ~ASYNC_SPD_MASK
buf[4] |= ASYNC_SPD_CUST
# set serial_struct
try:
res = FCNTL.ioctl(port.fd, TERMIOS.TIOCSSERIAL, buf)
except IOError:
raise ValueError('Failed to set custom baud rate: %r' % baudrate)
baudrate_constants = {
0: 0000000, # hang up
50: 0000001,
75: 0000002,
110: 0000003,
134: 0000004,
150: 0000005,
200: 0000006,
300: 0000007,
600: 0000010,
1200: 0000011,
1800: 0000012,
2400: 0000013,
4800: 0000014,
9600: 0000015,
19200: 0000016,
38400: 0000017,
57600: 0010001,
115200: 0010002,
230400: 0010003,
460800: 0010004,
500000: 0010005,
576000: 0010006,
921600: 0010007,
1000000: 0010010,
1152000: 0010011,
1500000: 0010012,
2000000: 0010013,
2500000: 0010014,
3000000: 0010015,
3500000: 0010016,
4000000: 0010017
}
elif plat == 'cygwin': # cygwin/win32 (confirmed)
def device(port):
return '/dev/com%d' % (port + 1)
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat == 'openbsd3': # BSD (confirmed)
def device(port):
return '/dev/ttyp%d' % port
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:3] == 'bsd' or \
plat[:7] == 'freebsd' or \
plat[:7] == 'openbsd': # BSD (confirmed for freebsd4: cuaa%d)
def device(port):
return '/dev/cuad%d' % port
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:6] == 'darwin': # OS X
version = os.uname()[2].split('.')
# Tiger or above can support arbitrary serial speeds
if int(version[0]) >= 8:
def set_special_baudrate(port, baudrate):
# use IOKit-specific call to set up high speeds
import array, fcntl
buf = array.array('i', [baudrate])
IOSSIOSPEED = 0x80045402 #_IOW('T', 2, speed_t)
fcntl.ioctl(port.fd, IOSSIOSPEED, buf, 1)
else: # version < 8
def set_special_baudrate(port, baudrate):
raise ValueError("baud rate not supported")
def device(port):
return '/dev/cuad%d' % port
baudrate_constants = {}
elif plat[:6] == 'netbsd': # NetBSD 1.6 testing by Erk
def device(port):
return '/dev/dty%02d' % port
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:4] == 'irix': # IRIX (partially tested)
def device(port):
return '/dev/ttyf%d' % (port+1) #XXX different device names depending on flow control
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:2] == 'hp': # HP-UX (not tested)
def device(port):
return '/dev/tty%dp0' % (port+1)
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:5] == 'sunos': # Solaris/SunOS (confirmed)
def device(port):
return '/dev/tty%c' % (ord('a')+port)
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
elif plat[:3] == 'aix': # AIX
def device(port):
return '/dev/tty%d' % (port)
def set_special_baudrate(port, baudrate):
raise ValueError("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
else:
# platform detection has failed...
sys.stderr.write("""\
don't know how to number ttys on this system.
! Use an explicit path (eg /dev/ttyS1) or send this information to
! the author of this module:
sys.platform = %r
os.name = %r
serialposix.py version = %s
also add the device name of the serial port and where the
counting starts for the first serial port.
e.g. 'first serial port: /dev/ttyS0'
and with a bit luck you can get this module running...
""" % (sys.platform, os.name, VERSION))
# no exception, just continue with a brave attempt to build a device name
# even if the device name is not correct for the platform it has chances
# to work using a string with the real device name as port parameter.
def device(portum):
return '/dev/ttyS%d' % portnum
def set_special_baudrate(port, baudrate):
raise SerialException("sorry don't know how to handle non standard baud rate on this platform")
baudrate_constants = {}
#~ raise Exception, "this module does not run on this platform, sorry."
# whats up with "aix", "beos", ....
# they should work, just need to know the device names.
# load some constants for later use.
# try to use values from TERMIOS, use defaults from linux otherwise
TIOCMGET = hasattr(TERMIOS, 'TIOCMGET') and TERMIOS.TIOCMGET or 0x5415
TIOCMBIS = hasattr(TERMIOS, 'TIOCMBIS') and TERMIOS.TIOCMBIS or 0x5416
TIOCMBIC = hasattr(TERMIOS, 'TIOCMBIC') and TERMIOS.TIOCMBIC or 0x5417
TIOCMSET = hasattr(TERMIOS, 'TIOCMSET') and TERMIOS.TIOCMSET or 0x5418
#TIOCM_LE = hasattr(TERMIOS, 'TIOCM_LE') and TERMIOS.TIOCM_LE or 0x001
TIOCM_DTR = hasattr(TERMIOS, 'TIOCM_DTR') and TERMIOS.TIOCM_DTR or 0x002
TIOCM_RTS = hasattr(TERMIOS, 'TIOCM_RTS') and TERMIOS.TIOCM_RTS or 0x004
#TIOCM_ST = hasattr(TERMIOS, 'TIOCM_ST') and TERMIOS.TIOCM_ST or 0x008
#TIOCM_SR = hasattr(TERMIOS, 'TIOCM_SR') and TERMIOS.TIOCM_SR or 0x010
TIOCM_CTS = hasattr(TERMIOS, 'TIOCM_CTS') and TERMIOS.TIOCM_CTS or 0x020
TIOCM_CAR = hasattr(TERMIOS, 'TIOCM_CAR') and TERMIOS.TIOCM_CAR or 0x040
TIOCM_RNG = hasattr(TERMIOS, 'TIOCM_RNG') and TERMIOS.TIOCM_RNG or 0x080
TIOCM_DSR = hasattr(TERMIOS, 'TIOCM_DSR') and TERMIOS.TIOCM_DSR or 0x100
TIOCM_CD = hasattr(TERMIOS, 'TIOCM_CD') and TERMIOS.TIOCM_CD or TIOCM_CAR
TIOCM_RI = hasattr(TERMIOS, 'TIOCM_RI') and TERMIOS.TIOCM_RI or TIOCM_RNG
#TIOCM_OUT1 = hasattr(TERMIOS, 'TIOCM_OUT1') and TERMIOS.TIOCM_OUT1 or 0x2000
#TIOCM_OUT2 = hasattr(TERMIOS, 'TIOCM_OUT2') and TERMIOS.TIOCM_OUT2 or 0x4000
TIOCINQ = hasattr(TERMIOS, 'FIONREAD') and TERMIOS.FIONREAD or 0x541B
TIOCM_zero_str = struct.pack('I', 0)
TIOCM_RTS_str = struct.pack('I', TIOCM_RTS)
TIOCM_DTR_str = struct.pack('I', TIOCM_DTR)
TIOCSBRK = hasattr(TERMIOS, 'TIOCSBRK') and TERMIOS.TIOCSBRK or 0x5427
TIOCCBRK = hasattr(TERMIOS, 'TIOCCBRK') and TERMIOS.TIOCCBRK or 0x5428
class PosixSerial(SerialBase):
"""Serial port class POSIX implementation. Serial port configuration is
done with termios and fcntl. Runs on Linux and many other Un*x like
systems."""
def open(self):
"""Open port with current settings. This may throw a SerialException
if the port cannot be opened."""
self.fd = None
if self._port is None:
raise SerialException("Port must be configured before it can be used.")
# open
try:
self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
except Exception, msg:
self.fd = None
raise SerialException("could not open port %s: %s" % (self._port, msg))
#~ fcntl.fcntl(self.fd, FCNTL.F_SETFL, 0) # set blocking
try:
self._reconfigurePort()
except:
try:
os.close(self.fd)
except:
# ignore any exception when closing the port
# also to keep original exception that happened when setting up
pass
self.fd = None
raise
else:
self._isOpen = True
#~ self.flushInput()
def _reconfigurePort(self):
"""Set communication parameters on opened port."""
if self.fd is None:
raise SerialException("Can only operate on a valid file descriptor")
custom_baud = None
vmin = vtime = 0 # timeout is done via select
if self._interCharTimeout is not None:
vmin = 1
vtime = int(self._interCharTimeout * 10)
try:
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self.fd)
except termios.error, msg: # if a port is nonexistent but has a /dev file, it'll fail here
raise SerialException("Could not configure port: %s" % msg)
# set up raw mode / no echo / binary
cflag |= (TERMIOS.CLOCAL|TERMIOS.CREAD)
lflag &= ~(TERMIOS.ICANON|TERMIOS.ECHO|TERMIOS.ECHOE|TERMIOS.ECHOK|TERMIOS.ECHONL|
TERMIOS.ISIG|TERMIOS.IEXTEN) #|TERMIOS.ECHOPRT
for flag in ('ECHOCTL', 'ECHOKE'): # netbsd workaround for Erk
if hasattr(TERMIOS, flag):
lflag &= ~getattr(TERMIOS, flag)
oflag &= ~(TERMIOS.OPOST)
iflag &= ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IGNBRK)
if hasattr(TERMIOS, 'IUCLC'):
iflag &= ~TERMIOS.IUCLC
if hasattr(TERMIOS, 'PARMRK'):
iflag &= ~TERMIOS.PARMRK
# setup baud rate
try:
ispeed = ospeed = getattr(TERMIOS, 'B%s' % (self._baudrate))
except AttributeError:
try:
ispeed = ospeed = baudrate_constants[self._baudrate]
except KeyError:
#~ raise ValueError('Invalid baud rate: %r' % self._baudrate)
# may need custom baud rate, it isn't in our list.
ispeed = ospeed = getattr(TERMIOS, 'B38400')
try:
custom_baud = int(self._baudrate) # store for later
except ValueError:
raise ValueError('Invalid baud rate: %r' % self._baudrate)
else:
if custom_baud < 0:
raise ValueError('Invalid baud rate: %r' % self._baudrate)
# setup char len
cflag &= ~TERMIOS.CSIZE
if self._bytesize == 8:
cflag |= TERMIOS.CS8
elif self._bytesize == 7:
cflag |= TERMIOS.CS7
elif self._bytesize == 6:
cflag |= TERMIOS.CS6
elif self._bytesize == 5:
cflag |= TERMIOS.CS5
else:
raise ValueError('Invalid char len: %r' % self._bytesize)
# setup stopbits
if self._stopbits == STOPBITS_ONE:
cflag &= ~(TERMIOS.CSTOPB)
elif self._stopbits == STOPBITS_ONE_POINT_FIVE:
cflag |= (TERMIOS.CSTOPB) # XXX same as TWO.. there is no POSIX support for 1.5
elif self._stopbits == STOPBITS_TWO:
cflag |= (TERMIOS.CSTOPB)
else:
raise ValueError('Invalid stop bit specification: %r' % self._stopbits)
# setup parity
iflag &= ~(TERMIOS.INPCK|TERMIOS.ISTRIP)
if self._parity == PARITY_NONE:
cflag &= ~(TERMIOS.PARENB|TERMIOS.PARODD)
elif self._parity == PARITY_EVEN:
cflag &= ~(TERMIOS.PARODD)
cflag |= (TERMIOS.PARENB)
elif self._parity == PARITY_ODD:
cflag |= (TERMIOS.PARENB|TERMIOS.PARODD)
else:
raise ValueError('Invalid parity: %r' % self._parity)
# setup flow control
# xonxoff
if hasattr(TERMIOS, 'IXANY'):
if self._xonxoff:
iflag |= (TERMIOS.IXON|TERMIOS.IXOFF) #|TERMIOS.IXANY)
else:
iflag &= ~(TERMIOS.IXON|TERMIOS.IXOFF|TERMIOS.IXANY)
else:
if self._xonxoff:
iflag |= (TERMIOS.IXON|TERMIOS.IXOFF)
else:
iflag &= ~(TERMIOS.IXON|TERMIOS.IXOFF)
# rtscts
if hasattr(TERMIOS, 'CRTSCTS'):
if self._rtscts:
cflag |= (TERMIOS.CRTSCTS)
else:
cflag &= ~(TERMIOS.CRTSCTS)
elif hasattr(TERMIOS, 'CNEW_RTSCTS'): # try it with alternate constant name
if self._rtscts:
cflag |= (TERMIOS.CNEW_RTSCTS)
else:
cflag &= ~(TERMIOS.CNEW_RTSCTS)
# XXX should there be a warning if setting up rtscts (and xonxoff etc) fails??
# buffer
# vmin "minimal number of characters to be read. = for non blocking"
if vmin < 0 or vmin > 255:
raise ValueError('Invalid vmin: %r ' % vmin)
cc[TERMIOS.VMIN] = vmin
# vtime
if vtime < 0 or vtime > 255:
raise ValueError('Invalid vtime: %r' % vtime)
cc[TERMIOS.VTIME] = vtime
# activate settings
termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
# apply custom baud rate, if any
if custom_baud is not None:
set_special_baudrate(self, custom_baud)
def close(self):
"""Close port"""
if self._isOpen:
if self.fd is not None:
os.close(self.fd)
self.fd = None
self._isOpen = False
def makeDeviceName(self, port):
return device(port)
# - - - - - - - - - - - - - - - - - - - - - - - -
def inWaiting(self):
"""Return the number of characters currently in the input buffer."""
#~ s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str)
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
return struct.unpack('I',s)[0]
# select based implementation, proved to work on many systems
def read(self, size=1):
"""Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read."""
if self.fd is None: raise portNotOpenError
read = bytearray()
while len(read) < size:
ready,_,_ = select.select([self.fd],[],[], self._timeout)
# If select was used with a timeout, and the timeout occurs, it
# returns with empty lists -> thus abort read operation.
# For timeout == 0 (non-blocking operation) also abort when there
# is nothing to read.
if not ready:
break # timeout
buf = os.read(self.fd, size-len(read))
# read should always return some data as select reported it was
# ready to read when we get to this point.
if not buf:
# Disconnected devices, at least on Linux, show the
# behavior that they are always ready to read immediately
# but reading returns nothing.
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
read.extend(buf)
return bytes(read)
def write(self, data):
"""Output the given string over the serial port."""
if self.fd is None: raise portNotOpenError
t = len(data)
d = data
if self._writeTimeout is not None and self._writeTimeout > 0:
timeout = time.time() + self._writeTimeout
else:
timeout = None
while t > 0:
try:
n = os.write(self.fd, d)
if timeout:
# when timeout is set, use select to wait for being ready
# with the time left as timeout
timeleft = timeout - time.time()
if timeleft < 0:
raise writeTimeoutError
_, ready, _ = select.select([], [self.fd], [], timeleft)
if not ready:
raise writeTimeoutError
d = d[n:]
t = t - n
except OSError, v:
if v.errno != errno.EAGAIN:
raise SerialException('write failed: %s' % (v,))
return len(data)
def flush(self):
"""Flush of file like objects. In this case, wait until all data
is written."""
self.drainOutput()
def flushInput(self):
"""Clear input buffer, discarding all that is in the buffer."""
if self.fd is None:
raise portNotOpenError
termios.tcflush(self.fd, TERMIOS.TCIFLUSH)
def flushOutput(self):
"""Clear output buffer, aborting the current output and
discarding all that is in the buffer."""
if self.fd is None:
raise portNotOpenError
termios.tcflush(self.fd, TERMIOS.TCOFLUSH)
def sendBreak(self, duration=0.25):
"""Send break condition. Timed, returns to idle state after given duration."""
if self.fd is None:
raise portNotOpenError
termios.tcsendbreak(self.fd, int(duration/0.25))
def setBreak(self, level=1):
"""Set break: Controls TXD. When active, no transmitting is possible."""
if self.fd is None: raise portNotOpenError
if level:
fcntl.ioctl(self.fd, TIOCSBRK)
else:
fcntl.ioctl(self.fd, TIOCCBRK)
def setRTS(self, level=1):
"""Set terminal status line: Request To Send"""
if self.fd is None: raise portNotOpenError
if level:
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str)
else:
fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_RTS_str)
def setDTR(self, level=1):
"""Set terminal status line: Data Terminal Ready"""
if self.fd is None: raise portNotOpenError
if level:
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
else:
fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str)
def getCTS(self):
"""Read terminal status line: Clear To Send"""
if self.fd is None: raise portNotOpenError
s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str)
return struct.unpack('I',s)[0] & TIOCM_CTS != 0
def getDSR(self):
"""Read terminal status line: Data Set Ready"""
if self.fd is None: raise portNotOpenError
s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str)
return struct.unpack('I',s)[0] & TIOCM_DSR != 0
def getRI(self):
"""Read terminal status line: Ring Indicator"""
if self.fd is None: raise portNotOpenError
s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str)
return struct.unpack('I',s)[0] & TIOCM_RI != 0
def getCD(self):
"""Read terminal status line: Carrier Detect"""
if self.fd is None: raise portNotOpenError
s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str)
return struct.unpack('I',s)[0] & TIOCM_CD != 0
# - - platform specific - - - -
def drainOutput(self):
"""internal - not portable!"""
if self.fd is None: raise portNotOpenError
termios.tcdrain(self.fd)
def nonblocking(self):
"""internal - not portable!"""
if self.fd is None:
raise portNotOpenError
fcntl.fcntl(self.fd, FCNTL.F_SETFL, FCNTL.O_NONBLOCK)
def fileno(self):
"""For easier use of the serial port instance with select.
WARNING: this function is not portable to different platforms!"""
if self.fd is None: raise portNotOpenError
return self.fd
def flowControl(self, enable):
"""manually control flow - when hardware or software flow control is
enabled"""
if enable:
termios.tcflow(self.fd, TERMIOS.TCION)
else:
termios.tcflow(self.fd, TERMIOS.TCIOFF)
# assemble Serial class with the platform specifc implementation and the base
# for file-like behavior. for Python 2.6 and newer, that provide the new I/O
# library, derrive from io.RawIOBase
try:
import io
except ImportError:
# classic version with our own file-like emulation
class Serial(PosixSerial, FileLike):
pass
else:
# io library present
class Serial(PosixSerial, io.RawIOBase):
pass
class PosixPollSerial(Serial):
"""poll based read implementation. not all systems support poll properly.
however this one has better handling of errors, such as a device
disconnecting while it's in use (e.g. USB-serial unplugged)"""
def read(self, size=1):
"""Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read."""
if self.fd is None: raise portNotOpenError
read = bytearray()
poll = select.poll()
poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
if size > 0:
while len(read) < size:
# print "\tread(): size",size, "have", len(read) #debug
# wait until device becomes ready to read (or something fails)
for fd, event in poll.poll(self._timeout):
if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
raise SerialException('device reports error (poll)')
# we don't care if it is select.POLLIN or timeout, that's
# handled below
buf = os.read(self.fd, size - len(read))
read.extend(buf)
if ((self._timeout is not None and self._timeout >= 0) or
(self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
break # early abort on timeout
return bytes(read)
if __name__ == '__main__':
s = Serial(0,
baudrate=19200, # baud rate
bytesize=EIGHTBITS, # number of data bits
parity=PARITY_EVEN, # enable parity checking
stopbits=STOPBITS_ONE, # number of stop bits
timeout=3, # set a timeout value, None for waiting forever
xonxoff=0, # enable software flow control
rtscts=0, # enable RTS/CTS flow control
)
s.setRTS(1)
s.setDTR(1)
s.flushInput()
s.flushOutput()
s.write('hello')
sys.stdout.write('%r\n' % s.read(5))
sys.stdout.write('%s\n' % s.inWaiting())
del s
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
2018,
11973,
10977,
13282,
367,
13036,
708,
12,
10130,
12,
6289,
12,
25333,
199,
3,
859,
367,
3012,
5004,
367,
18169,
9025,
10460,
12,
2839,
10130,
199,
3,
1937,
636,
826,
4343,
647,
199,
3,
199,
3,
334,
35,
9,
12521,
13,
6542,
2799,
5719,
491,
1873,
335,
280,
665,
2764,
12736,
280,
32,
71,
9457,
14,
846,
30,
199,
3,
642,
365,
1854,
1334,
282,
2867,
2032,
4190,
12,
1937,
4190,
14,
2424,
199,
3,
199,
3,
4184,
4079,
641,
1233,
687,
598,
17633,
699,
14,
17379,
4751,
221,
665,
26655,
266,
32,
433,
338,
14,
957,
20020,
199,
3,
221,
14904,
921,
8915,
14,
433,
338,
14,
957,
15,
3707,
15,
26655,
266,
15,
1548,
15,
1575,
4174,
3571,
14,
647,
199,
3,
199,
3,
6941,
26,
1455,
921,
1544,
14,
69,
305,
588,
87,
14,
957,
22500,
2664,
415,
15,
2171,
15,
2171,
14,
1360,
199,
199,
646,
984,
12,
747,
12,
12871,
12,
28725,
12,
2702,
12,
3504,
12,
7554,
12,
900,
199,
504,
3012,
1974,
492,
627,
199,
199,
3,
4226,
1104,
314,
2018,
1015,
465,
2005,
5262,
1172,
12155,
14,
199,
692,
334,
1274,
14,
4097,
1023,
665,
378,
88,
996,
16569,
70,
16,
304,
272,
492,
31510,
45,
13532,
199,
2836,
26,
272,
31510,
45,
13532,
275,
28725,
199,
199,
692,
334,
1274,
14,
4097,
1023,
665,
378,
88,
996,
24215,
70,
16,
304,
272,
492,
481,
12874,
7308,
199,
2836,
26,
272,
481,
12874,
7308,
275,
12871,
199,
199,
3,
862,
370,
9696,
314,
4403,
880,
626,
282,
2243,
883,
506,
4895,
1396,
199,
3,
642,
1233,
1853,
1077,
17169,
282,
2243,
342,
436,
663,
63,
6664,
63,
2470,
27112,
342,
805,
199,
3,
367,
314,
4298,
199,
14156,
275,
984,
14,
3246,
14,
2325,
342,
199,
199,
692,
257,
20819,
1491,
21,
61,
508,
283,
5135,
356,
259,
327,
10130,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
4707,
51,
5,
68,
7,
450,
1844,
339,
4319,
57,
6389,
63,
5763,
36,
63,
12880,
275,
378,
88,
709,
1216,
272,
4319,
57,
6389,
63,
5763,
36,
63,
17365,
275,
378,
88,
24281,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
492,
1625,
267,
4123,
275,
1625,
14,
1144,
360,
73,
297,
359,
16,
61,
627,
4337,
9,
398,
327,
664,
3012,
63,
1820,
267,
481,
12874,
7308,
14,
2308,
8077,
8,
719,
14,
2592,
12,
31510,
45,
13532,
14,
52,
2090,
4064,
19637,
12,
4123,
9,
398,
327,
663,
3537,
487,
8286,
267,
4123,
59,
22,
61,
275,
4123,
59,
23,
61,
1182,
19325,
27112,
398,
327,
1678,
3285,
267,
4123,
59,
20,
61,
18415,
6146,
26222,
6389,
63,
5763,
36,
63,
12880,
267,
4123,
59,
20,
61,
8901,
4319,
57,
6389,
63,
5763,
36,
63,
17365,
398,
327,
663,
3012,
63,
1820,
267,
862,
26,
288,
522,
275,
481,
12874,
7308,
14,
2308,
8077,
8,
719,
14,
2592,
12,
31510,
45,
13532,
14,
52,
2090,
14391,
540,
4938,
12,
4123,
9,
267,
871,
5925,
26,
288,
746,
1722,
360,
4276,
370,
663,
3537,
19325,
1181,
6634,
26,
450,
82,
7,
450,
19325,
27112,
9,
339,
19325,
27112,
63,
5559,
275,
469,
267,
378,
26,
755,
378,
3273,
12,
221,
327,
30084,
1536,
267,
5238,
26,
420,
378,
19983,
12,
267,
13098,
26,
420,
378,
993,
996,
12,
267,
16814,
26,
258,
378,
993,
1644,
12,
267,
25956,
26,
258,
378,
993,
966,
12,
267,
14711,
26,
258,
378,
993,
1717,
12,
267,
1926,
26,
258,
378,
993,
1690,
12,
267,
9601,
26,
258,
378,
993,
1780,
12,
267,
11624,
26,
258,
378,
993,
709,
12,
267,
413,
1840,
26,
259,
378,
993,
845,
12,
267,
6155,
383,
26,
259,
378,
993,
713,
12,
267,
499,
5303,
26,
259,
378,
993,
969,
12,
267,
841,
6718,
26,
259,
378,
993,
1079,
12,
267,
1749,
6683,
26,
259,
378,
993,
1046,
12,
267,
5851,
1840,
26,
257,
378,
993,
975,
12,
267,
29772,
383,
26,
257,
378,
993,
1196,
12,
267,
959,
2114,
383,
26,
257,
378,
614,
4183,
12,
267,
22560,
1840,
26,
221,
378,
614,
9425,
12,
267,
6546,
27130,
26,
221,
378,
614,
16861,
12,
267,
12426,
25822,
26,
221,
378,
16569,
966,
12,
267,
959,
5345,
26,
221,
378,
614,
15646,
12,
267,
959,
2114,
1493,
26,
221,
378,
614,
20965,
12,
267,
1749,
9669,
383,
26,
221,
378,
614,
22530,
12,
267,
19492,
26,
378,
16569,
709,
12,
267,
22560,
8269,
26,
378,
16569,
845,
12,
267,
4114,
5345,
26,
378,
16569,
713,
12,
267,
499,
3273,
26,
378,
16569,
969,
12,
267,
5661,
5345,
26,
378,
16569,
1079,
12,
267,
650,
3273,
26,
378,
16569,
1046,
12,
267,
8685,
5345,
26,
378,
16569,
975,
12,
267,
841,
3273,
26,
378,
16569,
1196,
272,
789,
199,
199,
4164,
20819,
508,
283,
16680,
356,
755,
327,
23941,
15,
2676,
708,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
957,
5,
68,
7,
450,
334,
719,
435,
413,
9,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
746,
1722,
480,
1509,
651,
2793,
1133,
5715,
4212,
370,
2429,
2222,
4465,
19325,
1181,
6634,
641,
642,
4298,
531,
339,
19325,
27112,
63,
5559,
275,
1052,
199,
199,
4164,
20819,
508,
283,
1490,
15746,
19,
356,
259,
327,
6289,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
4707,
80,
5,
68,
7,
450,
1844,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
746,
1722,
480,
1509,
651,
2793,
1133,
5715,
4212,
370,
2429,
2222,
4465,
19325,
1181,
6634,
641,
642,
4298,
531,
339,
19325,
27112,
63,
5559,
275,
1052,
199,
199,
4164,
20819,
1491,
19,
61,
508,
283,
15746,
7,
503,
221,
971,
1362,
20819,
1491,
23,
61,
508,
283,
29629,
7,
503,
971,
1362,
20819,
1491,
23,
61,
508,
283,
1490,
15746,
356,
221,
327,
6289,
334,
16391,
367,
2867,
15746,
20,
26,
286,
10091,
5,
68,
9,
339,
347,
2243,
8,
719,
304
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
2018,
11973,
10977,
13282,
367,
13036,
708,
12,
10130,
12,
6289,
12,
25333,
199,
3,
859,
367,
3012,
5004,
367,
18169,
9025,
10460,
12,
2839,
10130,
199,
3,
1937,
636,
826,
4343,
647,
199,
3,
199,
3,
334,
35,
9,
12521,
13,
6542,
2799,
5719,
491,
1873,
335,
280,
665,
2764,
12736,
280,
32,
71,
9457,
14,
846,
30,
199,
3,
642,
365,
1854,
1334,
282,
2867,
2032,
4190,
12,
1937,
4190,
14,
2424,
199,
3,
199,
3,
4184,
4079,
641,
1233,
687,
598,
17633,
699,
14,
17379,
4751,
221,
665,
26655,
266,
32,
433,
338,
14,
957,
20020,
199,
3,
221,
14904,
921,
8915,
14,
433,
338,
14,
957,
15,
3707,
15,
26655,
266,
15,
1548,
15,
1575,
4174,
3571,
14,
647,
199,
3,
199,
3,
6941,
26,
1455,
921,
1544,
14,
69,
305,
588,
87,
14,
957,
22500,
2664,
415,
15,
2171,
15,
2171,
14,
1360,
199,
199,
646,
984,
12,
747,
12,
12871,
12,
28725,
12,
2702,
12,
3504,
12,
7554,
12,
900,
199,
504,
3012,
1974,
492,
627,
199,
199,
3,
4226,
1104,
314,
2018,
1015,
465,
2005,
5262,
1172,
12155,
14,
199,
692,
334,
1274,
14,
4097,
1023,
665,
378,
88,
996,
16569,
70,
16,
304,
272,
492,
31510,
45,
13532,
199,
2836,
26,
272,
31510,
45,
13532,
275,
28725,
199,
199,
692,
334,
1274,
14,
4097,
1023,
665,
378,
88,
996,
24215,
70,
16,
304,
272,
492,
481,
12874,
7308,
199,
2836,
26,
272,
481,
12874,
7308,
275,
12871,
199,
199,
3,
862,
370,
9696,
314,
4403,
880,
626,
282,
2243,
883,
506,
4895,
1396,
199,
3,
642,
1233,
1853,
1077,
17169,
282,
2243,
342,
436,
663,
63,
6664,
63,
2470,
27112,
342,
805,
199,
3,
367,
314,
4298,
199,
14156,
275,
984,
14,
3246,
14,
2325,
342,
199,
199,
692,
257,
20819,
1491,
21,
61,
508,
283,
5135,
356,
259,
327,
10130,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
4707,
51,
5,
68,
7,
450,
1844,
339,
4319,
57,
6389,
63,
5763,
36,
63,
12880,
275,
378,
88,
709,
1216,
272,
4319,
57,
6389,
63,
5763,
36,
63,
17365,
275,
378,
88,
24281,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
492,
1625,
267,
4123,
275,
1625,
14,
1144,
360,
73,
297,
359,
16,
61,
627,
4337,
9,
398,
327,
664,
3012,
63,
1820,
267,
481,
12874,
7308,
14,
2308,
8077,
8,
719,
14,
2592,
12,
31510,
45,
13532,
14,
52,
2090,
4064,
19637,
12,
4123,
9,
398,
327,
663,
3537,
487,
8286,
267,
4123,
59,
22,
61,
275,
4123,
59,
23,
61,
1182,
19325,
27112,
398,
327,
1678,
3285,
267,
4123,
59,
20,
61,
18415,
6146,
26222,
6389,
63,
5763,
36,
63,
12880,
267,
4123,
59,
20,
61,
8901,
4319,
57,
6389,
63,
5763,
36,
63,
17365,
398,
327,
663,
3012,
63,
1820,
267,
862,
26,
288,
522,
275,
481,
12874,
7308,
14,
2308,
8077,
8,
719,
14,
2592,
12,
31510,
45,
13532,
14,
52,
2090,
14391,
540,
4938,
12,
4123,
9,
267,
871,
5925,
26,
288,
746,
1722,
360,
4276,
370,
663,
3537,
19325,
1181,
6634,
26,
450,
82,
7,
450,
19325,
27112,
9,
339,
19325,
27112,
63,
5559,
275,
469,
267,
378,
26,
755,
378,
3273,
12,
221,
327,
30084,
1536,
267,
5238,
26,
420,
378,
19983,
12,
267,
13098,
26,
420,
378,
993,
996,
12,
267,
16814,
26,
258,
378,
993,
1644,
12,
267,
25956,
26,
258,
378,
993,
966,
12,
267,
14711,
26,
258,
378,
993,
1717,
12,
267,
1926,
26,
258,
378,
993,
1690,
12,
267,
9601,
26,
258,
378,
993,
1780,
12,
267,
11624,
26,
258,
378,
993,
709,
12,
267,
413,
1840,
26,
259,
378,
993,
845,
12,
267,
6155,
383,
26,
259,
378,
993,
713,
12,
267,
499,
5303,
26,
259,
378,
993,
969,
12,
267,
841,
6718,
26,
259,
378,
993,
1079,
12,
267,
1749,
6683,
26,
259,
378,
993,
1046,
12,
267,
5851,
1840,
26,
257,
378,
993,
975,
12,
267,
29772,
383,
26,
257,
378,
993,
1196,
12,
267,
959,
2114,
383,
26,
257,
378,
614,
4183,
12,
267,
22560,
1840,
26,
221,
378,
614,
9425,
12,
267,
6546,
27130,
26,
221,
378,
614,
16861,
12,
267,
12426,
25822,
26,
221,
378,
16569,
966,
12,
267,
959,
5345,
26,
221,
378,
614,
15646,
12,
267,
959,
2114,
1493,
26,
221,
378,
614,
20965,
12,
267,
1749,
9669,
383,
26,
221,
378,
614,
22530,
12,
267,
19492,
26,
378,
16569,
709,
12,
267,
22560,
8269,
26,
378,
16569,
845,
12,
267,
4114,
5345,
26,
378,
16569,
713,
12,
267,
499,
3273,
26,
378,
16569,
969,
12,
267,
5661,
5345,
26,
378,
16569,
1079,
12,
267,
650,
3273,
26,
378,
16569,
1046,
12,
267,
8685,
5345,
26,
378,
16569,
975,
12,
267,
841,
3273,
26,
378,
16569,
1196,
272,
789,
199,
199,
4164,
20819,
508,
283,
16680,
356,
755,
327,
23941,
15,
2676,
708,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
957,
5,
68,
7,
450,
334,
719,
435,
413,
9,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
746,
1722,
480,
1509,
651,
2793,
1133,
5715,
4212,
370,
2429,
2222,
4465,
19325,
1181,
6634,
641,
642,
4298,
531,
339,
19325,
27112,
63,
5559,
275,
1052,
199,
199,
4164,
20819,
508,
283,
1490,
15746,
19,
356,
259,
327,
6289,
334,
16391,
9,
339,
347,
2243,
8,
719,
304,
267,
372,
1994,
2374,
15,
4707,
80,
5,
68,
7,
450,
1844,
339,
347,
663,
63,
6664,
63,
2470,
27112,
8,
719,
12,
19325,
27112,
304,
267,
746,
1722,
480,
1509,
651,
2793,
1133,
5715,
4212,
370,
2429,
2222,
4465,
19325,
1181,
6634,
641,
642,
4298,
531,
339,
19325,
27112,
63,
5559,
275,
1052,
199,
199,
4164,
20819,
1491,
19,
61,
508,
283,
15746,
7,
503,
221,
971,
1362,
20819,
1491,
23,
61,
508,
283,
29629,
7,
503,
971,
1362,
20819,
1491,
23,
61,
508,
283,
1490,
15746,
356,
221,
327,
6289,
334,
16391,
367,
2867,
15746,
20,
26,
286,
10091,
5,
68,
9,
339,
347,
2243,
8,
719,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
thomasgilgenast/spqr-nonrel
|
django/core/management/__init__.py
|
152
|
17415
|
import os
import sys
from optparse import OptionParser, NO_DEFAULT
import imp
import django
from django.core.management.base import BaseCommand, CommandError, handle_default_options
from django.utils.importlib import import_module
# For backwards compatibility: get_version() used to be in this module.
get_version = django.get_version
# A cache of loaded commands, so that call_command
# doesn't have to reload every time it's called.
_commands = None
def find_commands(management_dir):
"""
Given a path to a management directory, returns a list of all the command
names that are available.
Returns an empty list if no commands are defined.
"""
command_dir = os.path.join(management_dir, 'commands')
try:
return [f[:-3] for f in os.listdir(command_dir)
if not f.startswith('_') and f.endswith('.py')]
except OSError:
return []
def find_management_module(app_name):
"""
Determines the path to the management module for the given app_name,
without actually importing the application or the management module.
Raises ImportError if the management module cannot be found for any reason.
"""
parts = app_name.split('.')
parts.append('management')
parts.reverse()
part = parts.pop()
path = None
# When using manage.py, the project module is added to the path,
# loaded, then removed from the path. This means that
# testproject.testapp.models can be loaded in future, even if
# testproject isn't in the path. When looking for the management
# module, we need look for the case where the project name is part
# of the app_name but the project directory itself isn't on the path.
try:
f, path, descr = imp.find_module(part,path)
except ImportError,e:
if os.path.basename(os.getcwd()) != part:
raise e
while parts:
part = parts.pop()
f, path, descr = imp.find_module(part, path and [path] or None)
return path
def load_command_class(app_name, name):
"""
Given a command name and an application name, returns the Command
class instance. All errors raised by the import process
(ImportError, AttributeError) are allowed to propagate.
"""
module = import_module('%s.management.commands.%s' % (app_name, name))
return module.Command()
def get_commands():
"""
Returns a dictionary mapping command names to their callback applications.
This works by looking for a management.commands package in django.core, and
in each installed application -- if a commands package exists, all commands
in that package are registered.
Core commands are always included. If a settings module has been
specified, user-defined commands will also be included, the
startproject command will be disabled, and the startapp command
will be modified to use the directory in which the settings module appears.
The dictionary is in the format {command_name: app_name}. Key-value
pairs from this dictionary can then be used in calls to
load_command_class(app_name, command_name)
If a specific version of a command must be loaded (e.g., with the
startapp command), the instantiated module can be placed in the
dictionary in place of the application name.
The dictionary is cached on the first call and reused on subsequent
calls.
"""
global _commands
if _commands is None:
_commands = dict([(name, 'django.core') for name in find_commands(__path__[0])])
# Find the installed apps
try:
from django.conf import settings
apps = settings.INSTALLED_APPS
except (AttributeError, EnvironmentError, ImportError):
apps = []
# Find the project directory
try:
from django.conf import settings
module = import_module(settings.SETTINGS_MODULE)
project_directory = setup_environ(module, settings.SETTINGS_MODULE)
except (AttributeError, EnvironmentError, ImportError, KeyError):
project_directory = None
# Find and load the management module for each installed app.
for app_name in apps:
try:
path = find_management_module(app_name)
_commands.update(dict([(name, app_name)
for name in find_commands(path)]))
except ImportError:
pass # No management module - ignore this app
if project_directory:
# Remove the "startproject" command from self.commands, because
# that's a django-admin.py command, not a manage.py command.
del _commands['startproject']
# Override the startapp command so that it always uses the
# project_directory, not the current working directory
# (which is default).
from django.core.management.commands.startapp import ProjectCommand
_commands['startapp'] = ProjectCommand(project_directory)
return _commands
def call_command(name, *args, **options):
"""
Calls the given command, with the given options and args/kwargs.
This is the primary API you should use for calling specific commands.
Some examples:
call_command('syncdb')
call_command('shell', plain=True)
call_command('sqlall', 'myapp')
"""
# Load the command object.
try:
app_name = get_commands()[name]
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
klass = app_name
else:
klass = load_command_class(app_name, name)
except KeyError:
raise CommandError("Unknown command: %r" % name)
# Grab out a list of defaults from the options. optparse does this for us
# when the script runs from the command line, but since call_command can
# be called programatically, we need to simulate the loading and handling
# of defaults (see #10080 for details).
defaults = dict([(o.dest, o.default)
for o in klass.option_list
if o.default is not NO_DEFAULT])
defaults.update(options)
return klass.execute(*args, **defaults)
class LaxOptionParser(OptionParser):
"""
An option parser that doesn't raise any errors on unknown options.
This is needed because the --settings and --pythonpath options affect
the commands (and thus the options) that are available to the user.
"""
def error(self, msg):
pass
def print_help(self):
"""Output nothing.
The lax options are included in the normal option parser, so under
normal usage, we don't need to print the lax options.
"""
pass
def print_lax_help(self):
"""Output the basic options available to every command.
This just redirects to the default print_help() behaviour.
"""
OptionParser.print_help(self)
def _process_args(self, largs, rargs, values):
"""
Overrides OptionParser._process_args to exclusively handle default
options and ignore args and other options.
This overrides the behavior of the super class, which stop parsing
at the first unrecognized option.
"""
while rargs:
arg = rargs[0]
try:
if arg[0:2] == "--" and len(arg) > 2:
# process a single long option (possibly with value(s))
# the superclass code pops the arg off rargs
self._process_long_opt(rargs, values)
elif arg[:1] == "-" and len(arg) > 1:
# process a cluster of short options (possibly with
# value(s) for the last one only)
# the superclass code pops the arg off rargs
self._process_short_opts(rargs, values)
else:
# it's either a non-default option or an arg
# either way, add it to the args list so we can keep
# dealing with options
del rargs[0]
raise Exception
except:
largs.append(arg)
class ManagementUtility(object):
"""
Encapsulates the logic of the django-admin.py and manage.py utilities.
A ManagementUtility has a number of commands, which can be manipulated
by editing the self.commands dictionary.
"""
def __init__(self, argv=None):
self.argv = argv or sys.argv[:]
self.prog_name = os.path.basename(self.argv[0])
def main_help_text(self):
"""
Returns the script's main help text, as a string.
"""
usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,'']
usage.append('Available subcommands:')
commands = get_commands().keys()
commands.sort()
for cmd in commands:
usage.append(' %s' % cmd)
return '\n'.join(usage)
def fetch_command(self, subcommand):
"""
Tries to fetch the given subcommand, printing a message with the
appropriate command called from the command line (usually
"django-admin.py" or "manage.py") if it can't be found.
"""
try:
app_name = get_commands()[subcommand]
except KeyError:
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % \
(subcommand, self.prog_name))
sys.exit(1)
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
klass = app_name
else:
klass = load_command_class(app_name, subcommand)
return klass
def autocomplete(self):
"""
Output completion suggestions for BASH.
The output of this function is passed to BASH's `COMREPLY` variable and
treated as completion suggestions. `COMREPLY` expects a space
separated string as the result.
The `COMP_WORDS` and `COMP_CWORD` BASH environment variables are used
to get information about the cli input. Please refer to the BASH
man-page for more information about this variables.
Subcommand options are saved as pairs. A pair consists of
the long option string (e.g. '--exclude') and a boolean
value indicating if the option requires arguments. When printing to
stdout, a equal sign is appended to options which require arguments.
Note: If debugging this function, it is recommended to write the debug
output in a separate file. Otherwise the debug output will be treated
and formatted as potential completion suggestions.
"""
# Don't complete if user hasn't sourced bash_completion file.
if not os.environ.has_key('DJANGO_AUTO_COMPLETE'):
return
cwords = os.environ['COMP_WORDS'].split()[1:]
cword = int(os.environ['COMP_CWORD'])
try:
curr = cwords[cword-1]
except IndexError:
curr = ''
subcommands = get_commands().keys() + ['help']
options = [('--help', None)]
# subcommand
if cword == 1:
print ' '.join(sorted(filter(lambda x: x.startswith(curr), subcommands)))
# subcommand options
# special case: the 'help' subcommand has no options
elif cwords[0] in subcommands and cwords[0] != 'help':
subcommand_cls = self.fetch_command(cwords[0])
# special case: 'runfcgi' stores additional options as
# 'key=value' pairs
if cwords[0] == 'runfcgi':
from django.core.servers.fastcgi import FASTCGI_OPTIONS
options += [(k, 1) for k in FASTCGI_OPTIONS]
# special case: add the names of installed apps to options
elif cwords[0] in ('dumpdata', 'reset', 'sql', 'sqlall',
'sqlclear', 'sqlcustom', 'sqlindexes',
'sqlreset', 'sqlsequencereset', 'test'):
try:
from django.conf import settings
# Get the last part of the dotted path as the app name.
options += [(a.split('.')[-1], 0) for a in settings.INSTALLED_APPS]
except ImportError:
# Fail silently if DJANGO_SETTINGS_MODULE isn't set. The
# user will find out once they execute the command.
pass
options += [(s_opt.get_opt_string(), s_opt.nargs) for s_opt in
subcommand_cls.option_list]
# filter out previously specified options from available options
prev_opts = [x.split('=')[0] for x in cwords[1:cword-1]]
options = filter(lambda (x, v): x not in prev_opts, options)
# filter options by current input
options = sorted([(k, v) for k, v in options if k.startswith(curr)])
for option in options:
opt_label = option[0]
# append '=' to options which require args
if option[1]:
opt_label += '='
print opt_label
sys.exit(1)
def execute(self):
"""
Given the command-line arguments, this figures out which subcommand is
being run, creates a parser appropriate to that command, and runs it.
"""
# Preprocess options to extract --settings and --pythonpath.
# These options could affect the commands that are available, so they
# must be processed early.
parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
version=get_version(),
option_list=BaseCommand.option_list)
self.autocomplete()
try:
options, args = parser.parse_args(self.argv)
handle_default_options(options)
except:
pass # Ignore any option errors at this point.
try:
subcommand = self.argv[1]
except IndexError:
subcommand = 'help' # Display help if no arguments were given.
if subcommand == 'help':
if len(args) > 2:
self.fetch_command(args[2]).print_help(self.prog_name, args[2])
else:
parser.print_lax_help()
sys.stderr.write(self.main_help_text() + '\n')
sys.exit(1)
# Special-cases: We want 'django-admin.py --version' and
# 'django-admin.py --help' to work, for backwards compatibility.
elif self.argv[1:] == ['--version']:
# LaxOptionParser already takes care of printing the version.
pass
elif self.argv[1:] in (['--help'], ['-h']):
parser.print_lax_help()
sys.stderr.write(self.main_help_text() + '\n')
else:
self.fetch_command(subcommand).run_from_argv(self.argv)
def setup_environ(settings_mod, original_settings_path=None):
"""
Configures the runtime environment. This can also be used by external
scripts wanting to set up a similar environment to manage.py.
Returns the project directory (assuming the passed settings module is
directly in the project directory).
The "original_settings_path" parameter is optional, but recommended, since
trying to work out the original path from the module can be problematic.
"""
# Add this project to sys.path so that it's importable in the conventional
# way. For example, if this file (manage.py) lives in a directory
# "myproject", this code would add "/path/to/myproject" to sys.path.
if '__init__.py' in settings_mod.__file__:
p = os.path.dirname(settings_mod.__file__)
else:
p = settings_mod.__file__
project_directory, settings_filename = os.path.split(p)
if project_directory == os.curdir or not project_directory:
project_directory = os.getcwd()
project_name = os.path.basename(project_directory)
# Strip filename suffix to get the module name.
settings_name = os.path.splitext(settings_filename)[0]
# Strip $py for Jython compiled files (like settings$py.class)
if settings_name.endswith("$py"):
settings_name = settings_name[:-3]
# Set DJANGO_SETTINGS_MODULE appropriately.
if original_settings_path:
os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
else:
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
# Import the project module. We add the parent directory to PYTHONPATH to
# avoid some of the path errors new users can have.
sys.path.append(os.path.join(project_directory, os.pardir))
project_module = import_module(project_name)
sys.path.pop()
return project_directory
def execute_from_command_line(argv=None):
"""
A simple method that runs a ManagementUtility.
"""
utility = ManagementUtility(argv)
utility.execute()
def execute_manager(settings_mod, argv=None):
"""
Like execute_from_command_line(), but for use by manage.py, a
project-specific django-admin.py utility.
"""
setup_environ(settings_mod)
utility = ManagementUtility(argv)
utility.execute()
|
bsd-3-clause
|
[
646,
747,
199,
646,
984,
199,
504,
8691,
492,
13491,
12,
4825,
63,
3472,
199,
646,
1742,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
12,
2429,
63,
885,
63,
1419,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
199,
3,
2104,
8552,
7163,
26,
664,
63,
1023,
342,
1202,
370,
506,
315,
642,
859,
14,
199,
362,
63,
1023,
275,
1639,
14,
362,
63,
1023,
199,
199,
3,
437,
2581,
402,
6511,
3718,
12,
880,
626,
1240,
63,
1531,
199,
3,
3181,
1133,
1172,
370,
13101,
4036,
900,
652,
1159,
2797,
14,
199,
63,
4405,
275,
488,
199,
199,
318,
2342,
63,
4405,
8,
8110,
63,
694,
304,
272,
408,
272,
9138,
282,
931,
370,
282,
10041,
2082,
12,
2529,
282,
769,
402,
1006,
314,
1414,
272,
1561,
626,
787,
2808,
14,
339,
1803,
376,
2701,
769,
340,
949,
3718,
787,
3247,
14,
272,
408,
272,
1414,
63,
694,
275,
747,
14,
515,
14,
904,
8,
8110,
63,
694,
12,
283,
4405,
358,
272,
862,
26,
267,
372,
359,
70,
4439,
19,
61,
367,
289,
315,
747,
14,
7374,
8,
1531,
63,
694,
9,
355,
340,
440,
289,
14,
2460,
26341,
436,
289,
14,
4130,
5175,
647,
5440,
272,
871,
6440,
26,
267,
372,
942,
199,
199,
318,
2342,
63,
8110,
63,
578,
8,
571,
63,
354,
304,
272,
408,
272,
22391,
314,
931,
370,
314,
10041,
859,
367,
314,
1627,
1145,
63,
354,
12,
272,
1928,
5965,
16306,
314,
4223,
503,
314,
10041,
859,
14,
339,
6218,
3545,
340,
314,
10041,
859,
3913,
506,
1911,
367,
1263,
4499,
14,
272,
408,
272,
4184,
275,
1145,
63,
354,
14,
1294,
7563,
272,
4184,
14,
740,
360,
8110,
358,
272,
4184,
14,
4471,
342,
272,
1777,
275,
4184,
14,
1935,
342,
272,
931,
275,
488,
339,
327,
3979,
1808,
9635,
14,
647,
12,
314,
2199,
859,
365,
3483,
370,
314,
931,
12,
272,
327,
6511,
12,
2066,
4829,
687,
314,
931,
14,
961,
4910,
626,
272,
327,
511,
1715,
14,
19700,
14,
992,
883,
506,
6511,
315,
6466,
12,
2755,
340,
272,
327,
511,
1715,
5712,
1133,
315,
314,
931,
14,
3979,
10023,
367,
314,
10041,
272,
327,
859,
12,
781,
1929,
3648,
367,
314,
1930,
2382,
314,
2199,
536,
365,
1777,
272,
327,
402,
314,
1145,
63,
354,
1325,
314,
2199,
2082,
6337,
5712,
1133,
641,
314,
931,
14,
272,
862,
26,
267,
289,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
2064,
12,
515,
9,
272,
871,
3545,
12,
69,
26,
267,
340,
747,
14,
515,
14,
4846,
8,
736,
14,
9458,
1012,
1137,
1777,
26,
288,
746,
325,
339,
1830,
4184,
26,
267,
1777,
275,
4184,
14,
1935,
342,
267,
289,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
2064,
12,
931,
436,
359,
515,
61,
503,
488,
9,
272,
372,
931,
199,
199,
318,
2248,
63,
1531,
63,
533,
8,
571,
63,
354,
12,
536,
304,
272,
408,
272,
9138,
282,
1414,
536,
436,
376,
4223,
536,
12,
2529,
314,
5817,
272,
1021,
1256,
14,
2900,
2552,
4915,
701,
314,
492,
2112,
272,
334,
17825,
12,
4281,
9,
787,
4370,
370,
19843,
14,
272,
408,
272,
859,
275,
492,
63,
578,
3508,
83,
14,
8110,
14,
4405,
4111,
83,
7,
450,
334,
571,
63,
354,
12,
536,
430,
272,
372,
859,
14,
3110,
342,
199,
199,
318,
664,
63,
4405,
837,
272,
408,
272,
1803,
282,
2600,
4412,
1414,
1561,
370,
3932,
3233,
13103,
14,
339,
961,
5419,
701,
10023,
367,
282,
10041,
14,
4405,
2559,
315,
1639,
14,
1018,
12,
436,
272,
315,
1924,
4903,
4223,
1553,
340,
282,
3718,
2559,
3495,
12,
1006,
3718,
272,
315,
626,
2559,
787,
7264,
14,
339,
11672,
3718,
787,
3544,
5120,
14,
982,
282,
2202,
859,
965,
2757,
272,
2013,
12,
922,
13,
4037,
3718,
911,
2597,
506,
5120,
12,
314,
272,
1343,
1715,
1414,
911,
506,
6980,
12,
436,
314,
1343,
571,
1414,
272,
911,
506,
6042,
370,
675,
314,
2082,
315,
1314,
314,
2202,
859,
11337,
14,
339,
710,
2600,
365,
315,
314,
1475,
469,
1531,
63,
354,
26,
1145,
63,
354,
5565,
2606,
13,
585,
272,
6342,
687,
642,
2600,
883,
2066,
506,
1202,
315,
4882,
370,
272,
2248,
63,
1531,
63,
533,
8,
571,
63,
354,
12,
1414,
63,
354,
9,
339,
982,
282,
2488,
1015,
402,
282,
1414,
1471,
506,
6511,
334,
69,
14,
71,
2020,
543,
314,
272,
1343,
571,
1414,
395,
314,
17544,
859,
883,
506,
15090,
315,
314,
272,
2600,
315,
4192,
402,
314,
4223,
536,
14,
339,
710,
2600,
365,
6328,
641,
314,
1642,
1240,
436,
24826,
641,
13372,
272,
4882,
14,
272,
408,
272,
2288,
485,
4405,
272,
340,
485,
4405,
365,
488,
26,
267,
485,
4405,
275,
1211,
7694,
354,
12,
283,
1176,
14,
1018,
358,
367,
536,
315,
2342,
63,
4405,
3460,
515,
12298,
16,
24310,
398,
327,
6668,
314,
4903,
8686,
267,
862,
26,
288,
687,
1639,
14,
2190,
492,
2202,
288,
8686,
275,
2202,
14,
15942,
63,
14219,
267,
871,
334,
10227,
12,
25139,
12,
3545,
304,
288,
8686,
275,
942,
398,
327,
6668,
314,
2199,
2082,
267,
862,
26,
288,
687,
1639,
14,
2190,
492,
2202,
288,
859,
275,
492,
63,
578,
8,
1751,
14,
13931,
63,
10001,
9,
288,
2199,
63,
3619,
275,
3272,
63,
2314,
8,
578,
12,
2202,
14,
13931,
63,
10001,
9,
267,
871,
334,
10227,
12,
25139,
12,
3545,
12,
4067,
304,
288,
2199,
63,
3619,
275,
488,
398,
327,
6668,
436,
2248,
314,
10041,
859,
367,
1924,
4903,
1145,
14,
267,
367,
1145,
63,
354,
315,
8686,
26,
288,
862,
26,
355,
931,
275,
2342,
63,
8110,
63,
578,
8,
571,
63,
354,
9,
355,
485,
4405,
14,
873,
8,
807,
7694,
354,
12,
1145,
63,
354,
9,
4318,
367,
536,
315,
2342,
63,
4405,
8,
515,
19563,
288,
871,
3545,
26,
355,
986,
327,
3091,
10041,
859,
446,
3686,
642,
1145,
398,
340,
2199,
63,
3619,
26,
288,
327,
5852,
314,
298,
928,
1715,
2,
1414,
687,
291,
14,
4405,
12,
2952,
288,
327,
626,
1159,
282,
1639,
13,
2113,
14
] |
[
747,
199,
646,
984,
199,
504,
8691,
492,
13491,
12,
4825,
63,
3472,
199,
646,
1742,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
12,
2429,
63,
885,
63,
1419,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
199,
199,
3,
2104,
8552,
7163,
26,
664,
63,
1023,
342,
1202,
370,
506,
315,
642,
859,
14,
199,
362,
63,
1023,
275,
1639,
14,
362,
63,
1023,
199,
199,
3,
437,
2581,
402,
6511,
3718,
12,
880,
626,
1240,
63,
1531,
199,
3,
3181,
1133,
1172,
370,
13101,
4036,
900,
652,
1159,
2797,
14,
199,
63,
4405,
275,
488,
199,
199,
318,
2342,
63,
4405,
8,
8110,
63,
694,
304,
272,
408,
272,
9138,
282,
931,
370,
282,
10041,
2082,
12,
2529,
282,
769,
402,
1006,
314,
1414,
272,
1561,
626,
787,
2808,
14,
339,
1803,
376,
2701,
769,
340,
949,
3718,
787,
3247,
14,
272,
408,
272,
1414,
63,
694,
275,
747,
14,
515,
14,
904,
8,
8110,
63,
694,
12,
283,
4405,
358,
272,
862,
26,
267,
372,
359,
70,
4439,
19,
61,
367,
289,
315,
747,
14,
7374,
8,
1531,
63,
694,
9,
355,
340,
440,
289,
14,
2460,
26341,
436,
289,
14,
4130,
5175,
647,
5440,
272,
871,
6440,
26,
267,
372,
942,
199,
199,
318,
2342,
63,
8110,
63,
578,
8,
571,
63,
354,
304,
272,
408,
272,
22391,
314,
931,
370,
314,
10041,
859,
367,
314,
1627,
1145,
63,
354,
12,
272,
1928,
5965,
16306,
314,
4223,
503,
314,
10041,
859,
14,
339,
6218,
3545,
340,
314,
10041,
859,
3913,
506,
1911,
367,
1263,
4499,
14,
272,
408,
272,
4184,
275,
1145,
63,
354,
14,
1294,
7563,
272,
4184,
14,
740,
360,
8110,
358,
272,
4184,
14,
4471,
342,
272,
1777,
275,
4184,
14,
1935,
342,
272,
931,
275,
488,
339,
327,
3979,
1808,
9635,
14,
647,
12,
314,
2199,
859,
365,
3483,
370,
314,
931,
12,
272,
327,
6511,
12,
2066,
4829,
687,
314,
931,
14,
961,
4910,
626,
272,
327,
511,
1715,
14,
19700,
14,
992,
883,
506,
6511,
315,
6466,
12,
2755,
340,
272,
327,
511,
1715,
5712,
1133,
315,
314,
931,
14,
3979,
10023,
367,
314,
10041,
272,
327,
859,
12,
781,
1929,
3648,
367,
314,
1930,
2382,
314,
2199,
536,
365,
1777,
272,
327,
402,
314,
1145,
63,
354,
1325,
314,
2199,
2082,
6337,
5712,
1133,
641,
314,
931,
14,
272,
862,
26,
267,
289,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
2064,
12,
515,
9,
272,
871,
3545,
12,
69,
26,
267,
340,
747,
14,
515,
14,
4846,
8,
736,
14,
9458,
1012,
1137,
1777,
26,
288,
746,
325,
339,
1830,
4184,
26,
267,
1777,
275,
4184,
14,
1935,
342,
267,
289,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
2064,
12,
931,
436,
359,
515,
61,
503,
488,
9,
272,
372,
931,
199,
199,
318,
2248,
63,
1531,
63,
533,
8,
571,
63,
354,
12,
536,
304,
272,
408,
272,
9138,
282,
1414,
536,
436,
376,
4223,
536,
12,
2529,
314,
5817,
272,
1021,
1256,
14,
2900,
2552,
4915,
701,
314,
492,
2112,
272,
334,
17825,
12,
4281,
9,
787,
4370,
370,
19843,
14,
272,
408,
272,
859,
275,
492,
63,
578,
3508,
83,
14,
8110,
14,
4405,
4111,
83,
7,
450,
334,
571,
63,
354,
12,
536,
430,
272,
372,
859,
14,
3110,
342,
199,
199,
318,
664,
63,
4405,
837,
272,
408,
272,
1803,
282,
2600,
4412,
1414,
1561,
370,
3932,
3233,
13103,
14,
339,
961,
5419,
701,
10023,
367,
282,
10041,
14,
4405,
2559,
315,
1639,
14,
1018,
12,
436,
272,
315,
1924,
4903,
4223,
1553,
340,
282,
3718,
2559,
3495,
12,
1006,
3718,
272,
315,
626,
2559,
787,
7264,
14,
339,
11672,
3718,
787,
3544,
5120,
14,
982,
282,
2202,
859,
965,
2757,
272,
2013,
12,
922,
13,
4037,
3718,
911,
2597,
506,
5120,
12,
314,
272,
1343,
1715,
1414,
911,
506,
6980,
12,
436,
314,
1343,
571,
1414,
272,
911,
506,
6042,
370,
675,
314,
2082,
315,
1314,
314,
2202,
859,
11337,
14,
339,
710,
2600,
365,
315,
314,
1475,
469,
1531,
63,
354,
26,
1145,
63,
354,
5565,
2606,
13,
585,
272,
6342,
687,
642,
2600,
883,
2066,
506,
1202,
315,
4882,
370,
272,
2248,
63,
1531,
63,
533,
8,
571,
63,
354,
12,
1414,
63,
354,
9,
339,
982,
282,
2488,
1015,
402,
282,
1414,
1471,
506,
6511,
334,
69,
14,
71,
2020,
543,
314,
272,
1343,
571,
1414,
395,
314,
17544,
859,
883,
506,
15090,
315,
314,
272,
2600,
315,
4192,
402,
314,
4223,
536,
14,
339,
710,
2600,
365,
6328,
641,
314,
1642,
1240,
436,
24826,
641,
13372,
272,
4882,
14,
272,
408,
272,
2288,
485,
4405,
272,
340,
485,
4405,
365,
488,
26,
267,
485,
4405,
275,
1211,
7694,
354,
12,
283,
1176,
14,
1018,
358,
367,
536,
315,
2342,
63,
4405,
3460,
515,
12298,
16,
24310,
398,
327,
6668,
314,
4903,
8686,
267,
862,
26,
288,
687,
1639,
14,
2190,
492,
2202,
288,
8686,
275,
2202,
14,
15942,
63,
14219,
267,
871,
334,
10227,
12,
25139,
12,
3545,
304,
288,
8686,
275,
942,
398,
327,
6668,
314,
2199,
2082,
267,
862,
26,
288,
687,
1639,
14,
2190,
492,
2202,
288,
859,
275,
492,
63,
578,
8,
1751,
14,
13931,
63,
10001,
9,
288,
2199,
63,
3619,
275,
3272,
63,
2314,
8,
578,
12,
2202,
14,
13931,
63,
10001,
9,
267,
871,
334,
10227,
12,
25139,
12,
3545,
12,
4067,
304,
288,
2199,
63,
3619,
275,
488,
398,
327,
6668,
436,
2248,
314,
10041,
859,
367,
1924,
4903,
1145,
14,
267,
367,
1145,
63,
354,
315,
8686,
26,
288,
862,
26,
355,
931,
275,
2342,
63,
8110,
63,
578,
8,
571,
63,
354,
9,
355,
485,
4405,
14,
873,
8,
807,
7694,
354,
12,
1145,
63,
354,
9,
4318,
367,
536,
315,
2342,
63,
4405,
8,
515,
19563,
288,
871,
3545,
26,
355,
986,
327,
3091,
10041,
859,
446,
3686,
642,
1145,
398,
340,
2199,
63,
3619,
26,
288,
327,
5852,
314,
298,
928,
1715,
2,
1414,
687,
291,
14,
4405,
12,
2952,
288,
327,
626,
1159,
282,
1639,
13,
2113,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
onshape-public/onshape-clients
|
python/onshape_client/oas/models/bt_string_format_match_pattern2446.py
|
1
|
7539
|
# coding: utf-8
"""
Onshape REST API
The Onshape REST API consumed by all clients. # noqa: E501
The version of the OpenAPI document: 1.113
Contact: api-support@onshape.zendesk.com
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import re # noqa: F401
import sys # noqa: F401
import six # noqa: F401
import nulltype # noqa: F401
from onshape_client.oas.model_utils import ( # noqa: F401
ModelComposed,
ModelNormal,
ModelSimple,
date,
datetime,
file_type,
int,
none_type,
str,
validate_get_composed_info,
)
try:
from onshape_client.oas.models import bt_string_format_condition683
except ImportError:
bt_string_format_condition683 = sys.modules[
"onshape_client.oas.models.bt_string_format_condition683"
]
try:
from onshape_client.oas.models import bt_string_format_match_pattern2446_all_of
except ImportError:
bt_string_format_match_pattern2446_all_of = sys.modules[
"onshape_client.oas.models.bt_string_format_match_pattern2446_all_of"
]
class BTStringFormatMatchPattern2446(ModelComposed):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
Attributes:
allowed_values (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
with a capitalized key describing the allowed value and an allowed
value. These dicts store the allowed enum values.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
discriminator_value_class_map (dict): A dict to go from the discriminator
variable value to the discriminator class name.
validations (dict): The key is the tuple path to the attribute
and the for var_name this is (var_name,). The value is a dict
that stores validations for max_length, min_length, max_items,
min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum,
inclusive_minimum, and regex.
additional_properties_type (tuple): A tuple of classes accepted
as additional properties values.
"""
allowed_values = {}
validations = {}
additional_properties_type = None
@staticmethod
def openapi_types():
"""
This must be a class method so a model may have properties that are
of type self, this ensures that we don't create a cyclic import
Returns
openapi_types (dict): The key is attribute name
and the value is attribute type.
"""
return {
"bt_type": (str,), # noqa: E501
"reg_exp_to_match": (str,), # noqa: E501
"error_message": (str,), # noqa: E501
"should_reset_value_when_confirmed": (bool,), # noqa: E501
}
@staticmethod
def discriminator():
return None
attribute_map = {
"bt_type": "btType", # noqa: E501
"reg_exp_to_match": "regExpToMatch", # noqa: E501
"error_message": "errorMessage", # noqa: E501
"should_reset_value_when_confirmed": "shouldResetValueWhenConfirmed", # noqa: E501
}
required_properties = set(
[
"_data_store",
"_check_type",
"_from_server",
"_path_to_item",
"_configuration",
"_composed_instances",
"_var_name_to_model_instances",
"_additional_properties_model_instances",
]
)
def __init__(
self,
_check_type=True,
_from_server=False,
_path_to_item=(),
_configuration=None,
**kwargs
): # noqa: E501
"""bt_string_format_match_pattern2446.BTStringFormatMatchPattern2446 - a model defined in OpenAPI
Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
raised if the wrong type is input.
Defaults to True
_path_to_item (tuple/list): This is a list of keys or values to
drill down to the model in received_data
when deserializing a response
_from_server (bool): True if the data is from the server
False if the data is from the client (default)
_configuration (Configuration): the instance to use when
deserializing a file_type parameter.
If passed, type conversion is attempted
If omitted no type conversion is done.
bt_type (str): [optional] # noqa: E501
reg_exp_to_match (str): [optional] # noqa: E501
error_message (str): [optional] # noqa: E501
should_reset_value_when_confirmed (bool): [optional] # noqa: E501
"""
self._data_store = {}
self._check_type = _check_type
self._from_server = _from_server
self._path_to_item = _path_to_item
self._configuration = _configuration
constant_args = {
"_check_type": _check_type,
"_path_to_item": _path_to_item,
"_from_server": _from_server,
"_configuration": _configuration,
}
required_args = {}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
composed_info = validate_get_composed_info(constant_args, model_args, self)
self._composed_instances = composed_info[0]
self._var_name_to_model_instances = composed_info[1]
self._additional_properties_model_instances = composed_info[2]
unused_args = composed_info[3]
for var_name, var_value in required_args.items():
setattr(self, var_name, var_value)
for var_name, var_value in six.iteritems(kwargs):
if (
var_name in unused_args
and self._configuration is not None
and self._configuration.discard_unknown_keys
and not self._additional_properties_model_instances
):
# discard variable.
continue
setattr(self, var_name, var_value)
@staticmethod
def _composed_schemas():
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
# when we invoke this method. If we kept this at the class
# level we would get an error beause the class level
# code would be run when this module is imported, and these composed
# classes don't exist yet because their module has not finished
# loading
return {
"anyOf": [],
"allOf": [
bt_string_format_condition683.BTStringFormatCondition683,
bt_string_format_match_pattern2446_all_of.BTStringFormatMatchPattern2446AllOf,
],
"oneOf": [],
}
|
mit
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
593,
561,
15221,
14880,
3261,
339,
710,
593,
561,
15221,
14880,
3261,
16949,
701,
1006,
13431,
14,
221,
327,
8151,
26,
662,
8216,
339,
710,
1015,
402,
314,
3232,
3735,
2213,
26,
413,
14,
9225,
272,
18684,
26,
2986,
13,
4058,
32,
265,
1392,
14,
5193,
10368,
14,
957,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
295,
221,
327,
8151,
26,
481,
8854,
199,
646,
984,
221,
327,
8151,
26,
481,
8854,
199,
199,
646,
3816,
221,
327,
8151,
26,
481,
8854,
199,
646,
2973,
466,
221,
327,
8151,
26,
481,
8854,
199,
199,
504,
641,
1392,
63,
1258,
14,
79,
305,
14,
1238,
63,
1208,
492,
334,
221,
327,
8151,
26,
481,
8854,
272,
5822,
16273,
939,
12,
272,
5822,
6241,
12,
272,
5822,
3184,
12,
272,
1434,
12,
272,
2197,
12,
272,
570,
63,
466,
12,
272,
1109,
12,
272,
7179,
63,
466,
12,
272,
620,
12,
272,
4107,
63,
362,
63,
7784,
939,
63,
815,
12,
199,
9,
199,
199,
893,
26,
272,
687,
641,
1392,
63,
1258,
14,
79,
305,
14,
992,
492,
22342,
63,
875,
63,
908,
63,
5394,
25689,
199,
2590,
3545,
26,
272,
22342,
63,
875,
63,
908,
63,
5394,
25689,
275,
984,
14,
3112,
59,
267,
298,
265,
1392,
63,
1258,
14,
79,
305,
14,
992,
14,
13061,
63,
875,
63,
908,
63,
5394,
25689,
2,
272,
1622,
199,
893,
26,
272,
687,
641,
1392,
63,
1258,
14,
79,
305,
14,
992,
492,
22342,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
199,
2590,
3545,
26,
272,
22342,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
275,
984,
14,
3112,
59,
267,
298,
265,
1392,
63,
1258,
14,
79,
305,
14,
992,
14,
13061,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
2,
272,
1622,
421,
199,
533,
699,
52,
1558,
3484,
4486,
9959,
1194,
2466,
8,
1685,
16273,
939,
304,
272,
408,
19855,
26,
961,
1021,
365,
2599,
4046,
701,
3232,
3735,
15042,
14,
272,
15397,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
339,
4226,
440,
5283,
314,
1021,
10250,
14,
339,
9382,
26,
489,
4370,
63,
1459,
334,
807,
304,
710,
790,
365,
314,
2008,
931,
370,
314,
2225,
881,
436,
314,
367,
2729,
63,
354,
642,
365,
334,
1391,
63,
354,
12,
680,
710,
574,
365,
282,
1211,
881,
543,
282,
17094,
1759,
790,
13660,
314,
4370,
574,
436,
376,
4370,
881,
574,
14,
5723,
10809,
3877,
314,
4370,
4952,
1338,
14,
489,
2225,
63,
1130,
334,
807,
304,
710,
790,
365,
2225,
536,
881,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
489,
487,
24565,
63,
585,
63,
533,
63,
1130,
334,
807,
304,
437,
1211,
370,
2621,
687,
314,
487,
24565,
881,
1750,
574,
370,
314,
487,
24565,
1021,
536,
14,
489,
1686,
1298,
334,
807,
304,
710,
790,
365,
314,
2008,
931,
370,
314,
2225,
881,
436,
314,
367,
2729,
63,
354,
642,
365,
334,
1391,
63,
354,
12,
680,
710,
574,
365,
282,
1211,
881,
626,
14086,
1686,
1298,
367,
1390,
63,
1267,
12,
1748,
63,
1267,
12,
1390,
63,
1744,
12,
881,
1748,
63,
1744,
12,
13914,
63,
11555,
12,
20728,
63,
11555,
12,
13914,
63,
10700,
12,
881,
20728,
63,
10700,
12,
436,
5163,
14,
489,
4722,
63,
3282,
63,
466,
334,
2960,
304,
437,
2008,
402,
3992,
10226,
881,
465,
4722,
4382,
1338,
14,
272,
408,
339,
4370,
63,
1459,
275,
1052,
339,
1686,
1298,
275,
1052,
339,
4722,
63,
3282,
63,
466,
275,
488,
339,
768,
4639,
272,
347,
1551,
1246,
63,
1313,
837,
267,
408,
267,
961,
1471,
506,
282,
1021,
1083,
880,
282,
1402,
1443,
1172,
4382,
626,
787,
267,
402,
730,
291,
12,
642,
15620,
626,
781,
2793,
1133,
1218,
282,
32637,
492,
398,
1803,
288,
1551,
1246,
63,
1313,
334,
807,
304,
710,
790,
365,
2225,
536,
355,
436,
314,
574,
365,
2225,
730,
14,
267,
408,
267,
372,
469,
288,
298,
13061,
63,
466,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
1135,
63,
1474,
63,
475,
63,
1431,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
705,
63,
1188,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
5626,
63,
3958,
63,
585,
63,
6526,
63,
16391,
582,
334,
2245,
4706,
221,
327,
8151,
26,
662,
8216,
267,
789,
339,
768,
4639,
272,
347,
487,
24565,
837,
267,
372,
488,
339,
2225,
63,
1130,
275,
469,
267,
298,
13061,
63,
466,
582,
298,
13061,
804,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
1135,
63,
1474,
63,
475,
63,
1431,
582,
298,
1135,
4527,
1378,
4486,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
705,
63,
1188,
582,
298,
705,
2209,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
5626,
63,
3958,
63,
585,
63,
6526,
63,
16391,
582,
298,
5626,
9637,
1110,
11423,
714,
11451,
401,
221,
327,
8151,
26,
662,
8216,
272,
789,
339,
1415,
63,
3282,
275,
663,
8,
267,
359,
288,
2668,
576,
63,
1617,
401,
288,
2668,
1074,
63,
466,
401,
288,
2668,
504,
63,
1000,
401,
288,
2668,
515,
63,
475,
63,
1053,
401,
288,
2668,
4758,
401,
288,
2668,
7784,
939,
63,
5990,
401,
288,
2668,
1391,
63,
354,
63,
475,
63,
1238,
63,
5990,
401,
288,
2668,
8460,
63,
3282,
63,
1238,
63,
5990,
401,
267,
1622,
272,
776,
339,
347,
636,
826,
721,
267,
291,
12,
267,
485,
1074,
63,
466,
29,
549,
12,
267,
485,
504,
63,
1000,
29,
797,
12,
267,
485,
515,
63,
475,
63,
1053,
16729,
267,
485,
4758,
29,
403,
12,
267,
1011,
958,
272,
3461,
221,
327,
8151,
26,
662,
8216,
267,
408,
13061,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
14,
19162,
1558,
3484,
4486,
9959,
1194,
2466,
446,
282,
1402,
3247,
315,
3232,
3735,
398,
6431,
3033,
26,
288,
485,
1074,
63,
466,
334,
2245
] |
[
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
593,
561,
15221,
14880,
3261,
339,
710,
593,
561,
15221,
14880,
3261,
16949,
701,
1006,
13431,
14,
221,
327,
8151,
26,
662,
8216,
339,
710,
1015,
402,
314,
3232,
3735,
2213,
26,
413,
14,
9225,
272,
18684,
26,
2986,
13,
4058,
32,
265,
1392,
14,
5193,
10368,
14,
957,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
295,
221,
327,
8151,
26,
481,
8854,
199,
646,
984,
221,
327,
8151,
26,
481,
8854,
199,
199,
646,
3816,
221,
327,
8151,
26,
481,
8854,
199,
646,
2973,
466,
221,
327,
8151,
26,
481,
8854,
199,
199,
504,
641,
1392,
63,
1258,
14,
79,
305,
14,
1238,
63,
1208,
492,
334,
221,
327,
8151,
26,
481,
8854,
272,
5822,
16273,
939,
12,
272,
5822,
6241,
12,
272,
5822,
3184,
12,
272,
1434,
12,
272,
2197,
12,
272,
570,
63,
466,
12,
272,
1109,
12,
272,
7179,
63,
466,
12,
272,
620,
12,
272,
4107,
63,
362,
63,
7784,
939,
63,
815,
12,
199,
9,
199,
199,
893,
26,
272,
687,
641,
1392,
63,
1258,
14,
79,
305,
14,
992,
492,
22342,
63,
875,
63,
908,
63,
5394,
25689,
199,
2590,
3545,
26,
272,
22342,
63,
875,
63,
908,
63,
5394,
25689,
275,
984,
14,
3112,
59,
267,
298,
265,
1392,
63,
1258,
14,
79,
305,
14,
992,
14,
13061,
63,
875,
63,
908,
63,
5394,
25689,
2,
272,
1622,
199,
893,
26,
272,
687,
641,
1392,
63,
1258,
14,
79,
305,
14,
992,
492,
22342,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
199,
2590,
3545,
26,
272,
22342,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
275,
984,
14,
3112,
59,
267,
298,
265,
1392,
63,
1258,
14,
79,
305,
14,
992,
14,
13061,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
63,
452,
63,
1618,
2,
272,
1622,
421,
199,
533,
699,
52,
1558,
3484,
4486,
9959,
1194,
2466,
8,
1685,
16273,
939,
304,
272,
408,
19855,
26,
961,
1021,
365,
2599,
4046,
701,
3232,
3735,
15042,
14,
272,
15397,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
339,
4226,
440,
5283,
314,
1021,
10250,
14,
339,
9382,
26,
489,
4370,
63,
1459,
334,
807,
304,
710,
790,
365,
314,
2008,
931,
370,
314,
2225,
881,
436,
314,
367,
2729,
63,
354,
642,
365,
334,
1391,
63,
354,
12,
680,
710,
574,
365,
282,
1211,
881,
543,
282,
17094,
1759,
790,
13660,
314,
4370,
574,
436,
376,
4370,
881,
574,
14,
5723,
10809,
3877,
314,
4370,
4952,
1338,
14,
489,
2225,
63,
1130,
334,
807,
304,
710,
790,
365,
2225,
536,
881,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
489,
487,
24565,
63,
585,
63,
533,
63,
1130,
334,
807,
304,
437,
1211,
370,
2621,
687,
314,
487,
24565,
881,
1750,
574,
370,
314,
487,
24565,
1021,
536,
14,
489,
1686,
1298,
334,
807,
304,
710,
790,
365,
314,
2008,
931,
370,
314,
2225,
881,
436,
314,
367,
2729,
63,
354,
642,
365,
334,
1391,
63,
354,
12,
680,
710,
574,
365,
282,
1211,
881,
626,
14086,
1686,
1298,
367,
1390,
63,
1267,
12,
1748,
63,
1267,
12,
1390,
63,
1744,
12,
881,
1748,
63,
1744,
12,
13914,
63,
11555,
12,
20728,
63,
11555,
12,
13914,
63,
10700,
12,
881,
20728,
63,
10700,
12,
436,
5163,
14,
489,
4722,
63,
3282,
63,
466,
334,
2960,
304,
437,
2008,
402,
3992,
10226,
881,
465,
4722,
4382,
1338,
14,
272,
408,
339,
4370,
63,
1459,
275,
1052,
339,
1686,
1298,
275,
1052,
339,
4722,
63,
3282,
63,
466,
275,
488,
339,
768,
4639,
272,
347,
1551,
1246,
63,
1313,
837,
267,
408,
267,
961,
1471,
506,
282,
1021,
1083,
880,
282,
1402,
1443,
1172,
4382,
626,
787,
267,
402,
730,
291,
12,
642,
15620,
626,
781,
2793,
1133,
1218,
282,
32637,
492,
398,
1803,
288,
1551,
1246,
63,
1313,
334,
807,
304,
710,
790,
365,
2225,
536,
355,
436,
314,
574,
365,
2225,
730,
14,
267,
408,
267,
372,
469,
288,
298,
13061,
63,
466,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
1135,
63,
1474,
63,
475,
63,
1431,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
705,
63,
1188,
582,
334,
495,
4706,
221,
327,
8151,
26,
662,
8216,
288,
298,
5626,
63,
3958,
63,
585,
63,
6526,
63,
16391,
582,
334,
2245,
4706,
221,
327,
8151,
26,
662,
8216,
267,
789,
339,
768,
4639,
272,
347,
487,
24565,
837,
267,
372,
488,
339,
2225,
63,
1130,
275,
469,
267,
298,
13061,
63,
466,
582,
298,
13061,
804,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
1135,
63,
1474,
63,
475,
63,
1431,
582,
298,
1135,
4527,
1378,
4486,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
705,
63,
1188,
582,
298,
705,
2209,
401,
221,
327,
8151,
26,
662,
8216,
267,
298,
5626,
63,
3958,
63,
585,
63,
6526,
63,
16391,
582,
298,
5626,
9637,
1110,
11423,
714,
11451,
401,
221,
327,
8151,
26,
662,
8216,
272,
789,
339,
1415,
63,
3282,
275,
663,
8,
267,
359,
288,
2668,
576,
63,
1617,
401,
288,
2668,
1074,
63,
466,
401,
288,
2668,
504,
63,
1000,
401,
288,
2668,
515,
63,
475,
63,
1053,
401,
288,
2668,
4758,
401,
288,
2668,
7784,
939,
63,
5990,
401,
288,
2668,
1391,
63,
354,
63,
475,
63,
1238,
63,
5990,
401,
288,
2668,
8460,
63,
3282,
63,
1238,
63,
5990,
401,
267,
1622,
272,
776,
339,
347,
636,
826,
721,
267,
291,
12,
267,
485,
1074,
63,
466,
29,
549,
12,
267,
485,
504,
63,
1000,
29,
797,
12,
267,
485,
515,
63,
475,
63,
1053,
16729,
267,
485,
4758,
29,
403,
12,
267,
1011,
958,
272,
3461,
221,
327,
8151,
26,
662,
8216,
267,
408,
13061,
63,
875,
63,
908,
63,
1431,
63,
3401,
1194,
2466,
14,
19162,
1558,
3484,
4486,
9959,
1194,
2466,
446,
282,
1402,
3247,
315,
3232,
3735,
398,
6431,
3033,
26,
288,
485,
1074,
63,
466,
334,
2245,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hottwaj/django
|
django/utils/tree.py
|
372
|
4883
|
"""
A class for storing a tree graph. Primarily used for filter constructs in the
ORM.
"""
import copy
class Node(object):
"""
A single internal node in the tree graph. A Node should be viewed as a
connection (the root) with the children being either leaf nodes or other
Node instances.
"""
# Standard connector type. Clients usually won't use this at all and
# subclasses will usually override the value.
default = 'DEFAULT'
def __init__(self, children=None, connector=None, negated=False):
"""
Constructs a new Node. If no connector is given, the default will be
used.
"""
self.children = children[:] if children else []
self.connector = connector or self.default
self.negated = negated
# We need this because of django.db.models.query_utils.Q. Q. __init__() is
# problematic, but it is a natural Node subclass in all other respects.
@classmethod
def _new_instance(cls, children=None, connector=None, negated=False):
"""
This is called to create a new instance of this class when we need new
Nodes (or subclasses) in the internal code in this class. Normally, it
just shadows __init__(). However, subclasses with an __init__ signature
that is not an extension of Node.__init__ might need to implement this
method to allow a Node to create a new instance of them (if they have
any extra setting up to do).
"""
obj = Node(children, connector, negated)
obj.__class__ = cls
return obj
def __str__(self):
if self.negated:
return '(NOT (%s: %s))' % (self.connector, ', '.join(str(c) for c
in self.children))
return '(%s: %s)' % (self.connector, ', '.join(str(c) for c in
self.children))
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self)
def __deepcopy__(self, memodict):
"""
Utility method used by copy.deepcopy().
"""
obj = Node(connector=self.connector, negated=self.negated)
obj.__class__ = self.__class__
obj.children = copy.deepcopy(self.children, memodict)
return obj
def __len__(self):
"""
The size of a node if the number of children it has.
"""
return len(self.children)
def __bool__(self):
"""
For truth value testing.
"""
return bool(self.children)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
def __contains__(self, other):
"""
Returns True is 'other' is a direct child of this instance.
"""
return other in self.children
def add(self, data, conn_type, squash=True):
"""
Combines this tree and the data represented by data using the
connector conn_type. The combine is done by squashing the node other
away if possible.
This tree (self) will never be pushed to a child node of the
combined tree, nor will the connector or negated properties change.
The function returns a node which can be used in place of data
regardless if the node other got squashed or not.
If `squash` is False the data is prepared and added as a child to
this tree without further logic.
"""
if data in self.children:
return data
if not squash:
self.children.append(data)
return data
if self.connector == conn_type:
# We can reuse self.children to append or squash the node other.
if (isinstance(data, Node) and not data.negated
and (data.connector == conn_type or len(data) == 1)):
# We can squash the other node's children directly into this
# node. We are just doing (AB)(CD) == (ABCD) here, with the
# addition that if the length of the other node is 1 the
# connector doesn't matter. However, for the len(self) == 1
# case we don't want to do the squashing, as it would alter
# self.connector.
self.children.extend(data.children)
return self
else:
# We could use perhaps additional logic here to see if some
# children could be used for pushdown here.
self.children.append(data)
return data
else:
obj = self._new_instance(self.children, self.connector,
self.negated)
self.connector = conn_type
self.children = [obj, data]
return data
def negate(self):
"""
Negate the sense of the root connector.
"""
self.negated = not self.negated
|
bsd-3-clause
|
[
624,
199,
33,
1021,
367,
16915,
282,
3123,
3343,
14,
8538,
30468,
1202,
367,
2457,
21638,
315,
314,
199,
8832,
14,
199,
624,
199,
199,
646,
1331,
421,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
5007,
1031,
315,
314,
3123,
3343,
14,
437,
5013,
1077,
506,
2455,
379,
465,
282,
272,
1950,
334,
1589,
1738,
9,
543,
314,
4978,
3769,
1902,
11747,
3380,
503,
1163,
272,
5013,
4454,
14,
272,
408,
272,
327,
9739,
13252,
730,
14,
6810,
83,
9987,
7859,
1133,
675,
642,
737,
1006,
436,
272,
327,
9180,
911,
9987,
4278,
314,
574,
14,
272,
849,
275,
283,
3472,
7,
339,
347,
636,
826,
721,
277,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
9215,
83,
282,
892,
5013,
14,
982,
949,
13252,
365,
1627,
12,
314,
849,
911,
506,
267,
1202,
14,
267,
408,
267,
291,
14,
3223,
275,
4978,
5873,
340,
4978,
587,
942,
267,
291,
14,
11815,
275,
13252,
503,
291,
14,
885,
267,
291,
14,
8705,
972,
275,
14158,
972,
339,
327,
2136,
1929,
642,
2952,
402,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
14,
49,
14,
1413,
14,
636,
826,
4533,
365,
272,
327,
557,
31197,
12,
1325,
652,
365,
282,
19981,
5013,
5516,
315,
1006,
1163,
14021,
83,
14,
272,
768,
3744,
272,
347,
485,
1222,
63,
842,
8,
1886,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
961,
365,
2797,
370,
1218,
282,
892,
1256,
402,
642,
1021,
1380,
781,
1929,
892,
267,
23836,
334,
269,
9180,
9,
315,
314,
5007,
1233,
315,
642,
1021,
14,
24573,
12,
652,
267,
2951,
15084,
83,
636,
826,
31261,
9738,
12,
9180,
543,
376,
636,
826,
363,
4955,
267,
626,
365,
440,
376,
3329,
402,
5013,
855,
826,
363,
5594,
1929,
370,
5669,
642,
267,
1083,
370,
2040,
282,
5013,
370,
1218,
282,
892,
1256,
402,
3062,
334,
692,
2985,
1172,
267,
1263,
2402,
4260,
1536,
370,
886,
680,
267,
408,
267,
1559,
275,
5013,
8,
3223,
12,
13252,
12,
14158,
972,
9,
267,
1559,
855,
533,
363,
275,
843,
267,
372,
1559,
339,
347,
636,
495,
721,
277,
304,
267,
340,
291,
14,
8705,
972,
26,
288,
372,
8189,
4609,
4366,
83,
26,
450,
83,
23089,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
8,
495,
8,
67,
9,
367,
286,
490,
315,
291,
14,
3223,
430,
267,
372,
25676,
83,
26,
450,
83,
3171,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
8,
495,
8,
67,
9,
367,
286,
315,
355,
291,
14,
3223,
430,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
9,
339,
347,
636,
8293,
721,
277,
12,
11955,
807,
304,
267,
408,
267,
20511,
1083,
1202,
701,
1331,
14,
8293,
1252,
267,
408,
267,
1559,
275,
5013,
8,
11815,
29,
277,
14,
11815,
12,
14158,
972,
29,
277,
14,
8705,
972,
9,
267,
1559,
855,
533,
363,
275,
291,
855,
533,
363,
267,
1559,
14,
3223,
275,
1331,
14,
8293,
8,
277,
14,
3223,
12,
11955,
807,
9,
267,
372,
1559,
339,
347,
636,
552,
721,
277,
304,
267,
408,
267,
710,
1568,
402,
282,
1031,
340,
314,
1329,
402,
4978,
652,
965,
14,
267,
408,
267,
372,
822,
8,
277,
14,
3223,
9,
339,
347,
636,
2245,
721,
277,
304,
267,
408,
267,
2104,
16865,
574,
5343,
14,
267,
408,
267,
372,
2155,
8,
277,
14,
3223,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
339,
347,
636,
6134,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
365,
283,
1848,
7,
365,
282,
4125,
1982,
402,
642,
1256,
14,
267,
408,
267,
372,
1163,
315,
291,
14,
3223,
339,
347,
1050,
8,
277,
12,
666,
12,
2557,
63,
466,
12,
12345,
1119,
29,
549,
304,
267,
408,
267,
22170,
397,
642,
3123,
436,
314,
666,
11159,
701,
666,
1808,
314,
267,
13252,
2557,
63,
466,
14,
710,
13323,
365,
4224,
701,
12345,
1119,
316,
314,
1031,
1163,
267,
13437,
340,
3962,
14,
398,
961,
3123,
334,
277,
9,
911,
7078,
506,
22319,
370,
282,
1982,
1031,
402,
314,
267,
12149,
3123,
12,
6590,
911,
314,
13252,
503,
14158,
972,
4382,
1570,
14,
398,
710,
805,
2529,
282,
1031,
1314,
883,
506,
1202,
315,
4192,
402,
666,
267,
15270,
340,
314,
1031,
1163,
4788,
12345,
21189,
503,
440,
14,
398,
982,
658,
8471,
1119,
64,
365,
756,
314,
666,
365,
16318,
436,
3483,
465,
282,
1982,
370,
267,
642,
3123,
1928,
9848,
9661,
14,
267,
408,
267,
340,
666,
315,
291,
14,
3223,
26,
288,
372,
666,
267,
340,
440,
12345,
1119,
26,
288,
291,
14,
3223,
14,
740,
8,
576,
9,
288,
372,
666,
267,
340,
291,
14,
11815,
508,
2557,
63,
466,
26,
288,
327,
2136,
883,
12598,
291,
14,
3223,
370,
5666,
503,
12345,
1119,
314,
1031,
1163,
14,
288,
340,
334,
6074,
8,
576,
12,
5013,
9,
436,
440,
666,
14,
8705,
972,
490,
436,
334,
576,
14,
11815,
508,
2557,
63,
466,
503,
822,
8,
576,
9,
508,
413,
2298,
355,
327,
2136,
883,
12345,
1119,
314,
1163,
1031,
1159,
4978,
5370,
1901,
642,
355,
327,
1031,
14,
2136,
787,
2951,
9689,
334,
1217,
5130,
7695,
9,
508,
334,
31578,
9,
2348,
12,
543,
314,
355,
327,
10234,
626,
340,
314,
2582,
402,
314,
1163,
1031,
365,
413,
314,
355,
327,
13252,
3181,
1133,
17247,
14,
9738,
12,
367,
314,
822,
8,
277,
9,
508,
413,
355,
327,
1930,
781,
2793,
1133,
2934,
370,
886,
314,
12345,
1119,
316,
12,
465,
652,
3955,
17355,
355,
327,
291,
14,
11815,
14,
355,
291,
14,
3223,
14,
2880,
8,
576,
14,
3223,
9,
355,
372,
291,
288,
587,
26,
355,
327,
2136,
4293,
675,
25358,
4722,
9661,
2348,
370,
1937,
340,
2005,
355,
327,
4978,
4293,
506,
1202,
367,
6675,
2110,
2348,
14,
355,
291,
14,
3223,
14,
740,
8,
576,
9,
355,
372,
666,
267,
587,
26,
288,
1559
] |
[
199,
33,
1021,
367,
16915,
282,
3123,
3343,
14,
8538,
30468,
1202,
367,
2457,
21638,
315,
314,
199,
8832,
14,
199,
624,
199,
199,
646,
1331,
421,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
5007,
1031,
315,
314,
3123,
3343,
14,
437,
5013,
1077,
506,
2455,
379,
465,
282,
272,
1950,
334,
1589,
1738,
9,
543,
314,
4978,
3769,
1902,
11747,
3380,
503,
1163,
272,
5013,
4454,
14,
272,
408,
272,
327,
9739,
13252,
730,
14,
6810,
83,
9987,
7859,
1133,
675,
642,
737,
1006,
436,
272,
327,
9180,
911,
9987,
4278,
314,
574,
14,
272,
849,
275,
283,
3472,
7,
339,
347,
636,
826,
721,
277,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
9215,
83,
282,
892,
5013,
14,
982,
949,
13252,
365,
1627,
12,
314,
849,
911,
506,
267,
1202,
14,
267,
408,
267,
291,
14,
3223,
275,
4978,
5873,
340,
4978,
587,
942,
267,
291,
14,
11815,
275,
13252,
503,
291,
14,
885,
267,
291,
14,
8705,
972,
275,
14158,
972,
339,
327,
2136,
1929,
642,
2952,
402,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
14,
49,
14,
1413,
14,
636,
826,
4533,
365,
272,
327,
557,
31197,
12,
1325,
652,
365,
282,
19981,
5013,
5516,
315,
1006,
1163,
14021,
83,
14,
272,
768,
3744,
272,
347,
485,
1222,
63,
842,
8,
1886,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
961,
365,
2797,
370,
1218,
282,
892,
1256,
402,
642,
1021,
1380,
781,
1929,
892,
267,
23836,
334,
269,
9180,
9,
315,
314,
5007,
1233,
315,
642,
1021,
14,
24573,
12,
652,
267,
2951,
15084,
83,
636,
826,
31261,
9738,
12,
9180,
543,
376,
636,
826,
363,
4955,
267,
626,
365,
440,
376,
3329,
402,
5013,
855,
826,
363,
5594,
1929,
370,
5669,
642,
267,
1083,
370,
2040,
282,
5013,
370,
1218,
282,
892,
1256,
402,
3062,
334,
692,
2985,
1172,
267,
1263,
2402,
4260,
1536,
370,
886,
680,
267,
408,
267,
1559,
275,
5013,
8,
3223,
12,
13252,
12,
14158,
972,
9,
267,
1559,
855,
533,
363,
275,
843,
267,
372,
1559,
339,
347,
636,
495,
721,
277,
304,
267,
340,
291,
14,
8705,
972,
26,
288,
372,
8189,
4609,
4366,
83,
26,
450,
83,
23089,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
8,
495,
8,
67,
9,
367,
286,
490,
315,
291,
14,
3223,
430,
267,
372,
25676,
83,
26,
450,
83,
3171,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
8,
495,
8,
67,
9,
367,
286,
315,
355,
291,
14,
3223,
430,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
9,
339,
347,
636,
8293,
721,
277,
12,
11955,
807,
304,
267,
408,
267,
20511,
1083,
1202,
701,
1331,
14,
8293,
1252,
267,
408,
267,
1559,
275,
5013,
8,
11815,
29,
277,
14,
11815,
12,
14158,
972,
29,
277,
14,
8705,
972,
9,
267,
1559,
855,
533,
363,
275,
291,
855,
533,
363,
267,
1559,
14,
3223,
275,
1331,
14,
8293,
8,
277,
14,
3223,
12,
11955,
807,
9,
267,
372,
1559,
339,
347,
636,
552,
721,
277,
304,
267,
408,
267,
710,
1568,
402,
282,
1031,
340,
314,
1329,
402,
4978,
652,
965,
14,
267,
408,
267,
372,
822,
8,
277,
14,
3223,
9,
339,
347,
636,
2245,
721,
277,
304,
267,
408,
267,
2104,
16865,
574,
5343,
14,
267,
408,
267,
372,
2155,
8,
277,
14,
3223,
9,
339,
347,
636,
10262,
721,
277,
304,
420,
327,
2018,
499,
7163,
267,
372,
730,
8,
277,
2843,
2245,
721,
277,
9,
339,
347,
636,
6134,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
365,
283,
1848,
7,
365,
282,
4125,
1982,
402,
642,
1256,
14,
267,
408,
267,
372,
1163,
315,
291,
14,
3223,
339,
347,
1050,
8,
277,
12,
666,
12,
2557,
63,
466,
12,
12345,
1119,
29,
549,
304,
267,
408,
267,
22170,
397,
642,
3123,
436,
314,
666,
11159,
701,
666,
1808,
314,
267,
13252,
2557,
63,
466,
14,
710,
13323,
365,
4224,
701,
12345,
1119,
316,
314,
1031,
1163,
267,
13437,
340,
3962,
14,
398,
961,
3123,
334,
277,
9,
911,
7078,
506,
22319,
370,
282,
1982,
1031,
402,
314,
267,
12149,
3123,
12,
6590,
911,
314,
13252,
503,
14158,
972,
4382,
1570,
14,
398,
710,
805,
2529,
282,
1031,
1314,
883,
506,
1202,
315,
4192,
402,
666,
267,
15270,
340,
314,
1031,
1163,
4788,
12345,
21189,
503,
440,
14,
398,
982,
658,
8471,
1119,
64,
365,
756,
314,
666,
365,
16318,
436,
3483,
465,
282,
1982,
370,
267,
642,
3123,
1928,
9848,
9661,
14,
267,
408,
267,
340,
666,
315,
291,
14,
3223,
26,
288,
372,
666,
267,
340,
440,
12345,
1119,
26,
288,
291,
14,
3223,
14,
740,
8,
576,
9,
288,
372,
666,
267,
340,
291,
14,
11815,
508,
2557,
63,
466,
26,
288,
327,
2136,
883,
12598,
291,
14,
3223,
370,
5666,
503,
12345,
1119,
314,
1031,
1163,
14,
288,
340,
334,
6074,
8,
576,
12,
5013,
9,
436,
440,
666,
14,
8705,
972,
490,
436,
334,
576,
14,
11815,
508,
2557,
63,
466,
503,
822,
8,
576,
9,
508,
413,
2298,
355,
327,
2136,
883,
12345,
1119,
314,
1163,
1031,
1159,
4978,
5370,
1901,
642,
355,
327,
1031,
14,
2136,
787,
2951,
9689,
334,
1217,
5130,
7695,
9,
508,
334,
31578,
9,
2348,
12,
543,
314,
355,
327,
10234,
626,
340,
314,
2582,
402,
314,
1163,
1031,
365,
413,
314,
355,
327,
13252,
3181,
1133,
17247,
14,
9738,
12,
367,
314,
822,
8,
277,
9,
508,
413,
355,
327,
1930,
781,
2793,
1133,
2934,
370,
886,
314,
12345,
1119,
316,
12,
465,
652,
3955,
17355,
355,
327,
291,
14,
11815,
14,
355,
291,
14,
3223,
14,
2880,
8,
576,
14,
3223,
9,
355,
372,
291,
288,
587,
26,
355,
327,
2136,
4293,
675,
25358,
4722,
9661,
2348,
370,
1937,
340,
2005,
355,
327,
4978,
4293,
506,
1202,
367,
6675,
2110,
2348,
14,
355,
291,
14,
3223,
14,
740,
8,
576,
9,
355,
372,
666,
267,
587,
26,
288,
1559,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
csdms/pymt
|
tests/test_timeline.py
|
2
|
3554
|
#! /usr/bin/env python
import pytest
from pytest import approx
from pymt.timeline import Timeline
def test_init_without_args():
timeline = Timeline()
assert 0.0 == timeline.time
assert set() == timeline.events
with pytest.raises(IndexError):
timeline.time_of_next_event
with pytest.raises(IndexError):
timeline.next_event
def test_init_with_one_event():
timeline = Timeline([("event 1", 1.0)])
assert set(["event 1"]) == timeline.events
assert 1.0 == timeline.time_of_next_event
assert "event 1" == timeline.next_event
def test_init_with_two_events():
timeline = Timeline([("event 1", 1.0), ("event 2", 0.25)])
assert set(["event 1", "event 2"]) == timeline.events
assert timeline.time_of_next_event == approx(0.25)
assert timeline.next_event == "event 2"
def test_non_zero_start():
timeline = Timeline([("event 1", 1.0), ("event 2", 0.25)], start=-1)
assert timeline.time_of_next_event == approx(-0.75)
assert timeline.pop_until(0.0) == [
"event 2",
"event 2",
"event 2",
"event 1",
"event 2",
]
def test_pop_empty_timeline():
timeline = Timeline()
with pytest.raises(IndexError):
timeline.pop()
def test_pop_events():
timeline = Timeline([("event 1", 1.0), ("event 2", 0.25)])
for time in [0.25, 0.5, 0.75]:
assert timeline.pop() == "event 2"
assert timeline.time == approx(time)
assert timeline.pop() == "event 1"
assert timeline.time == approx(1.0)
assert timeline.pop() == "event 2"
assert timeline.time == approx(1.0)
def test_pop_until():
timeline = Timeline([("event 1", 1.0), ("event 2", 0.5)])
events = timeline.pop_until(0.2)
assert events == []
assert timeline.time == approx(0.2)
events = timeline.pop_until(1.0)
assert events == ["event 2", "event 1", "event 2"]
assert timeline.time == approx(1.0)
def test_hashable_event():
timeline = Timeline([(("event", 2), 0.5), (("event", 0), 1.0)])
assert ("event", 2) == timeline.pop()
assert ("event", 0) == timeline.pop()
assert ("event", 2) == timeline.pop()
def test_unhashable_event():
(first_event, second_event) = (dict(foo="bar"), dict(bar="baz"))
timeline = Timeline([(first_event, 0.5), (second_event, 1.0)])
assert first_event is timeline.pop()
assert second_event is timeline.pop()
assert first_event is timeline.pop()
def test_one_time_event():
timeline = Timeline([("recurring-event", 1.0)])
timeline.add_one_time_event("one-timer", 0.1)
events = timeline.pop_until(2.0)
assert events == ["one-timer", "recurring-event", "recurring-event"]
def test_repeated_events():
(first_event, second_event) = (dict(foo="bar"), dict(bar="baz"))
timeline = Timeline([(first_event, 0.5), (second_event, 1.0), (first_event, 0.75)])
assert first_event is timeline.pop()
assert first_event is timeline.pop()
assert second_event is timeline.pop()
assert first_event is timeline.pop()
timeline = Timeline([(first_event, 0.5), (second_event, 1.0), (first_event, 1.0)])
assert first_event is timeline.pop()
assert second_event is timeline.pop()
assert first_event is timeline.pop()
assert first_event is timeline.pop()
timeline = Timeline([(first_event, 0.5), (first_event, 1.0), (second_event, 1.0)])
assert first_event is timeline.pop()
assert first_event is timeline.pop()
assert second_event is timeline.pop()
assert first_event is timeline.pop()
|
mit
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
4613,
199,
504,
4613,
492,
14106,
199,
199,
504,
1134,
2037,
14,
19369,
492,
4703,
604,
421,
199,
318,
511,
63,
826,
63,
7395,
63,
589,
837,
272,
20780,
275,
4703,
604,
342,
272,
702,
378,
14,
16,
508,
20780,
14,
521,
272,
702,
663,
342,
508,
20780,
14,
4368,
339,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
272,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
2184,
63,
1430,
421,
199,
318,
511,
63,
826,
63,
1045,
63,
368,
63,
1430,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
3948,
339,
702,
663,
5234,
1430,
413,
3135,
508,
20780,
14,
4368,
272,
702,
413,
14,
16,
508,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
272,
702,
298,
1430,
413,
2,
508,
20780,
14,
2184,
63,
1430,
421,
199,
318,
511,
63,
826,
63,
1045,
63,
5601,
63,
4368,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
3948,
339,
702,
663,
5234,
1430,
413,
401,
298,
1430,
499,
3135,
508,
20780,
14,
4368,
272,
702,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
508,
14106,
8,
16,
14,
821,
9,
272,
702,
20780,
14,
2184,
63,
1430,
508,
298,
1430,
499,
2,
421,
199,
318,
511,
63,
2865,
63,
4262,
63,
928,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
4360,
1343,
4022,
17,
9,
272,
702,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
508,
14106,
2801,
16,
14,
2194,
9,
272,
702,
20780,
14,
1935,
63,
8111,
8,
16,
14,
16,
9,
508,
359,
267,
298,
1430,
499,
401,
267,
298,
1430,
499,
401,
267,
298,
1430,
499,
401,
267,
298,
1430,
413,
401,
267,
298,
1430,
499,
401,
272,
1622,
421,
199,
318,
511,
63,
1935,
63,
1667,
63,
19369,
837,
272,
20780,
275,
4703,
604,
342,
272,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
1935,
63,
4368,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
3948,
272,
367,
900,
315,
359,
16,
14,
821,
12,
378,
14,
21,
12,
378,
14,
2194,
2189,
267,
702,
20780,
14,
1935,
342,
508,
298,
1430,
499,
2,
267,
702,
20780,
14,
521,
508,
14106,
8,
521,
9,
272,
702,
20780,
14,
1935,
342,
508,
298,
1430,
413,
2,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
339,
702,
20780,
14,
1935,
342,
508,
298,
1430,
499,
2,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
421,
199,
318,
511,
63,
1935,
63,
8111,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
21,
3948,
272,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
16,
14,
18,
9,
272,
702,
4474,
508,
942,
272,
702,
20780,
14,
521,
508,
14106,
8,
16,
14,
18,
9,
339,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
17,
14,
16,
9,
272,
702,
4474,
508,
2097,
1430,
499,
401,
298,
1430,
413,
401,
298,
1430,
499,
937,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
421,
199,
318,
511,
63,
24596,
63,
1430,
837,
272,
20780,
275,
4703,
604,
7694,
480,
1430,
401,
499,
395,
378,
14,
21,
395,
19110,
1430,
401,
378,
395,
413,
14,
16,
3948,
272,
702,
1689,
1430,
401,
499,
9,
508,
20780,
14,
1935,
342,
272,
702,
1689,
1430,
401,
378,
9,
508,
20780,
14,
1935,
342,
272,
702,
1689,
1430,
401,
499,
9,
508,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
324,
24596,
63,
1430,
837,
272,
334,
2246,
63,
1430,
12,
3499,
63,
1430,
9,
275,
334,
807,
8,
1421,
628,
1700,
1288,
1211,
8,
1700,
628,
6185,
2237,
272,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
368,
63,
521,
63,
1430,
837,
272,
20780,
275,
4703,
604,
27187,
6794,
5985,
13,
1430,
401,
413,
14,
16,
3948,
272,
20780,
14,
525,
63,
368,
63,
521,
63,
1430,
480,
368,
13,
7414,
401,
378,
14,
17,
9,
272,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
18,
14,
16,
9,
272,
702,
4474,
508,
2097,
368,
13,
7414,
401,
298,
6794,
5985,
13,
1430,
401,
298,
6794,
5985,
13,
1430,
937,
421,
199,
318,
511,
63,
7593,
63,
4368,
837,
272,
334,
2246,
63,
1430,
12,
3499,
63,
1430,
9,
275,
334,
807,
8,
1421,
628,
1700,
1288,
1211,
8,
1700,
628,
6185,
2237,
272,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
395,
334,
2246,
63,
1430,
12,
378,
14,
2194,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
339,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
395,
334,
2246,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
339,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
2246,
63,
1430,
12,
413,
14,
16,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
4613,
199,
504,
4613,
492,
14106,
199,
199,
504,
1134,
2037,
14,
19369,
492,
4703,
604,
421,
199,
318,
511,
63,
826,
63,
7395,
63,
589,
837,
272,
20780,
275,
4703,
604,
342,
272,
702,
378,
14,
16,
508,
20780,
14,
521,
272,
702,
663,
342,
508,
20780,
14,
4368,
339,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
272,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
2184,
63,
1430,
421,
199,
318,
511,
63,
826,
63,
1045,
63,
368,
63,
1430,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
3948,
339,
702,
663,
5234,
1430,
413,
3135,
508,
20780,
14,
4368,
272,
702,
413,
14,
16,
508,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
272,
702,
298,
1430,
413,
2,
508,
20780,
14,
2184,
63,
1430,
421,
199,
318,
511,
63,
826,
63,
1045,
63,
5601,
63,
4368,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
3948,
339,
702,
663,
5234,
1430,
413,
401,
298,
1430,
499,
3135,
508,
20780,
14,
4368,
272,
702,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
508,
14106,
8,
16,
14,
821,
9,
272,
702,
20780,
14,
2184,
63,
1430,
508,
298,
1430,
499,
2,
421,
199,
318,
511,
63,
2865,
63,
4262,
63,
928,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
4360,
1343,
4022,
17,
9,
272,
702,
20780,
14,
521,
63,
1618,
63,
2184,
63,
1430,
508,
14106,
2801,
16,
14,
2194,
9,
272,
702,
20780,
14,
1935,
63,
8111,
8,
16,
14,
16,
9,
508,
359,
267,
298,
1430,
499,
401,
267,
298,
1430,
499,
401,
267,
298,
1430,
499,
401,
267,
298,
1430,
413,
401,
267,
298,
1430,
499,
401,
272,
1622,
421,
199,
318,
511,
63,
1935,
63,
1667,
63,
19369,
837,
272,
20780,
275,
4703,
604,
342,
272,
543,
4613,
14,
3536,
8,
12129,
304,
267,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
1935,
63,
4368,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
821,
3948,
272,
367,
900,
315,
359,
16,
14,
821,
12,
378,
14,
21,
12,
378,
14,
2194,
2189,
267,
702,
20780,
14,
1935,
342,
508,
298,
1430,
499,
2,
267,
702,
20780,
14,
521,
508,
14106,
8,
521,
9,
272,
702,
20780,
14,
1935,
342,
508,
298,
1430,
413,
2,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
339,
702,
20780,
14,
1935,
342,
508,
298,
1430,
499,
2,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
421,
199,
318,
511,
63,
1935,
63,
8111,
837,
272,
20780,
275,
4703,
604,
27187,
1430,
413,
401,
413,
14,
16,
395,
1689,
1430,
499,
401,
378,
14,
21,
3948,
272,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
16,
14,
18,
9,
272,
702,
4474,
508,
942,
272,
702,
20780,
14,
521,
508,
14106,
8,
16,
14,
18,
9,
339,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
17,
14,
16,
9,
272,
702,
4474,
508,
2097,
1430,
499,
401,
298,
1430,
413,
401,
298,
1430,
499,
937,
272,
702,
20780,
14,
521,
508,
14106,
8,
17,
14,
16,
9,
421,
199,
318,
511,
63,
24596,
63,
1430,
837,
272,
20780,
275,
4703,
604,
7694,
480,
1430,
401,
499,
395,
378,
14,
21,
395,
19110,
1430,
401,
378,
395,
413,
14,
16,
3948,
272,
702,
1689,
1430,
401,
499,
9,
508,
20780,
14,
1935,
342,
272,
702,
1689,
1430,
401,
378,
9,
508,
20780,
14,
1935,
342,
272,
702,
1689,
1430,
401,
499,
9,
508,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
324,
24596,
63,
1430,
837,
272,
334,
2246,
63,
1430,
12,
3499,
63,
1430,
9,
275,
334,
807,
8,
1421,
628,
1700,
1288,
1211,
8,
1700,
628,
6185,
2237,
272,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
421,
199,
318,
511,
63,
368,
63,
521,
63,
1430,
837,
272,
20780,
275,
4703,
604,
27187,
6794,
5985,
13,
1430,
401,
413,
14,
16,
3948,
272,
20780,
14,
525,
63,
368,
63,
521,
63,
1430,
480,
368,
13,
7414,
401,
378,
14,
17,
9,
272,
4474,
275,
20780,
14,
1935,
63,
8111,
8,
18,
14,
16,
9,
272,
702,
4474,
508,
2097,
368,
13,
7414,
401,
298,
6794,
5985,
13,
1430,
401,
298,
6794,
5985,
13,
1430,
937,
421,
199,
318,
511,
63,
7593,
63,
4368,
837,
272,
334,
2246,
63,
1430,
12,
3499,
63,
1430,
9,
275,
334,
807,
8,
1421,
628,
1700,
1288,
1211,
8,
1700,
628,
6185,
2237,
272,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
395,
334,
2246,
63,
1430,
12,
378,
14,
2194,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
339,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
395,
334,
2246,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
3499,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
272,
702,
1642,
63,
1430,
365,
20780,
14,
1935,
342,
339,
20780,
275,
4703,
604,
7694,
2246,
63,
1430,
12,
378,
14,
21,
395,
334,
2246,
63,
1430,
12,
413,
14,
16,
395,
334,
4375,
63,
1430,
12,
413,
14,
16,
3948,
272,
702,
1642,
63,
1430,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yb-kim/gemV
|
configs/ruby/MOESI_CMP_directory.py
|
3
|
8055
|
# Copyright (c) 2006-2007 The Regents of The University of Michigan
# Copyright (c) 2009 Advanced Micro Devices, 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 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: Brad Beckmann
import math
import m5
from m5.objects import *
from m5.defines import buildEnv
from Ruby import create_topology
#
# Note: the L1 Cache latency is only used by the sequencer on fast path hits
#
class L1Cache(RubyCache):
latency = 3
#
# Note: the L2 Cache latency is not currently used
#
class L2Cache(RubyCache):
latency = 15
def define_options(parser):
return
def create_system(options, system, piobus, dma_ports, ruby_system):
if buildEnv['PROTOCOL'] != 'MOESI_CMP_directory':
panic("This script requires the MOESI_CMP_directory protocol to be built.")
cpu_sequencers = []
#
# The ruby network creation expects the list of nodes in the system to be
# consistent with the NetDest list. Therefore the l1 controller nodes must be
# listed before the directory nodes and directory nodes before dma nodes, etc.
#
l1_cntrl_nodes = []
l2_cntrl_nodes = []
dir_cntrl_nodes = []
dma_cntrl_nodes = []
#
# Must create the individual controllers before the network to ensure the
# controller constructors are called before the network constructor
#
l2_bits = int(math.log(options.num_l2caches, 2))
block_size_bits = int(math.log(options.cacheline_size, 2))
cntrl_count = 0
for i in xrange(options.num_cpus):
#
# First create the Ruby objects associated with this cpu
#
l1i_cache = L1Cache(size = options.l1i_size,
assoc = options.l1i_assoc,
start_index_bit = block_size_bits,
is_icache = True)
l1d_cache = L1Cache(size = options.l1d_size,
assoc = options.l1d_assoc,
start_index_bit = block_size_bits,
is_icache = False)
l1_cntrl = L1Cache_Controller(version = i,
cntrl_id = cntrl_count,
L1Icache = l1i_cache,
L1Dcache = l1d_cache,
l2_select_num_bits = l2_bits,
send_evictions = (
options.cpu_type == "detailed"),
transitions_per_cycle = options.ports,
ruby_system = ruby_system)
cpu_seq = RubySequencer(version = i,
icache = l1i_cache,
dcache = l1d_cache,
ruby_system = ruby_system)
l1_cntrl.sequencer = cpu_seq
if piobus != None:
cpu_seq.pio_port = piobus.slave
exec("ruby_system.l1_cntrl%d = l1_cntrl" % i)
#
# Add controllers and sequencers to the appropriate lists
#
cpu_sequencers.append(cpu_seq)
l1_cntrl_nodes.append(l1_cntrl)
cntrl_count += 1
l2_index_start = block_size_bits + l2_bits
for i in xrange(options.num_l2caches):
#
# First create the Ruby objects associated with this cpu
#
l2_cache = L2Cache(size = options.l2_size,
assoc = options.l2_assoc,
start_index_bit = l2_index_start)
l2_cntrl = L2Cache_Controller(version = i,
cntrl_id = cntrl_count,
L2cache = l2_cache,
transitions_per_cycle = options.ports,
ruby_system = ruby_system)
exec("ruby_system.l2_cntrl%d = l2_cntrl" % i)
l2_cntrl_nodes.append(l2_cntrl)
cntrl_count += 1
phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
assert(phys_mem_size % options.num_dirs == 0)
mem_module_size = phys_mem_size / options.num_dirs
# Run each of the ruby memory controllers at a ratio of the frequency of
# the ruby system.
# clk_divider value is a fix to pass regression.
ruby_system.memctrl_clk_domain = DerivedClockDomain(
clk_domain=ruby_system.clk_domain,
clk_divider=3)
for i in xrange(options.num_dirs):
#
# Create the Ruby objects associated with the directory controller
#
mem_cntrl = RubyMemoryControl(
clk_domain = ruby_system.memctrl_clk_domain,
version = i,
ruby_system = ruby_system)
dir_size = MemorySize('0B')
dir_size.value = mem_module_size
dir_cntrl = Directory_Controller(version = i,
cntrl_id = cntrl_count,
directory = \
RubyDirectoryMemory(version = i,
size = dir_size,
use_map = options.use_map),
memBuffer = mem_cntrl,
transitions_per_cycle = options.ports,
ruby_system = ruby_system)
exec("ruby_system.dir_cntrl%d = dir_cntrl" % i)
dir_cntrl_nodes.append(dir_cntrl)
cntrl_count += 1
for i, dma_port in enumerate(dma_ports):
#
# Create the Ruby objects associated with the dma controller
#
dma_seq = DMASequencer(version = i,
ruby_system = ruby_system)
dma_cntrl = DMA_Controller(version = i,
cntrl_id = cntrl_count,
dma_sequencer = dma_seq,
transitions_per_cycle = options.ports,
ruby_system = ruby_system)
exec("ruby_system.dma_cntrl%d = dma_cntrl" % i)
exec("ruby_system.dma_cntrl%d.dma_sequencer.slave = dma_port" % i)
dma_cntrl_nodes.append(dma_cntrl)
cntrl_count += 1
all_cntrls = l1_cntrl_nodes + \
l2_cntrl_nodes + \
dir_cntrl_nodes + \
dma_cntrl_nodes
topology = create_topology(all_cntrls, options)
return (cpu_sequencers, dir_cntrl_nodes, topology)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
8937,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
699,
9525,
6423,
346,
20059,
199,
199,
646,
3473,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
820,
10972,
492,
1218,
63,
10775,
199,
199,
3,
199,
3,
3390,
26,
314,
491,
17,
11977,
23967,
365,
1454,
1202,
701,
314,
542,
1514,
2247,
641,
7377,
931,
19745,
199,
3,
199,
533,
491,
17,
4437,
8,
50,
10972,
4437,
304,
272,
23967,
275,
650,
199,
199,
3,
199,
3,
3390,
26,
314,
491,
18,
11977,
23967,
365,
440,
5544,
1202,
199,
3,
199,
533,
491,
18,
4437,
8,
50,
10972,
4437,
304,
272,
23967,
275,
4114,
199,
199,
318,
5627,
63,
1419,
8,
2087,
304,
272,
372,
199,
199,
318,
1218,
63,
2253,
8,
1419,
12,
2656,
12,
299,
2308,
5610,
12,
366,
391,
63,
5203,
12,
31855,
63,
2253,
304,
339,
340,
1900,
7744,
459,
9583,
418,
1137,
283,
2679,
654,
41,
63,
23181,
63,
3619,
356,
267,
21379,
530,
480,
2765,
2884,
5074,
314,
10362,
654,
41,
63,
23181,
63,
3619,
4113,
370,
506,
6137,
2685,
339,
5033,
63,
261,
1514,
67,
1192,
275,
942,
2286,
327,
272,
327,
710,
31855,
2784,
7143,
14292,
314,
769,
402,
3380,
315,
314,
2656,
370,
506,
272,
327,
12137,
543,
314,
5365,
8004,
769,
14,
221,
21039,
314,
634,
17,
7614,
3380,
1471,
506,
272,
327,
10532,
2544,
314,
2082,
3380,
436,
2082,
3380,
2544,
366,
391,
3380,
12,
5423,
14,
272,
327,
272,
634,
17,
63,
6507,
4308,
63,
2415,
275,
942,
272,
634,
18,
63,
6507,
4308,
63,
2415,
275,
942,
272,
2935,
63,
6507,
4308,
63,
2415,
275,
942,
272,
366,
391,
63,
6507,
4308,
63,
2415,
275,
942,
339,
327,
272,
327,
9498,
1218,
314,
8212,
27325,
2544,
314,
2784,
370,
4868,
314,
272,
327,
7614,
31604,
787,
2797,
2544,
314,
2784,
3787,
272,
327,
272,
634,
18,
63,
5609,
275,
1109,
8,
3442,
14,
793,
8,
1419,
14,
1507,
63,
76,
18,
17595,
12,
499,
430,
272,
1853,
63,
890,
63,
5609,
275,
1109,
8,
3442,
14,
793,
8,
1419,
14,
20138,
32347,
63,
890,
12,
499,
430,
339,
12703,
4308,
63,
835,
275,
378,
2286,
367,
284,
315,
4945,
8,
1419,
14,
1507,
63,
8896,
304,
267,
327,
267,
327,
7758,
1218,
314,
820,
10972,
2251,
4568,
543,
642,
5033,
267,
327,
267,
634,
17,
73,
63,
1637,
275,
491,
17,
4437,
8,
890,
275,
1511,
14,
76,
17,
73,
63,
890,
12,
1169,
22149,
275,
1511,
14,
76,
17,
73,
63,
16824,
12,
1169,
1343,
63,
1080,
63,
2075,
275,
1853,
63,
890,
63,
5609,
12,
1169,
365,
63,
530,
21481,
275,
715,
9,
267,
634,
17,
68,
63,
1637,
275,
491,
17,
4437,
8,
890,
275,
1511,
14,
76,
17,
68,
63,
890,
12,
1169,
22149,
275,
1511,
14,
76,
17,
68,
63,
16824,
12,
1169,
1343,
63,
1080,
63,
2075,
275,
1853,
63,
890,
63,
5609,
12,
1169,
365,
63,
530,
21481,
275,
756,
9,
398,
634,
17,
63,
6507,
4308,
275,
491,
17,
4437,
63,
7506,
8,
1023,
275,
284,
12,
4228,
12703,
4308,
63,
344,
275,
12703,
4308,
63,
835,
12,
4228,
491,
17,
41,
1637,
275,
634,
17,
73,
63,
1637,
12,
4228,
491,
17,
36,
1637,
275,
634,
17,
68,
63,
1637,
12,
4228,
634,
18,
63,
2416,
63,
1507,
63,
5609,
275,
634,
18,
63,
5609,
12,
4228,
3222,
63,
69,
433,
2452,
275,
334,
5101,
1511,
14,
3541,
63,
466,
508,
298,
19170,
1288,
4228,
19077,
63,
529,
63,
7612,
275,
1511,
14,
5203,
12,
4228,
31855,
63,
2253,
275,
31855,
63,
2253,
9,
398,
5033,
63,
3610,
275,
820,
10972,
1513,
1514,
2247,
8,
1023,
275,
284,
12,
1816,
284,
1637,
275,
634,
17,
73,
63,
1637,
12,
1816,
366,
1637,
275,
634,
17,
68,
63,
1637,
12,
1816,
31855,
63,
2253,
275,
31855,
63,
2253,
9,
398,
634,
17,
63,
6507,
4308,
14,
261,
1514,
2247,
275,
5033,
63,
3610,
398,
340,
299,
2308,
5610,
1137,
488,
26,
288,
5033,
63,
3610,
14,
13937,
63,
719,
275,
299,
2308,
5610,
14,
12384,
398,
2146
] |
[
1898,
334,
67,
9,
8315,
13,
9488,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
1898,
334,
67,
9,
8937,
32445,
27022,
12272,
83,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
699,
9525,
6423,
346,
20059,
199,
199,
646,
3473,
199,
646,
333,
21,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
820,
10972,
492,
1218,
63,
10775,
199,
199,
3,
199,
3,
3390,
26,
314,
491,
17,
11977,
23967,
365,
1454,
1202,
701,
314,
542,
1514,
2247,
641,
7377,
931,
19745,
199,
3,
199,
533,
491,
17,
4437,
8,
50,
10972,
4437,
304,
272,
23967,
275,
650,
199,
199,
3,
199,
3,
3390,
26,
314,
491,
18,
11977,
23967,
365,
440,
5544,
1202,
199,
3,
199,
533,
491,
18,
4437,
8,
50,
10972,
4437,
304,
272,
23967,
275,
4114,
199,
199,
318,
5627,
63,
1419,
8,
2087,
304,
272,
372,
199,
199,
318,
1218,
63,
2253,
8,
1419,
12,
2656,
12,
299,
2308,
5610,
12,
366,
391,
63,
5203,
12,
31855,
63,
2253,
304,
339,
340,
1900,
7744,
459,
9583,
418,
1137,
283,
2679,
654,
41,
63,
23181,
63,
3619,
356,
267,
21379,
530,
480,
2765,
2884,
5074,
314,
10362,
654,
41,
63,
23181,
63,
3619,
4113,
370,
506,
6137,
2685,
339,
5033,
63,
261,
1514,
67,
1192,
275,
942,
2286,
327,
272,
327,
710,
31855,
2784,
7143,
14292,
314,
769,
402,
3380,
315,
314,
2656,
370,
506,
272,
327,
12137,
543,
314,
5365,
8004,
769,
14,
221,
21039,
314,
634,
17,
7614,
3380,
1471,
506,
272,
327,
10532,
2544,
314,
2082,
3380,
436,
2082,
3380,
2544,
366,
391,
3380,
12,
5423,
14,
272,
327,
272,
634,
17,
63,
6507,
4308,
63,
2415,
275,
942,
272,
634,
18,
63,
6507,
4308,
63,
2415,
275,
942,
272,
2935,
63,
6507,
4308,
63,
2415,
275,
942,
272,
366,
391,
63,
6507,
4308,
63,
2415,
275,
942,
339,
327,
272,
327,
9498,
1218,
314,
8212,
27325,
2544,
314,
2784,
370,
4868,
314,
272,
327,
7614,
31604,
787,
2797,
2544,
314,
2784,
3787,
272,
327,
272,
634,
18,
63,
5609,
275,
1109,
8,
3442,
14,
793,
8,
1419,
14,
1507,
63,
76,
18,
17595,
12,
499,
430,
272,
1853,
63,
890,
63,
5609,
275,
1109,
8,
3442,
14,
793,
8,
1419,
14,
20138,
32347,
63,
890,
12,
499,
430,
339,
12703,
4308,
63,
835,
275,
378,
2286,
367,
284,
315,
4945,
8,
1419,
14,
1507,
63,
8896,
304,
267,
327,
267,
327,
7758,
1218,
314,
820,
10972,
2251,
4568,
543,
642,
5033,
267,
327,
267,
634,
17,
73,
63,
1637,
275,
491,
17,
4437,
8,
890,
275,
1511,
14,
76,
17,
73,
63,
890,
12,
1169,
22149,
275,
1511,
14,
76,
17,
73,
63,
16824,
12,
1169,
1343,
63,
1080,
63,
2075,
275,
1853,
63,
890,
63,
5609,
12,
1169,
365,
63,
530,
21481,
275,
715,
9,
267,
634,
17,
68,
63,
1637,
275,
491,
17,
4437,
8,
890,
275,
1511,
14,
76,
17,
68,
63,
890,
12,
1169,
22149,
275,
1511,
14,
76,
17,
68,
63,
16824,
12,
1169,
1343,
63,
1080,
63,
2075,
275,
1853,
63,
890,
63,
5609,
12,
1169,
365,
63,
530,
21481,
275,
756,
9,
398,
634,
17,
63,
6507,
4308,
275,
491,
17,
4437,
63,
7506,
8,
1023,
275,
284,
12,
4228,
12703,
4308,
63,
344,
275,
12703,
4308,
63,
835,
12,
4228,
491,
17,
41,
1637,
275,
634,
17,
73,
63,
1637,
12,
4228,
491,
17,
36,
1637,
275,
634,
17,
68,
63,
1637,
12,
4228,
634,
18,
63,
2416,
63,
1507,
63,
5609,
275,
634,
18,
63,
5609,
12,
4228,
3222,
63,
69,
433,
2452,
275,
334,
5101,
1511,
14,
3541,
63,
466,
508,
298,
19170,
1288,
4228,
19077,
63,
529,
63,
7612,
275,
1511,
14,
5203,
12,
4228,
31855,
63,
2253,
275,
31855,
63,
2253,
9,
398,
5033,
63,
3610,
275,
820,
10972,
1513,
1514,
2247,
8,
1023,
275,
284,
12,
1816,
284,
1637,
275,
634,
17,
73,
63,
1637,
12,
1816,
366,
1637,
275,
634,
17,
68,
63,
1637,
12,
1816,
31855,
63,
2253,
275,
31855,
63,
2253,
9,
398,
634,
17,
63,
6507,
4308,
14,
261,
1514,
2247,
275,
5033,
63,
3610,
398,
340,
299,
2308,
5610,
1137,
488,
26,
288,
5033,
63,
3610,
14,
13937,
63,
719,
275,
299,
2308,
5610,
14,
12384,
398,
2146,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ojengwa/grr
|
lib/flows/general/find_test.py
|
3
|
5959
|
#!/usr/bin/env python
# -*- mode: python; encoding: utf-8 -*-
"""Tests for the Find flow."""
from grr.client import vfs
from grr.lib import action_mocks
from grr.lib import aff4
from grr.lib import flags
from grr.lib import rdfvalue
from grr.lib import test_lib
from grr.lib import type_info
from grr.lib import utils
class TestFindFlow(test_lib.FlowTestsBaseclass):
"""Test the interrogate flow."""
def setUp(self):
super(TestFindFlow, self).setUp()
# Install the mock
vfs_type = rdfvalue.PathSpec.PathType.OS
vfs.VFS_HANDLERS[vfs_type] = test_lib.ClientVFSHandlerFixture
def testInvalidFindSpec(self):
"""Test that its impossible to produce an invalid findspec."""
# The regular expression is not valid.
self.assertRaises(type_info.TypeValueError, rdfvalue.FindSpec,
path_regex="[")
def testFindFiles(self):
"""Test that the Find flow works with files."""
client_mock = action_mocks.ActionMock("Find")
output_path = "analysis/FindFlowTest1"
# Prepare a findspec.
findspec = rdfvalue.FindSpec(
path_regex="bash",
pathspec=rdfvalue.PathSpec(
path="/", pathtype=rdfvalue.PathSpec.PathType.OS))
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id,
token=self.token, output=output_path, findspec=findspec):
pass
# Check the output file is created
fd = aff4.FACTORY.Open(self.client_id.Add(output_path), token=self.token)
# Should match ["bash" and "rbash"].
matches = set([x.aff4path.Basename() for x in fd])
self.assertEqual(sorted(matches), ["bash", "rbash"])
self.assertEqual(len(fd), 4)
for child in fd:
path = utils.SmartStr(child.aff4path)
self.assertTrue(path.endswith("bash"))
self.assertEqual(child.__class__.__name__, "StatEntry")
def testFindFilesWithGlob(self):
"""Test that the Find flow works with glob."""
client_mock = action_mocks.ActionMock("Find")
output_path = "analysis/FindFlowTest1"
# Prepare a findspec.
findspec = rdfvalue.FindSpec(
path_glob="bash*",
pathspec=rdfvalue.PathSpec(
path="/", pathtype=rdfvalue.PathSpec.PathType.OS))
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id,
token=self.token, output=output_path, findspec=findspec):
pass
# Check the output file is created
fd = aff4.FACTORY.Open(self.client_id.Add(output_path), token=self.token)
# Make sure that bash is a file.
matches = set([x.aff4path.Basename() for x in fd])
self.assertEqual(sorted(matches), ["bash"])
self.assertEqual(len(fd), 2)
for child in fd:
path = utils.SmartStr(child.aff4path)
self.assertTrue(path.endswith("bash"))
self.assertEqual(child.__class__.__name__, "StatEntry")
def testFindDirectories(self):
"""Test that the Find flow works with directories."""
client_mock = action_mocks.ActionMock("Find")
output_path = "analysis/FindFlowTest2"
# Prepare a findspec.
findspec = rdfvalue.FindSpec(
path_regex="bin",
pathspec=rdfvalue.PathSpec(path="/",
pathtype=rdfvalue.PathSpec.PathType.OS))
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id,
token=self.token, output=output_path, findspec=findspec):
pass
# Check the output file is created
fd = aff4.FACTORY.Open(self.client_id.Add(output_path), token=self.token)
# Make sure that bin is a directory
self.assertEqual(len(fd), 2)
for child in fd:
path = utils.SmartStr(child.aff4path)
self.assertTrue("bin" in path)
self.assertEqual(child.__class__.__name__, "StatEntry")
def testFindWithMaxFiles(self):
"""Test that the Find flow works when specifying proto directly."""
client_mock = action_mocks.ActionMock("Find")
output_path = "analysis/FindFlowTest4"
# Prepare a findspec.
findspec = rdfvalue.FindSpec(
path_regex=".*",
pathspec=rdfvalue.PathSpec(path="/",
pathtype=rdfvalue.PathSpec.PathType.OS))
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id, token=self.token,
findspec=findspec, iteration_count=3, output=output_path,
max_results=7):
pass
# Check the output file is created
fd = aff4.FACTORY.Open(self.client_id.Add(output_path), token=self.token)
# Make sure we got the right number of results.
self.assertEqual(len(fd), 7)
def testCollectionOverwriting(self):
"""Test we overwrite the collection every time the flow is executed."""
client_mock = action_mocks.ActionMock("Find")
output_path = "analysis/FindFlowTest5"
# Prepare a findspec.
findspec = rdfvalue.FindSpec()
findspec.path_regex = "bin"
findspec.pathspec.path = "/"
findspec.pathspec.pathtype = rdfvalue.PathSpec.PathType.OS
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id, token=self.token,
findspec=findspec, output=output_path):
pass
# Check the output file with the right number of results.
fd = aff4.FACTORY.Open(self.client_id.Add(output_path),
token=self.token)
self.assertEqual(len(fd), 2)
# Now find a new result, should overwrite the collection
findspec.path_regex = "dd"
for _ in test_lib.TestFlowHelper(
"FindFiles", client_mock, client_id=self.client_id, token=self.token,
findspec=findspec, output=output_path, max_results=1):
pass
fd = aff4.FACTORY.Open(self.client_id.Add(output_path),
token=self.token)
self.assertEqual(len(fd), 1)
def main(argv):
# Run the full test suite
test_lib.GrrTestProgram(argv=argv)
if __name__ == "__main__":
flags.StartMain(main)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
818,
26,
2366,
27,
2644,
26,
2774,
13,
24,
1882,
199,
199,
624,
2925,
367,
314,
6668,
6369,
1041,
199,
504,
31118,
14,
1258,
492,
31628,
199,
504,
31118,
14,
773,
492,
1595,
63,
25191,
199,
504,
31118,
14,
773,
492,
9876,
20,
199,
504,
31118,
14,
773,
492,
3285,
199,
504,
31118,
14,
773,
492,
18148,
585,
199,
504,
31118,
14,
773,
492,
511,
63,
773,
199,
504,
31118,
14,
773,
492,
730,
63,
815,
199,
504,
31118,
14,
773,
492,
3778,
421,
199,
533,
1379,
6591,
5060,
8,
396,
63,
773,
14,
5060,
2925,
1563,
533,
304,
523,
408,
774,
314,
1640,
13095,
6369,
1041,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
6591,
5060,
12,
291,
680,
5996,
342,
272,
327,
13276,
314,
1683,
272,
31628,
63,
466,
275,
18148,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
272,
31628,
14,
54,
7079,
63,
10854,
28778,
59,
20970,
63,
466,
61,
275,
511,
63,
773,
14,
3041,
54,
7079,
2461,
12812,
819,
347,
511,
3364,
6591,
5307,
8,
277,
304,
272,
408,
774,
626,
2399,
26847,
370,
7389,
376,
3866,
2342,
1650,
1041,
272,
327,
710,
5578,
3965,
365,
440,
1686,
14,
272,
291,
14,
1855,
8,
466,
63,
815,
14,
804,
3393,
12,
18148,
585,
14,
6591,
5307,
12,
1993,
931,
63,
3821,
628,
59,
531,
819,
347,
511,
6591,
5535,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
1584,
1041,
272,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
17,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
3821,
628,
16408,
401,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
288,
931,
9555,
401,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
7719,
1336,
2097,
16408,
2,
436,
298,
4848,
1119,
4140,
272,
4450,
275,
663,
779,
88,
14,
9181,
20,
515,
14,
1563,
354,
342,
367,
671,
315,
6111,
566,
272,
291,
14,
629,
8,
5917,
8,
6742,
395,
2097,
16408,
401,
298,
4848,
1119,
3135,
339,
291,
14,
629,
8,
552,
8,
2592,
395,
841,
9,
272,
367,
1982,
315,
6111,
26,
489,
931,
275,
3778,
14,
29111,
2848,
8,
1739,
14,
9181,
20,
515,
9,
489,
291,
14,
1815,
8,
515,
14,
4130,
480,
16408,
2237,
489,
291,
14,
629,
8,
1739,
855,
533,
4914,
354,
3108,
298,
11232,
3900,
531,
819,
347,
511,
6591,
5535,
3007,
25954,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
5739,
1041,
272,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
17,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
6463,
628,
16408,
14421,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
288,
931,
9555,
401,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
4155,
3238,
626,
20387,
365,
282,
570,
14,
272,
4450,
275,
663,
779,
88,
14,
9181,
20,
515,
14,
1563,
354,
342,
367,
671,
315,
6111,
566,
272,
291,
14,
629,
8,
5917,
8,
6742,
395,
2097,
16408,
3135,
339,
291,
14,
629,
8,
552,
8,
2592,
395,
499,
9,
272,
367,
1982,
315,
6111,
26,
489,
931,
275,
3778,
14,
29111,
2848,
8,
1739,
14,
9181,
20,
515,
9,
489,
291,
14,
1815,
8,
515,
14,
4130,
480,
16408,
2237,
489,
291,
14,
629,
8,
1739,
855,
533,
4914,
354,
3108,
298,
11232,
3900,
531,
819,
347,
511,
6591,
13752,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
6602,
1041,
339,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
18,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
3821,
628,
1393,
401,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
515,
9555,
401,
3521,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
4155,
3238,
626,
2517,
365,
282,
2082,
272,
291,
14,
629,
8,
552,
8,
2592,
395,
499,
9,
272,
367,
1982,
315,
6111,
26
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
818,
26,
2366,
27,
2644,
26,
2774,
13,
24,
1882,
199,
199,
624,
2925,
367,
314,
6668,
6369,
1041,
199,
504,
31118,
14,
1258,
492,
31628,
199,
504,
31118,
14,
773,
492,
1595,
63,
25191,
199,
504,
31118,
14,
773,
492,
9876,
20,
199,
504,
31118,
14,
773,
492,
3285,
199,
504,
31118,
14,
773,
492,
18148,
585,
199,
504,
31118,
14,
773,
492,
511,
63,
773,
199,
504,
31118,
14,
773,
492,
730,
63,
815,
199,
504,
31118,
14,
773,
492,
3778,
421,
199,
533,
1379,
6591,
5060,
8,
396,
63,
773,
14,
5060,
2925,
1563,
533,
304,
523,
408,
774,
314,
1640,
13095,
6369,
1041,
819,
347,
3613,
8,
277,
304,
272,
1613,
8,
774,
6591,
5060,
12,
291,
680,
5996,
342,
272,
327,
13276,
314,
1683,
272,
31628,
63,
466,
275,
18148,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
272,
31628,
14,
54,
7079,
63,
10854,
28778,
59,
20970,
63,
466,
61,
275,
511,
63,
773,
14,
3041,
54,
7079,
2461,
12812,
819,
347,
511,
3364,
6591,
5307,
8,
277,
304,
272,
408,
774,
626,
2399,
26847,
370,
7389,
376,
3866,
2342,
1650,
1041,
272,
327,
710,
5578,
3965,
365,
440,
1686,
14,
272,
291,
14,
1855,
8,
466,
63,
815,
14,
804,
3393,
12,
18148,
585,
14,
6591,
5307,
12,
1993,
931,
63,
3821,
628,
59,
531,
819,
347,
511,
6591,
5535,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
1584,
1041,
272,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
17,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
3821,
628,
16408,
401,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
288,
931,
9555,
401,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
7719,
1336,
2097,
16408,
2,
436,
298,
4848,
1119,
4140,
272,
4450,
275,
663,
779,
88,
14,
9181,
20,
515,
14,
1563,
354,
342,
367,
671,
315,
6111,
566,
272,
291,
14,
629,
8,
5917,
8,
6742,
395,
2097,
16408,
401,
298,
4848,
1119,
3135,
339,
291,
14,
629,
8,
552,
8,
2592,
395,
841,
9,
272,
367,
1982,
315,
6111,
26,
489,
931,
275,
3778,
14,
29111,
2848,
8,
1739,
14,
9181,
20,
515,
9,
489,
291,
14,
1815,
8,
515,
14,
4130,
480,
16408,
2237,
489,
291,
14,
629,
8,
1739,
855,
533,
4914,
354,
3108,
298,
11232,
3900,
531,
819,
347,
511,
6591,
5535,
3007,
25954,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
5739,
1041,
272,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
17,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
6463,
628,
16408,
14421,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
288,
931,
9555,
401,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
4155,
3238,
626,
20387,
365,
282,
570,
14,
272,
4450,
275,
663,
779,
88,
14,
9181,
20,
515,
14,
1563,
354,
342,
367,
671,
315,
6111,
566,
272,
291,
14,
629,
8,
5917,
8,
6742,
395,
2097,
16408,
3135,
339,
291,
14,
629,
8,
552,
8,
2592,
395,
499,
9,
272,
367,
1982,
315,
6111,
26,
489,
931,
275,
3778,
14,
29111,
2848,
8,
1739,
14,
9181,
20,
515,
9,
489,
291,
14,
1815,
8,
515,
14,
4130,
480,
16408,
2237,
489,
291,
14,
629,
8,
1739,
855,
533,
4914,
354,
3108,
298,
11232,
3900,
531,
819,
347,
511,
6591,
13752,
8,
277,
304,
272,
408,
774,
626,
314,
6668,
6369,
5419,
543,
6602,
1041,
339,
1890,
63,
1805,
275,
1595,
63,
25191,
14,
3310,
3346,
480,
6591,
531,
272,
1072,
63,
515,
275,
298,
10466,
15,
6591,
5060,
774,
18,
2,
339,
327,
17008,
282,
2342,
1650,
14,
272,
2342,
1650,
275,
18148,
585,
14,
6591,
5307,
8,
267,
931,
63,
3821,
628,
1393,
401,
267,
931,
1650,
29,
17120,
585,
14,
2042,
5307,
8,
515,
9555,
401,
3521,
931,
466,
29,
17120,
585,
14,
2042,
5307,
14,
2042,
804,
14,
3100,
430,
339,
367,
485,
315,
511,
63,
773,
14,
774,
5060,
4433,
8,
267,
298,
6591,
5535,
401,
1890,
63,
1805,
12,
1890,
63,
344,
29,
277,
14,
1258,
63,
344,
12,
267,
1526,
29,
277,
14,
1418,
12,
1072,
29,
1199,
63,
515,
12,
2342,
1650,
29,
1623,
1650,
304,
489,
986,
339,
327,
2670,
314,
1072,
570,
365,
2737,
272,
6111,
275,
9876,
20,
14,
18164,
5347,
14,
4299,
8,
277,
14,
1258,
63,
344,
14,
1123,
8,
1199,
63,
515,
395,
1526,
29,
277,
14,
1418,
9,
339,
327,
4155,
3238,
626,
2517,
365,
282,
2082,
272,
291,
14,
629,
8,
552,
8,
2592,
395,
499,
9,
272,
367,
1982,
315,
6111,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jlspyaozhongkai/Uter
|
third_party_build/Python-2.7.9/lib/python2.7/test/test_capi.py
|
15
|
4750
|
# Run the _testcapi module tests (tests for the Python/C API): by defn,
# these are all functions _testcapi exports whose name begins with 'test_'.
from __future__ import with_statement
import sys
import time
import random
import unittest
from test import test_support
try:
import thread
import threading
except ImportError:
thread = None
threading = None
# Skip this test if the _testcapi module isn't available.
_testcapi = test_support.import_module('_testcapi')
@unittest.skipUnless(threading, 'Threading required for this test.')
class TestPendingCalls(unittest.TestCase):
def pendingcalls_submit(self, l, n):
def callback():
#this function can be interrupted by thread switching so let's
#use an atomic operation
l.append(None)
for i in range(n):
time.sleep(random.random()*0.02) #0.01 secs on average
#try submitting callback until successful.
#rely on regular interrupt to flush queue if we are
#unsuccessful.
while True:
if _testcapi._pending_threadfunc(callback):
break;
def pendingcalls_wait(self, l, n, context = None):
#now, stick around until l[0] has grown to 10
count = 0;
while len(l) != n:
#this busy loop is where we expect to be interrupted to
#run our callbacks. Note that callbacks are only run on the
#main thread
if False and test_support.verbose:
print "(%i)"%(len(l),),
for i in xrange(1000):
a = i*i
if context and not context.event.is_set():
continue
count += 1
self.assertTrue(count < 10000,
"timeout waiting for %i callbacks, got %i"%(n, len(l)))
if False and test_support.verbose:
print "(%i)"%(len(l),)
def test_pendingcalls_threaded(self):
#do every callback on a separate thread
n = 32 #total callbacks
threads = []
class foo(object):pass
context = foo()
context.l = []
context.n = 2 #submits per thread
context.nThreads = n // context.n
context.nFinished = 0
context.lock = threading.Lock()
context.event = threading.Event()
for i in range(context.nThreads):
t = threading.Thread(target=self.pendingcalls_thread, args = (context,))
t.start()
threads.append(t)
self.pendingcalls_wait(context.l, n, context)
for t in threads:
t.join()
def pendingcalls_thread(self, context):
try:
self.pendingcalls_submit(context.l, context.n)
finally:
with context.lock:
context.nFinished += 1
nFinished = context.nFinished
if False and test_support.verbose:
print "finished threads: ", nFinished
if nFinished == context.nThreads:
context.event.set()
def test_pendingcalls_non_threaded(self):
#again, just using the main thread, likely they will all be dispatched at
#once. It is ok to ask for too many, because we loop until we find a slot.
#the loop can be interrupted to dispatch.
#there are only 32 dispatch slots, so we go for twice that!
l = []
n = 64
self.pendingcalls_submit(l, n)
self.pendingcalls_wait(l, n)
@unittest.skipUnless(threading and thread, 'Threading required for this test.')
class TestThreadState(unittest.TestCase):
@test_support.reap_threads
def test_thread_state(self):
# some extra thread-state tests driven via _testcapi
def target():
idents = []
def callback():
idents.append(thread.get_ident())
_testcapi._test_thread_state(callback)
a = b = callback
time.sleep(1)
# Check our main thread is in the list exactly 3 times.
self.assertEqual(idents.count(thread.get_ident()), 3,
"Couldn't find main thread correctly in the list")
target()
t = threading.Thread(target=target)
t.start()
t.join()
def test_main():
for name in dir(_testcapi):
if name.startswith('test_'):
test = getattr(_testcapi, name)
if test_support.verbose:
print "internal", name
try:
test()
except _testcapi.error:
raise test_support.TestFailed, sys.exc_info()[1]
test_support.run_unittest(TestPendingCalls, TestThreadState)
if __name__ == "__main__":
test_main()
|
gpl-3.0
|
[
3,
3378,
314,
485,
396,
14145,
859,
2295,
334,
2219,
367,
314,
2018,
15,
35,
3261,
304,
221,
701,
347,
78,
12,
199,
3,
3520,
787,
1006,
3423,
485,
396,
14145,
22609,
7447,
536,
22241,
543,
283,
396,
63,
1370,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
984,
199,
646,
900,
199,
646,
2196,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
893,
26,
272,
492,
2462,
272,
492,
5796,
199,
2590,
3545,
26,
272,
2462,
275,
488,
272,
5796,
275,
488,
199,
3,
8232,
642,
511,
340,
314,
485,
396,
14145,
859,
5712,
1133,
2808,
14,
199,
63,
396,
14145,
275,
511,
63,
4058,
14,
646,
63,
578,
6412,
396,
14145,
358,
421,
199,
32,
2796,
14,
11278,
8,
12562,
12,
283,
4436,
316,
1415,
367,
642,
511,
2659,
199,
533,
1379,
15960,
18287,
8,
2796,
14,
1746,
304,
339,
347,
9413,
5352,
63,
7275,
8,
277,
12,
634,
12,
302,
304,
267,
347,
3233,
837,
288,
327,
3749,
805,
883,
506,
31366,
701,
2462,
31620,
880,
4691,
1159,
288,
327,
1180,
376,
15374,
3439,
288,
634,
14,
740,
8,
403,
9,
398,
367,
284,
315,
1425,
8,
78,
304,
288,
900,
14,
4532,
8,
2355,
14,
2355,
25608,
16,
14,
996,
9,
327,
16,
14,
614,
20091,
641,
8095,
288,
327,
893,
11482,
1337,
3233,
5133,
9512,
14,
288,
327,
264,
590,
641,
5578,
26791,
370,
8976,
4126,
340,
781,
787,
288,
327,
324,
18157,
14,
288,
1830,
715,
26,
355,
340,
485,
396,
14145,
423,
6455,
63,
2671,
1532,
8,
3058,
304,
490,
2059,
27,
339,
347,
9413,
5352,
63,
2573,
8,
277,
12,
634,
12,
302,
12,
1067,
275,
488,
304,
267,
327,
2131,
12,
29404,
6818,
5133,
634,
59,
16,
61,
965,
486,
18406,
370,
1616,
267,
2338,
275,
378,
27,
267,
1830,
822,
8,
76,
9,
1137,
302,
26,
288,
327,
3749,
10414,
89,
4438,
365,
2382,
781,
4282,
370,
506,
31366,
370,
288,
327,
1065,
4154,
13484,
14,
221,
3390,
626,
13484,
787,
1454,
1255,
641,
314,
288,
327,
973,
2462,
288,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
355,
870,
26448,
73,
2924,
2840,
552,
8,
76,
30148,
288,
367,
284,
315,
4945,
8,
5279,
304,
355,
282,
275,
284,
10,
73,
288,
340,
1067,
436,
440,
1067,
14,
1430,
14,
374,
63,
409,
837,
355,
1980,
288,
2338,
847,
413,
288,
291,
14,
1815,
8,
835,
665,
11630,
12,
355,
298,
2593,
10923,
367,
450,
73,
13484,
12,
4788,
450,
73,
14007,
78,
12,
822,
8,
76,
1724,
267,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
288,
870,
26448,
73,
2924,
2840,
552,
8,
76,
16945,
339,
347,
511,
63,
6455,
5352,
63,
19710,
8,
277,
304,
267,
327,
1117,
4036,
3233,
641,
282,
7396,
2462,
267,
302,
275,
4337,
327,
2923,
13484,
267,
7183,
275,
942,
267,
1021,
3925,
8,
785,
304,
1529,
267,
1067,
275,
3925,
342,
267,
1067,
14,
76,
275,
942,
267,
1067,
14,
78,
275,
499,
327,
7275,
83,
1126,
2462,
267,
1067,
14,
78,
22785,
275,
302,
5001,
1067,
14,
78,
267,
1067,
14,
78,
13430,
275,
378,
267,
1067,
14,
831,
275,
5796,
14,
6432,
342,
267,
1067,
14,
1430,
275,
5796,
14,
2390,
342,
398,
367,
284,
315,
1425,
8,
1100,
14,
78,
22785,
304,
288,
307,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
6455,
5352,
63,
2671,
12,
1249,
275,
334,
1100,
4641,
288,
307,
14,
928,
342,
288,
7183,
14,
740,
8,
84,
9,
398,
291,
14,
6455,
5352,
63,
2573,
8,
1100,
14,
76,
12,
302,
12,
1067,
9,
398,
367,
307,
315,
7183,
26,
288,
307,
14,
904,
342,
339,
347,
9413,
5352,
63,
2671,
8,
277,
12,
1067,
304,
267,
862,
26,
288,
291,
14,
6455,
5352,
63,
7275,
8,
1100,
14,
76,
12,
1067,
14,
78,
9,
267,
3753,
26,
288,
543,
1067,
14,
831,
26,
355,
1067,
14,
78,
13430,
847,
413,
355,
302,
13430,
275,
1067,
14,
78,
13430,
355,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
490,
870,
298,
8669,
7183,
26,
3872,
302,
13430,
288,
340,
302,
13430,
508,
1067,
14,
78,
22785,
26,
355,
1067,
14,
1430,
14,
409,
342,
339,
347,
511,
63,
6455,
5352,
63,
2865,
63,
19710,
8,
277,
304,
267,
327,
14199,
12,
2951,
1808,
314,
2446,
2462,
12,
12060,
2985,
911,
1006,
506,
7634,
379,
737,
267,
327,
5089,
14,
221,
2779,
365,
4112,
370,
7198,
367,
4634,
5002,
12,
2952,
781,
4438,
5133,
781,
2342,
282,
9348,
14,
267,
327,
1589,
4438,
883,
506,
31366,
370,
7634,
14,
267,
327,
16990,
787,
1454,
4337,
7634,
14319,
12,
880,
781,
2621,
367,
13373,
626,
1,
267,
634,
275,
942,
267,
302,
275,
5049,
267,
291,
14,
6455,
5352,
63,
7275,
8,
76,
12,
302,
9,
267,
291,
14,
6455,
5352,
63,
2573,
8,
76,
12,
302,
9,
421,
199,
32,
2796,
14,
11278,
8,
12562,
436,
2462,
12,
283,
4436,
316,
1415,
367,
642,
511,
2659,
199,
533,
1379,
4436,
2223,
8,
2796,
14,
1746,
304,
339,
768,
396,
63,
4058,
14,
264,
439,
63,
6962,
272,
347,
511,
63,
2671,
63,
929,
8,
277,
304,
267,
327,
2005,
2402,
2462,
13,
929,
2295,
20921,
1856,
4799,
485,
396,
14145,
267,
347,
1347,
837,
288,
12893,
83,
275,
942,
953,
347,
3233,
837,
355,
12893,
83,
14,
740,
8,
2671,
14,
362,
63,
5425,
1012,
953,
485,
396,
14145,
423,
396,
63,
2671,
63,
929,
8,
3058,
9,
288,
282,
275,
330,
275,
3233,
288,
900,
14,
4532,
8,
17,
9,
288,
327,
2670,
4154,
2446,
2462,
365,
315,
314,
769,
8840,
650,
5431,
14,
288,
291,
14,
629,
8,
5425,
83,
14,
835,
8,
2671,
14,
362,
63,
5425,
4000,
650,
12,
2490,
298,
20485,
1133,
2342,
2446,
2462,
6657,
315,
314,
769,
531,
398,
1347,
342,
267,
307,
275,
5796,
14,
4436,
8,
1375,
29,
1375,
9,
267,
307,
14,
928,
342,
267,
307,
14,
904,
342,
421,
199,
318,
511,
63,
973,
837,
272,
367,
536,
315,
2935,
1547,
396,
14145,
304,
267,
340,
536,
14,
2460,
360,
396,
25865,
288,
511
] |
[
3378,
314,
485,
396,
14145,
859,
2295,
334,
2219,
367,
314,
2018,
15,
35,
3261,
304,
221,
701,
347,
78,
12,
199,
3,
3520,
787,
1006,
3423,
485,
396,
14145,
22609,
7447,
536,
22241,
543,
283,
396,
63,
1370,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
984,
199,
646,
900,
199,
646,
2196,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
893,
26,
272,
492,
2462,
272,
492,
5796,
199,
2590,
3545,
26,
272,
2462,
275,
488,
272,
5796,
275,
488,
199,
3,
8232,
642,
511,
340,
314,
485,
396,
14145,
859,
5712,
1133,
2808,
14,
199,
63,
396,
14145,
275,
511,
63,
4058,
14,
646,
63,
578,
6412,
396,
14145,
358,
421,
199,
32,
2796,
14,
11278,
8,
12562,
12,
283,
4436,
316,
1415,
367,
642,
511,
2659,
199,
533,
1379,
15960,
18287,
8,
2796,
14,
1746,
304,
339,
347,
9413,
5352,
63,
7275,
8,
277,
12,
634,
12,
302,
304,
267,
347,
3233,
837,
288,
327,
3749,
805,
883,
506,
31366,
701,
2462,
31620,
880,
4691,
1159,
288,
327,
1180,
376,
15374,
3439,
288,
634,
14,
740,
8,
403,
9,
398,
367,
284,
315,
1425,
8,
78,
304,
288,
900,
14,
4532,
8,
2355,
14,
2355,
25608,
16,
14,
996,
9,
327,
16,
14,
614,
20091,
641,
8095,
288,
327,
893,
11482,
1337,
3233,
5133,
9512,
14,
288,
327,
264,
590,
641,
5578,
26791,
370,
8976,
4126,
340,
781,
787,
288,
327,
324,
18157,
14,
288,
1830,
715,
26,
355,
340,
485,
396,
14145,
423,
6455,
63,
2671,
1532,
8,
3058,
304,
490,
2059,
27,
339,
347,
9413,
5352,
63,
2573,
8,
277,
12,
634,
12,
302,
12,
1067,
275,
488,
304,
267,
327,
2131,
12,
29404,
6818,
5133,
634,
59,
16,
61,
965,
486,
18406,
370,
1616,
267,
2338,
275,
378,
27,
267,
1830,
822,
8,
76,
9,
1137,
302,
26,
288,
327,
3749,
10414,
89,
4438,
365,
2382,
781,
4282,
370,
506,
31366,
370,
288,
327,
1065,
4154,
13484,
14,
221,
3390,
626,
13484,
787,
1454,
1255,
641,
314,
288,
327,
973,
2462,
288,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
355,
870,
26448,
73,
2924,
2840,
552,
8,
76,
30148,
288,
367,
284,
315,
4945,
8,
5279,
304,
355,
282,
275,
284,
10,
73,
288,
340,
1067,
436,
440,
1067,
14,
1430,
14,
374,
63,
409,
837,
355,
1980,
288,
2338,
847,
413,
288,
291,
14,
1815,
8,
835,
665,
11630,
12,
355,
298,
2593,
10923,
367,
450,
73,
13484,
12,
4788,
450,
73,
14007,
78,
12,
822,
8,
76,
1724,
267,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
288,
870,
26448,
73,
2924,
2840,
552,
8,
76,
16945,
339,
347,
511,
63,
6455,
5352,
63,
19710,
8,
277,
304,
267,
327,
1117,
4036,
3233,
641,
282,
7396,
2462,
267,
302,
275,
4337,
327,
2923,
13484,
267,
7183,
275,
942,
267,
1021,
3925,
8,
785,
304,
1529,
267,
1067,
275,
3925,
342,
267,
1067,
14,
76,
275,
942,
267,
1067,
14,
78,
275,
499,
327,
7275,
83,
1126,
2462,
267,
1067,
14,
78,
22785,
275,
302,
5001,
1067,
14,
78,
267,
1067,
14,
78,
13430,
275,
378,
267,
1067,
14,
831,
275,
5796,
14,
6432,
342,
267,
1067,
14,
1430,
275,
5796,
14,
2390,
342,
398,
367,
284,
315,
1425,
8,
1100,
14,
78,
22785,
304,
288,
307,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
6455,
5352,
63,
2671,
12,
1249,
275,
334,
1100,
4641,
288,
307,
14,
928,
342,
288,
7183,
14,
740,
8,
84,
9,
398,
291,
14,
6455,
5352,
63,
2573,
8,
1100,
14,
76,
12,
302,
12,
1067,
9,
398,
367,
307,
315,
7183,
26,
288,
307,
14,
904,
342,
339,
347,
9413,
5352,
63,
2671,
8,
277,
12,
1067,
304,
267,
862,
26,
288,
291,
14,
6455,
5352,
63,
7275,
8,
1100,
14,
76,
12,
1067,
14,
78,
9,
267,
3753,
26,
288,
543,
1067,
14,
831,
26,
355,
1067,
14,
78,
13430,
847,
413,
355,
302,
13430,
275,
1067,
14,
78,
13430,
355,
340,
756,
436,
511,
63,
4058,
14,
3832,
26,
490,
870,
298,
8669,
7183,
26,
3872,
302,
13430,
288,
340,
302,
13430,
508,
1067,
14,
78,
22785,
26,
355,
1067,
14,
1430,
14,
409,
342,
339,
347,
511,
63,
6455,
5352,
63,
2865,
63,
19710,
8,
277,
304,
267,
327,
14199,
12,
2951,
1808,
314,
2446,
2462,
12,
12060,
2985,
911,
1006,
506,
7634,
379,
737,
267,
327,
5089,
14,
221,
2779,
365,
4112,
370,
7198,
367,
4634,
5002,
12,
2952,
781,
4438,
5133,
781,
2342,
282,
9348,
14,
267,
327,
1589,
4438,
883,
506,
31366,
370,
7634,
14,
267,
327,
16990,
787,
1454,
4337,
7634,
14319,
12,
880,
781,
2621,
367,
13373,
626,
1,
267,
634,
275,
942,
267,
302,
275,
5049,
267,
291,
14,
6455,
5352,
63,
7275,
8,
76,
12,
302,
9,
267,
291,
14,
6455,
5352,
63,
2573,
8,
76,
12,
302,
9,
421,
199,
32,
2796,
14,
11278,
8,
12562,
436,
2462,
12,
283,
4436,
316,
1415,
367,
642,
511,
2659,
199,
533,
1379,
4436,
2223,
8,
2796,
14,
1746,
304,
339,
768,
396,
63,
4058,
14,
264,
439,
63,
6962,
272,
347,
511,
63,
2671,
63,
929,
8,
277,
304,
267,
327,
2005,
2402,
2462,
13,
929,
2295,
20921,
1856,
4799,
485,
396,
14145,
267,
347,
1347,
837,
288,
12893,
83,
275,
942,
953,
347,
3233,
837,
355,
12893,
83,
14,
740,
8,
2671,
14,
362,
63,
5425,
1012,
953,
485,
396,
14145,
423,
396,
63,
2671,
63,
929,
8,
3058,
9,
288,
282,
275,
330,
275,
3233,
288,
900,
14,
4532,
8,
17,
9,
288,
327,
2670,
4154,
2446,
2462,
365,
315,
314,
769,
8840,
650,
5431,
14,
288,
291,
14,
629,
8,
5425,
83,
14,
835,
8,
2671,
14,
362,
63,
5425,
4000,
650,
12,
2490,
298,
20485,
1133,
2342,
2446,
2462,
6657,
315,
314,
769,
531,
398,
1347,
342,
267,
307,
275,
5796,
14,
4436,
8,
1375,
29,
1375,
9,
267,
307,
14,
928,
342,
267,
307,
14,
904,
342,
421,
199,
318,
511,
63,
973,
837,
272,
367,
536,
315,
2935,
1547,
396,
14145,
304,
267,
340,
536,
14,
2460,
360,
396,
25865,
288,
511,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nightjean/Deep-Learning
|
tensorflow/contrib/sparsemax/python/ops/sparsemax.py
|
104
|
2649
|
# 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.
# ==============================================================================
"""Sparsemax op."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn
from tensorflow.python.platform import resource_loader
__all__ = ["sparsemax"]
def sparsemax(logits, name=None):
"""Computes sparsemax activations [1].
For each batch `i` and class `j` we have
sparsemax[i, j] = max(logits[i, j] - tau(logits[i, :]), 0)
[1]: https://arxiv.org/abs/1602.02068
Args:
logits: A `Tensor`. Must be one of the following types: `half`, `float32`,
`float64`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `logits`.
"""
with ops.name_scope(name, "sparsemax", [logits]) as name:
logits = ops.convert_to_tensor(logits, name="logits")
obs = array_ops.shape(logits)[0]
dims = array_ops.shape(logits)[1]
z = logits - math_ops.reduce_mean(logits, axis=1)[:, array_ops.newaxis]
# sort z
z_sorted, _ = nn.top_k(z, k=dims)
# calculate k(z)
z_cumsum = math_ops.cumsum(z_sorted, axis=1)
k = math_ops.range(
1, math_ops.cast(dims, logits.dtype) + 1, dtype=logits.dtype)
z_check = 1 + k * z_sorted > z_cumsum
# because the z_check vector is always [1,1,...1,0,0,...0] finding the
# (index + 1) of the last `1` is the same as just summing the number of 1.
k_z = math_ops.reduce_sum(math_ops.cast(z_check, dtypes.int32), axis=1)
# calculate tau(z)
indices = array_ops.stack([math_ops.range(0, obs), k_z - 1], axis=1)
tau_sum = array_ops.gather_nd(z_cumsum, indices)
tau_z = (tau_sum - 1) / math_ops.cast(k_z, logits.dtype)
# calculate p
return math_ops.maximum(
math_ops.cast(0, logits.dtype), z - tau_z[:, array_ops.newaxis])
|
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,
8629,
988,
1687,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2073,
63,
3422,
199,
199,
363,
452,
363,
275,
2097,
4421,
988,
937,
421,
199,
318,
5178,
988,
8,
10492,
12,
536,
29,
403,
304,
523,
408,
22594,
5178,
988,
32038,
359,
17,
1055,
819,
2104,
1924,
3522,
658,
73,
64,
436,
1021,
658,
74,
64,
781,
1172,
272,
5178,
988,
59,
73,
12,
1335,
61,
275,
1390,
8,
10492,
59,
73,
12,
1335,
61,
446,
19188,
8,
10492,
59,
73,
12,
520,
2522,
378,
9,
819,
359,
17,
2189,
4178,
921,
27290,
14,
1308,
15,
2101,
15,
975,
996,
14,
996,
19846,
819,
3033,
26,
272,
11051,
26,
437,
658,
3861,
2313,
9498,
506,
1373,
402,
314,
2569,
2943,
26,
658,
10220,
3559,
658,
1609,
708,
3559,
489,
658,
1609,
772,
2313,
272,
536,
26,
437,
536,
367,
314,
3439,
334,
4144,
680,
819,
1803,
26,
272,
437,
658,
3861,
2313,
13481,
314,
2011,
730,
465,
658,
10492,
2313,
523,
408,
819,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
298,
4421,
988,
401,
359,
10492,
566,
465,
536,
26,
272,
11051,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
10492,
12,
536,
628,
10492,
531,
272,
16087,
275,
1625,
63,
1483,
14,
1392,
8,
10492,
2788,
16,
61,
272,
17476,
275,
1625,
63,
1483,
14,
1392,
8,
10492,
2788,
17,
61,
339,
1315,
275,
11051,
446,
3473,
63,
1483,
14,
5270,
63,
3670,
8,
10492,
12,
3114,
29,
17,
24517,
1625,
63,
1483,
14,
14483,
61,
339,
327,
4069,
1315,
272,
1315,
63,
5917,
12,
485,
275,
11542,
14,
2119,
63,
75,
8,
90,
12,
1022,
29,
5380,
9,
339,
327,
8671,
1022,
8,
90,
9,
272,
1315,
63,
23916,
275,
3473,
63,
1483,
14,
23916,
8,
90,
63,
5917,
12,
3114,
29,
17,
9,
272,
1022,
275,
3473,
63,
1483,
14,
1842,
8,
267,
413,
12,
3473,
63,
1483,
14,
2931,
8,
5380,
12,
11051,
14,
2271,
9,
435,
413,
12,
2152,
29,
10492,
14,
2271,
9,
272,
1315,
63,
1074,
275,
413,
435,
1022,
627,
1315,
63,
5917,
690,
1315,
63,
23916,
272,
327,
2952,
314,
1315,
63,
1074,
5477,
365,
3544,
359,
17,
12,
17,
12,
1396,
17,
12,
16,
12,
16,
12,
1396,
16,
61,
17196,
314,
272,
327,
334,
1080,
435,
413,
9,
402,
314,
2061,
658,
17,
64,
365,
314,
2011,
465,
2951,
3089,
14566,
314,
1329,
402,
413,
14,
272,
1022,
63,
90,
275,
3473,
63,
1483,
14,
5270,
63,
1838,
8,
3442,
63,
1483,
14,
2931,
8,
90,
63,
1074,
12,
6674,
14,
442,
708,
395,
3114,
29,
17,
9,
339,
327,
8671,
19188,
8,
90,
9,
272,
4918,
275,
1625,
63,
1483,
14,
2340,
779,
3442,
63,
1483,
14,
1842,
8,
16,
12,
16087,
395,
1022,
63,
90,
446,
413,
467,
3114,
29,
17,
9,
272,
19188,
63,
1838,
275,
1625,
63,
1483,
14,
13737,
63,
977,
8,
90,
63,
23916,
12,
4918,
9,
272,
19188,
63,
90,
275,
334,
16656,
63,
1838,
446,
413,
9,
1182,
3473,
63,
1483,
14,
2931,
8,
75,
63,
90,
12,
11051,
14,
2271,
9,
339,
327,
8671,
299,
272,
372,
3473,
63,
1483,
14,
11555,
8,
267,
3473,
63,
1483,
14,
2931,
8,
16,
12,
11051,
14,
2271,
395,
1315,
446,
19188,
63,
90,
3981,
1625,
63,
1483,
14,
14483,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
8629,
988,
1687,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2073,
63,
3422,
199,
199,
363,
452,
363,
275,
2097,
4421,
988,
937,
421,
199,
318,
5178,
988,
8,
10492,
12,
536,
29,
403,
304,
523,
408,
22594,
5178,
988,
32038,
359,
17,
1055,
819,
2104,
1924,
3522,
658,
73,
64,
436,
1021,
658,
74,
64,
781,
1172,
272,
5178,
988,
59,
73,
12,
1335,
61,
275,
1390,
8,
10492,
59,
73,
12,
1335,
61,
446,
19188,
8,
10492,
59,
73,
12,
520,
2522,
378,
9,
819,
359,
17,
2189,
4178,
921,
27290,
14,
1308,
15,
2101,
15,
975,
996,
14,
996,
19846,
819,
3033,
26,
272,
11051,
26,
437,
658,
3861,
2313,
9498,
506,
1373,
402,
314,
2569,
2943,
26,
658,
10220,
3559,
658,
1609,
708,
3559,
489,
658,
1609,
772,
2313,
272,
536,
26,
437,
536,
367,
314,
3439,
334,
4144,
680,
819,
1803,
26,
272,
437,
658,
3861,
2313,
13481,
314,
2011,
730,
465,
658,
10492,
2313,
523,
408,
819,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
298,
4421,
988,
401,
359,
10492,
566,
465,
536,
26,
272,
11051,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
10492,
12,
536,
628,
10492,
531,
272,
16087,
275,
1625,
63,
1483,
14,
1392,
8,
10492,
2788,
16,
61,
272,
17476,
275,
1625,
63,
1483,
14,
1392,
8,
10492,
2788,
17,
61,
339,
1315,
275,
11051,
446,
3473,
63,
1483,
14,
5270,
63,
3670,
8,
10492,
12,
3114,
29,
17,
24517,
1625,
63,
1483,
14,
14483,
61,
339,
327,
4069,
1315,
272,
1315,
63,
5917,
12,
485,
275,
11542,
14,
2119,
63,
75,
8,
90,
12,
1022,
29,
5380,
9,
339,
327,
8671,
1022,
8,
90,
9,
272,
1315,
63,
23916,
275,
3473,
63,
1483,
14,
23916,
8,
90,
63,
5917,
12,
3114,
29,
17,
9,
272,
1022,
275,
3473,
63,
1483,
14,
1842,
8,
267,
413,
12,
3473,
63,
1483,
14,
2931,
8,
5380,
12,
11051,
14,
2271,
9,
435,
413,
12,
2152,
29,
10492,
14,
2271,
9,
272,
1315,
63,
1074,
275,
413,
435,
1022,
627,
1315,
63,
5917,
690,
1315,
63,
23916,
272,
327,
2952,
314,
1315,
63,
1074,
5477,
365,
3544,
359,
17,
12,
17,
12,
1396,
17,
12,
16,
12,
16,
12,
1396,
16,
61,
17196,
314,
272,
327,
334,
1080,
435,
413,
9,
402,
314,
2061,
658,
17,
64,
365,
314,
2011,
465,
2951,
3089,
14566,
314,
1329,
402,
413,
14,
272,
1022,
63,
90,
275,
3473,
63,
1483,
14,
5270,
63,
1838,
8,
3442,
63,
1483,
14,
2931,
8,
90,
63,
1074,
12,
6674,
14,
442,
708,
395,
3114,
29,
17,
9,
339,
327,
8671,
19188,
8,
90,
9,
272,
4918,
275,
1625,
63,
1483,
14,
2340,
779,
3442,
63,
1483,
14,
1842,
8,
16,
12,
16087,
395,
1022,
63,
90,
446,
413,
467,
3114,
29,
17,
9,
272,
19188,
63,
1838,
275,
1625,
63,
1483,
14,
13737,
63,
977,
8,
90,
63,
23916,
12,
4918,
9,
272,
19188,
63,
90,
275,
334,
16656,
63,
1838,
446,
413,
9,
1182,
3473,
63,
1483,
14,
2931,
8,
75,
63,
90,
12,
11051,
14,
2271,
9,
339,
327,
8671,
299,
272,
372,
3473,
63,
1483,
14,
11555,
8,
267,
3473,
63,
1483,
14,
2931,
8,
16,
12,
11051,
14,
2271,
395,
1315,
446,
19188,
63,
90,
3981,
1625,
63,
1483,
14,
14483,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dan-ionut-fechete/ev3
|
test/test_ev3_motor.py
|
1
|
1650
|
from ev3.ev3dev import Motor
import unittest
import time
from util import get_input
class TestMotor(unittest.TestCase):
get_input('Attach a motor on port A then continue')
def __init__(self,*args, **kwargs):
super(TestMotor, self).__init__(*args, **kwargs)
self.d=Motor(port=Motor.PORT.A)
def setUp(self):
self.d.reset()
def test_run(self):
self.d.run_mode = 'forever'
self.d.regulation_mode = True
self.d.pulses_per_second_sp = 200
self.d.start()
time.sleep(5)
self.d.stop()
def test_run_forever(self):
self.d.run_forever(50, regulation_mode=False)
time.sleep(5)
self.d.stop()
self.d.run_forever(200, regulation_mode=True)
time.sleep(5)
self.d.stop()
def test_run_time_limited(self):
self.d.run_time_limited(time_sp=10000, speed_sp=80, regulation_mode=False,
stop_mode=Motor.STOP_MODE.COAST, ramp_up_sp=1000, ramp_down_sp=1000)
time.sleep(12)
def test_run_position_limited(self):
self.d.position=0
self.d.run_position_limited(position_sp=360, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE , ramp_up_sp=1000, ramp_down_sp=1000)
time.sleep(5)
def test_run_position_limited_relative (self):
self.d.position_mode=Motor.POSITION_MODE.RELATIVE
self.d.run_position_limited(position_sp=160, speed_sp=800,
stop_mode=Motor.STOP_MODE.BRAKE , ramp_up_sp=1000, ramp_down_sp=1000)
time.sleep(5)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
504,
8145,
19,
14,
6857,
19,
2374,
492,
603,
13147,
199,
646,
2882,
199,
646,
900,
199,
504,
4884,
492,
664,
63,
1210,
199,
199,
533,
1379,
31642,
8,
2796,
14,
1746,
304,
272,
664,
63,
1210,
360,
13240,
282,
28496,
641,
1844,
437,
2066,
1980,
358,
272,
347,
636,
826,
721,
277,
19166,
589,
12,
1011,
958,
304,
267,
1613,
8,
774,
31642,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
18418,
291,
14,
68,
29,
31642,
8,
719,
29,
31642,
14,
3657,
14,
33,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
68,
14,
3958,
342,
339,
347,
511,
63,
1065,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
632,
275,
283,
21327,
7,
267,
291,
14,
68,
14,
1135,
5332,
63,
632,
275,
715,
267,
291,
14,
68,
14,
80,
348,
874,
63,
529,
63,
4375,
63,
681,
275,
1926,
267,
291,
14,
68,
14,
928,
342,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
339,
347,
511,
63,
1065,
63,
21327,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
21327,
8,
1400,
12,
1295,
5332,
63,
632,
29,
797,
9,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
267,
291,
14,
68,
14,
1065,
63,
21327,
8,
1840,
12,
1295,
5332,
63,
632,
29,
549,
9,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
339,
347,
511,
63,
1065,
63,
521,
63,
14136,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
521,
63,
14136,
8,
521,
63,
681,
29,
9943,
12,
8112,
63,
681,
29,
1257,
12,
1295,
5332,
63,
632,
29,
797,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
1439,
11307,
12,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
713,
9,
272,
347,
511,
63,
1065,
63,
3124,
63,
14136,
8,
277,
304,
267,
291,
14,
68,
14,
3124,
29,
16,
267,
291,
14,
68,
14,
1065,
63,
3124,
63,
14136,
8,
3124,
63,
681,
29,
11197,
12,
8112,
63,
681,
29,
6718,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
34,
2847,
2430,
2360,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
21,
9,
339,
347,
511,
63,
1065,
63,
3124,
63,
14136,
63,
6188,
334,
277,
304,
18418,
291,
14,
68,
14,
3124,
63,
632,
29,
31642,
14,
15717,
63,
6963,
14,
13604,
14277,
267,
291,
14,
68,
14,
1065,
63,
3124,
63,
14136,
8,
3124,
63,
681,
29,
8488,
12,
8112,
63,
681,
29,
6718,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
34,
2847,
2430,
2360,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
21,
9,
9948,
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
] |
[
8145,
19,
14,
6857,
19,
2374,
492,
603,
13147,
199,
646,
2882,
199,
646,
900,
199,
504,
4884,
492,
664,
63,
1210,
199,
199,
533,
1379,
31642,
8,
2796,
14,
1746,
304,
272,
664,
63,
1210,
360,
13240,
282,
28496,
641,
1844,
437,
2066,
1980,
358,
272,
347,
636,
826,
721,
277,
19166,
589,
12,
1011,
958,
304,
267,
1613,
8,
774,
31642,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
18418,
291,
14,
68,
29,
31642,
8,
719,
29,
31642,
14,
3657,
14,
33,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
68,
14,
3958,
342,
339,
347,
511,
63,
1065,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
632,
275,
283,
21327,
7,
267,
291,
14,
68,
14,
1135,
5332,
63,
632,
275,
715,
267,
291,
14,
68,
14,
80,
348,
874,
63,
529,
63,
4375,
63,
681,
275,
1926,
267,
291,
14,
68,
14,
928,
342,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
339,
347,
511,
63,
1065,
63,
21327,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
21327,
8,
1400,
12,
1295,
5332,
63,
632,
29,
797,
9,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
267,
291,
14,
68,
14,
1065,
63,
21327,
8,
1840,
12,
1295,
5332,
63,
632,
29,
549,
9,
267,
900,
14,
4532,
8,
21,
9,
267,
291,
14,
68,
14,
2379,
342,
339,
347,
511,
63,
1065,
63,
521,
63,
14136,
8,
277,
304,
267,
291,
14,
68,
14,
1065,
63,
521,
63,
14136,
8,
521,
63,
681,
29,
9943,
12,
8112,
63,
681,
29,
1257,
12,
1295,
5332,
63,
632,
29,
797,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
1439,
11307,
12,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
713,
9,
272,
347,
511,
63,
1065,
63,
3124,
63,
14136,
8,
277,
304,
267,
291,
14,
68,
14,
3124,
29,
16,
267,
291,
14,
68,
14,
1065,
63,
3124,
63,
14136,
8,
3124,
63,
681,
29,
11197,
12,
8112,
63,
681,
29,
6718,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
34,
2847,
2430,
2360,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
21,
9,
339,
347,
511,
63,
1065,
63,
3124,
63,
14136,
63,
6188,
334,
277,
304,
18418,
291,
14,
68,
14,
3124,
63,
632,
29,
31642,
14,
15717,
63,
6963,
14,
13604,
14277,
267,
291,
14,
68,
14,
1065,
63,
3124,
63,
14136,
8,
3124,
63,
681,
29,
8488,
12,
8112,
63,
681,
29,
6718,
12,
2574,
3631,
63,
632,
29,
31642,
14,
11632,
63,
6963,
14,
34,
2847,
2430,
2360,
660,
311,
63,
384,
63,
681,
29,
5279,
12,
660,
311,
63,
2110,
63,
681,
29,
5279,
9,
267,
900,
14,
4532,
8,
21,
9,
9948,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ajaxsys/dict-admin
|
docutils/writers/s5_html/__init__.py
|
2
|
14734
|
# $Id: __init__.py 7025 2011-05-05 23:19:51Z milde $
# Authors: Chris Liechti <cliechti@gmx.net>;
# David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.
"""
S5/HTML Slideshow Writer.
"""
__docformat__ = 'reStructuredText'
import sys
import os
import re
import docutils
from docutils import frontend, nodes, utils
from docutils.writers import html4css1
from docutils.parsers.rst import directives
from docutils._compat import b
themes_dir_path = utils.relative_path(
os.path.join(os.getcwd(), 'dummy'),
os.path.join(os.path.dirname(__file__), 'themes'))
def find_theme(name):
# Where else to look for a theme?
# Check working dir? Destination dir? Config dir? Plugins dir?
path = os.path.join(themes_dir_path, name)
if not os.path.isdir(path):
raise docutils.ApplicationError(
'Theme directory not found: %r (path: %r)' % (name, path))
return path
class Writer(html4css1.Writer):
settings_spec = html4css1.Writer.settings_spec + (
'S5 Slideshow Specific Options',
'For the S5/HTML writer, the --no-toc-backlinks option '
'(defined in General Docutils Options above) is the default, '
'and should not be changed.',
(('Specify an installed S5 theme by name. Overrides --theme-url. '
'The default theme name is "default". The theme files will be '
'copied into a "ui/<theme>" directory, in the same directory as the '
'destination file (output HTML). Note that existing theme files '
'will not be overwritten (unless --overwrite-theme-files is used).',
['--theme'],
{'default': 'default', 'metavar': '<name>',
'overrides': 'theme_url'}),
('Specify an S5 theme URL. The destination file (output HTML) will '
'link to this theme; nothing will be copied. Overrides --theme.',
['--theme-url'],
{'metavar': '<URL>', 'overrides': 'theme'}),
('Allow existing theme files in the ``ui/<theme>`` directory to be '
'overwritten. The default is not to overwrite theme files.',
['--overwrite-theme-files'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),
('Keep existing theme files in the ``ui/<theme>`` directory; do not '
'overwrite any. This is the default.',
['--keep-theme-files'],
{'dest': 'overwrite_theme_files', 'action': 'store_false'}),
('Set the initial view mode to "slideshow" [default] or "outline".',
['--view-mode'],
{'choices': ['slideshow', 'outline'], 'default': 'slideshow',
'metavar': '<mode>'}),
('Normally hide the presentation controls in slideshow mode. '
'This is the default.',
['--hidden-controls'],
{'action': 'store_true', 'default': True,
'validator': frontend.validate_boolean}),
('Always show the presentation controls in slideshow mode. '
'The default is to hide the controls.',
['--visible-controls'],
{'dest': 'hidden_controls', 'action': 'store_false'}),
('Enable the current slide indicator ("1 / 15"). '
'The default is to disable it.',
['--current-slide'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),
('Disable the current slide indicator. This is the default.',
['--no-current-slide'],
{'dest': 'current_slide', 'action': 'store_false'}),))
settings_default_overrides = {'toc_backlinks': 0}
config_section = 's5_html writer'
config_section_dependencies = ('writers', 'html4css1 writer')
def __init__(self):
html4css1.Writer.__init__(self)
self.translator_class = S5HTMLTranslator
class S5HTMLTranslator(html4css1.HTMLTranslator):
s5_stylesheet_template = """\
<!-- configuration parameters -->
<meta name="defaultView" content="%(view_mode)s" />
<meta name="controlVis" content="%(control_visibility)s" />
<!-- style sheet links -->
<script src="%(path)s/slides.js" type="text/javascript"></script>
<link rel="stylesheet" href="%(path)s/slides.css"
type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="%(path)s/outline.css"
type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="%(path)s/print.css"
type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="%(path)s/opera.css"
type="text/css" media="projection" id="operaFix" />\n"""
# The script element must go in front of the link elements to
# avoid a flash of unstyled content (FOUC), reproducible with
# Firefox.
disable_current_slide = """
<style type="text/css">
#currentSlide {display: none;}
</style>\n"""
layout_template = """\
<div class="layout">
<div id="controls"></div>
<div id="currentSlide"></div>
<div id="header">
%(header)s
</div>
<div id="footer">
%(title)s%(footer)s
</div>
</div>\n"""
# <div class="topleft"></div>
# <div class="topright"></div>
# <div class="bottomleft"></div>
# <div class="bottomright"></div>
default_theme = 'default'
"""Name of the default theme."""
base_theme_file = '__base__'
"""Name of the file containing the name of the base theme."""
direct_theme_files = (
'slides.css', 'outline.css', 'print.css', 'opera.css', 'slides.js')
"""Names of theme files directly linked to in the output HTML"""
indirect_theme_files = (
's5-core.css', 'framing.css', 'pretty.css', 'blank.gif', 'iepngfix.htc')
"""Names of files used indirectly; imported or used by files in
`direct_theme_files`."""
required_theme_files = indirect_theme_files + direct_theme_files
"""Names of mandatory theme files."""
def __init__(self, *args):
html4css1.HTMLTranslator.__init__(self, *args)
#insert S5-specific stylesheet and script stuff:
self.theme_file_path = None
self.setup_theme()
view_mode = self.document.settings.view_mode
control_visibility = ('visible', 'hidden')[self.document.settings
.hidden_controls]
self.stylesheet.append(self.s5_stylesheet_template
% {'path': self.theme_file_path,
'view_mode': view_mode,
'control_visibility': control_visibility})
if not self.document.settings.current_slide:
self.stylesheet.append(self.disable_current_slide)
self.add_meta('<meta name="version" content="S5 1.1" />\n')
self.s5_footer = []
self.s5_header = []
self.section_count = 0
self.theme_files_copied = None
def setup_theme(self):
if self.document.settings.theme:
self.copy_theme()
elif self.document.settings.theme_url:
self.theme_file_path = self.document.settings.theme_url
else:
raise docutils.ApplicationError(
'No theme specified for S5/HTML writer.')
def copy_theme(self):
"""
Locate & copy theme files.
A theme may be explicitly based on another theme via a '__base__'
file. The default base theme is 'default'. Files are accumulated
from the specified theme, any base themes, and 'default'.
"""
settings = self.document.settings
path = find_theme(settings.theme)
theme_paths = [path]
self.theme_files_copied = {}
required_files_copied = {}
# This is a link (URL) in HTML, so we use "/", not os.sep:
self.theme_file_path = '%s/%s' % ('ui', settings.theme)
if settings._destination:
dest = os.path.join(
os.path.dirname(settings._destination), 'ui', settings.theme)
if not os.path.isdir(dest):
os.makedirs(dest)
else:
# no destination, so we can't copy the theme
return
default = 0
while path:
for f in os.listdir(path): # copy all files from each theme
if f == self.base_theme_file:
continue # ... except the "__base__" file
if ( self.copy_file(f, path, dest)
and f in self.required_theme_files):
required_files_copied[f] = 1
if default:
break # "default" theme has no base theme
# Find the "__base__" file in theme directory:
base_theme_file = os.path.join(path, self.base_theme_file)
# If it exists, read it and record the theme path:
if os.path.isfile(base_theme_file):
lines = open(base_theme_file).readlines()
for line in lines:
line = line.strip()
if line and not line.startswith('#'):
path = find_theme(line)
if path in theme_paths: # check for duplicates (cycles)
path = None # if found, use default base
else:
theme_paths.append(path)
break
else: # no theme name found
path = None # use default base
else: # no base theme file found
path = None # use default base
if not path:
path = find_theme(self.default_theme)
theme_paths.append(path)
default = 1
if len(required_files_copied) != len(self.required_theme_files):
# Some required files weren't found & couldn't be copied.
required = list(self.required_theme_files)
for f in required_files_copied.keys():
required.remove(f)
raise docutils.ApplicationError(
'Theme files not found: %s'
% ', '.join(['%r' % f for f in required]))
files_to_skip_pattern = re.compile(r'~$|\.bak$|#$|\.cvsignore$')
def copy_file(self, name, source_dir, dest_dir):
"""
Copy file `name` from `source_dir` to `dest_dir`.
Return 1 if the file exists in either `source_dir` or `dest_dir`.
"""
source = os.path.join(source_dir, name)
dest = os.path.join(dest_dir, name)
if dest in self.theme_files_copied:
return 1
else:
self.theme_files_copied[dest] = 1
if os.path.isfile(source):
if self.files_to_skip_pattern.search(source):
return None
settings = self.document.settings
if os.path.exists(dest) and not settings.overwrite_theme_files:
settings.record_dependencies.add(dest)
else:
src_file = open(source, 'rb')
src_data = src_file.read()
src_file.close()
dest_file = open(dest, 'wb')
dest_dir = dest_dir.replace(os.sep, '/')
dest_file.write(src_data.replace(
b('ui/default'),
dest_dir[dest_dir.rfind('ui/'):].encode(
sys.getfilesystemencoding())))
dest_file.close()
settings.record_dependencies.add(source)
return 1
if os.path.isfile(dest):
return 1
def depart_document(self, node):
self.head_prefix.extend([self.doctype,
self.head_prefix_template %
{'lang': self.settings.language_code}])
self.html_prolog.append(self.doctype)
self.meta.insert(0, self.content_type % self.settings.output_encoding)
self.head.insert(0, self.content_type % self.settings.output_encoding)
header = ''.join(self.s5_header)
footer = ''.join(self.s5_footer)
title = ''.join(self.html_title).replace('<h1 class="title">', '<h1>')
layout = self.layout_template % {'header': header,
'title': title,
'footer': footer}
self.fragment.extend(self.body)
self.body_prefix.extend(layout)
self.body_prefix.append('<div class="presentation">\n')
self.body_prefix.append(
self.starttag({'classes': ['slide'], 'ids': ['slide0']}, 'div'))
if not self.section_count:
self.body.append('</div>\n')
self.body_suffix.insert(0, '</div>\n')
# skip content-type meta tag with interpolated charset value:
self.html_head.extend(self.head[1:])
self.html_body.extend(self.body_prefix[1:] + self.body_pre_docinfo
+ self.docinfo + self.body
+ self.body_suffix[:-1])
def depart_footer(self, node):
start = self.context.pop()
self.s5_footer.append('<h2>')
self.s5_footer.extend(self.body[start:])
self.s5_footer.append('</h2>')
del self.body[start:]
def depart_header(self, node):
start = self.context.pop()
header = ['<div id="header">\n']
header.extend(self.body[start:])
header.append('\n</div>\n')
del self.body[start:]
self.s5_header.extend(header)
def visit_section(self, node):
if not self.section_count:
self.body.append('\n</div>\n')
self.section_count += 1
self.section_level += 1
if self.section_level > 1:
# dummy for matching div's
self.body.append(self.starttag(node, 'div', CLASS='section'))
else:
self.body.append(self.starttag(node, 'div', CLASS='slide'))
def visit_subtitle(self, node):
if isinstance(node.parent, nodes.section):
level = self.section_level + self.initial_header_level - 1
if level == 1:
level = 2
tag = 'h%s' % level
self.body.append(self.starttag(node, tag, ''))
self.context.append('</%s>\n' % tag)
else:
html4css1.HTMLTranslator.visit_subtitle(self, node)
def visit_title(self, node):
html4css1.HTMLTranslator.visit_title(self, node)
|
bsd-3-clause
|
[
3,
2672,
1304,
26,
636,
826,
4343,
647,
10045,
821,
7760,
13,
1717,
13,
1717,
6546,
26,
1167,
26,
2869,
58,
333,
24446,
2672,
202,
199,
3,
6642,
26,
2799,
5719,
491,
1873,
335,
280,
665,
2764,
12736,
280,
32,
71,
9457,
14,
846,
30,
27,
202,
199,
3,
3515,
20232,
22311,
836,
665,
8302,
836,
32,
1548,
14,
1308,
30,
202,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
2999,
199,
624,
202,
199,
51,
21,
15,
4943,
428,
8409,
2384,
24441,
14,
202,
199,
624,
2999,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
8065,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
295,
202,
199,
646,
18382,
202,
199,
504,
18382,
492,
22523,
12,
3380,
12,
3778,
202,
199,
504,
18382,
14,
26224,
492,
3517,
20,
3919,
17,
202,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
202,
199,
504,
18382,
423,
5819,
492,
330,
2999,
199,
23900,
63,
694,
63,
515,
275,
3778,
14,
6188,
63,
515,
8,
1128,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
283,
5869,
659,
1128,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
23900,
1333,
2999,
199,
318,
2342,
63,
7915,
8,
354,
304,
1128,
327,
17685,
587,
370,
3648,
367,
282,
8879,
31,
1128,
327,
2670,
6449,
2935,
31,
221,
28505,
2935,
31,
221,
4094,
2935,
31,
221,
30317,
2935,
31,
1128,
931,
275,
747,
14,
515,
14,
904,
8,
23900,
63,
694,
63,
515,
12,
536,
9,
1128,
340,
440,
747,
14,
515,
14,
6027,
8,
515,
304,
1039,
746,
18382,
14,
5039,
547,
8,
1675,
283,
16849,
2082,
440,
1911,
26,
450,
82,
334,
515,
26,
450,
82,
3171,
450,
334,
354,
12,
931,
430,
1128,
372,
931,
8065,
199,
533,
24441,
8,
1360,
20,
3919,
17,
14,
6261,
304,
2958,
2202,
63,
1650,
275,
3517,
20,
3919,
17,
14,
6261,
14,
1751,
63,
1650,
435,
334,
1039,
283,
51,
21,
428,
8409,
2384,
20411,
8394,
297,
1039,
283,
1858,
314,
428,
21,
15,
4943,
7060,
12,
314,
1553,
889,
13,
13255,
13,
894,
4614,
945,
283,
1039,
8189,
4037,
315,
1696,
5454,
1208,
8394,
3432,
9,
365,
314,
849,
12,
283,
1039,
283,
460,
1077,
440,
506,
2896,
3130,
1039,
13636,
17768,
376,
4903,
428,
21,
8879,
701,
536,
14,
221,
31144,
1553,
7915,
13,
633,
14,
221,
283,
16765,
283,
1918,
849,
8879,
536,
365,
298,
885,
1674,
221,
710,
8879,
1584,
911,
506,
283,
16765,
283,
23581,
1901,
282,
298,
1907,
8316,
7915,
4335,
2082,
12,
315,
314,
2011,
2082,
465,
314,
283,
16765,
283,
6881,
570,
334,
1199,
4163,
680,
221,
3390,
626,
3411,
8879,
1584,
283,
16765,
283,
14117,
440,
506,
20200,
334,
18447,
1553,
14658,
13,
7915,
13,
1725,
365,
1202,
680,
297,
16765,
14574,
7915,
995,
16765,
791,
885,
356,
283,
885,
297,
283,
23303,
356,
2650,
354,
4206,
18691,
283,
12867,
356,
283,
7915,
63,
633,
1604,
8740,
661,
17768,
376,
428,
21,
8879,
2851,
14,
221,
710,
5724,
570,
334,
1199,
4163,
9,
911,
283,
16765,
283,
1073,
370,
642,
8879,
27,
6548,
911,
506,
8876,
14,
221,
31144,
1553,
7915,
3130,
16765,
14574,
7915,
13,
633,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
12867,
356,
283,
7915,
1604,
8740,
661,
7852,
3411,
8879,
1584,
315,
314,
1124,
1907,
8316,
7915,
28210,
2082,
370,
506,
283,
16765,
283,
1883,
8938,
14,
221,
710,
849,
365,
440,
370,
8970,
8879,
1584,
3130,
16765,
14574,
14658,
13,
7915,
13,
1725,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
18567,
3411,
8879,
1584,
315,
314,
1124,
1907,
8316,
7915,
28210,
2082,
27,
886,
440,
283,
16765,
283,
14658,
1263,
14,
221,
961,
365,
314,
849,
3130,
16765,
14574,
3250,
13,
7915,
13,
1725,
995,
16765,
791,
2614,
356,
283,
14658,
63,
7915,
63,
1725,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
8740,
661,
1084,
314,
2536,
2455,
818,
370,
298,
19968,
2384,
2,
359,
885,
61,
503,
298,
11550,
1674,
297,
16765,
14574,
1345,
13,
632,
995,
16765,
791,
4577,
356,
788,
19968,
2384,
297,
283,
11550,
995,
283,
885,
356,
283,
19968,
2384,
297,
18691,
283,
23303,
356,
2650,
632,
30,
1604,
8740,
661,
15548,
1183,
13714,
314,
3451,
425,
13467,
315,
27063,
2384,
818,
14,
283,
16765,
283,
2765,
365,
314,
849,
3130,
16765,
14574,
5642,
13,
13658,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
885,
356,
715,
12,
18691,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
2439,
2885,
2498,
314,
3451,
425,
13467,
315,
27063,
2384,
818,
14,
221,
283,
16765,
283,
1918,
849,
365,
370,
13714,
314,
13467,
3130,
16765,
14574,
6604,
13,
13658,
995,
16765,
791,
2614,
356,
283,
5642,
63,
13658,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
8740,
661,
6476,
314,
1453,
27063,
16385,
1689,
17,
1182,
4114,
3471,
221,
283,
16765,
283,
1918,
849,
365,
370,
3507,
652,
3130,
16765,
14574,
1818,
13,
19968,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
13707,
314,
1453,
27063,
16385,
14,
221,
961,
365,
314,
849,
3130,
16765,
14574,
889,
13,
1818,
13,
19968,
995,
16765,
791,
2614,
356,
283,
1818,
63,
19968,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
430,
2958,
2202,
63,
885,
63,
12867,
275,
791,
13255,
63,
894,
4614,
356,
378,
93,
2958,
1101,
63,
2792,
275,
283,
83,
21,
63,
1360,
7060,
7,
1128,
1101,
63,
2792,
63,
5714,
275,
661,
26224,
297,
283,
1360,
20,
3919,
17,
7060,
358,
2958,
347,
636,
826,
721,
277,
304,
1039,
3517,
20,
3919,
17,
14,
6261,
855,
826,
721,
277,
9,
1039,
291,
14,
29346,
63,
533,
275,
428,
21,
4943,
26059,
8065,
199,
533,
428,
21,
4943,
26059,
8,
1360,
20,
3919,
17,
14,
4943,
26059,
304,
2958,
308,
21,
63,
15479,
63,
1160,
275,
9638,
202,
199,
25273,
2897,
2633,
10541,
202,
199,
28,
2024,
536,
628,
885,
2768,
2,
1564,
17662,
1345
] |
[
2672,
1304,
26,
636,
826,
4343,
647,
10045,
821,
7760,
13,
1717,
13,
1717,
6546,
26,
1167,
26,
2869,
58,
333,
24446,
2672,
202,
199,
3,
6642,
26,
2799,
5719,
491,
1873,
335,
280,
665,
2764,
12736,
280,
32,
71,
9457,
14,
846,
30,
27,
202,
199,
3,
3515,
20232,
22311,
836,
665,
8302,
836,
32,
1548,
14,
1308,
30,
202,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
2999,
199,
624,
202,
199,
51,
21,
15,
4943,
428,
8409,
2384,
24441,
14,
202,
199,
624,
2999,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
8065,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
295,
202,
199,
646,
18382,
202,
199,
504,
18382,
492,
22523,
12,
3380,
12,
3778,
202,
199,
504,
18382,
14,
26224,
492,
3517,
20,
3919,
17,
202,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
202,
199,
504,
18382,
423,
5819,
492,
330,
2999,
199,
23900,
63,
694,
63,
515,
275,
3778,
14,
6188,
63,
515,
8,
1128,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
283,
5869,
659,
1128,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
23900,
1333,
2999,
199,
318,
2342,
63,
7915,
8,
354,
304,
1128,
327,
17685,
587,
370,
3648,
367,
282,
8879,
31,
1128,
327,
2670,
6449,
2935,
31,
221,
28505,
2935,
31,
221,
4094,
2935,
31,
221,
30317,
2935,
31,
1128,
931,
275,
747,
14,
515,
14,
904,
8,
23900,
63,
694,
63,
515,
12,
536,
9,
1128,
340,
440,
747,
14,
515,
14,
6027,
8,
515,
304,
1039,
746,
18382,
14,
5039,
547,
8,
1675,
283,
16849,
2082,
440,
1911,
26,
450,
82,
334,
515,
26,
450,
82,
3171,
450,
334,
354,
12,
931,
430,
1128,
372,
931,
8065,
199,
533,
24441,
8,
1360,
20,
3919,
17,
14,
6261,
304,
2958,
2202,
63,
1650,
275,
3517,
20,
3919,
17,
14,
6261,
14,
1751,
63,
1650,
435,
334,
1039,
283,
51,
21,
428,
8409,
2384,
20411,
8394,
297,
1039,
283,
1858,
314,
428,
21,
15,
4943,
7060,
12,
314,
1553,
889,
13,
13255,
13,
894,
4614,
945,
283,
1039,
8189,
4037,
315,
1696,
5454,
1208,
8394,
3432,
9,
365,
314,
849,
12,
283,
1039,
283,
460,
1077,
440,
506,
2896,
3130,
1039,
13636,
17768,
376,
4903,
428,
21,
8879,
701,
536,
14,
221,
31144,
1553,
7915,
13,
633,
14,
221,
283,
16765,
283,
1918,
849,
8879,
536,
365,
298,
885,
1674,
221,
710,
8879,
1584,
911,
506,
283,
16765,
283,
23581,
1901,
282,
298,
1907,
8316,
7915,
4335,
2082,
12,
315,
314,
2011,
2082,
465,
314,
283,
16765,
283,
6881,
570,
334,
1199,
4163,
680,
221,
3390,
626,
3411,
8879,
1584,
283,
16765,
283,
14117,
440,
506,
20200,
334,
18447,
1553,
14658,
13,
7915,
13,
1725,
365,
1202,
680,
297,
16765,
14574,
7915,
995,
16765,
791,
885,
356,
283,
885,
297,
283,
23303,
356,
2650,
354,
4206,
18691,
283,
12867,
356,
283,
7915,
63,
633,
1604,
8740,
661,
17768,
376,
428,
21,
8879,
2851,
14,
221,
710,
5724,
570,
334,
1199,
4163,
9,
911,
283,
16765,
283,
1073,
370,
642,
8879,
27,
6548,
911,
506,
8876,
14,
221,
31144,
1553,
7915,
3130,
16765,
14574,
7915,
13,
633,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
12867,
356,
283,
7915,
1604,
8740,
661,
7852,
3411,
8879,
1584,
315,
314,
1124,
1907,
8316,
7915,
28210,
2082,
370,
506,
283,
16765,
283,
1883,
8938,
14,
221,
710,
849,
365,
440,
370,
8970,
8879,
1584,
3130,
16765,
14574,
14658,
13,
7915,
13,
1725,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
18567,
3411,
8879,
1584,
315,
314,
1124,
1907,
8316,
7915,
28210,
2082,
27,
886,
440,
283,
16765,
283,
14658,
1263,
14,
221,
961,
365,
314,
849,
3130,
16765,
14574,
3250,
13,
7915,
13,
1725,
995,
16765,
791,
2614,
356,
283,
14658,
63,
7915,
63,
1725,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
8740,
661,
1084,
314,
2536,
2455,
818,
370,
298,
19968,
2384,
2,
359,
885,
61,
503,
298,
11550,
1674,
297,
16765,
14574,
1345,
13,
632,
995,
16765,
791,
4577,
356,
788,
19968,
2384,
297,
283,
11550,
995,
283,
885,
356,
283,
19968,
2384,
297,
18691,
283,
23303,
356,
2650,
632,
30,
1604,
8740,
661,
15548,
1183,
13714,
314,
3451,
425,
13467,
315,
27063,
2384,
818,
14,
283,
16765,
283,
2765,
365,
314,
849,
3130,
16765,
14574,
5642,
13,
13658,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
885,
356,
715,
12,
18691,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
2439,
2885,
2498,
314,
3451,
425,
13467,
315,
27063,
2384,
818,
14,
221,
283,
16765,
283,
1918,
849,
365,
370,
13714,
314,
13467,
3130,
16765,
14574,
6604,
13,
13658,
995,
16765,
791,
2614,
356,
283,
5642,
63,
13658,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
8740,
661,
6476,
314,
1453,
27063,
16385,
1689,
17,
1182,
4114,
3471,
221,
283,
16765,
283,
1918,
849,
365,
370,
3507,
652,
3130,
16765,
14574,
1818,
13,
19968,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
13707,
314,
1453,
27063,
16385,
14,
221,
961,
365,
314,
849,
3130,
16765,
14574,
889,
13,
1818,
13,
19968,
995,
16765,
791,
2614,
356,
283,
1818,
63,
19968,
297,
283,
1287,
356,
283,
1617,
63,
3910,
1604,
430,
2958,
2202,
63,
885,
63,
12867,
275,
791,
13255,
63,
894,
4614,
356,
378,
93,
2958,
1101,
63,
2792,
275,
283,
83,
21,
63,
1360,
7060,
7,
1128,
1101,
63,
2792,
63,
5714,
275,
661,
26224,
297,
283,
1360,
20,
3919,
17,
7060,
358,
2958,
347,
636,
826,
721,
277,
304,
1039,
3517,
20,
3919,
17,
14,
6261,
855,
826,
721,
277,
9,
1039,
291,
14,
29346,
63,
533,
275,
428,
21,
4943,
26059,
8065,
199,
533,
428,
21,
4943,
26059,
8,
1360,
20,
3919,
17,
14,
4943,
26059,
304,
2958,
308,
21,
63,
15479,
63,
1160,
275,
9638,
202,
199,
25273,
2897,
2633,
10541,
202,
199,
28,
2024,
536,
628,
885,
2768,
2,
1564,
17662,
1345,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Sodki/ansible
|
lib/ansible/modules/network/lenovo/cnos_rollback.py
|
59
|
11069
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Lenovo, Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
# Module to Rollback Config back to Lenovo Switches
#
# Lenovo Networking
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: cnos_rollback
author: "Dave Kasberg (@dkasberg)"
short_description: Roll back the running or startup configuration from a remote server on devices running Lenovo CNOS
description:
- This module allows you to work with switch configurations. It provides a way to roll back configurations
of a switch from a remote server. This is achieved by using startup or running configurations of the target
device that were previously backed up to a remote server using FTP, SFTP, TFTP, or SCP.
The first step is to create a directory from where the remote server can be reached. The next step is to
provide the full file path of the backup configuration’s location. Authentication details required by the
remote server must be provided as well.
By default, this method overwrites the switch’s configuration file with the newly downloaded file.
This module uses SSH to manage network device configuration.
The results of the operation will be placed in a directory named 'results'
that must be created by the user in their local directory to where the playbook is run.
For more information about this module from Lenovo and customizing it usage for your
use cases, please visit U(http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_rollback.html)
version_added: "2.3"
extends_documentation_fragment: cnos
options:
configType:
description:
- This refers to the type of configuration which will be used for the rolling back process.
The choices are the running or startup configurations. There is no default value, so it will result
in an error if the input is incorrect.
required: Yes
default: Null
choices: [running-config, startup-config]
protocol:
description:
- This refers to the protocol used by the network device to interact with the remote server from where to
download the backup configuration. The choices are FTP, SFTP, TFTP, or SCP. Any other protocols will result
in error. If this parameter is not specified, there is no default value to be used.
required: Yes
default: Null
choices: [SFTP, SCP, FTP, TFTP]
rcserverip:
description:
- This specifies the IP Address of the remote server from where the backup configuration will be downloaded.
required: Yes
default: Null
rcpath:
description:
- This specifies the full file path of the configuration file located on the remote server. In case the relative
path is used as the variable value, the root folder for the user of the server needs to be specified.
required: Yes
default: Null
serverusername:
description:
- Specify the username for the server relating to the protocol used.
required: Yes
default: Null
serverpassword:
description:
- Specify the password for the server relating to the protocol used.
required: Yes
default: Null
'''
EXAMPLES = '''
Tasks : The following are examples of using the module cnos_rollback. These are written in the main.yml file of the tasks directory.
---
- name: Test Rollback of config - Running config
cnos_rolback:
host: "{{ inventory_hostname }}"
username: "{{ hostvars[inventory_hostname]['username'] }}"
password: "{{ hostvars[inventory_hostname]['password'] }}"
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
enablePassword: "{{ hostvars[inventory_hostname]['enablePassword'] }}"
outputfile: "./results/test_rollback_{{ inventory_hostname }}_output.txt"
configType: running-config
protocol: "sftp"
serverip: "10.241.106.118"
rcpath: "/root/cnos/G8272-running-config.txt"
serverusername: "root"
serverpassword: "root123"
- name: Test Rollback of config - Startup config
cnos_rolback:
host: "{{ inventory_hostname }}"
username: "{{ hostvars[inventory_hostname]['username'] }}"
password: "{{ hostvars[inventory_hostname]['password'] }}"
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
enablePassword: "{{ hostvars[inventory_hostname]['enablePassword'] }}"
outputfile: "./results/test_rollback_{{ inventory_hostname }}_output.txt"
configType: startup-config
protocol: "sftp"
serverip: "10.241.106.118"
rcpath: "/root/cnos/G8272-startup-config.txt"
serverusername: "root"
serverpassword: "root123"
- name: Test Rollback of config - Running config - TFTP
cnos_rolback:
host: "{{ inventory_hostname }}"
username: "{{ hostvars[inventory_hostname]['username'] }}"
password: "{{ hostvars[inventory_hostname]['password'] }}"
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
enablePassword: "{{ hostvars[inventory_hostname]['enablePassword'] }}"
outputfile: "./results/test_rollback_{{ inventory_hostname }}_output.txt"
configType: running-config
protocol: "tftp"
serverip: "10.241.106.118"
rcpath: "/anil/G8272-running-config.txt"
serverusername: "root"
serverpassword: "root123"
- name: Test Rollback of config - Startup config - TFTP
cnos_rolback:
host: "{{ inventory_hostname }}"
username: "{{ hostvars[inventory_hostname]['username'] }}"
password: "{{ hostvars[inventory_hostname]['password'] }}"
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
enablePassword: "{{ hostvars[inventory_hostname]['enablePassword'] }}"
outputfile: "./results/test_rollback_{{ inventory_hostname }}_output.txt"
configType: startup-config
protocol: "tftp"
serverip: "10.241.106.118"
rcpath: "/anil/G8272-startup-config.txt"
serverusername: "root"
serverpassword: "root123"
'''
RETURN = '''
msg:
description: Success or failure message
returned: always
type: string
sample: "Config file tranferred to Device"
'''
import sys
import paramiko
import time
import argparse
import socket
import array
import json
import time
import re
try:
from ansible.module_utils import cnos
HAS_LIB = True
except:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict
def main():
module = AnsibleModule(
argument_spec=dict(
outputfile=dict(required=True),
host=dict(required=True),
username=dict(required=True),
password=dict(required=True, no_log=True),
enablePassword=dict(required=False, no_log=True),
deviceType=dict(required=True),
configType=dict(required=True),
protocol=dict(required=True),
serverip=dict(required=True),
rcpath=dict(required=True),
serverusername=dict(required=False),
serverpassword=dict(required=False, no_log=True),),
supports_check_mode=False)
username = module.params['username']
password = module.params['password']
enablePassword = module.params['enablePassword']
outputfile = module.params['outputfile']
host = module.params['host']
deviceType = module.params['deviceType']
configType = module.params['configType']
protocol = module.params['protocol'].lower()
rcserverip = module.params['serverip']
rcpath = module.params['rcpath']
serveruser = module.params['serverusername']
serverpwd = module.params['serverpassword']
output = ""
timeout = 90
tftptimeout = 450
# Create instance of SSHClient object
remote_conn_pre = paramiko.SSHClient()
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# initiate SSH connection with the switch
remote_conn_pre.connect(host, username=username, password=password)
time.sleep(2)
# Use invoke_shell to establish an 'interactive session'
remote_conn = remote_conn_pre.invoke_shell()
time.sleep(2)
# Enable and enter configure terminal then send command
output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)
output = output + cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)
# Make terminal length = 0
output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)
# Invoke method for Config transfer from server
if(configType == 'running-config'):
if(protocol == "tftp" or protocol == "ftp"):
transfer_status = cnos.doRunningConfigRollback(protocol, tftptimeout, rcserverip, rcpath, serveruser, serverpwd, remote_conn)
elif(protocol == "sftp" or protocol == "scp"):
transfer_status = cnos.doSecureRunningConfigRollback(protocol, timeout, rcserverip, rcpath, serveruser, serverpwd, remote_conn)
else:
transfer_status = "Invalid Protocol option"
elif(configType == 'startup-config'):
if(protocol == "tftp" or protocol == "ftp"):
transfer_status = cnos.doStartUpConfigRollback(protocol, tftptimeout, rcserverip, rcpath, serveruser, serverpwd, remote_conn)
elif(protocol == "sftp" or protocol == "scp"):
transfer_status = cnos.doSecureStartUpConfigRollback(protocol, timeout, rcserverip, rcpath, serveruser, serverpwd, remote_conn)
else:
transfer_status = "Invalid Protocol option"
else:
transfer_status = "Invalid configType Option"
output = output + "\n Config Transfer status \n" + transfer_status
# Save it into the file
file = open(outputfile, "a")
file.write(output)
file.close()
# need to add logic to check when changes occur or not
errorMsg = cnos.checkOutputForError(output)
if(errorMsg is None):
module.exit_json(changed=True, msg="Config file tranferred to Device")
else:
module.fail_json(msg=errorMsg)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
5673,
370,
820,
14385,
894,
4094,
1771,
370,
15757,
31445,
17711,
397,
199,
3,
199,
3,
15757,
31445,
7220,
316,
199,
3,
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,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32535,
63,
10437,
199,
2502,
26,
298,
36,
811,
1804,
305,
14630,
8593,
6341,
305,
14630,
2924,
199,
3612,
63,
1802,
26,
820,
14385,
1771,
314,
3879,
503,
14210,
2897,
687,
282,
3982,
1654,
641,
7256,
3879,
15757,
31445,
445,
23141,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1736,
543,
6258,
13422,
14,
2779,
6571,
282,
4340,
370,
11848,
1771,
13422,
1362,
402,
282,
6258,
687,
282,
3982,
1654,
14,
961,
365,
22175,
1354,
701,
1808,
14210,
503,
3879,
13422,
402,
314,
1347,
1362,
2243,
626,
4898,
10889,
1771,
379,
1536,
370,
282,
3982,
1654,
1808,
23125,
12,
428,
15123,
12,
377,
15123,
12,
503,
428,
2890,
14,
1362,
710,
1642,
3650,
365,
370,
1218,
282,
2082,
687,
2382,
314,
3982,
1654,
883,
506,
13075,
14,
710,
2163,
3650,
365,
370,
1362,
5647,
314,
2615,
570,
931,
402,
314,
6902,
2897,
21045,
83,
2909,
14,
15995,
2436,
1415,
701,
314,
1362,
3982,
1654,
1471,
506,
2741,
465,
5521,
14,
1362,
4885,
849,
12,
642,
1083,
1806,
16334,
314,
6258,
21045,
83,
2897,
570,
543,
314,
13903,
13557,
570,
14,
1362,
961,
859,
4440,
12027,
370,
9635,
2784,
2243,
2897,
14,
1362,
710,
2058,
402,
314,
3439,
911,
506,
15090,
315,
282,
2082,
4310,
283,
2604,
7,
1362,
626,
1471,
506,
2737,
701,
314,
922,
315,
3932,
2257,
2082,
370,
2382,
314,
15695,
365,
1255,
14,
1362,
2104,
1655,
2556,
3595,
642,
859,
687,
15757,
31445,
436,
3537,
9147,
652,
4503,
367,
2195,
1362,
675,
5560,
12,
8749,
5684,
738,
8,
1014,
921,
2253,
88,
14,
552,
31445,
1725,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
2458,
18,
38,
957,
14,
552,
31445,
14,
5656,
77,
3308,
14,
4853,
14,
1301,
5,
18,
38,
6413,
736,
63,
10437,
14,
1360,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
11036,
63,
9970,
63,
7677,
26,
32535,
199,
1419,
26,
2043,
1101,
804,
26,
267,
1369,
26,
288,
446,
961,
15724,
370,
314,
730,
402,
2897,
1314,
911,
506,
1202,
367,
314,
882,
10564,
1771,
2112,
14,
1467,
710,
3415,
787,
314,
3879,
503,
14210,
13422,
14,
6006,
365,
949,
849,
574,
12,
880,
652,
911,
754,
1467,
315,
376,
1125,
340,
314,
1324,
365,
8927,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
267,
3415,
26,
359,
5720,
13,
888,
12,
14210,
13,
888,
61,
2043,
4113,
26,
267,
1369,
26,
288,
446,
961,
15724,
370,
314,
4113,
1202,
701,
314,
2784,
2243,
370,
17232,
543,
314,
3982,
1654,
687,
2382,
370,
1467,
5235,
314,
6902,
2897,
14,
710,
3415,
787,
23125,
12,
428,
15123,
12,
377,
15123,
12,
503,
428,
2890,
14,
6184,
1163,
19230,
911,
754,
1467,
315,
1125,
14,
982,
642,
2725,
365,
440,
2013,
12,
2337,
365,
949,
849,
574,
370,
506,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
267,
3415,
26,
359,
51,
15123,
12,
428,
2890,
12,
23125,
12,
377,
15123,
61,
2043,
4819,
1000,
711,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
3531,
9906,
402,
314,
3982,
1654,
687,
2382,
314,
6902,
2897,
911,
506,
13557,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
4819,
515,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
2615,
570,
931,
402,
314,
2897,
570,
16180,
641,
314,
3982,
1654,
14,
1010,
1930,
314,
3847,
1467,
931,
365,
1202,
465,
314,
1750,
574,
12,
314,
1738,
4922,
367,
314,
922,
402,
314,
1654,
4839,
370,
506,
2013,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
1654,
2473,
26,
267,
1369,
26,
288,
446,
13327,
314,
3434,
367,
314,
1654,
4668,
1958,
370,
314,
4113,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
1654,
2060,
26,
267,
1369,
26,
288,
446,
13327,
314,
2505,
367,
314,
1654,
4668,
1958,
370,
314,
4113,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
199,
2344,
199,
8918,
275,
1449,
199,
19295,
520,
710,
2569,
787,
7251,
402,
1808,
314,
859,
32535,
63,
10437,
14,
5723,
787,
5313,
315,
314,
2446,
14,
11714,
570,
402,
314,
6527,
2082,
14,
199,
2595,
199,
199,
13,
536,
26,
1379,
820,
14385,
894,
402,
1101,
446,
26848,
1101,
523,
32535,
63,
8459,
894,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
3434,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2473,
418,
7820,
489,
2505,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2060,
418,
7820,
489,
31343,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
1782,
804,
418,
7820,
489,
4756,
6139,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
4296,
6139,
418,
7820,
489,
32513
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
5673,
370,
820,
14385,
894,
4094,
1771,
370,
15757,
31445,
17711,
397,
199,
3,
199,
3,
15757,
31445,
7220,
316,
199,
3,
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,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32535,
63,
10437,
199,
2502,
26,
298,
36,
811,
1804,
305,
14630,
8593,
6341,
305,
14630,
2924,
199,
3612,
63,
1802,
26,
820,
14385,
1771,
314,
3879,
503,
14210,
2897,
687,
282,
3982,
1654,
641,
7256,
3879,
15757,
31445,
445,
23141,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1736,
543,
6258,
13422,
14,
2779,
6571,
282,
4340,
370,
11848,
1771,
13422,
1362,
402,
282,
6258,
687,
282,
3982,
1654,
14,
961,
365,
22175,
1354,
701,
1808,
14210,
503,
3879,
13422,
402,
314,
1347,
1362,
2243,
626,
4898,
10889,
1771,
379,
1536,
370,
282,
3982,
1654,
1808,
23125,
12,
428,
15123,
12,
377,
15123,
12,
503,
428,
2890,
14,
1362,
710,
1642,
3650,
365,
370,
1218,
282,
2082,
687,
2382,
314,
3982,
1654,
883,
506,
13075,
14,
710,
2163,
3650,
365,
370,
1362,
5647,
314,
2615,
570,
931,
402,
314,
6902,
2897,
21045,
83,
2909,
14,
15995,
2436,
1415,
701,
314,
1362,
3982,
1654,
1471,
506,
2741,
465,
5521,
14,
1362,
4885,
849,
12,
642,
1083,
1806,
16334,
314,
6258,
21045,
83,
2897,
570,
543,
314,
13903,
13557,
570,
14,
1362,
961,
859,
4440,
12027,
370,
9635,
2784,
2243,
2897,
14,
1362,
710,
2058,
402,
314,
3439,
911,
506,
15090,
315,
282,
2082,
4310,
283,
2604,
7,
1362,
626,
1471,
506,
2737,
701,
314,
922,
315,
3932,
2257,
2082,
370,
2382,
314,
15695,
365,
1255,
14,
1362,
2104,
1655,
2556,
3595,
642,
859,
687,
15757,
31445,
436,
3537,
9147,
652,
4503,
367,
2195,
1362,
675,
5560,
12,
8749,
5684,
738,
8,
1014,
921,
2253,
88,
14,
552,
31445,
1725,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
2458,
18,
38,
957,
14,
552,
31445,
14,
5656,
77,
3308,
14,
4853,
14,
1301,
5,
18,
38,
6413,
736,
63,
10437,
14,
1360,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
11036,
63,
9970,
63,
7677,
26,
32535,
199,
1419,
26,
2043,
1101,
804,
26,
267,
1369,
26,
288,
446,
961,
15724,
370,
314,
730,
402,
2897,
1314,
911,
506,
1202,
367,
314,
882,
10564,
1771,
2112,
14,
1467,
710,
3415,
787,
314,
3879,
503,
14210,
13422,
14,
6006,
365,
949,
849,
574,
12,
880,
652,
911,
754,
1467,
315,
376,
1125,
340,
314,
1324,
365,
8927,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
267,
3415,
26,
359,
5720,
13,
888,
12,
14210,
13,
888,
61,
2043,
4113,
26,
267,
1369,
26,
288,
446,
961,
15724,
370,
314,
4113,
1202,
701,
314,
2784,
2243,
370,
17232,
543,
314,
3982,
1654,
687,
2382,
370,
1467,
5235,
314,
6902,
2897,
14,
710,
3415,
787,
23125,
12,
428,
15123,
12,
377,
15123,
12,
503,
428,
2890,
14,
6184,
1163,
19230,
911,
754,
1467,
315,
1125,
14,
982,
642,
2725,
365,
440,
2013,
12,
2337,
365,
949,
849,
574,
370,
506,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
267,
3415,
26,
359,
51,
15123,
12,
428,
2890,
12,
23125,
12,
377,
15123,
61,
2043,
4819,
1000,
711,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
3531,
9906,
402,
314,
3982,
1654,
687,
2382,
314,
6902,
2897,
911,
506,
13557,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
4819,
515,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
2615,
570,
931,
402,
314,
2897,
570,
16180,
641,
314,
3982,
1654,
14,
1010,
1930,
314,
3847,
1467,
931,
365,
1202,
465,
314,
1750,
574,
12,
314,
1738,
4922,
367,
314,
922,
402,
314,
1654,
4839,
370,
506,
2013,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
1654,
2473,
26,
267,
1369,
26,
288,
446,
13327,
314,
3434,
367,
314,
1654,
4668,
1958,
370,
314,
4113,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
2043,
1654,
2060,
26,
267,
1369,
26,
288,
446,
13327,
314,
2505,
367,
314,
1654,
4668,
1958,
370,
314,
4113,
1202,
14,
267,
1415,
26,
29715,
267,
849,
26,
12119,
199,
2344,
199,
8918,
275,
1449,
199,
19295,
520,
710,
2569,
787,
7251,
402,
1808,
314,
859,
32535,
63,
10437,
14,
5723,
787,
5313,
315,
314,
2446,
14,
11714,
570,
402,
314,
6527,
2082,
14,
199,
2595,
199,
199,
13,
536,
26,
1379,
820,
14385,
894,
402,
1101,
446,
26848,
1101,
523,
32535,
63,
8459,
894,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
3434,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2473,
418,
7820,
489,
2505,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2060,
418,
7820,
489,
31343,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
1782,
804,
418,
7820,
489,
4756,
6139,
26,
7370,
21835,
59,
7212,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
rocco8773/bapsflib
|
bapsflib/_hdf/utils/hdfoverview.py
|
1
|
15938
|
# This file is part of the bapsflib package, a Python toolkit for the
# BaPSF group at UCLA.
#
# http://plasma.physics.ucla.edu/
#
# Copyright 2017-2018 Erik T. Everson and contributors
#
# License: Standard 3-clause BSD; see "LICENSES/LICENSE.txt" for full
# license terms and contributor agreement.
#
import os
import platform
import pprint as pp
from contextlib import redirect_stdout
from datetime import datetime
from .file import File
from ..maps.controls.templates import HDFMapControlTemplate
from ..maps.digitizers.templates import HDFMapDigiTemplate
from ..maps.msi.templates import HDFMapMSITemplate
class HDFOverview(object):
"""
Reports an overview of the HDF5 file mapping.
"""
def __init__(self, hdf_obj: File):
"""
:param hdf_obj: HDF5 file object
:type hdf_obj: :class:`~.file.File`
"""
super().__init__()
# store an instance of the HDF5 file object and map
if isinstance(hdf_obj, File):
self._file = hdf_obj
self._fmap = hdf_obj.file_map
else:
raise ValueError('input arg is not of type HDFMap')
def print(self):
"""
Print full Overview Report.
"""
# TODO: add reporting of 'data run sequence'
# TODO: add reporting of motion device's 'motion list'
#
from bapsflib import __version__
# ------ Print Header ------
time_format = '%-m/%-d/%Y %-I:%M:%S %p'
if platform.system() == 'Windows':
time_format = time_format.replace('-', '#')
print('=' * 72)
print('{} Overview'.format(self._file.info['file']))
print('Generated by bapsflib (v' + __version__ + ')')
print('Generated date: '
+ datetime.now().strftime(time_format))
print('=' * 72 + '\n\n')
# ------ Print General Info ------
self.report_general()
# ------ Print Discovery Report ------
self.report_discovery()
# ------ Print Detailed Reports ------
self.report_details()
def save(self, filename=''):
"""
Saves the HDF5 overview to a text file.
:param str filename: name of text file to save the overview
report generated by :meth:`print`.
"""
if filename == '':
# use the same name as the HDF5 file
filename = os.path.splitext(self._file.filename)[0]\
+ '.txt'
# write to file
with open(filename, 'w') as of:
with redirect_stdout(of):
self.print()
def report_general(self):
"""
Prints general HDF5 file info.
"""
# print basic file info
print('Filename: {}'.format(self._file.info['file']))
print('Abs. Path: {}'.format(
self._file.info['absolute file path']))
def report_discovery(self):
"""
Prints a discovery (brief) report of all detected MSI
diagnostics, digitizers, and control devices.
"""
# print header
print('\n\nDiscovery Report')
print('----------------\n')
# print digitizers
self.control_discovery()
print('\n')
# print digitizers
self.digitizer_discovery()
print('\n')
# print msi
self.msi_discovery()
print('\n')
# print unknowns
self.unknowns_discovery()
def report_details(self):
"""
Prints a detailed report of all detected MSI diagnostics,
digitizers, and control devices.
"""
# print header
print('\n\nDetailed Reports')
print('-----------------')
# digitizer report
self.report_digitizers()
# control devices report
self.report_controls()
# msi report
self.report_msi()
def control_discovery(self):
"""
Prints a discovery report of the Control devices.
"""
# is there a control group
_path = self._fmap.DEVICE_PATHS['control']
_detected = _path in self._file
# print number of diagnostics
ndevices = len(self._fmap.controls)
item = 'Control devices ({})'.format(ndevices)
status_print(item, '', '', indent=0)
# print status to screen
item = _path + '/'
found = 'found' if _detected else 'missing'
status_print(item, found, '', indent=1)
# list diagnostics
for device in self._fmap.controls:
status_print(device, '', '', indent=2)
def digitizer_discovery(self):
"""
Prints a discovery report of the Digitizer devices.
"""
# is there a digitizer group
_path = self._fmap.DEVICE_PATHS['digitizer']
_detected = _path in self._file
# print number of diagnostics
ndevices = len(self._fmap.digitizers)
item = 'Digitizer devices ({})'.format(ndevices)
status_print(item, '', '', indent=0)
# print status to screen
item = _path + '/'
found = 'found' if _detected else 'missing'
status_print(item, found, '', indent=1)
# list diagnostics
for device in self._fmap.digitizers:
if device == self._fmap.main_digitizer.device_name:
device += " (main)"
status_print(device, '', '', indent=2)
def msi_discovery(self):
"""
Prints a discovery report of the MSI devices.
"""
# is there a MSI group
_path = self._fmap.DEVICE_PATHS['msi']
_detected = _path in self._file
# print number of diagnostics
ndevices = len(self._fmap.msi)
item = 'MSI devices ({})'.format(ndevices)
status_print(item, '', '', indent=0)
# print status to screen
item = _path + '/'
found = 'found' if _detected else 'missing'
status_print(item, found, '', indent=1)
# list diagnostics
for device in self._fmap.msi:
status_print(device, '', '', indent=2)
def unknowns_discovery(self):
"""
Prints a discovery report of the Unknown devices.
"""
ndevices = len(self._fmap.unknowns)
item = 'Unknowns ({})'.format(ndevices)
note = 'aka unmapped'
status_print(item, note, '', indent=0)
# list unknowns
for device in self._fmap.unknowns:
status_print(device, '', '', indent=1)
def report_msi(self, name=None):
"""
Prints to screen a report of detected MSI diagnostics and
their configurations.
:param str name: name of MSI diagnostic. If :code:`None` or
`name` is not among MSI diagnostics, then all MSI
diagnostics are printed.
"""
# gather configs to print
if name in self._fmap.msi:
_dmap = {name: self._fmap.msi[name]}
else:
name = None
_dmap = self._fmap.msi
# print heading
title = 'MSI Diagnostic Report'
if name is not None:
title += ' ({} ONLY)'.format(name)
print('\n\n' + title)
print('^' * len(title) + '\n')
# print msi diagnostic config
for name, _map in _dmap.items():
# print msi diag name
status_print(_map.device_name, '', '')
# print path to diagnostic
item = 'path: ' + _map.info['group path']
status_print(item, '', '', indent=1)
# print the configs dict
self.report_msi_configs(_map)
@staticmethod
def report_msi_configs(msi: HDFMapMSITemplate):
"""
Print to screan information about the passed MSI configuration.
:param msi: a MSI mapping object
"""
# print configs title
status_print('configs', '', '', indent=1)
# pretty print the configs dict
ppconfig = pp.pformat(msi.configs)
for line in ppconfig.splitlines():
status_print(line, '', '', indent=2)
def report_digitizers(self, name=None):
"""
Prints to screen a report of detected digitizers and their
configurations.
:param str name: name of digitizer. If :code:`None` or
`name` is not among digitizers, then all digitizers are
printed.
"""
# gather configs to print
if name in self._fmap.digitizers:
_dmap = {name: self._fmap.digitizers[name]}
else:
name = None
_dmap = self._fmap.digitizers
# print heading
title = 'Digitizer Report'
if name is not None:
title += ' ({} ONLY)'.format(name)
print('\n\n' + title)
print('^' * len(title) + '\n')
# print digitizer config
for name, _map in _dmap.items():
# print digitizer name
item = name
if name == self._fmap.main_digitizer.device_name:
item += ' (main)'
status_print(item, '', '')
# print adc's
item = "adc's: {}".format(_map.device_adcs)
status_print(item, '', '', indent=1)
# print digitizer configs
self.report_digitizer_configs(_map)
@staticmethod
def report_digitizer_configs(digi: HDFMapDigiTemplate):
"""
Prints to screen information about the passed digitizer
configuration(s).
:param digi: a digitizer mapping object
"""
nconfigs = len(digi.configs)
if nconfigs != 0:
nconf_active = len(digi.active_configs)
item = 'Configurations Detected ({})'.format(nconfigs)
note = '({0} active, {1} inactive)'.format(
nconf_active, nconfigs - nconf_active)
status_print(item, '', note, indent=1)
for cname, config in digi.configs.items():
# print configuration name
item = cname
found = ''
note = 'active' if config['active'] else 'NOT active'
status_print(item, found, note, indent=2)
# print active adc's
item = "adc's (active): {}".format(config['adc'])
status_print(item, '', '', indent=3)
# print path for config
item = 'path: ' + config['config group path']
status_print(item, '', '', indent=3)
# print adc details for configuration
for adc in config['adc']:
# adc name
item = adc + ' adc connections'
status_print(item, '', '', indent=3)
# print adc header
line_indent = ('| ' * 4) + '+-- '
line = line_indent + '(brd, [ch, ...])'
line = line.ljust(51)
line += 'bit'.ljust(5)
line += 'clock rate'.ljust(13)
line += 'nshotnum'.ljust(10)
line += 'nt'.ljust(10)
line += 'shot ave.'.ljust(11)
line += 'sample ave.'
print(line)
# adc connections
nconns = len(config[adc])
for iconn in range(nconns):
conns = config[adc][iconn][0:2]
adc_stats = config[adc][iconn][2]
# construct and print line
line = line_indent + str(conns)
line = line.ljust(51)
line += str(adc_stats['bit']).ljust(5)
line += '{}'.format(
adc_stats['clock rate']).ljust(13)
line += str(adc_stats['nshotnum']).ljust(10)
line += str(adc_stats['nt']).ljust(10)
line += str(
adc_stats['shot average (software)']
).ljust(11)
line += str(
adc_stats['sample average (hardware)'])
print(line)
else:
status_print('Configurations Detected (0)', '', '',
indent=1)
def report_controls(self, name=None):
"""
Prints to screen a detailed report of detected control devices
and their configuration(s).
:param str name: name of control device. If :code:`None` or
`name` is not among controls, then all control devices are
printed.
"""
# gather configs to print
if name in self._fmap.controls:
_dmap = {name: self._fmap.controls[name]}
else:
name = None
_dmap = self._fmap.controls
# print heading
title = 'Control Device Report'
if name is not None:
title += ' ({} ONLY)'.format(name)
print('\n\n' + title)
print('^' * len(title) + '\n')
# print control config
for name, _map in _dmap.items():
# print control name
status_print(_map.device_name, '', '')
# print path to control
item = 'path: ' + _map.info['group path']
status_print(item, '', '', indent=1)
# print path to contype
item = 'contype: {}'.format(_map.contype)
status_print(item, '', '', indent=1)
# print configurations
self.report_control_configs(_map)
@staticmethod
def report_control_configs(control: HDFMapControlTemplate):
"""
Prints to screen information about the passed control device
configuration(s).
:param control: a control device mapping object
"""
nconfigs = len(control.configs)
if nconfigs != 0:
# display number of configurations
item = 'Configurations Detected ({})'.format(nconfigs)
status_print(item, '', '', indent=1)
# display config values
for cname, config in control.configs.items():
# print config_name
status_print(cname, '', '', indent=2)
# get pretty print string
ppconfig = pp.pformat(config)
for line in ppconfig.splitlines():
status_print(line, '', '', indent=3)
else:
item = 'Configurations Detected (0)'
status_print(item, '', '', indent=1)
def status_print(first: str, second: str, third: str,
indent=0, onetwo_pad=' ', second_tab=55):
"""
Stylistic status printing for :class:`HDFOverview`.
:param first: string for 1st column
:param second: string for 2nd column
:param third: string for 3rd column
:param int indent: num. of indentations for 1st column display
:param str onetwo_pad: one character string for pad style
between 1st and 2nd column
:param int second_tab: number of characters between start of string
and start of 2nd column
:Example:
.. code-block:: python
>>> status_print('one', 'two', 'three', second_tab=15)
one two three
>>> status_print('one', 'two', 'three', second_tab=15,
... indent=2, onetwo_pad='~')
| +-- one two three
"""
note_tab = 7
if indent == 0:
str_print = ''
elif indent == 1:
str_print = '+-- '
else:
str_print = ('| ' * (indent - 1)) + '+-- '
str_print += str(first) + ' '
str_print = str_print.ljust(second_tab - 1, onetwo_pad) + ' '
str_print += str(second).ljust(note_tab) + str(third)
print(str_print)
|
bsd-3-clause
|
[
3,
961,
570,
365,
1777,
402,
314,
330,
7461,
70,
773,
2559,
12,
282,
2018,
4744,
6065,
367,
314,
199,
3,
699,
65,
5067,
38,
1572,
737,
738,
8576,
14,
199,
3,
199,
3,
1455,
921,
1168,
305,
391,
14,
24724,
14,
947,
416,
14,
8654,
15,
199,
3,
199,
3,
1898,
9708,
13,
12682,
662,
25844,
377,
14,
662,
422,
834,
436,
8417,
199,
3,
199,
3,
844,
26,
9739,
650,
13,
8501,
6289,
27,
1937,
298,
2507,
8456,
654,
15,
3961,
14,
2424,
2,
367,
2615,
199,
3,
257,
4190,
2895,
436,
11615,
25025,
14,
199,
3,
199,
646,
747,
199,
646,
4298,
199,
646,
10933,
465,
11618,
199,
199,
504,
15502,
492,
4660,
63,
2703,
199,
504,
2197,
492,
2197,
199,
199,
504,
1275,
493,
492,
3814,
199,
504,
2508,
8919,
14,
13658,
14,
5876,
492,
24521,
2956,
3717,
4231,
199,
504,
2508,
8919,
14,
18367,
5277,
90,
1192,
14,
5876,
492,
24521,
2956,
36,
13721,
4231,
199,
504,
2508,
8919,
14,
77,
338,
14,
5876,
492,
24521,
2956,
3053,
649,
3051,
421,
199,
533,
869,
36,
3230,
422,
1345,
8,
785,
304,
272,
408,
272,
799,
5203,
376,
23503,
402,
314,
24521,
21,
570,
4412,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
394,
1587,
63,
1113,
26,
3814,
304,
267,
408,
267,
520,
635,
394,
1587,
63,
1113,
26,
24521,
21,
570,
909,
267,
520,
466,
394,
1587,
63,
1113,
26,
520,
533,
18739,
493,
14,
1173,
64,
267,
408,
267,
1613,
11027,
826,
4533,
398,
327,
3877,
376,
1256,
402,
314,
24521,
21,
570,
909,
436,
2341,
267,
340,
1228,
8,
19912,
63,
1113,
12,
3814,
304,
288,
291,
423,
493,
275,
394,
1587,
63,
1113,
288,
291,
423,
29621,
275,
394,
1587,
63,
1113,
14,
493,
63,
1130,
267,
587,
26,
288,
746,
1722,
360,
1210,
1680,
365,
440,
402,
730,
24521,
2956,
358,
339,
347,
870,
8,
277,
304,
267,
408,
267,
9101,
2615,
7259,
1345,
11774,
14,
267,
408,
267,
327,
3254,
26,
1050,
17290,
402,
283,
576,
1255,
3414,
7,
267,
327,
3254,
26,
1050,
17290,
402,
25134,
2243,
1159,
283,
15335,
769,
7,
267,
327,
267,
687,
330,
7461,
70,
773,
492,
636,
1023,
363,
267,
327,
21397,
9101,
10240,
32542,
21397,
267,
900,
63,
908,
275,
1543,
13,
77,
3149,
13,
68,
3149,
57,
19752,
41,
2689,
45,
2689,
51,
450,
80,
7,
267,
340,
4298,
14,
2253,
342,
508,
283,
8647,
356,
288,
900,
63,
908,
275,
900,
63,
908,
14,
1814,
13858,
3943,
358,
267,
870,
360,
534,
627,
15323,
9,
267,
870,
17519,
7259,
1345,
1370,
908,
8,
277,
423,
493,
14,
815,
459,
493,
5156,
267,
870,
360,
12706,
701,
330,
7461,
70,
773,
334,
86,
7,
435,
636,
1023,
363,
435,
5320,
358,
267,
870,
360,
12706,
1434,
26,
283,
1598,
435,
2197,
14,
2131,
1252,
6205,
8,
521,
63,
908,
430,
267,
870,
360,
534,
627,
15323,
435,
1557,
78,
60,
78,
358,
398,
327,
21397,
9101,
1696,
10332,
17388,
21397,
267,
291,
14,
3070,
63,
10706,
342,
398,
327,
21397,
9101,
5289,
6913,
11774,
13235,
21397,
267,
291,
14,
3070,
63,
14859,
342,
398,
327,
21397,
9101,
577,
1841,
1672,
799,
5203,
13235,
21397,
267,
291,
14,
3070,
63,
5087,
342,
339,
347,
3354,
8,
277,
12,
1788,
9280,
267,
408,
267,
428,
7047,
314,
24521,
21,
23503,
370,
282,
1318,
570,
14,
398,
520,
635,
620,
1788,
26,
536,
402,
1318,
570,
370,
3354,
314,
23503,
288,
3622,
4046,
701,
520,
5247,
1705,
1361,
2313,
267,
408,
267,
340,
1788,
508,
8061,
288,
327,
675,
314,
2011,
536,
465,
314,
24521,
21,
570,
288,
1788,
275,
747,
14,
515,
14,
7973,
8,
277,
423,
493,
14,
1501,
2788,
16,
7272,
2432,
435,
1987,
2424,
7,
398,
327,
2218,
370,
570,
267,
543,
1551,
8,
1501,
12,
283,
87,
358,
465,
402,
26,
288,
543,
4660,
63,
2703,
8,
1618,
304,
355,
291,
14,
1361,
342,
339,
347,
3622,
63,
10706,
8,
277,
304,
267,
408,
267,
9101,
83,
8605,
24521,
21,
570,
2256,
14,
267,
408,
267,
327,
870,
5678,
570,
2256,
267,
870,
360,
8117,
26,
258,
9499,
908,
8,
277,
423,
493,
14,
815,
459,
493,
5156,
267,
870,
360,
15447,
14,
6912,
26,
259,
9499,
908,
8,
288,
291,
423,
493,
14,
815,
459,
6116,
570,
931,
5156,
339,
347,
3622,
63,
14859,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
13172,
334,
19127,
9,
3622,
402,
1006,
10501,
603,
2684,
267,
8348,
21204,
12,
31190,
5277,
90,
1192,
12,
436,
3304,
7256,
14,
267,
408,
267,
327,
870,
1406,
267,
870,
2258,
78,
60,
78,
2825,
6913,
11774,
358,
267,
870,
360,
777,
60,
78,
358,
398,
327,
870,
31190,
5277,
90,
1192,
267,
291,
14,
2785,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
31190,
5277,
90,
1192,
267,
291,
14,
18367,
5277,
2282,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
333,
338,
267,
291,
14,
77,
338,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
625,
14996,
561,
267,
291,
14,
1778,
2131,
561,
63,
14859,
342,
339,
347,
3622,
63,
5087,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
16212,
3622,
402,
1006,
10501,
603,
2684,
8348,
21204,
12,
267,
31190,
5277,
90,
1192,
12,
436,
3304,
7256,
14,
267,
408,
267,
327,
870,
1406,
267,
870,
2258,
78,
60,
78,
36,
1841,
1672,
799,
5203,
358,
267,
870,
360,
777,
25815,
398,
327,
31190,
5277,
2282,
3622,
267,
291,
14,
3070,
63,
18367,
5277,
90,
1192,
342,
398,
327,
3304,
7256,
3622,
267,
291,
14,
3070,
63,
13658,
342,
398,
327,
333,
338,
3622,
267,
291,
14,
3070,
63,
77,
338,
342,
339,
347,
3304,
63,
14859,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
13172,
3622,
402,
314,
8612,
7256,
14,
267,
408,
267,
327,
365,
2337,
282,
3304,
1572,
267,
485,
515,
275,
291,
423,
29621,
14,
10555,
63,
20202,
459,
2785,
418,
267,
485,
25577,
275,
485,
515,
315,
291,
423,
493,
398,
327,
870,
1329,
402,
8348,
21204,
267,
302,
6410,
275,
822,
8,
277,
423,
29621
] |
[
961,
570,
365,
1777,
402,
314,
330,
7461,
70,
773,
2559,
12,
282,
2018,
4744,
6065,
367,
314,
199,
3,
699,
65,
5067,
38,
1572,
737,
738,
8576,
14,
199,
3,
199,
3,
1455,
921,
1168,
305,
391,
14,
24724,
14,
947,
416,
14,
8654,
15,
199,
3,
199,
3,
1898,
9708,
13,
12682,
662,
25844,
377,
14,
662,
422,
834,
436,
8417,
199,
3,
199,
3,
844,
26,
9739,
650,
13,
8501,
6289,
27,
1937,
298,
2507,
8456,
654,
15,
3961,
14,
2424,
2,
367,
2615,
199,
3,
257,
4190,
2895,
436,
11615,
25025,
14,
199,
3,
199,
646,
747,
199,
646,
4298,
199,
646,
10933,
465,
11618,
199,
199,
504,
15502,
492,
4660,
63,
2703,
199,
504,
2197,
492,
2197,
199,
199,
504,
1275,
493,
492,
3814,
199,
504,
2508,
8919,
14,
13658,
14,
5876,
492,
24521,
2956,
3717,
4231,
199,
504,
2508,
8919,
14,
18367,
5277,
90,
1192,
14,
5876,
492,
24521,
2956,
36,
13721,
4231,
199,
504,
2508,
8919,
14,
77,
338,
14,
5876,
492,
24521,
2956,
3053,
649,
3051,
421,
199,
533,
869,
36,
3230,
422,
1345,
8,
785,
304,
272,
408,
272,
799,
5203,
376,
23503,
402,
314,
24521,
21,
570,
4412,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
394,
1587,
63,
1113,
26,
3814,
304,
267,
408,
267,
520,
635,
394,
1587,
63,
1113,
26,
24521,
21,
570,
909,
267,
520,
466,
394,
1587,
63,
1113,
26,
520,
533,
18739,
493,
14,
1173,
64,
267,
408,
267,
1613,
11027,
826,
4533,
398,
327,
3877,
376,
1256,
402,
314,
24521,
21,
570,
909,
436,
2341,
267,
340,
1228,
8,
19912,
63,
1113,
12,
3814,
304,
288,
291,
423,
493,
275,
394,
1587,
63,
1113,
288,
291,
423,
29621,
275,
394,
1587,
63,
1113,
14,
493,
63,
1130,
267,
587,
26,
288,
746,
1722,
360,
1210,
1680,
365,
440,
402,
730,
24521,
2956,
358,
339,
347,
870,
8,
277,
304,
267,
408,
267,
9101,
2615,
7259,
1345,
11774,
14,
267,
408,
267,
327,
3254,
26,
1050,
17290,
402,
283,
576,
1255,
3414,
7,
267,
327,
3254,
26,
1050,
17290,
402,
25134,
2243,
1159,
283,
15335,
769,
7,
267,
327,
267,
687,
330,
7461,
70,
773,
492,
636,
1023,
363,
267,
327,
21397,
9101,
10240,
32542,
21397,
267,
900,
63,
908,
275,
1543,
13,
77,
3149,
13,
68,
3149,
57,
19752,
41,
2689,
45,
2689,
51,
450,
80,
7,
267,
340,
4298,
14,
2253,
342,
508,
283,
8647,
356,
288,
900,
63,
908,
275,
900,
63,
908,
14,
1814,
13858,
3943,
358,
267,
870,
360,
534,
627,
15323,
9,
267,
870,
17519,
7259,
1345,
1370,
908,
8,
277,
423,
493,
14,
815,
459,
493,
5156,
267,
870,
360,
12706,
701,
330,
7461,
70,
773,
334,
86,
7,
435,
636,
1023,
363,
435,
5320,
358,
267,
870,
360,
12706,
1434,
26,
283,
1598,
435,
2197,
14,
2131,
1252,
6205,
8,
521,
63,
908,
430,
267,
870,
360,
534,
627,
15323,
435,
1557,
78,
60,
78,
358,
398,
327,
21397,
9101,
1696,
10332,
17388,
21397,
267,
291,
14,
3070,
63,
10706,
342,
398,
327,
21397,
9101,
5289,
6913,
11774,
13235,
21397,
267,
291,
14,
3070,
63,
14859,
342,
398,
327,
21397,
9101,
577,
1841,
1672,
799,
5203,
13235,
21397,
267,
291,
14,
3070,
63,
5087,
342,
339,
347,
3354,
8,
277,
12,
1788,
9280,
267,
408,
267,
428,
7047,
314,
24521,
21,
23503,
370,
282,
1318,
570,
14,
398,
520,
635,
620,
1788,
26,
536,
402,
1318,
570,
370,
3354,
314,
23503,
288,
3622,
4046,
701,
520,
5247,
1705,
1361,
2313,
267,
408,
267,
340,
1788,
508,
8061,
288,
327,
675,
314,
2011,
536,
465,
314,
24521,
21,
570,
288,
1788,
275,
747,
14,
515,
14,
7973,
8,
277,
423,
493,
14,
1501,
2788,
16,
7272,
2432,
435,
1987,
2424,
7,
398,
327,
2218,
370,
570,
267,
543,
1551,
8,
1501,
12,
283,
87,
358,
465,
402,
26,
288,
543,
4660,
63,
2703,
8,
1618,
304,
355,
291,
14,
1361,
342,
339,
347,
3622,
63,
10706,
8,
277,
304,
267,
408,
267,
9101,
83,
8605,
24521,
21,
570,
2256,
14,
267,
408,
267,
327,
870,
5678,
570,
2256,
267,
870,
360,
8117,
26,
258,
9499,
908,
8,
277,
423,
493,
14,
815,
459,
493,
5156,
267,
870,
360,
15447,
14,
6912,
26,
259,
9499,
908,
8,
288,
291,
423,
493,
14,
815,
459,
6116,
570,
931,
5156,
339,
347,
3622,
63,
14859,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
13172,
334,
19127,
9,
3622,
402,
1006,
10501,
603,
2684,
267,
8348,
21204,
12,
31190,
5277,
90,
1192,
12,
436,
3304,
7256,
14,
267,
408,
267,
327,
870,
1406,
267,
870,
2258,
78,
60,
78,
2825,
6913,
11774,
358,
267,
870,
360,
777,
60,
78,
358,
398,
327,
870,
31190,
5277,
90,
1192,
267,
291,
14,
2785,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
31190,
5277,
90,
1192,
267,
291,
14,
18367,
5277,
2282,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
333,
338,
267,
291,
14,
77,
338,
63,
14859,
342,
267,
870,
2258,
78,
358,
398,
327,
870,
625,
14996,
561,
267,
291,
14,
1778,
2131,
561,
63,
14859,
342,
339,
347,
3622,
63,
5087,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
16212,
3622,
402,
1006,
10501,
603,
2684,
8348,
21204,
12,
267,
31190,
5277,
90,
1192,
12,
436,
3304,
7256,
14,
267,
408,
267,
327,
870,
1406,
267,
870,
2258,
78,
60,
78,
36,
1841,
1672,
799,
5203,
358,
267,
870,
360,
777,
25815,
398,
327,
31190,
5277,
2282,
3622,
267,
291,
14,
3070,
63,
18367,
5277,
90,
1192,
342,
398,
327,
3304,
7256,
3622,
267,
291,
14,
3070,
63,
13658,
342,
398,
327,
333,
338,
3622,
267,
291,
14,
3070,
63,
77,
338,
342,
339,
347,
3304,
63,
14859,
8,
277,
304,
267,
408,
267,
9101,
83,
282,
13172,
3622,
402,
314,
8612,
7256,
14,
267,
408,
267,
327,
365,
2337,
282,
3304,
1572,
267,
485,
515,
275,
291,
423,
29621,
14,
10555,
63,
20202,
459,
2785,
418,
267,
485,
25577,
275,
485,
515,
315,
291,
423,
493,
398,
327,
870,
1329,
402,
8348,
21204,
267,
302,
6410,
275,
822,
8,
277,
423,
29621,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jnordling/cabin
|
onadata/apps/api/viewsets/stats_viewset.py
|
5
|
1128
|
from rest_framework import viewsets
from onadata.apps.api.permissions import XFormPermissions
from onadata.apps.logger.models.xform import XForm
from onadata.libs import filters
from onadata.libs.mixins.anonymous_user_public_forms_mixin import (
AnonymousUserPublicFormsMixin)
from onadata.libs.mixins.last_modified_mixin import LastModifiedMixin
from onadata.libs.serializers.stats_serializer import (
StatsSerializer, StatsInstanceSerializer)
class StatsViewSet(LastModifiedMixin,
AnonymousUserPublicFormsMixin,
viewsets.ReadOnlyModelViewSet):
lookup_field = 'pk'
queryset = XForm.objects.all()
filter_backends = (filters.AnonDjangoObjectPermissionFilter, )
permission_classes = [XFormPermissions, ]
serializer_class = StatsSerializer
def get_serializer_class(self):
lookup = self.kwargs.get(self.lookup_field)
if lookup is not None:
serializer_class = StatsInstanceSerializer
else:
serializer_class = \
super(StatsViewSet, self).get_serializer_class()
return serializer_class
|
bsd-2-clause
|
[
504,
4618,
63,
4857,
492,
2455,
2193,
199,
199,
504,
641,
1517,
14,
5181,
14,
1246,
14,
6060,
492,
1323,
2821,
17004,
199,
504,
641,
1517,
14,
5181,
14,
2921,
14,
992,
14,
24226,
492,
1323,
2821,
199,
199,
504,
641,
1517,
14,
8450,
492,
4766,
199,
504,
641,
1517,
14,
8450,
14,
30192,
14,
12628,
63,
751,
63,
3455,
63,
3351,
63,
20406,
492,
334,
272,
29952,
9885,
26028,
4256,
9,
199,
504,
641,
1517,
14,
8450,
14,
30192,
14,
2019,
63,
5540,
63,
20406,
492,
15237,
11911,
4256,
199,
504,
641,
1517,
14,
8450,
14,
12844,
14,
3200,
63,
8349,
492,
334,
272,
29062,
7299,
12,
29062,
3244,
7299,
9,
421,
199,
533,
29062,
21902,
8,
6090,
11911,
4256,
12,
673,
29952,
9885,
26028,
4256,
12,
673,
2455,
2193,
14,
22210,
1685,
21902,
304,
339,
4237,
63,
698,
275,
283,
2051,
7,
272,
7594,
275,
1323,
2821,
14,
1462,
14,
452,
342,
272,
2457,
63,
7765,
275,
334,
4273,
14,
2493,
265,
9323,
1692,
7980,
4131,
12,
776,
272,
4983,
63,
2888,
275,
359,
56,
2821,
17004,
12,
1622,
272,
9146,
63,
533,
275,
29062,
7299,
339,
347,
664,
63,
8349,
63,
533,
8,
277,
304,
267,
4237,
275,
291,
14,
958,
14,
362,
8,
277,
14,
3892,
63,
698,
9,
267,
340,
4237,
365,
440,
488,
26,
288,
9146,
63,
533,
275,
29062,
3244,
7299,
267,
587,
26,
288,
9146,
63,
533,
275,
971,
355,
1613,
8,
8257,
21902,
12,
291,
680,
362,
63,
8349,
63,
533,
342,
398,
372,
9146,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4618,
63,
4857,
492,
2455,
2193,
199,
199,
504,
641,
1517,
14,
5181,
14,
1246,
14,
6060,
492,
1323,
2821,
17004,
199,
504,
641,
1517,
14,
5181,
14,
2921,
14,
992,
14,
24226,
492,
1323,
2821,
199,
199,
504,
641,
1517,
14,
8450,
492,
4766,
199,
504,
641,
1517,
14,
8450,
14,
30192,
14,
12628,
63,
751,
63,
3455,
63,
3351,
63,
20406,
492,
334,
272,
29952,
9885,
26028,
4256,
9,
199,
504,
641,
1517,
14,
8450,
14,
30192,
14,
2019,
63,
5540,
63,
20406,
492,
15237,
11911,
4256,
199,
504,
641,
1517,
14,
8450,
14,
12844,
14,
3200,
63,
8349,
492,
334,
272,
29062,
7299,
12,
29062,
3244,
7299,
9,
421,
199,
533,
29062,
21902,
8,
6090,
11911,
4256,
12,
673,
29952,
9885,
26028,
4256,
12,
673,
2455,
2193,
14,
22210,
1685,
21902,
304,
339,
4237,
63,
698,
275,
283,
2051,
7,
272,
7594,
275,
1323,
2821,
14,
1462,
14,
452,
342,
272,
2457,
63,
7765,
275,
334,
4273,
14,
2493,
265,
9323,
1692,
7980,
4131,
12,
776,
272,
4983,
63,
2888,
275,
359,
56,
2821,
17004,
12,
1622,
272,
9146,
63,
533,
275,
29062,
7299,
339,
347,
664,
63,
8349,
63,
533,
8,
277,
304,
267,
4237,
275,
291,
14,
958,
14,
362,
8,
277,
14,
3892,
63,
698,
9,
267,
340,
4237,
365,
440,
488,
26,
288,
9146,
63,
533,
275,
29062,
3244,
7299,
267,
587,
26,
288,
9146,
63,
533,
275,
971,
355,
1613,
8,
8257,
21902,
12,
291,
680,
362,
63,
8349,
63,
533,
342,
398,
372,
9146,
63,
533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Soya93/Extract-Refactoring
|
python/helpers/py2only/docutils/io.py
|
48
|
14403
|
# $Id: io.py 6269 2010-03-18 22:27:53Z milde $
# Author: David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.
"""
I/O classes provide a uniform API for low-level input and output. Subclasses
will exist for a variety of input/output mechanisms.
"""
__docformat__ = 'reStructuredText'
import sys
try:
import locale
except:
pass
import re
import codecs
from docutils import TransformSpec
from docutils._compat import b
class Input(TransformSpec):
"""
Abstract base class for input wrappers.
"""
component_type = 'input'
default_source_path = None
def __init__(self, source=None, source_path=None, encoding=None,
error_handler='strict'):
self.encoding = encoding
"""Text encoding for the input source."""
self.error_handler = error_handler
"""Text decoding error handler."""
self.source = source
"""The source of input data."""
self.source_path = source_path
"""A text reference to the source."""
if not source_path:
self.source_path = self.default_source_path
self.successful_encoding = None
"""The encoding that successfully decoded the source data."""
def __repr__(self):
return '%s: source=%r, source_path=%r' % (self.__class__, self.source,
self.source_path)
def read(self):
raise NotImplementedError
def decode(self, data):
"""
Decode a string, `data`, heuristically.
Raise UnicodeError if unsuccessful.
The client application should call ``locale.setlocale`` at the
beginning of processing::
locale.setlocale(locale.LC_ALL, '')
"""
if self.encoding and self.encoding.lower() == 'unicode':
assert isinstance(data, unicode), (
'input encoding is "unicode" '
'but input is not a unicode object')
if isinstance(data, unicode):
# Accept unicode even if self.encoding != 'unicode'.
return data
if self.encoding:
# We believe the user/application when the encoding is
# explicitly given.
encodings = [self.encoding]
else:
data_encoding = self.determine_encoding_from_data(data)
if data_encoding:
# If the data declares its encoding (explicitly or via a BOM),
# we believe it.
encodings = [data_encoding]
else:
# Apply heuristics only if no encoding is explicitly given and
# no BOM found. Start with UTF-8, because that only matches
# data that *IS* UTF-8:
encodings = ['utf-8']
try:
encodings.append(locale.getlocale()[1])
except:
pass
try:
encodings.append(locale.getdefaultlocale()[1])
except:
pass
# fallback encoding:
encodings.append('latin-1')
error = None
error_details = ''
for enc in encodings:
if not enc:
continue
try:
decoded = unicode(data, enc, self.error_handler)
self.successful_encoding = enc
# Return decoded, removing BOMs.
return decoded.replace(u'\ufeff', u'')
except (UnicodeError, LookupError), tmperror:
error = tmperror # working around Python 3 deleting the
# error variable after the except clause
if error is not None:
error_details = '\n(%s: %s)' % (error.__class__.__name__, error)
raise UnicodeError(
'Unable to decode input data. Tried the following encodings: '
'%s.%s'
% (', '.join([repr(enc) for enc in encodings if enc]),
error_details))
coding_slug = re.compile(b("coding[:=]\s*([-\w.]+)"))
"""Encoding declaration pattern."""
byte_order_marks = ((codecs.BOM_UTF8, 'utf-8'), # actually 'utf-8-sig'
(codecs.BOM_UTF16_BE, 'utf-16-be'),
(codecs.BOM_UTF16_LE, 'utf-16-le'),)
"""Sequence of (start_bytes, encoding) tuples for encoding detection.
The first bytes of input data are checked against the start_bytes strings.
A match indicates the given encoding."""
def determine_encoding_from_data(self, data):
"""
Try to determine the encoding of `data` by looking *in* `data`.
Check for a byte order mark (BOM) or an encoding declaration.
"""
# check for a byte order mark:
for start_bytes, encoding in self.byte_order_marks:
if data.startswith(start_bytes):
return encoding
# check for an encoding declaration pattern in first 2 lines of file:
for line in data.splitlines()[:2]:
match = self.coding_slug.search(line)
if match:
return match.group(1).decode('ascii')
return None
class Output(TransformSpec):
"""
Abstract base class for output wrappers.
"""
component_type = 'output'
default_destination_path = None
def __init__(self, destination=None, destination_path=None,
encoding=None, error_handler='strict'):
self.encoding = encoding
"""Text encoding for the output destination."""
self.error_handler = error_handler or 'strict'
"""Text encoding error handler."""
self.destination = destination
"""The destination for output data."""
self.destination_path = destination_path
"""A text reference to the destination."""
if not destination_path:
self.destination_path = self.default_destination_path
def __repr__(self):
return ('%s: destination=%r, destination_path=%r'
% (self.__class__, self.destination, self.destination_path))
def write(self, data):
"""`data` is a Unicode string, to be encoded by `self.encode`."""
raise NotImplementedError
def encode(self, data):
if self.encoding and self.encoding.lower() == 'unicode':
assert isinstance(data, unicode), (
'the encoding given is "unicode" but the output is not '
'a Unicode string')
return data
if not isinstance(data, unicode):
# Non-unicode (e.g. binary) output.
return data
else:
return data.encode(self.encoding, self.error_handler)
class FileInput(Input):
"""
Input for single, simple file-like objects.
"""
def __init__(self, source=None, source_path=None,
encoding=None, error_handler='strict',
autoclose=1, handle_io_errors=1, mode='rU'):
"""
:Parameters:
- `source`: either a file-like object (which is read directly), or
`None` (which implies `sys.stdin` if no `source_path` given).
- `source_path`: a path to a file, which is opened and then read.
- `encoding`: the expected text encoding of the input file.
- `error_handler`: the encoding error handler to use.
- `autoclose`: close automatically after read (boolean); always
false if `sys.stdin` is the source.
- `handle_io_errors`: summarize I/O errors here, and exit?
- `mode`: how the file is to be opened (see standard function
`open`). The default 'rU' provides universal newline support
for text files.
"""
Input.__init__(self, source, source_path, encoding, error_handler)
self.autoclose = autoclose
self.handle_io_errors = handle_io_errors
if source is None:
if source_path:
# Specify encoding in Python 3
if sys.version_info >= (3,0):
kwargs = {'encoding': self.encoding,
'errors': self.error_handler}
else:
kwargs = {}
try:
self.source = open(source_path, mode, **kwargs)
except IOError, error:
if not handle_io_errors:
raise
print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error)
print >>sys.stderr, ('Unable to open source file for '
"reading ('%s'). Exiting." %
source_path)
sys.exit(1)
else:
self.source = sys.stdin
self.autoclose = None
if not source_path:
try:
self.source_path = self.source.name
except AttributeError:
pass
def read(self):
"""
Read and decode a single file and return the data (Unicode string).
"""
try:
data = self.source.read()
finally:
if self.autoclose:
self.close()
return self.decode(data)
def readlines(self):
"""
Return lines of a single file as list of Unicode strings.
"""
try:
lines = self.source.readlines()
finally:
if self.autoclose:
self.close()
return [self.decode(line) for line in lines]
def close(self):
self.source.close()
class FileOutput(Output):
"""
Output for single, simple file-like objects.
"""
def __init__(self, destination=None, destination_path=None,
encoding=None, error_handler='strict', autoclose=1,
handle_io_errors=1):
"""
:Parameters:
- `destination`: either a file-like object (which is written
directly) or `None` (which implies `sys.stdout` if no
`destination_path` given).
- `destination_path`: a path to a file, which is opened and then
written.
- `autoclose`: close automatically after write (boolean); always
false if `sys.stdout` is the destination.
"""
Output.__init__(self, destination, destination_path,
encoding, error_handler)
self.opened = 1
self.autoclose = autoclose
self.handle_io_errors = handle_io_errors
if destination is None:
if destination_path:
self.opened = None
else:
self.destination = sys.stdout
self.autoclose = None
if not destination_path:
try:
self.destination_path = self.destination.name
except AttributeError:
pass
def open(self):
# Specify encoding in Python 3.
# (Do not use binary mode ('wb') as this prevents the
# conversion of newlines to the system specific default.)
if sys.version_info >= (3,0):
kwargs = {'encoding': self.encoding,
'errors': self.error_handler}
else:
kwargs = {}
try:
self.destination = open(self.destination_path, 'w', **kwargs)
except IOError, error:
if not self.handle_io_errors:
raise
print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error)
print >>sys.stderr, ('Unable to open destination file for writing'
" ('%s'). Exiting." % self.destination_path)
sys.exit(1)
self.opened = 1
def write(self, data):
"""Encode `data`, write it to a single file, and return it.
In Python 3, a (unicode) String is returned.
"""
if sys.version_info >= (3,0):
output = data # in py3k, write expects a (Unicode) string
else:
output = self.encode(data)
if not self.opened:
self.open()
try:
self.destination.write(output)
finally:
if self.autoclose:
self.close()
return output
def close(self):
self.destination.close()
self.opened = None
class BinaryFileOutput(FileOutput):
"""
A version of docutils.io.FileOutput which writes to a binary file.
"""
def open(self):
try:
self.destination = open(self.destination_path, 'wb')
except IOError, error:
if not self.handle_io_errors:
raise
print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error)
print >>sys.stderr, ('Unable to open destination file for writing '
"('%s'). Exiting." % self.destination_path)
sys.exit(1)
self.opened = 1
class StringInput(Input):
"""
Direct string input.
"""
default_source_path = '<string>'
def read(self):
"""Decode and return the source string."""
return self.decode(self.source)
class StringOutput(Output):
"""
Direct string output.
"""
default_destination_path = '<string>'
def write(self, data):
"""Encode `data`, store it in `self.destination`, and return it."""
self.destination = self.encode(data)
return self.destination
class NullInput(Input):
"""
Degenerate input: read nothing.
"""
default_source_path = 'null input'
def read(self):
"""Return a null string."""
return u''
class NullOutput(Output):
"""
Degenerate output: write nothing.
"""
default_destination_path = 'null output'
def write(self, data):
"""Do nothing ([don't even] send data to the bit bucket)."""
pass
class DocTreeInput(Input):
"""
Adapter for document tree input.
The document tree must be passed in the ``source`` parameter.
"""
default_source_path = 'doctree input'
def read(self):
"""Return the document tree."""
return self.source
|
apache-2.0
|
[
3,
2672,
1304,
26,
5890,
14,
647,
1227,
12442,
7129,
13,
1644,
13,
1085,
6928,
26,
1465,
26,
2481,
58,
333,
24446,
2672,
199,
3,
6529,
26,
20232,
22311,
836,
665,
8302,
836,
32,
1548,
14,
1308,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
624,
199,
41,
15,
47,
3992,
5647,
282,
14818,
3261,
367,
6465,
13,
1896,
1324,
436,
1072,
14,
221,
20196,
199,
14117,
2187,
367,
282,
32246,
402,
1324,
15,
1199,
562,
10832,
706,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
199,
199,
646,
984,
199,
893,
26,
272,
492,
5867,
199,
2590,
26,
272,
986,
199,
646,
295,
199,
646,
6010,
199,
504,
18382,
492,
19463,
5307,
199,
504,
18382,
423,
5819,
492,
330,
421,
199,
533,
6924,
8,
6939,
5307,
304,
339,
408,
272,
11836,
1300,
1021,
367,
1324,
17995,
14,
272,
408,
339,
3931,
63,
466,
275,
283,
1210,
7,
339,
849,
63,
1365,
63,
515,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1350,
29,
403,
12,
1350,
63,
515,
29,
403,
12,
2644,
29,
403,
12,
326,
1125,
63,
2232,
534,
4768,
735,
267,
291,
14,
2991,
275,
2644,
267,
408,
1872,
2644,
367,
314,
1324,
1350,
1041,
398,
291,
14,
705,
63,
2232,
275,
1125,
63,
2232,
267,
408,
1872,
15952,
1125,
3016,
1041,
398,
291,
14,
1365,
275,
1350,
267,
408,
1918,
1350,
402,
1324,
666,
1041,
398,
291,
14,
1365,
63,
515,
275,
1350,
63,
515,
267,
408,
33,
1318,
3659,
370,
314,
1350,
1041,
398,
340,
440,
1350,
63,
515,
26,
288,
291,
14,
1365,
63,
515,
275,
291,
14,
885,
63,
1365,
63,
515,
398,
291,
14,
18157,
63,
2991,
275,
488,
267,
408,
1918,
2644,
626,
8792,
11203,
314,
1350,
666,
1041,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
26,
1350,
2458,
82,
12,
1350,
63,
515,
2458,
82,
7,
450,
334,
277,
855,
533,
3108,
291,
14,
1365,
12,
8179,
291,
14,
1365,
63,
515,
9,
339,
347,
1586,
8,
277,
304,
267,
746,
4279,
339,
347,
4849,
8,
277,
12,
666,
304,
267,
408,
267,
22462,
282,
1059,
12,
658,
576,
3559,
25332,
1183,
14,
267,
14771,
20872,
340,
625,
18157,
14,
398,
710,
1890,
4223,
1077,
1240,
1124,
5508,
14,
409,
5508,
1040,
737,
314,
267,
9608,
402,
6661,
447,
953,
5867,
14,
409,
5508,
8,
5508,
14,
7027,
63,
1761,
12,
4074,
267,
408,
267,
340,
291,
14,
2991,
436,
291,
14,
2991,
14,
2325,
342,
508,
283,
2975,
356,
288,
702,
1228,
8,
576,
12,
2649,
395,
334,
355,
283,
1210,
2644,
365,
298,
2975,
2,
283,
355,
283,
7911,
1324,
365,
440,
282,
2649,
909,
358,
267,
340,
1228,
8,
576,
12,
2649,
304,
288,
327,
15506,
2649,
2755,
340,
291,
14,
2991,
1137,
283,
2975,
1370,
288,
372,
666,
267,
340,
291,
14,
2991,
26,
288,
327,
2136,
506,
317,
4754,
314,
922,
15,
3578,
1380,
314,
2644,
365,
288,
327,
7662,
1627,
14,
288,
14134,
275,
359,
277,
14,
2991,
61,
267,
587,
26,
288,
666,
63,
2991,
275,
291,
14,
22189,
63,
2991,
63,
504,
63,
576,
8,
576,
9,
288,
340,
666,
63,
2991,
26,
355,
327,
982,
314,
666,
477,
3995,
470,
2399,
2644,
334,
10306,
590,
503,
4799,
282,
17720,
395,
355,
327,
781,
506,
317,
4754,
652,
14,
355,
14134,
275,
359,
576,
63,
2991,
61,
288,
587,
26,
355,
327,
14618,
946,
300,
631,
2932,
1454,
340,
949,
2644,
365,
7662,
1627,
436,
355,
327,
949,
17720,
1911,
14,
221,
7707,
543,
9094,
13,
24,
12,
2952,
626,
1454,
4450,
355,
327,
666,
626,
627,
1311,
10,
9094,
13,
24,
26,
355,
14134,
275,
788,
1624,
13,
24,
418,
355,
862,
26,
490,
14134,
14,
740,
8,
5508,
14,
362,
5508,
3430,
17,
566,
355,
871,
26,
490,
986,
355,
862,
26,
490,
14134,
14,
740,
8,
5508,
14,
362,
885,
5508,
3430,
17,
566,
355,
871,
26,
490,
986,
355,
327,
9567,
2644,
26,
355,
14134,
14,
740,
360,
10378,
13,
17,
358,
267,
1125,
275,
488,
267,
1125,
63,
5087,
275,
2125,
267,
367,
12011,
315,
14134,
26,
288,
340,
440,
12011,
26,
355,
1980,
288,
862,
26,
355,
11203,
275,
2649,
8,
576,
12,
12011,
12,
291,
14,
705,
63,
2232,
9,
355,
291,
14,
18157,
63,
2991,
275,
12011,
355,
327,
1432,
11203,
12,
12881,
4367,
13586,
14,
355,
372,
11203,
14,
1814,
8,
85,
1154,
7224,
556,
297,
399,
17483,
288,
871,
334,
7087,
547,
12,
19021,
395,
3529,
705,
26,
355,
1125,
275,
3529,
705,
221,
327,
6449,
6818,
2018,
650,
13794,
314,
3303,
327,
1125,
1750,
2410,
314,
871,
8502,
267,
340,
1125,
365,
440,
488,
26,
288,
1125,
63,
5087,
275,
1557,
78,
4042,
83,
26,
450,
83,
3171,
450,
334,
705,
855,
533,
4914,
354,
3108,
1125,
9,
267,
746,
20872,
8,
288,
283,
6005,
370,
4849,
1324,
666,
14,
221,
12480,
379,
314,
2569,
14134,
26,
283,
288,
1543,
83,
4111,
83,
7,
288,
450,
334,
297,
1987,
904,
779,
2722,
8,
10945,
9,
367,
12011,
315,
14134,
340,
12011,
2522,
2049,
1125,
63,
5087,
430,
339,
2803,
63,
5464,
275,
295,
14,
2014,
8,
66,
480,
1523,
1491,
29,
7272,
83,
10,
779,
2696,
87,
14,
11896,
2237,
272,
408,
7630,
12560,
3851,
1041,
339,
3696,
63,
1648,
63,
10375,
275,
3666,
8933,
14,
19550,
63,
6610,
24,
12,
283,
1624,
13,
24,
659,
327,
5965,
283,
1624,
13,
24,
13,
4093,
7,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
12,
283,
1624,
13,
975,
13,
1235,
659,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
906,
12,
283,
1624,
13,
975,
13,
274,
659,
9,
272,
408,
5826,
402,
334,
928,
63,
2394,
12,
2644,
9,
6346,
367,
2644,
15212,
14,
272,
710,
1642,
2783,
402,
1324,
666,
787,
7923,
6169,
314,
1343,
63,
2394,
3326,
14,
272,
437,
1336,
9126,
314,
1627,
2644,
1041,
339,
347,
6705,
63,
2991,
63,
504,
63,
576,
8,
277,
12,
666,
304,
267,
408,
267,
7649,
370,
6705,
314,
2644,
402
] |
[
2672,
1304,
26,
5890,
14,
647,
1227,
12442,
7129,
13,
1644,
13,
1085,
6928,
26,
1465,
26,
2481,
58,
333,
24446,
2672,
199,
3,
6529,
26,
20232,
22311,
836,
665,
8302,
836,
32,
1548,
14,
1308,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
624,
199,
41,
15,
47,
3992,
5647,
282,
14818,
3261,
367,
6465,
13,
1896,
1324,
436,
1072,
14,
221,
20196,
199,
14117,
2187,
367,
282,
32246,
402,
1324,
15,
1199,
562,
10832,
706,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
199,
199,
646,
984,
199,
893,
26,
272,
492,
5867,
199,
2590,
26,
272,
986,
199,
646,
295,
199,
646,
6010,
199,
504,
18382,
492,
19463,
5307,
199,
504,
18382,
423,
5819,
492,
330,
421,
199,
533,
6924,
8,
6939,
5307,
304,
339,
408,
272,
11836,
1300,
1021,
367,
1324,
17995,
14,
272,
408,
339,
3931,
63,
466,
275,
283,
1210,
7,
339,
849,
63,
1365,
63,
515,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1350,
29,
403,
12,
1350,
63,
515,
29,
403,
12,
2644,
29,
403,
12,
326,
1125,
63,
2232,
534,
4768,
735,
267,
291,
14,
2991,
275,
2644,
267,
408,
1872,
2644,
367,
314,
1324,
1350,
1041,
398,
291,
14,
705,
63,
2232,
275,
1125,
63,
2232,
267,
408,
1872,
15952,
1125,
3016,
1041,
398,
291,
14,
1365,
275,
1350,
267,
408,
1918,
1350,
402,
1324,
666,
1041,
398,
291,
14,
1365,
63,
515,
275,
1350,
63,
515,
267,
408,
33,
1318,
3659,
370,
314,
1350,
1041,
398,
340,
440,
1350,
63,
515,
26,
288,
291,
14,
1365,
63,
515,
275,
291,
14,
885,
63,
1365,
63,
515,
398,
291,
14,
18157,
63,
2991,
275,
488,
267,
408,
1918,
2644,
626,
8792,
11203,
314,
1350,
666,
1041,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
26,
1350,
2458,
82,
12,
1350,
63,
515,
2458,
82,
7,
450,
334,
277,
855,
533,
3108,
291,
14,
1365,
12,
8179,
291,
14,
1365,
63,
515,
9,
339,
347,
1586,
8,
277,
304,
267,
746,
4279,
339,
347,
4849,
8,
277,
12,
666,
304,
267,
408,
267,
22462,
282,
1059,
12,
658,
576,
3559,
25332,
1183,
14,
267,
14771,
20872,
340,
625,
18157,
14,
398,
710,
1890,
4223,
1077,
1240,
1124,
5508,
14,
409,
5508,
1040,
737,
314,
267,
9608,
402,
6661,
447,
953,
5867,
14,
409,
5508,
8,
5508,
14,
7027,
63,
1761,
12,
4074,
267,
408,
267,
340,
291,
14,
2991,
436,
291,
14,
2991,
14,
2325,
342,
508,
283,
2975,
356,
288,
702,
1228,
8,
576,
12,
2649,
395,
334,
355,
283,
1210,
2644,
365,
298,
2975,
2,
283,
355,
283,
7911,
1324,
365,
440,
282,
2649,
909,
358,
267,
340,
1228,
8,
576,
12,
2649,
304,
288,
327,
15506,
2649,
2755,
340,
291,
14,
2991,
1137,
283,
2975,
1370,
288,
372,
666,
267,
340,
291,
14,
2991,
26,
288,
327,
2136,
506,
317,
4754,
314,
922,
15,
3578,
1380,
314,
2644,
365,
288,
327,
7662,
1627,
14,
288,
14134,
275,
359,
277,
14,
2991,
61,
267,
587,
26,
288,
666,
63,
2991,
275,
291,
14,
22189,
63,
2991,
63,
504,
63,
576,
8,
576,
9,
288,
340,
666,
63,
2991,
26,
355,
327,
982,
314,
666,
477,
3995,
470,
2399,
2644,
334,
10306,
590,
503,
4799,
282,
17720,
395,
355,
327,
781,
506,
317,
4754,
652,
14,
355,
14134,
275,
359,
576,
63,
2991,
61,
288,
587,
26,
355,
327,
14618,
946,
300,
631,
2932,
1454,
340,
949,
2644,
365,
7662,
1627,
436,
355,
327,
949,
17720,
1911,
14,
221,
7707,
543,
9094,
13,
24,
12,
2952,
626,
1454,
4450,
355,
327,
666,
626,
627,
1311,
10,
9094,
13,
24,
26,
355,
14134,
275,
788,
1624,
13,
24,
418,
355,
862,
26,
490,
14134,
14,
740,
8,
5508,
14,
362,
5508,
3430,
17,
566,
355,
871,
26,
490,
986,
355,
862,
26,
490,
14134,
14,
740,
8,
5508,
14,
362,
885,
5508,
3430,
17,
566,
355,
871,
26,
490,
986,
355,
327,
9567,
2644,
26,
355,
14134,
14,
740,
360,
10378,
13,
17,
358,
267,
1125,
275,
488,
267,
1125,
63,
5087,
275,
2125,
267,
367,
12011,
315,
14134,
26,
288,
340,
440,
12011,
26,
355,
1980,
288,
862,
26,
355,
11203,
275,
2649,
8,
576,
12,
12011,
12,
291,
14,
705,
63,
2232,
9,
355,
291,
14,
18157,
63,
2991,
275,
12011,
355,
327,
1432,
11203,
12,
12881,
4367,
13586,
14,
355,
372,
11203,
14,
1814,
8,
85,
1154,
7224,
556,
297,
399,
17483,
288,
871,
334,
7087,
547,
12,
19021,
395,
3529,
705,
26,
355,
1125,
275,
3529,
705,
221,
327,
6449,
6818,
2018,
650,
13794,
314,
3303,
327,
1125,
1750,
2410,
314,
871,
8502,
267,
340,
1125,
365,
440,
488,
26,
288,
1125,
63,
5087,
275,
1557,
78,
4042,
83,
26,
450,
83,
3171,
450,
334,
705,
855,
533,
4914,
354,
3108,
1125,
9,
267,
746,
20872,
8,
288,
283,
6005,
370,
4849,
1324,
666,
14,
221,
12480,
379,
314,
2569,
14134,
26,
283,
288,
1543,
83,
4111,
83,
7,
288,
450,
334,
297,
1987,
904,
779,
2722,
8,
10945,
9,
367,
12011,
315,
14134,
340,
12011,
2522,
2049,
1125,
63,
5087,
430,
339,
2803,
63,
5464,
275,
295,
14,
2014,
8,
66,
480,
1523,
1491,
29,
7272,
83,
10,
779,
2696,
87,
14,
11896,
2237,
272,
408,
7630,
12560,
3851,
1041,
339,
3696,
63,
1648,
63,
10375,
275,
3666,
8933,
14,
19550,
63,
6610,
24,
12,
283,
1624,
13,
24,
659,
327,
5965,
283,
1624,
13,
24,
13,
4093,
7,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
12,
283,
1624,
13,
975,
13,
1235,
659,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
906,
12,
283,
1624,
13,
975,
13,
274,
659,
9,
272,
408,
5826,
402,
334,
928,
63,
2394,
12,
2644,
9,
6346,
367,
2644,
15212,
14,
272,
710,
1642,
2783,
402,
1324,
666,
787,
7923,
6169,
314,
1343,
63,
2394,
3326,
14,
272,
437,
1336,
9126,
314,
1627,
2644,
1041,
339,
347,
6705,
63,
2991,
63,
504,
63,
576,
8,
277,
12,
666,
304,
267,
408,
267,
7649,
370,
6705,
314,
2644,
402,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
liaoyuke/EECS542_Final_Project_VQA
|
code/concept_extraction/lib/en/parser/nltk_lite/chat/zen.py
|
9
|
9944
|
# Natural Language Toolkit: Zen Chatbot
#
# Copyright (C) 2005-2006 University of Melbourne
# Author: Amy Holland <amyrh@csse.unimelb.edu.au>
# URL: <http://nltk.sf.net>
# For license information, see LICENSE.TXT
"""
Zen Chatbot talks in gems of Zen wisdom.
This is a sample conversation with Zen Chatbot:
ZC: Welcome, my child.
me: Good afternoon.
ZC: Ask the question you have come to ask.
me: How can I achieve enlightenment?
ZC: How do you suppose?
me: Through meditation.
ZC: Form is emptiness, and emptiness form.
me: How can I empty my mind of worldly troubles?
ZC: Will an answer to that really help in your search for enlightenment?
me: Yes.
ZC: It is better to be right than to be certain.
me: I seek truth and wisdom.
ZC: The search for truth is a long journey.
me: Are you sure?
ZC: Maybe sure, maybe not sure.
The chatbot structure is based on that of chat.eliza. Thus, it uses
a translation table to convert from question to response
i.e. "I am" --> "you are"
Of course, since Zen Chatbot does not understand the meaning of any words,
responses are very limited. Zen Chatbot will usually answer very vaguely, or
respond to a question by asking a different question, in much the same way
as Eliza.
"""
from en.parser.nltk_lite.chat import *
# responses are matched top to bottom, so non-specific matches occur later
# for each match, a list of possible responses is provided
responses = (
# Zen Chatbot opens with the line "Welcome, my child." The usual
# response will be a greeting problem: 'good' matches "good morning",
# "good day" etc, but also "good grief!" and other sentences starting
# with the word 'good' that may not be a greeting
(r'(hello(.*))|(good [a-zA-Z]+)',
( "The path to enlightenment is often difficult to see.",
"Greetings. I sense your mind is troubled. Tell me of your troubles.",
"Ask the question you have come to ask.",
"Hello. Do you seek englightenment?")),
# "I need" and "I want" can be followed by a thing (eg 'help')
# or an action (eg 'to see you')
#
# This is a problem with this style of response -
# person: "I need you"
# chatbot: "me can be achieved by hard work and dedication of the mind"
# i.e. 'you' is not really a thing that can be mapped this way, so this
# interpretation only makes sense for some inputs
#
(r'i need (.*)',
( "%1 can be achieved by hard work and dedication of the mind.",
"%1 is not a need, but a desire of the mind. Clear your mind of such concerns.",
"Focus your mind on%1, and you will find what you need.")),
(r'i want (.*)',
( "Desires of the heart will distract you from the path to enlightenment.",
"Will%1 help you attain enlightenment?",
"Is%1 a desire of the mind, or of the heart?")),
# why questions are separated into three types:
# "why..I" e.g. "why am I here?" "Why do I like cake?"
# "why..you" e.g. "why are you here?" "Why won't you tell me?"
# "why..." e.g. "Why is the sky blue?"
# problems:
# person: "Why can't you tell me?"
# chatbot: "Are you sure I tell you?"
# - this style works for positives (e.g. "why do you like cake?")
# but does not work for negatives (e.g. "why don't you like cake?")
(r'why (.*) i (.*)\?',
( "You%1%2?",
"Perhaps you only think you%1%2")),
(r'why (.*) you(.*)\?',
( "Why%1 you%2?",
"%2 I%1",
"Are you sure I%2?")),
(r'why (.*)\?',
( "I cannot tell you why%1.",
"Why do you think %1?" )),
# e.g. "are you listening?", "are you a duck"
(r'are you (.*)\?',
( "Maybe%1, maybe not%1.",
"Whether I am%1 or not is God's business.")),
# e.g. "am I a duck?", "am I going to die?"
(r'am i (.*)\?',
( "Perhaps%1, perhaps not%1.",
"Whether you are%1 or not is not for me to say.")),
# what questions, e.g. "what time is it?"
# problems:
# person: "What do you want?"
# chatbot: "Seek truth, not what do me want."
(r'what (.*)\?',
( "Seek truth, not what%1.",
"What%1 should not concern you.")),
# how questions, e.g. "how do you do?"
(r'how (.*)\?',
( "How do you suppose?",
"Will an answer to that really help in your search for enlightenment?",
"Ask yourself not how, but why.")),
# can questions, e.g. "can you run?", "can you come over here please?"
(r'can you (.*)\?',
( "I probably can, but I may not.",
"Maybe I can%1, and maybe I cannot.",
"I can do all, and I can do nothing.")),
# can questions, e.g. "can I have some cake?", "can I know truth?"
(r'can i (.*)\?',
( "You can%1 if you believe you can%1, and have a pure spirit.",
"Seek truth and you will know if you can%1.")),
# e.g. "It is raining" - implies the speaker is certain of a fact
(r'it is (.*)',
( "How can you be certain that%1, when you do not even know yourself?",
"Whether it is%1 or not does not change the way the world is.")),
# e.g. "is there a doctor in the house?"
(r'is there (.*)\?',
( "There is%1 if you believe there is.",
"It is possible that there is%1.")),
# e.g. "is it possible?", "is this true?"
(r'is(.*)\?',
( "%1 is not relevant.",
"Does this matter?")),
# non-specific question
(r'(.*)\?',
( "Do you think %1?",
"You seek the truth. Does the truth seek you?",
"If you intentionally pursue the answers to your questions, the answers become hard to see.",
"The answer to your question cannot be told. It must be experienced.")),
# expression of hate of form "I hate you" or "Kelly hates cheese"
(r'(.*) (hate[s]?)|(dislike[s]?)|(don\'t like)(.*)',
( "Perhaps it is not about hating %2, but about hate from within.",
"Weeds only grow when we dislike them",
"Hate is a very strong emotion.")),
# statement containing the word 'truth'
(r'(.*) truth(.*)',
( "Seek truth, and truth will seek you.",
"Remember, it is not the spoon which bends - only yourself.",
"The search for truth is a long journey.")),
# desire to do an action
# e.g. "I want to go shopping"
(r'i want to (.*)',
( "You may %1 if your heart truely desires to.",
"You may have to %1.")),
# desire for an object
# e.g. "I want a pony"
(r'i want (.*)',
( "Does your heart truely desire %1?",
"Is this a desire of the heart, or of the mind?")),
# e.g. "I can't wait" or "I can't do this"
(r'i can\'t (.*)',
( "What we can and can't do is a limitation of the mind.",
"There are limitations of the body, and limitations of the mind.",
"Have you tried to%1 with a clear mind?")),
# "I think.." indicates uncertainty. e.g. "I think so."
# problem: exceptions...
# e.g. "I think, therefore I am"
(r'i think (.*)',
( "Uncertainty in an uncertain world.",
"Indeed, how can we be certain of anything in such uncertain times.",
"Are you not, in fact, certain that%1?")),
# "I feel...emotions/sick/light-headed..."
(r'i feel (.*)',
( "Your body and your emotions are both symptoms of your mind."
"What do you believe is the root of such feelings?",
"Feeling%1 can be a sign of your state-of-mind.")),
# exclaimation mark indicating emotion
# e.g. "Wow!" or "No!"
(r'(.*)!',
( "I sense that you are feeling emotional today.",
"You need to calm your emotions.")),
# because [statement]
# e.g. "because I said so"
(r'because (.*)',
( "Does knowning the reasons behind things help you to understand"
" the things themselves?",
"If%1, what else must be true?")),
# yes or no - raise an issue of certainty/correctness
(r'(yes)|(no)',
( "Is there certainty in an uncertain world?",
"It is better to be right than to be certain.")),
# sentence containing word 'love'
(r'(.*)love(.*)',
( "Think of the trees: they let the birds perch and fly with no intention to call them when they come, and no longing for their return when they fly away. Let your heart be like the trees.",
"Free love!")),
# sentence containing word 'understand' - r
(r'(.*)understand(.*)',
( "If you understand, things are just as they are;"
" if you do not understand, things are just as they are.",
"Imagination is more important than knowledge.")),
# 'I', 'me', 'my' - person is talking about themself.
# this breaks down when words contain these - eg 'Thyme', 'Irish'
(r'(.*)(me )|( me)|(my)|(mine)|(i)(.*)',
( "'I', 'me', 'my'... these are selfish expressions.",
"Have you ever considered that you might be a selfish person?",
"Try to consider others, not just yourself.",
"Think not just of yourself, but of others.")),
# 'you' starting a sentence
# e.g. "you stink!"
(r'you (.*)',
( "My path is not of conern to you.",
"I am but one, and you but one more.")),
# say goodbye with some extra Zen wisdom.
(r'exit',
( "Farewell. The obstacle is the path.",
"Farewell. Life is a journey, not a destination.",
"Good bye. We are cups, constantly and quietly being filled."
"\nThe trick is knowning how to tip ourselves over and let the beautiful stuff out.")),
# fall through case -
# when stumped, respond with generic zen wisdom
#
(r'(.*)',
( "When you're enlightened, every word is wisdom.",
"Random talk is useless.",
"The reverse side also has a reverse side.",
"Form is emptiness, and emptiness is form.",
"I pour out a cup of water. Is the cup empty?"))
)
zen = Chat(responses, reflections)
def demo():
print '*'*75
print "Zen Chatbot!".center(75)
print '*'*75
print '"Look beyond mere words and letters - look into your mind"'.center(75)
print "* Talk your way to truth with Zen Chatbot."
print "* Type 'quit' when you have had enough."
print '*'*75
print "Welcome, my child."
converse(zen)
if __name__ == "__main__":
demo()
|
mit
|
[
3,
653,
292,
4889,
8466,
15650,
6065,
26,
3107,
287,
2799,
292,
3018,
199,
3,
199,
3,
1898,
334,
35,
9,
11811,
13,
7968,
15904,
402,
603,
352,
656,
349,
69,
199,
3,
6529,
26,
437,
1662,
869,
393,
9688,
665,
455,
89,
17157,
32,
1259,
261,
14,
324,
1036,
6374,
14,
8654,
14,
3844,
30,
199,
3,
2851,
26,
665,
1014,
921,
7530,
2663,
14,
7646,
14,
846,
30,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
199,
624,
199,
58,
287,
2799,
292,
3018,
22811,
83,
315,
2312,
706,
402,
3107,
287,
336,
374,
4556,
14,
199,
199,
2765,
365,
282,
2690,
3818,
20592,
543,
3107,
287,
2799,
292,
3018,
26,
199,
58,
35,
26,
259,
644,
14628,
12,
3002,
1982,
14,
199,
278,
26,
259,
22311,
2410,
889,
265,
14,
199,
58,
35,
26,
259,
30481,
314,
7894,
1265,
1172,
11492,
370,
7198,
14,
199,
278,
26,
259,
7494,
883,
473,
32194,
655,
18975,
724,
434,
31,
199,
58,
35,
26,
259,
7494,
886,
1265,
1029,
4070,
31,
199,
278,
26,
259,
3868,
3202,
562,
1741,
425,
14,
199,
58,
35,
26,
259,
8204,
365,
325,
4787,
9585,
12,
436,
325,
4787,
9585,
1824,
14,
199,
278,
26,
259,
7494,
883,
473,
2701,
3002,
25169,
402,
6701,
590,
29616,
83,
31,
199,
58,
35,
26,
259,
12823,
376,
6385,
370,
626,
7710,
1720,
315,
2195,
2754,
367,
655,
18975,
724,
434,
31,
199,
278,
26,
259,
29715,
14,
199,
58,
35,
26,
259,
2779,
365,
8034,
370,
506,
2451,
2419,
370,
506,
9842,
14,
199,
278,
26,
259,
473,
12005,
16865,
436,
336,
374,
4556,
14,
199,
58,
35,
26,
259,
710,
2754,
367,
16865,
365,
282,
1846,
5225,
349,
14655,
14,
199,
278,
26,
259,
23889,
1265,
3238,
31,
199,
58,
35,
26,
259,
23038,
3238,
12,
11703,
440,
3238,
14,
421,
199,
1918,
21472,
3018,
5523,
365,
4079,
641,
626,
402,
21472,
14,
18865,
8076,
14,
20227,
12,
652,
4440,
199,
65,
7761,
1817,
370,
3957,
687,
7894,
370,
1177,
199,
73,
14,
69,
14,
298,
41,
8140,
2,
10541,
298,
13297,
787,
2,
199,
199,
3466,
2518,
12,
3967,
3107,
287,
2799,
292,
3018,
1630,
440,
20647,
314,
11150,
402,
1263,
5932,
12,
199,
10360,
787,
7437,
13988,
14,
3107,
287,
2799,
292,
3018,
911,
9987,
6385,
7437,
373,
30904,
590,
12,
503,
199,
22720,
370,
282,
7894,
701,
7198,
316,
282,
3365,
7894,
12,
315,
8298,
314,
2011,
4340,
199,
305,
662,
317,
8076,
14,
199,
624,
199,
199,
504,
655,
14,
2087,
14,
7530,
2663,
63,
5333,
14,
10289,
492,
627,
199,
199,
3,
9320,
787,
7838,
2746,
370,
9048,
12,
880,
2222,
13,
6100,
4450,
4781,
2945,
199,
3,
367,
1924,
1336,
12,
282,
769,
402,
3962,
9320,
365,
2741,
199,
10360,
275,
334,
199,
199,
3,
3107,
287,
2799,
292,
3018,
30848,
543,
314,
1004,
298,
24679,
12,
3002,
1982,
2122,
710,
20195,
199,
3,
1177,
911,
506,
282,
486,
23457,
5160,
26,
283,
8302,
7,
4450,
298,
8302,
21333,
1835,
401,
199,
3,
298,
8302,
5382,
2,
5423,
12,
1325,
2597,
298,
8302,
27591,
2829,
9539,
221,
436,
1163,
24256,
6617,
199,
3,
543,
314,
4349,
283,
8302,
7,
626,
1443,
440,
506,
282,
486,
23457,
339,
334,
82,
6774,
5006,
19276,
430,
92,
8,
8302,
359,
65,
13,
6353,
13,
58,
28798,
272,
334,
298,
1918,
931,
370,
655,
18975,
724,
434,
365,
14115,
29870,
370,
1937,
4765,
489,
298,
39,
7936,
780,
14,
473,
12249,
2195,
25169,
365,
22621,
456,
1146,
14,
30528,
562,
402,
2195,
29616,
83,
4765,
489,
298,
25525,
314,
7894,
1265,
1172,
11492,
370,
7198,
4765,
489,
298,
6257,
14,
4226,
1265,
12005,
20171,
18975,
724,
434,
31,
8150,
2043,
199,
199,
3,
298,
41,
1929,
2,
436,
298,
41,
2934,
2,
883,
506,
9437,
701,
282,
8377,
334,
5902,
283,
3437,
358,
199,
3,
503,
376,
1595,
334,
5902,
283,
475,
1937,
1265,
358,
199,
3,
199,
3,
961,
365,
282,
5160,
543,
642,
3449,
402,
1177,
446,
257,
199,
3,
4954,
26,
259,
298,
41,
1929,
1265,
2,
199,
3,
21472,
3018,
26,
259,
298,
278,
883,
506,
22175,
1354,
701,
7508,
1736,
436,
477,
21171,
402,
314,
25169,
2,
199,
3,
284,
14,
69,
14,
283,
13297,
7,
365,
440,
7710,
282,
8377,
626,
883,
506,
9994,
642,
4340,
12,
880,
642,
199,
3,
28426,
1454,
7704,
12249,
367,
2005,
4153,
199,
3,
272,
334,
82,
7,
73,
1929,
334,
2795,
3196,
272,
334,
2071,
17,
883,
506,
22175,
1354,
701,
7508,
1736,
436,
477,
21171,
402,
314,
25169,
4765,
489,
2071,
17,
365,
440,
282,
1929,
12,
1325,
282,
477,
338,
264,
402,
314,
25169,
14,
14836,
2195,
25169,
402,
4066,
406,
2247,
561,
4765,
489,
298,
17310,
2195,
25169,
641,
5,
17,
12,
436,
1265,
911,
2342,
4052,
1265,
1929,
2685,
395,
339,
334,
82,
7,
73,
2934,
334,
2795,
3196,
272,
334,
298,
872,
338,
470,
402,
314,
946,
580,
911,
2917,
1957,
1265,
687,
314,
931,
370,
655,
18975,
724,
434,
4765,
489,
298,
20326,
5,
17,
1720,
1265,
737,
877,
655,
18975,
724,
434,
15583,
489,
298,
1831,
5,
17,
282,
477,
338,
264,
402,
314,
25169,
12,
503,
402,
314,
946,
580,
31,
8150,
2043,
199,
199,
3,
10842,
23071,
787,
11673,
1901,
7795,
2943,
26,
199,
3,
298,
26460,
703,
41,
2,
258,
325,
14,
71,
14,
298,
26460,
8140,
473,
2348,
13472,
298,
55,
3577,
886,
473,
2839,
1704,
415,
13472,
199,
3,
298,
26460,
703,
13297,
2,
259,
325,
14,
71,
14,
298,
26460,
787,
1265,
2348,
13472,
298,
55,
3577,
7859,
1133,
1265,
11480,
562,
13472,
199,
3,
298,
26460,
11500,
259,
325,
14,
71,
14,
298,
55,
3577,
365,
314,
2386,
89,
10030,
13472,
199,
3,
8826,
26,
199,
3,
258,
4954,
26,
221,
298,
55,
3577,
883,
1133,
1265,
11480,
562,
13472,
199,
3,
258,
21472,
3018,
26,
298,
17683,
1265,
3238,
473,
11480,
1265,
13472,
199,
3,
446,
642,
3449,
5419,
367,
27609,
334,
69,
14,
71,
14,
298,
26460,
886,
1265,
2839,
1704,
415,
18582,
199,
3,
257,
1325,
1630,
440,
1736,
367,
14158,
10661,
334,
69
] |
[
653,
292,
4889,
8466,
15650,
6065,
26,
3107,
287,
2799,
292,
3018,
199,
3,
199,
3,
1898,
334,
35,
9,
11811,
13,
7968,
15904,
402,
603,
352,
656,
349,
69,
199,
3,
6529,
26,
437,
1662,
869,
393,
9688,
665,
455,
89,
17157,
32,
1259,
261,
14,
324,
1036,
6374,
14,
8654,
14,
3844,
30,
199,
3,
2851,
26,
665,
1014,
921,
7530,
2663,
14,
7646,
14,
846,
30,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
199,
624,
199,
58,
287,
2799,
292,
3018,
22811,
83,
315,
2312,
706,
402,
3107,
287,
336,
374,
4556,
14,
199,
199,
2765,
365,
282,
2690,
3818,
20592,
543,
3107,
287,
2799,
292,
3018,
26,
199,
58,
35,
26,
259,
644,
14628,
12,
3002,
1982,
14,
199,
278,
26,
259,
22311,
2410,
889,
265,
14,
199,
58,
35,
26,
259,
30481,
314,
7894,
1265,
1172,
11492,
370,
7198,
14,
199,
278,
26,
259,
7494,
883,
473,
32194,
655,
18975,
724,
434,
31,
199,
58,
35,
26,
259,
7494,
886,
1265,
1029,
4070,
31,
199,
278,
26,
259,
3868,
3202,
562,
1741,
425,
14,
199,
58,
35,
26,
259,
8204,
365,
325,
4787,
9585,
12,
436,
325,
4787,
9585,
1824,
14,
199,
278,
26,
259,
7494,
883,
473,
2701,
3002,
25169,
402,
6701,
590,
29616,
83,
31,
199,
58,
35,
26,
259,
12823,
376,
6385,
370,
626,
7710,
1720,
315,
2195,
2754,
367,
655,
18975,
724,
434,
31,
199,
278,
26,
259,
29715,
14,
199,
58,
35,
26,
259,
2779,
365,
8034,
370,
506,
2451,
2419,
370,
506,
9842,
14,
199,
278,
26,
259,
473,
12005,
16865,
436,
336,
374,
4556,
14,
199,
58,
35,
26,
259,
710,
2754,
367,
16865,
365,
282,
1846,
5225,
349,
14655,
14,
199,
278,
26,
259,
23889,
1265,
3238,
31,
199,
58,
35,
26,
259,
23038,
3238,
12,
11703,
440,
3238,
14,
421,
199,
1918,
21472,
3018,
5523,
365,
4079,
641,
626,
402,
21472,
14,
18865,
8076,
14,
20227,
12,
652,
4440,
199,
65,
7761,
1817,
370,
3957,
687,
7894,
370,
1177,
199,
73,
14,
69,
14,
298,
41,
8140,
2,
10541,
298,
13297,
787,
2,
199,
199,
3466,
2518,
12,
3967,
3107,
287,
2799,
292,
3018,
1630,
440,
20647,
314,
11150,
402,
1263,
5932,
12,
199,
10360,
787,
7437,
13988,
14,
3107,
287,
2799,
292,
3018,
911,
9987,
6385,
7437,
373,
30904,
590,
12,
503,
199,
22720,
370,
282,
7894,
701,
7198,
316,
282,
3365,
7894,
12,
315,
8298,
314,
2011,
4340,
199,
305,
662,
317,
8076,
14,
199,
624,
199,
199,
504,
655,
14,
2087,
14,
7530,
2663,
63,
5333,
14,
10289,
492,
627,
199,
199,
3,
9320,
787,
7838,
2746,
370,
9048,
12,
880,
2222,
13,
6100,
4450,
4781,
2945,
199,
3,
367,
1924,
1336,
12,
282,
769,
402,
3962,
9320,
365,
2741,
199,
10360,
275,
334,
199,
199,
3,
3107,
287,
2799,
292,
3018,
30848,
543,
314,
1004,
298,
24679,
12,
3002,
1982,
2122,
710,
20195,
199,
3,
1177,
911,
506,
282,
486,
23457,
5160,
26,
283,
8302,
7,
4450,
298,
8302,
21333,
1835,
401,
199,
3,
298,
8302,
5382,
2,
5423,
12,
1325,
2597,
298,
8302,
27591,
2829,
9539,
221,
436,
1163,
24256,
6617,
199,
3,
543,
314,
4349,
283,
8302,
7,
626,
1443,
440,
506,
282,
486,
23457,
339,
334,
82,
6774,
5006,
19276,
430,
92,
8,
8302,
359,
65,
13,
6353,
13,
58,
28798,
272,
334,
298,
1918,
931,
370,
655,
18975,
724,
434,
365,
14115,
29870,
370,
1937,
4765,
489,
298,
39,
7936,
780,
14,
473,
12249,
2195,
25169,
365,
22621,
456,
1146,
14,
30528,
562,
402,
2195,
29616,
83,
4765,
489,
298,
25525,
314,
7894,
1265,
1172,
11492,
370,
7198,
4765,
489,
298,
6257,
14,
4226,
1265,
12005,
20171,
18975,
724,
434,
31,
8150,
2043,
199,
199,
3,
298,
41,
1929,
2,
436,
298,
41,
2934,
2,
883,
506,
9437,
701,
282,
8377,
334,
5902,
283,
3437,
358,
199,
3,
503,
376,
1595,
334,
5902,
283,
475,
1937,
1265,
358,
199,
3,
199,
3,
961,
365,
282,
5160,
543,
642,
3449,
402,
1177,
446,
257,
199,
3,
4954,
26,
259,
298,
41,
1929,
1265,
2,
199,
3,
21472,
3018,
26,
259,
298,
278,
883,
506,
22175,
1354,
701,
7508,
1736,
436,
477,
21171,
402,
314,
25169,
2,
199,
3,
284,
14,
69,
14,
283,
13297,
7,
365,
440,
7710,
282,
8377,
626,
883,
506,
9994,
642,
4340,
12,
880,
642,
199,
3,
28426,
1454,
7704,
12249,
367,
2005,
4153,
199,
3,
272,
334,
82,
7,
73,
1929,
334,
2795,
3196,
272,
334,
2071,
17,
883,
506,
22175,
1354,
701,
7508,
1736,
436,
477,
21171,
402,
314,
25169,
4765,
489,
2071,
17,
365,
440,
282,
1929,
12,
1325,
282,
477,
338,
264,
402,
314,
25169,
14,
14836,
2195,
25169,
402,
4066,
406,
2247,
561,
4765,
489,
298,
17310,
2195,
25169,
641,
5,
17,
12,
436,
1265,
911,
2342,
4052,
1265,
1929,
2685,
395,
339,
334,
82,
7,
73,
2934,
334,
2795,
3196,
272,
334,
298,
872,
338,
470,
402,
314,
946,
580,
911,
2917,
1957,
1265,
687,
314,
931,
370,
655,
18975,
724,
434,
4765,
489,
298,
20326,
5,
17,
1720,
1265,
737,
877,
655,
18975,
724,
434,
15583,
489,
298,
1831,
5,
17,
282,
477,
338,
264,
402,
314,
25169,
12,
503,
402,
314,
946,
580,
31,
8150,
2043,
199,
199,
3,
10842,
23071,
787,
11673,
1901,
7795,
2943,
26,
199,
3,
298,
26460,
703,
41,
2,
258,
325,
14,
71,
14,
298,
26460,
8140,
473,
2348,
13472,
298,
55,
3577,
886,
473,
2839,
1704,
415,
13472,
199,
3,
298,
26460,
703,
13297,
2,
259,
325,
14,
71,
14,
298,
26460,
787,
1265,
2348,
13472,
298,
55,
3577,
7859,
1133,
1265,
11480,
562,
13472,
199,
3,
298,
26460,
11500,
259,
325,
14,
71,
14,
298,
55,
3577,
365,
314,
2386,
89,
10030,
13472,
199,
3,
8826,
26,
199,
3,
258,
4954,
26,
221,
298,
55,
3577,
883,
1133,
1265,
11480,
562,
13472,
199,
3,
258,
21472,
3018,
26,
298,
17683,
1265,
3238,
473,
11480,
1265,
13472,
199,
3,
446,
642,
3449,
5419,
367,
27609,
334,
69,
14,
71,
14,
298,
26460,
886,
1265,
2839,
1704,
415,
18582,
199,
3,
257,
1325,
1630,
440,
1736,
367,
14158,
10661,
334,
69,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
was4444/chromium.src
|
tools/auto_bisect/bisect_results.py
|
15
|
10479
|
# 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 math
import os
import bisect_utils
import math_utils
import source_control
import ttest
from bisect_state import RevisionState
class BisectResults(object):
"""Contains results of the completed bisect.
Properties:
error: Error message if the bisect failed.
If the error is None, the following properties are present:
warnings: List of warnings from the bisect run.
state: BisectState object from which these results were generated.
first_working_revision: First good revision.
last_broken_revision: Last bad revision.
If both of above revisions are not None, the follow properties are present:
culprit_revisions: A list of revisions, which contain the bad change
introducing the failure.
regression_size: For performance bisects, this is a relative change of
the mean metric value. For other bisects this field always contains
'zero-to-nonzero'.
regression_std_err: For performance bisects, it is a pooled standard error
for groups of good and bad runs. Not used for other bisects.
confidence: For performance bisects, it is a confidence that the good and
bad runs are distinct groups. Not used for non-performance bisects.
"""
def __init__(self, bisect_state=None, depot_registry=None, opts=None,
runtime_warnings=None, error=None, abort_reason=None):
"""Computes final bisect results after a bisect run is complete.
This constructor should be called in one of the following ways:
BisectResults(state, depot_registry, opts, runtime_warnings)
BisectResults(error=error)
First option creates an object representing successful bisect results, while
second option creates an error result.
Args:
bisect_state: BisectState object representing latest bisect state.
depot_registry: DepotDirectoryRegistry object with information on each
repository in the bisect_state.
opts: Options passed to the bisect run.
runtime_warnings: A list of warnings from the bisect run.
error: Error message. When error is not None, other arguments are ignored.
"""
# Setting these attributes so that bisect printer does not break when the
# regression cannot be reproduced (no broken revision was found)
self.regression_size = 0
self.regression_std_err = 0
self.confidence = 0
self.culprit_revisions = []
self.error = error
self.abort_reason = abort_reason
if error is not None or abort_reason is not None:
return
assert (bisect_state is not None and depot_registry is not None and
opts is not None and runtime_warnings is not None), (
'Incorrect use of the BisectResults constructor. '
'When error is None, all other arguments are required.')
self.state = bisect_state
rev_states = bisect_state.GetRevisionStates()
first_working_rev, last_broken_rev = self.FindBreakingRevRange(rev_states)
self.first_working_revision = first_working_rev
self.last_broken_revision = last_broken_rev
self.warnings = runtime_warnings
self.retest_results_tot = None
self.retest_results_reverted = None
if first_working_rev is not None and last_broken_rev is not None:
statistics = self._ComputeRegressionStatistics(
rev_states, first_working_rev, last_broken_rev)
self.regression_size = statistics['regression_size']
self.regression_std_err = statistics['regression_std_err']
self.confidence = statistics['confidence']
self.culprit_revisions = self._FindCulpritRevisions(
rev_states, depot_registry, first_working_rev, last_broken_rev)
self.warnings += self._GetResultBasedWarnings(
self.culprit_revisions, opts, self.confidence)
def AddRetestResults(self, results_tot, results_reverted):
if not results_tot or not results_reverted:
self.warnings.append(
'Failed to re-test reverted culprit CL against ToT.')
return
confidence = BisectResults.ConfidenceScore(
results_reverted[0]['values'],
results_tot[0]['values'])
self.retest_results_tot = RevisionState('ToT', 'n/a', 0)
self.retest_results_tot.value = results_tot[0]
self.retest_results_reverted = RevisionState('Reverted', 'n/a', 0)
self.retest_results_reverted.value = results_reverted[0]
if confidence <= bisect_utils.HIGH_CONFIDENCE:
self.warnings.append(
'Confidence of re-test with reverted CL is not high.'
' Check that the regression hasn\'t already recovered. '
' There\'s still a chance this is a regression, as performance of'
' local builds may not match official builds.')
@staticmethod
def _GetResultBasedWarnings(culprit_revisions, opts, confidence):
warnings = []
if len(culprit_revisions) > 1:
warnings.append('Due to build errors, regression range could '
'not be narrowed down to a single commit.')
if opts.repeat_test_count == 1:
warnings.append('Tests were only set to run once. This may '
'be insufficient to get meaningful results.')
if 0 < confidence < bisect_utils.HIGH_CONFIDENCE:
warnings.append('Confidence is not high. Try bisecting again '
'with increased repeat_count, larger range, or '
'on another metric.')
if not confidence:
warnings.append('Confidence score is 0%. Try bisecting again on '
'another platform or another metric.')
return warnings
@staticmethod
def ConfidenceScore(sample1, sample2, accept_single_bad_or_good=False):
"""Calculates a confidence score.
This score is based on a statistical hypothesis test. The null
hypothesis is that the two groups of results have no difference,
i.e. there is no performance regression. The alternative hypothesis
is that there is some difference between the groups that's unlikely
to occur by chance.
The score returned by this function represents our confidence in the
alternative hypothesis.
Note that if there's only one item in either sample, this means only
one revision was classified good or bad, so there's not much evidence
to make a decision.
Args:
sample1: A flat list of "good" result numbers.
sample2: A flat list of "bad" result numbers.
accept_single_bad_or_good: If True, compute a value even if
there is only one bad or good revision.
Returns:
A float between 0 and 100; 0 if the samples aren't large enough.
"""
if ((len(sample1) <= 1 or len(sample2) <= 1) and
not accept_single_bad_or_good):
return 0.0
if not sample1 or not sample2:
return 0.0
_, _, p_value = ttest.WelchsTTest(sample1, sample2)
return 100.0 * (1.0 - p_value)
@staticmethod
def FindBreakingRevRange(revision_states):
"""Finds the last known good and first known bad revisions.
Note that since revision_states is expected to be in reverse chronological
order, the last known good revision is the first revision in the list that
has the passed property set to 1, therefore the name
`first_working_revision`. The inverse applies to `last_broken_revision`.
Args:
revision_states: A list of RevisionState instances.
Returns:
A tuple containing the two revision states at the border. (Last
known good and first known bad.)
"""
first_working_revision = None
last_broken_revision = None
for revision_state in revision_states:
if revision_state.passed == 1 and not first_working_revision:
first_working_revision = revision_state
if not revision_state.passed:
last_broken_revision = revision_state
return first_working_revision, last_broken_revision
@staticmethod
def _FindCulpritRevisions(revision_states, depot_registry, first_working_rev,
last_broken_rev):
cwd = os.getcwd()
culprit_revisions = []
for i in xrange(last_broken_rev.index, first_working_rev.index):
depot_registry.ChangeToDepotDir(revision_states[i].depot)
info = source_control.QueryRevisionInfo(revision_states[i].revision)
culprit_revisions.append((revision_states[i].revision, info,
revision_states[i].depot))
os.chdir(cwd)
return culprit_revisions
@classmethod
def _ComputeRegressionStatistics(cls, rev_states, first_working_rev,
last_broken_rev):
# TODO(sergiyb): We assume that value has "values" key, which may not be
# the case for failure-bisects, where there is a single value only.
broken_means = [state.value['values']
for state in rev_states[:last_broken_rev.index+1]
if state.value]
working_means = [state.value['values']
for state in rev_states[first_working_rev.index:]
if state.value]
# Flatten the lists to calculate mean of all values.
working_mean = sum(working_means, [])
broken_mean = sum(broken_means, [])
# Calculate the approximate size of the regression
mean_of_bad_runs = math_utils.Mean(broken_mean)
mean_of_good_runs = math_utils.Mean(working_mean)
regression_size = 100 * math_utils.RelativeChange(mean_of_good_runs,
mean_of_bad_runs)
if math.isnan(regression_size):
regression_size = 'zero-to-nonzero'
regression_std_err = math.fabs(math_utils.PooledStandardError(
[working_mean, broken_mean]) /
max(0.0001, min(mean_of_good_runs, mean_of_bad_runs))) * 100.0
# Give a "confidence" in the bisect culprit by seeing whether the results
# of the culprit revision and the revision before that appear to be
# statistically significantly different.
confidence = cls.ConfidenceScore(
sum([first_working_rev.value['values']], []),
sum([last_broken_rev.value['values']], []))
bad_greater_than_good = mean_of_bad_runs > mean_of_good_runs
return {'regression_size': regression_size,
'regression_std_err': regression_std_err,
'confidence': confidence,
'bad_greater_than_good': bad_greater_than_good}
|
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,
3473,
199,
646,
747,
199,
199,
646,
19063,
63,
1208,
199,
646,
3473,
63,
1208,
199,
646,
1350,
63,
2785,
199,
646,
307,
396,
199,
199,
504,
19063,
63,
929,
492,
27095,
2223,
421,
199,
533,
699,
13133,
6579,
8,
785,
304,
523,
408,
6906,
2058,
402,
314,
9709,
19063,
14,
819,
19329,
26,
272,
1125,
26,
4520,
1245,
340,
314,
19063,
3405,
14,
819,
982,
314,
1125,
365,
488,
12,
314,
2569,
4382,
787,
3451,
26,
272,
3598,
26,
3820,
402,
3598,
687,
314,
19063,
1255,
14,
272,
1174,
26,
699,
13133,
2223,
909,
687,
1314,
3520,
2058,
4898,
4046,
14,
272,
1642,
63,
9818,
63,
5792,
26,
7758,
6954,
6974,
14,
272,
2061,
63,
15697,
63,
5792,
26,
15237,
4875,
6974,
14,
819,
982,
3865,
402,
3432,
22164,
787,
440,
488,
12,
314,
2035,
4382,
787,
3451,
26,
272,
286,
348,
1359,
84,
63,
23449,
26,
437,
769,
402,
22164,
12,
1314,
1395,
314,
4875,
1570,
267,
13318,
14713,
314,
5988,
14,
272,
10864,
63,
890,
26,
2104,
10238,
330,
572,
3021,
12,
642,
365,
282,
3847,
1570,
402,
267,
314,
4615,
6370,
574,
14,
2104,
1163,
330,
572,
3021,
642,
901,
3544,
3509,
267,
283,
4262,
13,
475,
13,
10262,
1370,
272,
10864,
63,
1516,
63,
1508,
26,
2104,
10238,
330,
572,
3021,
12,
652,
365,
282,
1115,
26509,
4465,
1125,
267,
367,
4652,
402,
6954,
436,
4875,
7858,
14,
2832,
1202,
367,
1163,
330,
572,
3021,
14,
272,
15197,
26,
2104,
10238,
330,
572,
3021,
12,
652,
365,
282,
15197,
626,
314,
6954,
436,
267,
4875,
7858,
787,
15392,
4652,
14,
2832,
1202,
367,
2222,
13,
20576,
330,
572,
3021,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
19063,
63,
929,
29,
403,
12,
32544,
63,
5189,
29,
403,
12,
3999,
29,
403,
12,
2049,
8836,
63,
5451,
29,
403,
12,
1125,
29,
403,
12,
12004,
63,
5764,
29,
403,
304,
272,
408,
22594,
4242,
19063,
2058,
2410,
282,
19063,
1255,
365,
4890,
14,
339,
961,
3787,
1077,
506,
2797,
315,
1373,
402,
314,
2569,
15217,
26,
489,
699,
13133,
6579,
8,
929,
12,
32544,
63,
5189,
12,
3999,
12,
8836,
63,
5451,
9,
489,
699,
13133,
6579,
8,
705,
29,
705,
9,
339,
7758,
945,
8491,
376,
909,
6144,
9512,
19063,
2058,
12,
1830,
272,
3499,
945,
8491,
376,
1125,
754,
14,
339,
3033,
26,
489,
19063,
63,
929,
26,
699,
13133,
2223,
909,
6144,
8839,
19063,
1174,
14,
489,
32544,
63,
5189,
26,
1487,
14173,
6231,
10899,
909,
543,
2556,
641,
1924,
881,
7611,
315,
314,
19063,
63,
929,
14,
489,
3999,
26,
8394,
3032,
370,
314,
19063,
1255,
14,
489,
8836,
63,
5451,
26,
437,
769,
402,
3598,
687,
314,
19063,
1255,
14,
489,
1125,
26,
4520,
1245,
14,
3979,
1125,
365,
440,
488,
12,
1163,
2368,
787,
5525,
14,
272,
408,
272,
327,
13510,
3520,
3004,
880,
626,
19063,
16639,
1630,
440,
2059,
1380,
314,
272,
327,
10864,
3913,
506,
9172,
68,
334,
889,
10529,
6974,
1990,
1911,
9,
272,
291,
14,
12513,
63,
890,
275,
378,
272,
291,
14,
12513,
63,
1516,
63,
1508,
275,
378,
272,
291,
14,
13969,
275,
378,
272,
291,
14,
3119,
1359,
84,
63,
23449,
275,
942,
339,
291,
14,
705,
275,
1125,
272,
291,
14,
13845,
63,
5764,
275,
12004,
63,
5764,
272,
340,
1125,
365,
440,
488,
503,
12004,
63,
5764,
365,
440,
488,
26,
489,
372,
339,
702,
334,
23247,
63,
929,
365,
440,
488,
436,
32544,
63,
5189,
365,
440,
488,
436,
288,
3999,
365,
440,
488,
436,
8836,
63,
5451,
365,
440,
488,
395,
334,
355,
283,
18298,
675,
402,
314,
699,
13133,
6579,
3787,
14,
283,
355,
283,
11423,
1125,
365,
488,
12,
1006,
1163,
2368,
787,
1415,
2659,
339,
291,
14,
929,
275,
19063,
63,
929,
339,
6822,
63,
4981,
275,
19063,
63,
929,
14,
1002,
12714,
18010,
342,
272,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
275,
291,
14,
6591,
13948,
316,
26176,
4709,
8,
4964,
63,
4981,
9,
272,
291,
14,
2246,
63,
9818,
63,
5792,
275,
1642,
63,
9818,
63,
4964,
272,
291,
14,
2019,
63,
15697,
63,
5792,
275,
2061,
63,
15697,
63,
4964,
339,
291,
14,
5451,
275,
8836,
63,
5451,
339,
291,
14,
264,
396,
63,
2604,
63,
13280,
275,
488,
272,
291,
14,
264,
396,
63,
2604,
63,
264,
16542,
275,
488,
339,
340,
1642,
63,
9818,
63,
4964,
365,
440,
488,
436,
2061,
63,
15697,
63,
4964,
365,
440,
488,
26,
489,
11076,
275,
291,
423,
8564,
13013,
20750,
8,
881,
6822,
63,
4981,
12,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
9,
2541,
291,
14,
12513,
63,
890,
275,
11076,
459,
12513,
63,
890,
418,
489,
291,
14,
12513,
63,
1516,
63,
1508,
275,
11076,
459,
12513,
63,
1516,
63,
1508,
418,
489,
291,
14,
13969,
275,
11076,
459,
13969,
418,
2541,
291,
14,
3119,
1359,
84,
63,
23449,
275,
291,
423,
6591,
35,
348,
1359,
84,
497,
13193,
8,
881,
6822,
63,
4981,
12,
32544,
63,
5189,
12,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
9,
2541,
291,
14,
5451,
847,
291,
423,
1002,
2889,
20409,
15921,
8,
881,
291,
14,
3119,
1359,
84,
63,
23449,
12,
3999,
12,
291,
14,
13969,
9,
819,
347,
2654,
497,
396,
6579,
8,
277,
12,
2058,
63,
13280,
12,
2058,
63,
264,
16542,
304,
272,
340,
440,
2058,
63,
13280,
503,
440,
2058,
63,
264,
16542,
26,
489,
291,
14,
5451,
14,
740,
8,
881,
283,
4276,
370,
295,
13,
396,
295,
16542,
286,
348,
1359,
84,
13354,
6169,
4005,
52,
2659,
489,
372,
339,
15197,
275,
699,
13133,
6579,
14,
714,
8866,
12642,
8,
267,
2058,
63,
264,
16542,
59,
16,
2733,
1459,
995,
267,
2058,
63,
13280,
59,
16,
2733,
1459,
1105,
339,
291,
14,
264,
396,
63,
2604,
63,
13280,
275,
27095,
2223,
360,
1378,
52,
297,
283,
78
] |
[
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,
3473,
199,
646,
747,
199,
199,
646,
19063,
63,
1208,
199,
646,
3473,
63,
1208,
199,
646,
1350,
63,
2785,
199,
646,
307,
396,
199,
199,
504,
19063,
63,
929,
492,
27095,
2223,
421,
199,
533,
699,
13133,
6579,
8,
785,
304,
523,
408,
6906,
2058,
402,
314,
9709,
19063,
14,
819,
19329,
26,
272,
1125,
26,
4520,
1245,
340,
314,
19063,
3405,
14,
819,
982,
314,
1125,
365,
488,
12,
314,
2569,
4382,
787,
3451,
26,
272,
3598,
26,
3820,
402,
3598,
687,
314,
19063,
1255,
14,
272,
1174,
26,
699,
13133,
2223,
909,
687,
1314,
3520,
2058,
4898,
4046,
14,
272,
1642,
63,
9818,
63,
5792,
26,
7758,
6954,
6974,
14,
272,
2061,
63,
15697,
63,
5792,
26,
15237,
4875,
6974,
14,
819,
982,
3865,
402,
3432,
22164,
787,
440,
488,
12,
314,
2035,
4382,
787,
3451,
26,
272,
286,
348,
1359,
84,
63,
23449,
26,
437,
769,
402,
22164,
12,
1314,
1395,
314,
4875,
1570,
267,
13318,
14713,
314,
5988,
14,
272,
10864,
63,
890,
26,
2104,
10238,
330,
572,
3021,
12,
642,
365,
282,
3847,
1570,
402,
267,
314,
4615,
6370,
574,
14,
2104,
1163,
330,
572,
3021,
642,
901,
3544,
3509,
267,
283,
4262,
13,
475,
13,
10262,
1370,
272,
10864,
63,
1516,
63,
1508,
26,
2104,
10238,
330,
572,
3021,
12,
652,
365,
282,
1115,
26509,
4465,
1125,
267,
367,
4652,
402,
6954,
436,
4875,
7858,
14,
2832,
1202,
367,
1163,
330,
572,
3021,
14,
272,
15197,
26,
2104,
10238,
330,
572,
3021,
12,
652,
365,
282,
15197,
626,
314,
6954,
436,
267,
4875,
7858,
787,
15392,
4652,
14,
2832,
1202,
367,
2222,
13,
20576,
330,
572,
3021,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
19063,
63,
929,
29,
403,
12,
32544,
63,
5189,
29,
403,
12,
3999,
29,
403,
12,
2049,
8836,
63,
5451,
29,
403,
12,
1125,
29,
403,
12,
12004,
63,
5764,
29,
403,
304,
272,
408,
22594,
4242,
19063,
2058,
2410,
282,
19063,
1255,
365,
4890,
14,
339,
961,
3787,
1077,
506,
2797,
315,
1373,
402,
314,
2569,
15217,
26,
489,
699,
13133,
6579,
8,
929,
12,
32544,
63,
5189,
12,
3999,
12,
8836,
63,
5451,
9,
489,
699,
13133,
6579,
8,
705,
29,
705,
9,
339,
7758,
945,
8491,
376,
909,
6144,
9512,
19063,
2058,
12,
1830,
272,
3499,
945,
8491,
376,
1125,
754,
14,
339,
3033,
26,
489,
19063,
63,
929,
26,
699,
13133,
2223,
909,
6144,
8839,
19063,
1174,
14,
489,
32544,
63,
5189,
26,
1487,
14173,
6231,
10899,
909,
543,
2556,
641,
1924,
881,
7611,
315,
314,
19063,
63,
929,
14,
489,
3999,
26,
8394,
3032,
370,
314,
19063,
1255,
14,
489,
8836,
63,
5451,
26,
437,
769,
402,
3598,
687,
314,
19063,
1255,
14,
489,
1125,
26,
4520,
1245,
14,
3979,
1125,
365,
440,
488,
12,
1163,
2368,
787,
5525,
14,
272,
408,
272,
327,
13510,
3520,
3004,
880,
626,
19063,
16639,
1630,
440,
2059,
1380,
314,
272,
327,
10864,
3913,
506,
9172,
68,
334,
889,
10529,
6974,
1990,
1911,
9,
272,
291,
14,
12513,
63,
890,
275,
378,
272,
291,
14,
12513,
63,
1516,
63,
1508,
275,
378,
272,
291,
14,
13969,
275,
378,
272,
291,
14,
3119,
1359,
84,
63,
23449,
275,
942,
339,
291,
14,
705,
275,
1125,
272,
291,
14,
13845,
63,
5764,
275,
12004,
63,
5764,
272,
340,
1125,
365,
440,
488,
503,
12004,
63,
5764,
365,
440,
488,
26,
489,
372,
339,
702,
334,
23247,
63,
929,
365,
440,
488,
436,
32544,
63,
5189,
365,
440,
488,
436,
288,
3999,
365,
440,
488,
436,
8836,
63,
5451,
365,
440,
488,
395,
334,
355,
283,
18298,
675,
402,
314,
699,
13133,
6579,
3787,
14,
283,
355,
283,
11423,
1125,
365,
488,
12,
1006,
1163,
2368,
787,
1415,
2659,
339,
291,
14,
929,
275,
19063,
63,
929,
339,
6822,
63,
4981,
275,
19063,
63,
929,
14,
1002,
12714,
18010,
342,
272,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
275,
291,
14,
6591,
13948,
316,
26176,
4709,
8,
4964,
63,
4981,
9,
272,
291,
14,
2246,
63,
9818,
63,
5792,
275,
1642,
63,
9818,
63,
4964,
272,
291,
14,
2019,
63,
15697,
63,
5792,
275,
2061,
63,
15697,
63,
4964,
339,
291,
14,
5451,
275,
8836,
63,
5451,
339,
291,
14,
264,
396,
63,
2604,
63,
13280,
275,
488,
272,
291,
14,
264,
396,
63,
2604,
63,
264,
16542,
275,
488,
339,
340,
1642,
63,
9818,
63,
4964,
365,
440,
488,
436,
2061,
63,
15697,
63,
4964,
365,
440,
488,
26,
489,
11076,
275,
291,
423,
8564,
13013,
20750,
8,
881,
6822,
63,
4981,
12,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
9,
2541,
291,
14,
12513,
63,
890,
275,
11076,
459,
12513,
63,
890,
418,
489,
291,
14,
12513,
63,
1516,
63,
1508,
275,
11076,
459,
12513,
63,
1516,
63,
1508,
418,
489,
291,
14,
13969,
275,
11076,
459,
13969,
418,
2541,
291,
14,
3119,
1359,
84,
63,
23449,
275,
291,
423,
6591,
35,
348,
1359,
84,
497,
13193,
8,
881,
6822,
63,
4981,
12,
32544,
63,
5189,
12,
1642,
63,
9818,
63,
4964,
12,
2061,
63,
15697,
63,
4964,
9,
2541,
291,
14,
5451,
847,
291,
423,
1002,
2889,
20409,
15921,
8,
881,
291,
14,
3119,
1359,
84,
63,
23449,
12,
3999,
12,
291,
14,
13969,
9,
819,
347,
2654,
497,
396,
6579,
8,
277,
12,
2058,
63,
13280,
12,
2058,
63,
264,
16542,
304,
272,
340,
440,
2058,
63,
13280,
503,
440,
2058,
63,
264,
16542,
26,
489,
291,
14,
5451,
14,
740,
8,
881,
283,
4276,
370,
295,
13,
396,
295,
16542,
286,
348,
1359,
84,
13354,
6169,
4005,
52,
2659,
489,
372,
339,
15197,
275,
699,
13133,
6579,
14,
714,
8866,
12642,
8,
267,
2058,
63,
264,
16542,
59,
16,
2733,
1459,
995,
267,
2058,
63,
13280,
59,
16,
2733,
1459,
1105,
339,
291,
14,
264,
396,
63,
2604,
63,
13280,
275,
27095,
2223,
360,
1378,
52,
297,
283,
78,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hcsturix74/django
|
tests/or_lookups/tests.py
|
275
|
7624
|
from __future__ import unicode_literals
from datetime import datetime
from operator import attrgetter
from django.db.models import Q
from django.test import TestCase
from .models import Article
class OrLookupsTests(TestCase):
def setUp(self):
self.a1 = Article.objects.create(
headline='Hello', pub_date=datetime(2005, 11, 27)
).pk
self.a2 = Article.objects.create(
headline='Goodbye', pub_date=datetime(2005, 11, 28)
).pk
self.a3 = Article.objects.create(
headline='Hello and goodbye', pub_date=datetime(2005, 11, 29)
).pk
def test_filter_or(self):
self.assertQuerysetEqual(
Article.objects.filter(headline__startswith='Hello') | Article.objects.filter(headline__startswith='Goodbye'), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.filter(headline__contains='Hello') | Article.objects.filter(headline__contains='bye'), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.filter(headline__iexact='Hello') | Article.objects.filter(headline__contains='ood'), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.filter(Q(headline__startswith='Hello') | Q(headline__startswith='Goodbye')), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline")
)
def test_stages(self):
# You can shorten this syntax with code like the following, which is
# especially useful if building the query in stages:
articles = Article.objects.all()
self.assertQuerysetEqual(
articles.filter(headline__startswith='Hello') & articles.filter(headline__startswith='Goodbye'),
[]
)
self.assertQuerysetEqual(
articles.filter(headline__startswith='Hello') & articles.filter(headline__contains='bye'), [
'Hello and goodbye'
],
attrgetter("headline")
)
def test_pk_q(self):
self.assertQuerysetEqual(
Article.objects.filter(Q(pk=self.a1) | Q(pk=self.a2)), [
'Hello',
'Goodbye'
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.filter(Q(pk=self.a1) | Q(pk=self.a2) | Q(pk=self.a3)), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline"),
)
def test_pk_in(self):
self.assertQuerysetEqual(
Article.objects.filter(pk__in=[self.a1, self.a2, self.a3]), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline"),
)
self.assertQuerysetEqual(
Article.objects.filter(pk__in=(self.a1, self.a2, self.a3)), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline"),
)
self.assertQuerysetEqual(
Article.objects.filter(pk__in=[self.a1, self.a2, self.a3, 40000]), [
'Hello',
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline"),
)
def test_q_negated(self):
# Q objects can be negated
self.assertQuerysetEqual(
Article.objects.filter(Q(pk=self.a1) | ~Q(pk=self.a2)), [
'Hello',
'Hello and goodbye'
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.filter(~Q(pk=self.a1) & ~Q(pk=self.a2)), [
'Hello and goodbye'
],
attrgetter("headline"),
)
# This allows for more complex queries than filter() and exclude()
# alone would allow
self.assertQuerysetEqual(
Article.objects.filter(Q(pk=self.a1) & (~Q(pk=self.a2) | Q(pk=self.a3))), [
'Hello'
],
attrgetter("headline"),
)
def test_complex_filter(self):
# The 'complex_filter' method supports framework features such as
# 'limit_choices_to' which normally take a single dictionary of lookup
# arguments but need to support arbitrary queries via Q objects too.
self.assertQuerysetEqual(
Article.objects.complex_filter({'pk': self.a1}), [
'Hello'
],
attrgetter("headline"),
)
self.assertQuerysetEqual(
Article.objects.complex_filter(Q(pk=self.a1) | Q(pk=self.a2)), [
'Hello',
'Goodbye'
],
attrgetter("headline"),
)
def test_empty_in(self):
# Passing "in" an empty list returns no results ...
self.assertQuerysetEqual(
Article.objects.filter(pk__in=[]),
[]
)
# ... but can return results if we OR it with another query.
self.assertQuerysetEqual(
Article.objects.filter(Q(pk__in=[]) | Q(headline__icontains='goodbye')), [
'Goodbye',
'Hello and goodbye'
],
attrgetter("headline"),
)
def test_q_and(self):
# Q arg objects are ANDed
self.assertQuerysetEqual(
Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')), [
'Hello and goodbye'
],
attrgetter("headline")
)
# Q arg AND order is irrelevant
self.assertQuerysetEqual(
Article.objects.filter(Q(headline__contains='bye'), headline__startswith='Hello'), [
'Hello and goodbye'
],
attrgetter("headline"),
)
self.assertQuerysetEqual(
Article.objects.filter(Q(headline__startswith='Hello') & Q(headline__startswith='Goodbye')),
[]
)
def test_q_exclude(self):
self.assertQuerysetEqual(
Article.objects.exclude(Q(headline__startswith='Hello')), [
'Goodbye'
],
attrgetter("headline")
)
def test_other_arg_queries(self):
# Try some arg queries with operations other than filter.
self.assertEqual(
Article.objects.get(Q(headline__startswith='Hello'), Q(headline__contains='bye')).headline,
'Hello and goodbye'
)
self.assertEqual(
Article.objects.filter(Q(headline__startswith='Hello') | Q(headline__contains='bye')).count(),
3
)
self.assertQuerysetEqual(
Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')).values(), [
{"headline": "Hello and goodbye", "id": self.a3, "pub_date": datetime(2005, 11, 29)},
],
lambda o: o,
)
self.assertEqual(
Article.objects.filter(Q(headline__startswith='Hello')).in_bulk([self.a1, self.a2]),
{self.a1: Article.objects.get(pk=self.a1)}
)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2197,
492,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
421,
199,
533,
4236,
7521,
83,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
6257,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
8087,
9,
267,
7092,
2051,
267,
291,
14,
65,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
20652,
16481,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7294,
9,
267,
7092,
2051,
267,
291,
14,
65,
19,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
6257,
436,
6954,
16481,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7349,
9,
267,
7092,
2051,
339,
347,
511,
63,
1541,
63,
269,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
2460,
534,
20652,
16481,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
16481,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
32344,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
23521,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
11268,
363,
2460,
534,
6257,
358,
1204,
1413,
8,
11268,
363,
2460,
534,
20652,
16481,
3855,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
339,
347,
511,
63,
30646,
8,
277,
304,
267,
327,
2047,
883,
25123,
642,
6302,
543,
1233,
2839,
314,
2569,
12,
221,
1314,
365,
267,
327,
24002,
2997,
340,
10015,
314,
1827,
315,
24490,
26,
267,
23242,
275,
8281,
14,
1462,
14,
452,
342,
267,
291,
14,
7108,
8,
288,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1253,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
20652,
16481,
659,
288,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1253,
23242,
14,
1541,
8,
11268,
363,
6134,
534,
16481,
659,
359,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
339,
347,
511,
63,
2051,
63,
81,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
18,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
19,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
339,
347,
511,
63,
2051,
63,
262,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
1524,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
2522,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
2687,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
1524,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
12,
841,
993,
2522,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
339,
347,
511,
63,
81,
63,
8705,
972,
8,
277,
304,
267,
327,
1413,
2251,
883,
506,
14158,
972,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
6146,
49,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
26428,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1253,
6146,
49,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
267,
327,
961,
6127,
367,
1655,
6114,
9212,
2419,
2457,
342,
436,
5760,
342,
267,
327,
23016,
3955,
2040,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1253,
31742,
49,
8,
2051,
29,
277,
14,
65,
18,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
19,
11508,
359,
355,
283,
6257,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
2197,
492,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
421,
199,
533,
4236,
7521,
83,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
6257,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
8087,
9,
267,
7092,
2051,
267,
291,
14,
65,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
20652,
16481,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7294,
9,
267,
7092,
2051,
267,
291,
14,
65,
19,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
534,
6257,
436,
6954,
16481,
297,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7349,
9,
267,
7092,
2051,
339,
347,
511,
63,
1541,
63,
269,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
2460,
534,
20652,
16481,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
16481,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
32344,
534,
6257,
358,
1204,
8281,
14,
1462,
14,
1541,
8,
11268,
363,
6134,
534,
23521,
659,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
11268,
363,
2460,
534,
6257,
358,
1204,
1413,
8,
11268,
363,
2460,
534,
20652,
16481,
3855,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
339,
347,
511,
63,
30646,
8,
277,
304,
267,
327,
2047,
883,
25123,
642,
6302,
543,
1233,
2839,
314,
2569,
12,
221,
1314,
365,
267,
327,
24002,
2997,
340,
10015,
314,
1827,
315,
24490,
26,
267,
23242,
275,
8281,
14,
1462,
14,
452,
342,
267,
291,
14,
7108,
8,
288,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1253,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
20652,
16481,
659,
288,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
23242,
14,
1541,
8,
11268,
363,
2460,
534,
6257,
358,
1253,
23242,
14,
1541,
8,
11268,
363,
6134,
534,
16481,
659,
359,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
339,
347,
511,
63,
2051,
63,
81,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
18,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
19,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
339,
347,
511,
63,
2051,
63,
262,
8,
277,
304,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
1524,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
2522,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
2687,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
1826,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
2051,
363,
262,
1524,
277,
14,
65,
17,
12,
291,
14,
65,
18,
12,
291,
14,
65,
19,
12,
841,
993,
2522,
359,
355,
283,
6257,
297,
355,
283,
20652,
16481,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
339,
347,
511,
63,
81,
63,
8705,
972,
8,
277,
304,
267,
327,
1413,
2251,
883,
506,
14158,
972,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1204,
6146,
49,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
297,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
26428,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1253,
6146,
49,
8,
2051,
29,
277,
14,
65,
18,
1826,
359,
355,
283,
6257,
436,
6954,
16481,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
267,
327,
961,
6127,
367,
1655,
6114,
9212,
2419,
2457,
342,
436,
5760,
342,
267,
327,
23016,
3955,
2040,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1541,
8,
49,
8,
2051,
29,
277,
14,
65,
17,
9,
1253,
31742,
49,
8,
2051,
29,
277,
14,
65,
18,
9,
1204,
1413,
8,
2051,
29,
277,
14,
65,
19,
11508,
359,
355,
283,
6257,
7,
288,
2156,
288,
21829,
480,
11268,
1288,
267,
776,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lateminer/bitcoin
|
test/functional/rpc_preciousblock.py
|
28
|
5304
|
#!/usr/bin/env python3
# Copyright (c) 2015-2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the preciousblock RPC."""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)
def unidirectional_node_sync_via_rpc(node_src, node_dest):
blocks_to_copy = []
blockhash = node_src.getbestblockhash()
while True:
try:
assert len(node_dest.getblock(blockhash, False)) > 0
break
except:
blocks_to_copy.append(blockhash)
blockhash = node_src.getblockheader(blockhash, True)['previousblockhash']
blocks_to_copy.reverse()
for blockhash in blocks_to_copy:
blockdata = node_src.getblock(blockhash, False)
assert node_dest.submitblock(blockdata) in (None, 'inconclusive')
def node_sync_via_rpc(nodes):
for node_src in nodes:
for node_dest in nodes:
if node_src is node_dest:
continue
unidirectional_node_sync_via_rpc(node_src, node_dest)
class PreciousTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
self.supports_cli = False
def setup_network(self):
self.setup_nodes()
def run_test(self):
self.log.info("Ensure submitblock can in principle reorg to a competing chain")
gen_address = lambda i: self.nodes[i].get_deterministic_priv_key().address # A non-wallet address to mine to
self.nodes[0].generatetoaddress(1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 1)
hashZ = self.nodes[1].generatetoaddress(2, gen_address(1))[-1]
assert_equal(self.nodes[1].getblockcount(), 2)
node_sync_via_rpc(self.nodes[0:3])
assert_equal(self.nodes[0].getbestblockhash(), hashZ)
self.log.info("Mine blocks A-B-C on Node 0")
hashC = self.nodes[0].generatetoaddress(3, gen_address(0))[-1]
assert_equal(self.nodes[0].getblockcount(), 5)
self.log.info("Mine competing blocks E-F-G on Node 1")
hashG = self.nodes[1].generatetoaddress(3, gen_address(1))[-1]
assert_equal(self.nodes[1].getblockcount(), 5)
assert hashC != hashG
self.log.info("Connect nodes and check no reorg occurs")
# Submit competing blocks via RPC so any reorg should occur before we proceed (no way to wait on inaction for p2p sync)
node_sync_via_rpc(self.nodes[0:2])
self.connect_nodes(0, 1)
assert_equal(self.nodes[0].getbestblockhash(), hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashG)
self.log.info("Make Node0 prefer block G")
self.nodes[0].preciousblock(hashG)
assert_equal(self.nodes[0].getbestblockhash(), hashG)
self.log.info("Make Node0 prefer block C again")
self.nodes[0].preciousblock(hashC)
assert_equal(self.nodes[0].getbestblockhash(), hashC)
self.log.info("Make Node1 prefer block C")
self.nodes[1].preciousblock(hashC)
self.sync_blocks(self.nodes[0:2]) # wait because node 1 may not have downloaded hashC
assert_equal(self.nodes[1].getbestblockhash(), hashC)
self.log.info("Make Node1 prefer block G again")
self.nodes[1].preciousblock(hashG)
assert_equal(self.nodes[1].getbestblockhash(), hashG)
self.log.info("Make Node0 prefer block G again")
self.nodes[0].preciousblock(hashG)
assert_equal(self.nodes[0].getbestblockhash(), hashG)
self.log.info("Make Node1 prefer block C again")
self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashC)
self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1")
self.nodes[0].generatetoaddress(1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 6)
self.sync_blocks(self.nodes[0:2])
hashH = self.nodes[0].getbestblockhash()
assert_equal(self.nodes[1].getbestblockhash(), hashH)
self.log.info("Node1 should not be able to prefer block C anymore")
self.nodes[1].preciousblock(hashC)
assert_equal(self.nodes[1].getbestblockhash(), hashH)
self.log.info("Mine competing blocks I-J-K-L on Node 2")
self.nodes[2].generatetoaddress(4, gen_address(2))
assert_equal(self.nodes[2].getblockcount(), 6)
hashL = self.nodes[2].getbestblockhash()
self.log.info("Connect nodes and check no reorg occurs")
node_sync_via_rpc(self.nodes[1:3])
self.connect_nodes(1, 2)
self.connect_nodes(0, 2)
assert_equal(self.nodes[0].getbestblockhash(), hashH)
assert_equal(self.nodes[1].getbestblockhash(), hashH)
assert_equal(self.nodes[2].getbestblockhash(), hashL)
self.log.info("Make Node1 prefer block L")
self.nodes[1].preciousblock(hashL)
assert_equal(self.nodes[1].getbestblockhash(), hashL)
self.log.info("Make Node2 prefer block H")
self.nodes[2].preciousblock(hashH)
assert_equal(self.nodes[2].getbestblockhash(), hashH)
if __name__ == '__main__':
PreciousTest().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
13934,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
314,
876,
559,
1785,
1457,
11785,
1041,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
199,
9,
199,
199,
318,
15439,
21360,
63,
932,
63,
5186,
63,
12897,
63,
4354,
8,
932,
63,
2164,
12,
1031,
63,
2614,
304,
272,
5664,
63,
475,
63,
1574,
275,
942,
272,
1853,
2227,
275,
1031,
63,
2164,
14,
362,
7010,
25848,
342,
272,
1830,
715,
26,
267,
862,
26,
288,
702,
822,
8,
932,
63,
2614,
14,
17785,
8,
25848,
12,
756,
430,
690,
378,
288,
2059,
267,
871,
26,
288,
5664,
63,
475,
63,
1574,
14,
740,
8,
25848,
9,
288,
1853,
2227,
275,
1031,
63,
2164,
14,
17785,
1291,
8,
25848,
12,
715,
11820,
6352,
25848,
418,
272,
5664,
63,
475,
63,
1574,
14,
4471,
342,
272,
367,
1853,
2227,
315,
5664,
63,
475,
63,
1574,
26,
267,
1853,
576,
275,
1031,
63,
2164,
14,
17785,
8,
25848,
12,
756,
9,
267,
702,
1031,
63,
2614,
14,
7275,
1457,
8,
1457,
576,
9,
315,
334,
403,
12,
283,
262,
388,
6563,
358,
199,
199,
318,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
2415,
304,
272,
367,
1031,
63,
2164,
315,
3380,
26,
267,
367,
1031,
63,
2614,
315,
3380,
26,
288,
340,
1031,
63,
2164,
365,
1031,
63,
2614,
26,
355,
1980,
288,
15439,
21360,
63,
932,
63,
5186,
63,
12897,
63,
4354,
8,
932,
63,
2164,
12,
1031,
63,
2614,
9,
199,
199,
533,
5543,
559,
1785,
774,
8,
4734,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
1507,
63,
2415,
275,
650,
267,
291,
14,
9823,
63,
2764,
275,
756,
339,
347,
3272,
63,
1200,
8,
277,
304,
267,
291,
14,
2758,
63,
2415,
342,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
291,
14,
793,
14,
815,
480,
13913,
11482,
1457,
883,
315,
5448,
10352,
274,
295,
1308,
370,
282,
1013,
13800,
6036,
531,
267,
3805,
63,
1562,
275,
2400,
284,
26,
291,
14,
2415,
59,
73,
1055,
362,
63,
30709,
63,
10605,
63,
498,
1252,
1562,
221,
327,
437,
2222,
13,
13892,
2287,
370,
30820,
370,
267,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
3805,
63,
1562,
8,
16,
430,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
30710,
1062,
413,
9,
267,
2631,
58,
275,
291,
14,
2415,
59,
17,
1055,
4208,
475,
1562,
8,
18,
12,
3805,
63,
1562,
8,
17,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
30710,
1062,
499,
9,
267,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
277,
14,
2415,
59,
16,
26,
19,
566,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
58,
9,
398,
291,
14,
793,
14,
815,
480,
45,
1132,
5664,
437,
13,
34,
13,
35,
641,
5013,
378,
531,
267,
2631,
35,
275,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
19,
12,
3805,
63,
1562,
8,
16,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
30710,
1062,
959,
9,
267,
291,
14,
793,
14,
815,
480,
45,
1132,
1013,
13800,
5664,
662,
13,
38,
13,
39,
641,
5013,
413,
531,
267,
2631,
39,
275,
291,
14,
2415,
59,
17,
1055,
4208,
475,
1562,
8,
19,
12,
3805,
63,
1562,
8,
17,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
30710,
1062,
959,
9,
267,
702,
2631,
35,
1137,
2631,
39,
267,
291,
14,
793,
14,
815,
480,
8631,
3380,
436,
1104,
949,
295,
1308,
11058,
531,
267,
327,
28295,
1013,
13800,
5664,
4799,
11785,
880,
1263,
295,
1308,
1077,
4781,
2544,
781,
20320,
334,
889,
4340,
370,
3618,
641,
315,
1287,
367,
299,
18,
80,
7604,
9,
267,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
277,
14,
2415,
59,
16,
26,
18,
566,
267,
291,
14,
2242,
63,
2415,
8,
16,
12,
413,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
598,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
39,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
445,
4020,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
35,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
17,
16602,
1853,
445,
531,
267,
291,
14,
2415,
59,
17,
1055,
20940,
1785,
1457,
8,
2227,
35,
9,
267,
291,
14,
5186,
63,
4166,
8,
277,
14,
2415,
59,
16,
26,
18,
566,
221,
327,
3618,
2952,
1031,
413,
1443,
440,
1172,
13557,
2631,
35,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
17,
16602,
1853,
598,
4020,
531,
267,
291,
14,
2415,
59,
17,
1055,
20940,
1785,
1457,
8,
2227,
39,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
598,
4020,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
39,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
13934,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
314,
876,
559,
1785,
1457,
11785,
1041,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
199,
9,
199,
199,
318,
15439,
21360,
63,
932,
63,
5186,
63,
12897,
63,
4354,
8,
932,
63,
2164,
12,
1031,
63,
2614,
304,
272,
5664,
63,
475,
63,
1574,
275,
942,
272,
1853,
2227,
275,
1031,
63,
2164,
14,
362,
7010,
25848,
342,
272,
1830,
715,
26,
267,
862,
26,
288,
702,
822,
8,
932,
63,
2614,
14,
17785,
8,
25848,
12,
756,
430,
690,
378,
288,
2059,
267,
871,
26,
288,
5664,
63,
475,
63,
1574,
14,
740,
8,
25848,
9,
288,
1853,
2227,
275,
1031,
63,
2164,
14,
17785,
1291,
8,
25848,
12,
715,
11820,
6352,
25848,
418,
272,
5664,
63,
475,
63,
1574,
14,
4471,
342,
272,
367,
1853,
2227,
315,
5664,
63,
475,
63,
1574,
26,
267,
1853,
576,
275,
1031,
63,
2164,
14,
17785,
8,
25848,
12,
756,
9,
267,
702,
1031,
63,
2614,
14,
7275,
1457,
8,
1457,
576,
9,
315,
334,
403,
12,
283,
262,
388,
6563,
358,
199,
199,
318,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
2415,
304,
272,
367,
1031,
63,
2164,
315,
3380,
26,
267,
367,
1031,
63,
2614,
315,
3380,
26,
288,
340,
1031,
63,
2164,
365,
1031,
63,
2614,
26,
355,
1980,
288,
15439,
21360,
63,
932,
63,
5186,
63,
12897,
63,
4354,
8,
932,
63,
2164,
12,
1031,
63,
2614,
9,
199,
199,
533,
5543,
559,
1785,
774,
8,
4734,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
1507,
63,
2415,
275,
650,
267,
291,
14,
9823,
63,
2764,
275,
756,
339,
347,
3272,
63,
1200,
8,
277,
304,
267,
291,
14,
2758,
63,
2415,
342,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
291,
14,
793,
14,
815,
480,
13913,
11482,
1457,
883,
315,
5448,
10352,
274,
295,
1308,
370,
282,
1013,
13800,
6036,
531,
267,
3805,
63,
1562,
275,
2400,
284,
26,
291,
14,
2415,
59,
73,
1055,
362,
63,
30709,
63,
10605,
63,
498,
1252,
1562,
221,
327,
437,
2222,
13,
13892,
2287,
370,
30820,
370,
267,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
17,
12,
3805,
63,
1562,
8,
16,
430,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
30710,
1062,
413,
9,
267,
2631,
58,
275,
291,
14,
2415,
59,
17,
1055,
4208,
475,
1562,
8,
18,
12,
3805,
63,
1562,
8,
17,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
30710,
1062,
499,
9,
267,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
277,
14,
2415,
59,
16,
26,
19,
566,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
58,
9,
398,
291,
14,
793,
14,
815,
480,
45,
1132,
5664,
437,
13,
34,
13,
35,
641,
5013,
378,
531,
267,
2631,
35,
275,
291,
14,
2415,
59,
16,
1055,
4208,
475,
1562,
8,
19,
12,
3805,
63,
1562,
8,
16,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
30710,
1062,
959,
9,
267,
291,
14,
793,
14,
815,
480,
45,
1132,
1013,
13800,
5664,
662,
13,
38,
13,
39,
641,
5013,
413,
531,
267,
2631,
39,
275,
291,
14,
2415,
59,
17,
1055,
4208,
475,
1562,
8,
19,
12,
3805,
63,
1562,
8,
17,
430,
1988,
17,
61,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
30710,
1062,
959,
9,
267,
702,
2631,
35,
1137,
2631,
39,
267,
291,
14,
793,
14,
815,
480,
8631,
3380,
436,
1104,
949,
295,
1308,
11058,
531,
267,
327,
28295,
1013,
13800,
5664,
4799,
11785,
880,
1263,
295,
1308,
1077,
4781,
2544,
781,
20320,
334,
889,
4340,
370,
3618,
641,
315,
1287,
367,
299,
18,
80,
7604,
9,
267,
1031,
63,
5186,
63,
12897,
63,
4354,
8,
277,
14,
2415,
59,
16,
26,
18,
566,
267,
291,
14,
2242,
63,
2415,
8,
16,
12,
413,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
598,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
39,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
445,
4020,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
35,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
17,
16602,
1853,
445,
531,
267,
291,
14,
2415,
59,
17,
1055,
20940,
1785,
1457,
8,
2227,
35,
9,
267,
291,
14,
5186,
63,
4166,
8,
277,
14,
2415,
59,
16,
26,
18,
566,
221,
327,
3618,
2952,
1031,
413,
1443,
440,
1172,
13557,
2631,
35,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
35,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
17,
16602,
1853,
598,
4020,
531,
267,
291,
14,
2415,
59,
17,
1055,
20940,
1785,
1457,
8,
2227,
39,
9,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
17,
1055,
362,
7010,
25848,
1062,
2631,
39,
9,
267,
291,
14,
793,
14,
815,
480,
5483,
5013,
16,
16602,
1853,
598,
4020,
531,
267,
291,
14,
2415,
59,
16,
1055,
20940,
1785,
1457,
8,
2227,
39,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
lumig242/Hue-Integration-with-CDAP
|
apps/oozie/src/oozie/migrations/0022_auto__chg_field_mapreduce_node_ptr__chg_field_start_node_ptr.py
|
37
|
25559
|
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Mapreduce.node_ptr'
db.alter_column('oozie_mapreduce', 'node_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['oozie.Node'], unique=True, primary_key=True))
# Changing field 'Start.node_ptr'
db.alter_column('oozie_start', 'node_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['oozie.Node'], unique=True, primary_key=True))
def backwards(self, orm):
# Changing field 'Mapreduce.node_ptr'
db.alter_column('oozie_mapreduce', 'node_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['oozie.Node'], unique=True))
# Changing field 'Start.node_ptr'
db.alter_column('oozie_start', 'node_ptr_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['oozie.Node'], unique=True))
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 28, 16, 10, 12, 534880)'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 28, 16, 10, 12, 534819)'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'oozie.bundle': {
'Meta': {'object_name': 'Bundle', '_ormbases': ['oozie.Job']},
'coordinators': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['oozie.Coordinator']", 'through': "orm['oozie.BundledCoordinator']", 'symmetrical': 'False'}),
'job_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Job']", 'unique': 'True', 'primary_key': 'True'}),
'kick_off_time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 28, 16, 10, 12, 429841)'})
},
'oozie.bundledcoordinator': {
'Meta': {'object_name': 'BundledCoordinator'},
'bundle': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Bundle']"}),
'coordinator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Coordinator']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'parameters': ('django.db.models.fields.TextField', [], {'default': '\'[{"name":"oozie.use.system.libpath","value":"true"}]\''})
},
'oozie.coordinator': {
'Meta': {'object_name': 'Coordinator', '_ormbases': ['oozie.Job']},
'concurrency': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'end': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 31, 16, 10, 12, 427644)'}),
'execution': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
'frequency_number': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
'frequency_unit': ('django.db.models.fields.CharField', [], {'default': "'days'", 'max_length': '20'}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Job']", 'unique': 'True', 'primary_key': 'True'}),
'start': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 28, 16, 10, 12, 427612)'}),
'throttle': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'timeout': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'timezone': ('django.db.models.fields.CharField', [], {'default': "'America/Los_Angeles'", 'max_length': '24'}),
'workflow': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Workflow']", 'null': 'True'})
},
'oozie.datainput': {
'Meta': {'object_name': 'DataInput'},
'coordinator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Coordinator']"}),
'dataset': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Dataset']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
},
'oozie.dataoutput': {
'Meta': {'object_name': 'DataOutput'},
'coordinator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Coordinator']"}),
'dataset': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Dataset']", 'unique': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
},
'oozie.dataset': {
'Meta': {'object_name': 'Dataset'},
'advanced_end_instance': ('django.db.models.fields.CharField', [], {'default': "'0'", 'max_length': '128', 'blank': 'True'}),
'advanced_start_instance': ('django.db.models.fields.CharField', [], {'default': "'0'", 'max_length': '128'}),
'coordinator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Coordinator']"}),
'description': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1024', 'blank': 'True'}),
'done_flag': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '64', 'blank': 'True'}),
'frequency_number': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
'frequency_unit': ('django.db.models.fields.CharField', [], {'default': "'days'", 'max_length': '20'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'instance_choice': ('django.db.models.fields.CharField', [], {'default': "'default'", 'max_length': '10'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'start': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 8, 28, 16, 10, 12, 428249)'}),
'timezone': ('django.db.models.fields.CharField', [], {'default': "'America/Los_Angeles'", 'max_length': '24'}),
'uri': ('django.db.models.fields.CharField', [], {'default': "'/data/${YEAR}${MONTH}${DAY}'", 'max_length': '1024'})
},
'oozie.decision': {
'Meta': {'object_name': 'Decision'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.decisionend': {
'Meta': {'object_name': 'DecisionEnd'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.distcp': {
'Meta': {'object_name': 'DistCp'},
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"})
},
'oozie.email': {
'Meta': {'object_name': 'Email'},
'body': ('django.db.models.fields.TextField', [], {'default': "''"}),
'cc': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'subject': ('django.db.models.fields.TextField', [], {'default': "''"}),
'to': ('django.db.models.fields.TextField', [], {'default': "''"})
},
'oozie.end': {
'Meta': {'object_name': 'End'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.fork': {
'Meta': {'object_name': 'Fork'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.fs': {
'Meta': {'object_name': 'Fs'},
'chmods': ('django.db.models.fields.TextField', [], {'default': "'[]'", 'blank': 'True'}),
'deletes': ('django.db.models.fields.TextField', [], {'default': "'[]'", 'blank': 'True'}),
'mkdirs': ('django.db.models.fields.TextField', [], {'default': "'[]'", 'blank': 'True'}),
'moves': ('django.db.models.fields.TextField', [], {'default': "'[]'", 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'touchzs': ('django.db.models.fields.TextField', [], {'default': "'[]'", 'blank': 'True'})
},
'oozie.generic': {
'Meta': {'object_name': 'Generic'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'xml': ('django.db.models.fields.TextField', [], {'default': "''"})
},
'oozie.history': {
'Meta': {'object_name': 'History'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'job': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Job']"}),
'oozie_job_id': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'properties': ('django.db.models.fields.TextField', [], {}),
'submission_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
'submitter': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'oozie.hive': {
'Meta': {'object_name': 'Hive'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': '\'[{"name":"oozie.hive.defaults","value":"hive-site.xml"}]\''}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'script_path': ('django.db.models.fields.CharField', [], {'max_length': '256'})
},
'oozie.java': {
'Meta': {'object_name': 'Java'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'args': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'capture_output': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'jar_path': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'java_opts': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'main_class': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"})
},
'oozie.job': {
'Meta': {'object_name': 'Job'},
'deployment_dir': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'blank': 'True'}),
'description': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_shared': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
'is_trashed': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
'parameters': ('django.db.models.fields.TextField', [], {'default': '\'[{"name":"oozie.use.system.libpath","value":"true"}]\''}),
'schema_version': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
'oozie.join': {
'Meta': {'object_name': 'Join'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.kill': {
'Meta': {'object_name': 'Kill'},
'message': ('django.db.models.fields.CharField', [], {'default': "'Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]'", 'max_length': '256'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.link': {
'Meta': {'object_name': 'Link'},
'child': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'parent_node'", 'to': "orm['oozie.Node']"}),
'comment': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1024', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'child_node'", 'to': "orm['oozie.Node']"})
},
'oozie.mapreduce': {
'Meta': {'object_name': 'Mapreduce'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'jar_path': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"})
},
'oozie.node': {
'Meta': {'object_name': 'Node'},
'children': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'parents'", 'symmetrical': 'False', 'through': "orm['oozie.Link']", 'to': "orm['oozie.Node']"}),
'description': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1024', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'node_type': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'workflow': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Workflow']"})
},
'oozie.pig': {
'Meta': {'object_name': 'Pig'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'script_path': ('django.db.models.fields.CharField', [], {'max_length': '256'})
},
'oozie.shell': {
'Meta': {'object_name': 'Shell'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'capture_output': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'command': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"})
},
'oozie.sqoop': {
'Meta': {'object_name': 'Sqoop'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'prepares': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'script_path': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
},
'oozie.ssh': {
'Meta': {'object_name': 'Ssh'},
'capture_output': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'command': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'host': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'params': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'user': ('django.db.models.fields.CharField', [], {'max_length': '64'})
},
'oozie.start': {
'Meta': {'object_name': 'Start'},
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'})
},
'oozie.streaming': {
'Meta': {'object_name': 'Streaming'},
'archives': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'files': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'mapper': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'reducer': ('django.db.models.fields.CharField', [], {'max_length': '512'})
},
'oozie.subworkflow': {
'Meta': {'object_name': 'SubWorkflow'},
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'node_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Node']", 'unique': 'True', 'primary_key': 'True'}),
'propagate_configuration': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'sub_workflow': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['oozie.Workflow']"})
},
'oozie.workflow': {
'Meta': {'object_name': 'Workflow', '_ormbases': ['oozie.Job']},
'end': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'end_workflow'", 'null': 'True', 'to': "orm['oozie.End']"}),
'is_single': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'job_properties': ('django.db.models.fields.TextField', [], {'default': "'[]'"}),
'job_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['oozie.Job']", 'unique': 'True', 'primary_key': 'True'}),
'job_xml': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '512', 'blank': 'True'}),
'managed': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'start': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'start_workflow'", 'null': 'True', 'to': "orm['oozie.Start']"})
}
}
complete_apps = ['oozie']
|
apache-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
398,
327,
27854,
901,
283,
2956,
5270,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
28658,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
12,
5062,
63,
498,
29,
549,
430,
398,
327,
27854,
901,
283,
3162,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
928,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
12,
5062,
63,
498,
29,
549,
430,
2378,
347,
8552,
8,
277,
12,
9813,
304,
398,
327,
27854,
901,
283,
2956,
5270,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
28658,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
430,
398,
327,
27854,
901,
283,
3162,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
928,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
430,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
6965,
12,
1695,
12,
7294,
12,
3193,
12,
1616,
12,
3144,
12,
959,
13442,
1257,
9,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
6965,
12,
1695,
12,
7294,
12,
3193,
12,
1616,
12,
3144,
12,
959,
13442,
1167,
9,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
283
] |
[
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
398,
327,
27854,
901,
283,
2956,
5270,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
28658,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
12,
5062,
63,
498,
29,
549,
430,
398,
327,
27854,
901,
283,
3162,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
928,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
12,
5062,
63,
498,
29,
549,
430,
2378,
347,
8552,
8,
277,
12,
9813,
304,
398,
327,
27854,
901,
283,
2956,
5270,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
28658,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
430,
398,
327,
27854,
901,
283,
3162,
14,
932,
63,
4695,
7,
267,
1592,
14,
11858,
63,
2301,
360,
18811,
63,
928,
297,
283,
932,
63,
4695,
63,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
7533,
475,
29,
1025,
459,
18811,
14,
1716,
995,
3747,
29,
549,
430,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
6965,
12,
1695,
12,
7294,
12,
3193,
12,
1616,
12,
3144,
12,
959,
13442,
1257,
9,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
8,
6965,
12,
1695,
12,
7294,
12,
3193,
12,
1616,
12,
3144,
12,
959,
13442,
1167,
9,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
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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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
] |
boegel/hanythingondemand
|
test/unit/rmscheduler/__init__.py
|
16
|
1140
|
###
# Copyright 2009-2014 Ghent University
#
# This file is part of hanythingondemand
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# the Hercules foundation (http://www.herculesstichting.be/in_English)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# http://github.com/hpcugent/hanythingondemand
#
# hanythingondemand 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 v2.
#
# hanythingondemand 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 hanythingondemand. If not, see <http://www.gnu.org/licenses/>.
'''
@author Ewan Higgs (Universiteit Gent)
'''
|
gpl-2.0
|
[
5680,
199,
3,
1898,
8937,
13,
7280,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
394,
25058,
265,
24152,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
72,
25058,
265,
24152,
199,
3,
199,
3,
394,
25058,
265,
24152,
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,
373,
18,
14,
199,
3,
199,
3,
394,
25058,
265,
24152,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
394,
25058,
265,
24152,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
32,
2502,
662,
20444,
869,
528,
458,
334,
1358,
4380,
2124,
390,
598,
484,
9,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
8937,
13,
7280,
598,
72,
484,
15904,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
394,
25058,
265,
24152,
199,
3,
20657,
2737,
701,
314,
869,
4222,
8099,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
15,
287,
395,
199,
3,
543,
2291,
402,
598,
72,
484,
15904,
334,
1014,
921,
1518,
484,
14,
1235,
15,
72,
2352,
395,
199,
3,
314,
481,
274,
1292,
72,
17897,
23805,
30610,
264,
334,
54,
5153,
9,
334,
2859,
921,
86,
10845,
454,
453,
14,
1235,
15,
7530,
15,
287,
395,
199,
3,
314,
18769,
67,
443,
83,
1911,
425,
334,
1014,
921,
1544,
14,
2523,
67,
443,
83,
270,
1158,
1337,
14,
1235,
15,
262,
63,
19410,
9,
199,
3,
436,
314,
1487,
12493,
402,
662,
25129,
89,
12,
27491,
436,
1010,
889,
4255,
334,
37,
18759,
9,
334,
1014,
921,
1544,
14,
546,
73,
13,
86,
416,
290,
271,
828,
14,
1235,
15,
287,
680,
199,
3,
199,
3,
1455,
921,
5031,
14,
957,
15,
72,
2352,
1518,
484,
15,
72,
25058,
265,
24152,
199,
3,
199,
3,
394,
25058,
265,
24152,
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,
373,
18,
14,
199,
3,
199,
3,
394,
25058,
265,
24152,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
394,
25058,
265,
24152,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
32,
2502,
662,
20444,
869,
528,
458,
334,
1358,
4380,
2124,
390,
598,
484,
9,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
mspark93/VTK
|
Examples/Modelling/Python/faultLines.py
|
42
|
2235
|
#!/usr/bin/env python
# Create a constrained Delaunay triangulation following fault lines. The
# fault lines serve as constraint edges in the Delaunay triangulation.
import vtk
from vtk.util.misc import vtkGetDataRoot
from vtk.util.colors import *
VTK_DATA_ROOT = vtkGetDataRoot()
# Generate some points by reading a VTK data file. The data file also
# has edges that represent constraint lines. This is originally from a
# geologic horizon.
reader = vtk.vtkPolyDataReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/faults.vtk")
# Perform a 2D triangulation with constraint edges.
delny = vtk.vtkDelaunay2D()
delny.SetInputConnection(reader.GetOutputPort())
delny.SetSourceConnection(reader.GetOutputPort())
delny.SetTolerance(0.00001)
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(delny.GetOutputPort())
mapMesh = vtk.vtkPolyDataMapper()
mapMesh.SetInputConnection(normals.GetOutputPort())
meshActor = vtk.vtkActor()
meshActor.SetMapper(mapMesh)
meshActor.GetProperty().SetColor(beige)
# Now pretty up the mesh with tubed edges and balls at the vertices.
tuber = vtk.vtkTubeFilter()
tuber.SetInputConnection(reader.GetOutputPort())
tuber.SetRadius(25)
mapLines = vtk.vtkPolyDataMapper()
mapLines.SetInputConnection(tuber.GetOutputPort())
linesActor = vtk.vtkActor()
linesActor.SetMapper(mapLines)
linesActor.GetProperty().SetColor(1, 0, 0)
linesActor.GetProperty().SetColor(tomato)
# Create graphics objects
# Create the rendering window, renderer, and interactive renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
ren.AddActor(linesActor)
ren.AddActor(meshActor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(350, 250)
cam1 = vtk.vtkCamera()
cam1.SetClippingRange(2580, 129041)
cam1.SetFocalPoint(461550, 6.58e+006, 2132)
cam1.SetPosition(463960, 6.559e+06, 16982)
cam1.SetViewUp(-0.321899, 0.522244, 0.78971)
light = vtk.vtkLight()
light.SetPosition(0, 0, 1)
light.SetFocalPoint(0, 0, 0)
ren.SetActiveCamera(cam1)
ren.AddLight(light)
ren.GetActiveCamera().Zoom(1.5)
iren.LightFollowCameraOff()
iren.Initialize()
renWin.Render()
iren.Start()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
2790,
282,
28483,
18464,
65,
324,
1187,
3229,
621,
5332,
2569,
16898,
2385,
14,
710,
199,
3,
16898,
2385,
14062,
465,
5828,
8207,
315,
314,
18464,
65,
324,
1187,
3229,
621,
5332,
14,
199,
199,
646,
11144,
199,
504,
11144,
14,
1974,
14,
9923,
492,
11144,
25702,
6405,
199,
504,
11144,
14,
1974,
14,
7120,
492,
627,
199,
8156,
43,
63,
3998,
63,
5441,
275,
11144,
25702,
6405,
342,
199,
199,
3,
7958,
2005,
4501,
701,
7664,
282,
812,
15263,
666,
570,
14,
710,
666,
570,
2597,
199,
3,
965,
8207,
626,
2954,
5828,
2385,
14,
961,
365,
20657,
687,
282,
199,
3,
8509,
15370,
21726,
14,
199,
5503,
275,
11144,
14,
11919,
12747,
1451,
5929,
342,
199,
5503,
14,
1084,
7733,
8,
8156,
43,
63,
3998,
63,
5441,
435,
3286,
1451,
15,
1879,
83,
14,
11919,
531,
199,
199,
3,
14795,
282,
499,
36,
3229,
621,
5332,
543,
5828,
8207,
14,
199,
2264,
9745,
275,
11144,
14,
11919,
6994,
65,
324,
1187,
18,
36,
342,
199,
2264,
9745,
14,
32195,
8,
5503,
14,
30810,
1012,
199,
2264,
9745,
14,
1084,
2980,
3225,
8,
5503,
14,
30810,
1012,
199,
2264,
9745,
14,
1084,
1378,
8807,
8,
16,
14,
22417,
9,
199,
21215,
275,
11144,
14,
11919,
12747,
1451,
6241,
83,
342,
199,
21215,
14,
32195,
8,
2264,
9745,
14,
30810,
1012,
199,
1130,
12241,
275,
11144,
14,
11919,
12747,
1451,
11880,
342,
199,
1130,
12241,
14,
32195,
8,
21215,
14,
30810,
1012,
199,
6480,
12258,
275,
11144,
14,
11919,
12258,
342,
199,
6480,
12258,
14,
1084,
11880,
8,
1130,
12241,
9,
199,
6480,
12258,
14,
22845,
1252,
1084,
4117,
8,
20009,
303,
9,
199,
199,
3,
7356,
7268,
1536,
314,
9364,
543,
307,
456,
379,
8207,
436,
330,
30483,
737,
314,
14971,
14,
199,
84,
10400,
275,
11144,
14,
11919,
16397,
4131,
342,
199,
84,
10400,
14,
32195,
8,
5503,
14,
30810,
1012,
199,
84,
10400,
14,
1084,
19800,
8,
821,
9,
199,
1130,
9863,
275,
11144,
14,
11919,
12747,
1451,
11880,
342,
199,
1130,
9863,
14,
32195,
8,
84,
10400,
14,
30810,
1012,
199,
1278,
12258,
275,
11144,
14,
11919,
12258,
342,
199,
1278,
12258,
14,
1084,
11880,
8,
1130,
9863,
9,
199,
1278,
12258,
14,
22845,
1252,
1084,
4117,
8,
17,
12,
378,
12,
378,
9,
199,
1278,
12258,
14,
22845,
1252,
1084,
4117,
8,
475,
569,
79,
9,
199,
199,
3,
2790,
24348,
2251,
199,
3,
2790,
314,
14066,
4353,
12,
11889,
12,
436,
12777,
11889,
199,
828,
275,
11144,
14,
11919,
11355,
342,
199,
828,
8886,
275,
11144,
14,
11919,
9216,
4301,
342,
199,
828,
8886,
14,
1123,
11355,
8,
828,
9,
199,
73,
828,
275,
11144,
14,
11919,
9216,
4301,
607,
2967,
630,
342,
199,
73,
828,
14,
1084,
9216,
4301,
8,
828,
8886,
9,
199,
199,
3,
2654,
314,
282,
13451,
370,
314,
11889,
12,
663,
314,
8020,
436,
1568,
199,
828,
14,
1123,
12258,
8,
1278,
12258,
9,
199,
828,
14,
1123,
12258,
8,
6480,
12258,
9,
199,
828,
14,
1084,
14148,
8,
17,
12,
413,
12,
413,
9,
199,
828,
8886,
14,
1084,
2320,
8,
13595,
12,
16074,
9,
199,
199,
15176,
17,
275,
11144,
14,
11919,
18425,
342,
199,
15176,
17,
14,
1084,
20653,
3637,
4709,
8,
28936,
12,
25454,
10531,
9,
199,
15176,
17,
14,
1084,
38,
24560,
3428,
8,
2466,
1046,
1400,
12,
1227,
14,
2010,
69,
11,
8010,
12,
499,
6557,
9,
199,
15176,
17,
14,
1084,
5625,
8,
2466,
1355,
2259,
12,
1227,
14,
17257,
69,
11,
1690,
12,
20680,
2564,
9,
199,
15176,
17,
14,
1084,
2768,
1721,
2801,
16,
14,
708,
1085,
1020,
12,
378,
14,
29915,
11603,
12,
378,
14,
24407,
3172,
9,
199,
4040,
275,
11144,
14,
11919,
16393,
342,
199,
4040,
14,
1084,
5625,
8,
16,
12,
378,
12,
413,
9,
199,
4040,
14,
1084,
38,
24560,
3428,
8,
16,
12,
378,
12,
378,
9,
199,
828,
14,
1084,
7472,
18425,
8,
15176,
17,
9,
199,
828,
14,
1123,
16393,
8,
4040,
9,
199,
199,
828,
14,
1002,
7472,
18425,
1252,
26798,
8,
17,
14,
21,
9,
199,
73,
828,
14,
16393,
18696,
18425,
5195,
342,
199,
199,
73,
828,
14,
9345,
342,
199,
828,
8886,
14,
9216,
342,
199,
73,
828,
14,
3162,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
2790,
282,
28483,
18464,
65,
324,
1187,
3229,
621,
5332,
2569,
16898,
2385,
14,
710,
199,
3,
16898,
2385,
14062,
465,
5828,
8207,
315,
314,
18464,
65,
324,
1187,
3229,
621,
5332,
14,
199,
199,
646,
11144,
199,
504,
11144,
14,
1974,
14,
9923,
492,
11144,
25702,
6405,
199,
504,
11144,
14,
1974,
14,
7120,
492,
627,
199,
8156,
43,
63,
3998,
63,
5441,
275,
11144,
25702,
6405,
342,
199,
199,
3,
7958,
2005,
4501,
701,
7664,
282,
812,
15263,
666,
570,
14,
710,
666,
570,
2597,
199,
3,
965,
8207,
626,
2954,
5828,
2385,
14,
961,
365,
20657,
687,
282,
199,
3,
8509,
15370,
21726,
14,
199,
5503,
275,
11144,
14,
11919,
12747,
1451,
5929,
342,
199,
5503,
14,
1084,
7733,
8,
8156,
43,
63,
3998,
63,
5441,
435,
3286,
1451,
15,
1879,
83,
14,
11919,
531,
199,
199,
3,
14795,
282,
499,
36,
3229,
621,
5332,
543,
5828,
8207,
14,
199,
2264,
9745,
275,
11144,
14,
11919,
6994,
65,
324,
1187,
18,
36,
342,
199,
2264,
9745,
14,
32195,
8,
5503,
14,
30810,
1012,
199,
2264,
9745,
14,
1084,
2980,
3225,
8,
5503,
14,
30810,
1012,
199,
2264,
9745,
14,
1084,
1378,
8807,
8,
16,
14,
22417,
9,
199,
21215,
275,
11144,
14,
11919,
12747,
1451,
6241,
83,
342,
199,
21215,
14,
32195,
8,
2264,
9745,
14,
30810,
1012,
199,
1130,
12241,
275,
11144,
14,
11919,
12747,
1451,
11880,
342,
199,
1130,
12241,
14,
32195,
8,
21215,
14,
30810,
1012,
199,
6480,
12258,
275,
11144,
14,
11919,
12258,
342,
199,
6480,
12258,
14,
1084,
11880,
8,
1130,
12241,
9,
199,
6480,
12258,
14,
22845,
1252,
1084,
4117,
8,
20009,
303,
9,
199,
199,
3,
7356,
7268,
1536,
314,
9364,
543,
307,
456,
379,
8207,
436,
330,
30483,
737,
314,
14971,
14,
199,
84,
10400,
275,
11144,
14,
11919,
16397,
4131,
342,
199,
84,
10400,
14,
32195,
8,
5503,
14,
30810,
1012,
199,
84,
10400,
14,
1084,
19800,
8,
821,
9,
199,
1130,
9863,
275,
11144,
14,
11919,
12747,
1451,
11880,
342,
199,
1130,
9863,
14,
32195,
8,
84,
10400,
14,
30810,
1012,
199,
1278,
12258,
275,
11144,
14,
11919,
12258,
342,
199,
1278,
12258,
14,
1084,
11880,
8,
1130,
9863,
9,
199,
1278,
12258,
14,
22845,
1252,
1084,
4117,
8,
17,
12,
378,
12,
378,
9,
199,
1278,
12258,
14,
22845,
1252,
1084,
4117,
8,
475,
569,
79,
9,
199,
199,
3,
2790,
24348,
2251,
199,
3,
2790,
314,
14066,
4353,
12,
11889,
12,
436,
12777,
11889,
199,
828,
275,
11144,
14,
11919,
11355,
342,
199,
828,
8886,
275,
11144,
14,
11919,
9216,
4301,
342,
199,
828,
8886,
14,
1123,
11355,
8,
828,
9,
199,
73,
828,
275,
11144,
14,
11919,
9216,
4301,
607,
2967,
630,
342,
199,
73,
828,
14,
1084,
9216,
4301,
8,
828,
8886,
9,
199,
199,
3,
2654,
314,
282,
13451,
370,
314,
11889,
12,
663,
314,
8020,
436,
1568,
199,
828,
14,
1123,
12258,
8,
1278,
12258,
9,
199,
828,
14,
1123,
12258,
8,
6480,
12258,
9,
199,
828,
14,
1084,
14148,
8,
17,
12,
413,
12,
413,
9,
199,
828,
8886,
14,
1084,
2320,
8,
13595,
12,
16074,
9,
199,
199,
15176,
17,
275,
11144,
14,
11919,
18425,
342,
199,
15176,
17,
14,
1084,
20653,
3637,
4709,
8,
28936,
12,
25454,
10531,
9,
199,
15176,
17,
14,
1084,
38,
24560,
3428,
8,
2466,
1046,
1400,
12,
1227,
14,
2010,
69,
11,
8010,
12,
499,
6557,
9,
199,
15176,
17,
14,
1084,
5625,
8,
2466,
1355,
2259,
12,
1227,
14,
17257,
69,
11,
1690,
12,
20680,
2564,
9,
199,
15176,
17,
14,
1084,
2768,
1721,
2801,
16,
14,
708,
1085,
1020,
12,
378,
14,
29915,
11603,
12,
378,
14,
24407,
3172,
9,
199,
4040,
275,
11144,
14,
11919,
16393,
342,
199,
4040,
14,
1084,
5625,
8,
16,
12,
378,
12,
413,
9,
199,
4040,
14,
1084,
38,
24560,
3428,
8,
16,
12,
378,
12,
378,
9,
199,
828,
14,
1084,
7472,
18425,
8,
15176,
17,
9,
199,
828,
14,
1123,
16393,
8,
4040,
9,
199,
199,
828,
14,
1002,
7472,
18425,
1252,
26798,
8,
17,
14,
21,
9,
199,
73,
828,
14,
16393,
18696,
18425,
5195,
342,
199,
199,
73,
828,
14,
9345,
342,
199,
828,
8886,
14,
9216,
342,
199,
73,
828,
14,
3162,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
|
8430
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2014 Bitergia
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors:
# Jesus M. Gonzalez-Barahona <jgb@bitergia.com>
#
# Timezone analysis. Time zones for developers and contributions.
#
from grimoirelib_alch.family.scm import (
PeriodCondition as SCMPeriodCondition,
NomergesCondition as SCMNomergesCondition
)
from grimoirelib_alch.query.scm import DB as SCMDatabase
from grimoirelib_alch.family.mls import PeriodCondition as MLSPeriodCondition
from grimoirelib_alch.query.mls import DB as MLSDatabase
from grimoirelib_alch.family.activity_timezones import (
SCMActivityTZ, MLSActivityTZ
)
from vizgrimoire.analysis.analyses import Analyses
from vizgrimoire.SCM import SCM
from vizgrimoire.MLS import MLS
from datetime import datetime, timedelta
from jsonpickle import encode, set_encoder_options
import codecs
import logging
def produce_json (filename, data, compact = True):
if compact:
# Produce compact JSON output
set_encoder_options('json', separators=(',', ': '),
ensure_ascii=False,
encoding="utf8")
else:
# Produce pretty JSON output
set_encoder_options('json', sort_keys=True, indent=4,
separators=(',', ': '),
ensure_ascii=False,
encoding="utf8")
data_json = encode(data, unpicklable=False)
with codecs.open(filename, "w", "utf-8") as file:
file.write(data_json)
class Timezone(Analyses):
"""Clase for calculating the Timezone analysis.
Produces data about timezones for contributions.
"""
id = "timezone"
name = "Timezone"
desc = "Timezone of contributions in project"
def __get_sql__(self):
raise NotImplementedError
def result(self, data_source = None):
"""Produce result data for the analysis
Parameters
----------
data_source: SCM.SCM, MLS.MLS
Returns
-------
dictionary: timezone data.
It includes three generic components, with following keys:
"tz": list of timezones from -12 to 11,
"authors": list of authors for each timezone
"authors365": list of authors for each timezone on the
last 365 days
Depending on the type of data source, it will contain two more keys.
On SCM data sources:
"commits": list of commits for each timezone
"commits365": list of commits for each timezone on the
last 365 days
On MLS data sources:
"messages": list of messages for each timezone
"messages365": list of messages for each timezone on the
last 365 days
"""
logging.info("Producing data for study: Timezone")
if data_source is None:
logging.info("Error: no data source for study!")
return
if data_source not in (SCM, MLS):
logging.info("Error: data_source not supported!")
return
# Prepare the SQLAlchemy database url
url = 'mysql://' + self.db.user + ':' + \
self.db.password + '@' + self.db.host + '/'
schema = self.db.database
schema_id = self.db.identities_db
# Get startdate, endate as datetime objects
startdate = datetime.strptime(self.filters.startdate, "'%Y-%m-%d'")
enddate = datetime.strptime(self.filters.enddate, "'%Y-%m-%d'")
# Get last 365 days period
start365 = enddate - timedelta(days=365)
end365 = enddate
if data_source == SCM:
logging.info("Analyzing timezone for SCM")
nomerges = SCMNomergesCondition()
database = SCMDatabase(url=url, schema=schema,
schema_id=schema_id)
period = SCMPeriodCondition(start=startdate, end=enddate)
data = SCMActivityTZ(datasource=database, name="authors",
conditions=(period, nomerges))
period365 = SCMPeriodCondition(start=start365, end=end365)
data365 = SCMActivityTZ(datasource=database, name="authors",
conditions=(period365, nomerges))
elif data_source == MLS:
logging.info("Analyzing timezone for MLS")
database = MLSDatabase(url=url, schema=schema,
schema_id=schema_id)
period = MLSPeriodCondition(start=startdate, end=enddate,
date="first")
data = MLSActivityTZ(datasource=database, name="senders",
conditions=(period,))
period365 = MLSPeriodCondition(start=start365, end=end365,
date="first")
data365 = MLSActivityTZ(datasource=database, name="senders",
conditions=(period365,))
timezones = data.timezones()
timezones365 = data365.timezones()
if data_source == SCM:
timezones['commits365'] = timezones365['commits']
elif data_source == MLS:
timezones['messages365'] = timezones365['messages']
timezones['authors365'] = timezones365['authors']
return timezones
def create_report(self, data_source, destdir):
"""Create report for the analysis.
Creates JSON files with the results of the report for timezone:
ds-timezone.json
with ds being "scm" or "its".
Only works for SCM and MLS data sources.
Parameters
----------
data_source: SCM.SCM, MLS.MLS
destdir: name of directory for writing JSON files
"""
logging.info("Producing report for study: Timezone")
if data_source == SCM:
prefix = "scm"
elif data_source == MLS:
prefix = "mls"
else:
logging.info("Error: data_source not supported for Timezone")
return
result = self.result(data_source)
produce_json (destdir + "/" + prefix + "-timezone.json",
result)
logging.info("Producing report for study: Timezone (done!)")
if __name__ == '__main__':
from vizgrimoire.metrics.query_builder import DSQuery
from vizgrimoire.metrics.metrics_filter import MetricFilters
# Get
filters = MetricFilters("months", "'2013-06-01'", "'2014-01-01'", [])
dbcon = DSQuery(user = "jgb", password = "XXX",
database = "oscon_openstack_scm_tz",
identities_db = "oscon_openstack_scm_tz")
tz = Timezone(dbcon, filters)
# Produce pretty JSON output
set_encoder_options('json', sort_keys=True, indent=4,
separators=(',', ': '),
ensure_ascii=False,
encoding="utf8")
print encode(tz.result(SCM), unpicklable=False)
# Produce compact JSON output
set_encoder_options('json', separators=(',', ': '),
ensure_ascii=False,
encoding="utf8")
print encode(tz.result(SCM), unpicklable=False)
# Nos, MLS
dbcon = DSQuery(user = "jgb", password = "XXX",
database = "oscon_openstack_mls",
identities_db = "oscon_openstack_scm")
tz = Timezone(dbcon, filters)
# Produce pretty JSON output
set_encoder_options('json', sort_keys=True, indent=4,
separators=(',', ': '),
ensure_ascii=False,
encoding="utf8")
print encode(tz.result(MLS), unpicklable=False)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
6927,
699,
1661,
71,
4674,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
755,
1603,
397,
527,
603,
14,
598,
265,
90,
1895,
90,
13,
5281,
11326,
265,
65,
665,
74,
4908,
32,
66,
1661,
71,
4674,
14,
957,
30,
199,
3,
199,
3,
4703,
2619,
11284,
14,
4703,
18666,
367,
19782,
436,
406,
26675,
14,
199,
3,
199,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
17143,
492,
334,
272,
16532,
9558,
465,
12075,
1658,
281,
3320,
9558,
12,
272,
653,
1377,
82,
3389,
9558,
465,
428,
9249,
46,
1377,
82,
3389,
9558,
272,
776,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
1131,
14,
17143,
492,
6249,
465,
428,
9744,
1963,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
77,
478,
492,
16532,
9558,
465,
603,
5296,
15518,
9558,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
1131,
14,
77,
478,
492,
6249,
465,
28007,
3693,
1963,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
8240,
63,
7145,
83,
492,
334,
272,
428,
9249,
14350,
14226,
12,
603,
5296,
14350,
14226,
272,
776,
199,
199,
504,
373,
565,
7928,
573,
3621,
14,
10466,
14,
4797,
874,
492,
14279,
874,
199,
504,
373,
565,
7928,
573,
3621,
14,
5153,
45,
492,
428,
9249,
199,
504,
373,
565,
7928,
573,
3621,
14,
1698,
51,
492,
603,
5296,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
2022,
8092,
492,
3752,
12,
663,
63,
9347,
63,
1419,
199,
646,
6010,
199,
646,
2050,
199,
199,
318,
7389,
63,
1001,
334,
1501,
12,
666,
12,
23314,
275,
715,
304,
339,
340,
23314,
26,
267,
327,
2165,
3402,
23314,
4840,
1072,
267,
663,
63,
9347,
63,
1419,
360,
1001,
297,
17658,
2687,
23324,
7596,
17748,
1169,
4868,
63,
4371,
29,
797,
12,
1169,
2644,
628,
1624,
24,
531,
272,
587,
26,
267,
327,
2165,
3402,
7268,
4840,
1072,
267,
663,
63,
9347,
63,
1419,
360,
1001,
297,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
12,
1169,
17658,
2687,
23324,
7596,
17748,
1169,
4868,
63,
4371,
29,
797,
12,
1169,
2644,
628,
1624,
24,
531,
272,
666,
63,
1001,
275,
3752,
8,
576,
12,
625,
4510,
76,
461,
29,
797,
9,
272,
543,
6010,
14,
1490,
8,
1501,
12,
298,
87,
401,
298,
1624,
13,
24,
531,
465,
570,
26,
267,
570,
14,
952,
8,
576,
63,
1001,
9,
199,
199,
533,
4703,
2619,
8,
8014,
874,
304,
272,
408,
12086,
261,
367,
26079,
314,
4703,
2619,
11284,
14,
339,
2165,
10569,
666,
3595,
7137,
83,
367,
406,
26675,
14,
339,
408,
339,
1305,
275,
298,
7145,
2,
272,
536,
275,
298,
28705,
2,
272,
4328,
275,
298,
28705,
402,
406,
26675,
315,
2199,
2,
339,
347,
636,
362,
63,
3009,
721,
277,
304,
267,
746,
4279,
339,
347,
754,
8,
277,
12,
666,
63,
1365,
275,
488,
304,
267,
408,
24391,
754,
666,
367,
314,
11284,
398,
3897,
267,
4143,
398,
666,
63,
1365,
26,
428,
9249,
14,
5153,
45,
12,
603,
5296,
14,
1698,
51,
398,
1803,
267,
5514,
398,
2600,
26,
7137,
666,
14,
881,
2779,
6952,
7795,
7809,
7323,
12,
543,
2569,
2883,
26,
881,
298,
3903,
582,
769,
402,
7137,
83,
687,
446,
713,
370,
4119,
12,
881,
298,
8149,
582,
769,
402,
11462,
367,
1924,
7137,
881,
298,
8149,
12664,
582,
769,
402,
11462,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
8592,
1487,
6455,
641,
314,
730,
402,
666,
1350,
12,
652,
911,
1395,
2877,
1655,
2883,
14,
881,
4068,
428,
9249,
666,
5274,
26,
881,
298,
18679,
582,
769,
402,
20835,
367,
1924,
7137,
881,
298,
18679,
12664,
582,
769,
402,
20835,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
8592,
4068,
603,
5296,
666,
5274,
26,
881,
298,
3431,
582,
769,
402,
3788,
367,
1924,
7137,
881,
298,
3431,
12664,
582,
769,
402,
3788,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
267,
408,
267,
2050,
14,
815,
480,
24982,
666,
367,
25932,
26,
4703,
2619,
531,
398,
340,
666,
63,
1365,
365,
488,
26,
288,
2050,
14,
815,
480,
547,
26,
949,
666,
1350,
367,
25932,
9124,
288,
372,
398,
340,
666,
63,
1365,
440,
315,
334,
5153,
45,
12,
603,
5296,
304,
288,
2050,
14,
815,
480,
547,
26,
666,
63,
1365,
440,
3748,
9124,
288,
372,
398,
327,
17008,
314,
14303,
3050,
1166,
267,
1166,
275,
283,
8644,
22399,
435,
291,
14,
697,
14,
751,
435,
10871,
435,
971,
288,
291,
14,
697,
14,
2060,
435,
22143,
435,
291,
14,
697,
14,
1102,
435,
7324,
267,
4177,
275,
291,
14,
697,
14,
4659,
267,
4177,
63,
344,
275,
291,
14,
697,
14,
9281,
5080,
63,
697,
398,
327,
2372,
1343,
602,
12,
1284,
323,
465,
2197,
2251,
267,
1343,
602,
275,
2197,
14,
9866,
8,
277,
14,
4273,
14,
928,
602,
12,
17648,
57,
3295,
77,
3295,
68,
9859,
267,
1284,
602,
275,
2197,
14,
9866,
8,
277,
14,
4273,
14,
500,
602,
12,
17648,
57
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
6927,
699,
1661,
71,
4674,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
755,
1603,
397,
527,
603,
14,
598,
265,
90,
1895,
90,
13,
5281,
11326,
265,
65,
665,
74,
4908,
32,
66,
1661,
71,
4674,
14,
957,
30,
199,
3,
199,
3,
4703,
2619,
11284,
14,
4703,
18666,
367,
19782,
436,
406,
26675,
14,
199,
3,
199,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
17143,
492,
334,
272,
16532,
9558,
465,
12075,
1658,
281,
3320,
9558,
12,
272,
653,
1377,
82,
3389,
9558,
465,
428,
9249,
46,
1377,
82,
3389,
9558,
272,
776,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
1131,
14,
17143,
492,
6249,
465,
428,
9744,
1963,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
77,
478,
492,
16532,
9558,
465,
603,
5296,
15518,
9558,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
1131,
14,
77,
478,
492,
6249,
465,
28007,
3693,
1963,
199,
504,
27591,
573,
3621,
773,
63,
279,
335,
14,
6606,
14,
8240,
63,
7145,
83,
492,
334,
272,
428,
9249,
14350,
14226,
12,
603,
5296,
14350,
14226,
272,
776,
199,
199,
504,
373,
565,
7928,
573,
3621,
14,
10466,
14,
4797,
874,
492,
14279,
874,
199,
504,
373,
565,
7928,
573,
3621,
14,
5153,
45,
492,
428,
9249,
199,
504,
373,
565,
7928,
573,
3621,
14,
1698,
51,
492,
603,
5296,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
2022,
8092,
492,
3752,
12,
663,
63,
9347,
63,
1419,
199,
646,
6010,
199,
646,
2050,
199,
199,
318,
7389,
63,
1001,
334,
1501,
12,
666,
12,
23314,
275,
715,
304,
339,
340,
23314,
26,
267,
327,
2165,
3402,
23314,
4840,
1072,
267,
663,
63,
9347,
63,
1419,
360,
1001,
297,
17658,
2687,
23324,
7596,
17748,
1169,
4868,
63,
4371,
29,
797,
12,
1169,
2644,
628,
1624,
24,
531,
272,
587,
26,
267,
327,
2165,
3402,
7268,
4840,
1072,
267,
663,
63,
9347,
63,
1419,
360,
1001,
297,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
12,
1169,
17658,
2687,
23324,
7596,
17748,
1169,
4868,
63,
4371,
29,
797,
12,
1169,
2644,
628,
1624,
24,
531,
272,
666,
63,
1001,
275,
3752,
8,
576,
12,
625,
4510,
76,
461,
29,
797,
9,
272,
543,
6010,
14,
1490,
8,
1501,
12,
298,
87,
401,
298,
1624,
13,
24,
531,
465,
570,
26,
267,
570,
14,
952,
8,
576,
63,
1001,
9,
199,
199,
533,
4703,
2619,
8,
8014,
874,
304,
272,
408,
12086,
261,
367,
26079,
314,
4703,
2619,
11284,
14,
339,
2165,
10569,
666,
3595,
7137,
83,
367,
406,
26675,
14,
339,
408,
339,
1305,
275,
298,
7145,
2,
272,
536,
275,
298,
28705,
2,
272,
4328,
275,
298,
28705,
402,
406,
26675,
315,
2199,
2,
339,
347,
636,
362,
63,
3009,
721,
277,
304,
267,
746,
4279,
339,
347,
754,
8,
277,
12,
666,
63,
1365,
275,
488,
304,
267,
408,
24391,
754,
666,
367,
314,
11284,
398,
3897,
267,
4143,
398,
666,
63,
1365,
26,
428,
9249,
14,
5153,
45,
12,
603,
5296,
14,
1698,
51,
398,
1803,
267,
5514,
398,
2600,
26,
7137,
666,
14,
881,
2779,
6952,
7795,
7809,
7323,
12,
543,
2569,
2883,
26,
881,
298,
3903,
582,
769,
402,
7137,
83,
687,
446,
713,
370,
4119,
12,
881,
298,
8149,
582,
769,
402,
11462,
367,
1924,
7137,
881,
298,
8149,
12664,
582,
769,
402,
11462,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
8592,
1487,
6455,
641,
314,
730,
402,
666,
1350,
12,
652,
911,
1395,
2877,
1655,
2883,
14,
881,
4068,
428,
9249,
666,
5274,
26,
881,
298,
18679,
582,
769,
402,
20835,
367,
1924,
7137,
881,
298,
18679,
12664,
582,
769,
402,
20835,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
8592,
4068,
603,
5296,
666,
5274,
26,
881,
298,
3431,
582,
769,
402,
3788,
367,
1924,
7137,
881,
298,
3431,
12664,
582,
769,
402,
3788,
367,
1924,
7137,
641,
314,
1598,
2061,
28046,
7609,
267,
408,
267,
2050,
14,
815,
480,
24982,
666,
367,
25932,
26,
4703,
2619,
531,
398,
340,
666,
63,
1365,
365,
488,
26,
288,
2050,
14,
815,
480,
547,
26,
949,
666,
1350,
367,
25932,
9124,
288,
372,
398,
340,
666,
63,
1365,
440,
315,
334,
5153,
45,
12,
603,
5296,
304,
288,
2050,
14,
815,
480,
547,
26,
666,
63,
1365,
440,
3748,
9124,
288,
372,
398,
327,
17008,
314,
14303,
3050,
1166,
267,
1166,
275,
283,
8644,
22399,
435,
291,
14,
697,
14,
751,
435,
10871,
435,
971,
288,
291,
14,
697,
14,
2060,
435,
22143,
435,
291,
14,
697,
14,
1102,
435,
7324,
267,
4177,
275,
291,
14,
697,
14,
4659,
267,
4177,
63,
344,
275,
291,
14,
697,
14,
9281,
5080,
63,
697,
398,
327,
2372,
1343,
602,
12,
1284,
323,
465,
2197,
2251,
267,
1343,
602,
275,
2197,
14,
9866,
8,
277,
14,
4273,
14,
928,
602,
12,
17648,
57,
3295,
77,
3295,
68,
9859,
267,
1284,
602,
275,
2197,
14,
9866,
8,
277,
14,
4273,
14,
500,
602,
12,
17648,
57,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
abramhindle/UnnaturalCodeFork
|
python/testdata/launchpad/lib/lp/soyuz/model/files.py
|
1
|
1945
|
# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
__all__ = [
'BinaryPackageFile',
'SourceFileMixin',
'SourcePackageReleaseFile',
]
from sqlobject import ForeignKey
from zope.interface import implements
from lp.registry.interfaces.sourcepackage import SourcePackageFileType
from lp.services.database.enumcol import EnumCol
from lp.services.database.sqlbase import SQLBase
from lp.soyuz.enums import BinaryPackageFileType
from lp.soyuz.interfaces.files import (
IBinaryPackageFile,
ISourcePackageReleaseFile,
)
class BinaryPackageFile(SQLBase):
"""See IBinaryPackageFile """
implements(IBinaryPackageFile)
_table = 'BinaryPackageFile'
binarypackagerelease = ForeignKey(dbName='binarypackagerelease',
foreignKey='BinaryPackageRelease',
notNull=True)
libraryfile = ForeignKey(dbName='libraryfile',
foreignKey='LibraryFileAlias', notNull=True)
filetype = EnumCol(dbName='filetype',
schema=BinaryPackageFileType)
class SourceFileMixin:
"""Mix-in class for common functionality between source file classes."""
@property
def is_orig(self):
return self.filetype in (
SourcePackageFileType.ORIG_TARBALL,
SourcePackageFileType.COMPONENT_ORIG_TARBALL
)
class SourcePackageReleaseFile(SourceFileMixin, SQLBase):
"""See ISourcePackageFile"""
implements(ISourcePackageReleaseFile)
sourcepackagerelease = ForeignKey(foreignKey='SourcePackageRelease',
dbName='sourcepackagerelease')
libraryfile = ForeignKey(foreignKey='LibraryFileAlias',
dbName='libraryfile')
filetype = EnumCol(schema=SourcePackageFileType)
|
agpl-3.0
|
[
3,
1898,
8937,
13,
6965,
6855,
7174,
12126,
14,
221,
961,
2032,
365,
18233,
1334,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
1015,
650,
334,
3239,
314,
570,
5113,
680,
199,
199,
363,
6577,
363,
275,
730,
199,
363,
452,
363,
275,
359,
272,
283,
6636,
8599,
1173,
297,
272,
283,
2980,
1173,
4256,
297,
272,
283,
2980,
8599,
9625,
1173,
297,
272,
1622,
199,
199,
504,
5295,
27789,
492,
12718,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
504,
13204,
14,
5189,
14,
7436,
14,
1365,
2491,
492,
5800,
8599,
20683,
199,
504,
13204,
14,
5950,
14,
4659,
14,
4869,
761,
492,
11305,
2001,
199,
504,
13204,
14,
5950,
14,
4659,
14,
3009,
1095,
492,
5385,
1563,
199,
504,
13204,
14,
1152,
89,
9494,
14,
19921,
492,
14161,
8599,
20683,
199,
504,
13204,
14,
1152,
89,
9494,
14,
7436,
14,
1725,
492,
334,
272,
473,
6636,
8599,
1173,
12,
272,
2281,
616,
8599,
9625,
1173,
12,
272,
776,
421,
199,
533,
14161,
8599,
1173,
8,
4657,
1563,
304,
272,
408,
9295,
473,
6636,
8599,
1173,
408,
272,
9031,
8,
2100,
5354,
8599,
1173,
9,
272,
485,
1224,
275,
283,
6636,
8599,
1173,
7,
339,
3366,
2491,
3221,
275,
12718,
8,
697,
985,
534,
3008,
2491,
3221,
297,
4228,
289,
2994,
534,
6636,
8599,
9625,
297,
4228,
440,
8849,
29,
549,
9,
272,
3555,
493,
275,
12718,
8,
697,
985,
534,
4342,
493,
297,
2490,
289,
2994,
534,
7424,
1173,
14149,
297,
440,
8849,
29,
549,
9,
272,
26245,
275,
11305,
2001,
8,
697,
985,
534,
30358,
297,
2432,
4177,
29,
6636,
8599,
20683,
9,
421,
199,
533,
5800,
1173,
4256,
26,
272,
408,
18854,
13,
262,
1021,
367,
2863,
9330,
3382,
1350,
570,
3992,
1041,
339,
768,
1829,
272,
347,
365,
63,
2981,
8,
277,
304,
267,
372,
291,
14,
30358,
315,
334,
288,
5800,
8599,
20683,
14,
20332,
63,
52,
8611,
1761,
12,
288,
5800,
8599,
20683,
14,
20360,
63,
20332,
63,
52,
8611,
1761,
288,
776,
421,
199,
533,
5800,
8599,
9625,
1173,
8,
2980,
1173,
4256,
12,
5385,
1563,
304,
272,
408,
9295,
2281,
616,
8599,
1173,
624,
339,
9031,
8,
1311,
616,
8599,
9625,
1173,
9,
339,
1350,
2491,
3221,
275,
12718,
8,
6846,
1197,
534,
2980,
8599,
9625,
297,
4228,
1592,
985,
534,
1365,
2491,
3221,
358,
272,
3555,
493,
275,
12718,
8,
6846,
1197,
534,
7424,
1173,
14149,
297,
2490,
1592,
985,
534,
4342,
493,
358,
272,
26245,
275,
11305,
2001,
8,
3629,
29,
2980,
8599,
20683,
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
] |
[
1898,
8937,
13,
6965,
6855,
7174,
12126,
14,
221,
961,
2032,
365,
18233,
1334,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
1015,
650,
334,
3239,
314,
570,
5113,
680,
199,
199,
363,
6577,
363,
275,
730,
199,
363,
452,
363,
275,
359,
272,
283,
6636,
8599,
1173,
297,
272,
283,
2980,
1173,
4256,
297,
272,
283,
2980,
8599,
9625,
1173,
297,
272,
1622,
199,
199,
504,
5295,
27789,
492,
12718,
199,
504,
20110,
14,
3266,
492,
9031,
199,
199,
504,
13204,
14,
5189,
14,
7436,
14,
1365,
2491,
492,
5800,
8599,
20683,
199,
504,
13204,
14,
5950,
14,
4659,
14,
4869,
761,
492,
11305,
2001,
199,
504,
13204,
14,
5950,
14,
4659,
14,
3009,
1095,
492,
5385,
1563,
199,
504,
13204,
14,
1152,
89,
9494,
14,
19921,
492,
14161,
8599,
20683,
199,
504,
13204,
14,
1152,
89,
9494,
14,
7436,
14,
1725,
492,
334,
272,
473,
6636,
8599,
1173,
12,
272,
2281,
616,
8599,
9625,
1173,
12,
272,
776,
421,
199,
533,
14161,
8599,
1173,
8,
4657,
1563,
304,
272,
408,
9295,
473,
6636,
8599,
1173,
408,
272,
9031,
8,
2100,
5354,
8599,
1173,
9,
272,
485,
1224,
275,
283,
6636,
8599,
1173,
7,
339,
3366,
2491,
3221,
275,
12718,
8,
697,
985,
534,
3008,
2491,
3221,
297,
4228,
289,
2994,
534,
6636,
8599,
9625,
297,
4228,
440,
8849,
29,
549,
9,
272,
3555,
493,
275,
12718,
8,
697,
985,
534,
4342,
493,
297,
2490,
289,
2994,
534,
7424,
1173,
14149,
297,
440,
8849,
29,
549,
9,
272,
26245,
275,
11305,
2001,
8,
697,
985,
534,
30358,
297,
2432,
4177,
29,
6636,
8599,
20683,
9,
421,
199,
533,
5800,
1173,
4256,
26,
272,
408,
18854,
13,
262,
1021,
367,
2863,
9330,
3382,
1350,
570,
3992,
1041,
339,
768,
1829,
272,
347,
365,
63,
2981,
8,
277,
304,
267,
372,
291,
14,
30358,
315,
334,
288,
5800,
8599,
20683,
14,
20332,
63,
52,
8611,
1761,
12,
288,
5800,
8599,
20683,
14,
20360,
63,
20332,
63,
52,
8611,
1761,
288,
776,
421,
199,
533,
5800,
8599,
9625,
1173,
8,
2980,
1173,
4256,
12,
5385,
1563,
304,
272,
408,
9295,
2281,
616,
8599,
1173,
624,
339,
9031,
8,
1311,
616,
8599,
9625,
1173,
9,
339,
1350,
2491,
3221,
275,
12718,
8,
6846,
1197,
534,
2980,
8599,
9625,
297,
4228,
1592,
985,
534,
1365,
2491,
3221,
358,
272,
3555,
493,
275,
12718,
8,
6846,
1197,
534,
7424,
1173,
14149,
297,
2490,
1592,
985,
534,
4342,
493,
358,
272,
26245,
275,
11305,
2001,
8,
3629,
29,
2980,
8599,
20683,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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# 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 = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: lxd_container
short_description: Manage LXD Containers
version_added: "2.2"
description:
- Management of LXD containers
author: "Hiroaki Nakamura (@hnakamur)"
options:
name:
description:
- Name of a container.
required: true
architecture:
description:
- The architecture for the container (e.g. "x86_64" or "i686").
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)
required: false
config:
description:
- 'The config for the container (e.g. {"limits.cpu": "2"}).
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)'
- If the container already exists and its "config" value in metadata
obtained from
GET /1.0/containers/<name>
U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10containersname)
are different, they this module tries to apply the configurations.
- The key starts with 'volatile.' are ignored for this comparison.
- Not all config values are supported to apply the existing container.
Maybe you need to delete and recreate a container.
required: false
devices:
description:
- 'The devices for the container
(e.g. { "rootfs": { "path": "/dev/kvm", "type": "unix-char" }).
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)'
required: false
ephemeral:
description:
- Whether or not the container is ephemeral (e.g. true or false).
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)
required: false
source:
description:
- 'The source for the container
(e.g. { "type": "image",
"mode": "pull",
"server": "https://images.linuxcontainers.org",
"protocol": "lxd",
"alias": "ubuntu/xenial/amd64" }).
See U(https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1)'
required: false
state:
choices:
- started
- stopped
- restarted
- absent
- frozen
description:
- Define the state of a container.
required: false
default: started
timeout:
description:
- A timeout for changing the state of the container.
- This is also used as a timeout for waiting until IPv4 addresses
are set to the all network interfaces in the container after
starting or restarting.
required: false
default: 30
wait_for_ipv4_addresses:
description:
- If this is true, the M(lxd_container) waits until IPv4 addresses
are set to the all network interfaces in the container after
starting or restarting.
required: false
default: false
force_stop:
description:
- If this is true, the M(lxd_container) forces to stop the container
when it stops or restarts the container.
required: false
default: false
url:
description:
- The unix domain socket path or the https URL for the LXD server.
required: false
default: unix:/var/lib/lxd/unix.socket
key_file:
description:
- The client certificate key file path.
required: false
default: '"{}/.config/lxc/client.key" .format(os.environ["HOME"])'
cert_file:
description:
- The client certificate file path.
required: false
default: '"{}/.config/lxc/client.crt" .format(os.environ["HOME"])'
trust_password:
description:
- The client trusted password.
- You need to set this password on the LXD server before
running this module using the following command.
lxc config set core.trust_password <some random password>
See U(https://www.stgraber.org/2016/04/18/lxd-api-direct-interaction/)
- If trust_password is set, this module send a request for
authentication before sending any requests.
required: false
notes:
- Containers must have a unique name. If you attempt to create a container
with a name that already existed in the users namespace the module will
simply return as "unchanged".
- There are two ways to can run commands in containers, using the command
module or using the ansible lxd connection plugin bundled in Ansible >=
2.1, the later requires python to be installed in the container which can
be done with the command module.
- You can copy a file from the host to the container
with the Ansible M(copy) and M(template) module and the `lxd` connection plugin.
See the example below.
- You can copy a file in the creatd container to the localhost
with `command=lxc file pull container_name/dir/filename filename`.
See the first example below.
'''
EXAMPLES = '''
# An example for creating a Ubuntu container and install python
- hosts: localhost
connection: local
tasks:
- name: Create a started container
lxd_container:
name: mycontainer
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: lxd
alias: ubuntu/xenial/amd64
profiles: ["default"]
wait_for_ipv4_addresses: true
timeout: 600
- name: check python is installed in container
delegate_to: mycontainer
raw: dpkg -s python
register: python_install_check
failed_when: python_install_check.rc not in [0, 1]
changed_when: false
- name: install python in container
delegate_to: mycontainer
raw: apt-get install -y python
when: python_install_check.rc == 1
# An example for deleting a container
- hosts: localhost
connection: local
tasks:
- name: Delete a container
lxd_container:
name: mycontainer
state: absent
# An example for restarting a container
- hosts: localhost
connection: local
tasks:
- name: Restart a container
lxd_container:
name: mycontainer
state: restarted
# An example for restarting a container using https to connect to the LXD server
- hosts: localhost
connection: local
tasks:
- name: Restart a container
lxd_container:
url: https://127.0.0.1:8443
# These cert_file and key_file values are equal to the default values.
#cert_file: "{{ lookup('env', 'HOME') }}/.config/lxc/client.crt"
#key_file: "{{ lookup('env', 'HOME') }}/.config/lxc/client.key"
trust_password: mypassword
name: mycontainer
state: restarted
# Note your container must be in the inventory for the below example.
#
# [containers]
# mycontainer ansible_connection=lxd
#
- hosts:
- mycontainer
tasks:
- name: copy /etc/hosts in the created container to localhost with name "mycontainer-hosts"
fetch:
src: /etc/hosts
dest: /tmp/mycontainer-hosts
flat: true
'''
RETURN='''
addresses:
description: Mapping from the network device name to a list of IPv4 addresses in the container
returned: when state is started or restarted
type: object
sample: {"eth0": ["10.155.92.191"]}
old_state:
description: The old state of the container
returned: when state is started or restarted
type: string
sample: "stopped"
logs:
description: The logs of requests and responses.
returned: when ansible-playbook is invoked with -vvvv.
type: list
sample: "(too long to be placed here)"
actions:
description: List of actions performed for the container.
returned: success
type: list
sample: '["create", "start"]'
'''
import os
from ansible.module_utils.lxd import LXDClient, LXDClientException
# LXD_ANSIBLE_STATES is a map of states that contain values of methods used
# when a particular state is evoked.
LXD_ANSIBLE_STATES = {
'started': '_started',
'stopped': '_stopped',
'restarted': '_restarted',
'absent': '_destroyed',
'frozen': '_frozen'
}
# ANSIBLE_LXD_STATES is a map of states of lxd containers to the Ansible
# lxc_container module state parameter value.
ANSIBLE_LXD_STATES = {
'Running': 'started',
'Stopped': 'stopped',
'Frozen': 'frozen',
}
# CONFIG_PARAMS is a list of config attribute names.
CONFIG_PARAMS = [
'architecture', 'config', 'devices', 'ephemeral', 'profiles', 'source'
]
try:
callable(all)
except NameError:
# For python <2.5
# This definition is copied from https://docs.python.org/2/library/functions.html#all
def all(iterable):
for element in iterable:
if not element:
return False
return True
class LXDContainerManagement(object):
def __init__(self, module):
"""Management of LXC containers via Ansible.
:param module: Processed Ansible Module.
:type module: ``object``
"""
self.module = module
self.name = self.module.params['name']
self._build_config()
self.state = self.module.params['state']
self.timeout = self.module.params['timeout']
self.wait_for_ipv4_addresses = self.module.params['wait_for_ipv4_addresses']
self.force_stop = self.module.params['force_stop']
self.addresses = None
self.url = self.module.params['url']
self.key_file = self.module.params.get('key_file', None)
self.cert_file = self.module.params.get('cert_file', None)
self.debug = self.module._verbosity >= 4
try:
self.client = LXDClient(
self.url, key_file=self.key_file, cert_file=self.cert_file,
debug=self.debug
)
except LXDClientException as e:
self.module.fail_json(msg=e.msg)
self.trust_password = self.module.params.get('trust_password', None)
self.actions = []
def _build_config(self):
self.config = {}
for attr in CONFIG_PARAMS:
param_val = self.module.params.get(attr, None)
if param_val is not None:
self.config[attr] = param_val
def _get_container_json(self):
return self.client.do(
'GET', '/1.0/containers/{0}'.format(self.name),
ok_error_codes=[404]
)
def _get_container_state_json(self):
return self.client.do(
'GET', '/1.0/containers/{0}/state'.format(self.name),
ok_error_codes=[404]
)
@staticmethod
def _container_json_to_module_state(resp_json):
if resp_json['type'] == 'error':
return 'absent'
return ANSIBLE_LXD_STATES[resp_json['metadata']['status']]
def _change_state(self, action, force_stop=False):
body_json={'action': action, 'timeout': self.timeout}
if force_stop:
body_json['force'] = True
return self.client.do('PUT', '/1.0/containers/{0}/state'.format(self.name), body_json=body_json)
def _create_container(self):
config = self.config.copy()
config['name'] = self.name
self.client.do('POST', '/1.0/containers', config)
self.actions.append('create')
def _start_container(self):
self._change_state('start')
self.actions.append('start')
def _stop_container(self):
self._change_state('stop', self.force_stop)
self.actions.append('stop')
def _restart_container(self):
self._change_state('restart', self.force_stop)
self.actions.append('restart')
def _delete_container(self):
self.client.do('DELETE', '/1.0/containers/{0}'.format(self.name))
self.actions.append('delete')
def _freeze_container(self):
self._change_state('freeze')
self.actions.append('freeze')
def _unfreeze_container(self):
self._change_state('unfreeze')
self.actions.append('unfreez')
def _container_ipv4_addresses(self, ignore_devices=['lo']):
resp_json = self._get_container_state_json()
network = resp_json['metadata']['network'] or {}
network = dict((k, v) for k, v in network.items() if k not in ignore_devices) or {}
addresses = dict((k, [a['address'] for a in v['addresses'] if a['family'] == 'inet']) for k, v in network.items()) or {}
return addresses
@staticmethod
def _has_all_ipv4_addresses(addresses):
return len(addresses) > 0 and all([len(v) > 0 for v in addresses.values()])
def _get_addresses(self):
try:
due = datetime.datetime.now() + datetime.timedelta(seconds=self.timeout)
while datetime.datetime.now() < due:
time.sleep(1)
addresses = self._container_ipv4_addresses()
if self._has_all_ipv4_addresses(addresses):
self.addresses = addresses
return
except LXDClientException as e:
e.msg = 'timeout for getting IPv4 addresses'
raise
def _started(self):
if self.old_state == 'absent':
self._create_container()
self._start_container()
else:
if self.old_state == 'frozen':
self._unfreeze_container()
elif self.old_state == 'stopped':
self._start_container()
if self._needs_to_apply_container_configs():
self._apply_container_configs()
if self.wait_for_ipv4_addresses:
self._get_addresses()
def _stopped(self):
if self.old_state == 'absent':
self._create_container()
else:
if self.old_state == 'stopped':
if self._needs_to_apply_container_configs():
self._start_container()
self._apply_container_configs()
self._stop_container()
else:
if self.old_state == 'frozen':
self._unfreeze_container()
if self._needs_to_apply_container_configs():
self._apply_container_configs()
self._stop_container()
def _restarted(self):
if self.old_state == 'absent':
self._create_container()
self._start_container()
else:
if self.old_state == 'frozen':
self._unfreeze_container()
if self._needs_to_apply_container_configs():
self._apply_container_configs()
self._restart_container()
if self.wait_for_ipv4_addresses:
self._get_addresses()
def _destroyed(self):
if self.old_state != 'absent':
if self.old_state == 'frozen':
self._unfreeze_container()
if self.old_state != 'stopped':
self._stop_container()
self._delete_container()
def _frozen(self):
if self.old_state == 'absent':
self._create_container()
self._start_container()
self._freeze_container()
else:
if self.old_state == 'stopped':
self._start_container()
if self._needs_to_apply_container_configs():
self._apply_container_configs()
self._freeze_container()
def _needs_to_change_container_config(self, key):
if key not in self.config:
return False
if key == 'config':
old_configs = dict((k, v) for k, v in self.old_container_json['metadata'][key].items() if not k.startswith('volatile.'))
else:
old_configs = self.old_container_json['metadata'][key]
return self.config[key] != old_configs
def _needs_to_apply_container_configs(self):
return (
self._needs_to_change_container_config('architecture') or
self._needs_to_change_container_config('config') or
self._needs_to_change_container_config('ephemeral') or
self._needs_to_change_container_config('devices') or
self._needs_to_change_container_config('profiles')
)
def _apply_container_configs(self):
old_metadata = self.old_container_json['metadata']
body_json = {
'architecture': old_metadata['architecture'],
'config': old_metadata['config'],
'devices': old_metadata['devices'],
'profiles': old_metadata['profiles']
}
if self._needs_to_change_container_config('architecture'):
body_json['architecture'] = self.config['architecture']
if self._needs_to_change_container_config('config'):
for k, v in self.config['config'].items():
body_json['config'][k] = v
if self._needs_to_change_container_config('ephemeral'):
body_json['ephemeral'] = self.config['ephemeral']
if self._needs_to_change_container_config('devices'):
body_json['devices'] = self.config['devices']
if self._needs_to_change_container_config('profiles'):
body_json['profiles'] = self.config['profiles']
self.client.do('PUT', '/1.0/containers/{0}'.format(self.name), body_json=body_json)
self.actions.append('apply_container_configs')
def run(self):
"""Run the main method."""
try:
if self.trust_password is not None:
self.client.authenticate(self.trust_password)
self.old_container_json = self._get_container_json()
self.old_state = self._container_json_to_module_state(self.old_container_json)
action = getattr(self, LXD_ANSIBLE_STATES[self.state])
action()
state_changed = len(self.actions) > 0
result_json = {
'log_verbosity': self.module._verbosity,
'changed': state_changed,
'old_state': self.old_state,
'actions': self.actions
}
if self.client.debug:
result_json['logs'] = self.client.logs
if self.addresses is not None:
result_json['addresses'] = self.addresses
self.module.exit_json(**result_json)
except LXDClientException as e:
state_changed = len(self.actions) > 0
fail_params = {
'msg': e.msg,
'changed': state_changed,
'actions': self.actions
}
if self.client.debug:
fail_params['logs'] = e.kwargs['logs']
self.module.fail_json(**fail_params)
def main():
"""Ansible Main module."""
module = AnsibleModule(
argument_spec=dict(
name=dict(
type='str',
required=True
),
architecture=dict(
type='str',
),
config=dict(
type='dict',
),
description=dict(
type='str',
),
devices=dict(
type='dict',
),
ephemeral=dict(
type='bool',
),
profiles=dict(
type='list',
),
source=dict(
type='dict',
),
state=dict(
choices=LXD_ANSIBLE_STATES.keys(),
default='started'
),
timeout=dict(
type='int',
default=30
),
wait_for_ipv4_addresses=dict(
type='bool',
default=False
),
force_stop=dict(
type='bool',
default=False
),
url=dict(
type='str',
default='unix:/var/lib/lxd/unix.socket'
),
key_file=dict(
type='str',
default='{}/.config/lxc/client.key'.format(os.environ['HOME'])
),
cert_file=dict(
type='str',
default='{}/.config/lxc/client.crt'.format(os.environ['HOME'])
),
trust_password=dict(
type='str',
)
),
supports_check_mode=False,
)
lxd_manage = LXDContainerManagement(module=module)
lxd_manage.run()
# import module bits
from ansible.module_utils.basic import *
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,
7800,
12,
869,
14352,
27387,
653,
1151,
455,
12417,
665,
6164,
1151,
455,
300,
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,
421,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
634,
2207,
63,
3600,
199,
3612,
63,
1802,
26,
14944,
491,
18184,
1448,
877,
1192,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1802,
26,
523,
446,
8259,
402,
491,
18184,
15333,
199,
2502,
26,
298,
40,
14352,
27387,
653,
1151,
455,
12417,
8593,
6164,
1151,
455,
300,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
881,
446,
2812,
402,
282,
3970,
14,
267,
1415,
26,
2549,
272,
15931,
26,
267,
1369,
26,
881,
446,
710,
15931,
367,
314,
3970,
334,
69,
14,
71,
14,
298,
88,
1184,
63,
772,
2,
503,
298,
73,
10253,
3471,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
9,
267,
1415,
26,
3055,
272,
1101,
26,
267,
1369,
26,
881,
446,
283,
1918,
1101,
367,
314,
3970,
334,
69,
14,
71,
14,
2420,
9368,
14,
3541,
582,
298,
18,
3570,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
881,
446,
982,
314,
3970,
2575,
3495,
436,
2399,
298,
888,
2,
574,
315,
3341,
288,
15884,
687,
288,
9576,
1182,
17,
14,
16,
15,
13577,
8316,
354,
30,
288,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
709,
13577,
354,
9,
288,
787,
3365,
12,
2985,
642,
859,
11275,
370,
4838,
314,
13422,
14,
881,
446,
710,
790,
9174,
543,
283,
32059,
3530,
787,
5525,
367,
642,
9132,
14,
881,
446,
2832,
1006,
1101,
1338,
787,
3748,
370,
4838,
314,
3411,
3970,
14,
288,
23038,
1265,
1929,
370,
3145,
436,
23959,
282,
3970,
14,
267,
1415,
26,
3055,
272,
7256,
26,
267,
1369,
26,
881,
446,
283,
1918,
7256,
367,
314,
3970,
288,
334,
69,
14,
71,
14,
469,
298,
1231,
2319,
582,
469,
298,
515,
582,
3286,
2374,
15,
29272,
401,
298,
466,
582,
298,
11864,
13,
1560,
2,
789,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
267,
1415,
26,
3055,
272,
26288,
26,
267,
1369,
26,
881,
446,
7480,
503,
440,
314,
3970,
365,
26288,
334,
69,
14,
71,
14,
2549,
503,
3055,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
9,
267,
1415,
26,
3055,
272,
1350,
26,
267,
1369,
26,
881,
446,
283,
1918,
1350,
367,
314,
3970,
288,
334,
69,
14,
71,
14,
469,
298,
466,
582,
298,
1569,
401,
490,
298,
632,
582,
298,
9302,
401,
490,
298,
1000,
582,
298,
2859,
921,
4782,
14,
5135,
13577,
14,
1308,
401,
490,
298,
3922,
582,
298,
76,
2207,
401,
490,
298,
3620,
582,
298,
21151,
15,
13615,
2380,
15,
21778,
772,
2,
789,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
267,
1415,
26,
3055,
272,
1174,
26,
267,
3415,
26,
881,
446,
8239,
881,
446,
15248,
881,
446,
32277,
881,
446,
9552,
881,
446,
8101,
267,
1369,
26,
881,
446,
13930,
314,
1174,
402,
282,
3970,
14,
267,
1415,
26,
3055,
267,
849,
26,
8239,
272,
2653,
26,
267,
1369,
26,
881,
446,
437,
2653,
367,
13729,
314,
1174,
402,
314,
3970,
14,
881,
446,
961,
365,
2597,
1202,
465,
282,
2653,
367,
10923,
5133,
6509,
20,
7149,
288,
787,
663,
370,
314,
1006,
2784,
8386,
315,
314,
3970,
2410,
288,
6617,
503,
11004,
316,
14,
267,
1415,
26,
3055,
267,
849,
26,
4233,
272,
3618,
63,
509,
63,
4774,
20,
63,
7423,
26,
267,
1369,
26,
881,
446,
982,
642,
365,
2549,
12,
314,
603,
8,
76,
2207,
63,
3600,
9,
14442,
1405,
5133,
6509,
20,
7149,
288,
787,
663,
370,
314,
1006,
2784,
8386,
315,
314,
3970,
2410,
288,
6617,
503,
11004,
316,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
272,
3542,
63,
2379,
26,
267,
1369,
26,
881,
446,
982,
642,
365,
2549,
12,
314,
603,
8,
76,
2207,
63,
3600,
9,
25983,
370,
3631,
314,
3970,
288,
1380,
652,
20922,
503,
11004,
83,
314,
3970,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
272,
1166,
26,
267,
1369,
26,
881,
446,
710,
16572,
2881,
2838,
931,
503,
314,
4178,
2851,
367,
314,
491,
18184,
1654,
14,
267,
1415
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
869,
14352,
27387,
653,
1151,
455,
12417,
665,
6164,
1151,
455,
300,
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,
421,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
634,
2207,
63,
3600,
199,
3612,
63,
1802,
26,
14944,
491,
18184,
1448,
877,
1192,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1802,
26,
523,
446,
8259,
402,
491,
18184,
15333,
199,
2502,
26,
298,
40,
14352,
27387,
653,
1151,
455,
12417,
8593,
6164,
1151,
455,
300,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
881,
446,
2812,
402,
282,
3970,
14,
267,
1415,
26,
2549,
272,
15931,
26,
267,
1369,
26,
881,
446,
710,
15931,
367,
314,
3970,
334,
69,
14,
71,
14,
298,
88,
1184,
63,
772,
2,
503,
298,
73,
10253,
3471,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
9,
267,
1415,
26,
3055,
272,
1101,
26,
267,
1369,
26,
881,
446,
283,
1918,
1101,
367,
314,
3970,
334,
69,
14,
71,
14,
2420,
9368,
14,
3541,
582,
298,
18,
3570,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
881,
446,
982,
314,
3970,
2575,
3495,
436,
2399,
298,
888,
2,
574,
315,
3341,
288,
15884,
687,
288,
9576,
1182,
17,
14,
16,
15,
13577,
8316,
354,
30,
288,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
709,
13577,
354,
9,
288,
787,
3365,
12,
2985,
642,
859,
11275,
370,
4838,
314,
13422,
14,
881,
446,
710,
790,
9174,
543,
283,
32059,
3530,
787,
5525,
367,
642,
9132,
14,
881,
446,
2832,
1006,
1101,
1338,
787,
3748,
370,
4838,
314,
3411,
3970,
14,
288,
23038,
1265,
1929,
370,
3145,
436,
23959,
282,
3970,
14,
267,
1415,
26,
3055,
272,
7256,
26,
267,
1369,
26,
881,
446,
283,
1918,
7256,
367,
314,
3970,
288,
334,
69,
14,
71,
14,
469,
298,
1231,
2319,
582,
469,
298,
515,
582,
3286,
2374,
15,
29272,
401,
298,
466,
582,
298,
11864,
13,
1560,
2,
789,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
267,
1415,
26,
3055,
272,
26288,
26,
267,
1369,
26,
881,
446,
7480,
503,
440,
314,
3970,
365,
26288,
334,
69,
14,
71,
14,
2549,
503,
3055,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
9,
267,
1415,
26,
3055,
272,
1350,
26,
267,
1369,
26,
881,
446,
283,
1918,
1350,
367,
314,
3970,
288,
334,
69,
14,
71,
14,
469,
298,
466,
582,
298,
1569,
401,
490,
298,
632,
582,
298,
9302,
401,
490,
298,
1000,
582,
298,
2859,
921,
4782,
14,
5135,
13577,
14,
1308,
401,
490,
298,
3922,
582,
298,
76,
2207,
401,
490,
298,
3620,
582,
298,
21151,
15,
13615,
2380,
15,
21778,
772,
2,
789,
680,
288,
1666,
738,
8,
2859,
921,
5031,
14,
957,
15,
29357,
15,
76,
2207,
15,
6582,
15,
4133,
15,
1301,
15,
3911,
13,
1246,
14,
1064,
3,
1932,
13,
17,
3171,
267,
1415,
26,
3055,
272,
1174,
26,
267,
3415,
26,
881,
446,
8239,
881,
446,
15248,
881,
446,
32277,
881,
446,
9552,
881,
446,
8101,
267,
1369,
26,
881,
446,
13930,
314,
1174,
402,
282,
3970,
14,
267,
1415,
26,
3055,
267,
849,
26,
8239,
272,
2653,
26,
267,
1369,
26,
881,
446,
437,
2653,
367,
13729,
314,
1174,
402,
314,
3970,
14,
881,
446,
961,
365,
2597,
1202,
465,
282,
2653,
367,
10923,
5133,
6509,
20,
7149,
288,
787,
663,
370,
314,
1006,
2784,
8386,
315,
314,
3970,
2410,
288,
6617,
503,
11004,
316,
14,
267,
1415,
26,
3055,
267,
849,
26,
4233,
272,
3618,
63,
509,
63,
4774,
20,
63,
7423,
26,
267,
1369,
26,
881,
446,
982,
642,
365,
2549,
12,
314,
603,
8,
76,
2207,
63,
3600,
9,
14442,
1405,
5133,
6509,
20,
7149,
288,
787,
663,
370,
314,
1006,
2784,
8386,
315,
314,
3970,
2410,
288,
6617,
503,
11004,
316,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
272,
3542,
63,
2379,
26,
267,
1369,
26,
881,
446,
982,
642,
365,
2549,
12,
314,
603,
8,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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
] |
alphafoobar/intellij-community
|
python/testData/MockSdk3.4/python_stubs/sys.py
|
100
|
17611
|
# encoding: utf-8
# module sys
# from (built-in)
# by generator 1.135
"""
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.
Dynamic objects:
argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules
displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
To customize printing in an interactive session or to install a custom
top-level exception handler, assign other functions to replace these.
stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
By assigning other file objects (or objects that behave like files)
to these, it is possible to redirect all of the interpreter's I/O.
last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
These three are only available in an interactive session after a
traceback has been printed.
Static objects:
builtin_module_names -- tuple of module names built into this interpreter
copyright -- copyright notice pertaining to this interpreter
exec_prefix -- prefix used to find the machine-specific Python library
executable -- absolute path of the executable binary of the Python interpreter
float_info -- a struct sequence with information about the float implementation.
float_repr_style -- string indicating the style of repr() output for floats
hash_info -- a struct sequence with information about the hash algorithm.
hexversion -- version information encoded as a single integer
implementation -- Python implementation information.
int_info -- a struct sequence with information about the int implementation.
maxsize -- the largest supported length of containers.
maxunicode -- the value of the largest Unicode codepoint
platform -- platform identifier
prefix -- prefix used to find the Python library
thread_info -- a struct sequence with information about the thread implementation.
version -- the version of this interpreter as a string
version_info -- version information as a named tuple
dllhandle -- [Windows only] integer handle of the Python DLL
winver -- [Windows only] version number of the Python DLL
__stdin__ -- the original stdin; don't touch!
__stdout__ -- the original stdout; don't touch!
__stderr__ -- the original stderr; don't touch!
__displayhook__ -- the original displayhook; don't touch!
__excepthook__ -- the original excepthook; don't touch!
Functions:
displayhook() -- print an object to the screen, and save it in builtins._
excepthook() -- print an exception and its traceback to sys.stderr
exc_info() -- return thread-safe information about the current exception
exit() -- exit the interpreter by raising SystemExit
getdlopenflags() -- returns flags to be used for dlopen() calls
getprofile() -- get the global profiling function
getrefcount() -- return the reference count for an object (plus one :-)
getrecursionlimit() -- return the max recursion depth for the interpreter
getsizeof() -- return the size of an object in bytes
gettrace() -- get the global debug tracing function
setcheckinterval() -- control how often the interpreter checks for events
setdlopenflags() -- set the flags to be used for dlopen() calls
setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function
"""
# no imports
# Variables with simple values
api_version = 1013
base_exec_prefix = 'C:\\Python34'
base_prefix = 'C:\\Python34'
byteorder = 'little'
copyright = 'Copyright (c) 2001-2014 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.'
dllhandle = 1705771008
dont_write_bytecode = False
executable = 'C:\\Python34\\python.exe'
exec_prefix = 'C:\\Python34'
float_repr_style = 'short'
hexversion = 50594288
maxsize = 2147483647
maxunicode = 1114111
platform = 'win32'
prefix = 'C:\\Python34'
version = '3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)]'
winver = '3.4'
_home = None
__egginsert = 1
__plen = 5
# functions
def callstats(): # real signature unknown; restored from __doc__
"""
callstats() -> tuple of integers
Return a tuple of function call statistics, if CALL_PROFILE was defined
when Python was built. Otherwise, return None.
When enabled, this function returns detailed, implementation-specific
details about the number of function calls executed. The return value is
a 11-tuple where the entries in the tuple are counts of:
0. all function calls
1. calls to PyFunction_Type objects
2. PyFunction calls that do not create an argument tuple
3. PyFunction calls that do not create an argument tuple
and bypass PyEval_EvalCodeEx()
4. PyMethod calls
5. PyMethod calls on bound methods
6. PyType calls
7. PyCFunction calls
8. generator calls
9. All other calls
10. Number of stack pops performed by call_function()
"""
return ()
def call_tracing(func, args): # real signature unknown; restored from __doc__
"""
call_tracing(func, args) -> object
Call func(*args), while tracing is enabled. The tracing state is
saved, and restored afterwards. This is intended to be called from
a debugger from a checkpoint, to recursively debug some other code.
"""
return object()
def displayhook(p_object): # real signature unknown; restored from __doc__
"""
displayhook(object) -> None
Print an object to sys.stdout and also save it in builtins._
"""
pass
def excepthook(exctype, value, traceback): # real signature unknown; restored from __doc__
"""
excepthook(exctype, value, traceback) -> None
Handle an exception by displaying it with a traceback on sys.stderr.
"""
pass
def exc_info(): # real signature unknown; restored from __doc__
"""
exc_info() -> (type, value, traceback)
Return information about the most recent exception caught by an except
clause in the current stack frame or in an older stack frame.
"""
pass
def exit(status=None): # real signature unknown; restored from __doc__
"""
exit([status])
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is an integer, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
"""
pass
def getallocatedblocks(): # real signature unknown; restored from __doc__
"""
getallocatedblocks() -> integer
Return the number of memory blocks currently allocated, regardless of their
size.
"""
return 0
def getcheckinterval(): # real signature unknown; restored from __doc__
""" getcheckinterval() -> current check interval; see setcheckinterval(). """
pass
def getdefaultencoding(): # real signature unknown; restored from __doc__
"""
getdefaultencoding() -> string
Return the current default string encoding used by the Unicode
implementation.
"""
return ""
def getfilesystemencoding(): # real signature unknown; restored from __doc__
"""
getfilesystemencoding() -> string
Return the encoding used to convert Unicode filenames in
operating system filenames.
"""
return ""
def getprofile(): # real signature unknown; restored from __doc__
"""
getprofile()
Return the profiling function set with sys.setprofile.
See the profiler chapter in the library manual.
"""
pass
def getrecursionlimit(): # real signature unknown; restored from __doc__
"""
getrecursionlimit()
Return the current value of the recursion limit, the maximum depth
of the Python interpreter stack. This limit prevents infinite
recursion from causing an overflow of the C stack and crashing Python.
"""
pass
def getrefcount(p_object): # real signature unknown; restored from __doc__
"""
getrefcount(object) -> integer
Return the reference count of object. The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().
"""
return 0
def getsizeof(p_object, default): # real signature unknown; restored from __doc__
"""
getsizeof(object, default) -> int
Return the size of object in bytes.
"""
return 0
def getswitchinterval(): # real signature unknown; restored from __doc__
""" getswitchinterval() -> current thread switch interval; see setswitchinterval(). """
pass
def gettrace(): # real signature unknown; restored from __doc__
"""
gettrace()
Return the global debug tracing function set with sys.settrace.
See the debugger chapter in the library manual.
"""
pass
def getwindowsversion(): # real signature unknown; restored from __doc__
"""
getwindowsversion()
Return information about the running version of Windows as a named tuple.
The members are named: major, minor, build, platform, service_pack,
service_pack_major, service_pack_minor, suite_mask, and product_type. For
backward compatibility, only the first 5 items are available by indexing.
All elements are numbers, except service_pack which is a string. Platform
may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,
3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain
controller, 3 for a server.
"""
pass
def intern(string): # real signature unknown; restored from __doc__
"""
intern(string) -> string
``Intern'' the given string. This enters the string in the (global)
table of interned strings whose purpose is to speed up dictionary lookups.
Return the string itself or the previously interned string object with the
same value.
"""
return ""
def setcheckinterval(n): # real signature unknown; restored from __doc__
"""
setcheckinterval(n)
Tell the Python interpreter to check for asynchronous events every
n instructions. This also affects how often thread switches occur.
"""
pass
def setprofile(function): # real signature unknown; restored from __doc__
"""
setprofile(function)
Set the profiling function. It will be called on each function call
and return. See the profiler chapter in the library manual.
"""
pass
def setrecursionlimit(n): # real signature unknown; restored from __doc__
"""
setrecursionlimit(n)
Set the maximum depth of the Python interpreter stack to n. This
limit prevents infinite recursion from causing an overflow of the C
stack and crashing Python. The highest possible limit is platform-
dependent.
"""
pass
def setswitchinterval(n): # real signature unknown; restored from __doc__
"""
setswitchinterval(n)
Set the ideal thread switching delay inside the Python interpreter
The actual frequency of switching threads can be lower if the
interpreter executes long sequences of uninterruptible code
(this is implementation-specific and workload-dependent).
The parameter must represent the desired switching delay in seconds
A typical value is 0.005 (5 milliseconds).
"""
pass
def settrace(function): # real signature unknown; restored from __doc__
"""
settrace(function)
Set the global debug tracing function. It will be called on each
function call. See the debugger chapter in the library manual.
"""
pass
def _clear_type_cache(): # real signature unknown; restored from __doc__
"""
_clear_type_cache() -> None
Clear the internal type lookup cache.
"""
pass
def _current_frames(): # real signature unknown; restored from __doc__
"""
_current_frames() -> dictionary
Return a dictionary mapping each current thread T's thread id to T's
current stack frame.
This function should be used for specialized purposes only.
"""
return {}
def _debugmallocstats(): # real signature unknown; restored from __doc__
"""
_debugmallocstats()
Print summary info to stderr about the state of
pymalloc's structures.
In Py_DEBUG mode, also perform some expensive internal consistency
checks.
"""
pass
def _getframe(depth=None): # real signature unknown; restored from __doc__
"""
_getframe([depth]) -> frameobject
Return a frame object from the call stack. If optional integer depth is
given, return the frame object that many calls below the top of the stack.
If that is deeper than the call stack, ValueError is raised. The default
for depth is zero, returning the frame at the top of the call stack.
This function should be used for internal and specialized
purposes only.
"""
pass
def __displayhook__(*args, **kwargs): # real signature unknown
"""
displayhook(object) -> None
Print an object to sys.stdout and also save it in builtins._
"""
pass
def __excepthook__(*args, **kwargs): # real signature unknown
"""
excepthook(exctype, value, traceback) -> None
Handle an exception by displaying it with a traceback on sys.stderr.
"""
pass
def __interactivehook__(): # reliably restored by inspect
# no doc
pass
# classes
from .object import object
class __loader__(object):
"""
Meta path import for built-in modules.
All methods are either class or static methods to avoid the need to
instantiate the class.
"""
@classmethod
def find_module(cls, *args, **kwargs): # real signature unknown
"""
Find the built-in module.
If 'path' is ever specified then the search is considered a failure.
This method is deprecated. Use find_spec() instead.
"""
pass
@classmethod
def find_spec(cls, *args, **kwargs): # real signature unknown
pass
@classmethod
def get_code(cls, *args, **kwargs): # real signature unknown
""" Return None as built-in modules do not have code objects. """
pass
@classmethod
def get_source(cls, *args, **kwargs): # real signature unknown
""" Return None as built-in modules do not have source code. """
pass
@classmethod
def is_package(cls, *args, **kwargs): # real signature unknown
""" Return False as built-in modules are never packages. """
pass
@classmethod
def load_module(cls, *args, **kwargs): # real signature unknown
""" Load a built-in module. """
pass
def module_repr(module): # reliably restored by inspect
"""
Return repr for the module.
The method is deprecated. The import machinery does the job itself.
"""
pass
def __init__(self, *args, **kwargs): # real signature unknown
pass
__weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""list of weak references to the object (if defined)"""
__dict__ = None # (!) real value is ''
# variables with complex values
argv = [] # real value of type <class 'list'> skipped
builtin_module_names = () # real value of type <class 'tuple'> skipped
flags = (
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
)
float_info = (
1.7976931348623157e+308,
1024,
308,
2.2250738585072014e-308,
-1021,
-307,
15,
53,
2.220446049250313e-16,
2,
1,
)
hash_info = (
32,
2147483647,
314159,
0,
1000003,
'siphash24',
64,
128,
0,
)
implementation = None # (!) real value is ''
int_info = (
15,
2,
)
meta_path = [
__loader__,
None, # (!) real value is ''
None, # (!) real value is ''
None, # (!) real value is ''
]
modules = {} # real value of type <class 'dict'> skipped
path = [
'C:\\work\\ultimate\\out\\classes\\production\\python-helpers',
'C:\\Python34\\lib\\site-packages\\setuptools-4.0.1-py3.4.egg',
'C:\\Windows\\system32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34',
'C:\\Python34\\lib\\site-packages',
]
path_hooks = [
None, # (!) real value is ''
None, # (!) real value is ''
]
path_importer_cache = {} # real value of type <class 'dict'> skipped
stderr = None # (!) real value is ''
stdin = None # (!) real value is ''
stdout = None # (!) real value is ''
thread_info = (
'nt',
None,
None,
)
version_info = (
3,
4,
1,
'final',
0,
)
warnoptions = []
_mercurial = (
'CPython',
'v3.4.1',
'c0e311e010fc',
)
_xoptions = {}
__spec__ = None # (!) real value is ''
__stderr__ = stderr
__stdin__ = stdin
__stdout__ = stdout
# intermittent names
exc_value = Exception()
exc_traceback=None
|
apache-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
3,
859,
984,
199,
3,
687,
334,
11730,
13,
262,
9,
199,
3,
701,
4306,
413,
14,
8312,
199,
624,
199,
2765,
859,
6571,
2879,
370,
2005,
2251,
1202,
503,
26391,
701,
314,
199,
20244,
436,
370,
3423,
626,
17232,
30390,
543,
314,
12693,
14,
199,
199,
14451,
2251,
26,
199,
199,
3020,
1553,
1414,
1004,
2368,
27,
9238,
59,
16,
61,
365,
314,
2884,
11776,
340,
6040,
199,
515,
1553,
859,
2754,
931,
27,
931,
59,
16,
61,
365,
314,
2884,
2082,
12,
587,
2125,
199,
3112,
1553,
2600,
402,
6511,
4621,
199,
199,
2918,
3664,
1553,
2797,
370,
2498,
2058,
315,
376,
12777,
2351,
199,
476,
301,
13316,
6992,
1553,
2797,
370,
2429,
1263,
625,
24872,
1919,
1163,
2419,
14838,
523,
4005,
17551,
16116,
315,
376,
12777,
2351,
503,
370,
3907,
282,
3537,
523,
2746,
13,
1896,
1919,
3016,
12,
5090,
1163,
3423,
370,
3350,
3520,
14,
199,
199,
6626,
1553,
4465,
1324,
570,
909,
27,
1202,
701,
1324,
342,
199,
2703,
1553,
4465,
1072,
570,
909,
27,
1202,
701,
870,
342,
199,
3083,
1553,
4465,
1125,
909,
27,
1202,
367,
1125,
3788,
523,
4885,
26694,
1163,
570,
2251,
334,
269,
2251,
626,
24062,
2839,
1584,
9,
523,
370,
3520,
12,
652,
365,
3962,
370,
4660,
1006,
402,
314,
12693,
1159,
473,
15,
47,
14,
199,
199,
2019,
63,
466,
1553,
730,
402,
2061,
625,
24872,
1919,
199,
2019,
63,
585,
1553,
574,
402,
2061,
625,
24872,
1919,
199,
2019,
63,
6894,
1553,
5190,
402,
2061,
625,
24872,
1919,
523,
5723,
7795,
787,
1454,
2808,
315,
376,
12777,
2351,
2410,
282,
523,
5190,
965,
2757,
12487,
14,
199,
199,
9278,
2251,
26,
199,
199,
5351,
63,
578,
63,
1247,
1553,
2008,
402,
859,
1561,
6137,
1901,
642,
12693,
199,
7307,
1553,
4248,
4245,
1126,
24522,
370,
642,
12693,
199,
1628,
63,
1861,
1553,
2403,
1202,
370,
2342,
314,
6844,
13,
6100,
2018,
3555,
199,
5904,
1553,
3679,
931,
402,
314,
7286,
3366,
402,
314,
2018,
12693,
199,
1609,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2069,
4514,
14,
199,
1609,
63,
2722,
63,
2487,
1553,
1059,
9297,
314,
3449,
402,
4700,
342,
1072,
367,
15657,
199,
2227,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2631,
5563,
14,
199,
4097,
1023,
1553,
1015,
2556,
5737,
465,
282,
2849,
3000,
199,
12236,
1553,
2018,
4514,
2556,
14,
199,
442,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
1109,
4514,
14,
199,
13634,
1553,
314,
17451,
3748,
2582,
402,
15333,
14,
199,
988,
2975,
1553,
314,
574,
402,
314,
17451,
6140,
1233,
1403,
199,
3246,
1553,
4298,
5148,
199,
1861,
1553,
2403,
1202,
370,
2342,
314,
2018,
3555,
199,
2671,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2462,
4514,
14,
199,
1023,
1553,
314,
1015,
402,
642,
12693,
465,
282,
1059,
199,
1023,
63,
815,
1553,
1015,
2556,
465,
282,
4310,
2008,
199,
9259,
2479,
1553,
359,
8647,
1454,
61,
3000,
2429,
402,
314,
2018,
577,
4464,
199,
2676,
422,
1553,
359,
8647,
1454,
61,
1015,
1329,
402,
314,
2018,
577,
4464,
199,
363,
6626,
363,
1553,
314,
3379,
9009,
27,
2793,
1133,
12943,
1,
199,
363,
2703,
363,
1553,
314,
3379,
3839,
27,
2793,
1133,
12943,
1,
199,
363,
3083,
363,
1553,
314,
3379,
4635,
27,
2793,
1133,
12943,
1,
199,
363,
2918,
3664,
363,
1553,
314,
3379,
2929,
3664,
27,
2793,
1133,
12943,
1,
199,
363,
476,
301,
13316,
6992,
363,
1553,
314,
3379,
11553,
13316,
6992,
27,
2793,
1133,
12943,
1,
199,
199,
13967,
26,
199,
199,
2918,
3664,
342,
1553,
870,
376,
909,
370,
314,
6426,
12,
436,
3354,
652,
315,
12963,
423,
199,
476,
301,
13316,
6992,
342,
1553,
870,
376,
1919,
436,
2399,
5190,
370,
984,
14,
3083,
199,
2804,
63,
815,
342,
1553,
372,
2462,
13,
3489,
2556,
3595,
314,
1453,
1919,
199,
2224,
342,
1553,
4458,
314,
12693,
701,
17026,
14838,
199,
362,
68,
8329,
2469,
342,
1553,
2529,
3285,
370,
506,
1202,
367,
366,
8329,
342,
4882,
199,
362,
2913,
342,
1553,
664,
314,
2288,
30238,
805,
199,
32371,
342,
1553,
372,
314,
3659,
2338,
367,
376,
909,
334,
6666,
1373,
22901,
9,
199,
362,
21314,
3097,
342,
1553,
372,
314,
1390,
16189,
5818,
367,
314,
12693,
199,
362,
12590,
342,
1553,
372,
314,
1568,
402,
376,
909,
315,
2783,
199,
362,
3446,
342,
1553,
664,
314,
2288,
3105,
23465,
805,
199,
409,
1074,
4284,
342,
1553,
3304,
4212,
14115,
314,
12693,
5920,
367,
4474,
199,
409,
68,
8329,
2469,
342,
1553,
663,
314,
3285,
370,
506,
1202,
367,
366,
8329,
342,
4882,
199,
409,
2913,
342,
1553,
663,
314,
2288,
30238,
805,
199,
409,
21314,
3097,
342,
1553,
663,
314,
1390,
16189,
5818,
367,
314,
12693,
199,
28434,
342,
1553,
663,
314,
2288,
3105,
23465,
805,
199,
624,
199,
3,
949,
8925,
199,
199,
3,
17198,
543,
3486,
1338,
199,
199,
1246,
63,
1023,
275,
413,
13264,
199,
199,
1095,
63,
1628,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
7,
199,
199,
1095,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
7,
199,
199,
19415,
275,
283,
10182,
7,
199,
199,
7307,
275,
283,
7384,
334,
67,
9,
12521,
13,
7280,
2018,
2290,
2752,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
12293,
6423,
4299,
14,
957,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
9013,
21,
13,
8339,
11098,
367,
20548,
26993,
21412,
10661,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
9013,
17,
13,
7155,
21,
428,
280,
335,
1337,
16593,
24508,
280,
15820,
445,
18626,
453,
12,
437,
706,
351,
68,
455,
3134,
78,
2422,
5924,
5702,
3530,
199,
199,
9259,
2479,
275,
5557,
1717,
1138,
1960,
24,
199,
199,
18671,
63,
952,
63,
19812,
275,
756,
199,
199,
5904,
275,
283,
35,
18589,
4718,
1082,
1103,
1548,
14,
5803,
7,
199,
199,
1628,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
7,
199,
199,
1609,
63,
2722,
63,
2487,
275,
283,
3612,
7,
199,
199,
4097,
1023,
275,
5238,
1427,
2260,
1299,
199,
199,
13634,
275,
21237
] |
[
2644,
26,
2774,
13,
24,
199,
3,
859,
984,
199,
3,
687,
334,
11730,
13,
262,
9,
199,
3,
701,
4306,
413,
14,
8312,
199,
624,
199,
2765,
859,
6571,
2879,
370,
2005,
2251,
1202,
503,
26391,
701,
314,
199,
20244,
436,
370,
3423,
626,
17232,
30390,
543,
314,
12693,
14,
199,
199,
14451,
2251,
26,
199,
199,
3020,
1553,
1414,
1004,
2368,
27,
9238,
59,
16,
61,
365,
314,
2884,
11776,
340,
6040,
199,
515,
1553,
859,
2754,
931,
27,
931,
59,
16,
61,
365,
314,
2884,
2082,
12,
587,
2125,
199,
3112,
1553,
2600,
402,
6511,
4621,
199,
199,
2918,
3664,
1553,
2797,
370,
2498,
2058,
315,
376,
12777,
2351,
199,
476,
301,
13316,
6992,
1553,
2797,
370,
2429,
1263,
625,
24872,
1919,
1163,
2419,
14838,
523,
4005,
17551,
16116,
315,
376,
12777,
2351,
503,
370,
3907,
282,
3537,
523,
2746,
13,
1896,
1919,
3016,
12,
5090,
1163,
3423,
370,
3350,
3520,
14,
199,
199,
6626,
1553,
4465,
1324,
570,
909,
27,
1202,
701,
1324,
342,
199,
2703,
1553,
4465,
1072,
570,
909,
27,
1202,
701,
870,
342,
199,
3083,
1553,
4465,
1125,
909,
27,
1202,
367,
1125,
3788,
523,
4885,
26694,
1163,
570,
2251,
334,
269,
2251,
626,
24062,
2839,
1584,
9,
523,
370,
3520,
12,
652,
365,
3962,
370,
4660,
1006,
402,
314,
12693,
1159,
473,
15,
47,
14,
199,
199,
2019,
63,
466,
1553,
730,
402,
2061,
625,
24872,
1919,
199,
2019,
63,
585,
1553,
574,
402,
2061,
625,
24872,
1919,
199,
2019,
63,
6894,
1553,
5190,
402,
2061,
625,
24872,
1919,
523,
5723,
7795,
787,
1454,
2808,
315,
376,
12777,
2351,
2410,
282,
523,
5190,
965,
2757,
12487,
14,
199,
199,
9278,
2251,
26,
199,
199,
5351,
63,
578,
63,
1247,
1553,
2008,
402,
859,
1561,
6137,
1901,
642,
12693,
199,
7307,
1553,
4248,
4245,
1126,
24522,
370,
642,
12693,
199,
1628,
63,
1861,
1553,
2403,
1202,
370,
2342,
314,
6844,
13,
6100,
2018,
3555,
199,
5904,
1553,
3679,
931,
402,
314,
7286,
3366,
402,
314,
2018,
12693,
199,
1609,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2069,
4514,
14,
199,
1609,
63,
2722,
63,
2487,
1553,
1059,
9297,
314,
3449,
402,
4700,
342,
1072,
367,
15657,
199,
2227,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2631,
5563,
14,
199,
4097,
1023,
1553,
1015,
2556,
5737,
465,
282,
2849,
3000,
199,
12236,
1553,
2018,
4514,
2556,
14,
199,
442,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
1109,
4514,
14,
199,
13634,
1553,
314,
17451,
3748,
2582,
402,
15333,
14,
199,
988,
2975,
1553,
314,
574,
402,
314,
17451,
6140,
1233,
1403,
199,
3246,
1553,
4298,
5148,
199,
1861,
1553,
2403,
1202,
370,
2342,
314,
2018,
3555,
199,
2671,
63,
815,
1553,
282,
2702,
3414,
543,
2556,
3595,
314,
2462,
4514,
14,
199,
1023,
1553,
314,
1015,
402,
642,
12693,
465,
282,
1059,
199,
1023,
63,
815,
1553,
1015,
2556,
465,
282,
4310,
2008,
199,
9259,
2479,
1553,
359,
8647,
1454,
61,
3000,
2429,
402,
314,
2018,
577,
4464,
199,
2676,
422,
1553,
359,
8647,
1454,
61,
1015,
1329,
402,
314,
2018,
577,
4464,
199,
363,
6626,
363,
1553,
314,
3379,
9009,
27,
2793,
1133,
12943,
1,
199,
363,
2703,
363,
1553,
314,
3379,
3839,
27,
2793,
1133,
12943,
1,
199,
363,
3083,
363,
1553,
314,
3379,
4635,
27,
2793,
1133,
12943,
1,
199,
363,
2918,
3664,
363,
1553,
314,
3379,
2929,
3664,
27,
2793,
1133,
12943,
1,
199,
363,
476,
301,
13316,
6992,
363,
1553,
314,
3379,
11553,
13316,
6992,
27,
2793,
1133,
12943,
1,
199,
199,
13967,
26,
199,
199,
2918,
3664,
342,
1553,
870,
376,
909,
370,
314,
6426,
12,
436,
3354,
652,
315,
12963,
423,
199,
476,
301,
13316,
6992,
342,
1553,
870,
376,
1919,
436,
2399,
5190,
370,
984,
14,
3083,
199,
2804,
63,
815,
342,
1553,
372,
2462,
13,
3489,
2556,
3595,
314,
1453,
1919,
199,
2224,
342,
1553,
4458,
314,
12693,
701,
17026,
14838,
199,
362,
68,
8329,
2469,
342,
1553,
2529,
3285,
370,
506,
1202,
367,
366,
8329,
342,
4882,
199,
362,
2913,
342,
1553,
664,
314,
2288,
30238,
805,
199,
32371,
342,
1553,
372,
314,
3659,
2338,
367,
376,
909,
334,
6666,
1373,
22901,
9,
199,
362,
21314,
3097,
342,
1553,
372,
314,
1390,
16189,
5818,
367,
314,
12693,
199,
362,
12590,
342,
1553,
372,
314,
1568,
402,
376,
909,
315,
2783,
199,
362,
3446,
342,
1553,
664,
314,
2288,
3105,
23465,
805,
199,
409,
1074,
4284,
342,
1553,
3304,
4212,
14115,
314,
12693,
5920,
367,
4474,
199,
409,
68,
8329,
2469,
342,
1553,
663,
314,
3285,
370,
506,
1202,
367,
366,
8329,
342,
4882,
199,
409,
2913,
342,
1553,
663,
314,
2288,
30238,
805,
199,
409,
21314,
3097,
342,
1553,
663,
314,
1390,
16189,
5818,
367,
314,
12693,
199,
28434,
342,
1553,
663,
314,
2288,
3105,
23465,
805,
199,
624,
199,
3,
949,
8925,
199,
199,
3,
17198,
543,
3486,
1338,
199,
199,
1246,
63,
1023,
275,
413,
13264,
199,
199,
1095,
63,
1628,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
7,
199,
199,
1095,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
7,
199,
199,
19415,
275,
283,
10182,
7,
199,
199,
7307,
275,
283,
7384,
334,
67,
9,
12521,
13,
7280,
2018,
2290,
2752,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
12293,
6423,
4299,
14,
957,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
9013,
21,
13,
8339,
11098,
367,
20548,
26993,
21412,
10661,
3134,
78,
2422,
5924,
5702,
3134,
78,
60,
78,
7384,
334,
67,
9,
9013,
17,
13,
7155,
21,
428,
280,
335,
1337,
16593,
24508,
280,
15820,
445,
18626,
453,
12,
437,
706,
351,
68,
455,
3134,
78,
2422,
5924,
5702,
3530,
199,
199,
9259,
2479,
275,
5557,
1717,
1138,
1960,
24,
199,
199,
18671,
63,
952,
63,
19812,
275,
756,
199,
199,
5904,
275,
283,
35,
18589,
4718,
1082,
1103,
1548,
14,
5803,
7,
199,
199,
1628,
63,
1861,
275,
283,
35,
18589,
4718,
1082,
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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
] |
qguv/config
|
weechat/plugins/python/twitch.py
|
1
|
27158
|
# -*- coding: utf-8 -*-
# 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/>.
#
#
# This script checks stream status of any channel on any servers
# listed in the "plugins.var.python.twitch.servers" setting. When you
# switch to a buffer it will display updated infomation about the stream
# in the title bar. Typing '/twitch' in buffer will also fetch updated
# infomation. '/whois nick' will lookup user info and display it in current
# buffer.
#
# https://github.com/mumixam/weechat-twitch
#
# settings:
# plugins.var.python.twitch.servers (default: twitch)
# plugins.var.python.twitch.prefix_nicks (default: 1)
# plugins.var.python.twitch.debug (default: 0)
# plugins.var.python.twitch.ssl_verify (default: 1)
# plugins.var.python.twitch.notice_notify_block (default: 1)
# plugins.var.python.twitch.client_id (default: awtv6n371jb7uayyc4jaljochyjbfxs)
#
# # History:
#
# 2019-10-13, mumixam
# v0.8: changed input modifier hooks to use irc_in2_* instead
# added setting 'plugins.var.python.twitch.notice_notify_block'
# added setting 'plugins.var.python.twitch.client_id'
# 2019-09-25, mumixam
# v0.7: updated script to use current api
# 2019-03-03,
# v0.6: added support for CLEARMSG -MentalFS
# fixed issue with /whois -mumixam
# 2018-06-03, mumixam
# v0.5: enable curl verbose mode when debug is active, add option to disable ssl/tls verification,
# if stream title contains newline char replace it with space
# 2017-11-02, mumixam
# v0.4: added debug mode for API calls, minor bugfixes
# 2017-06-10, mumixam
# v0.3: fixed whois output of utf8 display names
# 2016-11-03, mumixam
# v0.2: added detailed /help
# 2016-10-30, mumixam
# v0.1: script added to weechat.org
SCRIPT_NAME = "twitch"
SCRIPT_AUTHOR = "mumixam"
SCRIPT_VERSION = "0.8"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "twitch.tv Chat Integration"
OPTIONS={
'servers': ('twitch','Name of server(s) which script will be active on, space seperated'),
'prefix_nicks': ('1','Prefix nicks based on ircv3 tags for mods/subs, This can be cpu intensive on very active chats [1 for enabled, 0 for disabled]'),
'debug': ('0','Debug mode'),
'ssl_verify': ('1', 'Verify SSL/TLS certs'),
'notice_notify_block': ('1', 'Changes notify level of NOTICEs to low'),
'client_id': ('awtv6n371jb7uayyc4jaljochyjbfxs', 'Twitch API Token')
}
import weechat
import json
from calendar import timegm
from datetime import datetime, timedelta
import time
import string
import ast
curlopt = {
"httpheader": "Client-ID: "+OPTIONS['client_id'][0],
"timeout": "5",
"verbose": "0",
"ssl_verifypeer": "1",
"ssl_verifyhost": "2"
}
gameid_cache = {}
uid_cache = {}
def days_hours_minutes(td):
age = ''
hours = td.seconds // 3600
min = td.seconds // 60 % 60
if not td.days == 0:
age += str(td.days) + 'd '
if not hours == 0:
age += str(hours) + 'h '
if not min == 0:
age += str(min) + 'm'
return age.strip()
def twitch_main(data, buffer, args):
if not args == 'bs':
weechat.buffer_set(buffer, 'localvar_set_tstatus', '')
username = weechat.buffer_get_string(buffer, 'short_name').replace('#', '')
server = weechat.buffer_get_string(buffer, 'localvar_server')
type = weechat.buffer_get_string(buffer, 'localvar_type')
if not (server in OPTIONS['servers'].split() and type == 'channel'):
return weechat.WEECHAT_RC_OK
url = 'https://api.twitch.tv/helix/streams?user_login=' + username
weechat.hook_process_hashtable(
"url:" + url, curlopt, 7 * 1000, "stream_api", buffer)
return weechat.WEECHAT_RC_OK
def makeutf8(data):
data = data.encode('utf8')
if not isinstance(data, str):
data=str(data,'utf8')
return data
def stream_api(data, command, rc, stdout, stderr):
try:
jsonDict = json.loads(stdout.strip())
except Exception as e:
weechat.prnt(data, '%stwitch.py: error communicating with twitch api' % weechat.prefix('error'))
if OPTIONS['debug']:
weechat.prnt(data,'%stwitch.py: return code: %s' % (weechat.prefix('error'),rc))
weechat.prnt(data,'%stwitch.py: stdout: %s' % (weechat.prefix('error'),stdout))
weechat.prnt(data,'%stwitch.py: stderr: %s' % (weechat.prefix('error'),stderr))
weechat.prnt(data,'%stwitch.py: exception: %s' % (weechat.prefix('error'),e))
return weechat.WEECHAT_RC_OK
currentbuf = weechat.current_buffer()
title_fg = weechat.color(
weechat.config_color(weechat.config_get("weechat.bar.title.color_fg")))
title_bg = weechat.color(
weechat.config_color(weechat.config_get("weechat.bar.title.color_bg")))
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
red = weechat.color('red')
blue = weechat.color('blue')
green = weechat.color('green')
ptime = time.strftime("%H:%M:%S")
subs = weechat.buffer_get_string(data, 'localvar_subs')
r9k = weechat.buffer_get_string(data, 'localvar_r9k')
slow = weechat.buffer_get_string(data, 'localvar_slow')
emote = weechat.buffer_get_string(data, 'localvar_emote')
if not 'data' in jsonDict.keys():
weechat.prnt(data, 'twitch.py: Error with twitch API (data key missing from json)')
return weechat.WEECHAT_RC_OK
if not jsonDict['data']:
line = "STREAM: %sOFFLINE%s %sCHECKED AT: (%s)" % (
red, title_fg, blue, ptime)
if subs:
line += " %s[SUBS]" % title_fg
if r9k:
line += " %s[R9K]" % title_fg
if slow:
line += " %s[SLOW@%s]" % (title_fg, slow)
if emote:
line += " %s[EMOTE]" % title_fg
weechat.buffer_set(data, "title", line)
else:
currenttime = time.time()
if len(jsonDict['data']) == 1:
jsonDict['data'] = jsonDict['data'][0]
output = 'STREAM: %sLIVE%s' % (green, title_fg)
if 'game_id' in jsonDict['data']:
if jsonDict['data']['game_id']:
game = jsonDict['data']['game_id']
game_id = game
if game in gameid_cache:
game = gameid_cache[game]
output += ' <%s> with' % game
if 'viewer_count' in jsonDict['data']:
viewers = jsonDict['data']['viewer_count']
output += ' %s viewers started' % viewers
if 'started_at' in jsonDict['data']:
createtime = jsonDict['data']['started_at'].replace('Z', 'GMT')
starttime = timegm(
time.strptime(createtime, '%Y-%m-%dT%H:%M:%S%Z'))
dur = timedelta(seconds=currenttime - starttime)
uptime = days_hours_minutes(dur)
output += ' %s ago' % uptime
if 'title' in jsonDict['data']:
titleutf8=jsonDict['data']['title'].replace('\n',' ').encode('utf8')
titleascii=jsonDict['data']['title'].encode('ascii','replace')
if not isinstance(titleutf8, str):
titleascii=str(titleascii,'utf8')
titleutf8=str(titleutf8,'utf8')
oldtitle = weechat.buffer_get_string(data, 'localvar_tstatus')
if not oldtitle == titleascii:
weechat.prnt(data, '%s--%s Title is "%s"' %
(pcolor, ccolor, titleutf8))
weechat.buffer_set(data, 'localvar_set_tstatus', titleascii)
output += ' (%s)' % ptime
if subs:
output += " %s[SUBS]" % title_fg
if r9k:
output += " %s[R9K]" % title_fg
if slow:
output += " %s[SLOW@%s]" % (title_fg, slow)
if emote:
output += " %s[EMOTE]" % title_fg
weechat.buffer_set(data, "title", output)
if not game_id in gameid_cache:
url = 'https://api.twitch.tv/helix/games?id=' + game_id
weechat.hook_process_hashtable(
"url:" + url, curlopt, 7 * 1000, "game_api", data)
return weechat.WEECHAT_RC_OK
def game_api(data, command, rc, stdout, stderr):
try:
jsonDict = json.loads(stdout.strip())
except Exception as e:
weechat.prnt(data, '%stwitch.py: error communicating with twitch api' % weechat.prefix('error'))
if OPTIONS['debug']:
weechat.prnt(data,'%stwitch.py: return code: %s' % (weechat.prefix('error'),rc))
weechat.prnt(data,'%stwitch.py: stdout: %s' % (weechat.prefix('error'),stdout))
weechat.prnt(data,'%stwitch.py: stderr: %s' % (weechat.prefix('error'),stderr))
weechat.prnt(data,'%stwitch.py: exception: %s' % (weechat.prefix('error'),e))
return weechat.WEECHAT_RC_OK
if 'data' in jsonDict.keys():
if not jsonDict['data']:
return weechat.WEECHAT_RC_OK
if len(jsonDict['data']) == 1:
jsonDict['data'] = jsonDict['data'][0]
old_title = weechat.buffer_get_string(data, "title")
id = jsonDict['data']['id']
name = makeutf8(jsonDict['data']['name'])
new_title = old_title.replace('<{}>'.format(id),'<{}>'.format(name))
weechat.buffer_set(data, "title", new_title)
gameid_cache[id] = name
return weechat.WEECHAT_RC_OK
def channel_api(data, command, rc, stdout, stderr):
try:
jsonDict = json.loads(stdout.strip())
except Exception as e:
weechat.prnt(data, '%stwitch.py: error communicating with twitch api' % weechat.prefix('error'))
if OPTIONS['debug']:
weechat.prnt(data['buffer'],'%stwitch.py: return code: %s' % (weechat.prefix('error'),rc))
weechat.prnt(data['buffer'],'%stwitch.py: stdout: %s' % (weechat.prefix('error'),stdout))
weechat.prnt(data['buffer'],'%stwitch.py: stderr: %s' % (weechat.prefix('error'),stderr))
weechat.prnt(data['buffer'],'%stwitch.py: exception: %s' % (weechat.prefix('error'),e))
return weechat.WEECHAT_RC_OK
currentbuf = weechat.current_buffer()
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
dcolor = weechat.color('chat_delimiters')
ncolor = weechat.color('chat_nick')
ul = weechat.color("underline")
rul = weechat.color("-underline")
pformat = weechat.config_string(
weechat.config_get("weechat.look.prefix_network"))
if 'total' in jsonDict:
uid = command.split('=')[-1]
name = 'WHOIS'
if 'to_id' in command:
followers = jsonDict['total']
if uid in uid_cache:
name = uid_cache[uid]
output = '%s%s %s[%s%s%s]%s %sFollowers%s: %s' % (
pcolor, pformat, dcolor, ncolor, name, dcolor, ccolor, ul, rul, followers)
weechat.prnt(data, makeutf8(output))
url = 'https://api.twitch.tv/helix/users/follows?from_id=' + uid
url_hook = weechat.hook_process_hashtable(
"url:" + url, curlopt, 7 * 1000, "channel_api", data)
return weechat.WEECHAT_RC_OK
if 'from_id' in command:
following = jsonDict['total']
if uid in uid_cache:
name = uid_cache[uid]
output = '%s%s %s[%s%s%s]%s %sFollowing%s: %s' % (
pcolor, pformat, dcolor, ncolor, name, dcolor, ccolor, ul, rul, following)
weechat.prnt(data, makeutf8(output))
return weechat.WEECHAT_RC_OK
if ('users' in jsonDict) and jsonDict['users'] and len(jsonDict['users'][0]) == 8:
dname = jsonDict['users'][0]['display_name']
name = jsonDict['users'][0]['name']
create = jsonDict['users'][0]['created_at'].split('T')[0]
status = jsonDict['users'][0]['bio']
uid = jsonDict['users'][0]['_id']
uid_cache[uid] = name
output = '%s%s %s[%s%s%s]%s %sDisplay Name%s: %s' % (
pcolor, pformat, dcolor, ncolor, name, dcolor, ccolor, ul, rul, dname)
output += '\n%s%s %s[%s%s%s]%s %sAccount Created%s: %s' % (
pcolor, pformat, dcolor, ncolor, name, dcolor, ccolor, ul, rul, create)
if status:
output += '\n%s%s %s[%s%s%s]%s %sBio%s: %s' % (
pcolor, pformat, dcolor, ncolor, name, dcolor, ccolor, ul, rul, status)
weechat.prnt(data, makeutf8(output))
url = 'https://api.twitch.tv/helix/users/follows?to_id=' + uid
url_hook = weechat.hook_process_hashtable(
"url:" + url, curlopt, 7 * 1000, "channel_api", data)
else:
weechat.prnt(data, 'Error: No Such User')
return weechat.WEECHAT_RC_OK
def twitch_clearchat(data, modifier, modifier_data, string):
mp = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
server = modifier_data
user = mp['text']
channel = mp['channel']
try:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
except:
tags = ''
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
if buffer:
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
ul = weechat.color("underline")
rul = weechat.color("-underline")
if user:
if 'ban-duration' in tags:
if 'ban-reason' in tags and tags['ban-reason']:
bn=tags['ban-reason'].replace('\s',' ')
weechat.prnt(buffer,"%s--%s %s has been timed out for %s seconds %sReason%s: %s" %
(pcolor, ccolor, user, tags['ban-duration'], ul, rul, bn))
else:
weechat.prnt(buffer,"%s--%s %s has been timed out for %s seconds" %
(pcolor, ccolor, user, tags['ban-duration']))
elif 'ban-reason' in tags:
if tags['ban-reason']:
bn=tags['ban-reason'].replace('\s',' ')
weechat.prnt(buffer,"%s--%s %s has been banned %sReason%s: %s" %
(pcolor, ccolor, user, ul, rul,bn))
else:
weechat.prnt(buffer,"%s--%s %s has been banned" %
(pcolor, ccolor, user))
else:
weechat.prnt(
buffer, "%s--%s %s's Chat Cleared By Moderator" % (pcolor, ccolor, user))
else:
weechat.prnt(
buffer, "%s--%s Entire Chat Cleared By Moderator" % (pcolor, ccolor))
return ""
def twitch_clearmsg(data, modifier, modifier_data, string):
mp = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
server = modifier_data
channel = mp['channel']
try:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
except:
tags = ''
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
if buffer:
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
if 'login' in tags:
weechat.prnt(buffer,"%s--%s a message from %s was deleted" % (pcolor, ccolor, tags['login']))
else:
weechat.prnt(buffer, "%s--%s a message was deleted" % (pcolor, ccolor))
return ""
def twitch_suppress(data, modifier, modifier_data, string):
return ""
def twitch_reconnect(data, modifier, modifier_data, string):
server = modifier_data
buffer = weechat.buffer_search("irc", "server.%s" % server)
if buffer:
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
weechat.prnt(
buffer, "%s--%s Server sent reconnect request. Issuing /reconnect" % (pcolor, ccolor))
weechat.command(buffer, "/reconnect")
return ""
def twitch_buffer_switch(data, signal, signal_data):
server = weechat.buffer_get_string(signal_data, 'localvar_server')
type = weechat.buffer_get_string(signal_data, 'localvar_type')
if not (server in OPTIONS['servers'].split() and type == 'channel'):
return weechat.WEECHAT_RC_OK
twitch_main('', signal_data, 'bs')
return weechat.WEECHAT_RC_OK
def twitch_roomstate(data, modifier, server, string):
message = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
buffer = weechat.buffer_search(
"irc", "%s.%s" % (server, message['channel']))
for tag in message['tags'].split(';'):
if tag == 'subs-only=0':
weechat.buffer_set(buffer, 'localvar_set_subs', '')
if tag == 'subs-only=1':
weechat.buffer_set(buffer, 'localvar_set_subs', '1')
if tag == 'r9k=0':
weechat.buffer_set(buffer, 'localvar_set_r9k', '')
if tag == 'r9k=1':
weechat.buffer_set(buffer, 'localvar_set_r9k', '1')
if tag == 'emote-only=0':
weechat.buffer_set(buffer, 'localvar_set_emote', '')
if tag == 'emote-only=1':
weechat.buffer_set(buffer, 'localvar_set_emote', '1')
if tag.startswith('slow='):
value = tag.split('=')[-1]
if value == '0':
weechat.buffer_set(buffer, 'localvar_set_slow', '')
if value > '0':
weechat.buffer_set(buffer, 'localvar_set_slow', value)
twitch_main('', buffer, 'bs')
return ''
def twitch_usernotice(data, modifier, server, string):
pcolor = weechat.color('chat_prefix_network')
ccolor = weechat.color('chat')
mp = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
buffer = weechat.buffer_search(
"irc", "%s.%s" % (server, mp['channel']))
if mp['tags']:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
msg = tags['system-msg'].replace('\s',' ')
if mp['text']:
msg += ' [Comment] '+mp['text']
weechat.prnt(buffer, '%s--%s %s' % (pcolor, ccolor, msg))
return ''
def twitch_whisper(data, modifier, modifier_data, string):
message = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
if message['tags']: string = '@'+message['tags']+' '
else: string = ''
string += ':'+message['host']
string += ' PRIVMSG'
string += ' '+message['arguments']
return string
def twitch_privmsg(data, modifier, server_name, string):
if not server_name in OPTIONS['servers'].split():
return string
message = weechat.info_get_hashtable(
'irc_message_parse', {"message": string})
if message['channel'].startswith('#'):
return string
newmsg = 'PRIVMSG #%s :/w %s %s' % (message['nick'],message['nick'],message['text'])
return newmsg
def twitch_in_privmsg(data, modifier, server_name, string, prefix=''):
if not OPTIONS['prefix_nicks']: return string
if not server_name in OPTIONS['servers'].split():
return string
mp = weechat.info_get_hashtable("irc_message_parse", {"message": string})
if not mp['tags']:
return string
if '#' + mp['nick'] == mp['channel']:
return mp['message_without_tags'].replace(mp['nick'], '~' + mp['nick'], 1)
tags = dict([s.split('=') for s in mp['tags'].split(';')])
if tags['user-type'] == 'mod':
prefix += '@'
if tags['subscriber'] == '1':
prefix += '%'
if prefix:
msg = mp['message_without_tags'].replace(
mp['nick'], prefix + mp['nick'], 1)
return '@' + mp['tags'] + ' ' + msg
else:
return string
def twitch_whois(data, modifier, server_name, string):
if not server_name in OPTIONS['servers'].split():
return string
msg = weechat.info_get_hashtable("irc_message_parse", {"message": string})
username = msg['nick'].lower()
currentbuf = weechat.current_buffer()
url = 'https://api.twitch.tv/kraken/users?login=' + username
params='&api_version=5'
url_hook = weechat.hook_process_hashtable(
"url:" + url+params, curlopt, 7 * 1000, "channel_api", currentbuf)
return ""
def twitch_notice(data, line):
if not OPTIONS['notice_notify_block']: return string
return {"notify_level": "0"}
def config_setup():
for option,value in OPTIONS.items():
weechat.config_set_desc_plugin(option, '%s' % value[1])
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, value[0])
OPTIONS[option] = value[0]
else:
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify' or option == 'notice_notify_block':
OPTIONS[option] = weechat.config_string_to_boolean(
weechat.config_get_plugin(option))
else:
OPTIONS[option] = weechat.config_get_plugin(option)
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
else:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
else:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
if option == 'client_id':
curlopt['httpheader'] = "Client-ID: " + value[0]
def config_change(pointer, name, value):
option = name.replace('plugins.var.python.'+SCRIPT_NAME+'.','')
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify' or option == 'notice_notify_block':
value=weechat.config_string_to_boolean(value)
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
if value == 1:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
if value == 1:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
if option == 'client_id':
curlopt['httpheader'] = "Client-ID: " + value
OPTIONS[option] = value
return weechat.WEECHAT_RC_OK
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
weechat.hook_command("twitch", SCRIPT_DESC, "",
" settings:\n"
" plugins.var.python.twitch.servers (default: twitch)\n"
" plugins.var.python.twitch.prefix_nicks (default: 1)\n"
" plugins.var.python.twitch.debug (default: 0)\n"
" plugins.var.python.twitch.ssl_verify (default: 0)\n"
" plugins.var.python.twitch.notice_notify_block (default: 1)\n"
" plugins.var.python.twitch.client_id (default: awtv6n371jb7uayyc4jaljochyjbfxs)\n"
"\n\n"
" This script checks stream status of any channel on any servers listed\n"
" in the \"plugins.var.python.twitch.servers\" setting. When you switch\n"
" to a buffer it will display updated infomation about the stream in the\n"
" title bar. Typing '/twitch' in a buffer will also fetch updated infomation.\n"
" '/whois nick' will lookup user info and display it in current buffer.\n\n"
" Option \"plugins.var.python.twitch.servers\" controls\n"
" what server this script will work on. The default is twitch\n"
" but you can have multiples separated by a space.\n"
" /set plugins.var.python.twitch.servers twitch twitchcopy\n"
"\n\n"
" This script also will prefix users nicks (@ for mod, % for sub,\n"
" and ~ for broadcaster). This will break the traditional function\n"
" of `/ignore add nightbot` and will require you to prefix nicks if you\n"
" want to ignore someone `/ignore add re:[~@%]{0,3}nightbot` should ignore\n"
" a nick with all or none of the prefixes used by this script.\n"
" NOTE: This may cause high cpu usage in very active chat and/or on slower cpus.\n"
" This can also be disabled by setting\n /set plugins.var.python.twitch.prefix_nicks off\n"
"\n\n"
" If you are experiencing errors you can enable debug mode by setting\n"
" /set plugins.var.python.twitch.debug on\n"
" You can also try disabling SSL/TLS cert verification.\n"
" /set plugins.var.python.twitch.ssl_verify off\n"
"\n\n"
" Required server settings:\n"
" /server add twitch irc.twitch.tv\n"
" /set irc.server.twitch.capabilities \"twitch.tv/membership,twitch.tv/commands,twitch.tv/tags\"\n"
" /set irc.server.twitch.nicks \"My Twitch Username\"\n"
" /set irc.server.twitch.password \"oauth:My Oauth Key\"\n"
"\n"
" If you do not have a oauth token one can be generated for your account here\n"
" https://twitchapps.com/tmi/\n"
"\n"
" This script now by default limits the level of NOTICEs from twitch server\n"
" What this does is makes it so 'Now hosting' notifications are classes as a low level message\n"
" So they no longer show up in your hotlist like a 'actual' message\n"
" If you would like to disable this set the following\n"
" /set plugins.var.python.twitch.notice_notify_block 0\n"
"\n"
" If would like to use your own Client-ID it can be set with\n"
" /set plugins.var.python.twitch.client_id (clientid)\n"
"\n"
" This script also has whisper support that works like a standard query. \"/query user\"\n\n",
"", "twitch_main", "")
weechat.hook_signal('buffer_switch', 'twitch_buffer_switch', '')
weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'config_change', '')
config_setup()
weechat.hook_line("", "", "irc_notice+nick_tmi.twitch.tv", "twitch_notice", "")
weechat.hook_modifier("irc_in2_CLEARCHAT", "twitch_clearchat", "")
weechat.hook_modifier("irc_in2_CLEARMSG", "twitch_clearmsg", "")
weechat.hook_modifier("irc_in2_RECONNECT", "twitch_reconnect", "")
weechat.hook_modifier("irc_in2_USERSTATE", "twitch_suppress", "")
weechat.hook_modifier("irc_in2_HOSTTARGET", "twitch_suppress", "")
weechat.hook_modifier("irc_in2_ROOMSTATE", "twitch_roomstate", "")
weechat.hook_modifier("irc_in2_USERNOTICE", "twitch_usernotice", "")
weechat.hook_modifier("irc_in2_WHISPER", "twitch_whisper", "")
weechat.hook_modifier("irc_out_PRIVMSG", "twitch_privmsg", "")
weechat.hook_modifier("irc_out_WHOIS", "twitch_whois", "")
weechat.hook_modifier("irc_in2_PRIVMSG", "twitch_in_privmsg", "")
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
199,
3,
961,
2884,
5920,
2547,
2004,
402,
1263,
3623,
641,
1263,
8037,
199,
3,
10532,
315,
314,
298,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
5871,
2,
4260,
14,
3979,
1265,
199,
3,
6258,
370,
282,
3335,
652,
911,
2929,
4588,
2256,
1615,
3595,
314,
2547,
199,
3,
315,
314,
2538,
4681,
14,
18320,
316,
1994,
84,
3111,
7,
315,
3335,
911,
2597,
5267,
4588,
199,
3,
2256,
1615,
14,
1994,
11345,
374,
14900,
7,
911,
4237,
922,
2256,
436,
2929,
652,
315,
1453,
199,
3,
3335,
14,
199,
3,
199,
3,
4178,
921,
5031,
14,
957,
15,
77,
453,
1148,
455,
15,
25515,
10289,
13,
84,
3111,
199,
3,
199,
3,
2202,
26,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
5871,
334,
885,
26,
307,
3111,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1861,
63,
11082,
83,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1757,
334,
885,
26,
378,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
4266,
63,
4712,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
20556,
63,
6814,
63,
1457,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1258,
63,
344,
334,
885,
26,
26936,
6993,
22,
78,
16124,
26257,
23,
85,
1187,
29874,
20,
74,
279,
743,
335,
89,
74,
4361,
7977,
9,
199,
3,
199,
3,
327,
27829,
26,
199,
3,
199,
3,
20312,
13,
709,
13,
969,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
24,
26,
2896,
1324,
17880,
12604,
370,
675,
22157,
63,
262,
18,
15192,
3140,
199,
3,
3698,
3483,
4260,
283,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
20556,
63,
6814,
63,
1457,
7,
199,
3,
3698,
3483,
4260,
283,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1258,
63,
344,
7,
199,
3,
20312,
13,
1643,
13,
821,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
23,
26,
4588,
2884,
370,
675,
1453,
2986,
199,
3,
20312,
13,
1644,
13,
1644,
12,
199,
3,
258,
373,
16,
14,
22,
26,
3483,
2291,
367,
445,
906,
689,
9740,
446,
45,
484,
279,
7079,
199,
3,
3698,
6317,
4976,
543,
1182,
11345,
374,
446,
77,
453,
1148,
455,
199,
3,
14894,
13,
1690,
13,
1644,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
21,
26,
4756,
26145,
3376,
818,
1380,
3105,
365,
4702,
12,
1050,
945,
370,
3507,
6149,
15,
9945,
14786,
12,
199,
3,
3698,
340,
2547,
2538,
3509,
8057,
1495,
3350,
652,
543,
4601,
199,
3,
9708,
13,
845,
13,
996,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
20,
26,
3483,
3105,
818,
367,
3261,
4882,
12,
12612,
6519,
26205,
199,
3,
9708,
13,
1690,
13,
709,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
19,
26,
6317,
3963,
374,
1072,
402,
2774,
24,
2929,
1561,
199,
3,
7800,
13,
845,
13,
1644,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
18,
26,
3483,
16212,
1182,
3437,
199,
3,
7800,
13,
709,
13,
1216,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
17,
26,
2884,
3483,
370,
781,
69,
10289,
14,
1308,
4388,
199,
10484,
63,
2339,
275,
298,
84,
3111,
2,
199,
10484,
63,
27938,
275,
298,
77,
453,
1148,
455,
2,
199,
10484,
63,
4612,
275,
298,
16,
14,
24,
2,
199,
10484,
63,
3961,
275,
298,
12006,
19,
2,
199,
10484,
63,
15119,
275,
298,
84,
3111,
14,
6993,
2799,
292,
27561,
2,
199,
8808,
3126,
272,
283,
5871,
356,
661,
84,
3111,
1673,
985,
402,
1654,
8,
83,
9,
1314,
2884,
911,
506,
4702,
641,
12,
4601,
542,
529,
972,
659,
272,
283,
1861,
63,
11082,
83,
356,
661,
17,
1673,
4793,
14900,
83,
4079,
641,
22157,
86,
19,
3762,
367,
24496,
15,
9841,
12,
961,
883,
506,
5033,
315,
724,
3398,
641,
7437,
4702,
682,
1956,
359,
17,
367,
5223,
12,
378,
367,
6980,
26987,
272,
283,
1757,
356,
661,
16,
1673,
7084,
818,
659,
272,
283,
4266,
63,
4712,
356,
661,
17,
297,
283,
7496,
7799,
15,
10224,
25949,
659,
272,
283,
20556,
63,
6814,
63,
1457,
356,
661,
17,
297,
283,
13907,
11705,
2166,
402,
12840,
83,
370,
6465,
659,
272,
283,
1258,
63,
344,
356,
661,
10084,
6993,
22,
78,
16124,
26257,
23,
85,
1187,
29874,
20,
74,
279,
743,
335,
89,
74,
4361,
7977,
297,
283,
52,
3111,
3261,
8767,
358,
199,
93,
421,
199,
646,
781,
69,
10289,
199,
646,
2022,
199,
504,
11234,
492,
900,
13844,
199,
504,
2197,
492,
2197,
12,
6871,
199,
646,
900,
199,
646,
1059,
199,
646,
6073,
199,
199,
895,
30379,
275,
469,
272,
298,
1014,
1291,
582,
298,
3041,
13,
998,
26,
7210,
8808,
459,
1258,
63,
344,
3488,
16,
467,
272,
298,
2593,
582,
298,
21,
401,
272,
298,
3832,
582,
298,
16,
401,
272,
298,
4266,
63,
422,
692,
514,
281,
582,
298,
17,
401,
272,
298,
4266,
63,
4712,
1102,
582,
298,
18,
2
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
199,
3,
961,
2884,
5920,
2547,
2004,
402,
1263,
3623,
641,
1263,
8037,
199,
3,
10532,
315,
314,
298,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
5871,
2,
4260,
14,
3979,
1265,
199,
3,
6258,
370,
282,
3335,
652,
911,
2929,
4588,
2256,
1615,
3595,
314,
2547,
199,
3,
315,
314,
2538,
4681,
14,
18320,
316,
1994,
84,
3111,
7,
315,
3335,
911,
2597,
5267,
4588,
199,
3,
2256,
1615,
14,
1994,
11345,
374,
14900,
7,
911,
4237,
922,
2256,
436,
2929,
652,
315,
1453,
199,
3,
3335,
14,
199,
3,
199,
3,
4178,
921,
5031,
14,
957,
15,
77,
453,
1148,
455,
15,
25515,
10289,
13,
84,
3111,
199,
3,
199,
3,
2202,
26,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
5871,
334,
885,
26,
307,
3111,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1861,
63,
11082,
83,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1757,
334,
885,
26,
378,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
4266,
63,
4712,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
20556,
63,
6814,
63,
1457,
334,
885,
26,
413,
9,
199,
3,
8963,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1258,
63,
344,
334,
885,
26,
26936,
6993,
22,
78,
16124,
26257,
23,
85,
1187,
29874,
20,
74,
279,
743,
335,
89,
74,
4361,
7977,
9,
199,
3,
199,
3,
327,
27829,
26,
199,
3,
199,
3,
20312,
13,
709,
13,
969,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
24,
26,
2896,
1324,
17880,
12604,
370,
675,
22157,
63,
262,
18,
15192,
3140,
199,
3,
3698,
3483,
4260,
283,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
20556,
63,
6814,
63,
1457,
7,
199,
3,
3698,
3483,
4260,
283,
5265,
14,
1391,
14,
1548,
14,
84,
3111,
14,
1258,
63,
344,
7,
199,
3,
20312,
13,
1643,
13,
821,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
23,
26,
4588,
2884,
370,
675,
1453,
2986,
199,
3,
20312,
13,
1644,
13,
1644,
12,
199,
3,
258,
373,
16,
14,
22,
26,
3483,
2291,
367,
445,
906,
689,
9740,
446,
45,
484,
279,
7079,
199,
3,
3698,
6317,
4976,
543,
1182,
11345,
374,
446,
77,
453,
1148,
455,
199,
3,
14894,
13,
1690,
13,
1644,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
21,
26,
4756,
26145,
3376,
818,
1380,
3105,
365,
4702,
12,
1050,
945,
370,
3507,
6149,
15,
9945,
14786,
12,
199,
3,
3698,
340,
2547,
2538,
3509,
8057,
1495,
3350,
652,
543,
4601,
199,
3,
9708,
13,
845,
13,
996,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
20,
26,
3483,
3105,
818,
367,
3261,
4882,
12,
12612,
6519,
26205,
199,
3,
9708,
13,
1690,
13,
709,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
19,
26,
6317,
3963,
374,
1072,
402,
2774,
24,
2929,
1561,
199,
3,
7800,
13,
845,
13,
1644,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
18,
26,
3483,
16212,
1182,
3437,
199,
3,
7800,
13,
709,
13,
1216,
12,
333,
453,
1148,
455,
199,
3,
258,
373,
16,
14,
17,
26,
2884,
3483,
370,
781,
69,
10289,
14,
1308,
4388,
199,
10484,
63,
2339,
275,
298,
84,
3111,
2,
199,
10484,
63,
27938,
275,
298,
77,
453,
1148,
455,
2,
199,
10484,
63,
4612,
275,
298,
16,
14,
24,
2,
199,
10484,
63,
3961,
275,
298,
12006,
19,
2,
199,
10484,
63,
15119,
275,
298,
84,
3111,
14,
6993,
2799,
292,
27561,
2,
199,
8808,
3126,
272,
283,
5871,
356,
661,
84,
3111,
1673,
985,
402,
1654,
8,
83,
9,
1314,
2884,
911,
506,
4702,
641,
12,
4601,
542,
529,
972,
659,
272,
283,
1861,
63,
11082,
83,
356,
661,
17,
1673,
4793,
14900,
83,
4079,
641,
22157,
86,
19,
3762,
367,
24496,
15,
9841,
12,
961,
883,
506,
5033,
315,
724,
3398,
641,
7437,
4702,
682,
1956,
359,
17,
367,
5223,
12,
378,
367,
6980,
26987,
272,
283,
1757,
356,
661,
16,
1673,
7084,
818,
659,
272,
283,
4266,
63,
4712,
356,
661,
17,
297,
283,
7496,
7799,
15,
10224,
25949,
659,
272,
283,
20556,
63,
6814,
63,
1457,
356,
661,
17,
297,
283,
13907,
11705,
2166,
402,
12840,
83,
370,
6465,
659,
272,
283,
1258,
63,
344,
356,
661,
10084,
6993,
22,
78,
16124,
26257,
23,
85,
1187,
29874,
20,
74,
279,
743,
335,
89,
74,
4361,
7977,
297,
283,
52,
3111,
3261,
8767,
358,
199,
93,
421,
199,
646,
781,
69,
10289,
199,
646,
2022,
199,
504,
11234,
492,
900,
13844,
199,
504,
2197,
492,
2197,
12,
6871,
199,
646,
900,
199,
646,
1059,
199,
646,
6073,
199,
199,
895,
30379,
275,
469,
272,
298,
1014,
1291,
582,
298,
3041,
13,
998,
26,
7210,
8808,
459,
1258,
63,
344,
3488,
16,
467,
272,
298,
2593,
582,
298,
21,
401,
272,
298,
3832,
582,
298,
16,
401,
272,
298,
4266,
63,
422,
692,
514,
281,
582,
298,
17,
401,
272,
298,
4266,
63,
4712,
1102,
582,
298,
18,
2,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AgostonSzepessy/servo
|
tests/wpt/web-platform-tests/tools/py/py/_code/_assertionnew.py
|
217
|
12384
|
"""
Find intermediate evalutation results in assert statements through builtin AST.
This should replace _assertionold.py eventually.
"""
import sys
import ast
import py
from py._code.assertion import _format_explanation, BuiltinAssertionError
if sys.platform.startswith("java") and sys.version_info < (2, 5, 2):
# See http://bugs.jython.org/issue1497
_exprs = ("BoolOp", "BinOp", "UnaryOp", "Lambda", "IfExp", "Dict",
"ListComp", "GeneratorExp", "Yield", "Compare", "Call",
"Repr", "Num", "Str", "Attribute", "Subscript", "Name",
"List", "Tuple")
_stmts = ("FunctionDef", "ClassDef", "Return", "Delete", "Assign",
"AugAssign", "Print", "For", "While", "If", "With", "Raise",
"TryExcept", "TryFinally", "Assert", "Import", "ImportFrom",
"Exec", "Global", "Expr", "Pass", "Break", "Continue")
_expr_nodes = set(getattr(ast, name) for name in _exprs)
_stmt_nodes = set(getattr(ast, name) for name in _stmts)
def _is_ast_expr(node):
return node.__class__ in _expr_nodes
def _is_ast_stmt(node):
return node.__class__ in _stmt_nodes
else:
def _is_ast_expr(node):
return isinstance(node, ast.expr)
def _is_ast_stmt(node):
return isinstance(node, ast.stmt)
class Failure(Exception):
"""Error found while interpreting AST."""
def __init__(self, explanation=""):
self.cause = sys.exc_info()
self.explanation = explanation
def interpret(source, frame, should_fail=False):
mod = ast.parse(source)
visitor = DebugInterpreter(frame)
try:
visitor.visit(mod)
except Failure:
failure = sys.exc_info()[1]
return getfailure(failure)
if should_fail:
return ("(assertion failed, but when it was re-run for "
"printing intermediate values, it did not fail. Suggestions: "
"compute assert expression before the assert or use --no-assert)")
def run(offending_line, frame=None):
if frame is None:
frame = py.code.Frame(sys._getframe(1))
return interpret(offending_line, frame)
def getfailure(failure):
explanation = _format_explanation(failure.explanation)
value = failure.cause[1]
if str(value):
lines = explanation.splitlines()
if not lines:
lines.append("")
lines[0] += " << %s" % (value,)
explanation = "\n".join(lines)
text = "%s: %s" % (failure.cause[0].__name__, explanation)
if text.startswith("AssertionError: assert "):
text = text[16:]
return text
operator_map = {
ast.BitOr : "|",
ast.BitXor : "^",
ast.BitAnd : "&",
ast.LShift : "<<",
ast.RShift : ">>",
ast.Add : "+",
ast.Sub : "-",
ast.Mult : "*",
ast.Div : "/",
ast.FloorDiv : "//",
ast.Mod : "%",
ast.Eq : "==",
ast.NotEq : "!=",
ast.Lt : "<",
ast.LtE : "<=",
ast.Gt : ">",
ast.GtE : ">=",
ast.Pow : "**",
ast.Is : "is",
ast.IsNot : "is not",
ast.In : "in",
ast.NotIn : "not in"
}
unary_map = {
ast.Not : "not %s",
ast.Invert : "~%s",
ast.USub : "-%s",
ast.UAdd : "+%s"
}
class DebugInterpreter(ast.NodeVisitor):
"""Interpret AST nodes to gleam useful debugging information. """
def __init__(self, frame):
self.frame = frame
def generic_visit(self, node):
# Fallback when we don't have a special implementation.
if _is_ast_expr(node):
mod = ast.Expression(node)
co = self._compile(mod)
try:
result = self.frame.eval(co)
except Exception:
raise Failure()
explanation = self.frame.repr(result)
return explanation, result
elif _is_ast_stmt(node):
mod = ast.Module([node])
co = self._compile(mod, "exec")
try:
self.frame.exec_(co)
except Exception:
raise Failure()
return None, None
else:
raise AssertionError("can't handle %s" %(node,))
def _compile(self, source, mode="eval"):
return compile(source, "<assertion interpretation>", mode)
def visit_Expr(self, expr):
return self.visit(expr.value)
def visit_Module(self, mod):
for stmt in mod.body:
self.visit(stmt)
def visit_Name(self, name):
explanation, result = self.generic_visit(name)
# See if the name is local.
source = "%r in locals() is not globals()" % (name.id,)
co = self._compile(source)
try:
local = self.frame.eval(co)
except Exception:
# have to assume it isn't
local = False
if not local:
return name.id, result
return explanation, result
def visit_Compare(self, comp):
left = comp.left
left_explanation, left_result = self.visit(left)
for op, next_op in zip(comp.ops, comp.comparators):
next_explanation, next_result = self.visit(next_op)
op_symbol = operator_map[op.__class__]
explanation = "%s %s %s" % (left_explanation, op_symbol,
next_explanation)
source = "__exprinfo_left %s __exprinfo_right" % (op_symbol,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_left=left_result,
__exprinfo_right=next_result)
except Exception:
raise Failure(explanation)
try:
if not result:
break
except KeyboardInterrupt:
raise
except:
break
left_explanation, left_result = next_explanation, next_result
rcomp = py.code._reprcompare
if rcomp:
res = rcomp(op_symbol, left_result, next_result)
if res:
explanation = res
return explanation, result
def visit_BoolOp(self, boolop):
is_or = isinstance(boolop.op, ast.Or)
explanations = []
for operand in boolop.values:
explanation, result = self.visit(operand)
explanations.append(explanation)
if result == is_or:
break
name = is_or and " or " or " and "
explanation = "(" + name.join(explanations) + ")"
return explanation, result
def visit_UnaryOp(self, unary):
pattern = unary_map[unary.op.__class__]
operand_explanation, operand_result = self.visit(unary.operand)
explanation = pattern % (operand_explanation,)
co = self._compile(pattern % ("__exprinfo_expr",))
try:
result = self.frame.eval(co, __exprinfo_expr=operand_result)
except Exception:
raise Failure(explanation)
return explanation, result
def visit_BinOp(self, binop):
left_explanation, left_result = self.visit(binop.left)
right_explanation, right_result = self.visit(binop.right)
symbol = operator_map[binop.op.__class__]
explanation = "(%s %s %s)" % (left_explanation, symbol,
right_explanation)
source = "__exprinfo_left %s __exprinfo_right" % (symbol,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_left=left_result,
__exprinfo_right=right_result)
except Exception:
raise Failure(explanation)
return explanation, result
def visit_Call(self, call):
func_explanation, func = self.visit(call.func)
arg_explanations = []
ns = {"__exprinfo_func" : func}
arguments = []
for arg in call.args:
arg_explanation, arg_result = self.visit(arg)
arg_name = "__exprinfo_%s" % (len(ns),)
ns[arg_name] = arg_result
arguments.append(arg_name)
arg_explanations.append(arg_explanation)
for keyword in call.keywords:
arg_explanation, arg_result = self.visit(keyword.value)
arg_name = "__exprinfo_%s" % (len(ns),)
ns[arg_name] = arg_result
keyword_source = "%s=%%s" % (keyword.arg)
arguments.append(keyword_source % (arg_name,))
arg_explanations.append(keyword_source % (arg_explanation,))
if call.starargs:
arg_explanation, arg_result = self.visit(call.starargs)
arg_name = "__exprinfo_star"
ns[arg_name] = arg_result
arguments.append("*%s" % (arg_name,))
arg_explanations.append("*%s" % (arg_explanation,))
if call.kwargs:
arg_explanation, arg_result = self.visit(call.kwargs)
arg_name = "__exprinfo_kwds"
ns[arg_name] = arg_result
arguments.append("**%s" % (arg_name,))
arg_explanations.append("**%s" % (arg_explanation,))
args_explained = ", ".join(arg_explanations)
explanation = "%s(%s)" % (func_explanation, args_explained)
args = ", ".join(arguments)
source = "__exprinfo_func(%s)" % (args,)
co = self._compile(source)
try:
result = self.frame.eval(co, **ns)
except Exception:
raise Failure(explanation)
pattern = "%s\n{%s = %s\n}"
rep = self.frame.repr(result)
explanation = pattern % (rep, rep, explanation)
return explanation, result
def _is_builtin_name(self, name):
pattern = "%r not in globals() and %r not in locals()"
source = pattern % (name.id, name.id)
co = self._compile(source)
try:
return self.frame.eval(co)
except Exception:
return False
def visit_Attribute(self, attr):
if not isinstance(attr.ctx, ast.Load):
return self.generic_visit(attr)
source_explanation, source_result = self.visit(attr.value)
explanation = "%s.%s" % (source_explanation, attr.attr)
source = "__exprinfo_expr.%s" % (attr.attr,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_expr=source_result)
except Exception:
raise Failure(explanation)
explanation = "%s\n{%s = %s.%s\n}" % (self.frame.repr(result),
self.frame.repr(result),
source_explanation, attr.attr)
# Check if the attr is from an instance.
source = "%r in getattr(__exprinfo_expr, '__dict__', {})"
source = source % (attr.attr,)
co = self._compile(source)
try:
from_instance = self.frame.eval(co, __exprinfo_expr=source_result)
except Exception:
from_instance = True
if from_instance:
rep = self.frame.repr(result)
pattern = "%s\n{%s = %s\n}"
explanation = pattern % (rep, rep, explanation)
return explanation, result
def visit_Assert(self, assrt):
test_explanation, test_result = self.visit(assrt.test)
if test_explanation.startswith("False\n{False =") and \
test_explanation.endswith("\n"):
test_explanation = test_explanation[15:-2]
explanation = "assert %s" % (test_explanation,)
if not test_result:
try:
raise BuiltinAssertionError
except Exception:
raise Failure(explanation)
return explanation, test_result
def visit_Assign(self, assign):
value_explanation, value_result = self.visit(assign.value)
explanation = "... = %s" % (value_explanation,)
name = ast.Name("__exprinfo_expr", ast.Load(),
lineno=assign.value.lineno,
col_offset=assign.value.col_offset)
new_assign = ast.Assign(assign.targets, name, lineno=assign.lineno,
col_offset=assign.col_offset)
mod = ast.Module([new_assign])
co = self._compile(mod, "exec")
try:
self.frame.exec_(co, __exprinfo_expr=value_result)
except Exception:
raise Failure(explanation)
return explanation, value_result
|
mpl-2.0
|
[
624,
199,
6591,
13197,
3468,
10326,
2058,
315,
702,
9834,
4012,
6762,
20788,
14,
199,
2765,
1077,
3350,
485,
18487,
1753,
14,
647,
21356,
14,
199,
624,
199,
199,
646,
984,
199,
646,
6073,
199,
199,
646,
1134,
199,
504,
1134,
423,
600,
14,
18487,
492,
485,
908,
63,
15228,
12,
22422,
14844,
421,
199,
692,
984,
14,
3246,
14,
2460,
480,
6138,
531,
436,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
12,
499,
304,
272,
327,
1666,
1455,
921,
13017,
14,
27179,
14,
1308,
15,
5237,
1079,
2576,
272,
485,
16006,
275,
1689,
10349,
4619,
401,
298,
13394,
4619,
401,
298,
22401,
4619,
401,
298,
21350,
401,
298,
3917,
4527,
401,
298,
2141,
401,
1598,
298,
1296,
2404,
401,
298,
7599,
4527,
401,
298,
22889,
401,
298,
16051,
401,
298,
2176,
401,
1598,
298,
15713,
401,
298,
5667,
401,
298,
2848,
401,
298,
1646,
401,
298,
2610,
1579,
401,
298,
985,
401,
1598,
298,
1296,
401,
298,
7075,
531,
272,
485,
270,
22862,
275,
1689,
3481,
6172,
401,
298,
2543,
6172,
401,
298,
1767,
401,
298,
5392,
401,
298,
9595,
401,
1598,
298,
21640,
9595,
401,
298,
5375,
401,
298,
1858,
401,
298,
25215,
401,
298,
3917,
401,
298,
3007,
401,
298,
18111,
401,
1598,
298,
12357,
920,
716,
401,
298,
12357,
8694,
1183,
401,
298,
9699,
401,
298,
6295,
401,
298,
6295,
2532,
401,
1598,
298,
4858,
401,
298,
7025,
401,
298,
8561,
401,
298,
4986,
401,
298,
13948,
401,
298,
24055,
531,
272,
485,
3684,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
16006,
9,
272,
485,
9649,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
270,
22862,
9,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
3684,
63,
2415,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
9649,
63,
2415,
199,
2836,
26,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
3684,
9,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
9649,
9,
421,
199,
533,
20367,
8,
1726,
304,
272,
408,
547,
1911,
1830,
6421,
1337,
20788,
1041,
339,
347,
636,
826,
721,
277,
12,
17531,
17364,
267,
291,
14,
2651,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
15228,
275,
17531,
421,
199,
318,
15579,
8,
1365,
12,
2787,
12,
1077,
63,
1633,
29,
797,
304,
272,
3413,
275,
6073,
14,
1122,
8,
1365,
9,
272,
18040,
275,
14245,
2620,
26499,
8,
1943,
9,
272,
862,
26,
267,
18040,
14,
5427,
8,
1494,
9,
272,
871,
20367,
26,
267,
5988,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
267,
372,
664,
5328,
8,
5328,
9,
272,
340,
1077,
63,
1633,
26,
267,
372,
1689,
8,
18487,
3405,
12,
1325,
1380,
652,
1990,
295,
13,
1065,
367,
298,
355,
298,
26514,
13197,
1338,
12,
652,
8103,
440,
2449,
14,
221,
428,
11914,
15293,
26,
298,
355,
298,
3357,
702,
3965,
2544,
314,
702,
503,
675,
1553,
889,
13,
479,
6320,
199,
199,
318,
1255,
8,
1997,
3219,
63,
604,
12,
2787,
29,
403,
304,
272,
340,
2787,
365,
488,
26,
267,
2787,
275,
1134,
14,
600,
14,
3160,
8,
1274,
423,
20912,
8,
17,
430,
272,
372,
15579,
8,
1997,
3219,
63,
604,
12,
2787,
9,
199,
199,
318,
664,
5328,
8,
5328,
304,
272,
17531,
275,
485,
908,
63,
15228,
8,
5328,
14,
15228,
9,
272,
574,
275,
5988,
14,
2651,
59,
17,
61,
272,
340,
620,
8,
585,
304,
267,
2385,
275,
17531,
14,
7644,
342,
267,
340,
440,
2385,
26,
288,
2385,
14,
740,
10804,
267,
2385,
59,
16,
61,
847,
298,
5213,
450,
83,
2,
450,
334,
585,
4258,
267,
17531,
275,
1867,
78,
1674,
904,
8,
1278,
9,
272,
1318,
275,
2071,
83,
26,
450,
83,
2,
450,
334,
5328,
14,
2651,
59,
16,
17979,
354,
3108,
17531,
9,
272,
340,
1318,
14,
2460,
480,
14844,
26,
702,
26699,
267,
1318,
275,
1318,
59,
975,
2938,
272,
372,
1318,
421,
199,
3856,
63,
1130,
275,
469,
272,
6073,
14,
4734,
2844,
520,
15733,
401,
272,
6073,
14,
4734,
56,
269,
520,
18129,
401,
272,
6073,
14,
4734,
3325,
520,
11746,
401,
272,
6073,
14,
44,
14379,
520,
3886,
28,
401,
272,
6073,
14,
50,
14379,
520,
298,
1140,
401,
272,
6073,
14,
1123,
520,
7210,
401,
272,
6073,
14,
2610,
520,
3905,
401,
272,
6073,
14,
30233,
520,
8969,
401,
272,
6073,
14,
24305,
520,
3286,
401,
272,
6073,
14,
38,
6367,
24305,
520,
23057,
401,
272,
6073,
14,
9871,
520,
2071,
401,
272,
6073,
14,
19706,
520,
298,
389,
401,
272,
6073,
14,
1763,
19706,
520,
298,
1111,
401,
272,
6073,
14,
31252,
520,
3886,
401,
272,
6073,
14,
31252,
37,
520,
3886,
11107,
272,
6073,
14,
39,
84,
520,
298,
7166,
272,
6073,
14,
39,
84,
37,
520,
298,
8119,
401,
272,
6073,
14,
23432,
520,
298,
538,
401,
272,
6073,
14,
1831,
520,
298,
374,
401,
272,
6073,
14,
1831,
1763,
520,
298,
374,
440,
401,
272,
6073,
14,
607,
520,
298,
262,
401,
272,
6073,
14,
1763,
607,
520,
298,
1397,
315,
2,
199,
93,
199,
199,
13124,
63,
1130,
275,
469,
272,
6073,
14,
1763,
520,
298,
1397,
450,
83,
401,
272,
6073,
14,
26498,
520,
26810,
5,
83,
401,
272,
6073,
14,
1668,
456,
520,
298,
3295,
83,
401,
272,
6073,
14,
53,
1123,
520,
7210,
5,
83,
2,
199,
93,
421,
199,
533,
14245,
2620,
26499,
8,
1810,
14,
1716,
18324,
304,
272,
408,
2620,
25133,
20788,
3380,
370,
486,
274,
455,
2997,
10201,
2556,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2787,
304,
267,
291,
14,
1943,
275,
2787,
339,
347,
7809,
63,
5427,
8,
277,
12,
1031,
304,
267,
327,
481,
5421,
1380,
781,
2793,
1133,
1172,
282,
4539,
4514,
14,
267,
340,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
288,
3413,
275,
6073,
14,
9093,
8
] |
[
199,
6591,
13197,
3468,
10326,
2058,
315,
702,
9834,
4012,
6762,
20788,
14,
199,
2765,
1077,
3350,
485,
18487,
1753,
14,
647,
21356,
14,
199,
624,
199,
199,
646,
984,
199,
646,
6073,
199,
199,
646,
1134,
199,
504,
1134,
423,
600,
14,
18487,
492,
485,
908,
63,
15228,
12,
22422,
14844,
421,
199,
692,
984,
14,
3246,
14,
2460,
480,
6138,
531,
436,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
12,
499,
304,
272,
327,
1666,
1455,
921,
13017,
14,
27179,
14,
1308,
15,
5237,
1079,
2576,
272,
485,
16006,
275,
1689,
10349,
4619,
401,
298,
13394,
4619,
401,
298,
22401,
4619,
401,
298,
21350,
401,
298,
3917,
4527,
401,
298,
2141,
401,
1598,
298,
1296,
2404,
401,
298,
7599,
4527,
401,
298,
22889,
401,
298,
16051,
401,
298,
2176,
401,
1598,
298,
15713,
401,
298,
5667,
401,
298,
2848,
401,
298,
1646,
401,
298,
2610,
1579,
401,
298,
985,
401,
1598,
298,
1296,
401,
298,
7075,
531,
272,
485,
270,
22862,
275,
1689,
3481,
6172,
401,
298,
2543,
6172,
401,
298,
1767,
401,
298,
5392,
401,
298,
9595,
401,
1598,
298,
21640,
9595,
401,
298,
5375,
401,
298,
1858,
401,
298,
25215,
401,
298,
3917,
401,
298,
3007,
401,
298,
18111,
401,
1598,
298,
12357,
920,
716,
401,
298,
12357,
8694,
1183,
401,
298,
9699,
401,
298,
6295,
401,
298,
6295,
2532,
401,
1598,
298,
4858,
401,
298,
7025,
401,
298,
8561,
401,
298,
4986,
401,
298,
13948,
401,
298,
24055,
531,
272,
485,
3684,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
16006,
9,
272,
485,
9649,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
270,
22862,
9,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
3684,
63,
2415,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
9649,
63,
2415,
199,
2836,
26,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
3684,
9,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
9649,
9,
421,
199,
533,
20367,
8,
1726,
304,
272,
408,
547,
1911,
1830,
6421,
1337,
20788,
1041,
339,
347,
636,
826,
721,
277,
12,
17531,
17364,
267,
291,
14,
2651,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
15228,
275,
17531,
421,
199,
318,
15579,
8,
1365,
12,
2787,
12,
1077,
63,
1633,
29,
797,
304,
272,
3413,
275,
6073,
14,
1122,
8,
1365,
9,
272,
18040,
275,
14245,
2620,
26499,
8,
1943,
9,
272,
862,
26,
267,
18040,
14,
5427,
8,
1494,
9,
272,
871,
20367,
26,
267,
5988,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
267,
372,
664,
5328,
8,
5328,
9,
272,
340,
1077,
63,
1633,
26,
267,
372,
1689,
8,
18487,
3405,
12,
1325,
1380,
652,
1990,
295,
13,
1065,
367,
298,
355,
298,
26514,
13197,
1338,
12,
652,
8103,
440,
2449,
14,
221,
428,
11914,
15293,
26,
298,
355,
298,
3357,
702,
3965,
2544,
314,
702,
503,
675,
1553,
889,
13,
479,
6320,
199,
199,
318,
1255,
8,
1997,
3219,
63,
604,
12,
2787,
29,
403,
304,
272,
340,
2787,
365,
488,
26,
267,
2787,
275,
1134,
14,
600,
14,
3160,
8,
1274,
423,
20912,
8,
17,
430,
272,
372,
15579,
8,
1997,
3219,
63,
604,
12,
2787,
9,
199,
199,
318,
664,
5328,
8,
5328,
304,
272,
17531,
275,
485,
908,
63,
15228,
8,
5328,
14,
15228,
9,
272,
574,
275,
5988,
14,
2651,
59,
17,
61,
272,
340,
620,
8,
585,
304,
267,
2385,
275,
17531,
14,
7644,
342,
267,
340,
440,
2385,
26,
288,
2385,
14,
740,
10804,
267,
2385,
59,
16,
61,
847,
298,
5213,
450,
83,
2,
450,
334,
585,
4258,
267,
17531,
275,
1867,
78,
1674,
904,
8,
1278,
9,
272,
1318,
275,
2071,
83,
26,
450,
83,
2,
450,
334,
5328,
14,
2651,
59,
16,
17979,
354,
3108,
17531,
9,
272,
340,
1318,
14,
2460,
480,
14844,
26,
702,
26699,
267,
1318,
275,
1318,
59,
975,
2938,
272,
372,
1318,
421,
199,
3856,
63,
1130,
275,
469,
272,
6073,
14,
4734,
2844,
520,
15733,
401,
272,
6073,
14,
4734,
56,
269,
520,
18129,
401,
272,
6073,
14,
4734,
3325,
520,
11746,
401,
272,
6073,
14,
44,
14379,
520,
3886,
28,
401,
272,
6073,
14,
50,
14379,
520,
298,
1140,
401,
272,
6073,
14,
1123,
520,
7210,
401,
272,
6073,
14,
2610,
520,
3905,
401,
272,
6073,
14,
30233,
520,
8969,
401,
272,
6073,
14,
24305,
520,
3286,
401,
272,
6073,
14,
38,
6367,
24305,
520,
23057,
401,
272,
6073,
14,
9871,
520,
2071,
401,
272,
6073,
14,
19706,
520,
298,
389,
401,
272,
6073,
14,
1763,
19706,
520,
298,
1111,
401,
272,
6073,
14,
31252,
520,
3886,
401,
272,
6073,
14,
31252,
37,
520,
3886,
11107,
272,
6073,
14,
39,
84,
520,
298,
7166,
272,
6073,
14,
39,
84,
37,
520,
298,
8119,
401,
272,
6073,
14,
23432,
520,
298,
538,
401,
272,
6073,
14,
1831,
520,
298,
374,
401,
272,
6073,
14,
1831,
1763,
520,
298,
374,
440,
401,
272,
6073,
14,
607,
520,
298,
262,
401,
272,
6073,
14,
1763,
607,
520,
298,
1397,
315,
2,
199,
93,
199,
199,
13124,
63,
1130,
275,
469,
272,
6073,
14,
1763,
520,
298,
1397,
450,
83,
401,
272,
6073,
14,
26498,
520,
26810,
5,
83,
401,
272,
6073,
14,
1668,
456,
520,
298,
3295,
83,
401,
272,
6073,
14,
53,
1123,
520,
7210,
5,
83,
2,
199,
93,
421,
199,
533,
14245,
2620,
26499,
8,
1810,
14,
1716,
18324,
304,
272,
408,
2620,
25133,
20788,
3380,
370,
486,
274,
455,
2997,
10201,
2556,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2787,
304,
267,
291,
14,
1943,
275,
2787,
339,
347,
7809,
63,
5427,
8,
277,
12,
1031,
304,
267,
327,
481,
5421,
1380,
781,
2793,
1133,
1172,
282,
4539,
4514,
14,
267,
340,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
288,
3413,
275,
6073,
14,
9093,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
kubeflow/kfserving
|
python/lgbserver/lgbserver/test_lightgbm_model_repository.py
|
1
|
1383
|
# Copyright 2020 kubeflow.org.
#
# 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 os
import pytest
from lgbserver import LightGBMModelRepository
model_dir = os.path.join(os.path.dirname(__file__), "example_model")
invalid_model_dir = os.path.join(os.path.dirname(__file__), "model_not_exist", "model")
@pytest.mark.asyncio
async def test_load():
repo = LightGBMModelRepository(model_dir=model_dir, nthread=1)
model_name = "model"
await repo.load(model_name)
assert repo.get_model(model_name) is not None
assert repo.is_model_ready(model_name)
@pytest.mark.asyncio
async def test_load_fail():
repo = LightGBMModelRepository(model_dir=model_dir, nthread=1)
model_name = "model"
with pytest.raises(Exception):
await repo.load(model_name)
assert repo.get_model(model_name) is None
assert not repo.is_model_ready(model_name)
|
apache-2.0
|
[
3,
1898,
25455,
23091,
1659,
14,
1308,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
4613,
199,
504,
634,
4908,
1000,
492,
29684,
6487,
45,
1685,
15614,
199,
199,
1238,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
2694,
63,
1238,
531,
199,
3197,
63,
1238,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
1238,
63,
1397,
63,
4494,
401,
298,
1238,
531,
421,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
912,
837,
272,
3831,
275,
29684,
6487,
45,
1685,
15614,
8,
1238,
63,
694,
29,
1238,
63,
694,
12,
302,
2671,
29,
17,
9,
272,
1402,
63,
354,
275,
298,
1238,
2,
272,
5517,
3831,
14,
912,
8,
1238,
63,
354,
9,
272,
702,
3831,
14,
362,
63,
1238,
8,
1238,
63,
354,
9,
365,
440,
488,
272,
702,
3831,
14,
374,
63,
1238,
63,
2179,
8,
1238,
63,
354,
9,
421,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
912,
63,
1633,
837,
272,
3831,
275,
29684,
6487,
45,
1685,
15614,
8,
1238,
63,
694,
29,
1238,
63,
694,
12,
302,
2671,
29,
17,
9,
272,
1402,
63,
354,
275,
298,
1238,
2,
272,
543,
4613,
14,
3536,
8,
1726,
304,
267,
5517,
3831,
14,
912,
8,
1238,
63,
354,
9,
267,
702,
3831,
14,
362,
63,
1238,
8,
1238,
63,
354,
9,
365,
488,
267,
702,
440,
3831,
14,
374,
63,
1238,
63,
2179,
8,
1238,
63,
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
] |
[
1898,
25455,
23091,
1659,
14,
1308,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
4613,
199,
504,
634,
4908,
1000,
492,
29684,
6487,
45,
1685,
15614,
199,
199,
1238,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
2694,
63,
1238,
531,
199,
3197,
63,
1238,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
1238,
63,
1397,
63,
4494,
401,
298,
1238,
531,
421,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
912,
837,
272,
3831,
275,
29684,
6487,
45,
1685,
15614,
8,
1238,
63,
694,
29,
1238,
63,
694,
12,
302,
2671,
29,
17,
9,
272,
1402,
63,
354,
275,
298,
1238,
2,
272,
5517,
3831,
14,
912,
8,
1238,
63,
354,
9,
272,
702,
3831,
14,
362,
63,
1238,
8,
1238,
63,
354,
9,
365,
440,
488,
272,
702,
3831,
14,
374,
63,
1238,
63,
2179,
8,
1238,
63,
354,
9,
421,
199,
32,
4462,
14,
1657,
14,
19343,
199,
4146,
347,
511,
63,
912,
63,
1633,
837,
272,
3831,
275,
29684,
6487,
45,
1685,
15614,
8,
1238,
63,
694,
29,
1238,
63,
694,
12,
302,
2671,
29,
17,
9,
272,
1402,
63,
354,
275,
298,
1238,
2,
272,
543,
4613,
14,
3536,
8,
1726,
304,
267,
5517,
3831,
14,
912,
8,
1238,
63,
354,
9,
267,
702,
3831,
14,
362,
63,
1238,
8,
1238,
63,
354,
9,
365,
488,
267,
702,
440,
3831,
14,
374,
63,
1238,
63,
2179,
8,
1238,
63,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Thermi/ocfs2-tools
|
ocfs2console/ocfs2interface/fsck.py
|
8
|
2563
|
# OCFS2Console - GUI frontend for OCFS2 management and debugging
# Copyright (C) 2005 Oracle. 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 021110-1307, USA.
import gtk
import gobject
from terminal import TerminalDialog, terminal_ok as fsck_ok
base_command = ('fsck.ocfs2',)
def fsck_volume(parent, device, check=False):
if check:
check_str = 'check'
else:
check_str = 'repair'
title = 'File System ' + check_str.capitalize()
dialog = TerminalDialog(parent=parent, title=title)
terminal = dialog.terminal
dialog.finished = False
terminal.connect('child-exited', child_exited, dialog)
command = fsck_command(device, check)
gobject.idle_add(start_command, terminal, command, dialog)
while 1:
dialog.run()
if dialog.finished:
break
msg = ('File system %s is still running. You should not close this '
'window until it is finished' % check_str)
info = gtk.MessageDialog(parent=dialog,
flags=gtk.DIALOG_DESTROY_WITH_PARENT,
type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_CLOSE,
message_format=msg)
info.run()
info.destroy()
dialog.destroy()
def start_command(terminal, command, dialog):
terminal.fork_command(command=command[0], argv=command)
return False
def child_exited(terminal, dialog):
dialog.finished = True
def fsck_command(device, check):
command = list(base_command)
if check:
command.append('-n')
else:
command.append('-y')
command.append("'%s'" % device)
realcommand = '%s; sleep 1' % ' '.join(command)
return ['/bin/sh', '-c', realcommand]
def main():
import sys
fsck_volume(None, sys.argv[1], check=True)
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3,
593,
5487,
51,
18,
9270,
446,
17160,
22523,
367,
593,
5487,
51,
18,
10041,
436,
10201,
199,
3,
1898,
334,
35,
9,
11811,
15309,
14,
221,
2900,
4481,
4644,
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,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
12497,
845,
709,
13,
13421,
12,
8217,
14,
199,
199,
646,
8116,
199,
646,
25595,
199,
199,
504,
11167,
492,
20429,
279,
5619,
12,
11167,
63,
745,
465,
7449,
346,
63,
745,
199,
199,
1095,
63,
1531,
275,
661,
2319,
346,
14,
679,
2319,
18,
9538,
199,
199,
318,
7449,
346,
63,
2405,
8,
1708,
12,
2243,
12,
1104,
29,
797,
304,
272,
340,
1104,
26,
267,
1104,
63,
495,
275,
283,
1074,
7,
272,
587,
26,
267,
1104,
63,
495,
275,
283,
25279,
7,
339,
2538,
275,
283,
1173,
6187,
283,
435,
1104,
63,
495,
14,
18351,
342,
339,
9592,
275,
20429,
279,
5619,
8,
1708,
29,
1708,
12,
2538,
29,
1213,
9,
272,
11167,
275,
9592,
14,
12010,
339,
9592,
14,
8669,
275,
756,
272,
11167,
14,
2242,
360,
1739,
13,
32290,
297,
1982,
63,
32290,
12,
9592,
9,
339,
1414,
275,
7449,
346,
63,
1531,
8,
1782,
12,
1104,
9,
272,
25595,
14,
12000,
63,
525,
8,
928,
63,
1531,
12,
11167,
12,
1414,
12,
9592,
9,
339,
1830,
413,
26,
267,
9592,
14,
1065,
342,
398,
340,
9592,
14,
8669,
26,
288,
2059,
398,
1499,
275,
661,
1173,
2656,
450,
83,
365,
5139,
3879,
14,
2047,
1077,
440,
4002,
642,
283,
2049,
283,
3806,
5133,
652,
365,
9158,
7,
450,
1104,
63,
495,
9,
398,
2256,
275,
8116,
14,
2209,
5619,
8,
1708,
29,
7196,
12,
639,
3285,
29,
12275,
14,
1914,
23622,
63,
19374,
1092,
57,
63,
9139,
63,
20562,
12,
639,
730,
29,
12275,
14,
8272,
63,
9171,
12,
639,
15766,
29,
12275,
14,
13272,
51,
63,
18219,
12,
639,
1245,
63,
908,
29,
1328,
9,
267,
2256,
14,
1065,
342,
267,
2256,
14,
7237,
342,
20950,
9592,
14,
7237,
342,
199,
199,
318,
1343,
63,
1531,
8,
12010,
12,
1414,
12,
9592,
304,
272,
11167,
14,
11796,
63,
1531,
8,
1531,
29,
1531,
59,
16,
467,
9238,
29,
1531,
9,
272,
372,
756,
199,
199,
318,
1982,
63,
32290,
8,
12010,
12,
9592,
304,
272,
9592,
14,
8669,
275,
715,
199,
199,
318,
7449,
346,
63,
1531,
8,
1782,
12,
1104,
304,
272,
1414,
275,
769,
8,
1095,
63,
1531,
9,
339,
340,
1104,
26,
267,
1414,
14,
740,
3654,
78,
358,
272,
587,
26,
267,
1414,
14,
740,
3654,
89,
358,
339,
1414,
14,
740,
21065,
83,
4065,
450,
2243,
9,
339,
3363,
1531,
275,
1543,
83,
27,
9435,
413,
7,
450,
283,
1987,
904,
8,
1531,
9,
339,
372,
18744,
1393,
15,
609,
297,
2475,
67,
297,
3363,
1531,
61,
199,
199,
318,
2446,
837,
272,
492,
984,
272,
7449,
346,
63,
2405,
8,
403,
12,
984,
14,
3020,
59,
17,
467,
1104,
29,
549,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
593,
5487,
51,
18,
9270,
446,
17160,
22523,
367,
593,
5487,
51,
18,
10041,
436,
10201,
199,
3,
1898,
334,
35,
9,
11811,
15309,
14,
221,
2900,
4481,
4644,
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,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
12497,
845,
709,
13,
13421,
12,
8217,
14,
199,
199,
646,
8116,
199,
646,
25595,
199,
199,
504,
11167,
492,
20429,
279,
5619,
12,
11167,
63,
745,
465,
7449,
346,
63,
745,
199,
199,
1095,
63,
1531,
275,
661,
2319,
346,
14,
679,
2319,
18,
9538,
199,
199,
318,
7449,
346,
63,
2405,
8,
1708,
12,
2243,
12,
1104,
29,
797,
304,
272,
340,
1104,
26,
267,
1104,
63,
495,
275,
283,
1074,
7,
272,
587,
26,
267,
1104,
63,
495,
275,
283,
25279,
7,
339,
2538,
275,
283,
1173,
6187,
283,
435,
1104,
63,
495,
14,
18351,
342,
339,
9592,
275,
20429,
279,
5619,
8,
1708,
29,
1708,
12,
2538,
29,
1213,
9,
272,
11167,
275,
9592,
14,
12010,
339,
9592,
14,
8669,
275,
756,
272,
11167,
14,
2242,
360,
1739,
13,
32290,
297,
1982,
63,
32290,
12,
9592,
9,
339,
1414,
275,
7449,
346,
63,
1531,
8,
1782,
12,
1104,
9,
272,
25595,
14,
12000,
63,
525,
8,
928,
63,
1531,
12,
11167,
12,
1414,
12,
9592,
9,
339,
1830,
413,
26,
267,
9592,
14,
1065,
342,
398,
340,
9592,
14,
8669,
26,
288,
2059,
398,
1499,
275,
661,
1173,
2656,
450,
83,
365,
5139,
3879,
14,
2047,
1077,
440,
4002,
642,
283,
2049,
283,
3806,
5133,
652,
365,
9158,
7,
450,
1104,
63,
495,
9,
398,
2256,
275,
8116,
14,
2209,
5619,
8,
1708,
29,
7196,
12,
639,
3285,
29,
12275,
14,
1914,
23622,
63,
19374,
1092,
57,
63,
9139,
63,
20562,
12,
639,
730,
29,
12275,
14,
8272,
63,
9171,
12,
639,
15766,
29,
12275,
14,
13272,
51,
63,
18219,
12,
639,
1245,
63,
908,
29,
1328,
9,
267,
2256,
14,
1065,
342,
267,
2256,
14,
7237,
342,
20950,
9592,
14,
7237,
342,
199,
199,
318,
1343,
63,
1531,
8,
12010,
12,
1414,
12,
9592,
304,
272,
11167,
14,
11796,
63,
1531,
8,
1531,
29,
1531,
59,
16,
467,
9238,
29,
1531,
9,
272,
372,
756,
199,
199,
318,
1982,
63,
32290,
8,
12010,
12,
9592,
304,
272,
9592,
14,
8669,
275,
715,
199,
199,
318,
7449,
346,
63,
1531,
8,
1782,
12,
1104,
304,
272,
1414,
275,
769,
8,
1095,
63,
1531,
9,
339,
340,
1104,
26,
267,
1414,
14,
740,
3654,
78,
358,
272,
587,
26,
267,
1414,
14,
740,
3654,
89,
358,
339,
1414,
14,
740,
21065,
83,
4065,
450,
2243,
9,
339,
3363,
1531,
275,
1543,
83,
27,
9435,
413,
7,
450,
283,
1987,
904,
8,
1531,
9,
339,
372,
18744,
1393,
15,
609,
297,
2475,
67,
297,
3363,
1531,
61,
199,
199,
318,
2446,
837,
272,
492,
984,
272,
7449,
346,
63,
2405,
8,
403,
12,
984,
14,
3020,
59,
17,
467,
1104,
29,
549,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
damdam-s/hr
|
hr_language/models/__init__.py
|
27
|
1028
|
# -*- encoding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from . import hr_language
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
11490,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
428,
1214,
19142,
13,
667,
3621,
10130,
8642,
1014,
921,
1544,
14,
23374,
19142,
667,
3621,
5135,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
11490,
199,
199,
504,
1275,
492,
16140,
63,
3671,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
11490,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
428,
1214,
19142,
13,
667,
3621,
10130,
8642,
1014,
921,
1544,
14,
23374,
19142,
667,
3621,
5135,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
11490,
199,
199,
504,
1275,
492,
16140,
63,
3671,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
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Construct Quad Tree/0427-Construct Quad Tree.py
|
1
|
1392
|
# Definition for a QuadTree node.
class Node:
def __init__(self, val, isLeaf, topLeft, topRight, bottomLeft, bottomRight):
self.val = val
self.isLeaf = isLeaf
self.topLeft = topLeft
self.topRight = topRight
self.bottomLeft = bottomLeft
self.bottomRight = bottomRight
class Solution:
def construct(self, grid: List[List[int]]) -> 'Node':
if not grid:
return None
def construct(row1, col1, row2, col2):
if row1 == row2 and col1 == col2:
return Node(bool(grid[row1][col1]), True, None, None, None, None)
topLeft = construct(row1, col1, (row1 + row2)//2, (col1 + col2)//2)
topRight = construct(row1, (col1 + col2)//2 + 1, (row1 + row2)//2, col2)
bottomLeft = construct((row1 + row2)//2 + 1, col1, row2, (col1 + col2)//2)
bottomRight = construct((row1 + row2)//2 + 1, (col1 + col2)//2 + 1, row2, col2)
if topLeft.isLeaf and topRight.isLeaf and bottomLeft.isLeaf and bottomRight.isLeaf and \
topLeft.val == topRight.val == bottomLeft.val == bottomRight.val:
return Node(topLeft.val, True, None, None, None, None)
else:
return Node(True, False, topLeft, topRight, bottomLeft, bottomRight)
return construct(0, 0, len(grid) - 1, len(grid[0]) - 1)
|
mit
|
[
3,
29398,
367,
282,
5843,
350,
3987,
1031,
14,
199,
533,
5013,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
365,
20475,
12,
2746,
8185,
12,
2746,
9121,
12,
9048,
8185,
12,
9048,
9121,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
374,
20475,
275,
365,
20475,
267,
291,
14,
2119,
8185,
275,
2746,
8185,
267,
291,
14,
2119,
9121,
275,
2746,
9121,
267,
291,
14,
8305,
8185,
275,
9048,
8185,
267,
291,
14,
8305,
9121,
275,
9048,
9121,
199,
199,
533,
9274,
26,
272,
347,
6982,
8,
277,
12,
6068,
26,
3820,
59,
1296,
59,
442,
3934,
1035,
283,
1716,
356,
267,
340,
440,
6068,
26,
288,
372,
488,
267,
347,
6982,
8,
1143,
17,
12,
1048,
17,
12,
1962,
18,
12,
1048,
18,
304,
288,
340,
1962,
17,
508,
1962,
18,
436,
1048,
17,
508,
1048,
18,
26,
355,
372,
5013,
8,
2245,
8,
3825,
59,
1143,
17,
1527,
761,
17,
2522,
715,
12,
488,
12,
488,
12,
488,
12,
488,
9,
288,
2746,
8185,
275,
6982,
8,
1143,
17,
12,
1048,
17,
12,
334,
1143,
17,
435,
1962,
18,
28428,
18,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
9,
288,
2746,
9121,
275,
6982,
8,
1143,
17,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
435,
413,
12,
334,
1143,
17,
435,
1962,
18,
28428,
18,
12,
1048,
18,
9,
288,
9048,
8185,
275,
6982,
1332,
1143,
17,
435,
1962,
18,
28428,
18,
435,
413,
12,
1048,
17,
12,
1962,
18,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
9,
288,
9048,
9121,
275,
6982,
1332,
1143,
17,
435,
1962,
18,
28428,
18,
435,
413,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
435,
413,
12,
1962,
18,
12,
1048,
18,
9,
288,
340,
2746,
8185,
14,
374,
20475,
436,
2746,
9121,
14,
374,
20475,
436,
9048,
8185,
14,
374,
20475,
436,
9048,
9121,
14,
374,
20475,
436,
971,
355,
2746,
8185,
14,
637,
508,
2746,
9121,
14,
637,
508,
9048,
8185,
14,
637,
508,
9048,
9121,
14,
637,
26,
355,
372,
5013,
8,
2119,
8185,
14,
637,
12,
715,
12,
488,
12,
488,
12,
488,
12,
488,
9,
288,
587,
26,
355,
372,
5013,
8,
549,
12,
756,
12,
2746,
8185,
12,
2746,
9121,
12,
9048,
8185,
12,
9048,
9121,
9,
10631,
372,
6982,
8,
16,
12,
378,
12,
822,
8,
3825,
9,
446,
413,
12,
822,
8,
3825,
59,
16,
566,
446,
413,
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
] |
[
29398,
367,
282,
5843,
350,
3987,
1031,
14,
199,
533,
5013,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
365,
20475,
12,
2746,
8185,
12,
2746,
9121,
12,
9048,
8185,
12,
9048,
9121,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
374,
20475,
275,
365,
20475,
267,
291,
14,
2119,
8185,
275,
2746,
8185,
267,
291,
14,
2119,
9121,
275,
2746,
9121,
267,
291,
14,
8305,
8185,
275,
9048,
8185,
267,
291,
14,
8305,
9121,
275,
9048,
9121,
199,
199,
533,
9274,
26,
272,
347,
6982,
8,
277,
12,
6068,
26,
3820,
59,
1296,
59,
442,
3934,
1035,
283,
1716,
356,
267,
340,
440,
6068,
26,
288,
372,
488,
267,
347,
6982,
8,
1143,
17,
12,
1048,
17,
12,
1962,
18,
12,
1048,
18,
304,
288,
340,
1962,
17,
508,
1962,
18,
436,
1048,
17,
508,
1048,
18,
26,
355,
372,
5013,
8,
2245,
8,
3825,
59,
1143,
17,
1527,
761,
17,
2522,
715,
12,
488,
12,
488,
12,
488,
12,
488,
9,
288,
2746,
8185,
275,
6982,
8,
1143,
17,
12,
1048,
17,
12,
334,
1143,
17,
435,
1962,
18,
28428,
18,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
9,
288,
2746,
9121,
275,
6982,
8,
1143,
17,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
435,
413,
12,
334,
1143,
17,
435,
1962,
18,
28428,
18,
12,
1048,
18,
9,
288,
9048,
8185,
275,
6982,
1332,
1143,
17,
435,
1962,
18,
28428,
18,
435,
413,
12,
1048,
17,
12,
1962,
18,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
9,
288,
9048,
9121,
275,
6982,
1332,
1143,
17,
435,
1962,
18,
28428,
18,
435,
413,
12,
334,
761,
17,
435,
1048,
18,
28428,
18,
435,
413,
12,
1962,
18,
12,
1048,
18,
9,
288,
340,
2746,
8185,
14,
374,
20475,
436,
2746,
9121,
14,
374,
20475,
436,
9048,
8185,
14,
374,
20475,
436,
9048,
9121,
14,
374,
20475,
436,
971,
355,
2746,
8185,
14,
637,
508,
2746,
9121,
14,
637,
508,
9048,
8185,
14,
637,
508,
9048,
9121,
14,
637,
26,
355,
372,
5013,
8,
2119,
8185,
14,
637,
12,
715,
12,
488,
12,
488,
12,
488,
12,
488,
9,
288,
587,
26,
355,
372,
5013,
8,
549,
12,
756,
12,
2746,
8185,
12,
2746,
9121,
12,
9048,
8185,
12,
9048,
9121,
9,
10631,
372,
6982,
8,
16,
12,
378,
12,
822,
8,
3825,
9,
446,
413,
12,
822,
8,
3825,
59,
16,
566,
446,
413,
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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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
] |
matthewzimmer/carnd-behavioral-cloning
|
zimpy/camera_preprocessor.py
|
1
|
1757
|
import cv2
import numpy as np
from scipy import misc
def flip_image(image_array, steering_angle):
return np.fliplr(image_array), -steering_angle
def preprocess_image(image_array, output_shape=None):
if output_shape is None:
output_shape = (66, 200)
image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2YUV)
# [y1:y2, x1:x2] - crops top portion as well as car's hood from image
image_array = image_array[50:140, 0:320]
# resize image to output_shape
image_array = cv2.resize(image_array, (output_shape[1], output_shape[0]), interpolation=cv2.INTER_AREA)
# image_array = image_array / 255 - 0.5
# image_array = image_array / 127.5 - 1.
# image_array = cv2.normalize(image_array, image_array, norm_type=cv2.NORM_MINMAX)
return image_array
def predict_images(model):
images = [
# ('/Users/matthewz/git/udacity/carnd/carnd-behavioral-cloning/IMG/center_2016_12_12_14_25_04_974.jpg', -0.1769547),
# ('/Users/matthewz/git/udacity/carnd/carnd-behavioral-cloning/IMG/center_2016_12_12_14_25_00_642.jpg', 0.1575889),
# ('/Users/matthewz/git/udacity/carnd/carnd-behavioral-cloning/IMG/center_2016_12_12_14_48_33_665.jpg', 0),
# ('/Users/matthewz/git/udacity/carnd/carnd-behavioral-cloning/IMG/center_2016_12_12_14_48_34_811.jpg', -0.01234567),
# ('/Users/matthewz/git/udacity/carnd/carnd-behavioral-cloning/IMG/center_2016_12_12_14_48_38_968.jpg', -0.1479061),
]
for image_tup in images:
image_array = misc.imread(image_tup[0])
image_array = preprocess_image(image_array)
pred = float(model.predict(image_array[None, :, :, :], batch_size=1))
true = float(image_tup[1])
print('P: {} T: {}'.format(pred, true))
|
mit
|
[
646,
6277,
18,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
18576,
421,
199,
318,
18761,
63,
1569,
8,
1569,
63,
1144,
12,
20345,
15663,
63,
4593,
304,
272,
372,
980,
14,
70,
317,
1168,
82,
8,
1569,
63,
1144,
395,
446,
1597,
15663,
63,
4593,
421,
199,
318,
23351,
63,
1569,
8,
1569,
63,
1144,
12,
1072,
63,
1392,
29,
403,
304,
272,
340,
1072,
63,
1392,
365,
488,
26,
267,
1072,
63,
1392,
275,
334,
1272,
12,
1926,
9,
272,
1834,
63,
1144,
275,
6277,
18,
14,
5107,
84,
4117,
8,
1569,
63,
1144,
12,
6277,
18,
14,
7134,
63,
34,
3975,
18,
57,
15110,
9,
339,
327,
359,
89,
17,
26,
89,
18,
12,
671,
17,
26,
88,
18,
61,
446,
286,
26307,
2746,
18046,
465,
5521,
465,
9590,
1159,
2636,
364,
687,
1834,
272,
1834,
63,
1144,
275,
1834,
63,
1144,
59,
1400,
26,
10037,
12,
378,
26,
12122,
61,
339,
327,
15210,
1834,
370,
1072,
63,
1392,
272,
1834,
63,
1144,
275,
6277,
18,
14,
8709,
8,
1569,
63,
1144,
12,
334,
1199,
63,
1392,
59,
17,
467,
1072,
63,
1392,
59,
16,
2522,
14046,
29,
5107,
18,
14,
3843,
63,
28591,
9,
339,
327,
1834,
63,
1144,
275,
1834,
63,
1144,
1182,
5450,
446,
378,
14,
21,
272,
327,
1834,
63,
1144,
275,
1834,
63,
1144,
1182,
12792,
14,
21,
446,
413,
14,
272,
327,
1834,
63,
1144,
275,
6277,
18,
14,
7721,
8,
1569,
63,
1144,
12,
1834,
63,
1144,
12,
6316,
63,
466,
29,
5107,
18,
14,
46,
8832,
63,
4896,
4283,
9,
339,
372,
1834,
63,
1144,
421,
199,
318,
12610,
63,
4782,
8,
1238,
304,
272,
5935,
275,
359,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
821,
63,
966,
63,
31125,
14,
8476,
297,
446,
16,
14,
1196,
1876,
16710,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
821,
63,
383,
63,
15463,
14,
8476,
297,
378,
14,
1046,
2194,
13976,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1153,
63,
16373,
14,
8476,
297,
378,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1082,
63,
26623,
14,
8476,
297,
446,
16,
14,
9461,
5308,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1703,
63,
25,
2333,
14,
8476,
297,
446,
16,
14,
1079,
1965,
22531,
395,
272,
1622,
339,
367,
1834,
63,
17034,
315,
5935,
26,
267,
1834,
63,
1144,
275,
18576,
14,
1017,
739,
8,
1569,
63,
17034,
59,
16,
566,
267,
1834,
63,
1144,
275,
23351,
63,
1569,
8,
1569,
63,
1144,
9,
267,
8869,
275,
2069,
8,
1238,
14,
6892,
8,
1569,
63,
1144,
59,
403,
12,
13785,
13785,
26450,
3522,
63,
890,
29,
17,
430,
267,
2549,
275,
2069,
8,
1569,
63,
17034,
59,
17,
566,
267,
870,
360,
48,
26,
1052,
259,
377,
26,
9499,
908,
8,
5991,
12,
2549,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6277,
18,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
18576,
421,
199,
318,
18761,
63,
1569,
8,
1569,
63,
1144,
12,
20345,
15663,
63,
4593,
304,
272,
372,
980,
14,
70,
317,
1168,
82,
8,
1569,
63,
1144,
395,
446,
1597,
15663,
63,
4593,
421,
199,
318,
23351,
63,
1569,
8,
1569,
63,
1144,
12,
1072,
63,
1392,
29,
403,
304,
272,
340,
1072,
63,
1392,
365,
488,
26,
267,
1072,
63,
1392,
275,
334,
1272,
12,
1926,
9,
272,
1834,
63,
1144,
275,
6277,
18,
14,
5107,
84,
4117,
8,
1569,
63,
1144,
12,
6277,
18,
14,
7134,
63,
34,
3975,
18,
57,
15110,
9,
339,
327,
359,
89,
17,
26,
89,
18,
12,
671,
17,
26,
88,
18,
61,
446,
286,
26307,
2746,
18046,
465,
5521,
465,
9590,
1159,
2636,
364,
687,
1834,
272,
1834,
63,
1144,
275,
1834,
63,
1144,
59,
1400,
26,
10037,
12,
378,
26,
12122,
61,
339,
327,
15210,
1834,
370,
1072,
63,
1392,
272,
1834,
63,
1144,
275,
6277,
18,
14,
8709,
8,
1569,
63,
1144,
12,
334,
1199,
63,
1392,
59,
17,
467,
1072,
63,
1392,
59,
16,
2522,
14046,
29,
5107,
18,
14,
3843,
63,
28591,
9,
339,
327,
1834,
63,
1144,
275,
1834,
63,
1144,
1182,
5450,
446,
378,
14,
21,
272,
327,
1834,
63,
1144,
275,
1834,
63,
1144,
1182,
12792,
14,
21,
446,
413,
14,
272,
327,
1834,
63,
1144,
275,
6277,
18,
14,
7721,
8,
1569,
63,
1144,
12,
1834,
63,
1144,
12,
6316,
63,
466,
29,
5107,
18,
14,
46,
8832,
63,
4896,
4283,
9,
339,
372,
1834,
63,
1144,
421,
199,
318,
12610,
63,
4782,
8,
1238,
304,
272,
5935,
275,
359,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
821,
63,
966,
63,
31125,
14,
8476,
297,
446,
16,
14,
1196,
1876,
16710,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
821,
63,
383,
63,
15463,
14,
8476,
297,
378,
14,
1046,
2194,
13976,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1153,
63,
16373,
14,
8476,
297,
378,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1082,
63,
26623,
14,
8476,
297,
446,
16,
14,
9461,
5308,
395,
267,
327,
14606,
12117,
15,
569,
29640,
90,
15,
3187,
15,
6727,
3690,
15,
7007,
977,
15,
7007,
977,
13,
17537,
279,
13,
429,
19718,
15,
26246,
15,
4218,
63,
9261,
63,
713,
63,
713,
63,
1079,
63,
2006,
63,
1703,
63,
25,
2333,
14,
8476,
297,
446,
16,
14,
1079,
1965,
22531,
395,
272,
1622,
339,
367,
1834,
63,
17034,
315,
5935,
26,
267,
1834,
63,
1144,
275,
18576,
14,
1017,
739,
8,
1569,
63,
17034,
59,
16,
566,
267,
1834,
63,
1144,
275,
23351,
63,
1569,
8,
1569,
63,
1144,
9,
267,
8869,
275,
2069,
8,
1238,
14,
6892,
8,
1569,
63,
1144,
59,
403,
12,
13785,
13785,
26450,
3522,
63,
890,
29,
17,
430,
267,
2549,
275,
2069,
8,
1569,
63,
17034,
59,
17,
566,
267,
870,
360,
48,
26,
1052,
259,
377,
26,
9499,
908,
8,
5991,
12,
2549,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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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
] |
signalw/charliechat
|
main/utils/queryGoogleForDirectionsv3.py
|
1
|
18357
|
import requests
from CharlieChat import settings
import re
#ticket price variables. assumes no charlie-card
#most prices pertain to charlie card zones. '1A' is the price to go between two '1A' stops only
#the whole numbers are prices to go between a 1A stop to the listed zone, the keys that end
#in .5 are inter-zone prices. So if going from zone 7 to zone 5, the price will be the value that matches
#|7-5\+.5 = 2.5
price_dict = {'subway':2.75,'bus':1.70,'1A':2.25,1:6.25,1.5:2.75,2:6.75,2.5:3.25,3:7.50,3.5:3.50,4:8.25,4.5:4.00,5:9.25,5.5:4.50,\
6:10.00,6.5:5.00,7:10.50,7.5:5.50,8:11.50,8.5:6.00,9:12.00,9.5:6.50,10:12.50,10.5:6.50}
#to help with pricing
zone_dict ={"South Station":"1A","JFK/UMass":"1A","Quincy Center":1,\
"Weymouth Landing/East Braintree":2,"East Weymouth":2,"West Hingham":3,\
"Nantasket Junction":4,"Cohasset":4,"North Scituate":5,"Greenbush":6,\
"Braintree":2,"Holbrook/Randolph":3,"Montello":4,"Brockton":4,\
"Campello":5,"Bridgewater":6,"Middleborough/Lakeville":8,"South Weymouth":3,\
"Abington":4,"Whitman":5,"Hanson":6,"Halifax":7,"Kingston/Route":3,"Plymouth":8,\
"Newmarket":"1A","Uphams Corner":"1A","Four Corners/Geneva Ave":"1A","Talbot Ave":"1A",\
"Morton Street":"1A","Fairmount":"1A","Readville":2,"Back Bay":"1A","Ruggles":"1A",\
"Hyde Park":1,"Route 128":2,"Canton Junction":3,"Canton Center":3,"Stoughton":4,"Sharon":4,\
"Mansfield":6,"Attleboro":7,"South Attleboro":7,"Providence":8,"T.F. Green Airport":9,\
"Wickford Junction":10,"Endicott":2,"Dedham Corporate Center":2,"Islington":3,\
"Norwood Depot":3,"Norwood Central":3,"Windsor Gardens":4,"Plimptonville":4,"Walpole":4,\
"Norfolk":5,"Franklin/Dean College":6,"Forge Park/495":6,"Forest Hills":"1A",\
"Roslindale Village":1,"Bellevue":1,"Highland":1,"West Roxbury":1,"Hersey":2,\
"Needham Junction":2,"Needham Center":2,"Needham Heights":2,"Yawkey":"1A",\
"Newtonville":1,"West Newton":2,"Auburndale":2,"Wellesley Farms":3,"Wellesley Hills":3,\
"Wellesley Square":3,"Natick Center":4,"West Natick":4,"Framingham":5,"Ashland":6,\
"Southborough":6,"Westborough":7,"Grafton":8,"Worcester":8,"North Station":"1A","Porter":"1A",\
"Belmont Center":1,"Waverley":1,"Waltham":2,"Brandeis/Roberts":2,"Kendal Green":3,"Hastings":3,"Silver Hill":3,\
"Lincoln":4,"Concord":5,"West Concord":5,"South Acton":6,"Littleton/Route 495":7,"Ayer":8,"Shirley":8,"North Leominster":8,\
"Fitchburg":8,"Wachusett":8,"West Medford":"1A","Wedgemere":1,"Winchester Center":1,"Mishawum":2,"Anderson RTC":2,"Wilmington":3,\
"North Billerica":5,"Lowell":6,"Malden Center":"1A","Wyoming Hill":1,"Melrose/Cedar Park":1,"Melrose Highlands":1,"Greenwood":2,\
"Wakefield":2,"Reading":2,"North Wilmington":3,"Ballardvale":4,"Andover":5,"Lawrence":6,"Bradford":7,"Haverhill":7,\
"Chelsea":"1A","River Works":2,"Lynn":2,"Swampscott":3,"Salem":3,"Beverly Depot":4,"North Beverly":5,"Hamilton/Wenham":5,\
"Ipswich":6,"Rowley":7,"Newburyport":8,"Montserrat":4,"Prides Crossing":5,"Beverly Farms":5,"Manchester":6,\
"West Gloucester":7,"Gloucester":7,"Rockport":8}
#necessary dictinaries for alerting API
alertnames = {'Chiswick Road': 'place-chswk', 'North Quincy': 'place-nqncy', 'Boston College': 'place-lake',\
'Babcock Street': 'place-babck', 'Riverway': 'place-rvrwy', 'Reservoir': 'place-rsmnl',\
'Green Street': 'place-grnst', 'Coolidge Corner': 'place-cool', \
'Warren Street': 'place-wrnst', 'Back of the Hill': 'place-bckhl', \
'Airport': 'place-aport', 'Museum of Fine Arts': 'place-mfa', 'South Street': 'place-sougr',\
'Copley': 'place-coecl', 'Mattapan': 'place-matt', 'Central': 'place-cntsq', \
'Waban': 'place-waban', 'Capen Street': 'place-capst', 'Kent Street': 'place-kntst', \
'Back Bay': 'place-bbsta', 'Andrew': 'place-andrw', 'Newton Highlands': 'place-newtn', \
'Alewife': 'place-alfcl', 'Ashmont': 'place-asmnl', 'Hawes Street': 'place-hwsst', 'Fenway': 'place-fenwy',\
'Prudential': 'place-prmnl', 'State Street': 'place-state', 'Ruggles': 'place-rugg', \
'Symphony': 'place-symcl', 'Fairbanks Street': 'place-fbkst', \
'Tappan Street': 'place-tapst', 'Boston Univ. East': 'place-buest', 'Assembly': \
'place-astao', 'World Trade Center': 'place-wtcst', 'Shawmut': 'place-smmnl',\
'Newton Centre': 'place-newto', 'Charles/MGH': 'place-chmnl', 'Central Ave.': \
'place-cenav', 'Riverside': 'place-river', 'Davis': 'place-davis', 'Chestnut Hill': \
'place-chhil', 'Science Park': 'place-spmnl', 'Butler': 'place-butlr', 'Savin Hill': 'place-shmnl', \
'Quincy Adams': 'place-qamnl', 'Quincy Center': 'place-qnctr', \
'Tufts Medical Center': 'place-tumnl', 'Saint Mary Street': 'place-smary', \
'Chestnut Hill Ave.': 'place-chill', 'Wonderland': 'place-wondl', 'Aquarium': \
'place-aqucl', 'Beachmont': 'place-bmmnl', 'Milton': 'place-miltt', 'Harvard':\
'place-harsq', 'Brookline Village': 'place-bvmnl', 'Longwood Medical Area': \
'place-lngmd', 'Downtown Crossing': 'place-dwnxg', 'Maverick': 'place-mvbcl', \
'Sullivan Square': 'place-sull', 'Boston Univ. Central': 'place-bucen', 'Suffolk Downs': 'place-sdmnl',\
'Mission Park': 'place-mispk', 'Brigham Circle': 'place-brmnl', 'Bowdoin': 'place-bomnl',\
'Pleasant Street': 'place-plsgr', 'Wood Island': 'place-wimnl', \
'Kendall/MIT': 'place-knncl','Kendall': 'place-knncl', 'Heath Street': 'place-hsmnl', 'Brookline Hills': 'place-brkhl', \
'Summit Ave.': 'place-sumav', 'Dean Road': 'place-denrd',\
'Hynes Convention Center': 'place-hymnl', 'Braintree': 'place-brntn', 'Kenmore': \
'place-kencl', 'Wellington': 'place-welln', 'Sutherland Road': 'place-sthld', \
'Brandon Hall': 'place-bndhl', 'Boston Univ. West': 'place-buwst', 'Porter': 'place-portr', \
'Stony Brook': 'place-sbmnl', 'JFK/Umass': 'place-jfk', 'Packards Corner': 'place-brico',\
'Chinatown': 'place-chncl', 'Saint Paul Street': 'place-stpul', 'Orient Heights': 'place-orhte', \
'Lechmere': 'place-lech', 'Malden Center': 'place-mlmnl', 'Haymarket': 'place-haecl', \
'Northeastern University': 'place-nuniv', 'Courthouse': 'place-crtst', \
'Englewood Ave.': 'place-engav', 'Fenwood Road': 'place-fenwd', 'Broadway': 'place-brdwy',\
'Allston Street': 'place-alsgr', 'Eliot': 'place-eliot', 'Revere Beach': 'place-rbmnl', \
'Jackson Square': 'place-jaksn', 'Beaconsfield': 'place-bcnfd', 'Park Street': 'place-pktrm', \
'Massachusetts Ave.': 'place-masta', 'Washington Street': 'place-wascm', 'Longwood': 'place-longw', \
'Blandford Street': 'place-bland', 'North Station': 'place-north', \
'Oak Grove': 'place-ogmnl', 'Cedar Grove': 'place-cedgr', 'Woodland': 'place-woodl', \
'Fields Corner': 'place-fldcr', 'Griggs Street': 'place-grigg', 'Boylston': 'place-boyls', \
'Washington Square': 'place-bcnwa', 'Wollaston': 'place-wlsta', 'Cleveland Circle': 'place-clmnl',\
'Harvard Ave.': 'place-harvd', 'Valley Road': 'place-valrd', 'Government Center': 'place-gover', \
'South Station': 'place-sstat', 'Arlington': 'place-armnl', 'Forest Hills': 'place-forhl',\
'Roxbury Crossing': 'place-rcmnl', 'Community College': 'place-ccmnl'}
routeorders = {'Green Line B': ['Lechmere', 'Science Park', 'North Station', 'Haymarket', \
'Park Street', 'Boylston', 'Arlington', 'Copley', 'Hynes Convention Center', 'Kenmore', \
'Blanford Street', 'Boston Univ. East', 'Boston Univ. Central', 'Boston Univ. West', \
'Saint Paul Street', 'Pleasant Street', 'Babcock Street', 'Packards Corner', \
'Harvard Avenue', 'Griggs Street', 'Allston Street', 'Warren Street', 'Washington Street', \
'Sutherland Road', 'Chiswick Road', 'Chestnut Hill Ave', ' South Street', 'Boston College'], \
'Blue': ['Wonderland', 'Revere Beach', 'Beachmont', 'Suffolk Downs', 'Orient Heights', 'Wood Island', \
'Airport', 'Maverick', 'Aquarium', 'State', 'Government', 'Bowdoin'], \
'Orange': ['Oak Grove', 'Malden Center', 'Wellington', 'Assembly', 'Sullivan Square', \
'Community College', 'North Station', 'Haymarket', 'State', 'Downtown Crossing', 'Chinatown', \
'Tufts', 'Back Bay', 'Massachusetts Ave.', 'Ruggles', 'Roxbury Crossing', 'Jackson Square',\
'Stony Brook', 'Greet Street', 'Forest Hills'], 'Green': ['Lechmere', 'Science Park', 'North Station',\
'Haymarket', 'Park Street', 'Boylston', 'Arlington', 'Copley', 'Hynes Convention Center', \
'Kenmore'], 'Green Line E': ['Lechmere', 'Science Park', 'North Station', 'Haymarket', \
'Park Street', 'Boylston', 'Arlington', 'Copley', 'Hynes Convention Center', 'Kenmore', \
'Prudential', 'Symphony', 'Northeastern', 'Longwood', 'Brigham Circle', 'Fenwood Road', \
'Mission Park', 'Riverway', 'Back of the Hill', 'Heath Street'], 'Red Ashmont': ['Alewife', \
'Davis', 'Porter', 'Harvard', 'Central', 'Kendall', 'Charles/MGH', 'Park Street', \
'Downtown Crossing', 'South Station', 'Broadway', 'Andrew', 'Savin Hill', 'Fields Corner',\
'Shawmut', 'Ashmont'], 'Green Line D': ['Lechmere', 'Science Park', 'North Station', \
'Haymarket', 'Park Street', 'Boylston', 'Arlington', 'Copley', 'Hynes Convention Center',\
'Kenmore', 'Fenway', 'Longwood', 'Brookline Village', 'Brookline Hills', 'Beaconsfiled',\
'Reservoir', 'Chestnut Hill', 'Newton Centre', 'Newton Highlands', 'Elliot', 'Waban', \
'Woodland', 'Riverside'], 'Green Line C': ['Lechmere', 'Science Park', 'North Station', \
'Haymarket', 'Park Street', 'Boylston', 'Arlington', 'Copley', 'Hynes Convention Center',\
'Kenmore', 'Saint Marys Street', 'Hawes Street', 'Kent Street', 'Saint Paul Street', \
'Coolidge Corner', 'Summit Ave.', 'Brandon hall', 'Fairbanks', 'Washington Square', \
'Tappan Street', 'Dean Road', 'Englewood Avenue', 'Cleaveland Circle'], 'Red Braintree':\
['Alewife', 'Davis', 'Porter', 'Harvard', 'Central', 'Kendall', 'Charles/MGH',\
'Park Street', 'Downtown Crossing', 'South Station', 'Broadway', 'Andrew', 'JFK/Umass', \
'North Quincy', 'Wollaston', 'Quincy Center', 'Quincy Adams', 'Braintree']}
#put parameters in URL path
def buildGoogleMapsURL(origin, destination, mode ='transit'):
url = "https://maps.googleapis.com/maps/api/directions/json"
params = {'origin':origin.replace(' ','+'),
'destination':destination.replace(' ','+'),
'key':settings.GOOGLE_API_KEY,
'mode':mode,
}
response = requests.get(url, params=params)
r = response.json()
return r
def buildAlertsURL(stop):
url = "http://realtime.mbta.com/developer/api/v2/alertsbystop"
params = {'stop':stop,
'include_access_alerts':'false',
'api_key':'xk7jp6dSYEeidJi0P8sBcQ',
'format':'json',
'include_service_alerts':'true',
}
response = requests.get(url,params=params)
r = response.json()
return r
def getUberPriceTime(start_lat, start_long, end_lat, end_long):
url='https://api.uber.com/v1/estimates/price'
url2 = 'https://api.uber.com/v1/estimates/time'
params = {'start_latitude':start_lat,
'start_longitude':start_long,
'end_latitude':start_lat,
'end_longitude':start_long,
'Accept-Language': 'en_US',
'server_token':'bEcr6qr2ggY-fVYXr0uump4AdxMLNZmCFvyJwJ-i',
'Content-Type': 'application/json',
}
price = requests.get(url,params=params)
p = price.json()
time = requests.get(url2,params=params)
t = time.json()
return p,t
def process_directions(origin,destination):
output_dict = {}
MBTA_trip_price = 0
txt2 = buildGoogleMapsURL(origin, destination)
if txt2['routes'] == []:
output_dict['MBTA directions'] = 'Directions not found'
output_dict['MBTA depart time']= 'Directions not found'
output_dict['MBTA arrival time'] ='Directions not found'
output_dict['MBTA duration']= 'Directions not found'
output_dict['MBTA alerts']= 'Directions not found'
output_dict['MBTA price'] = 'Directions not found'
output_dict['Uber price'] = 'Directions not found'
output_dict['Uber driver arrival (sec)'] = 'Directions not found'
output_dict['Uber duration'] = 'Directions not found'
#parse apart directions info
else:
txt = txt2['routes'][0]
start_lat = txt['legs'][0]['start_location']['lat']
start_lng = txt['legs'][0]['start_location']['lng']
end_lat = txt['legs'][0]['end_location']['lat']
end_lng = txt['legs'][0]['end_location']['lng']
#price and time for uberx. change index to get different uber prices
p,t = getUberPriceTime(start_lat, start_lng,end_lat,end_lng)
uber_price = p['prices'][1]['estimate']
uber_time = t['times'][1]['estimate']
#used for uber duration
drive_duration = buildGoogleMapsURL(origin, destination, mode = 'driving')['routes'][0]['legs'][0]['duration']['text']
arrivaltime = txt['legs'][0]['arrival_time']['text']
departtime = txt['legs'][0]['departure_time']['text']
duration = txt['legs'][0]['duration']['text']
directionsraw = str(txt2).split('html_instructions')[1:]
directions_cleaner = ""
for item in directionsraw:
if len(re.findall(r'Subway toward',item)) !=0 or len(re.findall(r'Light rail towards',item)) !=0 \
or len(re.findall(r'Train towards',item)) !=0 or len(re.findall(r'Bus towards',item)) !=0:
lineList = []
print(item)
subwayToward = item[:item.find('distance')][4:-3]
subwayDetails = item.split("'name': '")
getOnAt= subwayDetails[1].split("'")[0]
getOffAt = subwayDetails[2].split("'")[0]
if len(re.findall(r'Subway toward',item)) !=0:
MBTA_trip_price = MBTA_trip_price + price_dict['subway']
line = subwayDetails[5].split("'")[0]
if item == 'Red Line Subway towards Ashmont':
lineList = routeorders['Red Ashmont']
elif line =='Red Line':
lineList= routeorders['Red Braintree']
else:
lineList = routeorders[line.split()[0]]
elif len(re.findall(r'Light rail towards',item)) !=0:
line = subwayDetails[3].split("'")[0]
lineList = routeorders[line]
MBTA_trip_price = MBTA_trip_price + price_dict['subway']
elif len(re.findall(r'Bus towards',item)) !=0:
MBTA_trip_price = MBTA_trip_price + price_dict['bus']
line= subwayDetails[4].split("'")[0]
#this one is commuter rail and does not include alerts
else:
line= subwayDetails[5].split("'")[0]
onZone = zone_dict[getOnAt]
offZone = zone_dict[getOffAt]
if onZone=="1A" and offZone =="1A":
MBTA_trip_price = MBTA_trip_price + price_dict['1A']
elif onZone=="1A" or offZone =="1A":
if onZone != "1A":
MBTA_trip_price = MBTA_trip_price + price_dict[onZone]
else:
MBTA_trip_price = MBTA_trip_price + price_dict[offZone]
else:
MBTA_trip_price = MBTA_trip_price + price_dict[abs(onZone-offZone)+.5]
warning = ''
alertdict ={}
look = False
for i in range(len(lineList)):
if lineList[i] == getOnAt:
if look == True:
alertdict[lineList[i]] = alertnames[lineList[i]]
look = False
else:
look = True
alertdict[lineList[i]] =alertnames[lineList[i]]
elif lineList[i]==getOffAt:
if look ==True:
alertdict[lineList[i]] = alertnames[lineList[i]]
look = False
else:
alertdict[lineList[i]] = alertnames[lineList[i]]
else:
if look ==True:
alertdict[lineList[i]] = alertnames[lineList[i]]
for stop in alertdict:
alert2 = buildAlertsURL(alertnames[stop])
if alert2['alerts'] ==[]:
pass
else:
warning = warning+'\nAlert at '+stop+': '+str(alert2['alerts'][0]['short_header_text'])
directions_cleaner = directions_cleaner+'go to '\
+getOnAt+'\ntake '+line+' '+subwayToward+'\nget off at '+getOffAt+'\n'
else:
directions_cleaner = directions_cleaner + item[:item.find('distance')][4:-3] + "\n"
directions_cleaner = re.sub(r'(\<.*?\>)','',directions_cleaner)
output_dict['MBTA directions'] = directions_cleaner
output_dict['MBTA depart time']= '\nleave at', departtime
output_dict['MBTA arrival time'] ='\narrive by ', arrivaltime
output_dict['MBTA duration']= '\ntotal duration ',duration
output_dict['MBTA alerts']= 'warning, the following alerts exist"\n',warning
output_dict['MBTA price']= MBTA_trip_price
output_dict['Uber price'] = uber_price
output_dict['Uber driver arrival (sec)'] = uber_time
output_dict['Uber duration']=drive_duration
return output_dict
def return_travel_info(origin, destination):
print(origin)
print(destination)
printdict = process_directions(origin,destination)
return printdict
|
mit
|
[
646,
4145,
202,
199,
504,
6659,
21530,
21954,
492,
2202,
202,
199,
646,
295,
2999,
199,
3,
9201,
8033,
2860,
14,
15194,
949,
1495,
21530,
13,
5841,
202,
199,
3,
2786,
1979,
823,
1126,
877,
370,
1495,
21530,
12564,
18666,
14,
221,
283,
17,
33,
7,
365,
314,
8033,
370,
2621,
3382,
2877,
283,
17,
33,
7,
20922,
1454,
202,
199,
3,
1589,
8852,
5579,
787,
1979,
823,
370,
2621,
3382,
282,
413,
33,
3631,
370,
314,
10532,
5718,
12,
314,
2883,
626,
1284,
202,
199,
3,
262,
1275,
21,
787,
1640,
13,
2619,
1979,
823,
14,
2002,
340,
9995,
687,
5718,
1520,
370,
5718,
959,
12,
314,
8033,
911,
506,
314,
574,
626,
4450,
202,
199,
3,
92,
23,
13,
21,
60,
26240,
21,
275,
499,
14,
21,
202,
199,
4777,
63,
807,
275,
791,
954,
3316,
356,
18,
14,
2194,
2584,
5610,
356,
17,
14,
2760,
2584,
17,
33,
356,
18,
14,
821,
12,
17,
26,
22,
14,
821,
12,
17,
14,
21,
26,
18,
14,
2194,
12,
18,
26,
22,
14,
2194,
12,
18,
14,
21,
26,
19,
14,
821,
12,
19,
26,
23,
14,
1400,
12,
19,
14,
21,
26,
19,
14,
1400,
12,
20,
26,
24,
14,
821,
12,
20,
14,
21,
26,
20,
14,
383,
12,
21,
26,
25,
14,
821,
12,
21,
14,
21,
26,
20,
14,
1400,
4202,
1128,
1227,
26,
709,
14,
383,
12,
22,
14,
21,
26,
21,
14,
383,
12,
23,
26,
709,
14,
1400,
12,
23,
14,
21,
26,
21,
14,
1400,
12,
24,
26,
845,
14,
1400,
12,
24,
14,
21,
26,
22,
14,
383,
12,
25,
26,
713,
14,
383,
12,
25,
14,
21,
26,
22,
14,
1400,
12,
709,
26,
713,
14,
1400,
12,
709,
14,
21,
26,
22,
14,
1400,
93,
202,
199,
3,
475,
1720,
543,
299,
1567,
316,
202,
199,
2619,
63,
807,
275,
6641,
30534,
1933,
425,
5122,
17,
33,
2266,
42,
21490,
15,
2639,
405,
5122,
17,
33,
2266,
2371,
262,
1480,
24699,
582,
17,
4202,
1128,
298,
6004,
89,
573,
762,
491,
460,
316,
15,
37,
1810,
699,
3156,
850,
582,
18,
4589,
37,
1810,
2136,
89,
573,
762,
582,
18,
4589,
55,
597,
869,
316,
10670,
582,
19,
4202,
1128,
298,
46,
867,
12351,
1603,
648,
582,
20,
4589,
967,
1989,
409,
582,
20,
4589,
32066,
13916,
390,
4767,
582,
21,
4589,
19456,
464,
609,
582,
22,
4202,
1128,
298,
34,
3156,
850,
582,
18,
4589,
40,
393,
20670,
745,
15,
50,
460,
393,
838,
582,
19,
4589,
6671,
14146,
320,
582,
20,
4589,
34,
24892,
1860,
582,
20,
4202,
1128,
298,
3630,
311,
3312,
582,
21,
4589,
14491,
17217,
582,
22,
4589,
30734,
31938,
4937,
15,
44,
1728,
86,
17142,
582,
24,
4589,
30534,
2136,
89,
573,
762,
582,
19,
4202,
1128,
298,
5583,
31673,
582,
20,
4589,
5879,
390,
1237,
582,
21,
4589,
40,
796,
265,
582,
22,
4589,
40,
10874,
667,
88,
582,
23,
4589,
43,
316,
17874,
15,
7161,
582,
19,
4589,
48,
590,
573,
762,
582,
24,
4202,
1128,
298,
4665,
22270,
5122,
17,
33,
2266,
53,
838,
19470,
7499,
1372,
5122,
17,
33,
2266,
24766,
445,
6161,
1192,
15,
39,
6349,
3042,
437,
432,
5122,
17,
33,
2266,
52,
279,
3018,
437,
432,
5122,
17,
33,
22260,
1128,
298,
45,
361,
265,
14259,
5122,
17,
33,
2266,
1906,
723,
3956,
5122,
17,
33,
2266,
3284,
86,
17142,
582,
18,
4589,
4540,
29434,
5122,
17,
33,
2266,
50,
1518,
27033,
5122,
17,
33,
22260,
1128,
298,
21568,
271,
510,
1096,
582,
17,
4589,
7161,
7960,
582,
18,
4589,
35,
867,
265,
1603,
648,
582,
19,
4589,
35,
867,
265,
24699,
582,
19,
4589,
4759,
10846,
265,
582,
20,
4589,
2662,
285,
265,
582,
20,
4202,
1128,
298,
45,
796,
698,
582,
22,
4589,
1271,
1118,
31938,
79,
582,
23,
4589,
30534,
2854,
1118,
31938,
79,
582,
23,
4589,
919,
433,
5606,
582,
24,
4589,
52,
14,
38,
14,
32585,
22102,
719,
582,
25,
4202,
1128,
298,
55,
2000,
18090,
1603,
648,
582,
709,
4589,
1327,
27347,
6215,
582,
18,
4589,
36,
379,
10670,
7499,
7314,
323,
24699,
582,
18,
4589,
1831,
2983,
1860,
582,
19,
4202,
1128,
298,
23008,
22736,
1487,
14173,
582,
19,
4589,
23008,
22736,
32267,
9117,
582,
19,
4589,
55,
688,
1509,
598,
285,
28509,
582,
20,
4589,
48,
317,
311,
1860,
86,
17142,
582,
20,
4589,
55,
279,
25903,
582,
20,
4202,
1128,
298,
23008,
5900,
75,
582,
21,
4589,
38,
4648,
472,
15,
872,
290,
3626,
274,
303,
582,
22,
4589,
1858,
303,
510,
1096,
15,
20384,
582,
22,
4589,
21668,
869,
15350,
5122,
17,
33,
22260,
1128,
298,
50,
736,
472,
29258,
812,
30138,
582,
17,
4589,
34,
352,
6972,
310,
582,
17,
4589,
11688,
9688,
582,
17,
4589,
55,
597,
6848,
1774,
18359,
582,
17,
4589,
40,
281,
261,
89,
582,
18,
4202,
1128,
298,
17809,
10670,
1603,
648,
582,
18,
4589,
17809,
10670,
24699,
582,
18,
4589,
17809,
10670,
5311,
2492,
582,
18,
4589,
57,
10084,
498,
5122,
17,
33,
22260,
1128,
298,
4665,
1860,
86,
17142,
582,
17,
4589,
55,
597,
7053,
1860,
582,
18,
4589,
33,
456,
349,
29258,
582,
18,
4589,
55,
352,
2978,
15515,
481,
25005,
582,
19,
4589,
55,
352,
2978,
15515,
869,
15350,
582,
19,
4202,
1128,
298,
55,
352,
2978,
15515,
428,
5937,
582,
19,
4589,
46,
2159,
346,
24699,
582,
20,
4589,
55,
597,
653,
2159,
346,
582,
20,
4589,
38,
5975,
316,
10670,
582,
21,
4589,
33,
609,
9688,
582,
22,
4202,
1128,
298,
30534,
31938,
4937,
582,
22,
4589,
55,
597,
31938,
4937,
582,
23,
4589,
39,
4800,
265,
582,
24,
4589,
8908,
823,
351,
582,
24,
4589,
32066,
1933,
425,
5122,
17,
33,
2266,
48,
3968,
5122,
17,
33,
22260,
1128,
298,
34,
21226,
1888,
24699,
582,
17,
4589,
24804,
422,
15515,
582,
17,
4589,
55,
6130,
455,
582,
18,
4589,
34,
1312,
271,
374,
15,
3863,
605,
1086,
582,
18,
4589,
43,
500,
279,
32585,
582,
19,
4589,
40,
1810,
780,
582,
19,
4589,
51,
382,
422,
869,
778,
582,
19,
4202,
1128,
298,
27889,
761,
78,
582,
20,
4589,
714,
1577,
582,
21,
4589,
55,
597
] |
[
4145,
202,
199,
504,
6659,
21530,
21954,
492,
2202,
202,
199,
646,
295,
2999,
199,
3,
9201,
8033,
2860,
14,
15194,
949,
1495,
21530,
13,
5841,
202,
199,
3,
2786,
1979,
823,
1126,
877,
370,
1495,
21530,
12564,
18666,
14,
221,
283,
17,
33,
7,
365,
314,
8033,
370,
2621,
3382,
2877,
283,
17,
33,
7,
20922,
1454,
202,
199,
3,
1589,
8852,
5579,
787,
1979,
823,
370,
2621,
3382,
282,
413,
33,
3631,
370,
314,
10532,
5718,
12,
314,
2883,
626,
1284,
202,
199,
3,
262,
1275,
21,
787,
1640,
13,
2619,
1979,
823,
14,
2002,
340,
9995,
687,
5718,
1520,
370,
5718,
959,
12,
314,
8033,
911,
506,
314,
574,
626,
4450,
202,
199,
3,
92,
23,
13,
21,
60,
26240,
21,
275,
499,
14,
21,
202,
199,
4777,
63,
807,
275,
791,
954,
3316,
356,
18,
14,
2194,
2584,
5610,
356,
17,
14,
2760,
2584,
17,
33,
356,
18,
14,
821,
12,
17,
26,
22,
14,
821,
12,
17,
14,
21,
26,
18,
14,
2194,
12,
18,
26,
22,
14,
2194,
12,
18,
14,
21,
26,
19,
14,
821,
12,
19,
26,
23,
14,
1400,
12,
19,
14,
21,
26,
19,
14,
1400,
12,
20,
26,
24,
14,
821,
12,
20,
14,
21,
26,
20,
14,
383,
12,
21,
26,
25,
14,
821,
12,
21,
14,
21,
26,
20,
14,
1400,
4202,
1128,
1227,
26,
709,
14,
383,
12,
22,
14,
21,
26,
21,
14,
383,
12,
23,
26,
709,
14,
1400,
12,
23,
14,
21,
26,
21,
14,
1400,
12,
24,
26,
845,
14,
1400,
12,
24,
14,
21,
26,
22,
14,
383,
12,
25,
26,
713,
14,
383,
12,
25,
14,
21,
26,
22,
14,
1400,
12,
709,
26,
713,
14,
1400,
12,
709,
14,
21,
26,
22,
14,
1400,
93,
202,
199,
3,
475,
1720,
543,
299,
1567,
316,
202,
199,
2619,
63,
807,
275,
6641,
30534,
1933,
425,
5122,
17,
33,
2266,
42,
21490,
15,
2639,
405,
5122,
17,
33,
2266,
2371,
262,
1480,
24699,
582,
17,
4202,
1128,
298,
6004,
89,
573,
762,
491,
460,
316,
15,
37,
1810,
699,
3156,
850,
582,
18,
4589,
37,
1810,
2136,
89,
573,
762,
582,
18,
4589,
55,
597,
869,
316,
10670,
582,
19,
4202,
1128,
298,
46,
867,
12351,
1603,
648,
582,
20,
4589,
967,
1989,
409,
582,
20,
4589,
32066,
13916,
390,
4767,
582,
21,
4589,
19456,
464,
609,
582,
22,
4202,
1128,
298,
34,
3156,
850,
582,
18,
4589,
40,
393,
20670,
745,
15,
50,
460,
393,
838,
582,
19,
4589,
6671,
14146,
320,
582,
20,
4589,
34,
24892,
1860,
582,
20,
4202,
1128,
298,
3630,
311,
3312,
582,
21,
4589,
14491,
17217,
582,
22,
4589,
30734,
31938,
4937,
15,
44,
1728,
86,
17142,
582,
24,
4589,
30534,
2136,
89,
573,
762,
582,
19,
4202,
1128,
298,
5583,
31673,
582,
20,
4589,
5879,
390,
1237,
582,
21,
4589,
40,
796,
265,
582,
22,
4589,
40,
10874,
667,
88,
582,
23,
4589,
43,
316,
17874,
15,
7161,
582,
19,
4589,
48,
590,
573,
762,
582,
24,
4202,
1128,
298,
4665,
22270,
5122,
17,
33,
2266,
53,
838,
19470,
7499,
1372,
5122,
17,
33,
2266,
24766,
445,
6161,
1192,
15,
39,
6349,
3042,
437,
432,
5122,
17,
33,
2266,
52,
279,
3018,
437,
432,
5122,
17,
33,
22260,
1128,
298,
45,
361,
265,
14259,
5122,
17,
33,
2266,
1906,
723,
3956,
5122,
17,
33,
2266,
3284,
86,
17142,
582,
18,
4589,
4540,
29434,
5122,
17,
33,
2266,
50,
1518,
27033,
5122,
17,
33,
22260,
1128,
298,
21568,
271,
510,
1096,
582,
17,
4589,
7161,
7960,
582,
18,
4589,
35,
867,
265,
1603,
648,
582,
19,
4589,
35,
867,
265,
24699,
582,
19,
4589,
4759,
10846,
265,
582,
20,
4589,
2662,
285,
265,
582,
20,
4202,
1128,
298,
45,
796,
698,
582,
22,
4589,
1271,
1118,
31938,
79,
582,
23,
4589,
30534,
2854,
1118,
31938,
79,
582,
23,
4589,
919,
433,
5606,
582,
24,
4589,
52,
14,
38,
14,
32585,
22102,
719,
582,
25,
4202,
1128,
298,
55,
2000,
18090,
1603,
648,
582,
709,
4589,
1327,
27347,
6215,
582,
18,
4589,
36,
379,
10670,
7499,
7314,
323,
24699,
582,
18,
4589,
1831,
2983,
1860,
582,
19,
4202,
1128,
298,
23008,
22736,
1487,
14173,
582,
19,
4589,
23008,
22736,
32267,
9117,
582,
19,
4589,
55,
688,
1509,
598,
285,
28509,
582,
20,
4589,
48,
317,
311,
1860,
86,
17142,
582,
20,
4589,
55,
279,
25903,
582,
20,
4202,
1128,
298,
23008,
5900,
75,
582,
21,
4589,
38,
4648,
472,
15,
872,
290,
3626,
274,
303,
582,
22,
4589,
1858,
303,
510,
1096,
15,
20384,
582,
22,
4589,
21668,
869,
15350,
5122,
17,
33,
22260,
1128,
298,
50,
736,
472,
29258,
812,
30138,
582,
17,
4589,
34,
352,
6972,
310,
582,
17,
4589,
11688,
9688,
582,
17,
4589,
55,
597,
6848,
1774,
18359,
582,
17,
4589,
40,
281,
261,
89,
582,
18,
4202,
1128,
298,
17809,
10670,
1603,
648,
582,
18,
4589,
17809,
10670,
24699,
582,
18,
4589,
17809,
10670,
5311,
2492,
582,
18,
4589,
57,
10084,
498,
5122,
17,
33,
22260,
1128,
298,
4665,
1860,
86,
17142,
582,
17,
4589,
55,
597,
7053,
1860,
582,
18,
4589,
33,
456,
349,
29258,
582,
18,
4589,
55,
352,
2978,
15515,
481,
25005,
582,
19,
4589,
55,
352,
2978,
15515,
869,
15350,
582,
19,
4202,
1128,
298,
55,
352,
2978,
15515,
428,
5937,
582,
19,
4589,
46,
2159,
346,
24699,
582,
20,
4589,
55,
597,
653,
2159,
346,
582,
20,
4589,
38,
5975,
316,
10670,
582,
21,
4589,
33,
609,
9688,
582,
22,
4202,
1128,
298,
30534,
31938,
4937,
582,
22,
4589,
55,
597,
31938,
4937,
582,
23,
4589,
39,
4800,
265,
582,
24,
4589,
8908,
823,
351,
582,
24,
4589,
32066,
1933,
425,
5122,
17,
33,
2266,
48,
3968,
5122,
17,
33,
22260,
1128,
298,
34,
21226,
1888,
24699,
582,
17,
4589,
24804,
422,
15515,
582,
17,
4589,
55,
6130,
455,
582,
18,
4589,
34,
1312,
271,
374,
15,
3863,
605,
1086,
582,
18,
4589,
43,
500,
279,
32585,
582,
19,
4589,
40,
1810,
780,
582,
19,
4589,
51,
382,
422,
869,
778,
582,
19,
4202,
1128,
298,
27889,
761,
78,
582,
20,
4589,
714,
1577,
582,
21,
4589,
55,
597,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ewdurbin/sentry
|
src/sentry/models/user.py
|
4
|
4208
|
"""
sentry.models.user
~~~~~~~~~~~~~~~~~~
:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import warnings
from django.contrib.auth.models import AbstractBaseUser, UserManager
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from sentry.db.models import BaseManager, BaseModel, BoundedAutoField
class UserManager(BaseManager, UserManager):
pass
class User(BaseModel, AbstractBaseUser):
id = BoundedAutoField(primary_key=True)
username = models.CharField(_('username'), max_length=128, unique=True)
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('email address'), blank=True)
is_staff = models.BooleanField(
_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
is_active = models.BooleanField(
_('active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
is_superuser = models.BooleanField(
_('superuser status'), default=False,
help_text=_('Designates that this user has all permissions without '
'explicitly assigning them.'))
is_managed = models.BooleanField(
_('managed'), default=False,
help_text=_('Designates whether this user should be treated as '
'managed. Select this to disallow the user from '
'modifying their account (username, password, etc).'))
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
objects = UserManager(cache_fields=['pk'])
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
class Meta:
app_label = 'sentry'
db_table = 'auth_user'
verbose_name = _('user')
verbose_name_plural = _('users')
def delete(self):
if self.username == 'sentry':
raise Exception('You cannot delete the "sentry" user as it is required by Sentry.')
return super(User, self).delete()
def save(self, *args, **kwargs):
if not self.username:
self.username = self.email
return super(User, self).save(*args, **kwargs)
def has_perm(self, perm_name):
warnings.warn('User.has_perm is deprecated', DeprecationWarning)
return self.is_superuser
def has_module_perms(self, app_label):
# the admin requires this method
return self.is_superuser
def get_full_name(self):
return self.first_name
def get_short_name(self):
return self.username
def merge_to(from_user, to_user):
# TODO: we could discover relations automatically and make this useful
from sentry.models import (
AuditLogEntry, Activity, AuthIdentity, GroupBookmark, Organization,
OrganizationMember, UserOption
)
for obj in Organization.objects.filter(owner=from_user):
obj.update(owner=to_user)
for obj in OrganizationMember.objects.filter(user=from_user):
obj.update(user=to_user)
for obj in GroupBookmark.objects.filter(user=from_user):
obj.update(user=to_user)
for obj in UserOption.objects.filter(user=from_user):
obj.update(user=to_user)
for obj in UserOption.objects.filter(user=from_user):
obj.update(user=to_user)
Activity.objects.filter(
user=from_user,
).update(user=to_user)
AuditLogEntry.objects.filter(
actor=from_user,
).update(actor=to_user)
AuditLogEntry.objects.filter(
target_user=from_user,
).update(target_user=to_user)
AuthIdentity.objects.filter(
user=from_user,
).update(user=to_user)
def get_display_name(self):
return self.first_name or self.email or self.username
|
bsd-3-clause
|
[
624,
199,
3870,
14,
992,
14,
751,
199,
9753,
1714,
199,
199,
26,
7307,
26,
334,
67,
9,
7129,
13,
7280,
701,
314,
428,
2373,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
3598,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
2876,
2988,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
26230,
14,
697,
14,
992,
492,
3523,
2988,
12,
3523,
1685,
12,
5088,
4585,
4378,
421,
199,
533,
2876,
2988,
8,
1563,
2988,
12,
2876,
2988,
304,
272,
986,
421,
199,
533,
2876,
8,
27687,
12,
11836,
1563,
1899,
304,
272,
1305,
275,
5088,
4585,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
3434,
275,
1709,
14,
2183,
6723,
2473,
659,
1390,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
272,
1642,
63,
354,
275,
1709,
14,
2183,
6723,
2246,
536,
659,
1390,
63,
1267,
29,
1216,
12,
4596,
29,
549,
9,
272,
2061,
63,
354,
275,
1709,
14,
2183,
6723,
2019,
536,
659,
1390,
63,
1267,
29,
1216,
12,
4596,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
6723,
2123,
2287,
659,
4596,
29,
549,
9,
272,
365,
63,
7018,
275,
1709,
14,
5036,
8,
267,
4018,
7018,
2004,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
283,
490,
283,
2124,
12459,
272,
365,
63,
2682,
275,
1709,
14,
5036,
8,
267,
4018,
2682,
659,
849,
29,
549,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
283,
490,
283,
2682,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
12459,
272,
365,
63,
11434,
275,
1709,
14,
5036,
8,
267,
4018,
11434,
2004,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
283,
490,
283,
10306,
590,
26694,
3062,
12459,
272,
365,
63,
11122,
275,
1709,
14,
5036,
8,
267,
4018,
11122,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
283,
490,
283,
11122,
14,
9496,
642,
370,
2153,
3306,
314,
922,
687,
283,
490,
283,
8951,
316,
3932,
2933,
334,
2473,
12,
2505,
12,
5423,
680,
1333,
339,
1434,
63,
11806,
275,
1709,
14,
4626,
6723,
602,
16538,
659,
849,
29,
7145,
14,
2131,
9,
339,
2251,
275,
2876,
2988,
8,
1637,
63,
955,
2968,
2051,
1105,
339,
13044,
2339,
63,
8609,
275,
283,
2473,
7,
272,
25090,
63,
12767,
275,
788,
2123,
418,
339,
1021,
6288,
26,
267,
1145,
63,
1302,
275,
283,
3870,
7,
267,
1592,
63,
1224,
275,
283,
1178,
63,
751,
7,
267,
3376,
63,
354,
275,
4018,
751,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
3707,
358,
339,
347,
3145,
8,
277,
304,
267,
340,
291,
14,
2473,
508,
283,
3870,
356,
288,
746,
2186,
360,
5556,
3913,
3145,
314,
298,
3870,
2,
922,
465,
652,
365,
1415,
701,
428,
2373,
2659,
267,
372,
1613,
8,
1899,
12,
291,
680,
1807,
342,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
2473,
26,
288,
291,
14,
2473,
275,
291,
14,
2123,
267,
372,
1613,
8,
1899,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
965,
63,
8220,
8,
277,
12,
10869,
63,
354,
304,
267,
3598,
14,
4050,
360,
1899,
14,
1989,
63,
8220,
365,
5906,
297,
13413,
9,
267,
372,
291,
14,
374,
63,
11434,
339,
347,
965,
63,
578,
63,
12068,
8,
277,
12,
1145,
63,
1302,
304,
267,
327,
314,
4628,
5074,
642,
1083,
267,
372,
291,
14,
374,
63,
11434,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2246,
63,
354,
339,
347,
664,
63,
3612,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2473,
339,
347,
5389,
63,
475,
8,
504,
63,
751,
12,
370,
63,
751,
304,
267,
327,
3254,
26,
781,
4293,
20131,
16109,
5847,
436,
1852,
642,
2997,
267,
687,
26230,
14,
992,
492,
334,
288,
31853,
1741,
2445,
3900,
12,
21885,
12,
3590,
10193,
12,
5611,
8696,
1657,
12,
18863,
12,
288,
18863,
7021,
12,
2876,
2602,
267,
776,
398,
367,
1559,
315,
18863,
14,
1462,
14,
1541,
8,
4597,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
4597,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
18863,
7021,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
5611,
8696,
1657,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
2876,
2602,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
2876,
2602,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
398,
21885,
14,
1462,
14,
1541,
8,
288,
922,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
751,
29,
475,
63,
751,
9,
267,
31853,
1741,
2445,
3900,
14,
1462,
14,
1541,
8,
288,
20318,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
5021,
29,
475,
63,
751,
9,
267,
31853,
1741,
2445,
3900,
14,
1462,
14,
1541,
8,
288,
1347,
63,
751,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
1375,
63,
751,
29,
475,
63,
751,
9,
267,
3590,
10193,
14,
1462,
14,
1541,
8,
288,
922,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
751,
29,
475,
63,
751,
9,
339,
347,
664,
63,
2918,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2246,
63,
354,
503,
291,
14,
2123,
503,
291,
14,
2473,
199,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3870,
14,
992,
14,
751,
199,
9753,
1714,
199,
199,
26,
7307,
26,
334,
67,
9,
7129,
13,
7280,
701,
314,
428,
2373,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
3598,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
2876,
2988,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
26230,
14,
697,
14,
992,
492,
3523,
2988,
12,
3523,
1685,
12,
5088,
4585,
4378,
421,
199,
533,
2876,
2988,
8,
1563,
2988,
12,
2876,
2988,
304,
272,
986,
421,
199,
533,
2876,
8,
27687,
12,
11836,
1563,
1899,
304,
272,
1305,
275,
5088,
4585,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
3434,
275,
1709,
14,
2183,
6723,
2473,
659,
1390,
63,
1267,
29,
3933,
12,
3747,
29,
549,
9,
272,
1642,
63,
354,
275,
1709,
14,
2183,
6723,
2246,
536,
659,
1390,
63,
1267,
29,
1216,
12,
4596,
29,
549,
9,
272,
2061,
63,
354,
275,
1709,
14,
2183,
6723,
2019,
536,
659,
1390,
63,
1267,
29,
1216,
12,
4596,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
6723,
2123,
2287,
659,
4596,
29,
549,
9,
272,
365,
63,
7018,
275,
1709,
14,
5036,
8,
267,
4018,
7018,
2004,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
314,
922,
883,
943,
1901,
642,
4628,
283,
490,
283,
2124,
12459,
272,
365,
63,
2682,
275,
1709,
14,
5036,
8,
267,
4018,
2682,
659,
849,
29,
549,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
283,
490,
283,
2682,
14,
1910,
2416,
642,
3140,
402,
13794,
12639,
12459,
272,
365,
63,
11434,
275,
1709,
14,
5036,
8,
267,
4018,
11434,
2004,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
283,
490,
283,
10306,
590,
26694,
3062,
12459,
272,
365,
63,
11122,
275,
1709,
14,
5036,
8,
267,
4018,
11122,
659,
849,
29,
797,
12,
267,
1720,
63,
505,
12397,
20924,
2335,
3775,
642,
922,
1077,
506,
10184,
465,
283,
490,
283,
11122,
14,
9496,
642,
370,
2153,
3306,
314,
922,
687,
283,
490,
283,
8951,
316,
3932,
2933,
334,
2473,
12,
2505,
12,
5423,
680,
1333,
339,
1434,
63,
11806,
275,
1709,
14,
4626,
6723,
602,
16538,
659,
849,
29,
7145,
14,
2131,
9,
339,
2251,
275,
2876,
2988,
8,
1637,
63,
955,
2968,
2051,
1105,
339,
13044,
2339,
63,
8609,
275,
283,
2473,
7,
272,
25090,
63,
12767,
275,
788,
2123,
418,
339,
1021,
6288,
26,
267,
1145,
63,
1302,
275,
283,
3870,
7,
267,
1592,
63,
1224,
275,
283,
1178,
63,
751,
7,
267,
3376,
63,
354,
275,
4018,
751,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
3707,
358,
339,
347,
3145,
8,
277,
304,
267,
340,
291,
14,
2473,
508,
283,
3870,
356,
288,
746,
2186,
360,
5556,
3913,
3145,
314,
298,
3870,
2,
922,
465,
652,
365,
1415,
701,
428,
2373,
2659,
267,
372,
1613,
8,
1899,
12,
291,
680,
1807,
342,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
2473,
26,
288,
291,
14,
2473,
275,
291,
14,
2123,
267,
372,
1613,
8,
1899,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
965,
63,
8220,
8,
277,
12,
10869,
63,
354,
304,
267,
3598,
14,
4050,
360,
1899,
14,
1989,
63,
8220,
365,
5906,
297,
13413,
9,
267,
372,
291,
14,
374,
63,
11434,
339,
347,
965,
63,
578,
63,
12068,
8,
277,
12,
1145,
63,
1302,
304,
267,
327,
314,
4628,
5074,
642,
1083,
267,
372,
291,
14,
374,
63,
11434,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2246,
63,
354,
339,
347,
664,
63,
3612,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2473,
339,
347,
5389,
63,
475,
8,
504,
63,
751,
12,
370,
63,
751,
304,
267,
327,
3254,
26,
781,
4293,
20131,
16109,
5847,
436,
1852,
642,
2997,
267,
687,
26230,
14,
992,
492,
334,
288,
31853,
1741,
2445,
3900,
12,
21885,
12,
3590,
10193,
12,
5611,
8696,
1657,
12,
18863,
12,
288,
18863,
7021,
12,
2876,
2602,
267,
776,
398,
367,
1559,
315,
18863,
14,
1462,
14,
1541,
8,
4597,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
4597,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
18863,
7021,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
5611,
8696,
1657,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
2876,
2602,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
267,
367,
1559,
315,
2876,
2602,
14,
1462,
14,
1541,
8,
751,
29,
504,
63,
751,
304,
288,
1559,
14,
873,
8,
751,
29,
475,
63,
751,
9,
398,
21885,
14,
1462,
14,
1541,
8,
288,
922,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
751,
29,
475,
63,
751,
9,
267,
31853,
1741,
2445,
3900,
14,
1462,
14,
1541,
8,
288,
20318,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
5021,
29,
475,
63,
751,
9,
267,
31853,
1741,
2445,
3900,
14,
1462,
14,
1541,
8,
288,
1347,
63,
751,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
1375,
63,
751,
29,
475,
63,
751,
9,
267,
3590,
10193,
14,
1462,
14,
1541,
8,
288,
922,
29,
504,
63,
751,
12,
267,
7092,
873,
8,
751,
29,
475,
63,
751,
9,
339,
347,
664,
63,
2918,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2246,
63,
354,
503,
291,
14,
2123,
503,
291,
14,
2473,
199,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Michael DeHaan <michael.dehaan@gmail.com>, 2012-2013
# Copyright (c), Toshio Kuratomi <tkuratomi@ansible.com>, 2015
# 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.
#
# The match_hostname function and supporting code is under the terms and
# conditions of the Python Software Foundation License. They were taken from
# the Python3 standard library and adapted for use in Python2. See comments in the
# source for which code precisely is under this License. PSF License text
# follows:
#
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
# --------------------------------------------
#
# 1. This LICENSE AGREEMENT is between the Python Software Foundation
# ("PSF"), and the Individual or Organization ("Licensee") accessing and
# otherwise using this software ("Python") in source or binary form and
# its associated documentation.
#
# 2. Subject to the terms and conditions of this License Agreement, PSF hereby
# grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
# analyze, test, perform and/or display publicly, prepare derivative works,
# distribute, and otherwise use Python alone or in any derivative version,
# provided, however, that PSF's License Agreement and PSF's notice of copyright,
# i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are
# retained in Python alone or in any derivative version prepared by Licensee.
#
# 3. In the event Licensee prepares a derivative work that is based on
# or incorporates Python or any part thereof, and wants to make
# the derivative work available to others as provided herein, then
# Licensee hereby agrees to include in any such work a brief summary of
# the changes made to Python.
#
# 4. PSF is making Python available to Licensee on an "AS IS"
# basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
# IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
# DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
# FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
# INFRINGE ANY THIRD PARTY RIGHTS.
#
# 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
# FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
# A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
# OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
#
# 6. This License Agreement will automatically terminate upon a material
# breach of its terms and conditions.
#
# 7. Nothing in this License Agreement shall be deemed to create any
# relationship of agency, partnership, or joint venture between PSF and
# Licensee. This License Agreement does not grant permission to use PSF
# trademarks or trade name in a trademark sense to endorse or promote
# products or services of Licensee, or any third party.
#
# 8. By copying, installing or otherwise using Python, Licensee
# agrees to be bound by the terms and conditions of this License
# Agreement.
'''
The **urls** utils module offers a replacement for the urllib2 python library.
urllib2 is the python stdlib way to retrieve files from the Internet but it
lacks some security features (around verifying SSL certificates) that users
should care about in most situations. Using the functions in this module corrects
deficiencies in the urllib2 module wherever possible.
There are also third-party libraries (for instance, requests) which can be used
to replace urllib2 with a more secure library. However, all third party libraries
require that the library be installed on the managed machine. That is an extra step
for users making use of a module. If possible, avoid third party libraries by using
this code instead.
'''
import base64
import netrc
import os
import platform
import re
import socket
import sys
import tempfile
import traceback
try:
import httplib
except ImportError:
# Python 3
import http.client as httplib
import ansible.module_utils.six.moves.http_cookiejar as cookiejar
import ansible.module_utils.six.moves.urllib.request as urllib_request
import ansible.module_utils.six.moves.urllib.error as urllib_error
from ansible.module_utils.basic import get_distribution
from ansible.module_utils._text import to_bytes, to_native, to_text
try:
# python3
import urllib.request as urllib_request
from urllib.request import AbstractHTTPHandler
except ImportError:
# python2
import urllib2 as urllib_request
from urllib2 import AbstractHTTPHandler
try:
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlunparse
HAS_URLPARSE = True
except:
HAS_URLPARSE = False
try:
import ssl
HAS_SSL = True
except:
HAS_SSL = False
try:
# SNI Handling needs python2.7.9's SSLContext
from ssl import create_default_context, SSLContext
HAS_SSLCONTEXT = True
except ImportError:
HAS_SSLCONTEXT = False
# SNI Handling for python < 2.7.9 with urllib3 support
try:
# urllib3>=1.15
HAS_URLLIB3_SSL_WRAP_SOCKET = False
try:
from urllib3.contrib.pyopenssl import PyOpenSSLContext
except ImportError:
from requests.packages.urllib3.contrib.pyopenssl import PyOpenSSLContext
HAS_URLLIB3_PYOPENSSLCONTEXT = True
except ImportError:
# urllib3<1.15,>=1.6
HAS_URLLIB3_PYOPENSSLCONTEXT = False
try:
try:
from urllib3.contrib.pyopenssl import ssl_wrap_socket
except ImportError:
from requests.packages.urllib3.contrib.pyopenssl import ssl_wrap_socket
HAS_URLLIB3_SSL_WRAP_SOCKET = True
except ImportError:
pass
# Select a protocol that includes all secure tls protocols
# Exclude insecure ssl protocols if possible
if HAS_SSL:
# If we can't find extra tls methods, ssl.PROTOCOL_TLSv1 is sufficient
PROTOCOL = ssl.PROTOCOL_TLSv1
if not HAS_SSLCONTEXT and HAS_SSL:
try:
import ctypes
import ctypes.util
except ImportError:
# python 2.4 (likely rhel5 which doesn't have tls1.1 support in its openssl)
pass
else:
libssl_name = ctypes.util.find_library('ssl')
libssl = ctypes.CDLL(libssl_name)
for method in ('TLSv1_1_method', 'TLSv1_2_method'):
try:
libssl[method]
# Found something - we'll let openssl autonegotiate and hope
# the server has disabled sslv2 and 3. best we can do.
PROTOCOL = ssl.PROTOCOL_SSLv23
break
except AttributeError:
pass
del libssl
LOADED_VERIFY_LOCATIONS = set()
HAS_MATCH_HOSTNAME = True
try:
from ssl import match_hostname, CertificateError
except ImportError:
try:
from backports.ssl_match_hostname import match_hostname, CertificateError
except ImportError:
HAS_MATCH_HOSTNAME = False
if not HAS_MATCH_HOSTNAME:
# The following block of code is under the terms and conditions of the
# Python Software Foundation License
"""The match_hostname() function from Python 3.4, essential when using SSL."""
class CertificateError(ValueError):
pass
def _dnsname_match(dn, hostname, max_wildcards=1):
"""Matching according to RFC 6125, section 6.4.3
http://tools.ietf.org/html/rfc6125#section-6.4.3
"""
pats = []
if not dn:
return False
# Ported from python3-syntax:
# leftmost, *remainder = dn.split(r'.')
parts = dn.split(r'.')
leftmost = parts[0]
remainder = parts[1:]
wildcards = leftmost.count('*')
if wildcards > max_wildcards:
# Issue #17980: avoid denials of service by refusing more
# than one wildcard per fragment. A survey of established
# policy among SSL implementations showed it to be a
# reasonable choice.
raise CertificateError(
"too many wildcards in certificate DNS name: " + repr(dn))
# speed up common case w/o wildcards
if not wildcards:
return dn.lower() == hostname.lower()
# RFC 6125, section 6.4.3, subitem 1.
# The client SHOULD NOT attempt to match a presented identifier in which
# the wildcard character comprises a label other than the left-most label.
if leftmost == '*':
# When '*' is a fragment by itself, it matches a non-empty dotless
# fragment.
pats.append('[^.]+')
elif leftmost.startswith('xn--') or hostname.startswith('xn--'):
# RFC 6125, section 6.4.3, subitem 3.
# The client SHOULD NOT attempt to match a presented identifier
# where the wildcard character is embedded within an A-label or
# U-label of an internationalized domain name.
pats.append(re.escape(leftmost))
else:
# Otherwise, '*' matches any dotless string, e.g. www*
pats.append(re.escape(leftmost).replace(r'\*', '[^.]*'))
# add the remaining fragments, ignore any wildcards
for frag in remainder:
pats.append(re.escape(frag))
pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
return pat.match(hostname)
def match_hostname(cert, hostname):
"""Verify that *cert* (in decoded format as returned by
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
rules are followed, but IP addresses are not accepted for *hostname*.
CertificateError is raised on failure. On success, the function
returns nothing.
"""
if not cert:
raise ValueError("empty or no certificate")
dnsnames = []
san = cert.get('subjectAltName', ())
for key, value in san:
if key == 'DNS':
if _dnsname_match(value, hostname):
return
dnsnames.append(value)
if not dnsnames:
# The subject is only checked when there is no dNSName entry
# in subjectAltName
for sub in cert.get('subject', ()):
for key, value in sub:
# XXX according to RFC 2818, the most specific Common Name
# must be used.
if key == 'commonName':
if _dnsname_match(value, hostname):
return
dnsnames.append(value)
if len(dnsnames) > 1:
raise CertificateError("hostname %r " "doesn't match either of %s" % (hostname, ', '.join(map(repr, dnsnames))))
elif len(dnsnames) == 1:
raise CertificateError("hostname %r doesn't match %r" % (hostname, dnsnames[0]))
else:
raise CertificateError("no appropriate commonName or subjectAltName fields were found")
# End of Python Software Foundation Licensed code
HAS_MATCH_HOSTNAME = True
# This is a dummy cacert provided for Mac OS since you need at least 1
# ca cert, regardless of validity, for Python on Mac OS to use the
# keychain functionality in OpenSSL for validating SSL certificates.
# See: http://mercurial.selenic.com/wiki/CACertificates#Mac_OS_X_10.6_and_higher
b_DUMMY_CA_CERT = b"""-----BEGIN CERTIFICATE-----
MIICvDCCAiWgAwIBAgIJAO8E12S7/qEpMA0GCSqGSIb3DQEBBQUAMEkxCzAJBgNV
BAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEPMA0GA1UEBxMGRHVyaGFt
MRAwDgYDVQQKEwdBbnNpYmxlMB4XDTE0MDMxODIyMDAyMloXDTI0MDMxNTIyMDAy
MlowSTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYD
VQQHEwZEdXJoYW0xEDAOBgNVBAoTB0Fuc2libGUwgZ8wDQYJKoZIhvcNAQEBBQAD
gY0AMIGJAoGBANtvpPq3IlNlRbCHhZAcP6WCzhc5RbsDqyh1zrkmLi0GwcQ3z/r9
gaWfQBYhHpobK2Tiq11TfraHeNB3/VfNImjZcGpN8Fl3MWwu7LfVkJy3gNNnxkA1
4Go0/LmIvRFHhbzgfuo9NFgjPmmab9eqXJceqZIlz2C8xA7EeG7ku0+vAgMBAAGj
gaswgagwHQYDVR0OBBYEFPnN1nPRqNDXGlCqCvdZchRNi/FaMHkGA1UdIwRyMHCA
FPnN1nPRqNDXGlCqCvdZchRNi/FaoU2kSzBJMQswCQYDVQQGEwJVUzEXMBUGA1UE
CBMOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcTBkR1cmhhbTEQMA4GA1UEChMHQW5z
aWJsZYIJAO8E12S7/qEpMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEA
MUB80IR6knq9K/tY+hvPsZer6eFMzO3JGkRFBh2kn6JdMDnhYGX7AXVHGflrwNQH
qFy+aenWXsC0ZvrikFxbQnX8GVtDADtVznxOi7XzFw7JOxdsVrpXgSN0eh0aMzvV
zKPZsZ2miVGclicJHzm5q080b1p/sZtuKIEZk6vZqEg=
-----END CERTIFICATE-----
"""
#
# Exceptions
#
class ConnectionError(Exception):
"""Failed to connect to the server"""
pass
class ProxyError(ConnectionError):
"""Failure to connect because of a proxy"""
pass
class SSLValidationError(ConnectionError):
"""Failure to connect due to SSL validation failing"""
pass
class NoSSLError(SSLValidationError):
"""Needed to connect to an HTTPS url but no ssl library available to verify the certificate"""
pass
# Some environments (Google Compute Engine's CoreOS deploys) do not compile
# against openssl and thus do not have any HTTPS support.
CustomHTTPSConnection = CustomHTTPSHandler = None
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib_request, 'HTTPSHandler'):
class CustomHTTPSConnection(httplib.HTTPSConnection):
def __init__(self, *args, **kwargs):
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
self.context = None
if HAS_SSLCONTEXT:
self.context = create_default_context()
elif HAS_URLLIB3_PYOPENSSLCONTEXT:
self.context = PyOpenSSLContext(PROTOCOL)
if self.context and self.cert_file:
self.context.load_cert_chain(self.cert_file, self.key_file)
def connect(self):
"Connect to a host on a given (SSL) port."
if hasattr(self, 'source_address'):
sock = socket.create_connection((self.host, self.port), self.timeout, self.source_address)
else:
sock = socket.create_connection((self.host, self.port), self.timeout)
server_hostname = self.host
# Note: self._tunnel_host is not available on py < 2.6 but this code
# isn't used on py < 2.6 (lack of create_connection)
if self._tunnel_host:
self.sock = sock
self._tunnel()
server_hostname = self._tunnel_host
if HAS_SSLCONTEXT or HAS_URLLIB3_PYOPENSSLCONTEXT:
self.sock = self.context.wrap_socket(sock, server_hostname=server_hostname)
elif HAS_URLLIB3_SSL_WRAP_SOCKET:
self.sock = ssl_wrap_socket(sock, keyfile=self.key_file, cert_reqs=ssl.CERT_NONE, certfile=self.cert_file, ssl_version=PROTOCOL,
server_hostname=server_hostname)
else:
self.sock = ssl.wrap_socket(sock, keyfile=self.key_file, certfile=self.cert_file, ssl_version=PROTOCOL)
class CustomHTTPSHandler(urllib_request.HTTPSHandler):
def https_open(self, req):
return self.do_open(CustomHTTPSConnection, req)
https_request = AbstractHTTPHandler.do_request_
class HTTPSClientAuthHandler(urllib_request.HTTPSHandler):
'''Handles client authentication via cert/key
This is a fairly lightweight extension on HTTPSHandler, and can be used
in place of HTTPSHandler
'''
def __init__(self, client_cert=None, client_key=None, **kwargs):
urllib_request.HTTPSHandler.__init__(self, **kwargs)
self.client_cert = client_cert
self.client_key = client_key
def https_open(self, req):
return self.do_open(self._build_https_connection, req)
def _build_https_connection(self, host, **kwargs):
kwargs.update({
'cert_file': self.client_cert,
'key_file': self.client_key,
})
try:
kwargs['context'] = self._context
except AttributeError:
pass
return httplib.HTTPSConnection(host, **kwargs)
def generic_urlparse(parts):
'''
Returns a dictionary of url parts as parsed by urlparse,
but accounts for the fact that older versions of that
library do not support named attributes (ie. .netloc)
'''
generic_parts = dict()
if hasattr(parts, 'netloc'):
# urlparse is newer, just read the fields straight
# from the parts object
generic_parts['scheme'] = parts.scheme
generic_parts['netloc'] = parts.netloc
generic_parts['path'] = parts.path
generic_parts['params'] = parts.params
generic_parts['query'] = parts.query
generic_parts['fragment'] = parts.fragment
generic_parts['username'] = parts.username
generic_parts['password'] = parts.password
generic_parts['hostname'] = parts.hostname
generic_parts['port'] = parts.port
else:
# we have to use indexes, and then parse out
# the other parts not supported by indexing
generic_parts['scheme'] = parts[0]
generic_parts['netloc'] = parts[1]
generic_parts['path'] = parts[2]
generic_parts['params'] = parts[3]
generic_parts['query'] = parts[4]
generic_parts['fragment'] = parts[5]
# get the username, password, etc.
try:
netloc_re = re.compile(r'^((?:\w)+(?::(?:\w)+)?@)?([A-Za-z0-9.-]+)(:\d+)?$')
match = netloc_re.match(parts[1])
auth = match.group(1)
hostname = match.group(2)
port = match.group(3)
if port:
# the capture group for the port will include the ':',
# so remove it and convert the port to an integer
port = int(port[1:])
if auth:
# the capture group above includes the @, so remove it
# and then split it up based on the first ':' found
auth = auth[:-1]
username, password = auth.split(':', 1)
else:
username = password = None
generic_parts['username'] = username
generic_parts['password'] = password
generic_parts['hostname'] = hostname
generic_parts['port'] = port
except:
generic_parts['username'] = None
generic_parts['password'] = None
generic_parts['hostname'] = parts[1]
generic_parts['port'] = None
return generic_parts
class RequestWithMethod(urllib_request.Request):
'''
Workaround for using DELETE/PUT/etc with urllib2
Originally contained in library/net_infrastructure/dnsmadeeasy
'''
def __init__(self, url, method, data=None, headers=None):
if headers is None:
headers = {}
self._method = method.upper()
urllib_request.Request.__init__(self, url, data, headers)
def get_method(self):
if self._method:
return self._method
else:
return urllib_request.Request.get_method(self)
def RedirectHandlerFactory(follow_redirects=None, validate_certs=True):
"""This is a class factory that closes over the value of
``follow_redirects`` so that the RedirectHandler class has access to
that value without having to use globals, and potentially cause problems
where ``open_url`` or ``fetch_url`` are used multiple times in a module.
"""
class RedirectHandler(urllib_request.HTTPRedirectHandler):
"""This is an implementation of a RedirectHandler to match the
functionality provided by httplib2. It will utilize the value of
``follow_redirects`` that is passed into ``RedirectHandlerFactory``
to determine how redirects should be handled in urllib2.
"""
def redirect_request(self, req, fp, code, msg, hdrs, newurl):
handler = maybe_add_ssl_handler(newurl, validate_certs)
if handler:
urllib_request._opener.add_handler(handler)
if follow_redirects == 'urllib2':
return urllib_request.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, hdrs, newurl)
elif follow_redirects in ['no', 'none', False]:
raise urllib_error.HTTPError(newurl, code, msg, hdrs, fp)
do_redirect = False
if follow_redirects in ['all', 'yes', True]:
do_redirect = (code >= 300 and code < 400)
elif follow_redirects == 'safe':
m = req.get_method()
do_redirect = (code >= 300 and code < 400 and m in ('GET', 'HEAD'))
if do_redirect:
# be conciliant with URIs containing a space
newurl = newurl.replace(' ', '%20')
newheaders = dict((k, v) for k, v in req.headers.items()
if k.lower() not in ("content-length", "content-type"))
try:
# Python 2-3.3
origin_req_host = req.get_origin_req_host()
except AttributeError:
# Python 3.4+
origin_req_host = req.origin_req_host
return urllib_request.Request(newurl,
headers=newheaders,
origin_req_host=origin_req_host,
unverifiable=True)
else:
raise urllib_error.HTTPError(req.get_full_url(), code, msg, hdrs, fp)
return RedirectHandler
def build_ssl_validation_error(hostname, port, paths, exc=None):
'''Inteligently build out the SSLValidationError based on what support
you have installed
'''
msg = [
('Failed to validate the SSL certificate for %s:%s.'
' Make sure your managed systems have a valid CA'
' certificate installed.')
]
if not HAS_SSLCONTEXT:
msg.append('If the website serving the url uses SNI you need'
' python >= 2.7.9 on your managed machine')
msg.append(' (the python executable used (%s) is version: %s)' %
(sys.executable, ''.join(sys.version.splitlines())))
if not HAS_URLLIB3_PYOPENSSLCONTEXT or not HAS_URLLIB3_SSL_WRAP_SOCKET:
msg.append('or you can install the `urllib3`, `pyOpenSSL`,'
' `ndg-httpsclient`, and `pyasn1` python modules')
msg.append('to perform SNI verification in python >= 2.6.')
msg.append('You can use validate_certs=False if you do'
' not need to confirm the servers identity but this is'
' unsafe and not recommended.'
' Paths checked for this platform: %s.')
if exc:
msg.append('The exception msg was: %s.' % to_native(exc))
raise SSLValidationError(' '.join(msg) % (hostname, port, ", ".join(paths)))
class SSLValidationHandler(urllib_request.BaseHandler):
'''
A custom handler class for SSL validation.
Based on:
http://stackoverflow.com/questions/1087227/validate-ssl-certificates-with-python
http://techknack.net/python-urllib2-handlers/
'''
CONNECT_COMMAND = "CONNECT %s:%s HTTP/1.0\r\nConnection: close\r\n"
def __init__(self, hostname, port):
self.hostname = hostname
self.port = port
def get_ca_certs(self):
# tries to find a valid CA cert in one of the
# standard locations for the current distribution
ca_certs = []
paths_checked = []
system = to_text(platform.system(), errors='surrogate_or_strict')
# build a list of paths to check for .crt/.pem files
# based on the platform type
paths_checked.append('/etc/ssl/certs')
if system == u'Linux':
paths_checked.append('/etc/pki/ca-trust/extracted/pem')
paths_checked.append('/etc/pki/tls/certs')
paths_checked.append('/usr/share/ca-certificates/cacert.org')
elif system == u'FreeBSD':
paths_checked.append('/usr/local/share/certs')
elif system == u'OpenBSD':
paths_checked.append('/etc/ssl')
elif system == u'NetBSD':
ca_certs.append('/etc/openssl/certs')
elif system == u'SunOS':
paths_checked.append('/opt/local/etc/openssl/certs')
# fall back to a user-deployed cert in a standard
# location if the OS platform one is not available
paths_checked.append('/etc/ansible')
tmp_fd, tmp_path = tempfile.mkstemp()
to_add_fd, to_add_path = tempfile.mkstemp()
to_add = False
# Write the dummy ca cert if we are running on Mac OS X
if system == u'Darwin':
os.write(tmp_fd, b_DUMMY_CA_CERT)
# Default Homebrew path for OpenSSL certs
paths_checked.append('/usr/local/etc/openssl')
# for all of the paths, find any .crt or .pem files
# and compile them into single temp file for use
# in the ssl check to speed up the test
for path in paths_checked:
if os.path.exists(path) and os.path.isdir(path):
dir_contents = os.listdir(path)
for f in dir_contents:
full_path = os.path.join(path, f)
if os.path.isfile(full_path) and os.path.splitext(f)[1] in ('.crt', '.pem'):
try:
cert_file = open(full_path, 'rb')
cert = cert_file.read()
cert_file.close()
os.write(tmp_fd, cert)
os.write(tmp_fd, b'\n')
if full_path not in LOADED_VERIFY_LOCATIONS:
to_add = True
os.write(to_add_fd, cert)
os.write(to_add_fd, b'\n')
LOADED_VERIFY_LOCATIONS.add(full_path)
except (OSError, IOError):
pass
if not to_add:
to_add_path = None
return (tmp_path, to_add_path, paths_checked)
def validate_proxy_response(self, response, valid_codes=[200]):
'''
make sure we get back a valid code from the proxy
'''
try:
(http_version, resp_code, msg) = re.match(r'(HTTP/\d\.\d) (\d\d\d) (.*)', response).groups()
if int(resp_code) not in valid_codes:
raise Exception
except:
raise ProxyError('Connection to proxy failed')
def detect_no_proxy(self, url):
'''
Detect if the 'no_proxy' environment variable is set and honor those locations.
'''
env_no_proxy = os.environ.get('no_proxy')
if env_no_proxy:
env_no_proxy = env_no_proxy.split(',')
netloc = urlparse(url).netloc
for host in env_no_proxy:
if netloc.endswith(host) or netloc.split(':')[0].endswith(host):
# Our requested URL matches something in no_proxy, so don't
# use the proxy for this
return False
return True
def _make_context(self, to_add_ca_cert_path):
if HAS_URLLIB3_PYOPENSSLCONTEXT:
context = PyOpenSSLContext(PROTOCOL)
else:
context = create_default_context()
if to_add_ca_cert_path:
context.load_verify_locations(to_add_ca_cert_path)
return context
def http_request(self, req):
tmp_ca_cert_path, to_add_ca_cert_path, paths_checked = self.get_ca_certs()
https_proxy = os.environ.get('https_proxy')
context = None
if HAS_SSLCONTEXT or HAS_URLLIB3_PYOPENSSLCONTEXT:
context = self._make_context(to_add_ca_cert_path)
# Detect if 'no_proxy' environment variable is set and if our URL is included
use_proxy = self.detect_no_proxy(req.get_full_url())
if not use_proxy:
# ignore proxy settings for this host request
return req
try:
if https_proxy:
proxy_parts = generic_urlparse(urlparse(https_proxy))
port = proxy_parts.get('port') or 443
s = socket.create_connection((proxy_parts.get('hostname'), port))
if proxy_parts.get('scheme') == 'http':
s.sendall(self.CONNECT_COMMAND % (self.hostname, self.port))
if proxy_parts.get('username'):
credentials = "%s:%s" % (proxy_parts.get('username', ''), proxy_parts.get('password', ''))
s.sendall(b'Proxy-Authorization: Basic %s\r\n' % base64.b64encode(to_bytes(credentials, errors='surrogate_or_strict')).strip())
s.sendall(b'\r\n')
connect_result = b""
while connect_result.find(b"\r\n\r\n") <= 0:
connect_result += s.recv(4096)
# 128 kilobytes of headers should be enough for everyone.
if len(connect_result) > 131072:
raise ProxyError('Proxy sent too verbose headers. Only 128KiB allowed.')
self.validate_proxy_response(connect_result)
if context:
ssl_s = context.wrap_socket(s, server_hostname=self.hostname)
elif HAS_URLLIB3_SSL_WRAP_SOCKET:
ssl_s = ssl_wrap_socket(s, ca_certs=tmp_ca_cert_path, cert_reqs=ssl.CERT_REQUIRED, ssl_version=PROTOCOL, server_hostname=self.hostname)
else:
ssl_s = ssl.wrap_socket(s, ca_certs=tmp_ca_cert_path, cert_reqs=ssl.CERT_REQUIRED, ssl_version=PROTOCOL)
match_hostname(ssl_s.getpeercert(), self.hostname)
else:
raise ProxyError('Unsupported proxy scheme: %s. Currently ansible only supports HTTP proxies.' % proxy_parts.get('scheme'))
else:
s = socket.create_connection((self.hostname, self.port))
if context:
ssl_s = context.wrap_socket(s, server_hostname=self.hostname)
elif HAS_URLLIB3_SSL_WRAP_SOCKET:
ssl_s = ssl_wrap_socket(s, ca_certs=tmp_ca_cert_path, cert_reqs=ssl.CERT_REQUIRED, ssl_version=PROTOCOL, server_hostname=self.hostname)
else:
ssl_s = ssl.wrap_socket(s, ca_certs=tmp_ca_cert_path, cert_reqs=ssl.CERT_REQUIRED, ssl_version=PROTOCOL)
match_hostname(ssl_s.getpeercert(), self.hostname)
# close the ssl connection
# ssl_s.unwrap()
s.close()
except (ssl.SSLError, CertificateError) as e:
build_ssl_validation_error(self.hostname, self.port, paths_checked, e)
except socket.error as e:
raise ConnectionError('Failed to connect to %s at port %s: %s' % (self.hostname, self.port, to_native(e)))
try:
# cleanup the temp file created, don't worry
# if it fails for some reason
os.remove(tmp_ca_cert_path)
except:
pass
try:
# cleanup the temp file created, don't worry
# if it fails for some reason
if to_add_ca_cert_path:
os.remove(to_add_ca_cert_path)
except:
pass
return req
https_request = http_request
def maybe_add_ssl_handler(url, validate_certs):
# FIXME: change the following to use the generic_urlparse function
# to remove the indexed references for 'parsed'
parsed = urlparse(url)
if parsed[0] == 'https' and validate_certs:
if not HAS_SSL:
raise NoSSLError('SSL validation is not available in your version of python. You can use validate_certs=False,'
' however this is unsafe and not recommended')
# do the cert validation
netloc = parsed[1]
if '@' in netloc:
netloc = netloc.split('@', 1)[1]
if ':' in netloc:
hostname, port = netloc.split(':', 1)
port = int(port)
else:
hostname = netloc
port = 443
# create the SSL validation handler and
# add it to the list of handlers
return SSLValidationHandler(hostname, port)
def open_url(url, data=None, headers=None, method=None, use_proxy=True,
force=False, last_mod_time=None, timeout=10, validate_certs=True,
url_username=None, url_password=None, http_agent=None,
force_basic_auth=False, follow_redirects='urllib2',
client_cert=None, client_key=None, cookies=None):
'''
Sends a request via HTTP(S) or FTP using urllib2 (Python2) or urllib (Python3)
Does not require the module environment
'''
handlers = []
ssl_handler = maybe_add_ssl_handler(url, validate_certs)
if ssl_handler:
handlers.append(ssl_handler)
# FIXME: change the following to use the generic_urlparse function
# to remove the indexed references for 'parsed'
parsed = urlparse(url)
if parsed[0] != 'ftp':
username = url_username
if headers is None:
headers = {}
if username:
password = url_password
netloc = parsed[1]
elif '@' in parsed[1]:
credentials, netloc = parsed[1].split('@', 1)
if ':' in credentials:
username, password = credentials.split(':', 1)
else:
username = credentials
password = ''
parsed = list(parsed)
parsed[1] = netloc
# reconstruct url without credentials
url = urlunparse(parsed)
if username and not force_basic_auth:
passman = urllib_request.HTTPPasswordMgrWithDefaultRealm()
# this creates a password manager
passman.add_password(None, netloc, username, password)
# because we have put None at the start it will always
# use this username/password combination for urls
# for which `theurl` is a super-url
authhandler = urllib_request.HTTPBasicAuthHandler(passman)
digest_authhandler = urllib_request.HTTPDigestAuthHandler(passman)
# create the AuthHandler
handlers.append(authhandler)
handlers.append(digest_authhandler)
elif username and force_basic_auth:
headers["Authorization"] = basic_auth_header(username, password)
else:
try:
rc = netrc.netrc(os.environ.get('NETRC'))
login = rc.authenticators(parsed[1])
except IOError:
login = None
if login:
username, _, password = login
if username and password:
headers["Authorization"] = basic_auth_header(username, password)
if not use_proxy:
proxyhandler = urllib_request.ProxyHandler({})
handlers.append(proxyhandler)
if HAS_SSLCONTEXT and not validate_certs:
# In 2.7.9, the default context validates certificates
context = SSLContext(ssl.PROTOCOL_SSLv23)
context.options |= ssl.OP_NO_SSLv2
context.options |= ssl.OP_NO_SSLv3
context.verify_mode = ssl.CERT_NONE
context.check_hostname = False
handlers.append(HTTPSClientAuthHandler(client_cert=client_cert,
client_key=client_key,
context=context))
elif client_cert:
handlers.append(HTTPSClientAuthHandler(client_cert=client_cert,
client_key=client_key))
# pre-2.6 versions of python cannot use the custom https
# handler, since the socket class is lacking create_connection.
# Some python builds lack HTTPS support.
if hasattr(socket, 'create_connection') and CustomHTTPSHandler:
handlers.append(CustomHTTPSHandler)
handlers.append(RedirectHandlerFactory(follow_redirects, validate_certs))
# add some nicer cookie handling
if cookies is not None:
handlers.append(urllib_request.HTTPCookieProcessor(cookies))
opener = urllib_request.build_opener(*handlers)
urllib_request.install_opener(opener)
data = to_bytes(data, nonstring='passthru')
if method:
if method.upper() not in ('OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT', 'PATCH'):
raise ConnectionError('invalid HTTP request method; %s' % method.upper())
request = RequestWithMethod(url, method.upper(), data)
else:
request = urllib_request.Request(url, data)
# add the custom agent header, to help prevent issues
# with sites that block the default urllib agent string
if http_agent:
request.add_header('User-agent', http_agent)
# Cache control
# Either we directly force a cache refresh
if force:
request.add_header('cache-control', 'no-cache')
# or we do it if the original is more recent than our copy
elif last_mod_time:
tstamp = last_mod_time.strftime('%a, %d %b %Y %H:%M:%S +0000')
request.add_header('If-Modified-Since', tstamp)
# user defined headers now, which may override things we've set above
if headers:
if not isinstance(headers, dict):
raise ValueError("headers provided to fetch_url() must be a dict")
for header in headers:
request.add_header(header, headers[header])
urlopen_args = [request, None]
if sys.version_info >= (2, 6, 0):
# urlopen in python prior to 2.6.0 did not
# have a timeout parameter
urlopen_args.append(timeout)
r = urllib_request.urlopen(*urlopen_args)
return r
#
# Module-related functions
#
def basic_auth_header(username, password):
"""Takes a username and password and returns a byte string suitable for
using as value of an Authorization header to do basic auth.
"""
return b"Basic %s" % base64.b64encode(to_bytes("%s:%s" % (username, password), errors='surrogate_or_strict'))
def url_argument_spec():
'''
Creates an argument spec that can be used with any module
that will be requesting content via urllib/urllib2
'''
return dict(
url=dict(),
force=dict(default='no', aliases=['thirsty'], type='bool'),
http_agent=dict(default='ansible-httpget'),
use_proxy=dict(default='yes', type='bool'),
validate_certs=dict(default='yes', type='bool'),
url_username=dict(required=False),
url_password=dict(required=False, no_log=True),
force_basic_auth=dict(required=False, type='bool', default='no'),
client_cert=dict(required=False, type='path', default=None),
client_key=dict(required=False, type='path', default=None),
)
def fetch_url(module, url, data=None, headers=None, method=None,
use_proxy=True, force=False, last_mod_time=None, timeout=10):
"""Sends a request via HTTP(S) or FTP (needs the module as parameter)
:arg module: The AnsibleModule (used to get username, password etc. (s.b.).
:arg url: The url to use.
:kwarg data: The data to be sent (in case of POST/PUT).
:kwarg headers: A dict with the request headers.
:kwarg method: "POST", "PUT", etc.
:kwarg boolean use_proxy: Default: True
:kwarg boolean force: If True: Do not get a cached copy (Default: False)
:kwarg last_mod_time: Default: None
:kwarg int timeout: Default: 10
:returns: A tuple of (**response**, **info**). Use ``response.body()`` to read the data.
The **info** contains the 'status' and other meta data. When a HttpError (status > 400)
occurred then ``info['body']`` contains the error response data::
Example::
data={...}
resp, info = fetch_url(module,
"http://example.com",
data=module.jsonify(data)
header={Content-type': 'application/json'},
method="POST")
status_code = info["status"]
body = resp.read()
if status_code >= 400 :
body = info['body']
"""
if not HAS_URLPARSE:
module.fail_json(msg='urlparse is not installed')
# Get validate_certs from the module params
validate_certs = module.params.get('validate_certs', True)
username = module.params.get('url_username', '')
password = module.params.get('url_password', '')
http_agent = module.params.get('http_agent', 'ansible-httpget')
force_basic_auth = module.params.get('force_basic_auth', '')
follow_redirects = module.params.get('follow_redirects', 'urllib2')
client_cert = module.params.get('client_cert')
client_key = module.params.get('client_key')
cookies = cookiejar.LWPCookieJar()
r = None
info = dict(url=url)
try:
r = open_url(url, data=data, headers=headers, method=method,
use_proxy=use_proxy, force=force, last_mod_time=last_mod_time, timeout=timeout,
validate_certs=validate_certs, url_username=username,
url_password=password, http_agent=http_agent, force_basic_auth=force_basic_auth,
follow_redirects=follow_redirects, client_cert=client_cert,
client_key=client_key, cookies=cookies)
info.update(r.info())
# parse the cookies into a nice dictionary
cookie_dict = dict()
for cookie in cookies:
cookie_dict[cookie.name] = cookie.value
info['cookies'] = cookie_dict
# finally update the result with a message about the fetch
info.update(dict(msg="OK (%s bytes)" % r.headers.get('Content-Length', 'unknown'), url=r.geturl(), status=r.code))
except NoSSLError as e:
distribution = get_distribution()
if distribution is not None and distribution.lower() == 'redhat':
module.fail_json(msg='%s. You can also install python-ssl from EPEL' % to_native(e))
else:
module.fail_json(msg='%s' % to_native(e))
except (ConnectionError, ValueError) as e:
module.fail_json(msg=to_native(e))
except urllib_error.HTTPError as e:
try:
body = e.read()
except AttributeError:
body = ''
# Try to add exception info to the output but don't fail if we can't
try:
info.update(dict(**e.info()))
except:
pass
info.update({'msg': to_native(e), 'body': body, 'status': e.code})
except urllib_error.URLError as e:
code = int(getattr(e, 'code', -1))
info.update(dict(msg="Request failed: %s" % to_native(e), status=code))
except socket.error as e:
info.update(dict(msg="Connection failure: %s" % to_native(e), status=-1))
except Exception as e:
info.update(dict(msg="An unknown error occurred: %s" % to_native(e), status=-1),
exception=traceback.format_exc())
return r, info
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
6244,
6029,
13,
6965,
199,
3,
1898,
334,
67,
395,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
2663,
300,
4188,
73,
32,
4853,
14,
957,
6244,
6900,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
710,
1336,
63,
4269,
805,
436,
21038,
1233,
365,
1334,
314,
2895,
436,
199,
3,
3704,
402,
314,
2018,
2290,
2752,
844,
14,
221,
9322,
4898,
9394,
687,
199,
3,
314,
2018,
19,
4465,
3555,
436,
26266,
367,
675,
315,
2018,
18,
14,
221,
1666,
6786,
315,
314,
199,
3,
1350,
367,
1314,
1233,
28334,
590,
365,
1334,
642,
844,
14,
221,
29770,
844,
1318,
199,
3,
11924,
26,
199,
3,
199,
3,
18280,
4141,
481,
47,
6131,
2594,
5113,
15945,
499,
199,
3,
11016,
4559,
199,
3,
199,
3,
413,
14,
961,
5113,
26787,
907,
9591,
365,
3382,
314,
2018,
2290,
2752,
199,
3,
1689,
5067,
38,
1288,
436,
314,
1010,
15067,
503,
18863,
1689,
3761,
69,
531,
18549,
436,
199,
3,
4257,
1808,
642,
2032,
1689,
4718,
531,
315,
1350,
503,
3366,
1824,
436,
199,
3,
2399,
4568,
3794,
14,
199,
3,
199,
3,
499,
14,
26793,
370,
314,
2895,
436,
3704,
402,
642,
844,
28629,
12,
29770,
11882,
199,
3,
7192,
2285,
844,
69,
282,
7179,
88,
6563,
12,
882,
89,
13248,
13,
4624,
12,
6701,
13,
13062,
4190,
370,
9172,
12,
199,
3,
19897,
12,
511,
12,
5147,
436,
15,
269,
2929,
7974,
317,
429,
89,
12,
9275,
18883,
5419,
12,
199,
3,
11207,
12,
436,
4257,
675,
2018,
23016,
503,
315,
1263,
18883,
1015,
12,
199,
3,
2741,
12,
13432,
12,
626,
29770,
1159,
844,
28629,
436,
29770,
1159,
4245,
402,
4248,
12,
199,
3,
284,
14,
69,
2020,
298,
7384,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
199,
3,
7760,
12,
6029,
12,
6171,
12,
6927,
2018,
2290,
2752,
27,
2900,
5924,
5702,
2,
787,
199,
3,
30403,
315,
2018,
23016,
503,
315,
1263,
18883,
1015,
16318,
701,
844,
69,
14,
199,
3,
199,
3,
650,
14,
1010,
314,
1566,
844,
69,
876,
27749,
282,
18883,
1736,
626,
365,
4079,
641,
199,
3,
503,
30147,
2335,
2018,
503,
1263,
1777,
2337,
1618,
12,
436,
15061,
370,
1852,
199,
3,
314,
18883,
1736,
2808,
370,
11789,
465,
2741,
2348,
262,
12,
2066,
199,
3,
844,
69,
11882,
1839,
5710,
370,
2387,
315,
1263,
4066,
1736,
282,
29226,
6212,
402,
199,
3,
314,
4493,
6326,
370,
2018,
14,
199,
3,
199,
3,
841,
14,
29770,
365,
10663,
2018,
2808,
370,
844,
69,
641,
376,
298,
1179,
2281,
2,
199,
3,
5597,
14,
221,
29770,
4828,
43,
654,
4825,
5363,
19743,
12969,
1549,
2990,
12,
7168,
1549,
199,
3,
5292,
14,
221,
6515,
9683,
1634,
3651,
10818,
12,
5400,
2845,
5138,
2594,
12,
29770,
4828,
43,
654,
4825,
2401,
199,
3,
8990,
51,
1821,
5363,
27160,
1549,
3408,
1634,
3169,
1549,
3092,
199,
3,
2381,
1821,
3115,
3104,
1549,
4221,
619,
2334,
4815,
1634,
18280,
644,
14961,
2845,
199,
3,
1621,
12559,
37,
1821,
4221,
3927,
36,
10263,
2099,
7052,
51,
14,
199,
3,
199,
3,
959,
14,
29770,
7000,
2845,
6262,
7024,
2296,
5113,
37,
1549,
1821,
5010,
13044,
51,
1634,
18280,
199,
3,
2381,
1821,
9716,
12,
8820,
12,
1549,
9110,
6736,
1549,
9102,
4319,
199,
3,
437,
20668,
1634,
10362,
1914,
18114,
1206,
12,
5266,
3027,
5406,
1206,
12,
1549,
7334,
32210,
18280,
12,
199,
3,
1549,
1821,
577,
540,
6882,
14277,
377,
5293,
3359,
12,
9704,
8036,
9691,
1634,
2334,
9726,
377,
5293,
3359,
14,
199,
3,
199,
3,
1227,
14,
961,
844,
28629,
911,
5847,
15095,
12188,
282,
6285,
199,
3,
330,
12784,
402,
2399,
2895,
436,
3704,
14,
199,
3,
199,
3,
1520,
14,
20550,
315,
642,
844,
28629,
10989,
506,
27646,
3594,
370,
1218,
1263,
199,
3,
8931,
402,
1839,
9501,
12,
5854,
3319,
12,
503,
22211,
373,
484,
608,
3382,
29770,
436,
199,
3,
844,
69,
14,
221,
961,
844,
28629,
1630,
440,
16085,
4983,
370,
675,
29770
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
6244,
6029,
13,
6965,
199,
3,
1898,
334,
67,
395,
4005,
609,
2308,
1804,
300,
4188,
73,
665,
2663,
300,
4188,
73,
32,
4853,
14,
957,
6244,
6900,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
710,
1336,
63,
4269,
805,
436,
21038,
1233,
365,
1334,
314,
2895,
436,
199,
3,
3704,
402,
314,
2018,
2290,
2752,
844,
14,
221,
9322,
4898,
9394,
687,
199,
3,
314,
2018,
19,
4465,
3555,
436,
26266,
367,
675,
315,
2018,
18,
14,
221,
1666,
6786,
315,
314,
199,
3,
1350,
367,
1314,
1233,
28334,
590,
365,
1334,
642,
844,
14,
221,
29770,
844,
1318,
199,
3,
11924,
26,
199,
3,
199,
3,
18280,
4141,
481,
47,
6131,
2594,
5113,
15945,
499,
199,
3,
11016,
4559,
199,
3,
199,
3,
413,
14,
961,
5113,
26787,
907,
9591,
365,
3382,
314,
2018,
2290,
2752,
199,
3,
1689,
5067,
38,
1288,
436,
314,
1010,
15067,
503,
18863,
1689,
3761,
69,
531,
18549,
436,
199,
3,
4257,
1808,
642,
2032,
1689,
4718,
531,
315,
1350,
503,
3366,
1824,
436,
199,
3,
2399,
4568,
3794,
14,
199,
3,
199,
3,
499,
14,
26793,
370,
314,
2895,
436,
3704,
402,
642,
844,
28629,
12,
29770,
11882,
199,
3,
7192,
2285,
844,
69,
282,
7179,
88,
6563,
12,
882,
89,
13248,
13,
4624,
12,
6701,
13,
13062,
4190,
370,
9172,
12,
199,
3,
19897,
12,
511,
12,
5147,
436,
15,
269,
2929,
7974,
317,
429,
89,
12,
9275,
18883,
5419,
12,
199,
3,
11207,
12,
436,
4257,
675,
2018,
23016,
503,
315,
1263,
18883,
1015,
12,
199,
3,
2741,
12,
13432,
12,
626,
29770,
1159,
844,
28629,
436,
29770,
1159,
4245,
402,
4248,
12,
199,
3,
284,
14,
69,
2020,
298,
7384,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
199,
3,
7760,
12,
6029,
12,
6171,
12,
6927,
2018,
2290,
2752,
27,
2900,
5924,
5702,
2,
787,
199,
3,
30403,
315,
2018,
23016,
503,
315,
1263,
18883,
1015,
16318,
701,
844,
69,
14,
199,
3,
199,
3,
650,
14,
1010,
314,
1566,
844,
69,
876,
27749,
282,
18883,
1736,
626,
365,
4079,
641,
199,
3,
503,
30147,
2335,
2018,
503,
1263,
1777,
2337,
1618,
12,
436,
15061,
370,
1852,
199,
3,
314,
18883,
1736,
2808,
370,
11789,
465,
2741,
2348,
262,
12,
2066,
199,
3,
844,
69,
11882,
1839,
5710,
370,
2387,
315,
1263,
4066,
1736,
282,
29226,
6212,
402,
199,
3,
314,
4493,
6326,
370,
2018,
14,
199,
3,
199,
3,
841,
14,
29770,
365,
10663,
2018,
2808,
370,
844,
69,
641,
376,
298,
1179,
2281,
2,
199,
3,
5597,
14,
221,
29770,
4828,
43,
654,
4825,
5363,
19743,
12969,
1549,
2990,
12,
7168,
1549,
199,
3,
5292,
14,
221,
6515,
9683,
1634,
3651,
10818,
12,
5400,
2845,
5138,
2594,
12,
29770,
4828,
43,
654,
4825,
2401,
199,
3,
8990,
51,
1821,
5363,
27160,
1549,
3408,
1634,
3169,
1549,
3092,
199,
3,
2381,
1821,
3115,
3104,
1549,
4221,
619,
2334,
4815,
1634,
18280,
644,
14961,
2845,
199,
3,
1621,
12559,
37,
1821,
4221,
3927,
36,
10263,
2099,
7052,
51,
14,
199,
3,
199,
3,
959,
14,
29770,
7000,
2845,
6262,
7024,
2296,
5113,
37,
1549,
1821,
5010,
13044,
51,
1634,
18280,
199,
3,
2381,
1821,
9716,
12,
8820,
12,
1549,
9110,
6736,
1549,
9102,
4319,
199,
3,
437,
20668,
1634,
10362,
1914,
18114,
1206,
12,
5266,
3027,
5406,
1206,
12,
1549,
7334,
32210,
18280,
12,
199,
3,
1549,
1821,
577,
540,
6882,
14277,
377,
5293,
3359,
12,
9704,
8036,
9691,
1634,
2334,
9726,
377,
5293,
3359,
14,
199,
3,
199,
3,
1227,
14,
961,
844,
28629,
911,
5847,
15095,
12188,
282,
6285,
199,
3,
330,
12784,
402,
2399,
2895,
436,
3704,
14,
199,
3,
199,
3,
1520,
14,
20550,
315,
642,
844,
28629,
10989,
506,
27646,
3594,
370,
1218,
1263,
199,
3,
8931,
402,
1839,
9501,
12,
5854,
3319,
12,
503,
22211,
373,
484,
608,
3382,
29770,
436,
199,
3,
844,
69,
14,
221,
961,
844,
28629,
1630,
440,
16085,
4983,
370,
675,
29770,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
trondhindenes/ansible
|
lib/ansible/module_utils/facts/network/openbsd.py
|
232
|
1600
|
# 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.module_utils.facts.network.base import NetworkCollector
from ansible.module_utils.facts.network.generic_bsd import GenericBsdIfconfigNetwork
class OpenBSDNetwork(GenericBsdIfconfigNetwork):
"""
This is the OpenBSD Network Class.
It uses the GenericBsdIfconfigNetwork.
"""
platform = 'OpenBSD'
# OpenBSD 'ifconfig -a' does not have information about aliases
def get_interfaces_info(self, ifconfig_path, ifconfig_options='-aA'):
return super(OpenBSDNetwork, self).get_interfaces_info(ifconfig_path, ifconfig_options)
# Return macaddress instead of lladdr
def parse_lladdr_line(self, words, current_if, ips):
current_if['macaddress'] = words[1]
current_if['type'] = 'ether'
class OpenBSDNetworkCollector(NetworkCollector):
_fact_class = OpenBSDNetwork
_platform = 'OpenBSD'
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
6767,
63,
15746,
492,
8307,
34,
3893,
3917,
888,
4491,
421,
199,
533,
3232,
15400,
4491,
8,
9417,
34,
3893,
3917,
888,
4491,
304,
272,
408,
272,
961,
365,
314,
3232,
15400,
7220,
8089,
14,
272,
2779,
4440,
314,
8307,
34,
3893,
3917,
888,
4491,
14,
272,
408,
272,
4298,
275,
283,
4299,
15400,
7,
339,
327,
3232,
15400,
283,
692,
888,
446,
65,
7,
1630,
440,
1172,
2556,
3595,
5481,
272,
347,
664,
63,
7436,
63,
815,
8,
277,
12,
340,
888,
63,
515,
12,
340,
888,
63,
1419,
18274,
65,
33,
735,
267,
372,
1613,
8,
4299,
15400,
4491,
12,
291,
680,
362,
63,
7436,
63,
815,
8,
692,
888,
63,
515,
12,
340,
888,
63,
1419,
9,
339,
327,
1432,
4497,
1562,
3140,
402,
18338,
2697,
272,
347,
2198,
63,
914,
2697,
63,
604,
8,
277,
12,
5932,
12,
1453,
63,
692,
12,
15017,
304,
267,
1453,
63,
692,
459,
3088,
1562,
418,
275,
5932,
59,
17,
61,
267,
1453,
63,
692,
459,
466,
418,
275,
283,
27732,
7,
421,
199,
533,
3232,
15400,
4491,
12852,
8,
4491,
12852,
304,
272,
485,
7783,
63,
533,
275,
3232,
15400,
4491,
272,
485,
3246,
275,
283,
4299,
15400,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
6767,
63,
15746,
492,
8307,
34,
3893,
3917,
888,
4491,
421,
199,
533,
3232,
15400,
4491,
8,
9417,
34,
3893,
3917,
888,
4491,
304,
272,
408,
272,
961,
365,
314,
3232,
15400,
7220,
8089,
14,
272,
2779,
4440,
314,
8307,
34,
3893,
3917,
888,
4491,
14,
272,
408,
272,
4298,
275,
283,
4299,
15400,
7,
339,
327,
3232,
15400,
283,
692,
888,
446,
65,
7,
1630,
440,
1172,
2556,
3595,
5481,
272,
347,
664,
63,
7436,
63,
815,
8,
277,
12,
340,
888,
63,
515,
12,
340,
888,
63,
1419,
18274,
65,
33,
735,
267,
372,
1613,
8,
4299,
15400,
4491,
12,
291,
680,
362,
63,
7436,
63,
815,
8,
692,
888,
63,
515,
12,
340,
888,
63,
1419,
9,
339,
327,
1432,
4497,
1562,
3140,
402,
18338,
2697,
272,
347,
2198,
63,
914,
2697,
63,
604,
8,
277,
12,
5932,
12,
1453,
63,
692,
12,
15017,
304,
267,
1453,
63,
692,
459,
3088,
1562,
418,
275,
5932,
59,
17,
61,
267,
1453,
63,
692,
459,
466,
418,
275,
283,
27732,
7,
421,
199,
533,
3232,
15400,
4491,
12852,
8,
4491,
12852,
304,
272,
485,
7783,
63,
533,
275,
3232,
15400,
4491,
272,
485,
3246,
275,
283,
4299,
15400,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
huihoo/reader
|
vendor/paypal/pro/models.py
|
1
|
4422
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from string import split as L
from django.db import models
from django.utils.http import urlencode
from django.forms.models import model_to_dict
from django.contrib.auth.models import User
class PayPalNVP(models.Model):
"""Record of a NVP interaction with PayPal."""
TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # 2009-02-03T17:47:41Z
RESTRICTED_FIELDS = L("expdate cvv2 acct")
ADMIN_FIELDS = L("id user flag flag_code flag_info query response created_at updated_at ")
ITEM_FIELDS = L("amt custom invnum")
DIRECT_FIELDS = L("firstname lastname street city state countrycode zip")
# Response fields
method = models.CharField(max_length=64, blank=True)
ack = models.CharField(max_length=32, blank=True)
profilestatus = models.CharField(max_length=32, blank=True)
timestamp = models.DateTimeField(blank=True, null=True)
profileid = models.CharField(max_length=32, blank=True) # I-E596DFUSD882
profilereference = models.CharField(max_length=128, blank=True) # PROFILEREFERENCE
correlationid = models.CharField(max_length=32, blank=True) # 25b380cda7a21
token = models.CharField(max_length=64, blank=True)
payerid = models.CharField(max_length=64, blank=True)
# Transaction Fields
firstname = models.CharField("First Name", max_length=255, blank=True)
lastname = models.CharField("Last Name", max_length=255, blank=True)
street = models.CharField("Street Address", max_length=255, blank=True)
city = models.CharField("City", max_length=255, blank=True)
state = models.CharField("State", max_length=255, blank=True)
countrycode = models.CharField("Country", max_length=2,blank=True)
zip = models.CharField("Postal / Zip Code", max_length=32, blank=True)
# Custom fields
invnum = models.CharField(max_length=255, blank=True)
custom = models.CharField(max_length=255, blank=True)
# Admin fields
user = models.ForeignKey(User, blank=True, null=True)
flag = models.BooleanField(default=False, blank=True)
flag_code = models.CharField(max_length=32, blank=True)
flag_info = models.TextField(blank=True)
ipaddress = models.IPAddressField(blank=True)
query = models.TextField(blank=True)
response = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = "paypal_nvp"
verbose_name = "PayPal NVP"
def init(self, request, paypal_request, paypal_response):
"""Initialize a PayPalNVP instance from a HttpRequest."""
self.ipaddress = request.META.get('REMOTE_ADDR', '')
if hasattr(request, "user") and request.user.is_authenticated():
self.user = request.user
# No storing credit card info.
query_data = dict((k,v) for k, v in paypal_request.iteritems() if k not in self.RESTRICTED_FIELDS)
self.query = urlencode(query_data)
self.response = urlencode(paypal_response)
# Was there a flag on the play?
ack = paypal_response.get('ack', False)
if ack != "Success":
if ack == "SuccessWithWarning":
self.flag_info = paypal_response.get('l_longmessage0', '')
else:
self.set_flag(paypal_response.get('l_longmessage0', ''), paypal_response.get('l_errorcode', ''))
def set_flag(self, info, code=None):
"""Flag this instance for investigation."""
self.flag = True
self.flag_info += info
if code is not None:
self.flag_code = code
def process(self, request, item):
"""Do a direct payment."""
from vendor.paypal.pro.helpers import PayPalWPP
wpp = PayPalWPP(request)
# Change the model information into a dict that PayPal can understand.
params = model_to_dict(self, exclude=self.ADMIN_FIELDS)
params['acct'] = self.acct
params['creditcardtype'] = self.creditcardtype
params['expdate'] = self.expdate
params['cvv2'] = self.cvv2
params.update(item)
# Create recurring payment:
if 'billingperiod' in params:
return wpp.createRecurringPaymentsProfile(params, direct=True)
# Create single payment:
else:
return wpp.doDirectPayment(params)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1059,
492,
3715,
465,
491,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
199,
504,
1639,
14,
3351,
14,
992,
492,
1402,
63,
475,
63,
807,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
421,
199,
533,
15911,
24666,
7312,
48,
8,
992,
14,
1685,
304,
272,
408,
5433,
402,
282,
653,
14159,
18752,
543,
15911,
24666,
1041,
272,
32745,
63,
4807,
275,
2071,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
2,
221,
327,
8937,
13,
996,
13,
1644,
52,
1196,
26,
2417,
26,
2953,
58,
272,
14880,
50,
6196,
1149,
63,
12767,
275,
491,
480,
1474,
602,
6277,
86,
18,
29468,
531,
272,
29948,
63,
12767,
275,
491,
480,
344,
922,
3305,
3305,
63,
600,
3305,
63,
815,
1827,
1177,
2737,
63,
292,
4588,
63,
292,
6099,
272,
473,
22057,
63,
12767,
275,
491,
480,
19582,
3537,
4572,
1507,
531,
272,
8703,
63,
12767,
275,
491,
480,
25603,
2061,
354,
410,
7936,
14492,
1174,
9023,
600,
3482,
531,
339,
327,
7232,
1504,
272,
1083,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
272,
19807,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
14821,
4690,
1205,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
272,
4913,
275,
1709,
14,
4626,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
4690,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
221,
327,
473,
13,
37,
15112,
3888,
1668,
36,
19119,
272,
4690,
4443,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
4596,
29,
549,
9,
221,
327,
3611,
5110,
540,
14153,
540,
6013,
272,
21280,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
327,
5661,
66,
23281,
67,
983,
23,
65,
2025,
272,
1526,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
272,
8633,
281,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
2286,
327,
18244,
16424,
272,
1642,
354,
275,
1709,
14,
2183,
480,
7147,
2812,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
2061,
354,
275,
1709,
14,
2183,
480,
6090,
2812,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
410,
7936,
275,
1709,
14,
2183,
480,
933,
7936,
9906,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
14492,
275,
1709,
14,
2183,
480,
17024,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
1174,
275,
1709,
14,
2183,
480,
2223,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
9023,
600,
275,
1709,
14,
2183,
480,
17393,
401,
1390,
63,
1267,
29,
18,
12,
2500,
29,
549,
9,
272,
3482,
275,
1709,
14,
2183,
480,
6564,
279,
1182,
16688,
5495,
401,
1390,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
2286,
327,
8388,
1504,
272,
4572,
1507,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
3537,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
221,
2286,
327,
9516,
1504,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
3305,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
4596,
29,
549,
9,
272,
3305,
63,
600,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
272,
3305,
63,
815,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
14821,
20617,
275,
1709,
14,
26969,
8,
2500,
29,
549,
9,
272,
1827,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
1177,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
5493,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
25170,
63,
78,
11702,
2,
267,
3376,
63,
354,
275,
298,
10517,
24666,
653,
14159,
2,
2286,
347,
4205,
8,
277,
12,
1056,
12,
691,
22006,
63,
1069,
12,
691,
22006,
63,
1310,
304,
267,
408,
9345,
282,
15911,
24666,
7312,
48,
1256,
687,
282,
20730,
1041,
267,
291,
14,
21809,
275,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
297,
4074,
267,
340,
2688,
8,
1069,
12,
298,
751,
531,
436,
1056,
14,
751,
14,
374,
63,
12177,
837,
288,
291,
14,
751,
275,
1056,
14,
751,
398,
327,
3091,
16915,
16630,
12564,
2256,
14,
267,
1827,
63,
576,
275,
1211,
1332,
75,
12,
86,
9,
367,
1022,
12,
373,
315,
691,
22006,
63,
1069,
14,
4611,
342,
340,
1022,
440,
315,
291,
14,
15740,
50,
6196,
1149,
63,
12767,
9,
267,
291,
14,
1131,
275,
16511,
8,
1131,
63,
576,
9,
267,
291,
14,
1310,
275,
16511,
8,
25170,
63,
1310,
9,
398,
327,
644,
305,
2337,
282,
3305,
641,
314,
5232,
31,
18418,
19807,
275,
691,
22006,
63,
1310,
14,
362,
360,
564,
297,
756,
9,
267,
340,
19807,
1137,
298,
8300,
582,
288,
340,
19807,
508,
298,
8300,
3007,
3849,
582,
355,
291,
14,
4173,
63,
815,
275,
691,
22006,
63,
1310,
14,
362,
360,
76,
63,
2809,
1188,
16,
297,
4074,
288,
587,
26,
355,
291,
14,
409,
63,
4173,
8,
25170,
63,
1310,
14,
362,
360,
76,
63,
2809,
1188,
16,
297,
9929,
691,
22006,
63,
1310,
14,
362,
360,
76,
63,
28857,
297,
12381,
339,
347,
663,
63,
4173,
8,
277,
12,
2256,
12,
1233,
29,
403,
304,
267,
408,
5318,
642,
1256,
367,
315,
27174,
425,
1041,
267,
291,
14,
4173,
275,
715,
267,
291,
14,
4173,
63,
815,
847,
2256,
267,
340,
1233,
365,
440,
488,
26,
288,
291,
14,
4173,
63,
600,
275,
1233,
339,
347,
2112,
8,
277,
12,
1056
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1059,
492,
3715,
465,
491,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
1014,
492,
16511,
199,
504,
1639,
14,
3351,
14,
992,
492,
1402,
63,
475,
63,
807,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
421,
199,
533,
15911,
24666,
7312,
48,
8,
992,
14,
1685,
304,
272,
408,
5433,
402,
282,
653,
14159,
18752,
543,
15911,
24666,
1041,
272,
32745,
63,
4807,
275,
2071,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
2,
221,
327,
8937,
13,
996,
13,
1644,
52,
1196,
26,
2417,
26,
2953,
58,
272,
14880,
50,
6196,
1149,
63,
12767,
275,
491,
480,
1474,
602,
6277,
86,
18,
29468,
531,
272,
29948,
63,
12767,
275,
491,
480,
344,
922,
3305,
3305,
63,
600,
3305,
63,
815,
1827,
1177,
2737,
63,
292,
4588,
63,
292,
6099,
272,
473,
22057,
63,
12767,
275,
491,
480,
19582,
3537,
4572,
1507,
531,
272,
8703,
63,
12767,
275,
491,
480,
25603,
2061,
354,
410,
7936,
14492,
1174,
9023,
600,
3482,
531,
339,
327,
7232,
1504,
272,
1083,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
272,
19807,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
14821,
4690,
1205,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
272,
4913,
275,
1709,
14,
4626,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
4690,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
221,
327,
473,
13,
37,
15112,
3888,
1668,
36,
19119,
272,
4690,
4443,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
4596,
29,
549,
9,
221,
327,
3611,
5110,
540,
14153,
540,
6013,
272,
21280,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
327,
5661,
66,
23281,
67,
983,
23,
65,
2025,
272,
1526,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
272,
8633,
281,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
12,
4596,
29,
549,
9,
2286,
327,
18244,
16424,
272,
1642,
354,
275,
1709,
14,
2183,
480,
7147,
2812,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
2061,
354,
275,
1709,
14,
2183,
480,
6090,
2812,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
410,
7936,
275,
1709,
14,
2183,
480,
933,
7936,
9906,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
14492,
275,
1709,
14,
2183,
480,
17024,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
1174,
275,
1709,
14,
2183,
480,
2223,
401,
1390,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
9023,
600,
275,
1709,
14,
2183,
480,
17393,
401,
1390,
63,
1267,
29,
18,
12,
2500,
29,
549,
9,
272,
3482,
275,
1709,
14,
2183,
480,
6564,
279,
1182,
16688,
5495,
401,
1390,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
2286,
327,
8388,
1504,
272,
4572,
1507,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
272,
3537,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
9,
221,
2286,
327,
9516,
1504,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
3305,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
4596,
29,
549,
9,
272,
3305,
63,
600,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
12,
4596,
29,
549,
9,
272,
3305,
63,
815,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
14821,
20617,
275,
1709,
14,
26969,
8,
2500,
29,
549,
9,
272,
1827,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
1177,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
5493,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
298,
25170,
63,
78,
11702,
2,
267,
3376,
63,
354,
275,
298,
10517,
24666,
653,
14159,
2,
2286,
347,
4205,
8,
277,
12,
1056,
12,
691,
22006,
63,
1069,
12,
691,
22006,
63,
1310,
304,
267,
408,
9345,
282,
15911,
24666,
7312,
48,
1256,
687,
282,
20730,
1041,
267,
291,
14,
21809,
275,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
297,
4074,
267,
340,
2688,
8,
1069,
12,
298,
751,
531,
436,
1056,
14,
751,
14,
374,
63,
12177,
837,
288,
291,
14,
751,
275,
1056,
14,
751,
398,
327,
3091,
16915,
16630,
12564,
2256,
14,
267,
1827,
63,
576,
275,
1211,
1332,
75,
12,
86,
9,
367,
1022,
12,
373,
315,
691,
22006,
63,
1069,
14,
4611,
342,
340,
1022,
440,
315,
291,
14,
15740,
50,
6196,
1149,
63,
12767,
9,
267,
291,
14,
1131,
275,
16511,
8,
1131,
63,
576,
9,
267,
291,
14,
1310,
275,
16511,
8,
25170,
63,
1310,
9,
398,
327,
644,
305,
2337,
282,
3305,
641,
314,
5232,
31,
18418,
19807,
275,
691,
22006,
63,
1310,
14,
362,
360,
564,
297,
756,
9,
267,
340,
19807,
1137,
298,
8300,
582,
288,
340,
19807,
508,
298,
8300,
3007,
3849,
582,
355,
291,
14,
4173,
63,
815,
275,
691,
22006,
63,
1310,
14,
362,
360,
76,
63,
2809,
1188,
16,
297,
4074,
288,
587,
26,
355,
291,
14,
409,
63,
4173,
8,
25170,
63,
1310,
14,
362,
360,
76,
63,
2809,
1188,
16,
297,
9929,
691,
22006,
63,
1310,
14,
362,
360,
76,
63,
28857,
297,
12381,
339,
347,
663,
63,
4173,
8,
277,
12,
2256,
12,
1233,
29,
403,
304,
267,
408,
5318,
642,
1256,
367,
315,
27174,
425,
1041,
267,
291,
14,
4173,
275,
715,
267,
291,
14,
4173,
63,
815,
847,
2256,
267,
340,
1233,
365,
440,
488,
26,
288,
291,
14,
4173,
63,
600,
275,
1233,
339,
347,
2112,
8,
277,
12,
1056,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jreinhardt/BOLTS
|
freecad/bearings/bearings.py
|
2
|
10731
|
# **************************************************************************************
# * *
# * BOLTS - Open Library of Technical Specifications *
# * *
# * Copyright (C) 2013 Johannes Reinhardt <jreinhardt@ist-dein-freund.de> *
# * Copyright (C) 2013 Javier Martínez García <jaeco@gmx.com> *
# * *
# * 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 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 Street, Fifth Floor, Boston, MA 02110-1301 USA *
# * *
# **************************************************************************************
import math
# import FreeCAD
import Part
def makeRing(r1, r2):
"""
create a ring that can be used as a drop in replacement
for torus to work around a performance problem
"""
res = Part.makeCylinder(r1 + r2, 2 * r2).cut(Part.makeCylinder(r1 - r2, 3 * r2))
res.translate((0, 0, -r2))
return res
def singlerowradialbearing(params, document):
rout = 0.5 * params["d2"]
rin = 0.5 * params["d1"]
bth = params["B"]
r_fillet = 0.5 * params["r_fillet"]
name = params["name"]
seal = params["type"]
# shapes
shapes = []
RR = 0.015 * rout
rb = (rout - rin) * 0.25
cb = ((rout - rin) / 2.00 + rin)
# outer ring
our = Part.makeCylinder(
rout, bth
).cut(Part.makeCylinder(
cb + rb * 0.7, bth
))
our = our.makeFillet(r_fillet, our.Edges)
# inner ring
inr = Part.makeCylinder(
cb - rb * 0.7, bth
).cut(Part.makeCylinder(
rin, bth
))
inr = inr.makeFillet(r_fillet, inr.Edges)
if seal == "open" or seal.endswith("single"):
# track
t = Part.makeCylinder(
cb + rb, 2 * 0.7 * rb
).cut(Part.makeCylinder(
cb - rb, 2 * 0.7 * rb
))
t.translate((0, 0, (0.5 * bth) - ((2 * 0.7 * rb) / 2)))
our = our.cut(t)
inr = inr.cut(t)
shapes.append(our)
shapes.append(inr)
# Balls
nb = int(math.floor(math.pi * cb * 0.8 / rb))
for i in range(nb):
b = Part.makeSphere(rb)
Alpha = (i * 2 * math.pi) / nb
bv = (cb * math.cos(Alpha), cb * math.sin(Alpha), bth / 2)
b.translate(bv)
shapes.append(b)
if seal.endswith("single"):
# seal one side
sl = Part.makeCylinder(
cb + rb * 0.9, 0.5 * bth - RR
).cut(Part.makeCylinder(
cb - rb * 0.9, 0.5 * bth - RR
))
sl.translate((0, 0, 0.5 * bth + RR))
shapes.append(sl)
elif seal.endswith("double"):
shapes.append(our)
shapes.append(inr)
# seal
sl = Part.makeCylinder(
cb + rb * 0.9, bth - 2 * RR
).cut(Part.makeCylinder(
cb - rb * 0.9, bth - 2 * RR
))
sl.translate((0, 0, RR))
shapes.append(sl)
part = document.addObject("Part::Feature", "BOLTS_part")
comp = Part.Compound(shapes)
part.Shape = comp.removeSplitter()
part.Label = name
def doublerowradialbearing(params, document):
rin = 0.5 * params["d1"]
rout = 0.5 * params["d2"]
bth = params["B"]
name = params["name"]
rb = 0.3 * (rout - rin)
cb = (rout + rin) / 2.0
RR = 0.015 * rout
shapes = []
# outer ring
our1 = Part.makeCylinder(rout, bth)
our2 = Part.makeCylinder(cb + rb * 0.7, bth)
our3 = Part.makeCylinder(rout, 0.1 * bth)
our4 = Part.makeCylinder(rout - 0.12 * (rout - rin), 0.1 * bth)
our = our1.cut(our2)
oursv = (0, 0, 0.45 * bth)
ours = our3.cut(our4)
ours.translate(oursv)
our = our.cut(ours)
oure = our.Edges
our = our.makeFillet(RR, oure)
# inner ring
inr1 = Part.makeCylinder(cb - rb * 0.7, bth)
inr2 = Part.makeCylinder(rin, bth)
inr = inr1.cut(inr2)
inre = inr.Edges
inr = inr.makeFillet(RR, inre)
# track
t1 = makeRing(cb, rb)
t2 = makeRing(cb, rb)
vt1 = (0, 0, rb + bth / 2)
vt2 = (0, 0, (bth / 2) - rb)
t1.translate(vt1)
t2.translate(vt2)
our = our.cut(t1).cut(t2)
inr = inr.cut(t1).cut(t2)
# shapes
shapes.append(our)
shapes.append(inr)
# Balls
nb = (math.pi * cb) * 0.8 / (rb)
nb = math.floor(nb)
nb = int(nb)
for i in range(nb):
b = Part.makeSphere(rb)
Alpha = (i * 2 * math.pi) / nb
bv = (cb * math.cos(Alpha), cb * math.sin(Alpha), rb + bth / 2)
b.translate(bv)
shapes.append(b)
offset = math.asin(rb / cb)
for i in range(nb):
b = Part.makeSphere(rb)
Alpha = (i * 2 * math.pi) / nb
bv = (cb * math.cos(Alpha + offset), cb * math.sin(Alpha + offset), (bth / 2) - rb)
b.translate(bv)
shapes.append(b)
part = document.addObject("Part::Feature", "BOLTS_part")
comp = Part.Compound(shapes)
part.Shape = comp.removeSplitter()
part.Label = name
def axialthrustbearing(params, document):
rin_w = 0.5 * params["d_w"]
rin_g = 0.5 * params["d_g"]
rout_w = 0.5 * params["D_w"]
rout_g = 0.5 * params["D_g"]
r_fillet = params["r_fillet"]
bth = params["T"]
name = params["name"]
fth = 0.3 * bth # Thrust plate widh
shapes = []
# Lower ring
lr1 = Part.makeCylinder(rout_g, fth)
lr2 = Part.makeCylinder(rin_g, fth)
lr = lr1.cut(lr2)
lre = lr.Edges
lr = lr.makeFillet(r_fillet, lre)
# Upper ring
ur1 = Part.makeCylinder(rout_w, fth)
ur2 = Part.makeCylinder(rin_w, fth)
ur = ur1.cut(ur2)
ure = ur.Edges
ur = ur.makeFillet(r_fillet, ure)
# Positioning Vector
Vur = (0, 0, bth - fth)
ur.translate(Vur)
# Balltracks
tbigradius = ((rout_w - rin_g) / 2.00) + rin_g
tsmradius = (bth / 2.00) - (0.75 * fth)
Vtorus = (0, 0, bth / 2.00)
torus = makeRing(tbigradius, tsmradius)
# Positioning vector
torus.translate(Vtorus)
# Booleans
lr = lr.cut(torus)
ur = ur.cut(torus)
shapes.append(ur)
shapes.append(lr)
# Balls
RBall = tsmradius
CBall = tbigradius
# Ball number (constant multiplied by radius and rounded)
NBall = (2 * math.pi * CBall) / (2 * RBall)
NBall = math.floor(NBall)
NBall = NBall * 0.9
NBall = int(NBall)
# Ball creator
for i in range(NBall):
Ball = Part.makeSphere(RBall)
Alpha = (i * 2 * math.pi) / NBall
BV = (CBall * math.cos(Alpha), CBall * math.sin(Alpha), bth / 2.00)
Ball.translate(BV)
shapes.append(Ball)
part = document.addObject("Part::Feature", "BOLTS_part")
comp = Part.Compound(shapes)
part.Shape = comp.removeSplitter()
part.Label = name
def needlebearing(params, document):
rout = 0.5 * params["Ew"]
rin = 0.5 * params["Fw"]
bth = params["Bc"]
name = params["name"]
rnd = (rout - rin) / 2.00
cnd = ((rout - rin) / 2) + rin
# Needle number
nnd = 2 * math.pi * cnd / (1.8 * 2 * rnd)
nnd = int(math.floor(nnd))
shapes = []
# needle cage
ncrout = cnd + 0.175 * (rout - rin)
ncrin = cnd - 0.175 * (rout - rin)
nc1 = Part.makeCylinder(ncrout, bth)
nc2 = Part.makeCylinder(ncrin, bth)
nc = nc1.cut(nc2)
# needle space on the cage-
rsnd = rnd * 1.2
thsnd = bth * 0.8
for i in range(nnd):
snd = Part.makeCylinder(rsnd, thsnd)
Alpha = (i * 2 * math.pi) / nnd
nv = (cnd * math.cos(Alpha), cnd * math.sin(Alpha), 0.1 * bth)
snd.translate(nv)
nc = nc.cut(snd)
# Needle creation
for i in range(nnd):
nd = Part.makeCylinder(rnd, thsnd)
Alpha = (i * 2 * math.pi) / nnd
nv = (cnd * math.cos(Alpha), cnd * math.sin(Alpha), 0.1 * bth)
nd.translate(nv)
shapes.append(nd)
shapes.append(nc)
part = document.addObject("Part::Feature", "BOLTS_part")
comp = Part.Compound(shapes)
part.Shape = comp.removeSplitter()
part.Label = name
def cylindricalrollerbearing(params, document):
rin = 0.5 * params["d1"]
rout = 0.5 * params["d2"]
bth = params["B"]
name = params["name"]
rcy = 0.2 * (rout - rin)
ccy = (((rout - rin) / 2.0) + rin)
RR = 0.01 * rout
ncy = (2 * math.pi * ccy) * 0.8 / (2 * rcy)
ncy = math.floor(ncy)
ncy = int(ncy)
shapes = []
# outer ring
our1 = Part.makeCylinder(rout, bth)
our2 = Part.makeCylinder(ccy + 0.6 * rcy, bth)
our3 = Part.makeCylinder(ccy + rcy, bth * 0.6)
ourv = (0, 0, bth * 0.2)
our3.translate(ourv)
our = our1.cut(our2)
oure = our.Edges
our.makeFillet(RR, oure)
our = our.cut(our3)
# inner ring
inr1 = Part.makeCylinder(ccy - rcy, bth)
inr2 = Part.makeCylinder(rin, bth)
inr = inr1.cut(inr2)
inre = inr.Edges
inr.makeFillet(RR, inre)
# shapes
shapes.append(our)
shapes.append(inr)
# Cylinders
ncy = (2 * math.pi * ccy) * 0.8 / (2 * rcy)
ncy = math.floor(ncy)
ncy = int(ncy)
for i in range(ncy):
c = Part.makeCylinder(rcy, 0.6 * bth)
Alpha = (i * 2 * math.pi) / ncy
cv = (ccy * math.cos(Alpha), ccy * math.sin(Alpha), bth * 0.2)
c.translate(cv)
shapes.append(c)
part = document.addObject("Part::Feature", "BOLTS_part")
comp = Part.Compound(shapes)
part.Shape = comp.removeSplitter()
part.Label = name
|
gpl-3.0
|
[
3,
1011,
12360,
3096,
1116,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
699,
2228,
9730,
446,
3232,
11243,
402,
5773,
28836,
5367,
3477,
83,
13293,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
1898,
334,
35,
9,
6171,
7135,
72,
1189,
397,
799,
262,
8726,
84,
665,
74,
264,
262,
8726,
84,
32,
631,
13,
271,
262,
13,
20153,
725,
14,
271,
30,
3698,
627,
199,
3,
627,
259,
1898,
334,
35,
9,
6171,
1603,
7194,
281,
603,
580,
13676,
685,
90,
598,
9912,
13676,
65,
665,
3387,
69,
331,
32,
71,
9457,
14,
957,
30,
9668,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
7861,
627,
199,
3,
627,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
10473,
627,
199,
3,
627,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
8540,
627,
199,
3,
627,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
1263,
2945,
1015,
14,
17388,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
463,
627,
199,
3,
627,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
8295,
627,
199,
3,
627,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
4483,
627,
199,
3,
627,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
2476,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
4483,
627,
199,
3,
627,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
3777,
627,
199,
3,
627,
259,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
259,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
1011,
12360,
3096,
1116,
421,
199,
646,
3473,
199,
199,
3,
492,
20914,
199,
646,
14320,
421,
199,
318,
1852,
15420,
8,
82,
17,
12,
519,
18,
304,
272,
408,
272,
1218,
282,
12133,
626,
883,
506,
1202,
465,
282,
5978,
315,
8343,
272,
367,
11095,
527,
370,
1736,
6818,
282,
10238,
5160,
272,
408,
272,
522,
275,
14320,
14,
1875,
9156,
24447,
8,
82,
17,
435,
519,
18,
12,
499,
627,
519,
18,
680,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
82,
17,
446,
519,
18,
12,
650,
627,
519,
18,
430,
272,
522,
14,
5275,
1332,
16,
12,
378,
12,
446,
82,
18,
430,
272,
372,
522,
421,
199,
318,
2849,
1143,
12841,
279,
1235,
9332,
8,
1162,
12,
2213,
304,
272,
8659,
275,
378,
14,
21,
627,
1862,
905,
68,
18,
937,
272,
519,
262,
275,
378,
14,
21,
627,
1862,
905,
68,
17,
937,
272,
330,
273,
275,
1862,
905,
34,
937,
272,
519,
63,
1289,
2723,
275,
378,
14,
21,
627,
1862,
905,
82,
63,
1289,
2723,
937,
272,
536,
275,
1862,
905,
354,
937,
272,
542,
279,
275,
1862,
905,
466,
937,
339,
327,
11751,
272,
11751,
275,
942,
272,
27222,
275,
378,
14,
11164,
627,
8659,
272,
11587,
275,
334,
12791,
446,
519,
262,
9,
627,
378,
14,
821,
272,
7434,
275,
3666,
12791,
446,
519,
262,
9,
1182,
499,
14,
383,
435,
519,
262,
9,
272,
327,
6890,
12133,
272,
4154,
275,
14320,
14,
1875,
9156,
24447,
8,
267,
8659,
12,
330,
273,
272,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
267,
7434,
435,
11587,
627,
378,
14,
23,
12,
330,
273,
272,
5082,
272,
4154,
275,
4154,
14,
1875,
13079,
2723,
8,
82,
63,
1289,
2723,
12,
4154,
14,
24121,
9,
272,
327,
6506,
12133,
272,
315,
82,
275,
14320,
14,
1875,
9156,
24447,
8,
267,
7434,
446,
11587,
627,
378,
14,
23,
12,
330,
273,
272,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
267,
519,
262,
12,
330,
273,
272,
5082,
272,
315,
82,
275,
315,
82,
14,
1875,
13079,
2723,
8,
82,
63,
1289,
2723,
12,
315,
82,
14,
24121,
9,
339,
340,
542,
279,
508,
298,
1490,
2,
503,
542,
279,
14,
4130,
480,
4780,
2349,
267,
327,
4426,
267,
307,
275,
14320,
14,
1875,
9156,
24447,
8,
288,
7434,
435,
11587,
12,
499,
627,
378,
14,
23,
627,
11587,
267,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
288,
7434,
446,
11587,
12,
499,
627,
378,
14,
23,
627,
11587,
267,
5082,
267,
307,
14,
5275,
1332,
16,
12,
378,
12,
334,
16,
14,
21,
627,
330,
273,
9,
446,
3666,
18,
627,
378,
14,
23,
627,
11587,
9,
1182,
499,
1724,
267,
4154,
275,
4154,
14,
5919,
8,
84,
9,
267,
315,
82,
275,
315,
82,
14,
5919,
8,
84,
9,
267,
11751,
14,
740,
8,
567,
9,
267,
11751,
14,
740,
8,
262,
82,
9,
398,
327,
699,
30483,
267,
8526,
275,
1109,
8,
3442,
14,
11289,
8,
3442,
14,
1038,
627,
7434,
627,
378,
14,
24,
1182,
11587,
430,
267,
367,
284,
315,
1425,
8,
4994,
304,
288,
330,
275,
14320,
14,
1875,
22385,
8,
4848,
9,
288,
32657,
275,
334,
73,
627,
499,
627,
3473,
14,
1038,
9,
1182,
8526,
288,
25794,
275,
334,
2894,
627,
3473,
14,
5197,
8,
16192,
395,
7434,
627,
3473,
14,
5911,
8,
16192,
395,
330,
273,
1182,
499,
9,
288,
330,
14,
5275,
8,
23064,
9,
288,
11751,
14,
740,
8,
66,
9,
398,
340,
542,
279,
14,
4130,
480,
4780,
2349,
288,
327,
542,
279,
1373,
5366,
288,
5340,
275,
14320,
14,
1875,
9156,
24447,
8,
355,
7434,
435,
11587,
627,
378,
14,
25,
12,
378,
14,
21,
627,
330,
273,
446,
27222,
288,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
355,
7434,
446,
11587,
627,
378,
14,
25,
12,
378,
14,
21,
627,
330,
273,
446,
27222,
288,
5082,
288,
5340,
14,
5275,
1332,
16,
12,
378,
12,
378,
14,
21,
627,
330,
273,
435,
27222,
430,
288,
11751,
14,
740,
8,
2482,
9,
339,
916,
542,
279,
14,
4130,
480,
3157,
2349,
267,
11751,
14,
740,
8,
567,
9,
267
] |
[
1011,
12360,
3096,
1116,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
699,
2228,
9730,
446,
3232,
11243,
402,
5773,
28836,
5367,
3477,
83,
13293,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
1898,
334,
35,
9,
6171,
7135,
72,
1189,
397,
799,
262,
8726,
84,
665,
74,
264,
262,
8726,
84,
32,
631,
13,
271,
262,
13,
20153,
725,
14,
271,
30,
3698,
627,
199,
3,
627,
259,
1898,
334,
35,
9,
6171,
1603,
7194,
281,
603,
580,
13676,
685,
90,
598,
9912,
13676,
65,
665,
3387,
69,
331,
32,
71,
9457,
14,
957,
30,
9668,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
7861,
627,
199,
3,
627,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
10473,
627,
199,
3,
627,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
8540,
627,
199,
3,
627,
259,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
1263,
2945,
1015,
14,
17388,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
463,
627,
199,
3,
627,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
8295,
627,
199,
3,
627,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
4483,
627,
199,
3,
627,
259,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
2476,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
627,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
4483,
627,
199,
3,
627,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
3777,
627,
199,
3,
627,
259,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
259,
627,
199,
3,
627,
6208,
8540,
627,
199,
3,
1011,
12360,
3096,
1116,
421,
199,
646,
3473,
199,
199,
3,
492,
20914,
199,
646,
14320,
421,
199,
318,
1852,
15420,
8,
82,
17,
12,
519,
18,
304,
272,
408,
272,
1218,
282,
12133,
626,
883,
506,
1202,
465,
282,
5978,
315,
8343,
272,
367,
11095,
527,
370,
1736,
6818,
282,
10238,
5160,
272,
408,
272,
522,
275,
14320,
14,
1875,
9156,
24447,
8,
82,
17,
435,
519,
18,
12,
499,
627,
519,
18,
680,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
82,
17,
446,
519,
18,
12,
650,
627,
519,
18,
430,
272,
522,
14,
5275,
1332,
16,
12,
378,
12,
446,
82,
18,
430,
272,
372,
522,
421,
199,
318,
2849,
1143,
12841,
279,
1235,
9332,
8,
1162,
12,
2213,
304,
272,
8659,
275,
378,
14,
21,
627,
1862,
905,
68,
18,
937,
272,
519,
262,
275,
378,
14,
21,
627,
1862,
905,
68,
17,
937,
272,
330,
273,
275,
1862,
905,
34,
937,
272,
519,
63,
1289,
2723,
275,
378,
14,
21,
627,
1862,
905,
82,
63,
1289,
2723,
937,
272,
536,
275,
1862,
905,
354,
937,
272,
542,
279,
275,
1862,
905,
466,
937,
339,
327,
11751,
272,
11751,
275,
942,
272,
27222,
275,
378,
14,
11164,
627,
8659,
272,
11587,
275,
334,
12791,
446,
519,
262,
9,
627,
378,
14,
821,
272,
7434,
275,
3666,
12791,
446,
519,
262,
9,
1182,
499,
14,
383,
435,
519,
262,
9,
272,
327,
6890,
12133,
272,
4154,
275,
14320,
14,
1875,
9156,
24447,
8,
267,
8659,
12,
330,
273,
272,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
267,
7434,
435,
11587,
627,
378,
14,
23,
12,
330,
273,
272,
5082,
272,
4154,
275,
4154,
14,
1875,
13079,
2723,
8,
82,
63,
1289,
2723,
12,
4154,
14,
24121,
9,
272,
327,
6506,
12133,
272,
315,
82,
275,
14320,
14,
1875,
9156,
24447,
8,
267,
7434,
446,
11587,
627,
378,
14,
23,
12,
330,
273,
272,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
267,
519,
262,
12,
330,
273,
272,
5082,
272,
315,
82,
275,
315,
82,
14,
1875,
13079,
2723,
8,
82,
63,
1289,
2723,
12,
315,
82,
14,
24121,
9,
339,
340,
542,
279,
508,
298,
1490,
2,
503,
542,
279,
14,
4130,
480,
4780,
2349,
267,
327,
4426,
267,
307,
275,
14320,
14,
1875,
9156,
24447,
8,
288,
7434,
435,
11587,
12,
499,
627,
378,
14,
23,
627,
11587,
267,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
288,
7434,
446,
11587,
12,
499,
627,
378,
14,
23,
627,
11587,
267,
5082,
267,
307,
14,
5275,
1332,
16,
12,
378,
12,
334,
16,
14,
21,
627,
330,
273,
9,
446,
3666,
18,
627,
378,
14,
23,
627,
11587,
9,
1182,
499,
1724,
267,
4154,
275,
4154,
14,
5919,
8,
84,
9,
267,
315,
82,
275,
315,
82,
14,
5919,
8,
84,
9,
267,
11751,
14,
740,
8,
567,
9,
267,
11751,
14,
740,
8,
262,
82,
9,
398,
327,
699,
30483,
267,
8526,
275,
1109,
8,
3442,
14,
11289,
8,
3442,
14,
1038,
627,
7434,
627,
378,
14,
24,
1182,
11587,
430,
267,
367,
284,
315,
1425,
8,
4994,
304,
288,
330,
275,
14320,
14,
1875,
22385,
8,
4848,
9,
288,
32657,
275,
334,
73,
627,
499,
627,
3473,
14,
1038,
9,
1182,
8526,
288,
25794,
275,
334,
2894,
627,
3473,
14,
5197,
8,
16192,
395,
7434,
627,
3473,
14,
5911,
8,
16192,
395,
330,
273,
1182,
499,
9,
288,
330,
14,
5275,
8,
23064,
9,
288,
11751,
14,
740,
8,
66,
9,
398,
340,
542,
279,
14,
4130,
480,
4780,
2349,
288,
327,
542,
279,
1373,
5366,
288,
5340,
275,
14320,
14,
1875,
9156,
24447,
8,
355,
7434,
435,
11587,
627,
378,
14,
25,
12,
378,
14,
21,
627,
330,
273,
446,
27222,
288,
7092,
5919,
8,
8416,
14,
1875,
9156,
24447,
8,
355,
7434,
446,
11587,
627,
378,
14,
25,
12,
378,
14,
21,
627,
330,
273,
446,
27222,
288,
5082,
288,
5340,
14,
5275,
1332,
16,
12,
378,
12,
378,
14,
21,
627,
330,
273,
435,
27222,
430,
288,
11751,
14,
740,
8,
2482,
9,
339,
916,
542,
279,
14,
4130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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ryfeus/lambda-packs
|
pytorch/source/numpy/core/memmap.py
|
3
|
11612
|
from __future__ import division, absolute_import, print_function
import numpy as np
from .numeric import uint8, ndarray, dtype
from numpy.compat import (
long, basestring, os_fspath, contextlib_nullcontext, is_pathlib_path
)
from numpy.core.overrides import set_module
__all__ = ['memmap']
dtypedescr = dtype
valid_filemodes = ["r", "c", "r+", "w+"]
writeable_filemodes = ["r+", "w+"]
mode_equivalents = {
"readonly":"r",
"copyonwrite":"c",
"readwrite":"r+",
"write":"w+"
}
@set_module('numpy')
class memmap(ndarray):
"""Create a memory-map to an array stored in a *binary* file on disk.
Memory-mapped files are used for accessing small segments of large files
on disk, without reading the entire file into memory. NumPy's
memmap's are array-like objects. This differs from Python's ``mmap``
module, which uses file-like objects.
This subclass of ndarray has some unpleasant interactions with
some operations, because it doesn't quite fit properly as a subclass.
An alternative to using this subclass is to create the ``mmap``
object yourself, then create an ndarray with ndarray.__new__ directly,
passing the object created in its 'buffer=' parameter.
This class may at some point be turned into a factory function
which returns a view into an mmap buffer.
Delete the memmap instance to close the memmap file.
Parameters
----------
filename : str, file-like object, or pathlib.Path instance
The file name or file object to be used as the array data buffer.
dtype : data-type, optional
The data-type used to interpret the file contents.
Default is `uint8`.
mode : {'r+', 'r', 'w+', 'c'}, optional
The file is opened in this mode:
+------+-------------------------------------------------------------+
| 'r' | Open existing file for reading only. |
+------+-------------------------------------------------------------+
| 'r+' | Open existing file for reading and writing. |
+------+-------------------------------------------------------------+
| 'w+' | Create or overwrite existing file for reading and writing. |
+------+-------------------------------------------------------------+
| 'c' | Copy-on-write: assignments affect data in memory, but |
| | changes are not saved to disk. The file on disk is |
| | read-only. |
+------+-------------------------------------------------------------+
Default is 'r+'.
offset : int, optional
In the file, array data starts at this offset. Since `offset` is
measured in bytes, it should normally be a multiple of the byte-size
of `dtype`. When ``mode != 'r'``, even positive offsets beyond end of
file are valid; The file will be extended to accommodate the
additional data. By default, ``memmap`` will start at the beginning of
the file, even if ``filename`` is a file pointer ``fp`` and
``fp.tell() != 0``.
shape : tuple, optional
The desired shape of the array. If ``mode == 'r'`` and the number
of remaining bytes after `offset` is not a multiple of the byte-size
of `dtype`, you must specify `shape`. By default, the returned array
will be 1-D with the number of elements determined by file size
and data-type.
order : {'C', 'F'}, optional
Specify the order of the ndarray memory layout:
:term:`row-major`, C-style or :term:`column-major`,
Fortran-style. This only has an effect if the shape is
greater than 1-D. The default order is 'C'.
Attributes
----------
filename : str or pathlib.Path instance
Path to the mapped file.
offset : int
Offset position in the file.
mode : str
File mode.
Methods
-------
flush
Flush any changes in memory to file on disk.
When you delete a memmap object, flush is called first to write
changes to disk before removing the object.
See also
--------
lib.format.open_memmap : Create or load a memory-mapped ``.npy`` file.
Notes
-----
The memmap object can be used anywhere an ndarray is accepted.
Given a memmap ``fp``, ``isinstance(fp, numpy.ndarray)`` returns
``True``.
Memory-mapped files cannot be larger than 2GB on 32-bit systems.
When a memmap causes a file to be created or extended beyond its
current size in the filesystem, the contents of the new part are
unspecified. On systems with POSIX filesystem semantics, the extended
part will be filled with zero bytes.
Examples
--------
>>> data = np.arange(12, dtype='float32')
>>> data.resize((3,4))
This example uses a temporary file so that doctest doesn't write
files to your directory. You would use a 'normal' filename.
>>> from tempfile import mkdtemp
>>> import os.path as path
>>> filename = path.join(mkdtemp(), 'newfile.dat')
Create a memmap with dtype and shape that matches our data:
>>> fp = np.memmap(filename, dtype='float32', mode='w+', shape=(3,4))
>>> fp
memmap([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]], dtype=float32)
Write data to memmap array:
>>> fp[:] = data[:]
>>> fp
memmap([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]], dtype=float32)
>>> fp.filename == path.abspath(filename)
True
Deletion flushes memory changes to disk before removing the object:
>>> del fp
Load the memmap and verify data was stored:
>>> newfp = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> newfp
memmap([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]], dtype=float32)
Read-only memmap:
>>> fpr = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> fpr.flags.writeable
False
Copy-on-write memmap:
>>> fpc = np.memmap(filename, dtype='float32', mode='c', shape=(3,4))
>>> fpc.flags.writeable
True
It's possible to assign to copy-on-write array, but values are only
written into the memory copy of the array, and not written to disk:
>>> fpc
memmap([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]], dtype=float32)
>>> fpc[0,:] = 0
>>> fpc
memmap([[ 0., 0., 0., 0.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]], dtype=float32)
File on disk is unchanged:
>>> fpr
memmap([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]], dtype=float32)
Offset into a memmap:
>>> fpo = np.memmap(filename, dtype='float32', mode='r', offset=16)
>>> fpo
memmap([ 4., 5., 6., 7., 8., 9., 10., 11.], dtype=float32)
"""
__array_priority__ = -100.0
def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
shape=None, order='C'):
# Import here to minimize 'import numpy' overhead
import mmap
import os.path
try:
mode = mode_equivalents[mode]
except KeyError:
if mode not in valid_filemodes:
raise ValueError("mode must be one of %s" %
(valid_filemodes + list(mode_equivalents.keys())))
if mode == 'w+' and shape is None:
raise ValueError("shape must be given")
if hasattr(filename, 'read'):
f_ctx = contextlib_nullcontext(filename)
else:
f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b')
with f_ctx as fid:
fid.seek(0, 2)
flen = fid.tell()
descr = dtypedescr(dtype)
_dbytes = descr.itemsize
if shape is None:
bytes = flen - offset
if bytes % _dbytes:
raise ValueError("Size of available data is not a "
"multiple of the data-type size.")
size = bytes // _dbytes
shape = (size,)
else:
if not isinstance(shape, tuple):
shape = (shape,)
size = np.intp(1) # avoid default choice of np.int_, which might overflow
for k in shape:
size *= k
bytes = long(offset + size*_dbytes)
if mode == 'w+' or (mode == 'r+' and flen < bytes):
fid.seek(bytes - 1, 0)
fid.write(b'\0')
fid.flush()
if mode == 'c':
acc = mmap.ACCESS_COPY
elif mode == 'r':
acc = mmap.ACCESS_READ
else:
acc = mmap.ACCESS_WRITE
start = offset - offset % mmap.ALLOCATIONGRANULARITY
bytes -= start
array_offset = offset - start
mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
offset=array_offset, order=order)
self._mmap = mm
self.offset = offset
self.mode = mode
if is_pathlib_path(filename):
# special case - if we were constructed with a pathlib.path,
# then filename is a path object, not a string
self.filename = filename.resolve()
elif hasattr(fid, "name") and isinstance(fid.name, basestring):
# py3 returns int for TemporaryFile().name
self.filename = os.path.abspath(fid.name)
# same as memmap copies (e.g. memmap + 1)
else:
self.filename = None
return self
def __array_finalize__(self, obj):
if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
self._mmap = obj._mmap
self.filename = obj.filename
self.offset = obj.offset
self.mode = obj.mode
else:
self._mmap = None
self.filename = None
self.offset = None
self.mode = None
def flush(self):
"""
Write any changes in the array to the file on disk.
For further information, see `memmap`.
Parameters
----------
None
See Also
--------
memmap
"""
if self.base is not None and hasattr(self.base, 'flush'):
self.base.flush()
def __array_wrap__(self, arr, context=None):
arr = super(memmap, self).__array_wrap__(arr, context)
# Return a memmap if a memmap was given as the output of the
# ufunc. Leave the arr class unchanged if self is not a memmap
# to keep original memmap subclasses behavior
if self is arr or type(self) is not memmap:
return arr
# Return scalar instead of 0d memmap, e.g. for np.sum with
# axis=None
if arr.shape == ():
return arr[()]
# Return ndarray otherwise
return arr.view(np.ndarray)
def __getitem__(self, index):
res = super(memmap, self).__getitem__(index)
if type(res) is memmap and res._mmap is None:
return res.view(type=ndarray)
return res
|
mit
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
1275,
6677,
492,
3152,
24,
12,
6800,
12,
2152,
199,
504,
2680,
14,
5819,
492,
334,
272,
1846,
12,
7116,
12,
747,
63,
31947,
12,
15502,
63,
2307,
1100,
12,
365,
63,
515,
773,
63,
515,
199,
9,
199,
504,
2680,
14,
1018,
14,
12867,
492,
663,
63,
578,
199,
199,
363,
452,
363,
275,
788,
5286,
1130,
418,
199,
199,
2271,
12113,
275,
2152,
199,
1078,
63,
493,
10433,
275,
2097,
82,
401,
298,
67,
401,
298,
82,
22758,
298,
87,
11,
937,
199,
952,
461,
63,
493,
10433,
275,
2097,
82,
22758,
298,
87,
11,
937,
199,
199,
632,
63,
24179,
83,
275,
469,
272,
298,
6753,
5122,
82,
401,
272,
298,
1574,
265,
952,
5122,
67,
401,
272,
298,
24044,
5122,
82,
22758,
272,
298,
952,
5122,
87,
5207,
272,
789,
421,
199,
32,
409,
63,
578,
360,
4714,
358,
199,
533,
7573,
1130,
8,
8237,
304,
272,
408,
2499,
282,
4402,
13,
1130,
370,
376,
1625,
5489,
315,
282,
627,
3008,
10,
570,
641,
4543,
14,
339,
15825,
13,
11663,
1584,
787,
1202,
367,
18549,
7425,
11998,
402,
7031,
1584,
272,
641,
4543,
12,
1928,
7664,
314,
8039,
570,
1901,
4402,
14,
221,
20602,
1159,
272,
7573,
1130,
1159,
787,
1625,
13,
2930,
2251,
14,
221,
961,
22754,
687,
2018,
1159,
1124,
20671,
1040,
272,
859,
12,
1314,
4440,
570,
13,
2930,
2251,
14,
339,
961,
5516,
402,
6800,
965,
2005,
625,
11045,
305,
867,
315,
22990,
543,
272,
2005,
5331,
12,
2952,
652,
3181,
1133,
18794,
5542,
7684,
465,
282,
5516,
14,
272,
1626,
13943,
370,
1808,
642,
5516,
365,
370,
1218,
314,
1124,
20671,
1040,
272,
909,
28225,
12,
2066,
1218,
376,
6800,
543,
6800,
855,
1222,
363,
5370,
12,
272,
9476,
314,
909,
2737,
315,
2399,
283,
2738,
534,
2725,
14,
339,
961,
1021,
1443,
737,
2005,
2376,
506,
19136,
1901,
282,
6434,
805,
272,
1314,
2529,
282,
2455,
1901,
376,
21991,
3335,
14,
339,
8496,
314,
7573,
1130,
1256,
370,
4002,
314,
7573,
1130,
570,
14,
2378,
3897,
272,
4143,
272,
1788,
520,
620,
12,
570,
13,
2930,
909,
12,
503,
32212,
14,
2042,
1256,
267,
710,
570,
536,
503,
570,
909,
370,
506,
1202,
465,
314,
1625,
666,
3335,
14,
272,
2152,
520,
666,
13,
466,
12,
2716,
267,
710,
666,
13,
466,
1202,
370,
15579,
314,
570,
4072,
14,
267,
3758,
365,
658,
1635,
24,
2313,
272,
818,
520,
791,
82,
7386,
283,
82,
297,
283,
87,
7386,
283,
67,
2267,
2716,
267,
710,
570,
365,
12123,
315,
642,
818,
26,
398,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
82,
7,
221,
1204,
3232,
3411,
570,
367,
7664,
1454,
14,
12788,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
82,
4786,
1204,
3232,
3411,
570,
367,
7664,
436,
3575,
14,
463,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
87,
4786,
1204,
2790,
503,
8970,
3411,
570,
367,
7664,
436,
3575,
14,
221,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
67,
7,
221,
1204,
11247,
13,
265,
13,
952,
26,
18121,
12787,
666,
315,
4402,
12,
1325,
755,
1204,
267,
1204,
420,
1204,
4493,
787,
440,
6290,
370,
4543,
14,
221,
710,
570,
641,
4543,
365,
260,
1204,
267,
1204,
420,
1204,
1586,
13,
2118,
14,
2476,
8295,
1204,
267,
435,
28712,
6489,
4559,
6793,
398,
3758,
365,
283,
82,
18098,
272,
3268,
520,
1109,
12,
2716,
267,
1010,
314,
570,
12,
1625,
666,
9174,
737,
642,
3268,
14,
9336,
658,
2743,
64,
365,
267,
27396,
315,
2783,
12,
652,
1077,
12252,
506,
282,
3663,
402,
314,
3696,
13,
890,
267,
402,
658,
2271,
2313,
3979,
1124,
632,
1137,
283,
82,
31638,
2755,
7317,
15340,
20561,
1284,
402,
267,
570,
787,
1686,
27,
710,
570,
911,
506,
9243,
370,
1066,
1404,
364,
323,
314,
267,
4722,
666,
14,
4885,
849,
12,
1124,
5286,
1130,
1040,
911,
1343,
737,
314,
9608,
402,
267,
314,
570,
12,
2755,
340,
1124,
1501,
1040,
365,
282,
570,
7849,
1124,
3997,
1040,
436,
267,
1124,
3997,
14,
9974,
342,
1137,
378,
4345,
272,
2215,
520,
2008,
12,
2716,
267,
710,
6387,
2215,
402,
314,
1625,
14,
982,
1124,
632,
508,
283,
82,
14700,
436,
314,
1329,
267,
402,
7971,
2783,
2410,
658,
2743,
64,
365,
440,
282,
3663,
402,
314,
3696,
13,
890,
267,
402,
658,
2271,
3559,
1265,
1471,
4165,
658,
1392,
2313,
4885,
849,
12,
314,
2138,
1625,
267,
911,
506,
413,
13,
36,
543,
314,
1329,
402,
4008,
12037,
701,
570,
1568,
267,
436,
666,
13,
466,
14,
272,
1865,
520,
791,
35,
297,
283,
38,
2267,
2716,
267,
13327,
314,
1865,
402,
314,
6800,
4402,
7054,
26,
267,
520,
5125,
1705,
1143,
13,
8452,
3559,
445,
13,
2487,
503,
520,
5125,
1705,
2301,
13,
8452,
3559,
267,
19998,
13,
2487,
14,
221,
961,
1454,
965,
376,
7763,
340,
314,
2215,
365,
267,
8932,
2419,
413,
13,
36,
14,
221,
710,
849,
1865,
365,
283,
35,
1370,
339,
9382,
272,
4143,
272,
1788,
520,
620,
503,
32212,
14,
2042,
1256,
267,
6912,
370,
314,
9994,
570,
14,
272,
3268,
520,
1109,
267,
29432,
3421,
315,
314,
570,
14,
272,
818,
520,
620,
267,
3814,
818,
14,
339,
17653,
272,
5514,
272,
8976,
267,
11040,
2084,
1263,
4493,
315,
4402,
370,
570,
641,
4543,
14,
267,
3979,
1265,
3145,
282,
7573,
1130,
909,
12,
8976,
365,
2797,
1642,
370,
2218,
267,
4493,
370,
4543,
2544,
12881,
314,
909,
14,
2378,
1666,
2597,
272,
3001,
272,
1973,
14,
908,
14,
1490,
63,
5286,
1130,
520,
2790,
503,
2248,
282,
4402,
13,
11663,
21502,
20245,
1040,
570,
14,
339,
8144,
272,
9063,
272,
710,
7573,
1130,
909,
883,
506,
1202,
26523,
376,
6800,
365,
10226,
14,
272,
9138,
282,
7573,
1130,
1124,
3997,
4542,
1124,
6074,
8,
3997,
12,
2680,
14,
8237,
9719,
2529,
272,
1124,
549,
4345,
2286,
15825,
13,
11663,
1584,
3913,
506,
12142,
2419,
499,
6487,
641,
4337,
13,
2075,
10460,
14,
339,
3979,
282,
7573,
1130,
14486,
282,
570,
370,
506,
2737,
503,
9243,
20561
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
1275,
6677,
492,
3152,
24,
12,
6800,
12,
2152,
199,
504,
2680,
14,
5819,
492,
334,
272,
1846,
12,
7116,
12,
747,
63,
31947,
12,
15502,
63,
2307,
1100,
12,
365,
63,
515,
773,
63,
515,
199,
9,
199,
504,
2680,
14,
1018,
14,
12867,
492,
663,
63,
578,
199,
199,
363,
452,
363,
275,
788,
5286,
1130,
418,
199,
199,
2271,
12113,
275,
2152,
199,
1078,
63,
493,
10433,
275,
2097,
82,
401,
298,
67,
401,
298,
82,
22758,
298,
87,
11,
937,
199,
952,
461,
63,
493,
10433,
275,
2097,
82,
22758,
298,
87,
11,
937,
199,
199,
632,
63,
24179,
83,
275,
469,
272,
298,
6753,
5122,
82,
401,
272,
298,
1574,
265,
952,
5122,
67,
401,
272,
298,
24044,
5122,
82,
22758,
272,
298,
952,
5122,
87,
5207,
272,
789,
421,
199,
32,
409,
63,
578,
360,
4714,
358,
199,
533,
7573,
1130,
8,
8237,
304,
272,
408,
2499,
282,
4402,
13,
1130,
370,
376,
1625,
5489,
315,
282,
627,
3008,
10,
570,
641,
4543,
14,
339,
15825,
13,
11663,
1584,
787,
1202,
367,
18549,
7425,
11998,
402,
7031,
1584,
272,
641,
4543,
12,
1928,
7664,
314,
8039,
570,
1901,
4402,
14,
221,
20602,
1159,
272,
7573,
1130,
1159,
787,
1625,
13,
2930,
2251,
14,
221,
961,
22754,
687,
2018,
1159,
1124,
20671,
1040,
272,
859,
12,
1314,
4440,
570,
13,
2930,
2251,
14,
339,
961,
5516,
402,
6800,
965,
2005,
625,
11045,
305,
867,
315,
22990,
543,
272,
2005,
5331,
12,
2952,
652,
3181,
1133,
18794,
5542,
7684,
465,
282,
5516,
14,
272,
1626,
13943,
370,
1808,
642,
5516,
365,
370,
1218,
314,
1124,
20671,
1040,
272,
909,
28225,
12,
2066,
1218,
376,
6800,
543,
6800,
855,
1222,
363,
5370,
12,
272,
9476,
314,
909,
2737,
315,
2399,
283,
2738,
534,
2725,
14,
339,
961,
1021,
1443,
737,
2005,
2376,
506,
19136,
1901,
282,
6434,
805,
272,
1314,
2529,
282,
2455,
1901,
376,
21991,
3335,
14,
339,
8496,
314,
7573,
1130,
1256,
370,
4002,
314,
7573,
1130,
570,
14,
2378,
3897,
272,
4143,
272,
1788,
520,
620,
12,
570,
13,
2930,
909,
12,
503,
32212,
14,
2042,
1256,
267,
710,
570,
536,
503,
570,
909,
370,
506,
1202,
465,
314,
1625,
666,
3335,
14,
272,
2152,
520,
666,
13,
466,
12,
2716,
267,
710,
666,
13,
466,
1202,
370,
15579,
314,
570,
4072,
14,
267,
3758,
365,
658,
1635,
24,
2313,
272,
818,
520,
791,
82,
7386,
283,
82,
297,
283,
87,
7386,
283,
67,
2267,
2716,
267,
710,
570,
365,
12123,
315,
642,
818,
26,
398,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
82,
7,
221,
1204,
3232,
3411,
570,
367,
7664,
1454,
14,
12788,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
82,
4786,
1204,
3232,
3411,
570,
367,
7664,
436,
3575,
14,
463,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
87,
4786,
1204,
2790,
503,
8970,
3411,
570,
367,
7664,
436,
3575,
14,
221,
1204,
267,
435,
28712,
6489,
4559,
6793,
267,
1204,
283,
67,
7,
221,
1204,
11247,
13,
265,
13,
952,
26,
18121,
12787,
666,
315,
4402,
12,
1325,
755,
1204,
267,
1204,
420,
1204,
4493,
787,
440,
6290,
370,
4543,
14,
221,
710,
570,
641,
4543,
365,
260,
1204,
267,
1204,
420,
1204,
1586,
13,
2118,
14,
2476,
8295,
1204,
267,
435,
28712,
6489,
4559,
6793,
398,
3758,
365,
283,
82,
18098,
272,
3268,
520,
1109,
12,
2716,
267,
1010,
314,
570,
12,
1625,
666,
9174,
737,
642,
3268,
14,
9336,
658,
2743,
64,
365,
267,
27396,
315,
2783,
12,
652,
1077,
12252,
506,
282,
3663,
402,
314,
3696,
13,
890,
267,
402,
658,
2271,
2313,
3979,
1124,
632,
1137,
283,
82,
31638,
2755,
7317,
15340,
20561,
1284,
402,
267,
570,
787,
1686,
27,
710,
570,
911,
506,
9243,
370,
1066,
1404,
364,
323,
314,
267,
4722,
666,
14,
4885,
849,
12,
1124,
5286,
1130,
1040,
911,
1343,
737,
314,
9608,
402,
267,
314,
570,
12,
2755,
340,
1124,
1501,
1040,
365,
282,
570,
7849,
1124,
3997,
1040,
436,
267,
1124,
3997,
14,
9974,
342,
1137,
378,
4345,
272,
2215,
520,
2008,
12,
2716,
267,
710,
6387,
2215,
402,
314,
1625,
14,
982,
1124,
632,
508,
283,
82,
14700,
436,
314,
1329,
267,
402,
7971,
2783,
2410,
658,
2743,
64,
365,
440,
282,
3663,
402,
314,
3696,
13,
890,
267,
402,
658,
2271,
3559,
1265,
1471,
4165,
658,
1392,
2313,
4885,
849,
12,
314,
2138,
1625,
267,
911,
506,
413,
13,
36,
543,
314,
1329,
402,
4008,
12037,
701,
570,
1568,
267,
436,
666,
13,
466,
14,
272,
1865,
520,
791,
35,
297,
283,
38,
2267,
2716,
267,
13327,
314,
1865,
402,
314,
6800,
4402,
7054,
26,
267,
520,
5125,
1705,
1143,
13,
8452,
3559,
445,
13,
2487,
503,
520,
5125,
1705,
2301,
13,
8452,
3559,
267,
19998,
13,
2487,
14,
221,
961,
1454,
965,
376,
7763,
340,
314,
2215,
365,
267,
8932,
2419,
413,
13,
36,
14,
221,
710,
849,
1865,
365,
283,
35,
1370,
339,
9382,
272,
4143,
272,
1788,
520,
620,
503,
32212,
14,
2042,
1256,
267,
6912,
370,
314,
9994,
570,
14,
272,
3268,
520,
1109,
267,
29432,
3421,
315,
314,
570,
14,
272,
818,
520,
620,
267,
3814,
818,
14,
339,
17653,
272,
5514,
272,
8976,
267,
11040,
2084,
1263,
4493,
315,
4402,
370,
570,
641,
4543,
14,
267,
3979,
1265,
3145,
282,
7573,
1130,
909,
12,
8976,
365,
2797,
1642,
370,
2218,
267,
4493,
370,
4543,
2544,
12881,
314,
909,
14,
2378,
1666,
2597,
272,
3001,
272,
1973,
14,
908,
14,
1490,
63,
5286,
1130,
520,
2790,
503,
2248,
282,
4402,
13,
11663,
21502,
20245,
1040,
570,
14,
339,
8144,
272,
9063,
272,
710,
7573,
1130,
909,
883,
506,
1202,
26523,
376,
6800,
365,
10226,
14,
272,
9138,
282,
7573,
1130,
1124,
3997,
4542,
1124,
6074,
8,
3997,
12,
2680,
14,
8237,
9719,
2529,
272,
1124,
549,
4345,
2286,
15825,
13,
11663,
1584,
3913,
506,
12142,
2419,
499,
6487,
641,
4337,
13,
2075,
10460,
14,
339,
3979,
282,
7573,
1130,
14486,
282,
570,
370,
506,
2737,
503,
9243,
20561,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kmarius/qutebrowser
|
tests/unit/mainwindow/statusbar/test_backforward.py
|
2
|
3211
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2017-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser 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.
#
# qutebrowser 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 qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Test Backforward widget."""
import pytest
from qutebrowser.mainwindow.statusbar import backforward
@pytest.fixture
def backforward_widget(qtbot):
widget = backforward.Backforward()
qtbot.add_widget(widget)
return widget
@pytest.mark.parametrize('can_go_back, can_go_forward, expected_text', [
(False, False, ''),
(True, False, '[<]'),
(False, True, '[>]'),
(True, True, '[<>]'),
])
def test_backforward_widget(backforward_widget, tabbed_browser_stubs,
fake_web_tab, can_go_back, can_go_forward,
expected_text):
"""Ensure the Backforward widget shows the correct text."""
tab = fake_web_tab(can_go_back=can_go_back, can_go_forward=can_go_forward)
tabbed_browser = tabbed_browser_stubs[0]
tabbed_browser.current_index = 1
tabbed_browser.tabs = [tab]
backforward_widget.enabled = True
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
assert backforward_widget.text() == expected_text
assert backforward_widget.isVisible() == bool(expected_text)
# Check that the widget stays hidden if not in the statusbar
backforward_widget.enabled = False
backforward_widget.hide()
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
assert backforward_widget.isHidden()
# Check that the widget gets reset if empty.
if can_go_back and can_go_forward:
tab = fake_web_tab(can_go_back=False, can_go_forward=False)
tabbed_browser.tabs = [tab]
backforward_widget.enabled = True
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
assert backforward_widget.text() == ''
assert not backforward_widget.isVisible()
def test_none_tab(backforward_widget, tabbed_browser_stubs, fake_web_tab):
"""Make sure nothing crashes when passing None as tab."""
tab = fake_web_tab(can_go_back=True, can_go_forward=True)
tabbed_browser = tabbed_browser_stubs[0]
tabbed_browser.current_index = 1
tabbed_browser.tabs = [tab]
backforward_widget.enabled = True
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
assert backforward_widget.text() == '[<>]'
assert backforward_widget.isVisible()
tabbed_browser.current_index = -1
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
assert backforward_widget.text() == ''
assert not backforward_widget.isVisible()
|
gpl-3.0
|
[
3,
6695,
26,
18133,
29,
1548,
570,
2991,
29,
1624,
13,
24,
23014,
29,
20,
5584,
29,
20,
10844,
26,
199,
199,
3,
1898,
9708,
13,
12682,
11040,
269,
5653,
699,
6558,
72,
262,
334,
1918,
27154,
9,
665,
1198,
32,
392,
31127,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2173,
31127,
14,
199,
3,
199,
3,
2173,
31127,
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,
2173,
31127,
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,
2173,
31127,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
774,
10257,
6688,
3938,
1041,
199,
199,
646,
4613,
199,
199,
504,
2173,
31127,
14,
973,
3806,
14,
1205,
1700,
492,
1771,
6688,
421,
199,
32,
4462,
14,
5997,
199,
318,
1771,
6688,
63,
3440,
8,
8440,
3018,
304,
272,
3938,
275,
1771,
6688,
14,
4540,
6688,
342,
272,
19227,
3018,
14,
525,
63,
3440,
8,
3440,
9,
272,
372,
3938,
421,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2425,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
12,
1420,
63,
505,
297,
359,
272,
334,
797,
12,
756,
12,
9929,
272,
334,
549,
12,
756,
12,
6730,
28,
26987,
272,
334,
797,
12,
715,
12,
6730,
19109,
659,
272,
334,
549,
12,
715,
12,
6730,
16137,
26987,
199,
566,
199,
318,
511,
63,
894,
6688,
63,
3440,
8,
894,
6688,
63,
3440,
12,
5174,
6123,
63,
5750,
63,
8957,
12,
1169,
4026,
63,
2520,
63,
2902,
12,
883,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
12,
1169,
1420,
63,
505,
304,
272,
408,
13913,
314,
10257,
6688,
3938,
13703,
314,
3211,
1318,
1041,
272,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
2425,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
29,
2425,
63,
1939,
63,
6688,
9,
272,
5174,
6123,
63,
5750,
275,
5174,
6123,
63,
5750,
63,
8957,
59,
16,
61,
272,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
413,
272,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
272,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
1420,
63,
505,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
508,
2155,
8,
2062,
63,
505,
9,
339,
327,
2670,
626,
314,
3938,
2612,
588,
8752,
340,
440,
315,
314,
2004,
1700,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
756,
272,
1771,
6688,
63,
3440,
14,
8191,
342,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14983,
342,
339,
327,
2670,
626,
314,
3938,
7545,
5305,
340,
2701,
14,
272,
340,
883,
63,
1939,
63,
894,
436,
883,
63,
1939,
63,
6688,
26,
267,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
797,
12,
883,
63,
1939,
63,
6688,
29,
797,
9,
267,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
267,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
267,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
267,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
2125,
267,
702,
440,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
421,
199,
318,
511,
63,
3592,
63,
2902,
8,
894,
6688,
63,
3440,
12,
5174,
6123,
63,
5750,
63,
8957,
12,
4026,
63,
2520,
63,
2902,
304,
272,
408,
5483,
3238,
6548,
2467,
9030,
1380,
9476,
488,
465,
5174,
1041,
272,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
549,
12,
883,
63,
1939,
63,
6688,
29,
549,
9,
272,
5174,
6123,
63,
5750,
275,
5174,
6123,
63,
5750,
63,
8957,
59,
16,
61,
272,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
413,
272,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
339,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
6730,
16137,
6616,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
339,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
446,
17,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
339,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
2125,
272,
702,
440,
1771,
6688,
63,
3440,
14,
374,
14917,
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
] |
[
6695,
26,
18133,
29,
1548,
570,
2991,
29,
1624,
13,
24,
23014,
29,
20,
5584,
29,
20,
10844,
26,
199,
199,
3,
1898,
9708,
13,
12682,
11040,
269,
5653,
699,
6558,
72,
262,
334,
1918,
27154,
9,
665,
1198,
32,
392,
31127,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2173,
31127,
14,
199,
3,
199,
3,
2173,
31127,
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,
2173,
31127,
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,
2173,
31127,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
774,
10257,
6688,
3938,
1041,
199,
199,
646,
4613,
199,
199,
504,
2173,
31127,
14,
973,
3806,
14,
1205,
1700,
492,
1771,
6688,
421,
199,
32,
4462,
14,
5997,
199,
318,
1771,
6688,
63,
3440,
8,
8440,
3018,
304,
272,
3938,
275,
1771,
6688,
14,
4540,
6688,
342,
272,
19227,
3018,
14,
525,
63,
3440,
8,
3440,
9,
272,
372,
3938,
421,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2425,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
12,
1420,
63,
505,
297,
359,
272,
334,
797,
12,
756,
12,
9929,
272,
334,
549,
12,
756,
12,
6730,
28,
26987,
272,
334,
797,
12,
715,
12,
6730,
19109,
659,
272,
334,
549,
12,
715,
12,
6730,
16137,
26987,
199,
566,
199,
318,
511,
63,
894,
6688,
63,
3440,
8,
894,
6688,
63,
3440,
12,
5174,
6123,
63,
5750,
63,
8957,
12,
1169,
4026,
63,
2520,
63,
2902,
12,
883,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
12,
1169,
1420,
63,
505,
304,
272,
408,
13913,
314,
10257,
6688,
3938,
13703,
314,
3211,
1318,
1041,
272,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
2425,
63,
1939,
63,
894,
12,
883,
63,
1939,
63,
6688,
29,
2425,
63,
1939,
63,
6688,
9,
272,
5174,
6123,
63,
5750,
275,
5174,
6123,
63,
5750,
63,
8957,
59,
16,
61,
272,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
413,
272,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
272,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
1420,
63,
505,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
508,
2155,
8,
2062,
63,
505,
9,
339,
327,
2670,
626,
314,
3938,
2612,
588,
8752,
340,
440,
315,
314,
2004,
1700,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
756,
272,
1771,
6688,
63,
3440,
14,
8191,
342,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14983,
342,
339,
327,
2670,
626,
314,
3938,
7545,
5305,
340,
2701,
14,
272,
340,
883,
63,
1939,
63,
894,
436,
883,
63,
1939,
63,
6688,
26,
267,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
797,
12,
883,
63,
1939,
63,
6688,
29,
797,
9,
267,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
267,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
267,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
267,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
2125,
267,
702,
440,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
421,
199,
318,
511,
63,
3592,
63,
2902,
8,
894,
6688,
63,
3440,
12,
5174,
6123,
63,
5750,
63,
8957,
12,
4026,
63,
2520,
63,
2902,
304,
272,
408,
5483,
3238,
6548,
2467,
9030,
1380,
9476,
488,
465,
5174,
1041,
272,
5174,
275,
4026,
63,
2520,
63,
2902,
8,
2425,
63,
1939,
63,
894,
29,
549,
12,
883,
63,
1939,
63,
6688,
29,
549,
9,
272,
5174,
6123,
63,
5750,
275,
5174,
6123,
63,
5750,
63,
8957,
59,
16,
61,
272,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
413,
272,
5174,
6123,
63,
5750,
14,
8741,
275,
359,
2902,
61,
272,
1771,
6688,
63,
3440,
14,
3827,
275,
715,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
339,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
6730,
16137,
6616,
272,
702,
1771,
6688,
63,
3440,
14,
374,
14917,
342,
339,
5174,
6123,
63,
5750,
14,
1818,
63,
1080,
275,
446,
17,
272,
1771,
6688,
63,
3440,
14,
265,
63,
2902,
63,
895,
63,
633,
63,
2489,
8,
2902,
6123,
63,
5750,
9,
339,
702,
1771,
6688,
63,
3440,
14,
505,
342,
508,
2125,
272,
702,
440,
1771,
6688,
63,
3440,
14,
374,
14917,
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,
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
] |
aarsan/azure-sdk-for-python
|
azure-common/testutils/common_auth.py
|
6
|
1755
|
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
import json
import os.path
def get_token_from_username_password(authority_url, username, password):
import adal
token_response = adal.acquire_token_with_username_password(
authority_url,
username,
password,
)
return token_response.get('accessToken')
def get_token_from_client_credentials(authority, client_id, secret):
import adal
token_response = adal.acquire_token_with_client_credentials(
authority,
client_id,
secret,
)
return token_response.get('accessToken')
def get_token_from_json_file(working_folder):
'''
Read the token from a json file 'credentials_real.json' in this directory
where the file looks like this:
{
"authorization_header": "Bearer eyJ0...8f5w"
}
'''
with open(os.path.join(working_folder, 'credentials_real.json')) as credential_file:
credential = json.load(credential_file)
token = credential['authorization_header'].split()[1]
return token
|
apache-2.0
|
[
172,
120,
124,
25812,
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
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,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
7656,
9460,
199,
646,
2022,
199,
646,
747,
14,
515,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
2473,
63,
2060,
8,
23635,
63,
633,
12,
3434,
12,
2505,
304,
272,
492,
1503,
279,
272,
1526,
63,
1310,
275,
1503,
279,
14,
8174,
63,
1418,
63,
1045,
63,
2473,
63,
2060,
8,
267,
18330,
63,
633,
12,
267,
3434,
12,
267,
2505,
12,
272,
776,
272,
372,
1526,
63,
1310,
14,
362,
360,
2732,
3264,
358,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
1258,
63,
6942,
8,
23635,
12,
1890,
63,
344,
12,
7565,
304,
272,
492,
1503,
279,
272,
1526,
63,
1310,
275,
1503,
279,
14,
8174,
63,
1418,
63,
1045,
63,
1258,
63,
6942,
8,
267,
18330,
12,
267,
1890,
63,
344,
12,
267,
7565,
12,
272,
776,
272,
372,
1526,
63,
1310,
14,
362,
360,
2732,
3264,
358,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
1001,
63,
493,
8,
9818,
63,
3741,
304,
272,
1449,
272,
5574,
314,
1526,
687,
282,
2022,
570,
283,
6942,
63,
3093,
14,
1001,
7,
315,
642,
2082,
272,
2382,
314,
570,
10734,
2839,
642,
26,
272,
469,
489,
298,
15846,
63,
1291,
582,
298,
3655,
21462,
325,
89,
42,
16,
1396,
24,
70,
21,
87,
2,
272,
789,
272,
1449,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
9818,
63,
3741,
12,
283,
6942,
63,
3093,
14,
1001,
1333,
465,
16338,
63,
493,
26,
267,
16338,
275,
2022,
14,
912,
8,
15591,
63,
493,
9,
267,
1526,
275,
16338,
459,
15846,
63,
1291,
2278,
1294,
3430,
17,
61,
267,
372,
1526,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
120,
124,
25812,
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
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,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
7656,
9460,
199,
646,
2022,
199,
646,
747,
14,
515,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
2473,
63,
2060,
8,
23635,
63,
633,
12,
3434,
12,
2505,
304,
272,
492,
1503,
279,
272,
1526,
63,
1310,
275,
1503,
279,
14,
8174,
63,
1418,
63,
1045,
63,
2473,
63,
2060,
8,
267,
18330,
63,
633,
12,
267,
3434,
12,
267,
2505,
12,
272,
776,
272,
372,
1526,
63,
1310,
14,
362,
360,
2732,
3264,
358,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
1258,
63,
6942,
8,
23635,
12,
1890,
63,
344,
12,
7565,
304,
272,
492,
1503,
279,
272,
1526,
63,
1310,
275,
1503,
279,
14,
8174,
63,
1418,
63,
1045,
63,
1258,
63,
6942,
8,
267,
18330,
12,
267,
1890,
63,
344,
12,
267,
7565,
12,
272,
776,
272,
372,
1526,
63,
1310,
14,
362,
360,
2732,
3264,
358,
421,
199,
318,
664,
63,
1418,
63,
504,
63,
1001,
63,
493,
8,
9818,
63,
3741,
304,
272,
1449,
272,
5574,
314,
1526,
687,
282,
2022,
570,
283,
6942,
63,
3093,
14,
1001,
7,
315,
642,
2082,
272,
2382,
314,
570,
10734,
2839,
642,
26,
272,
469,
489,
298,
15846,
63,
1291,
582,
298,
3655,
21462,
325,
89,
42,
16,
1396,
24,
70,
21,
87,
2,
272,
789,
272,
1449,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
9818,
63,
3741,
12,
283,
6942,
63,
3093,
14,
1001,
1333,
465,
16338,
63,
493,
26,
267,
16338,
275,
2022,
14,
912,
8,
15591,
63,
493,
9,
267,
1526,
275,
16338,
459,
15846,
63,
1291,
2278,
1294,
3430,
17,
61,
267,
372,
1526,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
temasek/android_external_chromium_org
|
tools/cr/cr/commands/command.py
|
25
|
3270
|
# 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.
"""Module to hold the Command plugin."""
import argparse
import cr
class Command(cr.Plugin, cr.Plugin.Type):
"""Base class for implementing cr commands.
These are the sub-commands on the command line, and modify the
accepted remaining arguments.
Commands in general do not implement the functionality directly, instead they
run a sequence of actions.
"""
@classmethod
def Select(cls, context):
"""Called to select which command is active.
This picks a command based on the first non - argument on the command
line.
Args:
context: The context to select the command for.
Returns:
the selected command, or None if not specified on the command line.
"""
if context.args:
return getattr(context.args, '_command', None)
return None
def __init__(self):
super(Command, self).__init__()
self.help = 'Missing help: {0}'.format(self.__class__.__name__)
self.description = None
self.epilog = None
self.parser = None
self.requires_build_dir = True
def AddArguments(self, subparsers):
"""Add arguments to the command line parser.
Called by the main function to add the command to the command line parser.
Commands that override this function to add more arguments must invoke
this method.
Args:
subparsers: The argparse subparser manager to add this command to.
Returns:
the parser that was built for the command.
"""
self.parser = subparsers.add_parser(
self.name,
add_help=False,
help=self.help,
description=self.description or self.help,
epilog=self.epilog,
)
self.parser.set_defaults(_command=self)
cr.Context.AddCommonArguments(self.parser)
cr.base.client.AddArguments(self.parser)
return self.parser
def ConsumeArgs(self, parser, reason):
"""Adds a remaining argument consumer to the parser.
A helper method that commands can use to consume all remaining arguments.
Use for things like lists of targets.
Args:
parser: The parser to consume remains for.
reason: The reason to give the user in the help text.
"""
parser.add_argument(
'_remains', metavar='arguments',
nargs=argparse.REMAINDER,
help='The additional arguments to {0}.'.format(reason)
)
def EarlyArgProcessing(self, context):
"""Called to make decisions based on speculative argument parsing.
When this method is called, enough of the command line parsing has been
done that the command is selected. This allows the command to make any
modifications needed before the final argument parsing is done.
Args:
context: The context that is parsing the arguments.
"""
cr.base.client.ApplyOutArgument(context)
@cr.Plugin.activemethod
def Run(self, context):
"""The main method of the command.
This is the only thing that a command has to implement, and it should not
call this base version.
Args:
context: The context to run the command in.
"""
_ = context
raise NotImplementedError('Must be overridden.')
|
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,
624,
2377,
370,
10266,
314,
5817,
3589,
1041,
199,
199,
646,
7534,
199,
199,
646,
2467,
421,
199,
533,
5817,
8,
1556,
14,
5061,
12,
2467,
14,
5061,
14,
804,
304,
523,
408,
1563,
1021,
367,
18234,
2467,
3718,
14,
819,
5723,
787,
314,
1007,
13,
4405,
641,
314,
1414,
1004,
12,
436,
2811,
314,
523,
10226,
7971,
2368,
14,
523,
5817,
83,
315,
8605,
886,
440,
5669,
314,
9330,
5370,
12,
3140,
2985,
523,
1255,
282,
3414,
402,
5445,
14,
523,
408,
819,
768,
3744,
523,
347,
9496,
8,
1886,
12,
1067,
304,
272,
408,
10474,
370,
3504,
1314,
1414,
365,
4702,
14,
339,
961,
31055,
282,
1414,
4079,
641,
314,
1642,
2222,
446,
1423,
641,
314,
1414,
272,
1004,
14,
272,
3033,
26,
489,
1067,
26,
710,
1067,
370,
3504,
314,
1414,
367,
14,
272,
1803,
26,
489,
314,
4895,
1414,
12,
503,
488,
340,
440,
2013,
641,
314,
1414,
1004,
14,
272,
408,
272,
340,
1067,
14,
589,
26,
489,
372,
2519,
8,
1100,
14,
589,
12,
2513,
1531,
297,
488,
9,
272,
372,
488,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
3110,
12,
291,
2843,
826,
4533,
272,
291,
14,
3437,
275,
283,
7718,
1720,
26,
469,
16,
5285,
908,
8,
277,
855,
533,
4914,
354,
3368,
272,
291,
14,
1802,
275,
488,
272,
291,
14,
28349,
275,
488,
272,
291,
14,
2087,
275,
488,
272,
291,
14,
6537,
63,
1506,
63,
694,
275,
715,
819,
347,
2654,
14517,
8,
277,
12,
26763,
304,
272,
408,
1123,
2368,
370,
314,
1414,
1004,
1798,
14,
339,
12295,
701,
314,
2446,
805,
370,
1050,
314,
1414,
370,
314,
1414,
1004,
1798,
14,
272,
5817,
83,
626,
4278,
642,
805,
370,
1050,
1655,
2368,
1471,
12677,
272,
642,
1083,
14,
272,
3033,
26,
489,
26763,
26,
710,
7534,
1007,
2087,
5256,
370,
1050,
642,
1414,
370,
14,
272,
1803,
26,
489,
314,
1798,
626,
1990,
6137,
367,
314,
1414,
14,
272,
408,
272,
291,
14,
2087,
275,
26763,
14,
525,
63,
2087,
8,
267,
291,
14,
354,
12,
267,
1050,
63,
3437,
29,
797,
12,
267,
1720,
29,
277,
14,
3437,
12,
267,
1369,
29,
277,
14,
1802,
503,
291,
14,
3437,
12,
267,
29850,
29,
277,
14,
28349,
12,
272,
776,
272,
291,
14,
2087,
14,
409,
63,
4322,
1547,
1531,
29,
277,
9,
272,
2467,
14,
2998,
14,
1123,
7844,
14517,
8,
277,
14,
2087,
9,
272,
2467,
14,
1095,
14,
1258,
14,
1123,
14517,
8,
277,
14,
2087,
9,
272,
372,
291,
14,
2087,
819,
347,
1448,
3639,
6213,
8,
277,
12,
1798,
12,
4499,
304,
272,
408,
14995,
282,
7971,
1423,
9790,
370,
314,
1798,
14,
339,
437,
5922,
1083,
626,
3718,
883,
675,
370,
9451,
1006,
7971,
2368,
14,
272,
3645,
367,
7645,
2839,
5548,
402,
4545,
14,
272,
3033,
26,
489,
1798,
26,
710,
1798,
370,
9451,
25803,
367,
14,
489,
4499,
26,
710,
4499,
370,
8120,
314,
922,
315,
314,
1720,
1318,
14,
272,
408,
272,
1798,
14,
525,
63,
2094,
8,
267,
2513,
8902,
83,
297,
8214,
534,
4958,
297,
267,
9237,
29,
18978,
14,
907,
2054,
3192,
540,
12,
267,
1720,
534,
1918,
4722,
2368,
370,
469,
16,
5565,
1370,
908,
8,
5764,
9,
272,
776,
819,
347,
662,
285,
590,
6373,
9589,
8,
277,
12,
1067,
304,
272,
408,
10474,
370,
1852,
12985,
1356,
4079,
641,
3158,
16813,
1423,
6057,
14,
339,
3979,
642,
1083,
365,
2797,
12,
8321,
402,
314,
1414,
1004,
6057,
965,
2757,
272,
4224,
626,
314,
1414,
365,
4895,
14,
961,
6127,
314,
1414,
370,
1852,
1263,
272,
23070,
4346,
2544,
314,
4242,
1423,
6057,
365,
4224,
14,
339,
3033,
26,
489,
1067,
26,
710,
1067,
626,
365,
6057,
314,
2368,
14,
272,
408,
272,
2467,
14,
1095,
14,
1258,
14,
16581,
2204,
5201,
8,
1100,
9,
819,
768,
1556,
14,
5061,
14,
2682,
765,
523,
347,
3378,
8,
277,
12,
1067,
304,
272,
408,
1918,
2446,
1083,
402,
314,
1414,
14,
339,
961,
365,
314,
1454,
8377,
626,
282,
1414,
965,
370,
5669,
12,
436,
652,
1077,
440,
272,
1240,
642,
1300,
1015,
14,
272,
3033,
26,
489,
1067,
26,
710,
1067,
370,
1255,
314,
1414,
315,
14,
272,
408,
272,
485,
275,
1067,
272,
746,
4279,
360,
13757,
506,
10087,
2659,
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
] |
[
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,
624,
2377,
370,
10266,
314,
5817,
3589,
1041,
199,
199,
646,
7534,
199,
199,
646,
2467,
421,
199,
533,
5817,
8,
1556,
14,
5061,
12,
2467,
14,
5061,
14,
804,
304,
523,
408,
1563,
1021,
367,
18234,
2467,
3718,
14,
819,
5723,
787,
314,
1007,
13,
4405,
641,
314,
1414,
1004,
12,
436,
2811,
314,
523,
10226,
7971,
2368,
14,
523,
5817,
83,
315,
8605,
886,
440,
5669,
314,
9330,
5370,
12,
3140,
2985,
523,
1255,
282,
3414,
402,
5445,
14,
523,
408,
819,
768,
3744,
523,
347,
9496,
8,
1886,
12,
1067,
304,
272,
408,
10474,
370,
3504,
1314,
1414,
365,
4702,
14,
339,
961,
31055,
282,
1414,
4079,
641,
314,
1642,
2222,
446,
1423,
641,
314,
1414,
272,
1004,
14,
272,
3033,
26,
489,
1067,
26,
710,
1067,
370,
3504,
314,
1414,
367,
14,
272,
1803,
26,
489,
314,
4895,
1414,
12,
503,
488,
340,
440,
2013,
641,
314,
1414,
1004,
14,
272,
408,
272,
340,
1067,
14,
589,
26,
489,
372,
2519,
8,
1100,
14,
589,
12,
2513,
1531,
297,
488,
9,
272,
372,
488,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
3110,
12,
291,
2843,
826,
4533,
272,
291,
14,
3437,
275,
283,
7718,
1720,
26,
469,
16,
5285,
908,
8,
277,
855,
533,
4914,
354,
3368,
272,
291,
14,
1802,
275,
488,
272,
291,
14,
28349,
275,
488,
272,
291,
14,
2087,
275,
488,
272,
291,
14,
6537,
63,
1506,
63,
694,
275,
715,
819,
347,
2654,
14517,
8,
277,
12,
26763,
304,
272,
408,
1123,
2368,
370,
314,
1414,
1004,
1798,
14,
339,
12295,
701,
314,
2446,
805,
370,
1050,
314,
1414,
370,
314,
1414,
1004,
1798,
14,
272,
5817,
83,
626,
4278,
642,
805,
370,
1050,
1655,
2368,
1471,
12677,
272,
642,
1083,
14,
272,
3033,
26,
489,
26763,
26,
710,
7534,
1007,
2087,
5256,
370,
1050,
642,
1414,
370,
14,
272,
1803,
26,
489,
314,
1798,
626,
1990,
6137,
367,
314,
1414,
14,
272,
408,
272,
291,
14,
2087,
275,
26763,
14,
525,
63,
2087,
8,
267,
291,
14,
354,
12,
267,
1050,
63,
3437,
29,
797,
12,
267,
1720,
29,
277,
14,
3437,
12,
267,
1369,
29,
277,
14,
1802,
503,
291,
14,
3437,
12,
267,
29850,
29,
277,
14,
28349,
12,
272,
776,
272,
291,
14,
2087,
14,
409,
63,
4322,
1547,
1531,
29,
277,
9,
272,
2467,
14,
2998,
14,
1123,
7844,
14517,
8,
277,
14,
2087,
9,
272,
2467,
14,
1095,
14,
1258,
14,
1123,
14517,
8,
277,
14,
2087,
9,
272,
372,
291,
14,
2087,
819,
347,
1448,
3639,
6213,
8,
277,
12,
1798,
12,
4499,
304,
272,
408,
14995,
282,
7971,
1423,
9790,
370,
314,
1798,
14,
339,
437,
5922,
1083,
626,
3718,
883,
675,
370,
9451,
1006,
7971,
2368,
14,
272,
3645,
367,
7645,
2839,
5548,
402,
4545,
14,
272,
3033,
26,
489,
1798,
26,
710,
1798,
370,
9451,
25803,
367,
14,
489,
4499,
26,
710,
4499,
370,
8120,
314,
922,
315,
314,
1720,
1318,
14,
272,
408,
272,
1798,
14,
525,
63,
2094,
8,
267,
2513,
8902,
83,
297,
8214,
534,
4958,
297,
267,
9237,
29,
18978,
14,
907,
2054,
3192,
540,
12,
267,
1720,
534,
1918,
4722,
2368,
370,
469,
16,
5565,
1370,
908,
8,
5764,
9,
272,
776,
819,
347,
662,
285,
590,
6373,
9589,
8,
277,
12,
1067,
304,
272,
408,
10474,
370,
1852,
12985,
1356,
4079,
641,
3158,
16813,
1423,
6057,
14,
339,
3979,
642,
1083,
365,
2797,
12,
8321,
402,
314,
1414,
1004,
6057,
965,
2757,
272,
4224,
626,
314,
1414,
365,
4895,
14,
961,
6127,
314,
1414,
370,
1852,
1263,
272,
23070,
4346,
2544,
314,
4242,
1423,
6057,
365,
4224,
14,
339,
3033,
26,
489,
1067,
26,
710,
1067,
626,
365,
6057,
314,
2368,
14,
272,
408,
272,
2467,
14,
1095,
14,
1258,
14,
16581,
2204,
5201,
8,
1100,
9,
819,
768,
1556,
14,
5061,
14,
2682,
765,
523,
347,
3378,
8,
277,
12,
1067,
304,
272,
408,
1918,
2446,
1083,
402,
314,
1414,
14,
339,
961,
365,
314,
1454,
8377,
626,
282,
1414,
965,
370,
5669,
12,
436,
652,
1077,
440,
272,
1240,
642,
1300,
1015,
14,
272,
3033,
26,
489,
1067,
26,
710,
1067,
370,
1255,
314,
1414,
315,
14,
272,
408,
272,
485,
275,
1067,
272,
746,
4279,
360,
13757,
506,
10087,
2659,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BladeSmithJohn/nixysa
|
nixysa/unsized_array_binding.py
|
9
|
27709
|
#!/usr/bin/python2.4
#
# Copyright 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""unsized_array binding model module.
This module implements the glue functions for the unsized_array binding model,
used for unsized arrays.
In C++, objects using this binding model are represented by a std::vector of
the C++ member representation of the base type (for example, an array of
by_pointer data will be a std::vector of a pointer to that data type). The
std::vector itself is passed by const reference (or by pointer if mutable), and
returned by copy. For example:
void SetValue(const std::vector<Class> &value);
std::vector<Class> GetValue();
For JS bindings, the array is represented by a JavaScript array.
"""
import string
class InvalidArrayUsage(Exception):
"""Raised when an array is used incorrectly."""
pass
def _CppTypeString(scope, type_defn):
"""Gets the C++ type of the array.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the array type.
Returns:
the C++ type describing the array.
"""
data_type = type_defn.GetFinalType().data_type
data_type_bm = data_type.binding_model
data_type_string, need_defn = data_type_bm.CppMemberString(scope, data_type)
return 'std::vector<%s >' % data_type_string, need_defn
def JavaMemberString(scope, type_defn):
"""Gets the representation of a member name in Java.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a string representing the type
"""
# Silence gpylint
scope, type_defn = scope, type_defn
return 'Array'
def CppTypedefString(scope, type_defn):
"""Gets the representation of a type when used in a C++ typedef.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the representation of
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
"""
return _CppTypeString(scope, type_defn)
def CppMemberString(scope, type_defn):
"""Gets the representation of a type when used as a C++ class member.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the representation of
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
"""
return _CppTypeString(scope, type_defn)
def CppReturnValueString(scope, type_defn):
"""Gets the representation of a type when used as a C++ function return value.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the representation of
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
"""
return _CppTypeString(scope, type_defn)
def CppParameterString(scope, type_defn):
"""Gets the representation of a type when used for a function parameter.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the representation of
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
"""
type_string, need_defn = _CppTypeString(scope, type_defn)
return 'const %s&' % type_string, need_defn
def CppMutableParameterString(scope, type_defn):
"""Gets the representation of a type for a mutable function parameter.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the string representing
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
"""
type_string, need_defn = _CppTypeString(scope, type_defn)
return '%s*' % type_string, need_defn
def CppMutableToNonMutable(scope, type_defn, expr):
"""Gets the string converting a mutable expression to a non-mutable one.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
expr: a string for the mutable expression.
Returns:
a string, which is the non-mutable expression.
"""
(scope, type_defn) = (scope, type_defn) # silence gpylint.
return '*(%s)' % expr
def CppBaseClassString(scope, type_defn):
"""Gets the representation of a type for a base class.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition for the type.
Returns:
a (string, boolean) pair, the first element being the string representing
the type, the second element indicating whether or not the definition of
the type is needed for the expression to be valid.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppCallMethod(scope, type_defn, object_expr, mutable, method, param_exprs):
"""Gets the representation of a member function call.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object being called.
object_expr: a string, which is the expression for the object being called.
mutable: a boolean, whether or not the 'object_expr' expression is mutable
or not
method: a Function, representing the function to call.
param_exprs: a list of strings, each being the expression for the value of
each parameter.
Returns:
a string, which is the expression for the function call.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppCallStaticMethod(scope, type_defn, method, param_exprs):
"""Gets the representation of a static function call.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object being called.
method: a Function, representing the function to call.
param_exprs: a list of strings, each being the expression for the value of
each parameter.
Returns:
a string, which is the expression for the function call.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppCallConstructor(scope, type_defn, method, param_exprs):
"""Gets the representation of a constructor call.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object being called.
method: a Function, representing the constructor to call.
param_exprs: a list of strings, each being the expression for the value of
each parameter.
Returns:
a string, which is the expression for the constructor call.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppSetField(scope, type_defn, object_expr, field, param_expr):
"""Gets the representation of an expression setting a field in an object.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object containing the
field being set.
object_expr: a string, which is the expression for the object containing
the field being set.
field: a string, the name of the field to be set.
param_expr: a strings, being the expression for the value to be set.
Returns:
a string, which is the expression for setting the field.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppGetField(scope, type_defn, object_expr, field):
"""Gets the representation of an expression getting a field in an object.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object containing the
field being retrieved.
object_expr: a string, which is the expression for the object containing
the field being retrieved.
field: a string, the name of the field to be retrieved.
Returns:
a string, which is the expression for getting the field.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppSetStatic(scope, type_defn, field, param_expr):
"""Gets the representation of an expression setting a static field.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object containing the
field being set.
field: a string, the name of the field to be set.
param_expr: a strings, being the expression for the value to be set.
Returns:
a string, which is the expression for setting the field.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def CppGetStatic(scope, type_defn, field):
"""Gets the representation of an expression getting a static field.
Args:
scope: a Definition for the scope in which the expression will be written.
type_defn: a Definition, representing the type of the object containing the
field being retrieved.
field: a string, the name of the field to be retrieved.
Returns:
a string, which is the expression for getting the field.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def JSDocTypeString(type_defn):
"""Gets the representation of a type in JSDoc notation.
Args:
type_defn: a Definition for the type.
Returns:
a string that is the JSDoc notation of type_defn.
"""
type_defn = type_defn.GetFinalType()
element_type_defn = type_defn.data_type.GetFinalType()
return ('!Array.<%s>' %
element_type_defn.binding_model.JSDocTypeString(element_type_defn))
def NpapiBindingGlueHeader(scope, type_defn):
"""Gets the NPAPI glue header for a given type.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
Returns:
a string, the glue header.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def NpapiBindingGlueCpp(scope, type_defn):
"""Gets the NPAPI glue implementation for a given type.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
Returns:
a string, the glue implementation.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def NpapiDispatchFunctionHeader(scope, type_defn, variable, npp, success):
"""Gets a header for NPAPI glue dispatch functions.
This function creates a string containing a C++ code snippet that should be
included at the beginning of NPAPI glue dispatch functions like Invoke or
GetProperty. This code snippet will declare and initialize certain variables
that will be used in the dispatch functions, like the NPObject representing
the object, or a pointer to the NPP instance.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
variable: a string, representing a name of a variable that can be used to
store a reference to the object.
npp: a string, representing the name of the variable that holds the pointer
to the NPP instance. Will be declared by the code snippet.
success: the name of a bool variable containing the current success status.
(is not declared by the code snippet).
Returns:
a (string, string) pair, the first string being the code snippet, and the
second string being an expression to access the object.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
_from_npvariant_template = string.Template("""
${Type} ${variable};
do {
if (!NPVARIANT_IS_OBJECT(${input})) {
*error_handle = "Error in " ${context}
": was expecting an array but got a non-object.";
${success} = false;
break;
}
NPObject *npobject = NPVARIANT_TO_OBJECT(${input});
NPVariant value;
if (!GetNPObjectProperty(${npp}, npobject, "length", &value)) {
${success} = false;
*error_handle = "Error in " ${context}
": input had no valid length property.";
}
if (!NPVARIANT_IS_NUMBER(value)) {
NPN_ReleaseVariantValue(&value);
${success} = false;
*error_handle = "Error in " ${context}
": input had no valid numeric length property.";
break;
}
int size = static_cast<int>(NPVARIANT_TO_NUMBER(value));
${variable}.resize(size);
for (int i = 0; i < size; i++) {
if (!GetNPArrayProperty(${npp}, npobject, i, &value)) {
${success} = false;
*error_handle = "Exception while validating " ${context}
": array had no value at an index less than "
"or equal to the index requested.";
break;
}
${GetValue}
NPN_ReleaseVariantValue(&value);
if (!${success}) {
*error_handle = "Exception while validating " ${context}
": a value at an index less than or equal to the "
"index requested was missing or of invalid type.";
break;
}
${variable}[i] = ${expr};
}
} while (false);
""")
def NpapiFromNPVariant(scope, type_defn, input_expr, variable, success,
exception_context, npp):
"""Gets the string to get a value from a NPVariant.
This function creates a string containing a C++ code snippet that is used to
retrieve a value from a NPVariant. If an error occurs, like if the NPVariant
is not of the correct type, the snippet will set the success status variable
to false.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type of the value.
input_expr: an expression representing the NPVariant to get the value from.
variable: a string, representing a name of a variable that can be used to
store a reference to the value.
success: the name of a bool variable containing the current success status.
exception_context: the name of a string containing context information, for
use in exception reporting.
npp: a string, representing the name of the variable that holds the pointer
to the NPP instance.
Returns:
a (string, string) pair, the first string being the code snippet and the
second one being the expression to access that value.
"""
data_type = type_defn.GetFinalType().data_type
data_type_bm = data_type.binding_model
text, expr = data_type_bm.NpapiFromNPVariant(scope, data_type, 'value',
'%s_i' % variable, success,
exception_context, npp)
type_name, unused_need_defn = _CppTypeString(scope, type_defn)
text = _from_npvariant_template.substitute(Type=type_name,
variable=variable,
input=input_expr,
GetValue=text,
expr=expr,
npp=npp,
success=success,
context=exception_context)
return (text, variable)
_expr_to_npvariant_template = string.Template("""
${Type} ${variable} = ${expr};
NPObject *${variable}_npobject = CreateArray(${npp});
static const char *array_push_identifier = "push";
NPIdentifier identifier = NPN_GetStringIdentifier(array_push_identifier);
for (${Type}::size_type i = 0; i < ${variable}.size(); ++i) {
NPVariant value;
${SetValuePre}
if (!${success}) break;
${SetValuePost}
NPVariant result;
NPN_Invoke(${npp}, ${variable}_npobject, identifier, &value, 1, &result);
NPN_ReleaseVariantValue(&value);
NPN_ReleaseVariantValue(&result);
}
""")
def NpapiExprToNPVariant(scope, type_defn, variable, expression, output,
success, npp):
"""Gets the string to store a value into a NPVariant.
This function creates a string containing a C++ code snippet that is used to
store a value into a NPVariant. That operation takes two phases, one that
allocates necessary NPAPI resources, and that can fail, and one that actually
sets the NPVariant (that can't fail). If an error occurs, the snippet will
set the success status variable to false.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type of the value.
variable: a string, representing a name of a variable that can be used to
store a reference to the value.
expression: a string representing the expression that yields the value to
be stored.
output: an expression representing a pointer to the NPVariant to store the
value into.
success: the name of a bool variable containing the current success status.
npp: a string, representing the name of the variable that holds the pointer
to the NPP instance.
Returns:
a (string, string) pair, the first string being the code snippet for the
first phase, and the second one being the code snippet for the second phase.
"""
data_type = type_defn.GetFinalType().data_type
data_type_bm = data_type.binding_model
pre, post = data_type_bm.NpapiExprToNPVariant(scope, data_type,
'%s_value' % variable,
'%s[i]' % variable, '&value',
success, npp)
type_name, unused_need_defn = _CppTypeString(scope, type_defn)
text = _expr_to_npvariant_template.substitute(Type=type_name,
variable=variable,
expr=expression,
npp=npp,
SetValuePre=pre,
SetValuePost=post,
success=success)
return (text, 'OBJECT_TO_NPVARIANT(%s_npobject, *%s);' % (variable, output))
def PpapiBindingGlueHeader(scope, type_defn):
"""Gets the PPAPI glue header for a given type.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
Returns:
a string, the glue header.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def PpapiBindingGlueCpp(scope, type_defn):
"""Gets the PPAPI glue implementation for a given type.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
Returns:
a string, the glue implementation.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
def PpapiDispatchFunctionHeader(scope, type_defn, variable, npp, success):
"""Gets a header for PPAPI glue dispatch functions.
This function creates a string containing a C++ code snippet that should be
included at the beginning of PPAPI glue dispatch functions like Call or
GetProperty. This code snippet will declare and initialize certain variables
that will be used in the dispatch functions, like the pp::Var representing
the object, or a pointer to the pp::Instance.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type.
variable: a string, representing a name of a variable that can be used to
store a reference to the object.
npp: a string, representing the name of the variable that holds the pointer
to the pp::Instance. Will be declared by the code snippet.
success: the name of a bool variable containing the current success status.
(is not declared by the code snippet).
Returns:
a (string, string) pair, the first string being the code snippet, and the
second string being an expression to access the object.
Raises:
InvalidArrayUsage: always. This function should not be called on an array.
"""
raise InvalidArrayUsage
_from_ppvar_template = string.Template("""
${Type} ${variable};
do {
if (!${input}.is_object()) {
*exception = pp::Var("Error in " ${context}
": was expecting an array but got a non-object.");
${success} = false;
break;
}
pp::VarPrivate arrayObject(${input});
pp::Var count = arrayObject.GetProperty(pp::Var("length"));
if (!count.is_number()) {
*exception = pp::Var("Error in " ${context}
": input had no valid length property.");
${success} = false;
break;
}
int size = count.AsInt();
if (size < 0) {
*exception = pp::Var("Error in " ${context}
": input had negative length property.");
${success} = false;
break;
}
${variable}.resize(size);
for (int i = 0; i < size; i++) {
pp::Var value = arrayObject.GetProperty(pp::Var(i));
${GetValue}
if (!${success}) {
*exception = pp::Var("Exception while validating " ${context}
": a value at an index less than or equal to the "
"index requested was missing or of invalid type.");
break;
}
${variable}[i] = ${expr};
}
} while (false);
""")
def PpapiFromPPVar(scope, type_defn, input_expr, variable, success,
exception_context, npp):
"""Gets the string to get a value from a pp::Var.
This function creates a string containing a C++ code snippet that is used to
retrieve a value from a pp::Var. If an error occurs, like if the pp::Var
is not of the correct type, the snippet will set the success status variable
to false.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type of the value.
input_expr: an expression representing the pp::Var to get the value from.
variable: a string, representing a name of a variable that can be used to
store a reference to the value.
success: the name of a bool variable containing the current success status.
exception_context: the name of a string containing context information, for
use in exception reporting.
npp: a string, representing the name of the variable that holds the pointer
to the pp::Instance.
Returns:
a (string, string) pair, the first string being the code snippet and the
second one being the expression to access that value.
"""
data_type = type_defn.GetFinalType().data_type
data_type_bm = data_type.binding_model
text, expr = data_type_bm.PpapiFromPPVar(scope, data_type, 'value',
'%s_i' % variable, success,
exception_context, npp)
type_name, unused_need_defn = _CppTypeString(scope, type_defn)
text = _from_ppvar_template.substitute(Type=type_name,
variable=variable,
input=input_expr,
GetValue=text,
expr=expr,
npp=npp,
success=success,
context=exception_context)
return (text, variable)
_expr_to_ppvar_template = string.Template("""
${Type} ${variable} = ${expr};
pp::VarPrivate ${variable}_ppvar = pp::VarPrivate(CreateArray(${npp}));
if (${variable}_ppvar.is_object()) {
for (${Type}::size_type i = 0; i < ${variable}.size(); i++) {
pp::Var value;
${SetValuePre}
if (!${success}) break;
${SetValuePost}
${variable}_ppvar.Call("push", value);
}
} else {
*exception = pp::Var("Unable to allocate JS array");
${success} = false;
}
""")
def PpapiExprToPPVar(scope, type_defn, variable, expression, output,
success, npp):
"""Gets the string to store a value into a pp::Var.
This function creates a string containing a C++ code snippet that is used to
store a value into a pp::Var. That operation takes two phases, one that
allocates necessary PPAPI resources, and that can fail, and one that actually
sets the pp::Var (that can't fail). If an error occurs, the snippet will
set the success status variable to false.
Args:
scope: a Definition for the scope in which the glue will be written.
type_defn: a Definition, representing the type of the value.
variable: a string, representing a name of a variable that can be used to
store a reference to the value.
expression: a string representing the expression that yields the value to
be stored.
output: an expression representing a pointer to the pp::Var to store the
value into.
success: the name of a bool variable containing the current success status.
npp: a string, representing the name of the variable that holds the pointer
to the pp::Instance.
Returns:
a (string, string) pair, the first string being the code snippet for the
first phase, and the second one being the code snippet for the second phase.
"""
data_type = type_defn.GetFinalType().data_type
data_type_bm = data_type.binding_model
pre, post = data_type_bm.PpapiExprToPPVar(scope, data_type,
'%s_value' % variable,
'%s[i]' % variable, '&value',
success, npp)
type_name, unused_need_defn = _CppTypeString(scope, type_defn)
text = _expr_to_ppvar_template.substitute(Type=type_name,
variable=variable,
expr=expression,
npp=npp,
SetValuePre=pre,
SetValuePost=post,
success=success)
return (text, '*%s = %s_ppvar;' % (output, variable))
def main():
pass
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
324,
15308,
63,
1144,
11696,
1402,
859,
14,
199,
199,
2765,
859,
9031,
314,
6482,
310,
3423,
367,
314,
625,
15308,
63,
1144,
11696,
1402,
12,
199,
2972,
367,
625,
15308,
6572,
14,
199,
199,
607,
445,
4176,
12,
2251,
1808,
642,
11696,
1402,
787,
11159,
701,
282,
2418,
447,
4106,
402,
199,
1589,
445,
4176,
3653,
6025,
402,
314,
1300,
730,
334,
509,
2893,
12,
376,
1625,
402,
199,
991,
63,
3929,
666,
911,
506,
282,
2418,
447,
4106,
402,
282,
7849,
370,
626,
666,
730,
680,
221,
710,
199,
1516,
447,
4106,
6337,
365,
3032,
701,
950,
3659,
334,
269,
701,
7849,
340,
17194,
395,
436,
199,
19065,
701,
1331,
14,
2104,
2893,
26,
819,
2309,
2494,
1110,
8,
1297,
2418,
447,
4106,
28,
2543,
30,
1253,
585,
2736,
523,
2418,
447,
4106,
28,
2543,
30,
2372,
1110,
7303,
199,
199,
1858,
18001,
17792,
12,
314,
1625,
365,
11159,
701,
282,
15250,
1625,
14,
199,
624,
199,
199,
646,
1059,
421,
199,
533,
6378,
3836,
7692,
8,
1726,
304,
523,
408,
16894,
1380,
376,
1625,
365,
1202,
22743,
1041,
523,
986,
421,
199,
318,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
445,
4176,
730,
402,
314,
1625,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
1625,
730,
14,
819,
1803,
26,
272,
314,
445,
4176,
730,
13660,
314,
1625,
14,
523,
408,
523,
666,
63,
466,
275,
730,
63,
27950,
14,
1002,
12776,
804,
1252,
576,
63,
466,
523,
666,
63,
466,
63,
12648,
275,
666,
63,
466,
14,
9140,
63,
1238,
523,
666,
63,
466,
63,
875,
12,
1929,
63,
27950,
275,
666,
63,
466,
63,
12648,
14,
19705,
7021,
1558,
8,
2645,
12,
666,
63,
466,
9,
523,
372,
283,
1516,
447,
4106,
21110,
83,
690,
7,
450,
666,
63,
466,
63,
875,
12,
1929,
63,
27950,
421,
199,
318,
9586,
7021,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
3653,
536,
315,
9586,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
1059,
6144,
314,
730,
523,
408,
523,
327,
428,
441,
21225,
486,
26324,
523,
4194,
12,
730,
63,
27950,
275,
4194,
12,
730,
63,
27950,
523,
372,
283,
3836,
7,
421,
199,
318,
445,
802,
804,
318,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
315,
282,
445,
4176,
22037,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
7021,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
465,
282,
445,
4176,
1021,
3653,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
1767,
1110,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
465,
282,
445,
4176,
805,
372,
574,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
4720,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
367,
282,
805,
2725,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
324,
15308,
63,
1144,
11696,
1402,
859,
14,
199,
199,
2765,
859,
9031,
314,
6482,
310,
3423,
367,
314,
625,
15308,
63,
1144,
11696,
1402,
12,
199,
2972,
367,
625,
15308,
6572,
14,
199,
199,
607,
445,
4176,
12,
2251,
1808,
642,
11696,
1402,
787,
11159,
701,
282,
2418,
447,
4106,
402,
199,
1589,
445,
4176,
3653,
6025,
402,
314,
1300,
730,
334,
509,
2893,
12,
376,
1625,
402,
199,
991,
63,
3929,
666,
911,
506,
282,
2418,
447,
4106,
402,
282,
7849,
370,
626,
666,
730,
680,
221,
710,
199,
1516,
447,
4106,
6337,
365,
3032,
701,
950,
3659,
334,
269,
701,
7849,
340,
17194,
395,
436,
199,
19065,
701,
1331,
14,
2104,
2893,
26,
819,
2309,
2494,
1110,
8,
1297,
2418,
447,
4106,
28,
2543,
30,
1253,
585,
2736,
523,
2418,
447,
4106,
28,
2543,
30,
2372,
1110,
7303,
199,
199,
1858,
18001,
17792,
12,
314,
1625,
365,
11159,
701,
282,
15250,
1625,
14,
199,
624,
199,
199,
646,
1059,
421,
199,
533,
6378,
3836,
7692,
8,
1726,
304,
523,
408,
16894,
1380,
376,
1625,
365,
1202,
22743,
1041,
523,
986,
421,
199,
318,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
445,
4176,
730,
402,
314,
1625,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
1625,
730,
14,
819,
1803,
26,
272,
314,
445,
4176,
730,
13660,
314,
1625,
14,
523,
408,
523,
666,
63,
466,
275,
730,
63,
27950,
14,
1002,
12776,
804,
1252,
576,
63,
466,
523,
666,
63,
466,
63,
12648,
275,
666,
63,
466,
14,
9140,
63,
1238,
523,
666,
63,
466,
63,
875,
12,
1929,
63,
27950,
275,
666,
63,
466,
63,
12648,
14,
19705,
7021,
1558,
8,
2645,
12,
666,
63,
466,
9,
523,
372,
283,
1516,
447,
4106,
21110,
83,
690,
7,
450,
666,
63,
466,
63,
875,
12,
1929,
63,
27950,
421,
199,
318,
9586,
7021,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
3653,
536,
315,
9586,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
1059,
6144,
314,
730,
523,
408,
523,
327,
428,
441,
21225,
486,
26324,
523,
4194,
12,
730,
63,
27950,
275,
4194,
12,
730,
63,
27950,
523,
372,
283,
3836,
7,
421,
199,
318,
445,
802,
804,
318,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
315,
282,
445,
4176,
22037,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
7021,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
465,
282,
445,
4176,
1021,
3653,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
1767,
1110,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
465,
282,
445,
4176,
805,
372,
574,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
503,
440,
314,
5492,
402,
272,
314,
730,
365,
4346,
367,
314,
3965,
370,
506,
1686,
14,
523,
408,
523,
372,
485,
19705,
804,
1558,
8,
2645,
12,
730,
63,
27950,
9,
421,
199,
318,
445,
802,
4720,
1558,
8,
2645,
12,
730,
63,
27950,
304,
523,
408,
14426,
314,
6025,
402,
282,
730,
1380,
1202,
367,
282,
805,
2725,
14,
819,
3033,
26,
272,
4194,
26,
282,
29398,
367,
314,
4194,
315,
1314,
314,
3965,
911,
506,
5313,
14,
272,
730,
63,
27950,
26,
282,
29398,
367,
314,
730,
14,
819,
1803,
26,
272,
282,
334,
875,
12,
5046,
9,
4092,
12,
314,
1642,
1819,
3769,
314,
6025,
402,
272,
314,
730,
12,
314,
3499,
1819,
9297,
3775,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dendisuhubdy/tensorflow
|
tensorflow/python/keras/engine/saving_test.py
|
2
|
27094
|
# 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.
#,============================================================================
"""Tests for model saving."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import shutil
import tempfile
from absl.testing import parameterized
import numpy as np
from tensorflow.python import keras
from tensorflow.python.eager import context
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.keras.engine import training
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.platform import test
from tensorflow.python.training import training as training_module
try:
import h5py # pylint:disable=g-import-not-at-top
except ImportError:
h5py = None
class TestWeightSavingAndLoading(test.TestCase, parameterized.TestCase):
def test_weight_loading(self):
with self.test_session():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3)(a)
b = keras.layers.Dense(1)(x)
model = keras.models.Model(a, b)
x = np.random.random((3, 2))
ref_y = model.predict(x)
weights = model.get_weights()
model.set_weights(weights)
y = model.predict(x)
self.assertAllClose(ref_y, y)
with self.assertRaises(ValueError):
model.set_weights(weights[1:])
with self.assertRaises(ValueError):
model.set_weights(weights[::-1])
temp_dir = self.get_temp_dir()
self.addCleanup(shutil.rmtree, temp_dir)
no_extension_path = os.path.join(temp_dir, 'test')
model.save_weights(no_extension_path, save_format='tf')
model.load_weights(no_extension_path)
y = model.predict(x)
self.assertAllClose(ref_y, y)
if h5py is None:
return # Skip rest of test if H5py isn't available.
h5_path = os.path.join(temp_dir, 'test.h5')
model.save_weights(h5_path)
model.load_weights(h5_path)
y = model.predict(x)
self.assertAllClose(ref_y, y)
model.load_weights(h5_path, by_name=True)
y = model.predict(x)
self.assertAllClose(ref_y, y)
model.save_weights(no_extension_path, save_format='hdf5')
model.load_weights(no_extension_path)
y = model.predict(x)
self.assertAllClose(ref_y, y)
def test_weight_preprocessing(self):
input_dim = 3
output_dim = 3
size = 2
cases = [
[
(keras.layers.Bidirectional(keras.layers.SimpleRNN(2))),
[np.random.random((2, 1)), np.random.random((2, 1))],
(None, 3, 2),
],
[
(keras.layers.TimeDistributed(keras.layers.Dense(1))),
[np.random.random((2, 1)), np.random.random((1,))],
(None, 3, 2),
],
[
(keras.layers.Conv1D(output_dim, size, use_bias=False)),
[np.random.random((output_dim, input_dim, size, 1))],
(None, 4, input_dim),
],
[
(keras.layers.Conv2D(output_dim, size,
use_bias=False, data_format='channels_first')),
[np.random.random((output_dim, input_dim, size, size))],
(None, input_dim, 4, 4),
],
[
(keras.layers.Conv2DTranspose(output_dim, size,
use_bias=False,
data_format='channels_first')),
[np.random.random((output_dim, input_dim, size, size))],
(None, input_dim, 4, 4),
],
[
(keras.layers.Conv2DTranspose(output_dim, size,
use_bias=False,
data_format='channels_last')),
[np.random.random((size, size, input_dim, output_dim))],
(None, 4, 4, input_dim),
],
[
(keras.layers.Conv3D(output_dim, size,
use_bias=False, data_format='channels_first')),
[np.random.random((output_dim, input_dim, size, size, size))],
(None, input_dim, 4, 4, 4),
],
[
(keras.layers.GRU(output_dim)),
[np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,)),
np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,)),
np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,))],
(None, 4, input_dim),
],
[
(keras.layers.LSTM(output_dim)),
[np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,)),
np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,)),
np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,)),
np.random.random((input_dim, output_dim)),
np.random.random((output_dim, output_dim)),
np.random.random((output_dim,))],
(None, 4, input_dim),
],
]
for layer, weights, input_shape in cases:
layer.build(input_shape)
_ = keras.engine.saving.preprocess_weights_for_loading(
layer, weights, original_keras_version='1')
model = keras.models.Sequential([keras.layers.Dense(2, input_dim=2)])
_ = keras.engine.saving.preprocess_weights_for_loading(
model, model.weights, original_keras_version='1')
x = keras.Input((2,))
y = keras.layers.Dense(2)(x)
model = keras.models.Model(x, y)
_ = keras.engine.saving.preprocess_weights_for_loading(
model, model.weights, original_keras_version='1')
@parameterized.named_parameters(
('gru', keras.layers.GRU, {
'units': 2,
'input_shape': (3, 5)
}),
('gru_with_reset_after', keras.layers.GRU, {
'units': 2,
'input_shape': (3, 5),
'reset_after': True
}),
('lstm', keras.layers.LSTM, {
'units': 2,
'input_shape': (3, 5)
}),
('cudnngru', keras.layers.CuDNNGRU, {
'units': 2,
'input_shape': (3, 5)
}),
('cudnnlstm', keras.layers.CuDNNLSTM, {
'units': 2,
'input_shape': (3, 5)
}))
def test_preprocess_weights_for_loading_rnn_should_be_idempotent(
self, layer_class, layer_args):
with self.test_session():
layer = layer_class(**layer_args)
layer.build(input_shape=layer_args.get('input_shape'))
weights1 = layer.get_weights()
weights2 = keras.engine.saving.preprocess_weights_for_loading(
layer, weights1)
_ = [
self.assertAllClose(x, y, rtol=1e-05)
for (x, y) in zip(weights1, weights2)
]
def test_sequential_weight_loading(self):
if h5py is None:
return
temp_dir = self.get_temp_dir()
self.addCleanup(shutil.rmtree, temp_dir)
h5_path = os.path.join(temp_dir, 'test.h5')
num_hidden = 5
input_dim = 3
batch_size = 5
num_classes = 2
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(num_hidden, input_dim=input_dim))
model.add(keras.layers.Dense(num_classes))
x = np.random.random((batch_size, input_dim))
ref_y = model.predict(x)
model.save_weights(h5_path)
model = keras.models.Sequential()
model.add(keras.layers.Dense(num_hidden, input_dim=input_dim))
model.add(keras.layers.Dense(num_classes))
model.load_weights(h5_path)
y = model.predict(x)
self.assertAllClose(y, ref_y)
class TestWholeModelSaving(test.TestCase):
def test_sequential_model_saving(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.RepeatVector(3))
model.add(keras.layers.TimeDistributed(keras.layers.Dense(3)))
model.compile(loss=keras.losses.MSE,
optimizer=keras.optimizers.RMSprop(lr=0.0001),
metrics=[keras.metrics.categorical_accuracy],
sample_weight_mode='temporal')
x = np.random.random((1, 3))
y = np.random.random((1, 3, 3))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
new_model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
out2 = new_model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
# test that new updates are the same with both models
x = np.random.random((1, 3))
y = np.random.random((1, 3, 3))
model.train_on_batch(x, y)
new_model.train_on_batch(x, y)
out = model.predict(x)
out2 = new_model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
def test_sequential_model_saving_without_compile(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.RepeatVector(3))
model.add(keras.layers.TimeDistributed(keras.layers.Dense(3)))
x = np.random.random((1, 3))
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
# Save the model without any compilation or training.
keras.models.save_model(model, fname)
new_model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
out2 = new_model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
def test_sequential_model_saving_2(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
# test with custom optimizer, loss
class CustomOp(keras.optimizers.RMSprop):
pass
def custom_loss(y_true, y_pred):
return keras.losses.mse(y_true, y_pred)
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.Dense(3))
model.compile(loss=custom_loss, optimizer=CustomOp(), metrics=['acc'])
x = np.random.random((1, 3))
y = np.random.random((1, 3))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(
fname,
custom_objects={'CustomOp': CustomOp,
'custom_loss': custom_loss})
os.close(fd)
os.remove(fname)
out2 = model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
def test_functional_model_saving(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
inputs = keras.layers.Input(shape=(3,))
x = keras.layers.Dense(2)(inputs)
output = keras.layers.Dense(3)(x)
model = keras.models.Model(inputs, output)
model.compile(loss=keras.losses.MSE,
optimizer=keras.optimizers.RMSprop(lr=0.0001),
metrics=[keras.metrics.categorical_accuracy])
x = np.random.random((1, 3))
y = np.random.random((1, 3))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
out2 = model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
def test_saving_without_compilation(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.Dense(3))
model.compile(loss='mse', optimizer='sgd', metrics=['acc'])
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
def test_saving_with_tf_optimizer(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.Dense(3))
model.compile(loss='mse',
optimizer=training_module.AdadeltaOptimizer(0.1),
metrics=['acc'])
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
def test_saving_right_after_compilation(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(3,)))
model.add(keras.layers.Dense(3))
model.compile(loss='mse', optimizer='sgd', metrics=['acc'])
model._make_train_function()
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
def test_saving_lambda_numpy_array_arguments(self):
if h5py is None:
self.skipTest('h5py required to run this test')
mean = np.random.random((4, 2, 3))
std = np.abs(np.random.random((4, 2, 3))) + 1e-5
inputs = keras.layers.Input(shape=(4, 2, 3))
output = keras.layers.Lambda(lambda image, mu, std: (image - mu) / std,
arguments={'mu': mean, 'std': std})(inputs)
model = keras.models.Model(inputs, output)
model.compile(loss='mse', optimizer='sgd', metrics=['acc'])
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
os.close(fd)
os.remove(fname)
self.assertAllClose(mean, model.layers[1].arguments['mu'])
self.assertAllClose(std, model.layers[1].arguments['std'])
def test_saving_model_with_long_layer_names(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
# This layer name will make the `layers_name` HDF5 attribute blow
# out of proportion. Note that it fits into the internal HDF5
# attribute memory limit on its own but because h5py converts
# the list of layer names into numpy array, which uses the same
# amout of memory for every item, it increases the memory
# requirements substantially.
x = keras.Input(shape=(2,), name='input_' + ('x' * (2**15)))
f = x
for i in range(4):
f = keras.layers.Dense(2, name='dense_%d' % (i,))(f)
model = keras.Model(inputs=[x], outputs=[f])
model.compile(loss='mse', optimizer='adam', metrics=['acc'])
x = np.random.random((1, 2))
y = np.random.random((1, 2))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
# Check that the HDF5 files contains chunked array
# of layer names.
with h5py.File(fname, 'r') as h5file:
num_names_arrays = len([attr for attr in h5file['model_weights'].attrs
if attr.startswith('layer_names')])
# The chunking of layer names array should have happened.
self.assertGreater(num_names_arrays, 0)
out2 = model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
# Cleanup
os.close(fd)
os.remove(fname)
def test_saving_model_with_long_weights_names(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
x = keras.Input(shape=(2,), name='nested_model_input')
f = x
for i in range(4):
f = keras.layers.Dense(2, name='nested_model_dense_%d' % (i,))(f)
# This layer name will make the `weights_name`
# HDF5 attribute blow out of proportion.
f = keras.layers.Dense(2, name='nested_model_output' + ('x' * (2**14)))(f)
nested_model = keras.Model(inputs=[x], outputs=[f], name='nested_model')
x = keras.Input(shape=(2,), name='outer_model_input')
f = nested_model(x)
f = keras.layers.Dense(2, name='outer_model_output')(f)
model = keras.Model(inputs=[x], outputs=[f])
model.compile(loss='mse', optimizer='adam', metrics=['acc'])
x = np.random.random((1, 2))
y = np.random.random((1, 2))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
keras.models.save_model(model, fname)
model = keras.models.load_model(fname)
# Check that the HDF5 files contains chunked array
# of weight names.
with h5py.File(fname, 'r') as h5file:
num_weight_arrays = len(
[attr for attr in h5file['model_weights']['nested_model'].attrs
if attr.startswith('weight_names')])
# The chunking of layer names array should have happened.
self.assertGreater(num_weight_arrays, 0)
out2 = model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
# Cleanup
os.close(fd)
os.remove(fname)
def test_model_saving_to_pre_created_h5py_file(self):
if h5py is None:
self.skipTest('h5py required to run this test')
with self.test_session():
inputs = keras.Input(shape=(3,))
x = keras.layers.Dense(2)(inputs)
outputs = keras.layers.Dense(3)(x)
model = keras.Model(inputs, outputs)
model.compile(loss=keras.losses.MSE,
optimizer=keras.optimizers.Adam(),
metrics=[keras.metrics.categorical_accuracy])
x = np.random.random((1, 3))
y = np.random.random((1, 3))
model.train_on_batch(x, y)
out = model.predict(x)
fd, fname = tempfile.mkstemp('.h5')
with h5py.File(fname, mode='r+') as h5file:
keras.models.save_model(model, h5file)
loaded_model = keras.models.load_model(h5file)
out2 = loaded_model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
# Test non-default options in h5
with h5py.File('_', driver='core',
backing_store=False) as h5file:
keras.models.save_model(model, h5file)
loaded_model = keras.models.load_model(h5file)
out2 = loaded_model.predict(x)
self.assertAllClose(out, out2, atol=1e-05)
# Cleanup
os.close(fd)
os.remove(fname)
class SubclassedModel(training.Model):
def __init__(self):
super(SubclassedModel, self).__init__()
self.x_layer = keras.layers.Dense(3)
self.b_layer = keras.layers.Dense(1)
def call(self, a):
return self.b_layer(self.x_layer(a))
class TestWeightSavingAndLoadingTFFormat(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def test_tensorflow_format_overwrite(self):
with self.test_session() as session:
model = SubclassedModel()
temp_dir = self.get_temp_dir()
prefix = os.path.join(temp_dir, 'ckpt')
x = constant_op.constant(np.random.random((3, 2)), dtype=dtypes.float32)
executing_eagerly = context.executing_eagerly()
model(x) # pylint: disable=not-callable
if not executing_eagerly:
session.run([v.initializer for v in model.variables])
model.save_weights(prefix, save_format='tensorflow')
model.save_weights(prefix, save_format='tensorflow', overwrite=True)
with self.assertRaises(EOFError):
# Indirectly tests that the user is prompted
model.save_weights(prefix, save_format='tensorflow', overwrite=False)
def test_no_graph_pollution(self):
with context.graph_mode():
graph = ops.Graph()
with graph.as_default(), self.test_session(graph) as session:
model = SubclassedModel()
temp_dir = self.get_temp_dir()
prefix = os.path.join(temp_dir, 'ckpt')
x = constant_op.constant(np.random.random((3, 2)), dtype=dtypes.float32)
model(x) # pylint: disable=not-callable
session.run([v.initializer for v in model.variables])
model.save_weights(prefix, save_format='tensorflow')
op_count = len(graph.get_operations())
model.save_weights(prefix, save_format='tensorflow')
self.assertEqual(len(graph.get_operations()), op_count)
model.load_weights(prefix)
op_count = len(graph.get_operations())
model.load_weights(prefix)
self.assertEqual(len(graph.get_operations()), op_count)
def _weight_loading_test_template(self, make_model_fn):
with self.test_session() as session:
model = make_model_fn()
temp_dir = self.get_temp_dir()
prefix = os.path.join(temp_dir, 'ckpt')
x = constant_op.constant(np.random.random((3, 2)), dtype=dtypes.float32)
executing_eagerly = context.executing_eagerly()
ref_y_tensor = model(x)
if not executing_eagerly:
session.run([v.initializer for v in model.variables])
ref_y = self.evaluate(ref_y_tensor)
model.save_weights(prefix, save_format='tf')
for v in model.variables:
self.evaluate(
v.assign(random_ops.random_normal(shape=array_ops.shape(v))))
self.addCleanup(shutil.rmtree, temp_dir)
model.load_weights(prefix)
y = self.evaluate(model(x))
self.assertAllClose(ref_y, y)
# Test restore-on-create if this is a subclassed Model (graph Networks
# will have already created their variables).
load_model = make_model_fn()
load_model.load_weights(prefix)
restore_on_create_y_tensor = load_model(x)
restore_on_create_y = self.evaluate(restore_on_create_y_tensor)
self.assertAllClose(ref_y, restore_on_create_y)
@test_util.run_in_graph_and_eager_modes()
def test_weight_loading_graph_model(self):
def _make_graph_model():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3)(a)
b = keras.layers.Dense(1)(x)
return keras.models.Model(a, b)
self._weight_loading_test_template(_make_graph_model)
@test_util.run_in_graph_and_eager_modes()
def test_weight_loading_subclassed_model(self):
self._weight_loading_test_template(SubclassedModel)
def _new_layer_weight_loading_test_template(
self, first_model_fn, second_model_fn, restore_init_fn):
with self.test_session() as session:
model = first_model_fn()
temp_dir = self.get_temp_dir()
prefix = os.path.join(temp_dir, 'ckpt')
x = constant_op.constant(np.random.random((3, 2)), dtype=dtypes.float32)
executing_eagerly = context.executing_eagerly()
ref_y_tensor = model(x)
if not executing_eagerly:
session.run([v.initializer for v in model.variables])
ref_y = self.evaluate(ref_y_tensor)
model.save_weights(prefix)
for v in model.variables:
self.evaluate(
v.assign(random_ops.random_normal(shape=array_ops.shape(v))))
self.addCleanup(shutil.rmtree, temp_dir)
second_model = second_model_fn()
second_model.load_weights(prefix)
second_model(x)
self.evaluate(restore_init_fn(second_model))
second_model.save_weights(prefix)
# Check that the second model's checkpoint loads into the original model
model.load_weights(prefix)
y = self.evaluate(model(x))
self.assertAllClose(ref_y, y)
@test_util.run_in_graph_and_eager_modes()
def test_weight_loading_graph_model_added_layer(self):
def _save_graph_model():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3, name='first')(a)
b = keras.layers.Dense(1, name='second')(x)
return keras.models.Model(a, b)
def _restore_graph_model():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3, name='first')(a)
y = keras.layers.Dense(1, name='second')(x)
b = keras.layers.Dense(3, name='secondjr')(y)
return keras.models.Model(a, b)
def _restore_init_fn(restore_model):
return [v.initializer for v in restore_model.layers[-1].variables]
self._new_layer_weight_loading_test_template(
_save_graph_model, _restore_graph_model,
_restore_init_fn)
@test_util.run_in_graph_and_eager_modes()
def test_weight_loading_graph_model_added_no_weight_layer(self):
def _save_graph_model():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3, name='first')(a)
b = keras.layers.Dense(1, name='second')(x)
return keras.models.Model(a, b)
def _restore_graph_model():
a = keras.layers.Input(shape=(2,))
x = keras.layers.Dense(3, name='first')(a)
y = keras.layers.Dropout(rate=0.1)(x)
b = keras.layers.Dense(1, name='second')(y)
return keras.models.Model(a, b)
def _restore_init_fn(restore_model):
del restore_model # unused
return []
self._new_layer_weight_loading_test_template(
_save_graph_model, _restore_graph_model,
_restore_init_fn)
@test_util.run_in_graph_and_eager_modes()
def test_weight_loading_subclassed_model_added_layer(self):
class SubclassedModelRestore(training.Model):
def __init__(self):
super(SubclassedModelRestore, self).__init__()
self.x_layer = keras.layers.Dense(3)
self.y_layer = keras.layers.Dense(3)
self.b_layer = keras.layers.Dense(1)
def call(self, a):
return self.b_layer(self.y_layer(self.x_layer(a)))
def _restore_init_fn(restore_model):
return [v.initializer for v in restore_model.y_layer.variables]
self._new_layer_weight_loading_test_template(
SubclassedModel, SubclassedModelRestore,
_restore_init_fn)
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
12,
5695,
5769,
199,
624,
2925,
367,
1402,
13369,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
492,
6093,
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,
7588,
492,
6093,
465,
6093,
63,
578,
199,
199,
893,
26,
523,
492,
394,
21,
647,
221,
327,
4287,
26,
5993,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
2590,
3545,
26,
523,
394,
21,
647,
275,
488,
421,
199,
533,
1379,
16359,
30125,
3325,
19236,
8,
396,
14,
1746,
12,
29526,
14,
1746,
304,
819,
347,
511,
63,
3463,
63,
8786,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
282,
275,
11708,
14,
4359,
14,
3205,
8,
1392,
2687,
18,
4641,
489,
671,
275,
11708,
14,
4359,
14,
15327,
8,
19,
5130,
65,
9,
489,
330,
275,
11708,
14,
4359,
14,
15327,
8,
17,
5130,
88,
9,
489,
1402,
275,
11708,
14,
992,
14,
1685,
8,
65,
12,
330,
9,
2541,
671,
275,
980,
14,
2355,
14,
2355,
1332,
19,
12,
499,
430,
489,
2984,
63,
89,
275,
1402,
14,
6892,
8,
88,
9,
489,
4931,
275,
1402,
14,
362,
63,
4916,
342,
489,
1402,
14,
409,
63,
4916,
8,
4916,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
543,
291,
14,
1855,
8,
3393,
304,
267,
1402,
14,
409,
63,
4916,
8,
4916,
59,
17,
5728,
489,
543,
291,
14,
1855,
8,
3393,
304,
267,
1402,
14,
409,
63,
4916,
8,
4916,
14172,
17,
566,
2541,
2388,
63,
694,
275,
291,
14,
362,
63,
808,
63,
694,
342,
489,
291,
14,
12808,
8,
20938,
14,
9242,
12,
2388,
63,
694,
9,
2541,
949,
63,
3435,
63,
515,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
396,
358,
489,
1402,
14,
2117,
63,
4916,
8,
889,
63,
3435,
63,
515,
12,
3354,
63,
908,
534,
3249,
358,
489,
1402,
14,
912,
63,
4916,
8,
889,
63,
3435,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
340,
394,
21,
647,
365,
488,
26,
267,
372,
221,
327,
8232,
4618,
402,
511,
340,
869,
21,
647,
5712,
1133,
2808,
14,
2541,
394,
21,
63,
515,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
396,
14,
72,
21,
358,
489,
1402,
14,
2117,
63,
4916,
8,
72,
21,
63,
515,
9,
489,
1402,
14,
912,
63,
4916,
8,
72,
21,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
1402,
14,
912,
63,
4916,
8,
72,
21,
63,
515,
12,
701,
63,
354,
29,
549,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
1402,
14,
2117,
63,
4916,
8,
889,
63,
3435,
63,
515,
12,
3354,
63,
908,
534,
19912,
21,
358,
489,
1402,
14,
912,
63,
4916,
8,
889,
63,
3435,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
819,
347,
511,
63,
3463,
63,
21402,
8,
277,
304,
272,
1324,
63,
3572,
275,
650,
272,
1072,
63,
3572,
275,
650,
272,
1568,
275,
499,
272,
5560,
275,
359,
267,
359,
288,
334,
8811,
14,
4359,
14,
17975,
21360,
8,
8811,
14,
4359,
14,
3184,
24124,
8,
18,
11508,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
18,
12,
413,
1826,
980,
14,
2355,
14,
2355,
1332,
18,
12,
413,
25106,
288,
334,
403,
12,
650,
12,
499,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
1366,
27398,
8,
8811,
14,
4359,
14,
15327,
8,
17,
11508,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
18,
12,
413,
1826,
980,
14,
2355,
14,
2355,
1332,
17,
4641,
467,
288,
334,
403,
12,
650,
12,
499,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
11596,
17,
36,
8,
1199,
63,
3572,
12,
1568,
12,
675,
63,
8160,
29,
797,
1826,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
1199,
63,
3572,
12,
1324,
63,
3572,
12,
1568,
12,
413,
25106,
288,
334,
403,
12,
841,
12,
1324,
63,
3572,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
11596,
18,
36,
8,
1199,
63,
3572,
12,
1568,
12,
639,
675
] |
[
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,
12,
5695,
5769,
199,
624,
2925,
367,
1402,
13369,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
492,
6093,
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,
7588,
492,
6093,
465,
6093,
63,
578,
199,
199,
893,
26,
523,
492,
394,
21,
647,
221,
327,
4287,
26,
5993,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
2590,
3545,
26,
523,
394,
21,
647,
275,
488,
421,
199,
533,
1379,
16359,
30125,
3325,
19236,
8,
396,
14,
1746,
12,
29526,
14,
1746,
304,
819,
347,
511,
63,
3463,
63,
8786,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
282,
275,
11708,
14,
4359,
14,
3205,
8,
1392,
2687,
18,
4641,
489,
671,
275,
11708,
14,
4359,
14,
15327,
8,
19,
5130,
65,
9,
489,
330,
275,
11708,
14,
4359,
14,
15327,
8,
17,
5130,
88,
9,
489,
1402,
275,
11708,
14,
992,
14,
1685,
8,
65,
12,
330,
9,
2541,
671,
275,
980,
14,
2355,
14,
2355,
1332,
19,
12,
499,
430,
489,
2984,
63,
89,
275,
1402,
14,
6892,
8,
88,
9,
489,
4931,
275,
1402,
14,
362,
63,
4916,
342,
489,
1402,
14,
409,
63,
4916,
8,
4916,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
543,
291,
14,
1855,
8,
3393,
304,
267,
1402,
14,
409,
63,
4916,
8,
4916,
59,
17,
5728,
489,
543,
291,
14,
1855,
8,
3393,
304,
267,
1402,
14,
409,
63,
4916,
8,
4916,
14172,
17,
566,
2541,
2388,
63,
694,
275,
291,
14,
362,
63,
808,
63,
694,
342,
489,
291,
14,
12808,
8,
20938,
14,
9242,
12,
2388,
63,
694,
9,
2541,
949,
63,
3435,
63,
515,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
396,
358,
489,
1402,
14,
2117,
63,
4916,
8,
889,
63,
3435,
63,
515,
12,
3354,
63,
908,
534,
3249,
358,
489,
1402,
14,
912,
63,
4916,
8,
889,
63,
3435,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
340,
394,
21,
647,
365,
488,
26,
267,
372,
221,
327,
8232,
4618,
402,
511,
340,
869,
21,
647,
5712,
1133,
2808,
14,
2541,
394,
21,
63,
515,
275,
747,
14,
515,
14,
904,
8,
808,
63,
694,
12,
283,
396,
14,
72,
21,
358,
489,
1402,
14,
2117,
63,
4916,
8,
72,
21,
63,
515,
9,
489,
1402,
14,
912,
63,
4916,
8,
72,
21,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
1402,
14,
912,
63,
4916,
8,
72,
21,
63,
515,
12,
701,
63,
354,
29,
549,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
2541,
1402,
14,
2117,
63,
4916,
8,
889,
63,
3435,
63,
515,
12,
3354,
63,
908,
534,
19912,
21,
358,
489,
1402,
14,
912,
63,
4916,
8,
889,
63,
3435,
63,
515,
9,
489,
612,
275,
1402,
14,
6892,
8,
88,
9,
489,
291,
14,
7260,
8,
1121,
63,
89,
12,
612,
9,
819,
347,
511,
63,
3463,
63,
21402,
8,
277,
304,
272,
1324,
63,
3572,
275,
650,
272,
1072,
63,
3572,
275,
650,
272,
1568,
275,
499,
272,
5560,
275,
359,
267,
359,
288,
334,
8811,
14,
4359,
14,
17975,
21360,
8,
8811,
14,
4359,
14,
3184,
24124,
8,
18,
11508,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
18,
12,
413,
1826,
980,
14,
2355,
14,
2355,
1332,
18,
12,
413,
25106,
288,
334,
403,
12,
650,
12,
499,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
1366,
27398,
8,
8811,
14,
4359,
14,
15327,
8,
17,
11508,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
18,
12,
413,
1826,
980,
14,
2355,
14,
2355,
1332,
17,
4641,
467,
288,
334,
403,
12,
650,
12,
499,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
11596,
17,
36,
8,
1199,
63,
3572,
12,
1568,
12,
675,
63,
8160,
29,
797,
1826,
288,
359,
1590,
14,
2355,
14,
2355,
1332,
1199,
63,
3572,
12,
1324,
63,
3572,
12,
1568,
12,
413,
25106,
288,
334,
403,
12,
841,
12,
1324,
63,
3572,
395,
267,
2156,
267,
359,
288,
334,
8811,
14,
4359,
14,
11596,
18,
36,
8,
1199,
63,
3572,
12,
1568,
12,
639,
675,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mylons/kubernetes
|
cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py
|
52
|
11792
|
#!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
The main hook file is called by Juju.
"""
import contextlib
import os
import socket
import subprocess
import sys
from charmhelpers.core import hookenv, host
from charmhelpers.contrib import ssl
from kubernetes_installer import KubernetesInstaller
from path import Path
hooks = hookenv.Hooks()
@contextlib.contextmanager
def check_sentinel(filepath):
"""
A context manager method to write a file while the code block is doing
something and remove the file when done.
"""
fail = False
try:
yield filepath.exists()
except:
fail = True
filepath.touch()
raise
finally:
if fail is False and filepath.exists():
filepath.remove()
@hooks.hook('config-changed')
def config_changed():
"""
On the execution of the juju event 'config-changed' this function
determines the appropriate architecture and the configured version to
create kubernetes binary files.
"""
hookenv.log('Starting config-changed')
charm_dir = Path(hookenv.charm_dir())
config = hookenv.config()
# Get the version of kubernetes to install.
version = config['version']
username = config['username']
password = config['password']
certificate = config['apiserver-cert']
key = config['apiserver-key']
if version == 'master':
# The 'master' branch of kuberentes is used when master is configured.
branch = 'master'
elif version == 'local':
# Check for kubernetes binaries in the local files/output directory.
branch = None
else:
# Create a branch to a tag to get the release version.
branch = 'tags/{0}'.format(version)
cert_file = '/srv/kubernetes/apiserver.crt'
key_file = '/srv/kubernetes/apiserver.key'
# When the cert or key changes we need to restart the apiserver.
if config.changed('apiserver-cert') or config.changed('apiserver-key'):
hookenv.log('Certificate or key has changed.')
if not certificate or not key:
generate_cert(key=key_file, cert=cert_file)
else:
hookenv.log('Writing new certificate and key to server.')
with open(key_file, 'w') as file:
file.write(key)
with open(cert_file, 'w') as file:
file.write(certificate)
# Restart apiserver as the certificate or key has changed.
if host.service_running('apiserver'):
host.service_restart('apiserver')
# Reload nginx because it proxies https to apiserver.
if host.service_running('nginx'):
host.service_reload('nginx')
if config.changed('username') or config.changed('password'):
hookenv.log('Username or password changed, creating authentication.')
basic_auth(config['username'], config['username'], config['password'])
if host.service_running('apiserver'):
host.service_restart('apiserver')
# Get package architecture, rather than arch from the kernel (uname -m).
arch = subprocess.check_output(['dpkg', '--print-architecture']).strip()
if not branch:
output_path = charm_dir / 'files/output'
kube_installer = KubernetesInstaller(arch, version, output_path)
else:
# Build the kuberentes binaries from source on the units.
kubernetes_dir = Path('/opt/kubernetes')
# Construct the path to the binaries using the arch.
output_path = kubernetes_dir / '_output/local/bin/linux' / arch
kube_installer = KubernetesInstaller(arch, version, output_path)
if not kubernetes_dir.exists():
message = 'The kubernetes source directory {0} does not exist. ' \
'Was the kubernetes repository cloned during the install?'
print(message.format(kubernetes_dir))
exit(1)
# Change to the kubernetes directory (git repository).
with kubernetes_dir:
# Create a command to get the current branch.
git_branch = 'git branch | grep "\*" | cut -d" " -f2'
current_branch = subprocess.check_output(git_branch, shell=True)
current_branch = current_branch.strip()
print('Current branch: ', current_branch)
# Create the path to a file to indicate if the build was broken.
broken_build = charm_dir / '.broken_build'
# write out the .broken_build file while this block is executing.
with check_sentinel(broken_build) as last_build_failed:
print('Last build failed: ', last_build_failed)
# Rebuild if current version is different or last build failed.
if current_branch != version or last_build_failed:
kube_installer.build(branch)
if not output_path.isdir():
broken_build.touch()
# Create the symoblic links to the right directories.
kube_installer.install()
relation_changed()
hookenv.log('The config-changed hook completed successfully.')
@hooks.hook('etcd-relation-changed', 'minions-api-relation-changed')
def relation_changed():
template_data = get_template_data()
# Check required keys
for k in ('etcd_servers',):
if not template_data.get(k):
print 'Missing data for', k, template_data
return
print 'Running with\n', template_data
# Render and restart as needed
for n in ('apiserver', 'controller-manager', 'scheduler'):
if render_file(n, template_data) or not host.service_running(n):
host.service_restart(n)
# Render the file that makes the kubernetes binaries available to minions.
if render_file(
'distribution', template_data,
'conf.tmpl', '/etc/nginx/sites-enabled/distribution') or \
not host.service_running('nginx'):
host.service_reload('nginx')
# Render the default nginx template.
if render_file(
'nginx', template_data,
'conf.tmpl', '/etc/nginx/sites-enabled/default') or \
not host.service_running('nginx'):
host.service_reload('nginx')
# Send api endpoint to minions
notify_minions()
@hooks.hook('network-relation-changed')
def network_relation_changed():
relation_id = hookenv.relation_id()
hookenv.relation_set(relation_id, ignore_errors=True)
def notify_minions():
print('Notify minions.')
config = hookenv.config()
for r in hookenv.relation_ids('minions-api'):
hookenv.relation_set(
r,
hostname=hookenv.unit_private_ip(),
port=8080,
version=config['version'])
print('Notified minions of version ' + config['version'])
def basic_auth(name, id, pwd=None, file='/srv/kubernetes/basic-auth.csv'):
"""
Create a basic authentication file for kubernetes. The file is a csv file
with 3 columns: password, user name, user id. From the Kubernetes docs:
The basic auth credentials last indefinitely, and the password cannot be
changed without restarting apiserver.
"""
if not pwd:
import random
import string
alphanumeric = string.ascii_letters + string.digits
pwd = ''.join(random.choice(alphanumeric) for _ in range(16))
lines = []
auth_file = Path(file)
if auth_file.isfile():
lines = auth_file.lines()
for line in lines:
target = ',{0},{1}'.format(name, id)
if target in line:
lines.remove(line)
auth_line = '{0},{1},{2}'.format(pwd, name, id)
lines.append(auth_line)
auth_file.write_lines(lines)
def generate_cert(common_name=None,
key='/srv/kubernetes/apiserver.key',
cert='/srv/kubernetes/apiserver.crt'):
"""
Create the certificate and key for the Kubernetes tls enablement.
"""
hookenv.log('Generating new self signed certificate and key', 'INFO')
if not common_name:
common_name = hookenv.unit_get('public-address')
if os.path.isfile(key) or os.path.isfile(cert):
hookenv.log('Overwriting the existing certificate or key', 'WARNING')
hookenv.log('Generating certificate for {0}'.format(common_name), 'INFO')
# Generate the self signed certificate with the public address as CN.
# https://pythonhosted.org/charmhelpers/api/charmhelpers.contrib.ssl.html
ssl.generate_selfsigned(key, cert, cn=common_name)
def get_template_data():
rels = hookenv.relations()
config = hookenv.config()
version = config['version']
template_data = {}
template_data['etcd_servers'] = ','.join([
'http://%s:%s' % (s[0], s[1]) for s in sorted(
get_rel_hosts('etcd', rels, ('hostname', 'port')))])
template_data['minions'] = ','.join(get_rel_hosts('minions-api', rels))
private_ip = hookenv.unit_private_ip()
public_ip = hookenv.unit_public_ip()
template_data['api_public_address'] = _bind_addr(public_ip)
template_data['api_private_address'] = _bind_addr(private_ip)
template_data['bind_address'] = '127.0.0.1'
template_data['api_http_uri'] = 'http://%s:%s' % (private_ip, 8080)
template_data['api_https_uri'] = 'https://%s:%s' % (private_ip, 6443)
arch = subprocess.check_output(['dpkg', '--print-architecture']).strip()
template_data['web_uri'] = '/kubernetes/%s/local/bin/linux/%s/' % (version,
arch)
if version == 'local':
template_data['alias'] = hookenv.charm_dir() + '/files/output/'
else:
directory = '/opt/kubernetes/_output/local/bin/linux/%s/' % arch
template_data['alias'] = directory
_encode(template_data)
return template_data
def _bind_addr(addr):
if addr.replace('.', '').isdigit():
return addr
try:
return socket.gethostbyname(addr)
except socket.error:
raise ValueError('Could not resolve address %s' % addr)
def _encode(d):
for k, v in d.items():
if isinstance(v, unicode):
d[k] = v.encode('utf8')
def get_rel_hosts(rel_name, rels, keys=('private-address',)):
hosts = []
for r, data in rels.get(rel_name, {}).items():
for unit_id, unit_data in data.items():
if unit_id == hookenv.local_unit():
continue
values = [unit_data.get(k) for k in keys]
if not all(values):
continue
hosts.append(len(values) == 1 and values[0] or values)
return hosts
def render_file(name, data, src_suffix='upstart.tmpl', tgt_path=None):
tmpl_path = os.path.join(
os.environ.get('CHARM_DIR'), 'files', '%s.%s' % (name, src_suffix))
with open(tmpl_path) as fh:
tmpl = fh.read()
rendered = tmpl % data
if tgt_path is None:
tgt_path = '/etc/init/%s.conf' % name
if os.path.exists(tgt_path):
with open(tgt_path) as fh:
contents = fh.read()
if contents == rendered:
return False
with open(tgt_path, 'w') as fh:
fh.write(rendered)
return True
if __name__ == '__main__':
hooks.execute(sys.argv)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
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,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
1918,
2446,
5759,
570,
365,
2797,
701,
1603,
17189,
85,
14,
199,
624,
199,
646,
15502,
199,
646,
747,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
504,
1495,
77,
7546,
14,
1018,
492,
21404,
12,
1591,
199,
504,
1495,
77,
7546,
14,
2828,
492,
6149,
199,
504,
31160,
63,
17047,
492,
28723,
27598,
199,
504,
931,
492,
6912,
199,
199,
7922,
275,
21404,
14,
8481,
83,
342,
421,
199,
32,
23464,
14,
14237,
199,
318,
1104,
63,
13400,
8,
7218,
304,
272,
408,
272,
437,
1067,
5256,
1083,
370,
2218,
282,
570,
1830,
314,
1233,
1853,
365,
9689,
272,
6020,
436,
2813,
314,
570,
1380,
4224,
14,
272,
408,
272,
2449,
275,
756,
272,
862,
26,
267,
1995,
9911,
14,
2444,
342,
272,
871,
26,
267,
2449,
275,
715,
267,
9911,
14,
12376,
342,
267,
746,
272,
3753,
26,
267,
340,
2449,
365,
756,
436,
9911,
14,
2444,
837,
288,
9911,
14,
2168,
342,
421,
199,
32,
7922,
14,
3664,
360,
888,
13,
2489,
358,
199,
318,
1101,
63,
2489,
837,
272,
408,
272,
4068,
314,
6451,
402,
314,
1335,
17189,
85,
1566,
283,
888,
13,
2489,
7,
642,
805,
272,
16756,
314,
5827,
15931,
436,
314,
7526,
1015,
370,
272,
1218,
31160,
3366,
1584,
14,
272,
408,
272,
21404,
14,
793,
360,
14139,
1101,
13,
2489,
358,
272,
1495,
77,
63,
694,
275,
6912,
8,
3664,
1813,
14,
1560,
77,
63,
694,
1012,
272,
1101,
275,
21404,
14,
888,
342,
272,
327,
2372,
314,
1015,
402,
31160,
370,
3907,
14,
272,
1015,
275,
1101,
459,
1023,
418,
272,
3434,
275,
1101,
459,
2473,
418,
272,
2505,
275,
1101,
459,
2060,
418,
272,
5897,
275,
1101,
459,
1246,
1000,
13,
4736,
418,
272,
790,
275,
1101,
459,
1246,
1000,
13,
498,
418,
339,
340,
1015,
508,
283,
4133,
356,
267,
327,
710,
283,
4133,
7,
5246,
402,
23091,
828,
744,
365,
1202,
1380,
5288,
365,
7526,
14,
267,
5246,
275,
283,
4133,
7,
272,
916,
1015,
508,
283,
1832,
356,
267,
327,
2670,
367,
31160,
21984,
315,
314,
2257,
1584,
15,
1199,
2082,
14,
267,
5246,
275,
488,
272,
587,
26,
267,
327,
2790,
282,
5246,
370,
282,
1947,
370,
664,
314,
4683,
1015,
14,
267,
5246,
275,
283,
2969,
5321,
16,
5285,
908,
8,
1023,
9,
339,
6250,
63,
493,
275,
1994,
15165,
15,
17422,
15,
1246,
1000,
14,
16617,
7,
272,
790,
63,
493,
275,
1994,
15165,
15,
17422,
15,
1246,
1000,
14,
498,
7,
272,
327,
3979,
314,
6250,
503,
790,
4493,
781,
1929,
370,
11004,
314,
2986,
1000,
14,
272,
340,
1101,
14,
2489,
360,
1246,
1000,
13,
4736,
358,
503,
1101,
14,
2489,
360,
1246,
1000,
13,
498,
735,
267,
21404,
14,
793,
360,
11414,
503,
790,
965,
2896,
2659,
267,
340,
440,
5897,
503,
440,
790,
26,
288,
3550,
63,
4736,
8,
498,
29,
498,
63,
493,
12,
6250,
29,
4736,
63,
493,
9,
267,
587,
26,
288,
21404,
14,
793,
360,
16646,
892,
5897,
436,
790,
370,
1654,
2659,
288,
543,
1551,
8,
498,
63,
493,
12,
283,
87,
358,
465,
570,
26,
355,
570,
14,
952,
8,
498,
9,
288,
543,
1551,
8,
4736,
63,
493,
12,
283,
87,
358,
465,
570,
26,
355,
570,
14,
952,
8,
6999,
9,
267,
327,
799,
928,
2986,
1000,
465,
314,
5897,
503,
790,
965,
2896,
14,
267,
340,
1591,
14,
1364,
63,
5720,
360,
1246,
1000,
735,
288,
1591,
14,
1364,
63,
10506,
360,
1246,
1000,
358,
267,
327,
799,
912,
302,
19101,
2952,
652,
14942,
4178,
370,
2986,
1000,
14,
267,
340,
1591,
14,
1364,
63,
5720,
360,
25826,
735,
288,
1591,
14,
1364,
63,
9233,
360,
25826,
358,
339,
340,
1101,
14,
2489,
360,
2473,
358,
503,
1101,
14,
2489,
360,
2060,
735,
267,
21404,
14,
793,
360,
13355,
503,
2505,
2896,
12,
6425,
6299,
2659,
267,
5678,
63,
1178,
8,
888,
459,
2473,
995,
1101,
459,
2473,
995,
1101,
459,
2060,
1105,
267,
340,
1591,
14,
1364,
63,
5720,
360,
1246,
1000,
735,
288,
1591,
14,
1364,
63,
10506,
360,
1246,
1000,
358,
339,
327,
2372,
2559,
15931,
12,
7830,
2419,
3819,
687,
314,
5114,
334,
16040,
446,
77,
680,
272,
3819,
275,
3873,
14,
1074,
63,
1199,
2941,
68,
4600,
297,
2850,
1361,
13,
19134,
13227,
1913,
342,
339,
340,
440,
5246,
26,
267,
1072,
63,
515,
275,
1495,
77,
63,
694,
1182,
283,
1725,
15,
1199,
7,
267,
23091,
63,
17047,
275,
28723,
27598,
8,
1047,
12,
1015,
12,
1072,
63,
515,
9,
272,
587,
26,
398,
327,
6516,
314,
23091,
828,
744,
21984,
687,
1350,
641,
314,
6204,
14,
267,
31160,
63,
694,
275,
6912,
2336,
2992,
15,
17422,
358,
398,
327,
9215,
314,
931,
370,
314,
21984,
1808,
314,
3819,
14,
267,
1072,
63,
515,
275,
31160,
63,
694,
1182,
2513,
1199,
15,
1832,
15,
1393,
15,
5135,
7,
1182,
3819,
267,
23091,
63,
17047,
275,
28723,
27598,
8,
1047,
12,
1015,
12,
1072,
63,
515,
9,
398,
340,
440,
31160,
63,
694,
14,
2444,
837,
288,
1245,
275,
283,
1918,
31160,
1350,
2082,
469,
16,
93,
1630,
440,
2187,
14,
283,
971,
355,
283,
55,
305,
314,
31160,
7611,
26210,
5309,
314,
3907,
14069,
288,
870,
8,
1188,
14,
908,
8,
17422,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
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,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
1918,
2446,
5759,
570,
365,
2797,
701,
1603,
17189,
85,
14,
199,
624,
199,
646,
15502,
199,
646,
747,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
504,
1495,
77,
7546,
14,
1018,
492,
21404,
12,
1591,
199,
504,
1495,
77,
7546,
14,
2828,
492,
6149,
199,
504,
31160,
63,
17047,
492,
28723,
27598,
199,
504,
931,
492,
6912,
199,
199,
7922,
275,
21404,
14,
8481,
83,
342,
421,
199,
32,
23464,
14,
14237,
199,
318,
1104,
63,
13400,
8,
7218,
304,
272,
408,
272,
437,
1067,
5256,
1083,
370,
2218,
282,
570,
1830,
314,
1233,
1853,
365,
9689,
272,
6020,
436,
2813,
314,
570,
1380,
4224,
14,
272,
408,
272,
2449,
275,
756,
272,
862,
26,
267,
1995,
9911,
14,
2444,
342,
272,
871,
26,
267,
2449,
275,
715,
267,
9911,
14,
12376,
342,
267,
746,
272,
3753,
26,
267,
340,
2449,
365,
756,
436,
9911,
14,
2444,
837,
288,
9911,
14,
2168,
342,
421,
199,
32,
7922,
14,
3664,
360,
888,
13,
2489,
358,
199,
318,
1101,
63,
2489,
837,
272,
408,
272,
4068,
314,
6451,
402,
314,
1335,
17189,
85,
1566,
283,
888,
13,
2489,
7,
642,
805,
272,
16756,
314,
5827,
15931,
436,
314,
7526,
1015,
370,
272,
1218,
31160,
3366,
1584,
14,
272,
408,
272,
21404,
14,
793,
360,
14139,
1101,
13,
2489,
358,
272,
1495,
77,
63,
694,
275,
6912,
8,
3664,
1813,
14,
1560,
77,
63,
694,
1012,
272,
1101,
275,
21404,
14,
888,
342,
272,
327,
2372,
314,
1015,
402,
31160,
370,
3907,
14,
272,
1015,
275,
1101,
459,
1023,
418,
272,
3434,
275,
1101,
459,
2473,
418,
272,
2505,
275,
1101,
459,
2060,
418,
272,
5897,
275,
1101,
459,
1246,
1000,
13,
4736,
418,
272,
790,
275,
1101,
459,
1246,
1000,
13,
498,
418,
339,
340,
1015,
508,
283,
4133,
356,
267,
327,
710,
283,
4133,
7,
5246,
402,
23091,
828,
744,
365,
1202,
1380,
5288,
365,
7526,
14,
267,
5246,
275,
283,
4133,
7,
272,
916,
1015,
508,
283,
1832,
356,
267,
327,
2670,
367,
31160,
21984,
315,
314,
2257,
1584,
15,
1199,
2082,
14,
267,
5246,
275,
488,
272,
587,
26,
267,
327,
2790,
282,
5246,
370,
282,
1947,
370,
664,
314,
4683,
1015,
14,
267,
5246,
275,
283,
2969,
5321,
16,
5285,
908,
8,
1023,
9,
339,
6250,
63,
493,
275,
1994,
15165,
15,
17422,
15,
1246,
1000,
14,
16617,
7,
272,
790,
63,
493,
275,
1994,
15165,
15,
17422,
15,
1246,
1000,
14,
498,
7,
272,
327,
3979,
314,
6250,
503,
790,
4493,
781,
1929,
370,
11004,
314,
2986,
1000,
14,
272,
340,
1101,
14,
2489,
360,
1246,
1000,
13,
4736,
358,
503,
1101,
14,
2489,
360,
1246,
1000,
13,
498,
735,
267,
21404,
14,
793,
360,
11414,
503,
790,
965,
2896,
2659,
267,
340,
440,
5897,
503,
440,
790,
26,
288,
3550,
63,
4736,
8,
498,
29,
498,
63,
493,
12,
6250,
29,
4736,
63,
493,
9,
267,
587,
26,
288,
21404,
14,
793,
360,
16646,
892,
5897,
436,
790,
370,
1654,
2659,
288,
543,
1551,
8,
498,
63,
493,
12,
283,
87,
358,
465,
570,
26,
355,
570,
14,
952,
8,
498,
9,
288,
543,
1551,
8,
4736,
63,
493,
12,
283,
87,
358,
465,
570,
26,
355,
570,
14,
952,
8,
6999,
9,
267,
327,
799,
928,
2986,
1000,
465,
314,
5897,
503,
790,
965,
2896,
14,
267,
340,
1591,
14,
1364,
63,
5720,
360,
1246,
1000,
735,
288,
1591,
14,
1364,
63,
10506,
360,
1246,
1000,
358,
267,
327,
799,
912,
302,
19101,
2952,
652,
14942,
4178,
370,
2986,
1000,
14,
267,
340,
1591,
14,
1364,
63,
5720,
360,
25826,
735,
288,
1591,
14,
1364,
63,
9233,
360,
25826,
358,
339,
340,
1101,
14,
2489,
360,
2473,
358,
503,
1101,
14,
2489,
360,
2060,
735,
267,
21404,
14,
793,
360,
13355,
503,
2505,
2896,
12,
6425,
6299,
2659,
267,
5678,
63,
1178,
8,
888,
459,
2473,
995,
1101,
459,
2473,
995,
1101,
459,
2060,
1105,
267,
340,
1591,
14,
1364,
63,
5720,
360,
1246,
1000,
735,
288,
1591,
14,
1364,
63,
10506,
360,
1246,
1000,
358,
339,
327,
2372,
2559,
15931,
12,
7830,
2419,
3819,
687,
314,
5114,
334,
16040,
446,
77,
680,
272,
3819,
275,
3873,
14,
1074,
63,
1199,
2941,
68,
4600,
297,
2850,
1361,
13,
19134,
13227,
1913,
342,
339,
340,
440,
5246,
26,
267,
1072,
63,
515,
275,
1495,
77,
63,
694,
1182,
283,
1725,
15,
1199,
7,
267,
23091,
63,
17047,
275,
28723,
27598,
8,
1047,
12,
1015,
12,
1072,
63,
515,
9,
272,
587,
26,
398,
327,
6516,
314,
23091,
828,
744,
21984,
687,
1350,
641,
314,
6204,
14,
267,
31160,
63,
694,
275,
6912,
2336,
2992,
15,
17422,
358,
398,
327,
9215,
314,
931,
370,
314,
21984,
1808,
314,
3819,
14,
267,
1072,
63,
515,
275,
31160,
63,
694,
1182,
2513,
1199,
15,
1832,
15,
1393,
15,
5135,
7,
1182,
3819,
267,
23091,
63,
17047,
275,
28723,
27598,
8,
1047,
12,
1015,
12,
1072,
63,
515,
9,
398,
340,
440,
31160,
63,
694,
14,
2444,
837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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
MrKepzie/google-test
|
test/gtest_break_on_failure_unittest.py
|
2140
|
7339
|
#!/usr/bin/env python
#
# Copyright 2006, 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.
"""Unit test for Google Test's break-on-failure mode.
A user can ask Google Test to seg-fault when an assertion fails, using
either the GTEST_BREAK_ON_FAILURE environment variable or the
--gtest_break_on_failure flag. This script tests such functionality
by invoking gtest_break_on_failure_unittest_ (a program written with
Google Test) with different environments and command line flags.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import gtest_test_utils
import os
import sys
# Constants.
IS_WINDOWS = os.name == 'nt'
# The environment variable for enabling/disabling the break-on-failure mode.
BREAK_ON_FAILURE_ENV_VAR = 'GTEST_BREAK_ON_FAILURE'
# The command line flag for enabling/disabling the break-on-failure mode.
BREAK_ON_FAILURE_FLAG = 'gtest_break_on_failure'
# The environment variable for enabling/disabling the throw-on-failure mode.
THROW_ON_FAILURE_ENV_VAR = 'GTEST_THROW_ON_FAILURE'
# The environment variable for enabling/disabling the catch-exceptions mode.
CATCH_EXCEPTIONS_ENV_VAR = 'GTEST_CATCH_EXCEPTIONS'
# Path to the gtest_break_on_failure_unittest_ program.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
'gtest_break_on_failure_unittest_')
environ = gtest_test_utils.environ
SetEnvVar = gtest_test_utils.SetEnvVar
# Tests in this file run a Google-Test-based test program and expect it
# to terminate prematurely. Therefore they are incompatible with
# the premature-exit-file protocol by design. Unset the
# premature-exit filepath to prevent Google Test from creating
# the file.
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
def Run(command):
"""Runs a command; returns 1 if it was killed by a signal, or 0 otherwise."""
p = gtest_test_utils.Subprocess(command, env=environ)
if p.terminated_by_signal:
return 1
else:
return 0
# The tests.
class GTestBreakOnFailureUnitTest(gtest_test_utils.TestCase):
"""Tests using the GTEST_BREAK_ON_FAILURE environment variable or
the --gtest_break_on_failure flag to turn assertion failures into
segmentation faults.
"""
def RunAndVerify(self, env_var_value, flag_value, expect_seg_fault):
"""Runs gtest_break_on_failure_unittest_ and verifies that it does
(or does not) have a seg-fault.
Args:
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
variable; None if the variable should be unset.
flag_value: value of the --gtest_break_on_failure flag;
None if the flag should not be present.
expect_seg_fault: 1 if the program is expected to generate a seg-fault;
0 otherwise.
"""
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, env_var_value)
if env_var_value is None:
env_var_value_msg = ' is not set'
else:
env_var_value_msg = '=' + env_var_value
if flag_value is None:
flag = ''
elif flag_value == '0':
flag = '--%s=0' % BREAK_ON_FAILURE_FLAG
else:
flag = '--%s' % BREAK_ON_FAILURE_FLAG
command = [EXE_PATH]
if flag:
command.append(flag)
if expect_seg_fault:
should_or_not = 'should'
else:
should_or_not = 'should not'
has_seg_fault = Run(command)
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, None)
msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' %
(BREAK_ON_FAILURE_ENV_VAR, env_var_value_msg, ' '.join(command),
should_or_not))
self.assert_(has_seg_fault == expect_seg_fault, msg)
def testDefaultBehavior(self):
"""Tests the behavior of the default mode."""
self.RunAndVerify(env_var_value=None,
flag_value=None,
expect_seg_fault=0)
def testEnvVar(self):
"""Tests using the GTEST_BREAK_ON_FAILURE environment variable."""
self.RunAndVerify(env_var_value='0',
flag_value=None,
expect_seg_fault=0)
self.RunAndVerify(env_var_value='1',
flag_value=None,
expect_seg_fault=1)
def testFlag(self):
"""Tests using the --gtest_break_on_failure flag."""
self.RunAndVerify(env_var_value=None,
flag_value='0',
expect_seg_fault=0)
self.RunAndVerify(env_var_value=None,
flag_value='1',
expect_seg_fault=1)
def testFlagOverridesEnvVar(self):
"""Tests that the flag overrides the environment variable."""
self.RunAndVerify(env_var_value='0',
flag_value='0',
expect_seg_fault=0)
self.RunAndVerify(env_var_value='0',
flag_value='1',
expect_seg_fault=1)
self.RunAndVerify(env_var_value='1',
flag_value='0',
expect_seg_fault=0)
self.RunAndVerify(env_var_value='1',
flag_value='1',
expect_seg_fault=1)
def testBreakOnFailureOverridesThrowOnFailure(self):
"""Tests that gtest_break_on_failure overrides gtest_throw_on_failure."""
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, '1')
try:
self.RunAndVerify(env_var_value=None,
flag_value='1',
expect_seg_fault=1)
finally:
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, None)
if IS_WINDOWS:
def testCatchExceptionsDoesNotInterfere(self):
"""Tests that gtest_catch_exceptions doesn't interfere."""
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, '1')
try:
self.RunAndVerify(env_var_value='1',
flag_value='1',
expect_seg_fault=1)
finally:
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, None)
if __name__ == '__main__':
gtest_test_utils.Main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
5072,
511,
367,
4475,
1379,
1159,
2059,
13,
265,
13,
5328,
818,
14,
199,
199,
33,
922,
883,
7198,
4475,
1379,
370,
8812,
13,
1879,
1380,
376,
14412,
6918,
12,
1808,
199,
22051,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
1750,
503,
314,
199,
306,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
14,
221,
961,
2884,
2295,
4066,
9330,
199,
991,
26750,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
334,
65,
2240,
5313,
543,
199,
13266,
1379,
9,
543,
3365,
22196,
436,
1414,
1004,
3285,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
646,
747,
199,
646,
984,
421,
199,
3,
22296,
14,
199,
199,
1311,
63,
20509,
275,
747,
14,
354,
508,
283,
343,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
2059,
13,
265,
13,
5328,
818,
14,
199,
14731,
63,
615,
63,
13989,
63,
9984,
63,
5568,
275,
283,
16151,
63,
14731,
63,
615,
63,
13989,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
29310,
15,
2297,
14744,
314,
2059,
13,
265,
13,
5328,
818,
14,
199,
14731,
63,
615,
63,
13989,
63,
3719,
275,
283,
8385,
63,
4785,
63,
265,
63,
5328,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
7978,
13,
265,
13,
5328,
818,
14,
199,
2080,
11415,
63,
615,
63,
13989,
63,
9984,
63,
5568,
275,
283,
16151,
63,
2080,
11415,
63,
615,
63,
13989,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
8579,
13,
3924,
818,
14,
199,
35,
8078,
63,
25054,
63,
9984,
63,
5568,
275,
283,
16151,
63,
35,
8078,
63,
25054,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
2240,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
4785,
63,
265,
63,
5328,
63,
2796,
15452,
421,
199,
2314,
275,
9088,
63,
396,
63,
1208,
14,
2314,
199,
1084,
19342,
275,
9088,
63,
396,
63,
1208,
14,
1084,
19342,
199,
199,
3,
6496,
315,
642,
570,
1255,
282,
4475,
13,
774,
13,
6788,
511,
2240,
436,
4282,
652,
199,
3,
370,
15095,
876,
19925,
590,
14,
221,
21039,
2985,
787,
18457,
543,
199,
3,
314,
876,
19925,
13,
2224,
13,
493,
4113,
701,
12899,
14,
221,
1910,
409,
314,
199,
3,
876,
19925,
13,
2224,
9911,
370,
7981,
4475,
1379,
687,
6425,
199,
3,
314,
570,
14,
199,
1084,
19342,
8,
8385,
63,
396,
63,
1208,
14,
4225,
45,
13214,
63,
17219,
63,
3817,
63,
9984,
63,
5568,
12,
488,
9,
421,
199,
318,
3378,
8,
1531,
304,
523,
408,
16291,
282,
1414,
27,
2529,
413,
340,
652,
1990,
26659,
701,
282,
4673,
12,
503,
378,
4257,
1041,
819,
299,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
1531,
12,
2589,
29,
2314,
9,
523,
340,
299,
14,
18375,
63,
991,
63,
4653,
26,
272,
372,
413,
523,
587,
26,
272,
372,
378,
421,
199,
3,
710,
2295,
14,
421,
199,
533,
598,
774,
13948,
3314,
6782,
29037,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
408,
2925,
1808,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
1750,
503,
523,
314,
1553,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
370,
7485,
14412,
9081,
1901,
523,
27315,
16898,
83,
14,
523,
408,
819,
347,
3378,
14222,
8,
277,
12,
2589,
63,
1391,
63,
585,
12,
3305,
63,
585,
12,
4282,
63,
8359,
63,
1879,
304,
272,
408,
16291,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
436,
22694,
626,
652,
1630,
272,
334,
269,
1630,
440,
9,
1172,
282,
8812,
13,
1879,
14,
339,
3033,
26,
489,
2589,
63,
1391,
63,
585,
26,
259,
574,
402,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
717,
1750,
27,
488,
340,
314,
1750,
1077,
506,
15376,
14,
489,
3305,
63,
585,
26,
755,
574,
402,
314,
1553,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
27,
717,
488,
340,
314
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
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,
5072,
511,
367,
4475,
1379,
1159,
2059,
13,
265,
13,
5328,
818,
14,
199,
199,
33,
922,
883,
7198,
4475,
1379,
370,
8812,
13,
1879,
1380,
376,
14412,
6918,
12,
1808,
199,
22051,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
1750,
503,
314,
199,
306,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
14,
221,
961,
2884,
2295,
4066,
9330,
199,
991,
26750,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
334,
65,
2240,
5313,
543,
199,
13266,
1379,
9,
543,
3365,
22196,
436,
1414,
1004,
3285,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
646,
747,
199,
646,
984,
421,
199,
3,
22296,
14,
199,
199,
1311,
63,
20509,
275,
747,
14,
354,
508,
283,
343,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
2059,
13,
265,
13,
5328,
818,
14,
199,
14731,
63,
615,
63,
13989,
63,
9984,
63,
5568,
275,
283,
16151,
63,
14731,
63,
615,
63,
13989,
7,
199,
199,
3,
710,
1414,
1004,
3305,
367,
29310,
15,
2297,
14744,
314,
2059,
13,
265,
13,
5328,
818,
14,
199,
14731,
63,
615,
63,
13989,
63,
3719,
275,
283,
8385,
63,
4785,
63,
265,
63,
5328,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
7978,
13,
265,
13,
5328,
818,
14,
199,
2080,
11415,
63,
615,
63,
13989,
63,
9984,
63,
5568,
275,
283,
16151,
63,
2080,
11415,
63,
615,
63,
13989,
7,
199,
199,
3,
710,
3734,
1750,
367,
29310,
15,
2297,
14744,
314,
8579,
13,
3924,
818,
14,
199,
35,
8078,
63,
25054,
63,
9984,
63,
5568,
275,
283,
16151,
63,
35,
8078,
63,
25054,
7,
199,
199,
3,
6912,
370,
314,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
2240,
14,
199,
23017,
63,
3243,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
8,
272,
283,
8385,
63,
4785,
63,
265,
63,
5328,
63,
2796,
15452,
421,
199,
2314,
275,
9088,
63,
396,
63,
1208,
14,
2314,
199,
1084,
19342,
275,
9088,
63,
396,
63,
1208,
14,
1084,
19342,
199,
199,
3,
6496,
315,
642,
570,
1255,
282,
4475,
13,
774,
13,
6788,
511,
2240,
436,
4282,
652,
199,
3,
370,
15095,
876,
19925,
590,
14,
221,
21039,
2985,
787,
18457,
543,
199,
3,
314,
876,
19925,
13,
2224,
13,
493,
4113,
701,
12899,
14,
221,
1910,
409,
314,
199,
3,
876,
19925,
13,
2224,
9911,
370,
7981,
4475,
1379,
687,
6425,
199,
3,
314,
570,
14,
199,
1084,
19342,
8,
8385,
63,
396,
63,
1208,
14,
4225,
45,
13214,
63,
17219,
63,
3817,
63,
9984,
63,
5568,
12,
488,
9,
421,
199,
318,
3378,
8,
1531,
304,
523,
408,
16291,
282,
1414,
27,
2529,
413,
340,
652,
1990,
26659,
701,
282,
4673,
12,
503,
378,
4257,
1041,
819,
299,
275,
9088,
63,
396,
63,
1208,
14,
22299,
8,
1531,
12,
2589,
29,
2314,
9,
523,
340,
299,
14,
18375,
63,
991,
63,
4653,
26,
272,
372,
413,
523,
587,
26,
272,
372,
378,
421,
199,
3,
710,
2295,
14,
421,
199,
533,
598,
774,
13948,
3314,
6782,
29037,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
408,
2925,
1808,
314,
18652,
63,
14731,
63,
615,
63,
13989,
3734,
1750,
503,
523,
314,
1553,
8385,
63,
4785,
63,
265,
63,
5328,
3305,
370,
7485,
14412,
9081,
1901,
523,
27315,
16898,
83,
14,
523,
408,
819,
347,
3378,
14222,
8,
277,
12,
2589,
63,
1391,
63,
585,
12,
3305,
63,
585,
12,
4282,
63,
8359,
63,
1879,
304,
272,
408,
16291,
9088,
63,
4785,
63,
265,
63,
5328,
63,
2796,
63,
436,
22694,
626,
652,
1630,
272,
334,
269,
1630,
440,
9,
1172,
282,
8812,
13,
1879,
14,
339,
3033,
26,
489,
2589,
63,
1391,
63,
585,
26,
259,
574,
402,
314,
18652,
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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
] |
quheng/scikit-learn
|
sklearn/preprocessing/tests/test_label.py
|
156
|
17626
|
import numpy as np
from scipy.sparse import issparse
from scipy.sparse import coo_matrix
from scipy.sparse import csc_matrix
from scipy.sparse import csr_matrix
from scipy.sparse import dok_matrix
from scipy.sparse import lil_matrix
from sklearn.utils.multiclass import type_of_target
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import ignore_warnings
from sklearn.preprocessing.label import LabelBinarizer
from sklearn.preprocessing.label import MultiLabelBinarizer
from sklearn.preprocessing.label import LabelEncoder
from sklearn.preprocessing.label import label_binarize
from sklearn.preprocessing.label import _inverse_binarize_thresholding
from sklearn.preprocessing.label import _inverse_binarize_multiclass
from sklearn import datasets
iris = datasets.load_iris()
def toarray(a):
if hasattr(a, "toarray"):
a = a.toarray()
return a
def test_label_binarizer():
lb = LabelBinarizer()
# one-class case defaults to negative label
inp = ["pos", "pos", "pos", "pos"]
expected = np.array([[0, 0, 0, 0]]).T
got = lb.fit_transform(inp)
assert_array_equal(lb.classes_, ["pos"])
assert_array_equal(expected, got)
assert_array_equal(lb.inverse_transform(got), inp)
# two-class case
inp = ["neg", "pos", "pos", "neg"]
expected = np.array([[0, 1, 1, 0]]).T
got = lb.fit_transform(inp)
assert_array_equal(lb.classes_, ["neg", "pos"])
assert_array_equal(expected, got)
to_invert = np.array([[1, 0],
[0, 1],
[0, 1],
[1, 0]])
assert_array_equal(lb.inverse_transform(to_invert), inp)
# multi-class case
inp = ["spam", "ham", "eggs", "ham", "0"]
expected = np.array([[0, 0, 0, 1],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 0]])
got = lb.fit_transform(inp)
assert_array_equal(lb.classes_, ['0', 'eggs', 'ham', 'spam'])
assert_array_equal(expected, got)
assert_array_equal(lb.inverse_transform(got), inp)
def test_label_binarizer_unseen_labels():
lb = LabelBinarizer()
expected = np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
got = lb.fit_transform(['b', 'd', 'e'])
assert_array_equal(expected, got)
expected = np.array([[0, 0, 0],
[1, 0, 0],
[0, 0, 0],
[0, 1, 0],
[0, 0, 1],
[0, 0, 0]])
got = lb.transform(['a', 'b', 'c', 'd', 'e', 'f'])
assert_array_equal(expected, got)
def test_label_binarizer_set_label_encoding():
lb = LabelBinarizer(neg_label=-2, pos_label=0)
# two-class case with pos_label=0
inp = np.array([0, 1, 1, 0])
expected = np.array([[-2, 0, 0, -2]]).T
got = lb.fit_transform(inp)
assert_array_equal(expected, got)
assert_array_equal(lb.inverse_transform(got), inp)
lb = LabelBinarizer(neg_label=-2, pos_label=2)
# multi-class case
inp = np.array([3, 2, 1, 2, 0])
expected = np.array([[-2, -2, -2, +2],
[-2, -2, +2, -2],
[-2, +2, -2, -2],
[-2, -2, +2, -2],
[+2, -2, -2, -2]])
got = lb.fit_transform(inp)
assert_array_equal(expected, got)
assert_array_equal(lb.inverse_transform(got), inp)
@ignore_warnings
def test_label_binarizer_errors():
# Check that invalid arguments yield ValueError
one_class = np.array([0, 0, 0, 0])
lb = LabelBinarizer().fit(one_class)
multi_label = [(2, 3), (0,), (0, 2)]
assert_raises(ValueError, lb.transform, multi_label)
lb = LabelBinarizer()
assert_raises(ValueError, lb.transform, [])
assert_raises(ValueError, lb.inverse_transform, [])
assert_raises(ValueError, LabelBinarizer, neg_label=2, pos_label=1)
assert_raises(ValueError, LabelBinarizer, neg_label=2, pos_label=2)
assert_raises(ValueError, LabelBinarizer, neg_label=1, pos_label=2,
sparse_output=True)
# Fail on y_type
assert_raises(ValueError, _inverse_binarize_thresholding,
y=csr_matrix([[1, 2], [2, 1]]), output_type="foo",
classes=[1, 2], threshold=0)
# Sequence of seq type should raise ValueError
y_seq_of_seqs = [[], [1, 2], [3], [0, 1, 3], [2]]
assert_raises(ValueError, LabelBinarizer().fit_transform, y_seq_of_seqs)
# Fail on the number of classes
assert_raises(ValueError, _inverse_binarize_thresholding,
y=csr_matrix([[1, 2], [2, 1]]), output_type="foo",
classes=[1, 2, 3], threshold=0)
# Fail on the dimension of 'binary'
assert_raises(ValueError, _inverse_binarize_thresholding,
y=np.array([[1, 2, 3], [2, 1, 3]]), output_type="binary",
classes=[1, 2, 3], threshold=0)
# Fail on multioutput data
assert_raises(ValueError, LabelBinarizer().fit, np.array([[1, 3], [2, 1]]))
assert_raises(ValueError, label_binarize, np.array([[1, 3], [2, 1]]),
[1, 2, 3])
def test_label_encoder():
# Test LabelEncoder's transform and inverse_transform methods
le = LabelEncoder()
le.fit([1, 1, 4, 5, -1, 0])
assert_array_equal(le.classes_, [-1, 0, 1, 4, 5])
assert_array_equal(le.transform([0, 1, 4, 4, 5, -1, -1]),
[1, 2, 3, 3, 4, 0, 0])
assert_array_equal(le.inverse_transform([1, 2, 3, 3, 4, 0, 0]),
[0, 1, 4, 4, 5, -1, -1])
assert_raises(ValueError, le.transform, [0, 6])
def test_label_encoder_fit_transform():
# Test fit_transform
le = LabelEncoder()
ret = le.fit_transform([1, 1, 4, 5, -1, 0])
assert_array_equal(ret, [2, 2, 3, 4, 0, 1])
le = LabelEncoder()
ret = le.fit_transform(["paris", "paris", "tokyo", "amsterdam"])
assert_array_equal(ret, [1, 1, 2, 0])
def test_label_encoder_errors():
# Check that invalid arguments yield ValueError
le = LabelEncoder()
assert_raises(ValueError, le.transform, [])
assert_raises(ValueError, le.inverse_transform, [])
# Fail on unseen labels
le = LabelEncoder()
le.fit([1, 2, 3, 1, -1])
assert_raises(ValueError, le.inverse_transform, [-1])
def test_sparse_output_multilabel_binarizer():
# test input as iterable of iterables
inputs = [
lambda: [(2, 3), (1,), (1, 2)],
lambda: (set([2, 3]), set([1]), set([1, 2])),
lambda: iter([iter((2, 3)), iter((1,)), set([1, 2])]),
]
indicator_mat = np.array([[0, 1, 1],
[1, 0, 0],
[1, 1, 0]])
inverse = inputs[0]()
for sparse_output in [True, False]:
for inp in inputs:
# With fit_tranform
mlb = MultiLabelBinarizer(sparse_output=sparse_output)
got = mlb.fit_transform(inp())
assert_equal(issparse(got), sparse_output)
if sparse_output:
got = got.toarray()
assert_array_equal(indicator_mat, got)
assert_array_equal([1, 2, 3], mlb.classes_)
assert_equal(mlb.inverse_transform(got), inverse)
# With fit
mlb = MultiLabelBinarizer(sparse_output=sparse_output)
got = mlb.fit(inp()).transform(inp())
assert_equal(issparse(got), sparse_output)
if sparse_output:
got = got.toarray()
assert_array_equal(indicator_mat, got)
assert_array_equal([1, 2, 3], mlb.classes_)
assert_equal(mlb.inverse_transform(got), inverse)
assert_raises(ValueError, mlb.inverse_transform,
csr_matrix(np.array([[0, 1, 1],
[2, 0, 0],
[1, 1, 0]])))
def test_multilabel_binarizer():
# test input as iterable of iterables
inputs = [
lambda: [(2, 3), (1,), (1, 2)],
lambda: (set([2, 3]), set([1]), set([1, 2])),
lambda: iter([iter((2, 3)), iter((1,)), set([1, 2])]),
]
indicator_mat = np.array([[0, 1, 1],
[1, 0, 0],
[1, 1, 0]])
inverse = inputs[0]()
for inp in inputs:
# With fit_tranform
mlb = MultiLabelBinarizer()
got = mlb.fit_transform(inp())
assert_array_equal(indicator_mat, got)
assert_array_equal([1, 2, 3], mlb.classes_)
assert_equal(mlb.inverse_transform(got), inverse)
# With fit
mlb = MultiLabelBinarizer()
got = mlb.fit(inp()).transform(inp())
assert_array_equal(indicator_mat, got)
assert_array_equal([1, 2, 3], mlb.classes_)
assert_equal(mlb.inverse_transform(got), inverse)
def test_multilabel_binarizer_empty_sample():
mlb = MultiLabelBinarizer()
y = [[1, 2], [1], []]
Y = np.array([[1, 1],
[1, 0],
[0, 0]])
assert_array_equal(mlb.fit_transform(y), Y)
def test_multilabel_binarizer_unknown_class():
mlb = MultiLabelBinarizer()
y = [[1, 2]]
assert_raises(KeyError, mlb.fit(y).transform, [[0]])
mlb = MultiLabelBinarizer(classes=[1, 2])
assert_raises(KeyError, mlb.fit_transform, [[0]])
def test_multilabel_binarizer_given_classes():
inp = [(2, 3), (1,), (1, 2)]
indicator_mat = np.array([[0, 1, 1],
[1, 0, 0],
[1, 0, 1]])
# fit_transform()
mlb = MultiLabelBinarizer(classes=[1, 3, 2])
assert_array_equal(mlb.fit_transform(inp), indicator_mat)
assert_array_equal(mlb.classes_, [1, 3, 2])
# fit().transform()
mlb = MultiLabelBinarizer(classes=[1, 3, 2])
assert_array_equal(mlb.fit(inp).transform(inp), indicator_mat)
assert_array_equal(mlb.classes_, [1, 3, 2])
# ensure works with extra class
mlb = MultiLabelBinarizer(classes=[4, 1, 3, 2])
assert_array_equal(mlb.fit_transform(inp),
np.hstack(([[0], [0], [0]], indicator_mat)))
assert_array_equal(mlb.classes_, [4, 1, 3, 2])
# ensure fit is no-op as iterable is not consumed
inp = iter(inp)
mlb = MultiLabelBinarizer(classes=[1, 3, 2])
assert_array_equal(mlb.fit(inp).transform(inp), indicator_mat)
def test_multilabel_binarizer_same_length_sequence():
# Ensure sequences of the same length are not interpreted as a 2-d array
inp = [[1], [0], [2]]
indicator_mat = np.array([[0, 1, 0],
[1, 0, 0],
[0, 0, 1]])
# fit_transform()
mlb = MultiLabelBinarizer()
assert_array_equal(mlb.fit_transform(inp), indicator_mat)
assert_array_equal(mlb.inverse_transform(indicator_mat), inp)
# fit().transform()
mlb = MultiLabelBinarizer()
assert_array_equal(mlb.fit(inp).transform(inp), indicator_mat)
assert_array_equal(mlb.inverse_transform(indicator_mat), inp)
def test_multilabel_binarizer_non_integer_labels():
tuple_classes = np.empty(3, dtype=object)
tuple_classes[:] = [(1,), (2,), (3,)]
inputs = [
([('2', '3'), ('1',), ('1', '2')], ['1', '2', '3']),
([('b', 'c'), ('a',), ('a', 'b')], ['a', 'b', 'c']),
([((2,), (3,)), ((1,),), ((1,), (2,))], tuple_classes),
]
indicator_mat = np.array([[0, 1, 1],
[1, 0, 0],
[1, 1, 0]])
for inp, classes in inputs:
# fit_transform()
mlb = MultiLabelBinarizer()
assert_array_equal(mlb.fit_transform(inp), indicator_mat)
assert_array_equal(mlb.classes_, classes)
assert_array_equal(mlb.inverse_transform(indicator_mat), inp)
# fit().transform()
mlb = MultiLabelBinarizer()
assert_array_equal(mlb.fit(inp).transform(inp), indicator_mat)
assert_array_equal(mlb.classes_, classes)
assert_array_equal(mlb.inverse_transform(indicator_mat), inp)
mlb = MultiLabelBinarizer()
assert_raises(TypeError, mlb.fit_transform, [({}), ({}, {'a': 'b'})])
def test_multilabel_binarizer_non_unique():
inp = [(1, 1, 1, 0)]
indicator_mat = np.array([[1, 1]])
mlb = MultiLabelBinarizer()
assert_array_equal(mlb.fit_transform(inp), indicator_mat)
def test_multilabel_binarizer_inverse_validation():
inp = [(1, 1, 1, 0)]
mlb = MultiLabelBinarizer()
mlb.fit_transform(inp)
# Not binary
assert_raises(ValueError, mlb.inverse_transform, np.array([[1, 3]]))
# The following binary cases are fine, however
mlb.inverse_transform(np.array([[0, 0]]))
mlb.inverse_transform(np.array([[1, 1]]))
mlb.inverse_transform(np.array([[1, 0]]))
# Wrong shape
assert_raises(ValueError, mlb.inverse_transform, np.array([[1]]))
assert_raises(ValueError, mlb.inverse_transform, np.array([[1, 1, 1]]))
def test_label_binarize_with_class_order():
out = label_binarize([1, 6], classes=[1, 2, 4, 6])
expected = np.array([[1, 0, 0, 0], [0, 0, 0, 1]])
assert_array_equal(out, expected)
# Modified class order
out = label_binarize([1, 6], classes=[1, 6, 4, 2])
expected = np.array([[1, 0, 0, 0], [0, 1, 0, 0]])
assert_array_equal(out, expected)
out = label_binarize([0, 1, 2, 3], classes=[3, 2, 0, 1])
expected = np.array([[0, 0, 1, 0],
[0, 0, 0, 1],
[0, 1, 0, 0],
[1, 0, 0, 0]])
assert_array_equal(out, expected)
def check_binarized_results(y, classes, pos_label, neg_label, expected):
for sparse_output in [True, False]:
if ((pos_label == 0 or neg_label != 0) and sparse_output):
assert_raises(ValueError, label_binarize, y, classes,
neg_label=neg_label, pos_label=pos_label,
sparse_output=sparse_output)
continue
# check label_binarize
binarized = label_binarize(y, classes, neg_label=neg_label,
pos_label=pos_label,
sparse_output=sparse_output)
assert_array_equal(toarray(binarized), expected)
assert_equal(issparse(binarized), sparse_output)
# check inverse
y_type = type_of_target(y)
if y_type == "multiclass":
inversed = _inverse_binarize_multiclass(binarized, classes=classes)
else:
inversed = _inverse_binarize_thresholding(binarized,
output_type=y_type,
classes=classes,
threshold=((neg_label +
pos_label) /
2.))
assert_array_equal(toarray(inversed), toarray(y))
# Check label binarizer
lb = LabelBinarizer(neg_label=neg_label, pos_label=pos_label,
sparse_output=sparse_output)
binarized = lb.fit_transform(y)
assert_array_equal(toarray(binarized), expected)
assert_equal(issparse(binarized), sparse_output)
inverse_output = lb.inverse_transform(binarized)
assert_array_equal(toarray(inverse_output), toarray(y))
assert_equal(issparse(inverse_output), issparse(y))
def test_label_binarize_binary():
y = [0, 1, 0]
classes = [0, 1]
pos_label = 2
neg_label = -1
expected = np.array([[2, -1], [-1, 2], [2, -1]])[:, 1].reshape((-1, 1))
yield check_binarized_results, y, classes, pos_label, neg_label, expected
# Binary case where sparse_output = True will not result in a ValueError
y = [0, 1, 0]
classes = [0, 1]
pos_label = 3
neg_label = 0
expected = np.array([[3, 0], [0, 3], [3, 0]])[:, 1].reshape((-1, 1))
yield check_binarized_results, y, classes, pos_label, neg_label, expected
def test_label_binarize_multiclass():
y = [0, 1, 2]
classes = [0, 1, 2]
pos_label = 2
neg_label = 0
expected = 2 * np.eye(3)
yield check_binarized_results, y, classes, pos_label, neg_label, expected
assert_raises(ValueError, label_binarize, y, classes, neg_label=-1,
pos_label=pos_label, sparse_output=True)
def test_label_binarize_multilabel():
y_ind = np.array([[0, 1, 0], [1, 1, 1], [0, 0, 0]])
classes = [0, 1, 2]
pos_label = 2
neg_label = 0
expected = pos_label * y_ind
y_sparse = [sparse_matrix(y_ind)
for sparse_matrix in [coo_matrix, csc_matrix, csr_matrix,
dok_matrix, lil_matrix]]
for y in [y_ind] + y_sparse:
yield (check_binarized_results, y, classes, pos_label, neg_label,
expected)
assert_raises(ValueError, label_binarize, y, classes, neg_label=-1,
pos_label=pos_label, sparse_output=True)
def test_invalid_input_label_binarize():
assert_raises(ValueError, label_binarize, [0, 2], classes=[0, 2],
pos_label=0, neg_label=1)
def test_inverse_binarize_multiclass():
got = _inverse_binarize_multiclass(csr_matrix([[0, 1, 0],
[-1, 0, -1],
[0, 0, 0]]),
np.arange(3))
assert_array_equal(got, np.array([1, 1, 0]))
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
199,
504,
7026,
14,
4421,
492,
365,
4421,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
199,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
504,
7026,
14,
4421,
492,
22258,
63,
3642,
199,
504,
7026,
14,
4421,
492,
366,
745,
63,
3642,
199,
504,
7026,
14,
4421,
492,
1212,
76,
63,
3642,
199,
199,
504,
6357,
14,
1208,
14,
30016,
492,
730,
63,
1618,
63,
1375,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
21402,
14,
1302,
492,
10354,
13394,
31008,
199,
504,
6357,
14,
21402,
14,
1302,
492,
6879,
4314,
13394,
31008,
199,
504,
6357,
14,
21402,
14,
1302,
492,
10354,
6679,
199,
504,
6357,
14,
21402,
14,
1302,
492,
1768,
63,
1393,
285,
794,
199,
199,
504,
6357,
14,
21402,
14,
1302,
492,
485,
11668,
63,
1393,
285,
794,
63,
14898,
13122,
199,
504,
6357,
14,
21402,
14,
1302,
492,
485,
11668,
63,
1393,
285,
794,
63,
30016,
199,
199,
504,
6357,
492,
13148,
199,
199,
11885,
275,
13148,
14,
912,
63,
11885,
342,
421,
199,
318,
370,
1144,
8,
65,
304,
272,
340,
2688,
8,
65,
12,
298,
18993,
2349,
267,
282,
275,
282,
14,
18993,
342,
272,
372,
282,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
837,
272,
11104,
275,
10354,
13394,
31008,
342,
339,
327,
1373,
13,
533,
1930,
4243,
370,
6946,
1768,
272,
10702,
275,
2097,
1712,
401,
298,
1712,
401,
298,
1712,
401,
298,
1712,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
12,
378,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
2097,
1712,
3135,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
339,
327,
2877,
13,
533,
1930,
272,
10702,
275,
2097,
8705,
401,
298,
1712,
401,
298,
1712,
401,
298,
8705,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
413,
12,
413,
12,
378,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
2097,
8705,
401,
298,
1712,
3135,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
339,
370,
63,
18957,
275,
980,
14,
1144,
4038,
17,
12,
378,
467,
2079,
359,
16,
12,
413,
467,
2079,
359,
16,
12,
413,
467,
2079,
359,
17,
12,
378,
3934,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
475,
63,
18957,
395,
10702,
9,
339,
327,
3510,
13,
533,
1930,
272,
10702,
275,
2097,
8283,
401,
298,
10670,
401,
298,
14488,
401,
298,
10670,
401,
298,
16,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
12,
413,
467,
586,
359,
16,
12,
378,
12,
413,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
378,
467,
586,
359,
17,
12,
378,
12,
378,
12,
378,
3934,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
788,
16,
297,
283,
14488,
297,
283,
10670,
297,
283,
8283,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
63,
324,
8606,
63,
3512,
837,
272,
11104,
275,
10354,
13394,
31008,
342,
339,
1420,
275,
980,
14,
1144,
4038,
17,
12,
378,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
3934,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
2941,
66,
297,
283,
68,
297,
283,
69,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
339,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
467,
586,
359,
17,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
467,
586,
359,
16,
12,
378,
12,
378,
3934,
272,
4788,
275,
11104,
14,
4711,
2941,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
63,
409,
63,
1302,
63,
2991,
837,
272,
11104,
275,
10354,
13394,
31008,
8,
8705,
63,
1302,
4022,
18,
12,
2086,
63,
1302,
29,
16,
9,
339,
327,
2877,
13,
533,
1930,
543,
2086,
63,
1302,
29,
16,
272,
10702,
275,
980,
14,
1144,
779,
16,
12,
413,
12,
413,
12,
378,
566,
272,
1420,
275,
980,
14,
1144,
22844,
18,
12,
378,
12,
378,
12,
446,
18,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
339,
11104,
275,
10354,
13394,
31008,
8,
8705,
63,
1302,
4022,
18,
12,
2086,
63,
1302,
29,
18,
9,
339,
327,
3510,
13,
533,
1930,
272,
10702,
275,
980,
14,
1144,
779,
19,
12,
499,
12,
413,
12,
499,
12,
378,
566,
272,
1420,
275,
980,
14,
1144,
22844,
18,
12,
446,
18,
12,
446,
18,
12,
435,
18,
467,
586,
5243,
18,
12,
446,
18,
12,
435,
18,
12,
446,
18,
467,
586,
5243,
18,
12,
435,
18,
12,
446,
18,
12,
446,
18,
467,
586,
5243,
18,
12,
446,
18,
12,
435,
18,
12,
446,
18,
467,
586,
359,
11,
18,
12,
446,
18,
12,
446,
18,
12,
446,
18
] |
[
2680,
465,
980,
199,
199,
504,
7026,
14,
4421,
492,
365,
4421,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
199,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
504,
7026,
14,
4421,
492,
22258,
63,
3642,
199,
504,
7026,
14,
4421,
492,
366,
745,
63,
3642,
199,
504,
7026,
14,
4421,
492,
1212,
76,
63,
3642,
199,
199,
504,
6357,
14,
1208,
14,
30016,
492,
730,
63,
1618,
63,
1375,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
21402,
14,
1302,
492,
10354,
13394,
31008,
199,
504,
6357,
14,
21402,
14,
1302,
492,
6879,
4314,
13394,
31008,
199,
504,
6357,
14,
21402,
14,
1302,
492,
10354,
6679,
199,
504,
6357,
14,
21402,
14,
1302,
492,
1768,
63,
1393,
285,
794,
199,
199,
504,
6357,
14,
21402,
14,
1302,
492,
485,
11668,
63,
1393,
285,
794,
63,
14898,
13122,
199,
504,
6357,
14,
21402,
14,
1302,
492,
485,
11668,
63,
1393,
285,
794,
63,
30016,
199,
199,
504,
6357,
492,
13148,
199,
199,
11885,
275,
13148,
14,
912,
63,
11885,
342,
421,
199,
318,
370,
1144,
8,
65,
304,
272,
340,
2688,
8,
65,
12,
298,
18993,
2349,
267,
282,
275,
282,
14,
18993,
342,
272,
372,
282,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
837,
272,
11104,
275,
10354,
13394,
31008,
342,
339,
327,
1373,
13,
533,
1930,
4243,
370,
6946,
1768,
272,
10702,
275,
2097,
1712,
401,
298,
1712,
401,
298,
1712,
401,
298,
1712,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
12,
378,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
2097,
1712,
3135,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
339,
327,
2877,
13,
533,
1930,
272,
10702,
275,
2097,
8705,
401,
298,
1712,
401,
298,
1712,
401,
298,
8705,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
413,
12,
413,
12,
378,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
2097,
8705,
401,
298,
1712,
3135,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
339,
370,
63,
18957,
275,
980,
14,
1144,
4038,
17,
12,
378,
467,
2079,
359,
16,
12,
413,
467,
2079,
359,
16,
12,
413,
467,
2079,
359,
17,
12,
378,
3934,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
475,
63,
18957,
395,
10702,
9,
339,
327,
3510,
13,
533,
1930,
272,
10702,
275,
2097,
8283,
401,
298,
10670,
401,
298,
14488,
401,
298,
10670,
401,
298,
16,
937,
272,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
12,
413,
467,
586,
359,
16,
12,
378,
12,
413,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
12,
378,
467,
586,
359,
17,
12,
378,
12,
378,
12,
378,
3934,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
2888,
3131,
788,
16,
297,
283,
14488,
297,
283,
10670,
297,
283,
8283,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
63,
324,
8606,
63,
3512,
837,
272,
11104,
275,
10354,
13394,
31008,
342,
339,
1420,
275,
980,
14,
1144,
4038,
17,
12,
378,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
3934,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
2941,
66,
297,
283,
68,
297,
283,
69,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
339,
1420,
275,
980,
14,
1144,
4038,
16,
12,
378,
12,
378,
467,
586,
359,
17,
12,
378,
12,
378,
467,
586,
359,
16,
12,
378,
12,
378,
467,
586,
359,
16,
12,
413,
12,
378,
467,
586,
359,
16,
12,
378,
12,
413,
467,
586,
359,
16,
12,
378,
12,
378,
3934,
272,
4788,
275,
11104,
14,
4711,
2941,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
1105,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
421,
199,
318,
511,
63,
1302,
63,
1393,
31008,
63,
409,
63,
1302,
63,
2991,
837,
272,
11104,
275,
10354,
13394,
31008,
8,
8705,
63,
1302,
4022,
18,
12,
2086,
63,
1302,
29,
16,
9,
339,
327,
2877,
13,
533,
1930,
543,
2086,
63,
1302,
29,
16,
272,
10702,
275,
980,
14,
1144,
779,
16,
12,
413,
12,
413,
12,
378,
566,
272,
1420,
275,
980,
14,
1144,
22844,
18,
12,
378,
12,
378,
12,
446,
18,
3934,
14,
52,
272,
4788,
275,
11104,
14,
3269,
63,
4711,
8,
11416,
9,
272,
702,
63,
1144,
63,
1452,
8,
2062,
12,
4788,
9,
272,
702,
63,
1144,
63,
1452,
8,
6374,
14,
11668,
63,
4711,
8,
7808,
395,
10702,
9,
339,
11104,
275,
10354,
13394,
31008,
8,
8705,
63,
1302,
4022,
18,
12,
2086,
63,
1302,
29,
18,
9,
339,
327,
3510,
13,
533,
1930,
272,
10702,
275,
980,
14,
1144,
779,
19,
12,
499,
12,
413,
12,
499,
12,
378,
566,
272,
1420,
275,
980,
14,
1144,
22844,
18,
12,
446,
18,
12,
446,
18,
12,
435,
18,
467,
586,
5243,
18,
12,
446,
18,
12,
435,
18,
12,
446,
18,
467,
586,
5243,
18,
12,
435,
18,
12,
446,
18,
12,
446,
18,
467,
586,
5243,
18,
12,
446,
18,
12,
435,
18,
12,
446,
18,
467,
586,
359,
11,
18,
12,
446,
18,
12,
446,
18,
12,
446,
18,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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kte_new_lowfreq.py
|
1
|
6373
|
#!/usr/bin/env python3
from sympy import *
from mpmath import *
from matplotlib.pyplot import *
#init_printing() # make things prettier when we print stuff for debugging.
# ************************************************************************** #
# Magnetic field inside copper coil with hollow copper cylinder #
# ************************************************************************** #
# All values are in standard SI units unless otherwise noted.
# ---------------------------------------------------------#
# Define Variables and Constants #
# ---------------------------------------------------------#
npts = 19 # careful: number of points is npts + 1 (starts at 0)
#fmin = 5e-4
#fmax = 5e-2
fmin = 0.1
fmax = 0.2
highest_frequency = fmin * exp(log(fmax-fmin))
freq_max_ratio = highest_frequency / fmax
font = {
'family' : 'serif',
'color' : 'black',
'weight' : 'normal',
'size' : 9,
}
titlefont = {
'family' : 'serif',
'color' : 'black',
'weight' : 'normal',
'size' : 10,
}
plot_legend_fontsize = 9
plot_color_old = 'magenta'
plot_color_new = 'blue'
plot_color_common = 'black'
plot_label_points_old = r"St\"utzpunktformel A: $\displaystyle f_{kA} = f_{min} \cdot exp\Biggr(\frac{k}{NPTS} \cdot ln(f_{max}-f_{min})\Biggr)$"
plot_label_points_new = r"St\"utzpunktformel B: $\displaystyle f_{kB} = exp\Biggr((1-\frac{k}{NPTS}) \cdot ln(f_{min})\Biggr) \cdot exp\Biggr(\frac{k}{NPTS} \cdot ln(f_{max})\Biggr)$"
plot_label_vertical_common = r"minimale Frequenz St\"utzpunkt: "
plot_label_vertical_old = r"maximale Frequenz St\"utzpunkt, Methode A: "
plot_label_vertical_new = r"maximale Frequenz St\"utzpunkt, Methode B: "
plot_added_text = r"Verh\"altnis der maximalen Frequenzen Methode A -- Methode B: $\displaystyle \frac{f_{kA}}{f_{kB}}\Bigg|_{k=NPTS} \approx " + str(freq_max_ratio) + "$"
plot_freq_range_label = r"Eingestellter Frequenzbereich: $f_{min} = " + str(fmin) + r"$Hz bis $f_{max} = " + str(fmax) + r"$Hz"
plot_size_measurements = 24
plot_scale_x = 'log'
plot_label_x = r"Frequenz des St\"utzpunkts (Hz)"
plot_1_label_y = 'k (siehe Formel)'
plot_1_title = r"Vergleich St\"utzpunktformeln, effektiv abgedeckter Frequenzbereich:" + str(fmin) + " Hz bis " + str(highest_frequency) + " Hz, " + str(npts+1) + " Punkte"
y_lim_low = -2
y_lim_high = npts + 2
x_lim_low = 0.67 * fmin
x_lim_high = 1.33 * fmin * fmax
# ---------------------------------------------------------#
# Generate points for frequency axis #
# ---------------------------------------------------------#
n = np.linspace(0,npts,npts)
expufunc = np.frompyfunc(exp,1,1)
frequency_vector_old = fmin*expufunc(n*log(fmax-fmin)/npts)
frequency_vector_new = expufunc((1-n/npts)*log(fmin)) * expufunc(n*log(fmax)/npts)
plot_label_vertical_common += str(frequency_vector_old[0]) + " Hz"
plot_label_vertical_old += str(frequency_vector_old[npts-1]) + " Hz"
plot_label_vertical_new += str(frequency_vector_new[npts-1]) + " Hz"
# ---------------------------------------------------------#
# Plot the Things #
# ---------------------------------------------------------#
matplotlib.pyplot.rc('text', usetex=True)
matplotlib.pyplot.rc('font', family='serif')
#fig1 = figure(1)
#fig1 = figure(1,figsize=(9,9))
#fig1 = figure(1,figsize=(8.26,11.7)) # A4 size in inches
fig1 = figure(1,figsize=(8.26,10.0))
axes1 = fig1.add_subplot(111)
axes1.set_position([0.1,0.1,0.5,0.8])
axes1.scatter(frequency_vector_old,
n,
color=plot_color_old,
s=plot_size_measurements,
label=plot_label_points_old
)
axes1.scatter(frequency_vector_new,
n,
color=plot_color_new,
s=plot_size_measurements,
label=plot_label_points_new
)
# Draw the common starting point black and a bit bigger
axes1.scatter(frequency_vector_old[0],
n[0],
color=plot_color_common,
s=plot_size_measurements*1.5,
)
axes1.plot([frequency_vector_old[0],frequency_vector_old[0]],
[y_lim_low,y_lim_high],
color=plot_color_common,
label=plot_label_vertical_common
)
axes1.plot([frequency_vector_old[npts-1],frequency_vector_old[npts-1]],
[y_lim_low,y_lim_high],
color=plot_color_old,
label=plot_label_vertical_old
)
axes1.plot([frequency_vector_new[npts-1],frequency_vector_new[npts-1]],
[y_lim_low,y_lim_high],
color=plot_color_new,
label=plot_label_vertical_new
)
axes1.set_xscale(plot_scale_x)
axes1.set_ylim([y_lim_low,y_lim_high])
#axes1.set_xlim([x_lim_low,x_lim_high])
axes1.set_xlabel(plot_label_x,fontdict=font)
axes1.set_ylabel(plot_1_label_y,fontdict=font)
axes1.set_title(plot_1_title,fontdict=titlefont)
axes1.tick_params(labelsize=9)
# ---------------------------------------------------- #
# Work some magic to append the fraction of the two #
# methods to the legend instead of it being some #
# random piece of text on the plot. #
# ---------------------------------------------------- #
rect = matplotlib.patches.Rectangle([0,0],0,0,color='white',label=plot_added_text)
rect2= matplotlib.patches.Rectangle([0,0],0,0,color='white',label=plot_freq_range_label)
handles,legends = axes1.get_legend_handles_labels()
handles.append(rect)
handles.append(rect2)
axes1.legend(handles=handles,fontsize=plot_legend_fontsize,loc='upper left',bbox_to_anchor=(0.0,-0.075))
# ---------------------------------------------------- #
# This would be necessary if we wanted to actually #
# draw the patch, leaving this here for future #
# reference. #
# ---------------------------------------------------- #
#axes1.add_patch(rect)
fig1.subplots_adjust(bottom=0.29,left=0.05,right=0.99,top=.98,hspace=0.3)
fig1.savefig('plots-pgf/stuetzpunkte-lowfreq.pgf')
fig1.savefig('plots-pdf/stuetzpunkte-lowfreq.pdf')
#show()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
504,
5840,
492,
627,
199,
504,
6118,
3442,
492,
627,
199,
504,
8027,
14,
13563,
492,
627,
199,
3,
826,
63,
26514,
342,
258,
327,
1852,
7645,
876,
84,
13949,
1380,
781,
870,
8292,
367,
10201,
14,
421,
199,
3,
1011,
14355,
327,
199,
3,
603,
29575,
764,
901,
6272,
4870,
529,
512,
382,
543,
221,
394,
13346,
4870,
529,
6325,
24447,
3777,
327,
199,
3,
1011,
14355,
327,
199,
199,
3,
2900,
1338,
787,
315,
4465,
428,
41,
6204,
7444,
4257,
949,
471,
14,
421,
199,
3,
9527,
518,
8492,
199,
3,
13930,
17198,
436,
22296,
13235,
327,
199,
3,
9527,
518,
8492,
199,
78,
8382,
4519,
275,
5851,
327,
25082,
26,
1329,
402,
4501,
365,
302,
8382,
435,
413,
334,
17116,
737,
378,
9,
199,
3,
70,
827,
4519,
275,
959,
69,
13,
20,
199,
3,
70,
988,
4519,
275,
959,
69,
13,
18,
199,
70,
827,
4519,
275,
378,
14,
17,
199,
70,
988,
4519,
275,
378,
14,
18,
199,
31381,
63,
11132,
275,
289,
827,
627,
1437,
8,
793,
8,
70,
988,
13,
70,
827,
430,
199,
5646,
63,
988,
63,
6884,
259,
275,
15356,
63,
11132,
1182,
289,
988,
199,
4246,
275,
469,
267,
283,
6606,
7,
520,
283,
24977,
297,
267,
283,
2326,
7,
221,
520,
283,
8399,
297,
267,
283,
3463,
7,
520,
283,
3302,
297,
267,
283,
890,
7,
257,
520,
1749,
12,
267,
789,
199,
1213,
4246,
275,
469,
267,
283,
6606,
7,
520,
283,
24977,
297,
267,
283,
2326,
7,
221,
520,
283,
8399,
297,
267,
283,
3463,
7,
520,
283,
3302,
297,
267,
283,
890,
7,
257,
520,
1616,
12,
267,
789,
199,
2798,
63,
10231,
63,
22124,
755,
275,
1749,
199,
2798,
63,
2326,
63,
1753,
3777,
275,
283,
5615,
21335,
7,
199,
2798,
63,
2326,
63,
1222,
3777,
275,
283,
6304,
7,
199,
2798,
63,
2326,
63,
2330,
3515,
275,
283,
8399,
7,
199,
2798,
63,
1302,
63,
3438,
63,
1753,
420,
275,
519,
2,
933,
4451,
337,
90,
80,
1778,
84,
509,
26908,
437,
26,
2672,
60,
2918,
2487,
289,
7348,
75,
33,
93,
275,
289,
7348,
827,
93,
971,
2866,
357,
1437,
60,
7279,
2587,
2961,
10865,
91,
75,
8847,
46,
4189,
51,
93,
971,
2866,
357,
10359,
8,
70,
7348,
988,
17063,
70,
7348,
827,
30446,
7279,
2587,
9,
17351,
199,
2798,
63,
1302,
63,
3438,
63,
1222,
420,
275,
519,
2,
933,
4451,
337,
90,
80,
1778,
84,
509,
26908,
699,
26,
2672,
60,
2918,
2487,
289,
7348,
75,
34,
93,
275,
1437,
60,
7279,
2587,
1332,
17,
2696,
10865,
91,
75,
8847,
46,
4189,
51,
1552,
971,
2866,
357,
10359,
8,
70,
7348,
827,
30446,
7279,
2587,
9,
971,
2866,
357,
1437,
60,
7279,
2587,
2961,
10865,
91,
75,
8847,
46,
4189,
51,
93,
971,
2866,
357,
10359,
8,
70,
7348,
988,
30446,
7279,
2587,
9,
17351,
199,
2798,
63,
1302,
63,
7870,
63,
2330,
275,
519,
2,
827,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
26,
298,
199,
2798,
63,
1302,
63,
7870,
63,
1753,
259,
275,
519,
2,
988,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
12,
3194,
273,
380,
437,
26,
298,
199,
2798,
63,
1302,
63,
7870,
63,
1222,
259,
275,
519,
2,
988,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
12,
3194,
273,
380,
699,
26,
298,
199,
2798,
63,
3270,
63,
505,
3322,
275,
519,
2,
3673,
72,
4451,
4478,
26294,
16921,
1390,
11744,
552,
481,
5456,
5193,
3194,
273,
380,
437,
1553,
3194,
273,
380,
699,
26,
2672,
60,
2918,
2487,
971,
10865,
91,
70,
7348,
75,
33,
4863,
91,
70,
7348,
75,
34,
4863,
60,
7279,
71,
92,
7348,
75,
29,
46,
4189,
51,
93,
971,
16815,
298,
435,
620,
8,
5646,
63,
988,
63,
6884,
9,
435,
7880,
2,
199,
2798,
63,
5646,
63,
1842,
63,
1302,
420,
275,
519,
2,
37,
17081,
1597,
914,
351,
481,
5456,
90,
1235,
264,
1158,
26,
2672,
70,
7348,
827,
93,
275,
298,
435,
620,
8,
70,
827,
9,
435,
519,
2,
4,
13026,
330,
374,
2672,
70,
7348,
988,
93,
275,
298,
435,
620,
8,
70,
988,
9,
435,
519,
2,
4,
13026,
2,
199,
2798,
63,
890,
63,
30264,
258,
275,
5504,
199,
2798,
63,
3467,
63,
88,
5185,
275,
283,
793,
7,
199,
2798,
63,
1302,
63,
88,
5185,
275,
519,
2,
38,
5456,
90,
18618,
1933,
4451,
337,
90,
80,
1778,
1086,
334,
13026,
2924,
199,
2798,
63,
17,
63,
1302,
63,
89,
3777,
275,
283,
75,
334,
23994,
426,
2104,
26908,
3171,
199,
2798,
63,
17,
63,
1213,
5185,
275,
519,
2,
3673,
3845,
1158,
1933,
4451,
337,
90,
80,
1778,
84,
509,
278,
6066,
12,
325,
2026,
75,
280,
86,
2236,
303,
31919,
351,
481,
5456,
90,
1235,
264,
1158,
5424,
435,
620,
8,
70,
827,
9,
435,
298,
30152,
330,
374,
298,
435,
620,
8,
31381,
63,
11132,
9,
435,
298,
30152,
12,
298,
435,
620,
8,
78,
8382,
11,
17,
9,
435,
298,
510,
1778,
266,
2,
199,
89,
63,
4175,
63,
674,
8295,
275,
446,
18,
199,
89,
63,
4175,
63,
6260,
463,
275,
302,
8382,
435,
499,
199,
88,
63,
4175,
63,
674,
8295,
275,
378,
14,
1822,
627,
289,
827,
199,
88,
63,
4175,
63,
6260,
463,
275,
413,
14,
1153,
627,
289,
827,
627,
289,
988,
421,
199,
3,
9527,
518,
8492,
199,
3,
7958,
4501,
367,
9857,
3114,
9668,
327,
199,
3,
9527,
518,
8492,
199,
78,
8540,
275,
980,
14,
11649,
8,
16,
12,
78,
8382,
12,
78,
8382,
9,
199,
1474,
18810,
3777,
275,
980,
14,
21775,
5086,
1532,
8,
1474,
12,
17,
12,
17,
9,
199,
11132,
63,
4106,
63,
1753,
275,
289,
827,
10,
1474,
18810,
8,
78,
10,
793,
8,
70,
988,
13,
70,
827,
2447,
78,
8382,
9,
199,
11132,
63,
4106,
63,
1222,
275,
1437,
18810,
1332,
17,
13,
78,
15,
78,
8382,
3342,
793,
8,
70,
827,
430,
627,
1437,
18810,
8,
78,
10,
793,
8,
70,
988,
2447,
78,
8382,
9,
199,
199
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
504,
5840,
492,
627,
199,
504,
6118,
3442,
492,
627,
199,
504,
8027,
14,
13563,
492,
627,
199,
3,
826,
63,
26514,
342,
258,
327,
1852,
7645,
876,
84,
13949,
1380,
781,
870,
8292,
367,
10201,
14,
421,
199,
3,
1011,
14355,
327,
199,
3,
603,
29575,
764,
901,
6272,
4870,
529,
512,
382,
543,
221,
394,
13346,
4870,
529,
6325,
24447,
3777,
327,
199,
3,
1011,
14355,
327,
199,
199,
3,
2900,
1338,
787,
315,
4465,
428,
41,
6204,
7444,
4257,
949,
471,
14,
421,
199,
3,
9527,
518,
8492,
199,
3,
13930,
17198,
436,
22296,
13235,
327,
199,
3,
9527,
518,
8492,
199,
78,
8382,
4519,
275,
5851,
327,
25082,
26,
1329,
402,
4501,
365,
302,
8382,
435,
413,
334,
17116,
737,
378,
9,
199,
3,
70,
827,
4519,
275,
959,
69,
13,
20,
199,
3,
70,
988,
4519,
275,
959,
69,
13,
18,
199,
70,
827,
4519,
275,
378,
14,
17,
199,
70,
988,
4519,
275,
378,
14,
18,
199,
31381,
63,
11132,
275,
289,
827,
627,
1437,
8,
793,
8,
70,
988,
13,
70,
827,
430,
199,
5646,
63,
988,
63,
6884,
259,
275,
15356,
63,
11132,
1182,
289,
988,
199,
4246,
275,
469,
267,
283,
6606,
7,
520,
283,
24977,
297,
267,
283,
2326,
7,
221,
520,
283,
8399,
297,
267,
283,
3463,
7,
520,
283,
3302,
297,
267,
283,
890,
7,
257,
520,
1749,
12,
267,
789,
199,
1213,
4246,
275,
469,
267,
283,
6606,
7,
520,
283,
24977,
297,
267,
283,
2326,
7,
221,
520,
283,
8399,
297,
267,
283,
3463,
7,
520,
283,
3302,
297,
267,
283,
890,
7,
257,
520,
1616,
12,
267,
789,
199,
2798,
63,
10231,
63,
22124,
755,
275,
1749,
199,
2798,
63,
2326,
63,
1753,
3777,
275,
283,
5615,
21335,
7,
199,
2798,
63,
2326,
63,
1222,
3777,
275,
283,
6304,
7,
199,
2798,
63,
2326,
63,
2330,
3515,
275,
283,
8399,
7,
199,
2798,
63,
1302,
63,
3438,
63,
1753,
420,
275,
519,
2,
933,
4451,
337,
90,
80,
1778,
84,
509,
26908,
437,
26,
2672,
60,
2918,
2487,
289,
7348,
75,
33,
93,
275,
289,
7348,
827,
93,
971,
2866,
357,
1437,
60,
7279,
2587,
2961,
10865,
91,
75,
8847,
46,
4189,
51,
93,
971,
2866,
357,
10359,
8,
70,
7348,
988,
17063,
70,
7348,
827,
30446,
7279,
2587,
9,
17351,
199,
2798,
63,
1302,
63,
3438,
63,
1222,
420,
275,
519,
2,
933,
4451,
337,
90,
80,
1778,
84,
509,
26908,
699,
26,
2672,
60,
2918,
2487,
289,
7348,
75,
34,
93,
275,
1437,
60,
7279,
2587,
1332,
17,
2696,
10865,
91,
75,
8847,
46,
4189,
51,
1552,
971,
2866,
357,
10359,
8,
70,
7348,
827,
30446,
7279,
2587,
9,
971,
2866,
357,
1437,
60,
7279,
2587,
2961,
10865,
91,
75,
8847,
46,
4189,
51,
93,
971,
2866,
357,
10359,
8,
70,
7348,
988,
30446,
7279,
2587,
9,
17351,
199,
2798,
63,
1302,
63,
7870,
63,
2330,
275,
519,
2,
827,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
26,
298,
199,
2798,
63,
1302,
63,
7870,
63,
1753,
259,
275,
519,
2,
988,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
12,
3194,
273,
380,
437,
26,
298,
199,
2798,
63,
1302,
63,
7870,
63,
1222,
259,
275,
519,
2,
988,
11744,
274,
481,
5456,
90,
1933,
4451,
337,
90,
80,
1778,
84,
12,
3194,
273,
380,
699,
26,
298,
199,
2798,
63,
3270,
63,
505,
3322,
275,
519,
2,
3673,
72,
4451,
4478,
26294,
16921,
1390,
11744,
552,
481,
5456,
5193,
3194,
273,
380,
437,
1553,
3194,
273,
380,
699,
26,
2672,
60,
2918,
2487,
971,
10865,
91,
70,
7348,
75,
33,
4863,
91,
70,
7348,
75,
34,
4863,
60,
7279,
71,
92,
7348,
75,
29,
46,
4189,
51,
93,
971,
16815,
298,
435,
620,
8,
5646,
63,
988,
63,
6884,
9,
435,
7880,
2,
199,
2798,
63,
5646,
63,
1842,
63,
1302,
420,
275,
519,
2,
37,
17081,
1597,
914,
351,
481,
5456,
90,
1235,
264,
1158,
26,
2672,
70,
7348,
827,
93,
275,
298,
435,
620,
8,
70,
827,
9,
435,
519,
2,
4,
13026,
330,
374,
2672,
70,
7348,
988,
93,
275,
298,
435,
620,
8,
70,
988,
9,
435,
519,
2,
4,
13026,
2,
199,
2798,
63,
890,
63,
30264,
258,
275,
5504,
199,
2798,
63,
3467,
63,
88,
5185,
275,
283,
793,
7,
199,
2798,
63,
1302,
63,
88,
5185,
275,
519,
2,
38,
5456,
90,
18618,
1933,
4451,
337,
90,
80,
1778,
1086,
334,
13026,
2924,
199,
2798,
63,
17,
63,
1302,
63,
89,
3777,
275,
283,
75,
334,
23994,
426,
2104,
26908,
3171,
199,
2798,
63,
17,
63,
1213,
5185,
275,
519,
2,
3673,
3845,
1158,
1933,
4451,
337,
90,
80,
1778,
84,
509,
278,
6066,
12,
325,
2026,
75,
280,
86,
2236,
303,
31919,
351,
481,
5456,
90,
1235,
264,
1158,
5424,
435,
620,
8,
70,
827,
9,
435,
298,
30152,
330,
374,
298,
435,
620,
8,
31381,
63,
11132,
9,
435,
298,
30152,
12,
298,
435,
620,
8,
78,
8382,
11,
17,
9,
435,
298,
510,
1778,
266,
2,
199,
89,
63,
4175,
63,
674,
8295,
275,
446,
18,
199,
89,
63,
4175,
63,
6260,
463,
275,
302,
8382,
435,
499,
199,
88,
63,
4175,
63,
674,
8295,
275,
378,
14,
1822,
627,
289,
827,
199,
88,
63,
4175,
63,
6260,
463,
275,
413,
14,
1153,
627,
289,
827,
627,
289,
988,
421,
199,
3,
9527,
518,
8492,
199,
3,
7958,
4501,
367,
9857,
3114,
9668,
327,
199,
3,
9527,
518,
8492,
199,
78,
8540,
275,
980,
14,
11649,
8,
16,
12,
78,
8382,
12,
78,
8382,
9,
199,
1474,
18810,
3777,
275,
980,
14,
21775,
5086,
1532,
8,
1474,
12,
17,
12,
17,
9,
199,
11132,
63,
4106,
63,
1753,
275,
289,
827,
10,
1474,
18810,
8,
78,
10,
793,
8,
70,
988,
13,
70,
827,
2447,
78,
8382,
9,
199,
11132,
63,
4106,
63,
1222,
275,
1437,
18810,
1332,
17,
13,
78,
15,
78,
8382,
3342,
793,
8,
70,
827,
430,
627,
1437,
18810,
8,
78,
10,
793,
8,
70,
988,
2447,
78,
8382,
9,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CompassionCH/l10n-switzerland
|
l10n_ch_fds_upload_dd/__manifest__.py
|
1
|
1739
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Swiss Postfinance File Delivery Services module for Odoo
# Copyright (C) 2015 Compassion CH
# @author: Nicolas Tran
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Swiss Postfinance FDS Direct Debit Upload',
'summary': 'Upload Direct Debit files to FDS PostFinance',
'version': '10.0.1.0.1',
'license': 'AGPL-3',
'author': 'Compassion CH, Odoo Community Association (OCA)',
'website': 'http://www.compassion.ch/',
'category': 'Finance',
'depends': [
'l10n_ch_fds_postfinance',
'l10n_ch_lsv_dd',
],
'external_dependencies': {
'python': ['pysftp']
},
'data': [
'views/payment_order_upload_dd_wizard_view.xml',
'views/fds_postfinance_account_dd_view.xml',
'security/ir.model.access.csv',
],
'images': [],
'demo': [],
'test': [],
'installable': True,
'auto_install': False,
}
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
16666,
19857,
7711,
2408,
554,
3814,
1487,
317,
2588,
21813,
859,
367,
28935,
199,
3,
259,
1898,
334,
35,
9,
6900,
3599,
305,
438,
6624,
199,
3,
259,
768,
2502,
26,
30650,
761,
305,
19894,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
10941,
19857,
7711,
2408,
554,
481,
3177,
21128,
1487,
2075,
19149,
297,
272,
283,
4705,
356,
283,
10301,
21128,
1487,
2075,
1584,
370,
481,
3177,
7711,
8694,
554,
297,
272,
283,
1023,
356,
283,
709,
14,
16,
14,
17,
14,
16,
14,
17,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
2502,
356,
283,
2404,
305,
438,
6624,
12,
28935,
7046,
6639,
24207,
425,
334,
47,
3263,
3196,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
863,
305,
438,
14,
335,
3678,
272,
283,
3710,
356,
283,
8694,
554,
297,
272,
283,
8912,
356,
359,
267,
283,
76,
709,
78,
63,
335,
63,
14240,
63,
1932,
2408,
554,
297,
267,
283,
76,
709,
78,
63,
335,
63,
478,
86,
63,
617,
297,
272,
2156,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
356,
788,
15983,
8915,
418,
272,
1660,
272,
283,
576,
356,
359,
267,
283,
4196,
15,
7948,
63,
1648,
63,
5064,
63,
617,
63,
9819,
63,
1345,
14,
1652,
297,
267,
283,
4196,
15,
14240,
63,
1932,
2408,
554,
63,
2048,
63,
617,
63,
1345,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
272,
2156,
272,
283,
4782,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
16666,
19857,
7711,
2408,
554,
3814,
1487,
317,
2588,
21813,
859,
367,
28935,
199,
3,
259,
1898,
334,
35,
9,
6900,
3599,
305,
438,
6624,
199,
3,
259,
768,
2502,
26,
30650,
761,
305,
19894,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
91,
272,
283,
354,
356,
283,
10941,
19857,
7711,
2408,
554,
481,
3177,
21128,
1487,
2075,
19149,
297,
272,
283,
4705,
356,
283,
10301,
21128,
1487,
2075,
1584,
370,
481,
3177,
7711,
8694,
554,
297,
272,
283,
1023,
356,
283,
709,
14,
16,
14,
17,
14,
16,
14,
17,
297,
272,
283,
1682,
356,
283,
1254,
2749,
13,
19,
297,
272,
283,
2502,
356,
283,
2404,
305,
438,
6624,
12,
28935,
7046,
6639,
24207,
425,
334,
47,
3263,
3196,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
863,
305,
438,
14,
335,
3678,
272,
283,
3710,
356,
283,
8694,
554,
297,
272,
283,
8912,
356,
359,
267,
283,
76,
709,
78,
63,
335,
63,
14240,
63,
1932,
2408,
554,
297,
267,
283,
76,
709,
78,
63,
335,
63,
478,
86,
63,
617,
297,
272,
2156,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
356,
788,
15983,
8915,
418,
272,
1660,
272,
283,
576,
356,
359,
267,
283,
4196,
15,
7948,
63,
1648,
63,
5064,
63,
617,
63,
9819,
63,
1345,
14,
1652,
297,
267,
283,
4196,
15,
14240,
63,
1932,
2408,
554,
63,
2048,
63,
617,
63,
1345,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
272,
2156,
272,
283,
4782,
356,
990,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
chemelnucfin/tensorflow
|
tensorflow/python/debug/cli/analyzer_cli.py
|
5
|
58700
|
# 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.
# ==============================================================================
"""CLI Backend for the Analyzer Part of the Debugger.
The analyzer performs post hoc analysis of dumped intermediate tensors and
graph structure information from debugged Session.run() calls.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import copy
import re
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.python.debug.cli import cli_config
from tensorflow.python.debug.cli import cli_shared
from tensorflow.python.debug.cli import command_parser
from tensorflow.python.debug.cli import debugger_cli_common
from tensorflow.python.debug.cli import evaluator
from tensorflow.python.debug.cli import ui_factory
from tensorflow.python.debug.lib import debug_graphs
from tensorflow.python.debug.lib import source_utils
RL = debugger_cli_common.RichLine
# String constants for the depth-dependent hanging indent at the beginning
# of each line.
HANG_UNFINISHED = "| " # Used for unfinished recursion depths.
HANG_FINISHED = " "
HANG_SUFFIX = "|- "
# String constant for displaying depth and op type.
DEPTH_TEMPLATE = "(%d) "
OP_TYPE_TEMPLATE = "[%s] "
# String constants for control inputs/outputs, etc.
CTRL_LABEL = "(Ctrl) "
ELLIPSIS = "..."
SORT_TENSORS_BY_TIMESTAMP = "timestamp"
SORT_TENSORS_BY_DUMP_SIZE = "dump_size"
SORT_TENSORS_BY_OP_TYPE = "op_type"
SORT_TENSORS_BY_TENSOR_NAME = "tensor_name"
def _add_main_menu(output,
node_name=None,
enable_list_tensors=True,
enable_node_info=True,
enable_print_tensor=True,
enable_list_inputs=True,
enable_list_outputs=True):
"""Generate main menu for the screen output from a command.
Args:
output: (debugger_cli_common.RichTextLines) the output object to modify.
node_name: (str or None) name of the node involved (if any). If None,
the menu items node_info, list_inputs and list_outputs will be
automatically disabled, overriding the values of arguments
enable_node_info, enable_list_inputs and enable_list_outputs.
enable_list_tensors: (bool) whether the list_tensor menu item will be
enabled.
enable_node_info: (bool) whether the node_info item will be enabled.
enable_print_tensor: (bool) whether the print_tensor item will be enabled.
enable_list_inputs: (bool) whether the item list_inputs will be enabled.
enable_list_outputs: (bool) whether the item list_outputs will be enabled.
"""
menu = debugger_cli_common.Menu()
menu.append(
debugger_cli_common.MenuItem(
"list_tensors", "list_tensors", enabled=enable_list_tensors))
if node_name:
menu.append(
debugger_cli_common.MenuItem(
"node_info",
"node_info -a -d -t %s" % node_name,
enabled=enable_node_info))
menu.append(
debugger_cli_common.MenuItem(
"print_tensor",
"print_tensor %s" % node_name,
enabled=enable_print_tensor))
menu.append(
debugger_cli_common.MenuItem(
"list_inputs",
"list_inputs -c -r %s" % node_name,
enabled=enable_list_inputs))
menu.append(
debugger_cli_common.MenuItem(
"list_outputs",
"list_outputs -c -r %s" % node_name,
enabled=enable_list_outputs))
else:
menu.append(
debugger_cli_common.MenuItem(
"node_info", None, enabled=False))
menu.append(
debugger_cli_common.MenuItem("print_tensor", None, enabled=False))
menu.append(
debugger_cli_common.MenuItem("list_inputs", None, enabled=False))
menu.append(
debugger_cli_common.MenuItem("list_outputs", None, enabled=False))
menu.append(
debugger_cli_common.MenuItem("run_info", "run_info"))
menu.append(
debugger_cli_common.MenuItem("help", "help"))
output.annotations[debugger_cli_common.MAIN_MENU_KEY] = menu
class DebugAnalyzer(object):
"""Analyzer for debug data from dump directories."""
_TIMESTAMP_COLUMN_HEAD = "t (ms)"
_DUMP_SIZE_COLUMN_HEAD = "Size (B)"
_OP_TYPE_COLUMN_HEAD = "Op type"
_TENSOR_NAME_COLUMN_HEAD = "Tensor name"
# Op types to be omitted when generating descriptions of graph structure.
_GRAPH_STRUCT_OP_TYPE_BLACKLIST = (
"_Send", "_Recv", "_HostSend", "_HostRecv", "_Retval")
def __init__(self, debug_dump, config):
"""DebugAnalyzer constructor.
Args:
debug_dump: A DebugDumpDir object.
config: A `cli_config.CLIConfig` object that carries user-facing
configurations.
"""
self._debug_dump = debug_dump
self._evaluator = evaluator.ExpressionEvaluator(self._debug_dump)
# Initialize tensor filters state.
self._tensor_filters = {}
self._build_argument_parsers(config)
config.set_callback("graph_recursion_depth",
self._build_argument_parsers)
# TODO(cais): Implement list_nodes.
def _build_argument_parsers(self, config):
"""Build argument parsers for DebugAnalayzer.
Args:
config: A `cli_config.CLIConfig` object.
Returns:
A dict mapping command handler name to `ArgumentParser` instance.
"""
# Argument parsers for command handlers.
self._arg_parsers = {}
# Parser for list_tensors.
ap = argparse.ArgumentParser(
description="List dumped intermediate tensors.",
usage=argparse.SUPPRESS)
ap.add_argument(
"-f",
"--tensor_filter",
dest="tensor_filter",
type=str,
default="",
help="List only Tensors passing the filter of the specified name")
ap.add_argument(
"-fenn",
"--filter_exclude_node_names",
dest="filter_exclude_node_names",
type=str,
default="",
help="When applying the tensor filter, exclude node with names "
"matching the regular expression. Applicable only if --tensor_filter "
"or -f is used.")
ap.add_argument(
"-n",
"--node_name_filter",
dest="node_name_filter",
type=str,
default="",
help="filter node name by regex.")
ap.add_argument(
"-t",
"--op_type_filter",
dest="op_type_filter",
type=str,
default="",
help="filter op type by regex.")
ap.add_argument(
"-s",
"--sort_by",
dest="sort_by",
type=str,
default=SORT_TENSORS_BY_TIMESTAMP,
help=("the field to sort the data by: (%s | %s | %s | %s)" %
(SORT_TENSORS_BY_TIMESTAMP, SORT_TENSORS_BY_DUMP_SIZE,
SORT_TENSORS_BY_OP_TYPE, SORT_TENSORS_BY_TENSOR_NAME)))
ap.add_argument(
"-r",
"--reverse",
dest="reverse",
action="store_true",
help="sort the data in reverse (descending) order")
self._arg_parsers["list_tensors"] = ap
# Parser for node_info.
ap = argparse.ArgumentParser(
description="Show information about a node.", usage=argparse.SUPPRESS)
ap.add_argument(
"node_name",
type=str,
help="Name of the node or an associated tensor, e.g., "
"hidden1/Wx_plus_b/MatMul, hidden1/Wx_plus_b/MatMul:0")
ap.add_argument(
"-a",
"--attributes",
dest="attributes",
action="store_true",
help="Also list attributes of the node.")
ap.add_argument(
"-d",
"--dumps",
dest="dumps",
action="store_true",
help="Also list dumps available from the node.")
ap.add_argument(
"-t",
"--traceback",
dest="traceback",
action="store_true",
help="Also include the traceback of the node's creation "
"(if available in Python).")
self._arg_parsers["node_info"] = ap
# Parser for list_inputs.
ap = argparse.ArgumentParser(
description="Show inputs to a node.", usage=argparse.SUPPRESS)
ap.add_argument(
"node_name",
type=str,
help="Name of the node or an output tensor from the node, e.g., "
"hidden1/Wx_plus_b/MatMul, hidden1/Wx_plus_b/MatMul:0")
ap.add_argument(
"-c", "--control", action="store_true", help="Include control inputs.")
ap.add_argument(
"-d",
"--depth",
dest="depth",
type=int,
default=config.get("graph_recursion_depth"),
help="Maximum depth of recursion used when showing the input tree.")
ap.add_argument(
"-r",
"--recursive",
dest="recursive",
action="store_true",
help="Show inputs to the node recursively, i.e., the input tree.")
ap.add_argument(
"-t",
"--op_type",
action="store_true",
help="Show op types of input nodes.")
self._arg_parsers["list_inputs"] = ap
# Parser for list_outputs.
ap = argparse.ArgumentParser(
description="Show the nodes that receive the outputs of given node.",
usage=argparse.SUPPRESS)
ap.add_argument(
"node_name",
type=str,
help="Name of the node or an output tensor from the node, e.g., "
"hidden1/Wx_plus_b/MatMul, hidden1/Wx_plus_b/MatMul:0")
ap.add_argument(
"-c", "--control", action="store_true", help="Include control inputs.")
ap.add_argument(
"-d",
"--depth",
dest="depth",
type=int,
default=config.get("graph_recursion_depth"),
help="Maximum depth of recursion used when showing the output tree.")
ap.add_argument(
"-r",
"--recursive",
dest="recursive",
action="store_true",
help="Show recipients of the node recursively, i.e., the output "
"tree.")
ap.add_argument(
"-t",
"--op_type",
action="store_true",
help="Show op types of recipient nodes.")
self._arg_parsers["list_outputs"] = ap
# Parser for print_tensor.
self._arg_parsers["print_tensor"] = (
command_parser.get_print_tensor_argparser(
"Print the value of a dumped tensor."))
# Parser for print_source.
ap = argparse.ArgumentParser(
description="Print a Python source file with overlaid debug "
"information, including the nodes (ops) or Tensors created at the "
"source lines.",
usage=argparse.SUPPRESS)
ap.add_argument(
"source_file_path",
type=str,
help="Path to the source file.")
ap.add_argument(
"-t",
"--tensors",
dest="tensors",
action="store_true",
help="Label lines with dumped Tensors, instead of ops.")
ap.add_argument(
"-m",
"--max_elements_per_line",
type=int,
default=10,
help="Maximum number of elements (ops or Tensors) to show per source "
"line.")
ap.add_argument(
"-b",
"--line_begin",
type=int,
default=1,
help="Print source beginning at line number (1-based.)")
self._arg_parsers["print_source"] = ap
# Parser for list_source.
ap = argparse.ArgumentParser(
description="List source files responsible for constructing nodes and "
"tensors present in the run().",
usage=argparse.SUPPRESS)
ap.add_argument(
"-p",
"--path_filter",
type=str,
default="",
help="Regular expression filter for file path.")
ap.add_argument(
"-n",
"--node_name_filter",
type=str,
default="",
help="Regular expression filter for node name.")
self._arg_parsers["list_source"] = ap
# Parser for eval.
ap = argparse.ArgumentParser(
description="""Evaluate an arbitrary expression. Can use tensor values
from the current debug dump. The debug tensor names should be enclosed
in pairs of backticks. Expressions with spaces should be enclosed in
a pair of double quotes or a pair of single quotes. By default, numpy
is imported as np and can be used in the expressions. E.g.,
1) eval np.argmax(`Softmax:0`),
2) eval 'np.sum(`Softmax:0`, axis=1)',
3) eval "np.matmul((`output/Identity:0`/`Softmax:0`).T, `Softmax:0`)".
""",
usage=argparse.SUPPRESS)
ap.add_argument(
"expression",
type=str,
help="""Expression to be evaluated.
1) in the simplest case, use <node_name>:<output_slot>, e.g.,
hidden_0/MatMul:0.
2) if the default debug op "DebugIdentity" is to be overridden, use
<node_name>:<output_slot>:<debug_op>, e.g.,
hidden_0/MatMul:0:DebugNumericSummary.
3) if the tensor of the same name exists on more than one device, use
<device_name>:<node_name>:<output_slot>[:<debug_op>], e.g.,
/job:worker/replica:0/task:0/gpu:0:hidden_0/MatMul:0
/job:worker/replica:0/task:2/cpu:0:hidden_0/MatMul:0:DebugNanCount.
4) if the tensor is executed multiple times in a given `Session.run`
call, specify the execution index with a 0-based integer enclose in a
pair of brackets at the end, e.g.,
RNN/tanh:0[0]
/job:worker/replica:0/task:0/gpu:0:RNN/tanh:0[0].""")
ap.add_argument(
"-a",
"--all",
dest="print_all",
action="store_true",
help="Print the tensor in its entirety, i.e., do not use ellipses "
"(may be slow for large results).")
ap.add_argument(
"-w",
"--write_path",
default="",
help="Path of the numpy file to write the evaluation result to, "
"using numpy.save()")
self._arg_parsers["eval"] = ap
def add_tensor_filter(self, filter_name, filter_callable):
"""Add a tensor filter.
A tensor filter is a named callable of the signature:
filter_callable(dump_datum, tensor),
wherein dump_datum is an instance of debug_data.DebugTensorDatum carrying
metadata about the dumped tensor, including tensor name, timestamps, etc.
tensor is the value of the dumped tensor as an numpy.ndarray object.
The return value of the function is a bool.
This is the same signature as the input argument to
debug_data.DebugDumpDir.find().
Args:
filter_name: (str) name of the filter. Cannot be empty.
filter_callable: (callable) a filter function of the signature described
as above.
Raises:
ValueError: If filter_name is an empty str.
TypeError: If filter_name is not a str.
Or if filter_callable is not callable.
"""
if not isinstance(filter_name, str):
raise TypeError("Input argument filter_name is expected to be str, "
"but is not.")
# Check that filter_name is not an empty str.
if not filter_name:
raise ValueError("Input argument filter_name cannot be empty.")
# Check that filter_callable is callable.
if not callable(filter_callable):
raise TypeError(
"Input argument filter_callable is expected to be callable, "
"but is not.")
self._tensor_filters[filter_name] = filter_callable
def get_tensor_filter(self, filter_name):
"""Retrieve filter function by name.
Args:
filter_name: Name of the filter set during add_tensor_filter() call.
Returns:
The callable associated with the filter name.
Raises:
ValueError: If there is no tensor filter of the specified filter name.
"""
if filter_name not in self._tensor_filters:
raise ValueError("There is no tensor filter named \"%s\"" % filter_name)
return self._tensor_filters[filter_name]
def get_help(self, handler_name):
return self._arg_parsers[handler_name].format_help()
def list_tensors(self, args, screen_info=None):
"""Command handler for list_tensors.
List tensors dumped during debugged Session.run() call.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
Raises:
ValueError: If `--filter_exclude_node_names` is used without `-f` or
`--tensor_filter` being used.
"""
# TODO(cais): Add annotations of substrings for dumped tensor names, to
# facilitate on-screen highlighting/selection of node names.
_ = screen_info
parsed = self._arg_parsers["list_tensors"].parse_args(args)
output = []
filter_strs = []
if parsed.op_type_filter:
op_type_regex = re.compile(parsed.op_type_filter)
filter_strs.append("Op type regex filter: \"%s\"" % parsed.op_type_filter)
else:
op_type_regex = None
if parsed.node_name_filter:
node_name_regex = re.compile(parsed.node_name_filter)
filter_strs.append("Node name regex filter: \"%s\"" %
parsed.node_name_filter)
else:
node_name_regex = None
output = debugger_cli_common.RichTextLines(filter_strs)
output.append("")
if parsed.tensor_filter:
try:
filter_callable = self.get_tensor_filter(parsed.tensor_filter)
except ValueError:
output = cli_shared.error("There is no tensor filter named \"%s\"." %
parsed.tensor_filter)
_add_main_menu(output, node_name=None, enable_list_tensors=False)
return output
data_to_show = self._debug_dump.find(
filter_callable,
exclude_node_names=parsed.filter_exclude_node_names)
else:
if parsed.filter_exclude_node_names:
raise ValueError(
"The flag --filter_exclude_node_names is valid only when "
"the flag -f or --tensor_filter is used.")
data_to_show = self._debug_dump.dumped_tensor_data
# TODO(cais): Implement filter by lambda on tensor value.
max_timestamp_width, max_dump_size_width, max_op_type_width = (
self._measure_tensor_list_column_widths(data_to_show))
# Sort the data.
data_to_show = self._sort_dump_data_by(
data_to_show, parsed.sort_by, parsed.reverse)
output.extend(
self._tensor_list_column_heads(parsed, max_timestamp_width,
max_dump_size_width, max_op_type_width))
dump_count = 0
for dump in data_to_show:
if node_name_regex and not node_name_regex.match(dump.node_name):
continue
if op_type_regex:
op_type = self._debug_dump.node_op_type(dump.node_name)
if not op_type_regex.match(op_type):
continue
rel_time = (dump.timestamp - self._debug_dump.t0) / 1000.0
dump_size_str = cli_shared.bytes_to_readable_str(dump.dump_size_bytes)
dumped_tensor_name = "%s:%d" % (dump.node_name, dump.output_slot)
op_type = self._debug_dump.node_op_type(dump.node_name)
line = "[%.3f]" % rel_time
line += " " * (max_timestamp_width - len(line))
line += dump_size_str
line += " " * (max_timestamp_width + max_dump_size_width - len(line))
line += op_type
line += " " * (max_timestamp_width + max_dump_size_width +
max_op_type_width - len(line))
line += dumped_tensor_name
output.append(
line,
font_attr_segs=[(
len(line) - len(dumped_tensor_name), len(line),
debugger_cli_common.MenuItem("", "pt %s" % dumped_tensor_name))])
dump_count += 1
if parsed.tensor_filter:
output.prepend([
"%d dumped tensor(s) passing filter \"%s\":" %
(dump_count, parsed.tensor_filter)
])
else:
output.prepend(["%d dumped tensor(s):" % dump_count])
_add_main_menu(output, node_name=None, enable_list_tensors=False)
return output
def _measure_tensor_list_column_widths(self, data):
"""Determine the maximum widths of the timestamp and op-type column.
This method assumes that data is sorted in the default order, i.e.,
by ascending timestamps.
Args:
data: (list of DebugTensorDaum) the data based on which the maximum
column widths will be determined.
Returns:
(int) maximum width of the timestamp column. 0 if data is empty.
(int) maximum width of the dump size column. 0 if data is empty.
(int) maximum width of the op type column. 0 if data is empty.
"""
max_timestamp_width = 0
if data:
max_rel_time_ms = (data[-1].timestamp - self._debug_dump.t0) / 1000.0
max_timestamp_width = len("[%.3f] " % max_rel_time_ms) + 1
max_timestamp_width = max(max_timestamp_width,
len(self._TIMESTAMP_COLUMN_HEAD) + 1)
max_dump_size_width = 0
for dump in data:
dump_size_str = cli_shared.bytes_to_readable_str(dump.dump_size_bytes)
if len(dump_size_str) + 1 > max_dump_size_width:
max_dump_size_width = len(dump_size_str) + 1
max_dump_size_width = max(max_dump_size_width,
len(self._DUMP_SIZE_COLUMN_HEAD) + 1)
max_op_type_width = 0
for dump in data:
op_type = self._debug_dump.node_op_type(dump.node_name)
if len(op_type) + 1 > max_op_type_width:
max_op_type_width = len(op_type) + 1
max_op_type_width = max(max_op_type_width,
len(self._OP_TYPE_COLUMN_HEAD) + 1)
return max_timestamp_width, max_dump_size_width, max_op_type_width
def _sort_dump_data_by(self, data, sort_by, reverse):
"""Sort a list of DebugTensorDatum in specified order.
Args:
data: (list of DebugTensorDatum) the data to be sorted.
sort_by: The field to sort data by.
reverse: (bool) Whether to use reversed (descending) order.
Returns:
(list of DebugTensorDatum) in sorted order.
Raises:
ValueError: given an invalid value of sort_by.
"""
if sort_by == SORT_TENSORS_BY_TIMESTAMP:
return sorted(
data,
reverse=reverse,
key=lambda x: x.timestamp)
elif sort_by == SORT_TENSORS_BY_DUMP_SIZE:
return sorted(data, reverse=reverse, key=lambda x: x.dump_size_bytes)
elif sort_by == SORT_TENSORS_BY_OP_TYPE:
return sorted(
data,
reverse=reverse,
key=lambda x: self._debug_dump.node_op_type(x.node_name))
elif sort_by == SORT_TENSORS_BY_TENSOR_NAME:
return sorted(
data,
reverse=reverse,
key=lambda x: "%s:%d" % (x.node_name, x.output_slot))
else:
raise ValueError("Unsupported key to sort tensors by: %s" % sort_by)
def _tensor_list_column_heads(self, parsed, max_timestamp_width,
max_dump_size_width, max_op_type_width):
"""Generate a line containing the column heads of the tensor list.
Args:
parsed: Parsed arguments (by argparse) of the list_tensors command.
max_timestamp_width: (int) maximum width of the timestamp column.
max_dump_size_width: (int) maximum width of the dump size column.
max_op_type_width: (int) maximum width of the op type column.
Returns:
A RichTextLines object.
"""
base_command = "list_tensors"
if parsed.tensor_filter:
base_command += " -f %s" % parsed.tensor_filter
if parsed.op_type_filter:
base_command += " -t %s" % parsed.op_type_filter
if parsed.node_name_filter:
base_command += " -n %s" % parsed.node_name_filter
attr_segs = {0: []}
row = self._TIMESTAMP_COLUMN_HEAD
command = "%s -s %s" % (base_command, SORT_TENSORS_BY_TIMESTAMP)
if parsed.sort_by == SORT_TENSORS_BY_TIMESTAMP and not parsed.reverse:
command += " -r"
attr_segs[0].append(
(0, len(row), [debugger_cli_common.MenuItem(None, command), "bold"]))
row += " " * (max_timestamp_width - len(row))
prev_len = len(row)
row += self._DUMP_SIZE_COLUMN_HEAD
command = "%s -s %s" % (base_command, SORT_TENSORS_BY_DUMP_SIZE)
if parsed.sort_by == SORT_TENSORS_BY_DUMP_SIZE and not parsed.reverse:
command += " -r"
attr_segs[0].append((prev_len, len(row),
[debugger_cli_common.MenuItem(None, command), "bold"]))
row += " " * (max_dump_size_width + max_timestamp_width - len(row))
prev_len = len(row)
row += self._OP_TYPE_COLUMN_HEAD
command = "%s -s %s" % (base_command, SORT_TENSORS_BY_OP_TYPE)
if parsed.sort_by == SORT_TENSORS_BY_OP_TYPE and not parsed.reverse:
command += " -r"
attr_segs[0].append((prev_len, len(row),
[debugger_cli_common.MenuItem(None, command), "bold"]))
row += " " * (
max_op_type_width + max_dump_size_width + max_timestamp_width - len(row)
)
prev_len = len(row)
row += self._TENSOR_NAME_COLUMN_HEAD
command = "%s -s %s" % (base_command, SORT_TENSORS_BY_TENSOR_NAME)
if parsed.sort_by == SORT_TENSORS_BY_TENSOR_NAME and not parsed.reverse:
command += " -r"
attr_segs[0].append((prev_len, len(row),
[debugger_cli_common.MenuItem("", command), "bold"]))
row += " " * (
max_op_type_width + max_dump_size_width + max_timestamp_width - len(row)
)
return debugger_cli_common.RichTextLines([row], font_attr_segs=attr_segs)
def node_info(self, args, screen_info=None):
"""Command handler for node_info.
Query information about a given node.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
"""
# TODO(cais): Add annotation of substrings for node names, to facilitate
# on-screen highlighting/selection of node names.
_ = screen_info
parsed = self._arg_parsers["node_info"].parse_args(args)
# Get a node name, regardless of whether the input is a node name (without
# output slot attached) or a tensor name (with output slot attached).
node_name, unused_slot = debug_graphs.parse_node_or_tensor_name(
parsed.node_name)
if not self._debug_dump.node_exists(node_name):
output = cli_shared.error(
"There is no node named \"%s\" in the partition graphs" % node_name)
_add_main_menu(
output,
node_name=None,
enable_list_tensors=True,
enable_node_info=False,
enable_list_inputs=False,
enable_list_outputs=False)
return output
# TODO(cais): Provide UI glossary feature to explain to users what the
# term "partition graph" means and how it is related to TF graph objects
# in Python. The information can be along the line of:
# "A tensorflow graph defined in Python is stripped of unused ops
# according to the feeds and fetches and divided into a number of
# partition graphs that may be distributed among multiple devices and
# hosts. The partition graphs are what's actually executed by the C++
# runtime during a run() call."
lines = ["Node %s" % node_name]
font_attr_segs = {
0: [(len(lines[-1]) - len(node_name), len(lines[-1]), "bold")]
}
lines.append("")
lines.append(" Op: %s" % self._debug_dump.node_op_type(node_name))
lines.append(" Device: %s" % self._debug_dump.node_device(node_name))
output = debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs)
# List node inputs (non-control and control).
inputs = self._exclude_blacklisted_ops(
self._debug_dump.node_inputs(node_name))
ctrl_inputs = self._exclude_blacklisted_ops(
self._debug_dump.node_inputs(node_name, is_control=True))
output.extend(self._format_neighbors("input", inputs, ctrl_inputs))
# List node output recipients (non-control and control).
recs = self._exclude_blacklisted_ops(
self._debug_dump.node_recipients(node_name))
ctrl_recs = self._exclude_blacklisted_ops(
self._debug_dump.node_recipients(node_name, is_control=True))
output.extend(self._format_neighbors("recipient", recs, ctrl_recs))
# Optional: List attributes of the node.
if parsed.attributes:
output.extend(self._list_node_attributes(node_name))
# Optional: List dumps available from the node.
if parsed.dumps:
output.extend(self._list_node_dumps(node_name))
if parsed.traceback:
output.extend(self._render_node_traceback(node_name))
_add_main_menu(output, node_name=node_name, enable_node_info=False)
return output
def _exclude_blacklisted_ops(self, node_names):
"""Exclude all nodes whose op types are in _GRAPH_STRUCT_OP_TYPE_BLACKLIST.
Args:
node_names: An iterable of node or graph element names.
Returns:
A list of node names that are not blacklisted.
"""
return [node_name for node_name in node_names
if self._debug_dump.node_op_type(
debug_graphs.get_node_name(node_name)) not in
self._GRAPH_STRUCT_OP_TYPE_BLACKLIST]
def _render_node_traceback(self, node_name):
"""Render traceback of a node's creation in Python, if available.
Args:
node_name: (str) name of the node.
Returns:
A RichTextLines object containing the stack trace of the node's
construction.
"""
lines = [RL(""), RL(""), RL("Traceback of node construction:", "bold")]
try:
node_stack = self._debug_dump.node_traceback(node_name)
for depth, (file_path, line, function_name, text) in enumerate(
node_stack):
lines.append("%d: %s" % (depth, file_path))
attribute = debugger_cli_common.MenuItem(
"", "ps %s -b %d" % (file_path, line)) if text else None
line_number_line = RL(" ")
line_number_line += RL("Line: %d" % line, attribute)
lines.append(line_number_line)
lines.append(" Function: %s" % function_name)
lines.append(" Text: " + (("\"%s\"" % text) if text else "None"))
lines.append("")
except KeyError:
lines.append("(Node unavailable in the loaded Python graph)")
except LookupError:
lines.append("(Unavailable because no Python graph has been loaded)")
return debugger_cli_common.rich_text_lines_from_rich_line_list(lines)
def list_inputs(self, args, screen_info=None):
"""Command handler for inputs.
Show inputs to a given node.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
"""
# Screen info not currently used by this handler. Include this line to
# mute pylint.
_ = screen_info
# TODO(cais): Use screen info to format the output lines more prettily,
# e.g., hanging indent of long node names.
parsed = self._arg_parsers["list_inputs"].parse_args(args)
output = self._list_inputs_or_outputs(
parsed.recursive,
parsed.node_name,
parsed.depth,
parsed.control,
parsed.op_type,
do_outputs=False)
node_name = debug_graphs.get_node_name(parsed.node_name)
_add_main_menu(output, node_name=node_name, enable_list_inputs=False)
return output
def print_tensor(self, args, screen_info=None):
"""Command handler for print_tensor.
Print value of a given dumped tensor.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
"""
parsed = self._arg_parsers["print_tensor"].parse_args(args)
np_printoptions = cli_shared.numpy_printoptions_from_screen_info(
screen_info)
# Determine if any range-highlighting is required.
highlight_options = cli_shared.parse_ranges_highlight(parsed.ranges)
tensor_name, tensor_slicing = (
command_parser.parse_tensor_name_with_slicing(parsed.tensor_name))
node_name, output_slot = debug_graphs.parse_node_or_tensor_name(tensor_name)
if (self._debug_dump.loaded_partition_graphs() and
not self._debug_dump.node_exists(node_name)):
output = cli_shared.error(
"Node \"%s\" does not exist in partition graphs" % node_name)
_add_main_menu(
output,
node_name=None,
enable_list_tensors=True,
enable_print_tensor=False)
return output
watch_keys = self._debug_dump.debug_watch_keys(node_name)
if output_slot is None:
output_slots = set()
for watch_key in watch_keys:
output_slots.add(int(watch_key.split(":")[1]))
if len(output_slots) == 1:
# There is only one dumped tensor from this node, so there is no
# ambiguity. Proceed to show the only dumped tensor.
output_slot = list(output_slots)[0]
else:
# There are more than one dumped tensors from this node. Indicate as
# such.
# TODO(cais): Provide an output screen with command links for
# convenience.
lines = [
"Node \"%s\" generated debug dumps from %s output slots:" %
(node_name, len(output_slots)),
"Please specify the output slot: %s:x." % node_name
]
output = debugger_cli_common.RichTextLines(lines)
_add_main_menu(
output,
node_name=node_name,
enable_list_tensors=True,
enable_print_tensor=False)
return output
# Find debug dump data that match the tensor name (node name + output
# slot).
matching_data = []
for watch_key in watch_keys:
debug_tensor_data = self._debug_dump.watch_key_to_data(watch_key)
for datum in debug_tensor_data:
if datum.output_slot == output_slot:
matching_data.append(datum)
if not matching_data:
# No dump for this tensor.
output = cli_shared.error("Tensor \"%s\" did not generate any dumps." %
parsed.tensor_name)
elif len(matching_data) == 1:
# There is only one dump for this tensor.
if parsed.number <= 0:
output = cli_shared.format_tensor(
matching_data[0].get_tensor(),
matching_data[0].watch_key,
np_printoptions,
print_all=parsed.print_all,
tensor_slicing=tensor_slicing,
highlight_options=highlight_options,
include_numeric_summary=parsed.numeric_summary,
write_path=parsed.write_path)
else:
output = cli_shared.error(
"Invalid number (%d) for tensor %s, which generated one dump." %
(parsed.number, parsed.tensor_name))
_add_main_menu(output, node_name=node_name, enable_print_tensor=False)
else:
# There are more than one dumps for this tensor.
if parsed.number < 0:
lines = [
"Tensor \"%s\" generated %d dumps:" % (parsed.tensor_name,
len(matching_data))
]
font_attr_segs = {}
for i, datum in enumerate(matching_data):
rel_time = (datum.timestamp - self._debug_dump.t0) / 1000.0
lines.append("#%d [%.3f ms] %s" % (i, rel_time, datum.watch_key))
command = "print_tensor %s -n %d" % (parsed.tensor_name, i)
font_attr_segs[len(lines) - 1] = [(
len(lines[-1]) - len(datum.watch_key), len(lines[-1]),
debugger_cli_common.MenuItem(None, command))]
lines.append("")
lines.append(
"You can use the -n (--number) flag to specify which dump to "
"print.")
lines.append("For example:")
lines.append(" print_tensor %s -n 0" % parsed.tensor_name)
output = debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs)
elif parsed.number >= len(matching_data):
output = cli_shared.error(
"Specified number (%d) exceeds the number of available dumps "
"(%d) for tensor %s" %
(parsed.number, len(matching_data), parsed.tensor_name))
else:
output = cli_shared.format_tensor(
matching_data[parsed.number].get_tensor(),
matching_data[parsed.number].watch_key + " (dump #%d)" %
parsed.number,
np_printoptions,
print_all=parsed.print_all,
tensor_slicing=tensor_slicing,
highlight_options=highlight_options,
write_path=parsed.write_path)
_add_main_menu(output, node_name=node_name, enable_print_tensor=False)
return output
def list_outputs(self, args, screen_info=None):
"""Command handler for inputs.
Show inputs to a given node.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
"""
# Screen info not currently used by this handler. Include this line to
# mute pylint.
_ = screen_info
# TODO(cais): Use screen info to format the output lines more prettily,
# e.g., hanging indent of long node names.
parsed = self._arg_parsers["list_outputs"].parse_args(args)
output = self._list_inputs_or_outputs(
parsed.recursive,
parsed.node_name,
parsed.depth,
parsed.control,
parsed.op_type,
do_outputs=True)
node_name = debug_graphs.get_node_name(parsed.node_name)
_add_main_menu(output, node_name=node_name, enable_list_outputs=False)
return output
def evaluate_expression(self, args, screen_info=None):
parsed = self._arg_parsers["eval"].parse_args(args)
eval_res = self._evaluator.evaluate(parsed.expression)
np_printoptions = cli_shared.numpy_printoptions_from_screen_info(
screen_info)
return cli_shared.format_tensor(
eval_res,
"from eval of expression '%s'" % parsed.expression,
np_printoptions,
print_all=parsed.print_all,
include_numeric_summary=True,
write_path=parsed.write_path)
def _reconstruct_print_source_command(self,
parsed,
line_begin,
max_elements_per_line_increase=0):
return "ps %s %s -b %d -m %d" % (
parsed.source_file_path, "-t" if parsed.tensors else "", line_begin,
parsed.max_elements_per_line + max_elements_per_line_increase)
def print_source(self, args, screen_info=None):
"""Print the content of a source file."""
del screen_info # Unused.
parsed = self._arg_parsers["print_source"].parse_args(args)
source_annotation = source_utils.annotate_source(
self._debug_dump,
parsed.source_file_path,
do_dumped_tensors=parsed.tensors)
source_lines, line_num_width = source_utils.load_source(
parsed.source_file_path)
labeled_source_lines = []
actual_initial_scroll_target = 0
for i, line in enumerate(source_lines):
annotated_line = RL("L%d" % (i + 1), cli_shared.COLOR_YELLOW)
annotated_line += " " * (line_num_width - len(annotated_line))
annotated_line += line
labeled_source_lines.append(annotated_line)
if i + 1 == parsed.line_begin:
actual_initial_scroll_target = len(labeled_source_lines) - 1
if i + 1 in source_annotation:
sorted_elements = sorted(source_annotation[i + 1])
for k, element in enumerate(sorted_elements):
if k >= parsed.max_elements_per_line:
omitted_info_line = RL(" (... Omitted %d of %d %s ...) " % (
len(sorted_elements) - parsed.max_elements_per_line,
len(sorted_elements),
"tensor(s)" if parsed.tensors else "op(s)"))
omitted_info_line += RL(
"+5",
debugger_cli_common.MenuItem(
None,
self._reconstruct_print_source_command(
parsed, i + 1, max_elements_per_line_increase=5)))
labeled_source_lines.append(omitted_info_line)
break
label = RL(" " * 4)
if self._debug_dump.debug_watch_keys(
debug_graphs.get_node_name(element)):
attribute = debugger_cli_common.MenuItem("", "pt %s" % element)
else:
attribute = cli_shared.COLOR_BLUE
label += RL(element, attribute)
labeled_source_lines.append(label)
output = debugger_cli_common.rich_text_lines_from_rich_line_list(
labeled_source_lines,
annotations={debugger_cli_common.INIT_SCROLL_POS_KEY:
actual_initial_scroll_target})
_add_main_menu(output, node_name=None)
return output
def _make_source_table(self, source_list, is_tf_py_library):
"""Make a table summarizing the source files that create nodes and tensors.
Args:
source_list: List of source files and related information as a list of
tuples (file_path, is_tf_library, num_nodes, num_tensors, num_dumps,
first_line).
is_tf_py_library: (`bool`) whether this table is for files that belong
to the TensorFlow Python library.
Returns:
The table as a `debugger_cli_common.RichTextLines` object.
"""
path_head = "Source file path"
num_nodes_head = "#(nodes)"
num_tensors_head = "#(tensors)"
num_dumps_head = "#(tensor dumps)"
if is_tf_py_library:
# Use color to mark files that are guessed to belong to TensorFlow Python
# library.
color = cli_shared.COLOR_GRAY
lines = [RL("TensorFlow Python library file(s):", color)]
else:
color = cli_shared.COLOR_WHITE
lines = [RL("File(s) outside TensorFlow Python library:", color)]
if not source_list:
lines.append(RL("[No files.]"))
lines.append(RL())
return debugger_cli_common.rich_text_lines_from_rich_line_list(lines)
path_column_width = max(
max([len(item[0]) for item in source_list]), len(path_head)) + 1
num_nodes_column_width = max(
max([len(str(item[2])) for item in source_list]),
len(num_nodes_head)) + 1
num_tensors_column_width = max(
max([len(str(item[3])) for item in source_list]),
len(num_tensors_head)) + 1
head = RL(path_head + " " * (path_column_width - len(path_head)), color)
head += RL(num_nodes_head + " " * (
num_nodes_column_width - len(num_nodes_head)), color)
head += RL(num_tensors_head + " " * (
num_tensors_column_width - len(num_tensors_head)), color)
head += RL(num_dumps_head, color)
lines.append(head)
for (file_path, _, num_nodes, num_tensors, num_dumps,
first_line_num) in source_list:
path_attributes = [color]
if source_utils.is_extension_uncompiled_python_source(file_path):
path_attributes.append(
debugger_cli_common.MenuItem(None, "ps %s -b %d" %
(file_path, first_line_num)))
line = RL(file_path, path_attributes)
line += " " * (path_column_width - len(line))
line += RL(
str(num_nodes) + " " * (num_nodes_column_width - len(str(num_nodes))),
color)
line += RL(
str(num_tensors) + " " *
(num_tensors_column_width - len(str(num_tensors))), color)
line += RL(str(num_dumps), color)
lines.append(line)
lines.append(RL())
return debugger_cli_common.rich_text_lines_from_rich_line_list(lines)
def list_source(self, args, screen_info=None):
"""List Python source files that constructed nodes and tensors."""
del screen_info # Unused.
parsed = self._arg_parsers["list_source"].parse_args(args)
source_list = source_utils.list_source_files_against_dump(
self._debug_dump,
path_regex_whitelist=parsed.path_filter,
node_name_regex_whitelist=parsed.node_name_filter)
top_lines = [
RL("List of source files that created nodes in this run", "bold")]
if parsed.path_filter:
top_lines.append(
RL("File path regex filter: \"%s\"" % parsed.path_filter))
if parsed.node_name_filter:
top_lines.append(
RL("Node name regex filter: \"%s\"" % parsed.node_name_filter))
top_lines.append(RL())
output = debugger_cli_common.rich_text_lines_from_rich_line_list(top_lines)
if not source_list:
output.append("[No source file information.]")
return output
output.extend(self._make_source_table(
[item for item in source_list if not item[1]], False))
output.extend(self._make_source_table(
[item for item in source_list if item[1]], True))
_add_main_menu(output, node_name=None)
return output
def _list_inputs_or_outputs(self,
recursive,
node_name,
depth,
control,
op_type,
do_outputs=False):
"""Helper function used by list_inputs and list_outputs.
Format a list of lines to display the inputs or output recipients of a
given node.
Args:
recursive: Whether the listing is to be done recursively, as a boolean.
node_name: The name of the node in question, as a str.
depth: Maximum recursion depth, applies only if recursive == True, as an
int.
control: Whether control inputs or control recipients are included, as a
boolean.
op_type: Whether the op types of the nodes are to be included, as a
boolean.
do_outputs: Whether recipients, instead of input nodes are to be
listed, as a boolean.
Returns:
Input or recipient tree formatted as a RichTextLines object.
"""
if do_outputs:
tracker = self._debug_dump.node_recipients
type_str = "Recipients of"
short_type_str = "recipients"
else:
tracker = self._debug_dump.node_inputs
type_str = "Inputs to"
short_type_str = "inputs"
lines = []
font_attr_segs = {}
# Check if this is a tensor name, instead of a node name.
node_name, _ = debug_graphs.parse_node_or_tensor_name(node_name)
# Check if node exists.
if not self._debug_dump.node_exists(node_name):
return cli_shared.error(
"There is no node named \"%s\" in the partition graphs" % node_name)
if recursive:
max_depth = depth
else:
max_depth = 1
if control:
include_ctrls_str = ", control %s included" % short_type_str
else:
include_ctrls_str = ""
line = "%s node \"%s\"" % (type_str, node_name)
font_attr_segs[0] = [(len(line) - 1 - len(node_name), len(line) - 1, "bold")
]
lines.append(line + " (Depth limit = %d%s):" % (max_depth, include_ctrls_str
))
command_template = "lo -c -r %s" if do_outputs else "li -c -r %s"
self._dfs_from_node(
lines,
font_attr_segs,
node_name,
tracker,
max_depth,
1, [],
control,
op_type,
command_template=command_template)
# Include legend.
lines.append("")
lines.append("Legend:")
lines.append(" (d): recursion depth = d.")
if control:
lines.append(" (Ctrl): Control input.")
if op_type:
lines.append(" [Op]: Input node has op type Op.")
# TODO(cais): Consider appending ":0" at the end of 1st outputs of nodes.
return debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs)
def _dfs_from_node(self,
lines,
attr_segs,
node_name,
tracker,
max_depth,
depth,
unfinished,
include_control=False,
show_op_type=False,
command_template=None):
"""Perform depth-first search (DFS) traversal of a node's input tree.
It recursively tracks the inputs (or output recipients) of the node called
node_name, and append these inputs (or output recipients) to a list of text
lines (lines) with proper indentation that reflects the recursion depth,
together with some formatting attributes (to attr_segs). The formatting
attributes can include command shortcuts, for example.
Args:
lines: Text lines to append to, as a list of str.
attr_segs: (dict) Attribute segments dictionary to append to.
node_name: Name of the node, as a str. This arg is updated during the
recursion.
tracker: A callable that takes one str as the node name input and
returns a list of str as the inputs/outputs.
This makes it this function general enough to be used with both
node-input and node-output tracking.
max_depth: Maximum recursion depth, as an int.
depth: Current recursion depth. This arg is updated during the
recursion.
unfinished: A stack of unfinished recursion depths, as a list of int.
include_control: Whether control dependencies are to be included as
inputs (and marked as such).
show_op_type: Whether op type of the input nodes are to be displayed
alongside the nodes' names.
command_template: (str) Template for command shortcut of the node names.
"""
# Make a shallow copy of the list because it may be extended later.
all_inputs = self._exclude_blacklisted_ops(
copy.copy(tracker(node_name, is_control=False)))
is_ctrl = [False] * len(all_inputs)
if include_control:
# Sort control inputs or recipients in alphabetical order of the node
# names.
ctrl_inputs = self._exclude_blacklisted_ops(
sorted(tracker(node_name, is_control=True)))
all_inputs.extend(ctrl_inputs)
is_ctrl.extend([True] * len(ctrl_inputs))
if not all_inputs:
if depth == 1:
lines.append(" [None]")
return
unfinished.append(depth)
# Create depth-dependent hanging indent for the line.
hang = ""
for k in xrange(depth):
if k < depth - 1:
if k + 1 in unfinished:
hang += HANG_UNFINISHED
else:
hang += HANG_FINISHED
else:
hang += HANG_SUFFIX
if all_inputs and depth > max_depth:
lines.append(hang + ELLIPSIS)
unfinished.pop()
return
hang += DEPTH_TEMPLATE % depth
for i, inp in enumerate(all_inputs):
op_type = self._debug_dump.node_op_type(debug_graphs.get_node_name(inp))
if op_type in self._GRAPH_STRUCT_OP_TYPE_BLACKLIST:
continue
if is_ctrl[i]:
ctrl_str = CTRL_LABEL
else:
ctrl_str = ""
op_type_str = ""
if show_op_type:
op_type_str = OP_TYPE_TEMPLATE % op_type
if i == len(all_inputs) - 1:
unfinished.pop()
line = hang + ctrl_str + op_type_str + inp
lines.append(line)
if command_template:
attr_segs[len(lines) - 1] = [(
len(line) - len(inp), len(line),
debugger_cli_common.MenuItem(None, command_template % inp))]
# Recursive call.
# The input's/output's name can be a tensor name, in the case of node
# with >1 output slots.
inp_node_name, _ = debug_graphs.parse_node_or_tensor_name(inp)
self._dfs_from_node(
lines,
attr_segs,
inp_node_name,
tracker,
max_depth,
depth + 1,
unfinished,
include_control=include_control,
show_op_type=show_op_type,
command_template=command_template)
def _format_neighbors(self, neighbor_type, non_ctrls, ctrls):
"""List neighbors (inputs or recipients) of a node.
Args:
neighbor_type: ("input" | "recipient")
non_ctrls: Non-control neighbor node names, as a list of str.
ctrls: Control neighbor node names, as a list of str.
Returns:
A RichTextLines object.
"""
# TODO(cais): Return RichTextLines instead, to allow annotation of node
# names.
lines = []
font_attr_segs = {}
lines.append("")
lines.append(" %d %s(s) + %d control %s(s):" %
(len(non_ctrls), neighbor_type, len(ctrls), neighbor_type))
lines.append(" %d %s(s):" % (len(non_ctrls), neighbor_type))
for non_ctrl in non_ctrls:
line = " [%s] %s" % (self._debug_dump.node_op_type(non_ctrl),
non_ctrl)
lines.append(line)
font_attr_segs[len(lines) - 1] = [(
len(line) - len(non_ctrl), len(line),
debugger_cli_common.MenuItem(None, "ni -a -d -t %s" % non_ctrl))]
if ctrls:
lines.append("")
lines.append(" %d control %s(s):" % (len(ctrls), neighbor_type))
for ctrl in ctrls:
line = " [%s] %s" % (self._debug_dump.node_op_type(ctrl), ctrl)
lines.append(line)
font_attr_segs[len(lines) - 1] = [(
len(line) - len(ctrl), len(line),
debugger_cli_common.MenuItem(None, "ni -a -d -t %s" % ctrl))]
return debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs)
def _list_node_attributes(self, node_name):
"""List neighbors (inputs or recipients) of a node.
Args:
node_name: Name of the node of which the attributes are to be listed.
Returns:
A RichTextLines object.
"""
lines = []
lines.append("")
lines.append("Node attributes:")
attrs = self._debug_dump.node_attributes(node_name)
for attr_key in attrs:
lines.append(" %s:" % attr_key)
attr_val_str = repr(attrs[attr_key]).strip().replace("\n", " ")
lines.append(" %s" % attr_val_str)
lines.append("")
return debugger_cli_common.RichTextLines(lines)
def _list_node_dumps(self, node_name):
"""List dumped tensor data from a node.
Args:
node_name: Name of the node of which the attributes are to be listed.
Returns:
A RichTextLines object.
"""
lines = []
font_attr_segs = {}
watch_keys = self._debug_dump.debug_watch_keys(node_name)
dump_count = 0
for watch_key in watch_keys:
debug_tensor_data = self._debug_dump.watch_key_to_data(watch_key)
for datum in debug_tensor_data:
line = " Slot %d @ %s @ %.3f ms" % (
datum.output_slot, datum.debug_op,
(datum.timestamp - self._debug_dump.t0) / 1000.0)
lines.append(line)
command = "pt %s:%d -n %d" % (node_name, datum.output_slot, dump_count)
font_attr_segs[len(lines) - 1] = [(
2, len(line), debugger_cli_common.MenuItem(None, command))]
dump_count += 1
output = debugger_cli_common.RichTextLines(
lines, font_attr_segs=font_attr_segs)
output_with_header = debugger_cli_common.RichTextLines(
["%d dumped tensor(s):" % dump_count, ""])
output_with_header.extend(output)
return output_with_header
def create_analyzer_ui(debug_dump,
tensor_filters=None,
ui_type="curses",
on_ui_exit=None,
config=None):
"""Create an instance of CursesUI based on a DebugDumpDir object.
Args:
debug_dump: (debug_data.DebugDumpDir) The debug dump to use.
tensor_filters: (dict) A dict mapping tensor filter name (str) to tensor
filter (Callable).
ui_type: (str) requested UI type, e.g., "curses", "readline".
on_ui_exit: (`Callable`) the callback to be called when the UI exits.
config: A `cli_config.CLIConfig` object.
Returns:
(base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer
commands and tab-completions registered.
"""
if config is None:
config = cli_config.CLIConfig()
analyzer = DebugAnalyzer(debug_dump, config=config)
if tensor_filters:
for tensor_filter_name in tensor_filters:
analyzer.add_tensor_filter(
tensor_filter_name, tensor_filters[tensor_filter_name])
cli = ui_factory.get_ui(ui_type, on_ui_exit=on_ui_exit, config=config)
cli.register_command_handler(
"list_tensors",
analyzer.list_tensors,
analyzer.get_help("list_tensors"),
prefix_aliases=["lt"])
cli.register_command_handler(
"node_info",
analyzer.node_info,
analyzer.get_help("node_info"),
prefix_aliases=["ni"])
cli.register_command_handler(
"list_inputs",
analyzer.list_inputs,
analyzer.get_help("list_inputs"),
prefix_aliases=["li"])
cli.register_command_handler(
"list_outputs",
analyzer.list_outputs,
analyzer.get_help("list_outputs"),
prefix_aliases=["lo"])
cli.register_command_handler(
"print_tensor",
analyzer.print_tensor,
analyzer.get_help("print_tensor"),
prefix_aliases=["pt"])
cli.register_command_handler(
"print_source",
analyzer.print_source,
analyzer.get_help("print_source"),
prefix_aliases=["ps"])
cli.register_command_handler(
"list_source",
analyzer.list_source,
analyzer.get_help("list_source"),
prefix_aliases=["ls"])
cli.register_command_handler(
"eval",
analyzer.evaluate_expression,
analyzer.get_help("eval"),
prefix_aliases=["ev"])
dumped_tensor_names = []
for datum in debug_dump.dumped_tensor_data:
dumped_tensor_names.append("%s:%d" % (datum.node_name, datum.output_slot))
# Tab completions for command "print_tensors".
cli.register_tab_comp_context(["print_tensor", "pt"], dumped_tensor_names)
return cli
|
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,
7802,
25674,
367,
314,
14279,
2282,
14320,
402,
314,
14245,
836,
14,
199,
199,
1918,
24608,
18628,
2963,
394,
679,
11284,
402,
31374,
13197,
10519,
436,
199,
2180,
5523,
2556,
687,
3105,
3046,
8596,
14,
1065,
342,
4882,
14,
199,
624,
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,
7534,
199,
646,
1331,
199,
646,
295,
199,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
5053,
63,
888,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
5053,
63,
5555,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
1414,
63,
2087,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
29207,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
8574,
63,
3702,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
16670,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
1350,
63,
1208,
199,
199,
2431,
275,
14958,
63,
2764,
63,
2330,
14,
50,
1158,
3049,
199,
199,
3,
2624,
5262,
367,
314,
5818,
13,
7106,
394,
8544,
4363,
737,
314,
9608,
199,
3,
402,
1924,
1004,
14,
199,
40,
3986,
63,
1734,
17383,
20450,
275,
15733,
221,
298,
221,
327,
8051,
367,
625,
8669,
16189,
5818,
83,
14,
199,
40,
3986,
63,
17383,
20450,
275,
298,
257,
298,
199,
40,
3986,
63,
12273,
275,
15733,
13,
298,
199,
199,
3,
2624,
4413,
367,
20589,
5818,
436,
1687,
730,
14,
199,
19715,
63,
7433,
275,
26448,
68,
9,
298,
199,
1938,
63,
2711,
63,
7433,
275,
26503,
83,
61,
298,
199,
199,
3,
2624,
5262,
367,
3304,
4153,
15,
4467,
12,
5423,
14,
199,
22584,
63,
13837,
275,
7340,
9778,
9,
298,
199,
21677,
275,
298,
11500,
199,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
20277,
275,
298,
3954,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
26406,
63,
4305,
275,
298,
2724,
63,
890,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
1938,
63,
2711,
275,
298,
411,
63,
466,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
52,
17850,
63,
2339,
275,
298,
3128,
63,
354,
2,
421,
199,
318,
485,
525,
63,
973,
63,
4470,
8,
1199,
12,
673,
1031,
63,
354,
29,
403,
12,
673,
4756,
63,
513,
63,
10206,
29,
549,
12,
673,
4756,
63,
932,
63,
815,
29,
549,
12,
673,
4756,
63,
1361,
63,
3128,
29,
549,
12,
673,
4756,
63,
513,
63,
3711,
29,
549,
12,
673,
4756,
63,
513,
63,
4467,
29,
549,
304,
523,
408,
6864,
2446,
6269,
367,
314,
6426,
1072,
687,
282,
1414,
14,
819,
3033,
26,
272,
1072,
26,
334,
17612,
63,
2764,
63,
2330,
14,
19537,
9863,
9,
314,
1072,
909,
370,
2811,
14,
272,
1031,
63,
354,
26,
334,
495,
503,
488,
9,
536,
402,
314,
1031,
28244,
334,
692,
1263,
680,
982,
488,
12,
489,
314,
6269,
2974,
1031,
63,
815,
12,
769,
63,
3711,
436,
769,
63,
4467,
911,
506,
489,
5847,
6980,
12,
18972,
314,
1338,
402,
2368,
489,
4756,
63,
932,
63,
815,
12,
4756,
63,
513,
63,
3711,
436,
4756,
63,
513,
63,
4467,
14,
272,
4756,
63,
513,
63,
10206,
26,
334,
2245,
9,
3775,
314,
769,
63,
3128,
6269,
1242,
911,
506,
489,
5223,
14,
272,
4756,
63,
932,
63,
815,
26,
334,
2245,
9,
3775,
314,
1031,
63,
815,
1242,
911,
506,
5223,
14,
272,
4756,
63,
1361,
63,
3128,
26,
334,
2245,
9,
3775,
314,
870,
63,
3128,
1242,
911,
506,
5223,
14,
272,
4756,
63,
513,
63,
3711,
26,
334,
2245,
9,
3775,
314,
1242,
769,
63,
3711,
911,
506,
5223,
14,
272,
4756,
63,
513,
63,
4467,
26,
334,
2245,
9,
3775,
314,
1242,
769,
63,
4467,
911,
506,
5223,
14,
523,
408,
819,
6269,
275,
14958,
63,
2764,
63,
2330,
14,
5977,
342,
819,
6269,
14,
740,
8,
489,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
881,
298,
513,
63,
10206,
401,
298,
513,
63,
10206,
401,
5223,
29,
4296,
63,
513,
63,
10206,
430,
819,
340,
1031,
63,
354,
26,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
932,
63,
815,
401,
288,
298,
932,
63,
815,
446,
65,
446,
68,
446,
84,
450,
83,
2,
450,
1031,
63,
354,
12,
288,
5223,
29,
4296,
63,
932,
63,
815,
430,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
1361,
63,
3128,
401,
288,
298,
1361,
63,
3128,
450,
83,
2,
450,
1031,
63,
354,
12,
288,
5223,
29,
4296,
63,
1361,
63,
3128,
430,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
513,
63,
3711,
401,
288,
298,
513,
63,
3711,
446,
67,
446,
82,
450,
83,
2,
450,
1031,
63,
354,
12,
288,
5223,
29,
4296,
63,
513,
63,
3711,
430,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
513,
63,
4467
] |
[
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,
7802,
25674,
367,
314,
14279,
2282,
14320,
402,
314,
14245,
836,
14,
199,
199,
1918,
24608,
18628,
2963,
394,
679,
11284,
402,
31374,
13197,
10519,
436,
199,
2180,
5523,
2556,
687,
3105,
3046,
8596,
14,
1065,
342,
4882,
14,
199,
624,
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,
7534,
199,
646,
1331,
199,
646,
295,
199,
199,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
5053,
63,
888,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
5053,
63,
5555,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
1414,
63,
2087,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
29207,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
8574,
63,
3702,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
16670,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
1350,
63,
1208,
199,
199,
2431,
275,
14958,
63,
2764,
63,
2330,
14,
50,
1158,
3049,
199,
199,
3,
2624,
5262,
367,
314,
5818,
13,
7106,
394,
8544,
4363,
737,
314,
9608,
199,
3,
402,
1924,
1004,
14,
199,
40,
3986,
63,
1734,
17383,
20450,
275,
15733,
221,
298,
221,
327,
8051,
367,
625,
8669,
16189,
5818,
83,
14,
199,
40,
3986,
63,
17383,
20450,
275,
298,
257,
298,
199,
40,
3986,
63,
12273,
275,
15733,
13,
298,
199,
199,
3,
2624,
4413,
367,
20589,
5818,
436,
1687,
730,
14,
199,
19715,
63,
7433,
275,
26448,
68,
9,
298,
199,
1938,
63,
2711,
63,
7433,
275,
26503,
83,
61,
298,
199,
199,
3,
2624,
5262,
367,
3304,
4153,
15,
4467,
12,
5423,
14,
199,
22584,
63,
13837,
275,
7340,
9778,
9,
298,
199,
21677,
275,
298,
11500,
199,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
20277,
275,
298,
3954,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
26406,
63,
4305,
275,
298,
2724,
63,
890,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
1938,
63,
2711,
275,
298,
411,
63,
466,
2,
199,
23447,
63,
52,
8456,
4149,
63,
8285,
63,
52,
17850,
63,
2339,
275,
298,
3128,
63,
354,
2,
421,
199,
318,
485,
525,
63,
973,
63,
4470,
8,
1199,
12,
673,
1031,
63,
354,
29,
403,
12,
673,
4756,
63,
513,
63,
10206,
29,
549,
12,
673,
4756,
63,
932,
63,
815,
29,
549,
12,
673,
4756,
63,
1361,
63,
3128,
29,
549,
12,
673,
4756,
63,
513,
63,
3711,
29,
549,
12,
673,
4756,
63,
513,
63,
4467,
29,
549,
304,
523,
408,
6864,
2446,
6269,
367,
314,
6426,
1072,
687,
282,
1414,
14,
819,
3033,
26,
272,
1072,
26,
334,
17612,
63,
2764,
63,
2330,
14,
19537,
9863,
9,
314,
1072,
909,
370,
2811,
14,
272,
1031,
63,
354,
26,
334,
495,
503,
488,
9,
536,
402,
314,
1031,
28244,
334,
692,
1263,
680,
982,
488,
12,
489,
314,
6269,
2974,
1031,
63,
815,
12,
769,
63,
3711,
436,
769,
63,
4467,
911,
506,
489,
5847,
6980,
12,
18972,
314,
1338,
402,
2368,
489,
4756,
63,
932,
63,
815,
12,
4756,
63,
513,
63,
3711,
436,
4756,
63,
513,
63,
4467,
14,
272,
4756,
63,
513,
63,
10206,
26,
334,
2245,
9,
3775,
314,
769,
63,
3128,
6269,
1242,
911,
506,
489,
5223,
14,
272,
4756,
63,
932,
63,
815,
26,
334,
2245,
9,
3775,
314,
1031,
63,
815,
1242,
911,
506,
5223,
14,
272,
4756,
63,
1361,
63,
3128,
26,
334,
2245,
9,
3775,
314,
870,
63,
3128,
1242,
911,
506,
5223,
14,
272,
4756,
63,
513,
63,
3711,
26,
334,
2245,
9,
3775,
314,
1242,
769,
63,
3711,
911,
506,
5223,
14,
272,
4756,
63,
513,
63,
4467,
26,
334,
2245,
9,
3775,
314,
1242,
769,
63,
4467,
911,
506,
5223,
14,
523,
408,
819,
6269,
275,
14958,
63,
2764,
63,
2330,
14,
5977,
342,
819,
6269,
14,
740,
8,
489,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
881,
298,
513,
63,
10206,
401,
298,
513,
63,
10206,
401,
5223,
29,
4296,
63,
513,
63,
10206,
430,
819,
340,
1031,
63,
354,
26,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
932,
63,
815,
401,
288,
298,
932,
63,
815,
446,
65,
446,
68,
446,
84,
450,
83,
2,
450,
1031,
63,
354,
12,
288,
5223,
29,
4296,
63,
932,
63,
815,
430,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330,
14,
20973,
8,
288,
298,
1361,
63,
3128,
401,
288,
298,
1361,
63,
3128,
450,
83,
2,
450,
1031,
63,
354,
12,
288,
5223,
29,
4296,
63,
1361,
63,
3128,
430,
272,
6269,
14,
740,
8,
267,
14958,
63,
2764,
63,
2330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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
] |
mapbased/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/tool/commands/openbugs_unittest.py
|
124
|
2412
|
# Copyright (C) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from webkitpy.tool.commands.commandtest import CommandsTest
from webkitpy.tool.commands.openbugs import OpenBugs
class OpenBugsTest(CommandsTest):
find_bugs_in_string_expectations = [
["123", []],
["1234", ["1234"]],
["12345", ["12345"]],
["123456", ["123456"]],
["1234567", []],
[" 123456 234567", ["123456", "234567"]],
]
def test_find_bugs_in_string(self):
openbugs = OpenBugs()
for expectation in self.find_bugs_in_string_expectations:
self.assertEqual(openbugs._find_bugs_in_string(expectation[0]), expectation[1])
def test_args_parsing(self):
expected_logs = "2 bugs found in input.\nMOCK: user.open_url: http://example.com/12345\nMOCK: user.open_url: http://example.com/23456\n"
self.assert_execute_outputs(OpenBugs(), ["12345\n23456"], expected_logs=expected_logs)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
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,
259,
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,
259,
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,
504,
18007,
14,
3557,
14,
4405,
14,
1531,
396,
492,
5817,
26935,
199,
504,
18007,
14,
3557,
14,
4405,
14,
1490,
13017,
492,
3232,
1713,
458,
199,
199,
533,
3232,
1713,
458,
774,
8,
14680,
774,
304,
339,
2342,
63,
13017,
63,
262,
63,
875,
63,
15752,
275,
359,
267,
2097,
4288,
401,
942,
467,
267,
2097,
4321,
401,
2097,
4321,
18396,
267,
2097,
13261,
401,
2097,
13261,
18396,
267,
2097,
19060,
401,
2097,
19060,
18396,
267,
2097,
30217,
401,
942,
467,
267,
2097,
14763,
1367,
26569,
5308,
401,
2097,
19060,
401,
298,
5533,
5308,
18396,
272,
1622,
339,
347,
511,
63,
1623,
63,
13017,
63,
262,
63,
875,
8,
277,
304,
267,
1551,
13017,
275,
3232,
1713,
458,
342,
267,
367,
17513,
315,
291,
14,
1623,
63,
13017,
63,
262,
63,
875,
63,
15752,
26,
288,
291,
14,
629,
8,
1490,
13017,
423,
1623,
63,
13017,
63,
262,
63,
875,
8,
20838,
59,
16,
2522,
17513,
59,
17,
566,
339,
347,
511,
63,
589,
63,
11059,
8,
277,
304,
267,
1420,
63,
7270,
275,
298,
18,
18227,
1911,
315,
1324,
3134,
78,
17749,
26,
922,
14,
1490,
63,
633,
26,
1455,
921,
2694,
14,
957,
15,
13261,
60,
78,
17749,
26,
922,
14,
1490,
63,
633,
26,
1455,
921,
2694,
14,
957,
15,
5533,
1367,
60,
78,
2,
267,
291,
14,
479,
63,
2526,
63,
4467,
8,
4299,
1713,
458,
1062,
2097,
13261,
60,
78,
5533,
1367,
2255,
1420,
63,
7270,
29,
2062,
63,
7270,
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
] |
[
1898,
334,
35,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
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,
259,
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,
259,
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,
504,
18007,
14,
3557,
14,
4405,
14,
1531,
396,
492,
5817,
26935,
199,
504,
18007,
14,
3557,
14,
4405,
14,
1490,
13017,
492,
3232,
1713,
458,
199,
199,
533,
3232,
1713,
458,
774,
8,
14680,
774,
304,
339,
2342,
63,
13017,
63,
262,
63,
875,
63,
15752,
275,
359,
267,
2097,
4288,
401,
942,
467,
267,
2097,
4321,
401,
2097,
4321,
18396,
267,
2097,
13261,
401,
2097,
13261,
18396,
267,
2097,
19060,
401,
2097,
19060,
18396,
267,
2097,
30217,
401,
942,
467,
267,
2097,
14763,
1367,
26569,
5308,
401,
2097,
19060,
401,
298,
5533,
5308,
18396,
272,
1622,
339,
347,
511,
63,
1623,
63,
13017,
63,
262,
63,
875,
8,
277,
304,
267,
1551,
13017,
275,
3232,
1713,
458,
342,
267,
367,
17513,
315,
291,
14,
1623,
63,
13017,
63,
262,
63,
875,
63,
15752,
26,
288,
291,
14,
629,
8,
1490,
13017,
423,
1623,
63,
13017,
63,
262,
63,
875,
8,
20838,
59,
16,
2522,
17513,
59,
17,
566,
339,
347,
511,
63,
589,
63,
11059,
8,
277,
304,
267,
1420,
63,
7270,
275,
298,
18,
18227,
1911,
315,
1324,
3134,
78,
17749,
26,
922,
14,
1490,
63,
633,
26,
1455,
921,
2694,
14,
957,
15,
13261,
60,
78,
17749,
26,
922,
14,
1490,
63,
633,
26,
1455,
921,
2694,
14,
957,
15,
5533,
1367,
60,
78,
2,
267,
291,
14,
479,
63,
2526,
63,
4467,
8,
4299,
1713,
458,
1062,
2097,
13261,
60,
78,
5533,
1367,
2255,
1420,
63,
7270,
29,
2062,
63,
7270,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
mkhutornenko/incubator-aurora
|
src/main/python/apache/thermos/observer/http/file_browser.py
|
1
|
4015
|
#
# 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 os
from xml.sax.saxutils import escape
import bottle
from twitter.common import log
from twitter.common.http import HttpServer
from .templating import HttpTemplate
MB = 1024 * 1024
DEFAULT_CHUNK_LENGTH = MB
MAX_CHUNK_LENGTH = 16 * MB
def _read_chunk(filename, offset=None, length=None):
offset = offset or -1
length = length or -1
try:
length = long(length)
offset = long(offset)
except ValueError:
return {}
if not os.path.isfile(filename):
return {}
try:
fstat = os.stat(filename)
except Exception as e:
log.error('Could not read from %s: %s' % (filename, e))
return {}
if offset == -1:
offset = fstat.st_size
if length == -1:
length = fstat.st_size - offset
with open(filename, "r") as fp:
fp.seek(offset)
try:
data = fp.read(length)
except IOError as e:
log.error('Failed to read %s: %s' % (filename, e), exc_info=True)
return {}
if data:
return dict(offset=offset, length=len(data), data=escape(data.decode('utf8', 'replace')))
return dict(offset=offset, length=0)
class TaskObserverFileBrowser(object):
"""
Mixin for Thermos observer File browser.
"""
@HttpServer.route("/logs/:task_id/:process/:run/:logtype")
@HttpServer.mako_view(HttpTemplate.load('logbrowse'))
def handle_logs(self, task_id, process, run, logtype):
types = self._observer.logs(task_id, process, int(run))
if logtype not in types:
bottle.abort(404, "No such log type: %s" % logtype)
base, path = types[logtype]
filename = os.path.join(base, path)
return {
'task_id': task_id,
'filename': filename,
'process': process,
'run': run,
'logtype': logtype
}
@HttpServer.route("/logdata/:task_id/:process/:run/:logtype")
def handle_logdata(self, task_id, process, run, logtype):
offset = self.Request.GET.get('offset', -1)
length = self.Request.GET.get('length', -1)
types = self._observer.logs(task_id, process, int(run))
if logtype not in types:
return {}
chroot, path = types[logtype]
return _read_chunk(os.path.join(chroot, path), offset, length)
@HttpServer.route("/file/:task_id/:path#.+#")
@HttpServer.mako_view(HttpTemplate.load('filebrowse'))
def handle_file(self, task_id, path):
if path is None:
bottle.abort(404, "No such file")
return {
'task_id': task_id,
'filename': path,
}
@HttpServer.route("/filedata/:task_id/:path#.+#")
def handle_filedata(self, task_id, path):
if path is None:
return {}
offset = self.Request.GET.get('offset', -1)
length = self.Request.GET.get('length', -1)
chroot, path = self._observer.valid_file(task_id, path)
if chroot is None or path is None:
return {}
return _read_chunk(os.path.join(chroot, path), offset, length)
@HttpServer.route("/browse/:task_id")
@HttpServer.route("/browse/:task_id/:path#.*#")
@HttpServer.mako_view(HttpTemplate.load('filelist'))
def handle_dir(self, task_id, path=None):
if path == "":
path = None
chroot, path = self._observer.valid_path(task_id, path)
return dict(task_id=task_id, chroot=chroot, path=path)
@HttpServer.route("/download/:task_id/:path#.+#")
def handle_download(self, task_id, path=None):
chroot, path = self._observer.valid_path(task_id, path)
if path is None:
bottle.abort(404, "No such file")
return bottle.static_file(path, root=chroot, download=True)
|
apache-2.0
|
[
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,
646,
747,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
199,
646,
5888,
1118,
199,
504,
15811,
14,
2330,
492,
943,
199,
504,
15811,
14,
2330,
14,
1014,
492,
4760,
3120,
199,
199,
504,
1275,
808,
24615,
492,
4760,
4231,
199,
199,
4567,
275,
6619,
627,
6619,
199,
3472,
63,
20512,
63,
9127,
275,
19487,
199,
4283,
63,
20512,
63,
9127,
275,
3193,
627,
19487,
421,
199,
318,
485,
739,
63,
4604,
8,
1501,
12,
3268,
29,
403,
12,
2582,
29,
403,
304,
523,
3268,
275,
3268,
503,
446,
17,
523,
2582,
275,
2582,
503,
446,
17,
819,
862,
26,
272,
2582,
275,
1846,
8,
1267,
9,
272,
3268,
275,
1846,
8,
2743,
9,
523,
871,
1722,
26,
272,
372,
1052,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
1501,
304,
272,
372,
1052,
819,
862,
26,
272,
289,
3736,
275,
747,
14,
3736,
8,
1501,
9,
523,
871,
2186,
465,
325,
26,
272,
943,
14,
705,
360,
6531,
440,
1586,
687,
450,
83,
26,
450,
83,
7,
450,
334,
1501,
12,
325,
430,
272,
372,
1052,
819,
340,
3268,
508,
446,
17,
26,
272,
3268,
275,
289,
3736,
14,
270,
63,
890,
819,
340,
2582,
508,
446,
17,
26,
272,
2582,
275,
289,
3736,
14,
270,
63,
890,
446,
3268,
819,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
4090,
26,
272,
4090,
14,
5507,
8,
2743,
9,
272,
862,
26,
489,
666,
275,
4090,
14,
739,
8,
1267,
9,
272,
871,
5925,
465,
325,
26,
489,
943,
14,
705,
360,
4276,
370,
1586,
450,
83,
26,
450,
83,
7,
450,
334,
1501,
12,
325,
395,
3178,
63,
815,
29,
549,
9,
489,
372,
1052,
819,
340,
666,
26,
272,
372,
1211,
8,
2743,
29,
2743,
12,
2582,
29,
552,
8,
576,
395,
666,
29,
3765,
8,
576,
14,
2708,
360,
1624,
24,
297,
283,
1814,
7058,
819,
372,
1211,
8,
2743,
29,
2743,
12,
2582,
29,
16,
9,
421,
199,
533,
8495,
22715,
1173,
11930,
8,
785,
304,
523,
408,
272,
28438,
367,
377,
2523,
16908,
27336,
3814,
7042,
14,
523,
408,
819,
768,
5779,
3120,
14,
4449,
4769,
7270,
22075,
1765,
63,
344,
22075,
1412,
22075,
1065,
22075,
793,
466,
531,
523,
768,
5779,
3120,
14,
19491,
63,
1345,
8,
5779,
4231,
14,
912,
360,
793,
4570,
1333,
523,
347,
2429,
63,
7270,
8,
277,
12,
2120,
63,
344,
12,
2112,
12,
1255,
12,
943,
466,
304,
272,
2943,
275,
291,
423,
23968,
14,
7270,
8,
1765,
63,
344,
12,
2112,
12,
1109,
8,
1065,
430,
272,
340,
943,
466,
440,
315,
2943,
26,
489,
5888,
1118,
14,
13845,
8,
5188,
12,
298,
1944,
4066,
943,
730,
26,
450,
83,
2,
450,
943,
466,
9,
272,
1300,
12,
931,
275,
2943,
59,
793,
466,
61,
272,
1788,
275,
747,
14,
515,
14,
904,
8,
1095,
12,
931,
9,
272,
372,
469,
489,
283,
1765,
63,
344,
356,
2120,
63,
344,
12,
489,
283,
1501,
356,
1788,
12,
489,
283,
1412,
356,
2112,
12,
489,
283,
1065,
356,
1255,
12,
489,
283,
793,
466,
356,
943,
466,
272,
789,
819,
768,
5779,
3120,
14,
4449,
4769,
793,
576,
22075,
1765,
63,
344,
22075,
1412,
22075,
1065,
22075,
793,
466,
531,
523,
347,
2429,
63,
793,
576,
8,
277,
12,
2120,
63,
344,
12,
2112,
12,
1255,
12,
943,
466,
304,
272,
3268,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
2743,
297,
446,
17,
9,
272,
2582,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
1267,
297,
446,
17,
9,
272,
2943,
275,
291,
423,
23968,
14,
7270,
8,
1765,
63,
344,
12,
2112,
12,
1109,
8,
1065,
430,
272,
340,
943,
466,
440,
315,
2943,
26,
489,
372,
1052,
272,
32028,
12,
931,
275,
2943,
59,
793,
466,
61,
272,
372,
485,
739,
63,
4604,
8,
736,
14,
515,
14,
904,
8,
24769,
12,
931,
395,
3268,
12,
2582,
9,
819,
768,
5779,
3120,
14,
4449,
4769,
493,
22075,
1765,
63,
344,
22075,
515,
3,
6977,
3,
531,
523,
768,
5779,
3120,
14,
19491,
63,
1345,
8,
5779,
4231,
14,
912,
360,
493,
4570,
1333,
523,
347,
2429,
63,
493,
8,
277,
12,
2120,
63,
344,
12,
931,
304,
272,
340,
931,
365,
488,
26,
489,
5888,
1118,
14,
13845,
8,
5188,
12,
298,
1944,
4066,
570,
531,
272,
372,
469,
489,
283,
1765,
63,
344,
356,
2120,
63,
344,
12,
489,
283,
1501,
356,
931,
12,
272,
789,
819,
768,
5779,
3120,
14,
4449,
4769,
493,
576,
22075,
1765,
63,
344,
22075,
515,
3,
6977,
3,
531,
523,
347,
2429,
63,
493,
576,
8,
277,
12,
2120,
63,
344,
12,
931,
304,
272,
340,
931,
365,
488,
26,
489,
372,
1052,
272,
3268,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
2743,
297,
446,
17,
9,
272,
2582,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
1267,
297,
446,
17,
9,
272,
32028,
12,
931,
275,
291,
423,
23968,
14,
1078,
63,
493,
8,
1765,
63,
344,
12,
931,
9,
272,
340,
32028,
365,
488,
503,
931,
365,
488,
26,
489,
372,
1052,
272,
372,
485,
739,
63,
4604,
8,
736,
14,
515,
14,
904,
8,
24769,
12,
931,
395,
3268,
12,
2582,
9,
819,
768,
5779,
3120,
14,
4449,
4769,
4570,
22075,
1765,
63,
344,
531,
523,
768,
5779,
3120,
14,
4449,
4769,
4570,
22075,
1765
] |
[
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,
646,
747,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
199,
199,
646,
5888,
1118,
199,
504,
15811,
14,
2330,
492,
943,
199,
504,
15811,
14,
2330,
14,
1014,
492,
4760,
3120,
199,
199,
504,
1275,
808,
24615,
492,
4760,
4231,
199,
199,
4567,
275,
6619,
627,
6619,
199,
3472,
63,
20512,
63,
9127,
275,
19487,
199,
4283,
63,
20512,
63,
9127,
275,
3193,
627,
19487,
421,
199,
318,
485,
739,
63,
4604,
8,
1501,
12,
3268,
29,
403,
12,
2582,
29,
403,
304,
523,
3268,
275,
3268,
503,
446,
17,
523,
2582,
275,
2582,
503,
446,
17,
819,
862,
26,
272,
2582,
275,
1846,
8,
1267,
9,
272,
3268,
275,
1846,
8,
2743,
9,
523,
871,
1722,
26,
272,
372,
1052,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
1501,
304,
272,
372,
1052,
819,
862,
26,
272,
289,
3736,
275,
747,
14,
3736,
8,
1501,
9,
523,
871,
2186,
465,
325,
26,
272,
943,
14,
705,
360,
6531,
440,
1586,
687,
450,
83,
26,
450,
83,
7,
450,
334,
1501,
12,
325,
430,
272,
372,
1052,
819,
340,
3268,
508,
446,
17,
26,
272,
3268,
275,
289,
3736,
14,
270,
63,
890,
819,
340,
2582,
508,
446,
17,
26,
272,
2582,
275,
289,
3736,
14,
270,
63,
890,
446,
3268,
819,
543,
1551,
8,
1501,
12,
298,
82,
531,
465,
4090,
26,
272,
4090,
14,
5507,
8,
2743,
9,
272,
862,
26,
489,
666,
275,
4090,
14,
739,
8,
1267,
9,
272,
871,
5925,
465,
325,
26,
489,
943,
14,
705,
360,
4276,
370,
1586,
450,
83,
26,
450,
83,
7,
450,
334,
1501,
12,
325,
395,
3178,
63,
815,
29,
549,
9,
489,
372,
1052,
819,
340,
666,
26,
272,
372,
1211,
8,
2743,
29,
2743,
12,
2582,
29,
552,
8,
576,
395,
666,
29,
3765,
8,
576,
14,
2708,
360,
1624,
24,
297,
283,
1814,
7058,
819,
372,
1211,
8,
2743,
29,
2743,
12,
2582,
29,
16,
9,
421,
199,
533,
8495,
22715,
1173,
11930,
8,
785,
304,
523,
408,
272,
28438,
367,
377,
2523,
16908,
27336,
3814,
7042,
14,
523,
408,
819,
768,
5779,
3120,
14,
4449,
4769,
7270,
22075,
1765,
63,
344,
22075,
1412,
22075,
1065,
22075,
793,
466,
531,
523,
768,
5779,
3120,
14,
19491,
63,
1345,
8,
5779,
4231,
14,
912,
360,
793,
4570,
1333,
523,
347,
2429,
63,
7270,
8,
277,
12,
2120,
63,
344,
12,
2112,
12,
1255,
12,
943,
466,
304,
272,
2943,
275,
291,
423,
23968,
14,
7270,
8,
1765,
63,
344,
12,
2112,
12,
1109,
8,
1065,
430,
272,
340,
943,
466,
440,
315,
2943,
26,
489,
5888,
1118,
14,
13845,
8,
5188,
12,
298,
1944,
4066,
943,
730,
26,
450,
83,
2,
450,
943,
466,
9,
272,
1300,
12,
931,
275,
2943,
59,
793,
466,
61,
272,
1788,
275,
747,
14,
515,
14,
904,
8,
1095,
12,
931,
9,
272,
372,
469,
489,
283,
1765,
63,
344,
356,
2120,
63,
344,
12,
489,
283,
1501,
356,
1788,
12,
489,
283,
1412,
356,
2112,
12,
489,
283,
1065,
356,
1255,
12,
489,
283,
793,
466,
356,
943,
466,
272,
789,
819,
768,
5779,
3120,
14,
4449,
4769,
793,
576,
22075,
1765,
63,
344,
22075,
1412,
22075,
1065,
22075,
793,
466,
531,
523,
347,
2429,
63,
793,
576,
8,
277,
12,
2120,
63,
344,
12,
2112,
12,
1255,
12,
943,
466,
304,
272,
3268,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
2743,
297,
446,
17,
9,
272,
2582,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
1267,
297,
446,
17,
9,
272,
2943,
275,
291,
423,
23968,
14,
7270,
8,
1765,
63,
344,
12,
2112,
12,
1109,
8,
1065,
430,
272,
340,
943,
466,
440,
315,
2943,
26,
489,
372,
1052,
272,
32028,
12,
931,
275,
2943,
59,
793,
466,
61,
272,
372,
485,
739,
63,
4604,
8,
736,
14,
515,
14,
904,
8,
24769,
12,
931,
395,
3268,
12,
2582,
9,
819,
768,
5779,
3120,
14,
4449,
4769,
493,
22075,
1765,
63,
344,
22075,
515,
3,
6977,
3,
531,
523,
768,
5779,
3120,
14,
19491,
63,
1345,
8,
5779,
4231,
14,
912,
360,
493,
4570,
1333,
523,
347,
2429,
63,
493,
8,
277,
12,
2120,
63,
344,
12,
931,
304,
272,
340,
931,
365,
488,
26,
489,
5888,
1118,
14,
13845,
8,
5188,
12,
298,
1944,
4066,
570,
531,
272,
372,
469,
489,
283,
1765,
63,
344,
356,
2120,
63,
344,
12,
489,
283,
1501,
356,
931,
12,
272,
789,
819,
768,
5779,
3120,
14,
4449,
4769,
493,
576,
22075,
1765,
63,
344,
22075,
515,
3,
6977,
3,
531,
523,
347,
2429,
63,
493,
576,
8,
277,
12,
2120,
63,
344,
12,
931,
304,
272,
340,
931,
365,
488,
26,
489,
372,
1052,
272,
3268,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
2743,
297,
446,
17,
9,
272,
2582,
275,
291,
14,
2017,
14,
2970,
14,
362,
360,
1267,
297,
446,
17,
9,
272,
32028,
12,
931,
275,
291,
423,
23968,
14,
1078,
63,
493,
8,
1765,
63,
344,
12,
931,
9,
272,
340,
32028,
365,
488,
503,
931,
365,
488,
26,
489,
372,
1052,
272,
372,
485,
739,
63,
4604,
8,
736,
14,
515,
14,
904,
8,
24769,
12,
931,
395,
3268,
12,
2582,
9,
819,
768,
5779,
3120,
14,
4449,
4769,
4570,
22075,
1765,
63,
344,
531,
523,
768,
5779,
3120,
14,
4449,
4769,
4570,
22075,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1,
1,
1,
1
] |
Menooker/gem5_pcm
|
src/arch/x86/isa/insts/simd128/floating_point/arithmetic/subtraction.py
|
91
|
3967
|
# 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
microcode = '''
def macroop SUBSS_XMM_XMM {
msubf xmml, xmml, xmmlm, size=4, ext=Scalar
};
def macroop SUBSS_XMM_M {
ldfp ufp1, seg, sib, disp, dataSize=8
msubf xmml, xmml, ufp1, size=4, ext=Scalar
};
def macroop SUBSS_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, disp, dataSize=8
msubf xmml, xmml, ufp1, size=4, ext=Scalar
};
def macroop SUBSD_XMM_XMM {
msubf xmml, xmml, xmmlm, size=8, ext=Scalar
};
def macroop SUBSD_XMM_M {
ldfp ufp1, seg, sib, disp, dataSize=8
msubf xmml, xmml, ufp1, size=8, ext=Scalar
};
def macroop SUBSD_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, disp, dataSize=8
msubf xmml, xmml, ufp1, size=8, ext=Scalar
};
def macroop SUBPS_XMM_XMM {
msubf xmml, xmml, xmmlm, size=4, ext=0
msubf xmmh, xmmh, xmmhm, size=4, ext=0
};
def macroop SUBPS_XMM_M {
ldfp ufp1, seg, sib, "DISPLACEMENT", dataSize=8
ldfp ufp2, seg, sib, "DISPLACEMENT + 8", dataSize=8
msubf xmml, xmml, ufp1, size=4, ext=0
msubf xmmh, xmmh, ufp2, size=4, ext=0
};
def macroop SUBPS_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, "DISPLACEMENT", dataSize=8
ldfp ufp2, seg, riprel, "DISPLACEMENT + 8", dataSize=8
msubf xmml, xmml, ufp1, size=4, ext=0
msubf xmmh, xmmh, ufp2, size=4, ext=0
};
def macroop SUBPD_XMM_XMM {
msubf xmml, xmml, xmmlm, size=8, ext=0
msubf xmmh, xmmh, xmmhm, size=8, ext=0
};
def macroop SUBPD_XMM_M {
ldfp ufp1, seg, sib, "DISPLACEMENT", dataSize=8
ldfp ufp2, seg, sib, "DISPLACEMENT + 8", dataSize=8
msubf xmml, xmml, ufp1, size=8, ext=0
msubf xmmh, xmmh, ufp2, size=8, ext=0
};
def macroop SUBPD_XMM_P {
rdip t7
ldfp ufp1, seg, riprel, "DISPLACEMENT", dataSize=8
ldfp ufp2, seg, riprel, "DISPLACEMENT + 8", dataSize=8
msubf xmml, xmml, ufp1, size=8, ext=0
msubf xmmh, xmmh, ufp2, size=8, ext=0
};
'''
|
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,
6453,
600,
275,
1449,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
18286,
14038,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
15930,
80,
26337,
18,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
435,
1695,
401,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
26337,
18,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
15930,
80,
26337,
18,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
435,
1695,
401,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
26337,
18,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
11435,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
18286,
14038,
12,
1568,
29,
24,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
11435,
63,
19439,
63,
45,
469,
272,
15930,
80
] |
[
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,
6453,
600,
275,
1449,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
2300,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
3693,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
9628,
12,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
24,
12,
1599,
29,
13090,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
18286,
14038,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
45,
469,
272,
15930,
80,
26337,
17,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
15930,
80,
26337,
18,
12,
8812,
12,
20417,
12,
298,
6178,
2749,
22194,
435,
1695,
401,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
26337,
18,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
5067,
63,
19439,
63,
48,
469,
272,
519,
21846,
307,
23,
272,
15930,
80,
26337,
17,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
401,
18252,
29,
24,
272,
15930,
80,
26337,
18,
12,
8812,
12,
8012,
30788,
12,
298,
6178,
2749,
22194,
435,
1695,
401,
18252,
29,
24,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
26337,
17,
12,
1568,
29,
20,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
26337,
18,
12,
1568,
29,
20,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
11435,
63,
19439,
63,
19439,
469,
272,
333,
954,
70,
18286,
76,
12,
18286,
76,
12,
18286,
14344,
12,
1568,
29,
24,
12,
1599,
29,
16,
272,
333,
954,
70,
18286,
72,
12,
18286,
72,
12,
18286,
14038,
12,
1568,
29,
24,
12,
1599,
29,
16,
199,
12084,
199,
199,
318,
21308,
7605,
11435,
63,
19439,
63,
45,
469,
272,
15930,
80,
0
] |
[
1,
1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edera/rg3-youtube-dl
|
youtube_dl/extractor/airmozilla.py
|
78
|
3097
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
int_or_none,
parse_duration,
parse_iso8601,
)
class AirMozillaIE(InfoExtractor):
_VALID_URL = r'https?://air\.mozilla\.org/(?P<id>[0-9a-z-]+)/?'
_TEST = {
'url': 'https://air.mozilla.org/privacy-lab-a-meetup-for-privacy-minded-people-in-san-francisco/',
'md5': '2e3e7486ba5d180e829d453875b9b8bf',
'info_dict': {
'id': '6x4q2w',
'ext': 'mp4',
'title': 'Privacy Lab - a meetup for privacy minded people in San Francisco',
'thumbnail': 're:https?://vid\.ly/(?P<id>[0-9a-z-]+)/poster',
'description': 'Brings together privacy professionals and others interested in privacy at for-profits, non-profits, and NGOs in an effort to contribute to the state of the ecosystem...',
'timestamp': 1422487800,
'upload_date': '20150128',
'location': 'SFO Commons',
'duration': 3780,
'view_count': int,
'categories': ['Main', 'Privacy'],
}
}
def _real_extract(self, url):
display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id)
video_id = self._html_search_regex(r'//vid.ly/(.*?)/embed', webpage, 'id')
embed_script = self._download_webpage('https://vid.ly/{0}/embed'.format(video_id), video_id)
jwconfig = self._search_regex(r'\svar jwconfig = (\{.*?\});\s', embed_script, 'metadata')
metadata = self._parse_json(jwconfig, video_id)
formats = [{
'url': source['file'],
'ext': source['type'],
'format_id': self._search_regex(r'&format=(.*)$', source['file'], 'video format'),
'format': source['label'],
'height': int(source['label'].rstrip('p')),
} for source in metadata['playlist'][0]['sources']]
self._sort_formats(formats)
view_count = int_or_none(self._html_search_regex(
r'Views since archived: ([0-9]+)',
webpage, 'view count', fatal=False))
timestamp = parse_iso8601(self._html_search_regex(
r'<time datetime="(.*?)"', webpage, 'timestamp', fatal=False))
duration = parse_duration(self._search_regex(
r'Duration:\s*(\d+\s*hours?\s*\d+\s*minutes?)',
webpage, 'duration', fatal=False))
return {
'id': video_id,
'title': self._og_search_title(webpage),
'formats': formats,
'url': self._og_search_url(webpage),
'display_id': display_id,
'thumbnail': metadata['playlist'][0].get('image'),
'description': self._og_search_description(webpage),
'timestamp': timestamp,
'location': self._html_search_regex(r'Location: (.*)', webpage, 'location', default=None),
'duration': duration,
'view_count': view_count,
'categories': re.findall(r'<a href=".*?" class="channel">(.*?)</a>', webpage),
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
421,
199,
533,
22102,
22285,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
8387,
4537,
12102,
4537,
1308,
9448,
48,
28,
344,
9514,
16,
13,
25,
65,
13,
90,
20253,
2447,
14069,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
8387,
14,
12102,
14,
1308,
15,
17258,
13,
5561,
13,
65,
13,
278,
386,
384,
13,
509,
13,
17258,
13,
827,
770,
13,
13562,
13,
262,
13,
18904,
13,
70,
1312,
19597,
3678,
267,
283,
1064,
21,
356,
283,
18,
69,
19,
69,
1342,
1184,
2470,
21,
68,
7663,
69,
31786,
68,
2322,
12399,
21,
66,
25,
66,
24,
4361,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
22,
88,
20,
81,
18,
87,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
4562,
86,
4085,
16871,
446,
282,
26743,
384,
367,
16254,
4085,
1748,
770,
13135,
315,
29359,
481,
1312,
19597,
297,
288,
283,
8311,
356,
283,
264,
26,
2859,
14144,
5017,
4537,
590,
9448,
48,
28,
344,
9514,
16,
13,
25,
65,
13,
90,
20253,
2447,
20801,
297,
288,
283,
1802,
356,
283,
12771,
780,
10451,
16254,
4085,
22398,
3552,
2551,
436,
11789,
22201,
315,
16254,
4085,
737,
367,
13,
496,
14948,
12,
2222,
13,
496,
14948,
12,
436,
653,
13160,
83,
315,
376,
28058,
370,
28567,
370,
314,
1174,
402,
314,
325,
331,
2253,
20833,
288,
283,
3954,
356,
4329,
8731,
1555,
6718,
12,
288,
283,
5064,
63,
602,
356,
283,
7806,
614,
1651,
297,
288,
283,
1985,
356,
283,
51,
3230,
7046,
4654,
297,
288,
283,
5553,
356,
6877,
1257,
12,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8906,
356,
788,
6756,
297,
283,
4562,
86,
4085,
995,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
2929,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
267,
3991,
63,
344,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
28866,
5017,
14,
590,
7985,
6697,
2447,
6427,
297,
9248,
12,
283,
344,
358,
398,
6441,
63,
1579,
275,
291,
423,
4249,
63,
12022,
360,
2859,
921,
5017,
14,
590,
5321,
16,
5995,
6427,
1370,
908,
8,
3722,
63,
344,
395,
3991,
63,
344,
9,
267,
1335,
87,
888,
275,
291,
423,
1733,
63,
3821,
8,
82,
1154,
83,
1391,
1335,
87,
888,
275,
14749,
91,
21040,
1552,
3779,
83,
297,
6441,
63,
1579,
12,
283,
2343,
358,
267,
3341,
275,
291,
423,
1122,
63,
1001,
8,
30561,
888,
12,
3991,
63,
344,
9,
398,
6752,
275,
8910,
288,
283,
633,
356,
1350,
459,
493,
995,
288,
283,
832,
356,
1350,
459,
466,
995,
288,
283,
908,
63,
344,
356,
291,
423,
1733,
63,
3821,
8,
82,
21840,
908,
2687,
12432,
4268,
1350,
459,
493,
995,
283,
3722,
1475,
659,
288,
283,
908,
356,
1350,
459,
1302,
995,
288,
283,
3333,
356,
1109,
8,
1365,
459,
1302,
2278,
6735,
360,
80,
3855,
267,
789,
367,
1350,
315,
3341,
459,
10411,
3488,
16,
2733,
4553,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
2455,
63,
835,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7,
21180,
3967,
3819,
12905,
26,
7287,
16,
13,
25,
28798,
288,
9248,
12,
283,
1345,
2338,
297,
14294,
29,
797,
430,
267,
4913,
275,
2198,
63,
4595,
15363,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
521,
2197,
628,
17140,
32691,
9248,
12,
283,
3954,
297,
14294,
29,
797,
430,
267,
7373,
275,
2198,
63,
5553,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7,
13283,
3427,
83,
22588,
68,
7896,
83,
10,
8419,
8995,
83,
7590,
68,
7896,
83,
10,
10430,
31,
3196,
288,
9248,
12,
283,
5553,
297,
14294,
29,
797,
430,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
395,
288,
283,
6321,
356,
6752,
12,
288,
283,
633,
356,
291,
423,
974,
63,
1733,
63,
633,
8,
12022,
395,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
8311,
356,
3341,
459,
10411,
3488,
16,
1055,
362,
360,
1569,
659,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
3954,
356,
4913,
12,
288,
283,
1985,
356,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7,
6592,
26,
334,
2795,
3196,
9248,
12,
283,
1985,
297,
849,
29,
403,
395,
288,
283,
5553,
356,
7373,
12,
288,
283,
1345,
63,
835,
356,
2455,
63,
835,
12,
288,
283,
8906,
356,
295,
14,
6452,
8,
82,
7601,
65,
4369,
628,
6697,
2,
1021,
628,
2775,
1743,
17140,
15939,
65,
4206,
9248,
395,
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
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
421,
199,
533,
22102,
22285,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
8387,
4537,
12102,
4537,
1308,
9448,
48,
28,
344,
9514,
16,
13,
25,
65,
13,
90,
20253,
2447,
14069,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
8387,
14,
12102,
14,
1308,
15,
17258,
13,
5561,
13,
65,
13,
278,
386,
384,
13,
509,
13,
17258,
13,
827,
770,
13,
13562,
13,
262,
13,
18904,
13,
70,
1312,
19597,
3678,
267,
283,
1064,
21,
356,
283,
18,
69,
19,
69,
1342,
1184,
2470,
21,
68,
7663,
69,
31786,
68,
2322,
12399,
21,
66,
25,
66,
24,
4361,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
22,
88,
20,
81,
18,
87,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
4562,
86,
4085,
16871,
446,
282,
26743,
384,
367,
16254,
4085,
1748,
770,
13135,
315,
29359,
481,
1312,
19597,
297,
288,
283,
8311,
356,
283,
264,
26,
2859,
14144,
5017,
4537,
590,
9448,
48,
28,
344,
9514,
16,
13,
25,
65,
13,
90,
20253,
2447,
20801,
297,
288,
283,
1802,
356,
283,
12771,
780,
10451,
16254,
4085,
22398,
3552,
2551,
436,
11789,
22201,
315,
16254,
4085,
737,
367,
13,
496,
14948,
12,
2222,
13,
496,
14948,
12,
436,
653,
13160,
83,
315,
376,
28058,
370,
28567,
370,
314,
1174,
402,
314,
325,
331,
2253,
20833,
288,
283,
3954,
356,
4329,
8731,
1555,
6718,
12,
288,
283,
5064,
63,
602,
356,
283,
7806,
614,
1651,
297,
288,
283,
1985,
356,
283,
51,
3230,
7046,
4654,
297,
288,
283,
5553,
356,
6877,
1257,
12,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8906,
356,
788,
6756,
297,
283,
4562,
86,
4085,
995,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
2929,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
267,
3991,
63,
344,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
28866,
5017,
14,
590,
7985,
6697,
2447,
6427,
297,
9248,
12,
283,
344,
358,
398,
6441,
63,
1579,
275,
291,
423,
4249,
63,
12022,
360,
2859,
921,
5017,
14,
590,
5321,
16,
5995,
6427,
1370,
908,
8,
3722,
63,
344,
395,
3991,
63,
344,
9,
267,
1335,
87,
888,
275,
291,
423,
1733,
63,
3821,
8,
82,
1154,
83,
1391,
1335,
87,
888,
275,
14749,
91,
21040,
1552,
3779,
83,
297,
6441,
63,
1579,
12,
283,
2343,
358,
267,
3341,
275,
291,
423,
1122,
63,
1001,
8,
30561,
888,
12,
3991,
63,
344,
9,
398,
6752,
275,
8910,
288,
283,
633,
356,
1350,
459,
493,
995,
288,
283,
832,
356,
1350,
459,
466,
995,
288,
283,
908,
63,
344,
356,
291,
423,
1733,
63,
3821,
8,
82,
21840,
908,
2687,
12432,
4268,
1350,
459,
493,
995,
283,
3722,
1475,
659,
288,
283,
908,
356,
1350,
459,
1302,
995,
288,
283,
3333,
356,
1109,
8,
1365,
459,
1302,
2278,
6735,
360,
80,
3855,
267,
789,
367,
1350,
315,
3341,
459,
10411,
3488,
16,
2733,
4553,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
2455,
63,
835,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7,
21180,
3967,
3819,
12905,
26,
7287,
16,
13,
25,
28798,
288,
9248,
12,
283,
1345,
2338,
297,
14294,
29,
797,
430,
267,
4913,
275,
2198,
63,
4595,
15363,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
521,
2197,
628,
17140,
32691,
9248,
12,
283,
3954,
297,
14294,
29,
797,
430,
267,
7373,
275,
2198,
63,
5553,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7,
13283,
3427,
83,
22588,
68,
7896,
83,
10,
8419,
8995,
83,
7590,
68,
7896,
83,
10,
10430,
31,
3196,
288,
9248,
12,
283,
5553,
297,
14294,
29,
797,
430,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
395,
288,
283,
6321,
356,
6752,
12,
288,
283,
633,
356,
291,
423,
974,
63,
1733,
63,
633,
8,
12022,
395,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
8311,
356,
3341,
459,
10411,
3488,
16,
1055,
362,
360,
1569,
659,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
3954,
356,
4913,
12,
288,
283,
1985,
356,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7,
6592,
26,
334,
2795,
3196,
9248,
12,
283,
1985,
297,
849,
29,
403,
395,
288,
283,
5553,
356,
7373,
12,
288,
283,
1345,
63,
835,
356,
2455,
63,
835,
12,
288,
283,
8906,
356,
295,
14,
6452,
8,
82,
7601,
65,
4369,
628,
6697,
2,
1021,
628,
2775,
1743,
17140,
15939,
65,
4206,
9248,
395,
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,
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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
] |
shujaatak/UAV_MissionPlanner
|
Lib/site-packages/numpy/linalg/__init__.py
|
54
|
2194
|
"""
Core Linear Algebra Tools
=========================
=============== ==========================================================
Linear algebra basics
==========================================================================
norm Vector or matrix norm
inv Inverse of a square matrix
solve Solve a linear system of equations
det Determinant of a square matrix
slogdet Logarithm of the determinant of a square matrix
lstsq Solve linear least-squares problem
pinv Pseudo-inverse (Moore-Penrose) calculated using a singular
value decomposition
matrix_power Integer power of a square matrix
=============== ==========================================================
=============== ==========================================================
Eigenvalues and decompositions
==========================================================================
eig Eigenvalues and vectors of a square matrix
eigh Eigenvalues and eigenvectors of a Hermitian matrix
eigvals Eigenvalues of a square matrix
eigvalsh Eigenvalues of a Hermitian matrix
qr QR decomposition of a matrix
svd Singular value decomposition of a matrix
cholesky Cholesky decomposition of a matrix
=============== ==========================================================
=============== ==========================================================
Tensor operations
==========================================================================
tensorsolve Solve a linear tensor equation
tensorinv Calculate an inverse of a tensor
=============== ==========================================================
=============== ==========================================================
Exceptions
==========================================================================
LinAlgError Indicates a failed linear algebra operation
=============== ==========================================================
"""
# To get sub-modules
from info import __doc__
from linalg import *
from numpy.testing import Tester
test = Tester(__file__).test
bench = Tester(__file__).test
|
gpl-2.0
|
[
624,
199,
5402,
12489,
4580,
19355,
23228,
199,
1280,
15495,
199,
199,
16964,
19691,
15495,
199,
10608,
741,
19355,
5678,
83,
199,
5695,
17575,
199,
4791,
3322,
11388,
503,
3634,
6316,
199,
5350,
3777,
1010,
2077,
402,
282,
12386,
3634,
199,
11356,
3698,
428,
3344,
282,
7798,
2656,
402,
26426,
199,
9886,
3777,
1487,
2704,
867,
402,
282,
12386,
3634,
199,
83,
793,
9886,
260,
5297,
18327,
77,
402,
314,
4563,
867,
402,
282,
12386,
3634,
199,
6916,
3526,
3698,
428,
3344,
7798,
5210,
13,
20956,
5160,
199,
80,
5350,
3322,
510,
9917,
13,
11668,
334,
3716,
720,
13,
15597,
293,
261,
9,
12950,
1808,
282,
15823,
355,
574,
22706,
199,
3642,
63,
5652,
259,
7225,
7074,
402,
282,
12386,
3634,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
37,
8478,
1459,
436,
477,
7784,
6150,
199,
5695,
17575,
199,
22129,
3777,
662,
8478,
1459,
436,
11102,
402,
282,
12386,
3634,
199,
69,
2056,
3322,
662,
8478,
1459,
436,
29802,
402,
282,
18769,
26649,
3634,
199,
22129,
3643,
260,
662,
8478,
1459,
402,
282,
12386,
3634,
199,
22129,
637,
609,
263,
662,
8478,
1459,
402,
282,
18769,
26649,
3634,
199,
16596,
4519,
1413,
50,
22706,
402,
282,
3634,
199,
18675,
3777,
428,
14257,
574,
22706,
402,
282,
3634,
199,
31369,
263,
8802,
19881,
22706,
402,
282,
3634,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
3861,
5331,
199,
5695,
17575,
199,
10206,
3344,
258,
428,
3344,
282,
7798,
2345,
18649,
199,
3128,
5350,
755,
12707,
376,
11484,
402,
282,
2345,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
16836,
199,
5695,
17575,
199,
27889,
28846,
547,
258,
19334,
282,
3405,
7798,
741,
19355,
3439,
199,
16964,
19691,
15495,
199,
199,
624,
199,
3,
4005,
664,
1007,
13,
3112,
199,
504,
2256,
492,
636,
1301,
363,
199,
199,
504,
16727,
492,
627,
199,
199,
504,
2680,
14,
4776,
492,
377,
17338,
199,
396,
275,
377,
17338,
3460,
493,
28634,
396,
199,
16571,
275,
377,
17338,
3460,
493,
28634,
396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
5402,
12489,
4580,
19355,
23228,
199,
1280,
15495,
199,
199,
16964,
19691,
15495,
199,
10608,
741,
19355,
5678,
83,
199,
5695,
17575,
199,
4791,
3322,
11388,
503,
3634,
6316,
199,
5350,
3777,
1010,
2077,
402,
282,
12386,
3634,
199,
11356,
3698,
428,
3344,
282,
7798,
2656,
402,
26426,
199,
9886,
3777,
1487,
2704,
867,
402,
282,
12386,
3634,
199,
83,
793,
9886,
260,
5297,
18327,
77,
402,
314,
4563,
867,
402,
282,
12386,
3634,
199,
6916,
3526,
3698,
428,
3344,
7798,
5210,
13,
20956,
5160,
199,
80,
5350,
3322,
510,
9917,
13,
11668,
334,
3716,
720,
13,
15597,
293,
261,
9,
12950,
1808,
282,
15823,
355,
574,
22706,
199,
3642,
63,
5652,
259,
7225,
7074,
402,
282,
12386,
3634,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
37,
8478,
1459,
436,
477,
7784,
6150,
199,
5695,
17575,
199,
22129,
3777,
662,
8478,
1459,
436,
11102,
402,
282,
12386,
3634,
199,
69,
2056,
3322,
662,
8478,
1459,
436,
29802,
402,
282,
18769,
26649,
3634,
199,
22129,
3643,
260,
662,
8478,
1459,
402,
282,
12386,
3634,
199,
22129,
637,
609,
263,
662,
8478,
1459,
402,
282,
18769,
26649,
3634,
199,
16596,
4519,
1413,
50,
22706,
402,
282,
3634,
199,
18675,
3777,
428,
14257,
574,
22706,
402,
282,
3634,
199,
31369,
263,
8802,
19881,
22706,
402,
282,
3634,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
3861,
5331,
199,
5695,
17575,
199,
10206,
3344,
258,
428,
3344,
282,
7798,
2345,
18649,
199,
3128,
5350,
755,
12707,
376,
11484,
402,
282,
2345,
199,
16964,
19691,
15495,
199,
199,
16964,
19691,
15495,
199,
16836,
199,
5695,
17575,
199,
27889,
28846,
547,
258,
19334,
282,
3405,
7798,
741,
19355,
3439,
199,
16964,
19691,
15495,
199,
199,
624,
199,
3,
4005,
664,
1007,
13,
3112,
199,
504,
2256,
492,
636,
1301,
363,
199,
199,
504,
16727,
492,
627,
199,
199,
504,
2680,
14,
4776,
492,
377,
17338,
199,
396,
275,
377,
17338,
3460,
493,
28634,
396,
199,
16571,
275,
377,
17338,
3460,
493,
28634,
396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
fkie-cad/FACT_core
|
src/test/acceptance/rest/test_rest_download.py
|
1
|
1656
|
from base64 import standard_b64encode
import time
import urllib.parse
from storage.db_interface_backend import BackEndDbInterface
from test.acceptance.base import TestAcceptanceBase
from test.common_helper import create_test_firmware
class TestIntegrationRestDownloadFirmware(TestAcceptanceBase):
def setUp(self):
super().setUp()
self._start_backend()
self.db_backend = BackEndDbInterface(config=self.config)
time.sleep(2) # wait for systems to start
def tearDown(self):
self.db_backend.shutdown()
self._stop_backend()
super().tearDown()
def _rest_search(self):
rv = self.test_client.get('/rest/firmware?query={}'.format(urllib.parse.quote('{"device_class": "test class"}')), follow_redirects=True)
self.assertIn(self.test_fw.uid.encode(), rv.data, "test firmware not found in rest search")
def _rest_download(self):
rv = self.test_client.get('/rest/binary/{}'.format(self.test_fw.uid), follow_redirects=True)
self.assertIn(standard_b64encode(self.test_fw.binary), rv.data, "rest download response incorrect")
self.assertIn('"file_name": "{}"'.format(self.test_fw.file_name).encode(), rv.data, "rest download response incorrect")
self.assertIn('"SHA256": "{}"'.format(self.test_fw.sha256).encode(), rv.data, "rest download response incorrect")
def test_run_from_upload_to_show_analysis(self):
self.test_fw = create_test_firmware(device_class="test class", device_name="test device", vendor="test vendor")
self.db_backend.add_firmware(self.test_fw)
self._rest_search()
self._rest_download()
|
gpl-3.0
|
[
504,
1300,
772,
492,
4465,
63,
66,
772,
2143,
199,
646,
900,
199,
646,
4011,
14,
1122,
199,
199,
504,
4887,
14,
697,
63,
3266,
63,
4620,
492,
10257,
3005,
8882,
4267,
199,
504,
511,
14,
28519,
14,
1095,
492,
1379,
8422,
554,
1563,
199,
504,
511,
14,
2330,
63,
3676,
492,
1218,
63,
396,
63,
26374,
421,
199,
533,
1379,
20405,
13726,
11950,
38,
20678,
8,
774,
8422,
554,
1563,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
423,
928,
63,
4620,
342,
267,
291,
14,
697,
63,
4620,
275,
10257,
3005,
8882,
4267,
8,
888,
29,
277,
14,
888,
9,
267,
900,
14,
4532,
8,
18,
9,
221,
327,
3618,
367,
10460,
370,
1343,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
697,
63,
4620,
14,
8831,
342,
267,
291,
423,
2379,
63,
4620,
342,
267,
1613,
1252,
12336,
342,
339,
347,
485,
3911,
63,
1733,
8,
277,
304,
267,
4336,
275,
291,
14,
396,
63,
1258,
14,
362,
2336,
3911,
15,
26374,
31,
1131,
27244,
908,
8,
4078,
14,
1122,
14,
3513,
360,
6641,
1782,
63,
533,
582,
298,
396,
1021,
3570,
3855,
2035,
63,
13607,
29,
549,
9,
267,
291,
14,
4080,
8,
277,
14,
396,
63,
8835,
14,
1535,
14,
2143,
1062,
4336,
14,
576,
12,
298,
396,
27969,
440,
1911,
315,
4618,
2754,
531,
339,
347,
485,
3911,
63,
4249,
8,
277,
304,
267,
4336,
275,
291,
14,
396,
63,
1258,
14,
362,
2336,
3911,
15,
3008,
30837,
908,
8,
277,
14,
396,
63,
8835,
14,
1535,
395,
2035,
63,
13607,
29,
549,
9,
267,
291,
14,
4080,
8,
6807,
63,
66,
772,
2143,
8,
277,
14,
396,
63,
8835,
14,
3008,
395,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
267,
291,
14,
4080,
14088,
493,
63,
354,
582,
28168,
1370,
908,
8,
277,
14,
396,
63,
8835,
14,
493,
63,
354,
680,
2143,
1062,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
267,
291,
14,
4080,
14088,
8461,
3912,
582,
28168,
1370,
908,
8,
277,
14,
396,
63,
8835,
14,
4835,
3912,
680,
2143,
1062,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
339,
347,
511,
63,
1065,
63,
504,
63,
5064,
63,
475,
63,
2384,
63,
10466,
8,
277,
304,
267,
291,
14,
396,
63,
8835,
275,
1218,
63,
396,
63,
26374,
8,
1782,
63,
533,
628,
396,
1021,
401,
2243,
63,
354,
628,
396,
2243,
401,
20868,
628,
396,
20868,
531,
267,
291,
14,
697,
63,
4620,
14,
525,
63,
26374,
8,
277,
14,
396,
63,
8835,
9,
398,
291,
423,
3911,
63,
1733,
342,
267,
291,
423,
3911,
63,
4249,
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
] |
[
1300,
772,
492,
4465,
63,
66,
772,
2143,
199,
646,
900,
199,
646,
4011,
14,
1122,
199,
199,
504,
4887,
14,
697,
63,
3266,
63,
4620,
492,
10257,
3005,
8882,
4267,
199,
504,
511,
14,
28519,
14,
1095,
492,
1379,
8422,
554,
1563,
199,
504,
511,
14,
2330,
63,
3676,
492,
1218,
63,
396,
63,
26374,
421,
199,
533,
1379,
20405,
13726,
11950,
38,
20678,
8,
774,
8422,
554,
1563,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
423,
928,
63,
4620,
342,
267,
291,
14,
697,
63,
4620,
275,
10257,
3005,
8882,
4267,
8,
888,
29,
277,
14,
888,
9,
267,
900,
14,
4532,
8,
18,
9,
221,
327,
3618,
367,
10460,
370,
1343,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
697,
63,
4620,
14,
8831,
342,
267,
291,
423,
2379,
63,
4620,
342,
267,
1613,
1252,
12336,
342,
339,
347,
485,
3911,
63,
1733,
8,
277,
304,
267,
4336,
275,
291,
14,
396,
63,
1258,
14,
362,
2336,
3911,
15,
26374,
31,
1131,
27244,
908,
8,
4078,
14,
1122,
14,
3513,
360,
6641,
1782,
63,
533,
582,
298,
396,
1021,
3570,
3855,
2035,
63,
13607,
29,
549,
9,
267,
291,
14,
4080,
8,
277,
14,
396,
63,
8835,
14,
1535,
14,
2143,
1062,
4336,
14,
576,
12,
298,
396,
27969,
440,
1911,
315,
4618,
2754,
531,
339,
347,
485,
3911,
63,
4249,
8,
277,
304,
267,
4336,
275,
291,
14,
396,
63,
1258,
14,
362,
2336,
3911,
15,
3008,
30837,
908,
8,
277,
14,
396,
63,
8835,
14,
1535,
395,
2035,
63,
13607,
29,
549,
9,
267,
291,
14,
4080,
8,
6807,
63,
66,
772,
2143,
8,
277,
14,
396,
63,
8835,
14,
3008,
395,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
267,
291,
14,
4080,
14088,
493,
63,
354,
582,
28168,
1370,
908,
8,
277,
14,
396,
63,
8835,
14,
493,
63,
354,
680,
2143,
1062,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
267,
291,
14,
4080,
14088,
8461,
3912,
582,
28168,
1370,
908,
8,
277,
14,
396,
63,
8835,
14,
4835,
3912,
680,
2143,
1062,
4336,
14,
576,
12,
298,
3911,
5235,
1177,
8927,
531,
339,
347,
511,
63,
1065,
63,
504,
63,
5064,
63,
475,
63,
2384,
63,
10466,
8,
277,
304,
267,
291,
14,
396,
63,
8835,
275,
1218,
63,
396,
63,
26374,
8,
1782,
63,
533,
628,
396,
1021,
401,
2243,
63,
354,
628,
396,
2243,
401,
20868,
628,
396,
20868,
531,
267,
291,
14,
697,
63,
4620,
14,
525,
63,
26374,
8,
277,
14,
396,
63,
8835,
9,
398,
291,
423,
3911,
63,
1733,
342,
267,
291,
423,
3911,
63,
4249,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
watspidererik/testenv
|
flask/lib/python2.7/site-packages/openid/fetchers.py
|
138
|
13937
|
# -*- test-case-name: openid.test.test_fetchers -*-
"""
This module contains the HTTP fetcher interface and several implementations.
"""
__all__ = ['fetch', 'getDefaultFetcher', 'setDefaultFetcher', 'HTTPResponse',
'HTTPFetcher', 'createHTTPFetcher', 'HTTPFetchingError',
'HTTPError']
import urllib2
import time
import cStringIO
import sys
import openid
import openid.urinorm
# Try to import httplib2 for caching support
# http://bitworking.org/projects/httplib2/
try:
import httplib2
except ImportError:
# httplib2 not available
httplib2 = None
# try to import pycurl, which will let us use CurlHTTPFetcher
try:
import pycurl
except ImportError:
pycurl = None
USER_AGENT = "python-openid/%s (%s)" % (openid.__version__, sys.platform)
MAX_RESPONSE_KB = 1024
def fetch(url, body=None, headers=None):
"""Invoke the fetch method on the default fetcher. Most users
should need only this method.
@raises Exception: any exceptions that may be raised by the default fetcher
"""
fetcher = getDefaultFetcher()
return fetcher.fetch(url, body, headers)
def createHTTPFetcher():
"""Create a default HTTP fetcher instance
prefers Curl to urllib2."""
if pycurl is None:
fetcher = Urllib2Fetcher()
else:
fetcher = CurlHTTPFetcher()
return fetcher
# Contains the currently set HTTP fetcher. If it is set to None, the
# library will call createHTTPFetcher() to set it. Do not access this
# variable outside of this module.
_default_fetcher = None
def getDefaultFetcher():
"""Return the default fetcher instance
if no fetcher has been set, it will create a default fetcher.
@return: the default fetcher
@rtype: HTTPFetcher
"""
global _default_fetcher
if _default_fetcher is None:
setDefaultFetcher(createHTTPFetcher())
return _default_fetcher
def setDefaultFetcher(fetcher, wrap_exceptions=True):
"""Set the default fetcher
@param fetcher: The fetcher to use as the default HTTP fetcher
@type fetcher: HTTPFetcher
@param wrap_exceptions: Whether to wrap exceptions thrown by the
fetcher wil HTTPFetchingError so that they may be caught
easier. By default, exceptions will be wrapped. In general,
unwrapped fetchers are useful for debugging of fetching errors
or if your fetcher raises well-known exceptions that you would
like to catch.
@type wrap_exceptions: bool
"""
global _default_fetcher
if fetcher is None or not wrap_exceptions:
_default_fetcher = fetcher
else:
_default_fetcher = ExceptionWrappingFetcher(fetcher)
def usingCurl():
"""Whether the currently set HTTP fetcher is a Curl HTTP fetcher."""
return isinstance(getDefaultFetcher(), CurlHTTPFetcher)
class HTTPResponse(object):
"""XXX document attributes"""
headers = None
status = None
body = None
final_url = None
def __init__(self, final_url=None, status=None, headers=None, body=None):
self.final_url = final_url
self.status = status
self.headers = headers
self.body = body
def __repr__(self):
return "<%s status %s for %s>" % (self.__class__.__name__,
self.status,
self.final_url)
class HTTPFetcher(object):
"""
This class is the interface for openid HTTP fetchers. This
interface is only important if you need to write a new fetcher for
some reason.
"""
def fetch(self, url, body=None, headers=None):
"""
This performs an HTTP POST or GET, following redirects along
the way. If a body is specified, then the request will be a
POST. Otherwise, it will be a GET.
@param headers: HTTP headers to include with the request
@type headers: {str:str}
@return: An object representing the server's HTTP response. If
there are network or protocol errors, an exception will be
raised. HTTP error responses, like 404 or 500, do not
cause exceptions.
@rtype: L{HTTPResponse}
@raise Exception: Different implementations will raise
different errors based on the underlying HTTP library.
"""
raise NotImplementedError
def _allowedURL(url):
return url.startswith('http://') or url.startswith('https://')
class HTTPFetchingError(Exception):
"""Exception that is wrapped around all exceptions that are raised
by the underlying fetcher when using the ExceptionWrappingFetcher
@ivar why: The exception that caused this exception
"""
def __init__(self, why=None):
Exception.__init__(self, why)
self.why = why
class ExceptionWrappingFetcher(HTTPFetcher):
"""Fetcher that wraps another fetcher, causing all exceptions
@cvar uncaught_exceptions: Exceptions that should be exposed to the
user if they are raised by the fetch call
"""
uncaught_exceptions = (SystemExit, KeyboardInterrupt, MemoryError)
def __init__(self, fetcher):
self.fetcher = fetcher
def fetch(self, *args, **kwargs):
try:
return self.fetcher.fetch(*args, **kwargs)
except self.uncaught_exceptions:
raise
except:
exc_cls, exc_inst = sys.exc_info()[:2]
if exc_inst is None:
# string exceptions
exc_inst = exc_cls
raise HTTPFetchingError(why=exc_inst)
class Urllib2Fetcher(HTTPFetcher):
"""An C{L{HTTPFetcher}} that uses urllib2.
"""
# Parameterized for the benefit of testing frameworks, see
# http://trac.openidenabled.com/trac/ticket/85
urlopen = staticmethod(urllib2.urlopen)
def fetch(self, url, body=None, headers=None):
if not _allowedURL(url):
raise ValueError('Bad URL scheme: %r' % (url,))
if headers is None:
headers = {}
headers.setdefault(
'User-Agent',
"%s Python-urllib/%s" % (USER_AGENT, urllib2.__version__,))
req = urllib2.Request(url, data=body, headers=headers)
try:
f = self.urlopen(req)
try:
return self._makeResponse(f)
finally:
f.close()
except urllib2.HTTPError, why:
try:
return self._makeResponse(why)
finally:
why.close()
def _makeResponse(self, urllib2_response):
resp = HTTPResponse()
resp.body = urllib2_response.read(MAX_RESPONSE_KB * 1024)
resp.final_url = urllib2_response.geturl()
resp.headers = dict(urllib2_response.info().items())
if hasattr(urllib2_response, 'code'):
resp.status = urllib2_response.code
else:
resp.status = 200
return resp
class HTTPError(HTTPFetchingError):
"""
This exception is raised by the C{L{CurlHTTPFetcher}} when it
encounters an exceptional situation fetching a URL.
"""
pass
# XXX: define what we mean by paranoid, and make sure it is.
class CurlHTTPFetcher(HTTPFetcher):
"""
An C{L{HTTPFetcher}} that uses pycurl for fetching.
See U{http://pycurl.sourceforge.net/}.
"""
ALLOWED_TIME = 20 # seconds
def __init__(self):
HTTPFetcher.__init__(self)
if pycurl is None:
raise RuntimeError('Cannot find pycurl library')
def _parseHeaders(self, header_file):
header_file.seek(0)
# Remove the status line from the beginning of the input
unused_http_status_line = header_file.readline().lower ()
if unused_http_status_line.startswith('http/1.1 100 '):
unused_http_status_line = header_file.readline()
unused_http_status_line = header_file.readline()
lines = [line.strip() for line in header_file]
# and the blank line from the end
empty_line = lines.pop()
if empty_line:
raise HTTPError("No blank line at end of headers: %r" % (line,))
headers = {}
for line in lines:
try:
name, value = line.split(':', 1)
except ValueError:
raise HTTPError(
"Malformed HTTP header line in response: %r" % (line,))
value = value.strip()
# HTTP headers are case-insensitive
name = name.lower()
headers[name] = value
return headers
def _checkURL(self, url):
# XXX: document that this can be overridden to match desired policy
# XXX: make sure url is well-formed and routeable
return _allowedURL(url)
def fetch(self, url, body=None, headers=None):
stop = int(time.time()) + self.ALLOWED_TIME
off = self.ALLOWED_TIME
if headers is None:
headers = {}
headers.setdefault('User-Agent',
"%s %s" % (USER_AGENT, pycurl.version,))
header_list = []
if headers is not None:
for header_name, header_value in headers.iteritems():
header_list.append('%s: %s' % (header_name, header_value))
c = pycurl.Curl()
try:
c.setopt(pycurl.NOSIGNAL, 1)
if header_list:
c.setopt(pycurl.HTTPHEADER, header_list)
# Presence of a body indicates that we should do a POST
if body is not None:
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, body)
while off > 0:
if not self._checkURL(url):
raise HTTPError("Fetching URL not allowed: %r" % (url,))
data = cStringIO.StringIO()
def write_data(chunk):
if data.tell() > 1024*MAX_RESPONSE_KB:
return 0
else:
return data.write(chunk)
response_header_data = cStringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, write_data)
c.setopt(pycurl.HEADERFUNCTION, response_header_data.write)
c.setopt(pycurl.TIMEOUT, off)
c.setopt(pycurl.URL, openid.urinorm.urinorm(url))
c.perform()
response_headers = self._parseHeaders(response_header_data)
code = c.getinfo(pycurl.RESPONSE_CODE)
if code in [301, 302, 303, 307]:
url = response_headers.get('location')
if url is None:
raise HTTPError(
'Redirect (%s) returned without a location' % code)
# Redirects are always GETs
c.setopt(pycurl.POST, 0)
# There is no way to reset POSTFIELDS to empty and
# reuse the connection, but we only use it once.
else:
resp = HTTPResponse()
resp.headers = response_headers
resp.status = code
resp.final_url = url
resp.body = data.getvalue()
return resp
off = stop - int(time.time())
raise HTTPError("Timed out fetching: %r" % (url,))
finally:
c.close()
class HTTPLib2Fetcher(HTTPFetcher):
"""A fetcher that uses C{httplib2} for performing HTTP
requests. This implementation supports HTTP caching.
@see: http://bitworking.org/projects/httplib2/
"""
def __init__(self, cache=None):
"""@param cache: An object suitable for use as an C{httplib2}
cache. If a string is passed, it is assumed to be a
directory name.
"""
if httplib2 is None:
raise RuntimeError('Cannot find httplib2 library. '
'See http://bitworking.org/projects/httplib2/')
super(HTTPLib2Fetcher, self).__init__()
# An instance of the httplib2 object that performs HTTP requests
self.httplib2 = httplib2.Http(cache)
# We want httplib2 to raise exceptions for errors, just like
# the other fetchers.
self.httplib2.force_exception_to_status_code = False
def fetch(self, url, body=None, headers=None):
"""Perform an HTTP request
@raises Exception: Any exception that can be raised by httplib2
@see: C{L{HTTPFetcher.fetch}}
"""
if body:
method = 'POST'
else:
method = 'GET'
if headers is None:
headers = {}
# httplib2 doesn't check to make sure that the URL's scheme is
# 'http' so we do it here.
if not (url.startswith('http://') or url.startswith('https://')):
raise ValueError('URL is not a HTTP URL: %r' % (url,))
httplib2_response, content = self.httplib2.request(
url, method, body=body, headers=headers)
# Translate the httplib2 response to our HTTP response abstraction
# When a 400 is returned, there is no "content-location"
# header set. This seems like a bug to me. I can't think of a
# case where we really care about the final URL when it is an
# error response, but being careful about it can't hurt.
try:
final_url = httplib2_response['content-location']
except KeyError:
# We're assuming that no redirects occurred
assert not httplib2_response.previous
# And this should never happen for a successful response
assert httplib2_response.status != 200
final_url = url
return HTTPResponse(
body=content,
final_url=final_url,
headers=dict(httplib2_response.items()),
status=httplib2_response.status,
)
|
mit
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
24494,
14,
396,
14,
396,
63,
3535,
1192,
1882,
199,
624,
199,
2765,
859,
3509,
314,
3101,
5267,
281,
3217,
436,
9978,
12591,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
3535,
297,
283,
362,
2698,
11135,
281,
297,
283,
409,
2698,
11135,
281,
297,
283,
27068,
297,
1779,
283,
2856,
11135,
281,
297,
283,
981,
2856,
11135,
281,
297,
283,
2856,
11135,
316,
547,
297,
1779,
283,
12815,
418,
199,
199,
646,
4011,
18,
199,
646,
900,
199,
646,
15073,
199,
646,
984,
199,
199,
646,
24494,
199,
646,
24494,
14,
300,
262,
1025,
199,
199,
3,
7649,
370,
492,
8809,
18,
367,
13627,
2291,
199,
3,
1455,
921,
2075,
9818,
14,
1308,
15,
6776,
15,
12942,
18,
15,
199,
893,
26,
272,
492,
8809,
18,
199,
2590,
3545,
26,
272,
327,
8809,
18,
440,
2808,
272,
8809,
18,
275,
488,
199,
199,
3,
862,
370,
492,
1134,
17096,
12,
1314,
911,
4691,
2739,
675,
445,
633,
2856,
11135,
281,
199,
893,
26,
272,
492,
1134,
17096,
199,
2590,
3545,
26,
272,
1134,
17096,
275,
488,
199,
199,
3791,
63,
14565,
275,
298,
1548,
13,
15403,
3149,
83,
4366,
83,
2924,
450,
334,
15403,
855,
1023,
3108,
984,
14,
3246,
9,
199,
4283,
63,
12801,
63,
12780,
275,
6619,
199,
199,
318,
5267,
8,
633,
12,
2396,
29,
403,
12,
2323,
29,
403,
304,
272,
408,
27736,
314,
5267,
1083,
641,
314,
849,
5267,
281,
14,
17536,
4390,
272,
1077,
1929,
1454,
642,
1083,
14,
339,
768,
3536,
2186,
26,
1263,
4967,
626,
1443,
506,
4915,
701,
314,
849,
5267,
281,
272,
408,
272,
5267,
281,
275,
664,
2698,
11135,
281,
342,
272,
372,
5267,
281,
14,
3535,
8,
633,
12,
2396,
12,
2323,
9,
199,
199,
318,
1218,
2856,
11135,
281,
837,
272,
408,
2499,
282,
849,
3101,
5267,
281,
1256,
339,
20491,
1192,
445,
633,
370,
4011,
18,
1041,
272,
340,
1134,
17096,
365,
488,
26,
267,
5267,
281,
275,
20503,
773,
18,
11135,
281,
342,
272,
587,
26,
267,
5267,
281,
275,
445,
633,
2856,
11135,
281,
342,
339,
372,
5267,
281,
199,
199,
3,
22493,
314,
5544,
663,
3101,
5267,
281,
14,
982,
652,
365,
663,
370,
488,
12,
314,
199,
3,
3555,
911,
1240,
1218,
2856,
11135,
281,
342,
370,
663,
652,
14,
4226,
440,
2879,
642,
199,
3,
1750,
9682,
402,
642,
859,
14,
199,
63,
885,
63,
26983,
275,
488,
199,
199,
318,
664,
2698,
11135,
281,
837,
272,
408,
1767,
314,
849,
5267,
281,
1256,
272,
340,
949,
5267,
281,
965,
2757,
663,
12,
652,
911,
1218,
282,
849,
5267,
281,
14,
339,
768,
1107,
26,
314,
849,
5267,
281,
272,
768,
4500,
26,
3101,
11135,
281,
272,
408,
272,
2288,
485,
885,
63,
26983,
339,
340,
485,
885,
63,
26983,
365,
488,
26,
267,
663,
2698,
11135,
281,
8,
981,
2856,
11135,
281,
1012,
339,
372,
485,
885,
63,
26983,
199,
199,
318,
663,
2698,
11135,
281,
8,
26983,
12,
4816,
63,
3924,
29,
549,
304,
272,
408,
1084,
314,
849,
5267,
281,
339,
768,
635,
5267,
281,
26,
710,
5267,
281,
370,
675,
465,
314,
849,
3101,
5267,
281,
272,
768,
466,
5267,
281,
26,
3101,
11135,
281,
339,
768,
635,
4816,
63,
3924,
26,
7480,
370,
4816,
4967,
14031,
701,
314,
267,
5267,
281,
336,
382,
3101,
11135,
316,
547,
880,
626,
2985,
1443,
506,
15604,
267,
14905,
14,
4885,
849,
12,
4967,
911,
506,
8072,
14,
1010,
8605,
12,
267,
625,
9130,
5267,
1192,
787,
2997,
367,
10201,
402,
21239,
2552,
267,
503,
340,
2195,
5267,
281,
6534,
5521,
13,
3159,
4967,
626,
1265,
3955,
267,
2839,
370,
8579,
14,
272,
768,
466,
4816,
63,
3924,
26,
2155,
272,
408,
272,
2288,
485,
885,
63,
26983,
272,
340,
5267,
281,
365,
488,
503,
440,
4816,
63,
3924,
26,
267,
485,
885,
63,
26983,
275,
5267,
281,
272,
587,
26,
267,
485,
885,
63,
26983,
275,
2186,
55,
15521,
11135,
281,
8,
26983,
9,
199,
199,
318,
1808,
35,
633,
837,
272,
408,
26625,
314,
5544,
663,
3101,
5267,
281,
365,
282,
445,
633,
3101,
5267,
281,
1041,
272,
372,
1228,
8,
362,
2698,
11135,
281,
1062,
445,
633,
2856,
11135,
281,
9,
199,
199,
533,
29034,
8,
785,
304,
272,
408,
13933,
2213,
3004,
624,
272,
2323,
275,
488,
272,
2004,
275,
488,
272,
2396,
275,
488,
272,
4242,
63,
633,
275,
488,
339,
347,
636,
826,
721,
277,
12,
4242,
63,
633,
29,
403,
12,
2004,
29,
403,
12,
2323,
29,
403,
12,
2396,
29,
403,
304,
267,
291,
14,
5094,
63,
633,
275,
4242,
63,
633,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2139,
275,
2323,
267,
291,
14,
2030,
275,
2396,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
2004,
450,
83,
367,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
5101,
291,
14,
1205,
12,
5101,
291,
14,
5094,
63,
633,
9,
199,
199,
533,
3101,
11135,
281,
8,
785,
304,
272,
408,
272,
961,
1021,
365,
314,
3217,
367,
24494,
3101,
5267,
1192,
14,
221,
961,
272,
3217,
365,
1454,
11012,
340,
1265,
1929,
370,
2218,
282,
892,
5267,
281,
367,
272,
2005,
4499,
14,
272,
408,
339,
347,
5267,
8,
277,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
304,
267,
408,
267,
961,
18628,
376,
3101,
8761,
503,
9576,
12,
2569,
17784,
3180,
267,
314,
4340,
14,
982,
282,
2396,
365,
2013,
12,
2066,
314,
1056,
911,
506,
282,
267,
8761,
14,
6630,
12,
652,
911,
506,
282,
9576,
14,
7318,
768,
635,
2323,
26,
3101,
2323,
370,
2387,
543,
314,
1056,
267,
768,
466,
2323,
26,
469,
495,
26,
495,
93,
398,
768,
1107,
26,
1626,
909,
6144,
314,
1654,
1159,
3101,
1177,
14,
982,
288,
2337,
787,
2784,
503,
4113,
2552,
12,
376,
1919,
911,
506,
288,
4915,
14,
3101,
1125,
9320,
12,
2839,
7901,
503,
6891,
12,
886,
440,
288,
7675,
4967,
14,
398,
768,
4500,
26,
491,
91,
27068,
93,
398,
768,
3730,
2186,
26,
18029,
640,
12591,
911,
746,
288,
3365,
2552,
4079,
641,
314,
8793,
3101,
3555,
14
] |
[
1882,
511,
13,
2546,
13,
354,
26,
24494,
14,
396,
14,
396,
63,
3535,
1192,
1882,
199,
624,
199,
2765,
859,
3509,
314,
3101,
5267,
281,
3217,
436,
9978,
12591,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
3535,
297,
283,
362,
2698,
11135,
281,
297,
283,
409,
2698,
11135,
281,
297,
283,
27068,
297,
1779,
283,
2856,
11135,
281,
297,
283,
981,
2856,
11135,
281,
297,
283,
2856,
11135,
316,
547,
297,
1779,
283,
12815,
418,
199,
199,
646,
4011,
18,
199,
646,
900,
199,
646,
15073,
199,
646,
984,
199,
199,
646,
24494,
199,
646,
24494,
14,
300,
262,
1025,
199,
199,
3,
7649,
370,
492,
8809,
18,
367,
13627,
2291,
199,
3,
1455,
921,
2075,
9818,
14,
1308,
15,
6776,
15,
12942,
18,
15,
199,
893,
26,
272,
492,
8809,
18,
199,
2590,
3545,
26,
272,
327,
8809,
18,
440,
2808,
272,
8809,
18,
275,
488,
199,
199,
3,
862,
370,
492,
1134,
17096,
12,
1314,
911,
4691,
2739,
675,
445,
633,
2856,
11135,
281,
199,
893,
26,
272,
492,
1134,
17096,
199,
2590,
3545,
26,
272,
1134,
17096,
275,
488,
199,
199,
3791,
63,
14565,
275,
298,
1548,
13,
15403,
3149,
83,
4366,
83,
2924,
450,
334,
15403,
855,
1023,
3108,
984,
14,
3246,
9,
199,
4283,
63,
12801,
63,
12780,
275,
6619,
199,
199,
318,
5267,
8,
633,
12,
2396,
29,
403,
12,
2323,
29,
403,
304,
272,
408,
27736,
314,
5267,
1083,
641,
314,
849,
5267,
281,
14,
17536,
4390,
272,
1077,
1929,
1454,
642,
1083,
14,
339,
768,
3536,
2186,
26,
1263,
4967,
626,
1443,
506,
4915,
701,
314,
849,
5267,
281,
272,
408,
272,
5267,
281,
275,
664,
2698,
11135,
281,
342,
272,
372,
5267,
281,
14,
3535,
8,
633,
12,
2396,
12,
2323,
9,
199,
199,
318,
1218,
2856,
11135,
281,
837,
272,
408,
2499,
282,
849,
3101,
5267,
281,
1256,
339,
20491,
1192,
445,
633,
370,
4011,
18,
1041,
272,
340,
1134,
17096,
365,
488,
26,
267,
5267,
281,
275,
20503,
773,
18,
11135,
281,
342,
272,
587,
26,
267,
5267,
281,
275,
445,
633,
2856,
11135,
281,
342,
339,
372,
5267,
281,
199,
199,
3,
22493,
314,
5544,
663,
3101,
5267,
281,
14,
982,
652,
365,
663,
370,
488,
12,
314,
199,
3,
3555,
911,
1240,
1218,
2856,
11135,
281,
342,
370,
663,
652,
14,
4226,
440,
2879,
642,
199,
3,
1750,
9682,
402,
642,
859,
14,
199,
63,
885,
63,
26983,
275,
488,
199,
199,
318,
664,
2698,
11135,
281,
837,
272,
408,
1767,
314,
849,
5267,
281,
1256,
272,
340,
949,
5267,
281,
965,
2757,
663,
12,
652,
911,
1218,
282,
849,
5267,
281,
14,
339,
768,
1107,
26,
314,
849,
5267,
281,
272,
768,
4500,
26,
3101,
11135,
281,
272,
408,
272,
2288,
485,
885,
63,
26983,
339,
340,
485,
885,
63,
26983,
365,
488,
26,
267,
663,
2698,
11135,
281,
8,
981,
2856,
11135,
281,
1012,
339,
372,
485,
885,
63,
26983,
199,
199,
318,
663,
2698,
11135,
281,
8,
26983,
12,
4816,
63,
3924,
29,
549,
304,
272,
408,
1084,
314,
849,
5267,
281,
339,
768,
635,
5267,
281,
26,
710,
5267,
281,
370,
675,
465,
314,
849,
3101,
5267,
281,
272,
768,
466,
5267,
281,
26,
3101,
11135,
281,
339,
768,
635,
4816,
63,
3924,
26,
7480,
370,
4816,
4967,
14031,
701,
314,
267,
5267,
281,
336,
382,
3101,
11135,
316,
547,
880,
626,
2985,
1443,
506,
15604,
267,
14905,
14,
4885,
849,
12,
4967,
911,
506,
8072,
14,
1010,
8605,
12,
267,
625,
9130,
5267,
1192,
787,
2997,
367,
10201,
402,
21239,
2552,
267,
503,
340,
2195,
5267,
281,
6534,
5521,
13,
3159,
4967,
626,
1265,
3955,
267,
2839,
370,
8579,
14,
272,
768,
466,
4816,
63,
3924,
26,
2155,
272,
408,
272,
2288,
485,
885,
63,
26983,
272,
340,
5267,
281,
365,
488,
503,
440,
4816,
63,
3924,
26,
267,
485,
885,
63,
26983,
275,
5267,
281,
272,
587,
26,
267,
485,
885,
63,
26983,
275,
2186,
55,
15521,
11135,
281,
8,
26983,
9,
199,
199,
318,
1808,
35,
633,
837,
272,
408,
26625,
314,
5544,
663,
3101,
5267,
281,
365,
282,
445,
633,
3101,
5267,
281,
1041,
272,
372,
1228,
8,
362,
2698,
11135,
281,
1062,
445,
633,
2856,
11135,
281,
9,
199,
199,
533,
29034,
8,
785,
304,
272,
408,
13933,
2213,
3004,
624,
272,
2323,
275,
488,
272,
2004,
275,
488,
272,
2396,
275,
488,
272,
4242,
63,
633,
275,
488,
339,
347,
636,
826,
721,
277,
12,
4242,
63,
633,
29,
403,
12,
2004,
29,
403,
12,
2323,
29,
403,
12,
2396,
29,
403,
304,
267,
291,
14,
5094,
63,
633,
275,
4242,
63,
633,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2139,
275,
2323,
267,
291,
14,
2030,
275,
2396,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
2004,
450,
83,
367,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
5101,
291,
14,
1205,
12,
5101,
291,
14,
5094,
63,
633,
9,
199,
199,
533,
3101,
11135,
281,
8,
785,
304,
272,
408,
272,
961,
1021,
365,
314,
3217,
367,
24494,
3101,
5267,
1192,
14,
221,
961,
272,
3217,
365,
1454,
11012,
340,
1265,
1929,
370,
2218,
282,
892,
5267,
281,
367,
272,
2005,
4499,
14,
272,
408,
339,
347,
5267,
8,
277,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
304,
267,
408,
267,
961,
18628,
376,
3101,
8761,
503,
9576,
12,
2569,
17784,
3180,
267,
314,
4340,
14,
982,
282,
2396,
365,
2013,
12,
2066,
314,
1056,
911,
506,
282,
267,
8761,
14,
6630,
12,
652,
911,
506,
282,
9576,
14,
7318,
768,
635,
2323,
26,
3101,
2323,
370,
2387,
543,
314,
1056,
267,
768,
466,
2323,
26,
469,
495,
26,
495,
93,
398,
768,
1107,
26,
1626,
909,
6144,
314,
1654,
1159,
3101,
1177,
14,
982,
288,
2337,
787,
2784,
503,
4113,
2552,
12,
376,
1919,
911,
506,
288,
4915,
14,
3101,
1125,
9320,
12,
2839,
7901,
503,
6891,
12,
886,
440,
288,
7675,
4967,
14,
398,
768,
4500,
26,
491,
91,
27068,
93,
398,
768,
3730,
2186,
26,
18029,
640,
12591,
911,
746,
288,
3365,
2552,
4079,
641,
314,
8793,
3101,
3555,
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,
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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
] |
ermin-sakic/common-open-research-emulator-CORE
|
coreemu-read-only/daemon/core/emane/ieee80211abg.py
|
8
|
7116
|
#
# CORE
# Copyright (c)2010-2014 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# author: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
#
'''
ieee80211abg.py: EMANE IEEE 802.11abg model for CORE
'''
import sys
import string
try:
from emanesh.events import EventService
except:
pass
from core.api import coreapi
from core.constants import *
from emane import EmaneModel
from universal import EmaneUniversalModel
class EmaneIeee80211abgModel(EmaneModel):
def __init__(self, session, objid = None, verbose = False):
EmaneModel.__init__(self, session, objid, verbose)
# model name
_name = "emane_ieee80211abg"
_80211rates = '1 1 Mbps,2 2 Mbps,3 5.5 Mbps,4 11 Mbps,5 6 Mbps,' + \
'6 9 Mbps,7 12 Mbps,8 18 Mbps,9 24 Mbps,10 36 Mbps,11 48 Mbps,' + \
'12 54 Mbps'
if 'EventService' in globals():
xml_path = '/usr/share/emane/xml/models/mac/ieee80211abg'
else:
xml_path = "/usr/share/emane/models/ieee80211abg/xml"
# MAC parameters
_confmatrix_mac_base = [
("mode", coreapi.CONF_DATA_TYPE_UINT8, '0',
'0 802.11b (DSSS only),1 802.11b (DSSS only),' + \
'2 802.11a or g (OFDM),3 802.11b/g (DSSS and OFDM)', 'mode'),
("enablepromiscuousmode", coreapi.CONF_DATA_TYPE_BOOL, '0',
'On,Off', 'enable promiscuous mode'),
("distance", coreapi.CONF_DATA_TYPE_UINT32, '1000',
'', 'max distance (m)'),
("unicastrate", coreapi.CONF_DATA_TYPE_UINT8, '4', _80211rates,
'unicast rate (Mbps)'),
("multicastrate", coreapi.CONF_DATA_TYPE_UINT8, '1', _80211rates,
'multicast rate (Mbps)'),
("rtsthreshold", coreapi.CONF_DATA_TYPE_UINT16, '0',
'', 'RTS threshold (bytes)'),
("pcrcurveuri", coreapi.CONF_DATA_TYPE_STRING,
'%s/ieee80211pcr.xml' % xml_path,
'', 'SINR/PCR curve file'),
("flowcontrolenable", coreapi.CONF_DATA_TYPE_BOOL, '0',
'On,Off', 'enable traffic flow control'),
("flowcontroltokens", coreapi.CONF_DATA_TYPE_UINT16, '10',
'', 'number of flow control tokens'),
]
# mac parameters introduced in EMANE 0.8.1
# Note: The entry format for category queue parameters (queuesize, aifs, etc) were changed in
# EMANE 9.x, but are being preserved for the time being due to space constraints in the
# CORE GUI. A conversion function (get9xmacparamequivalent) has been defined to support this.
_confmatrix_mac_extended = [
("wmmenable", coreapi.CONF_DATA_TYPE_BOOL, '0',
'On,Off', 'WiFi Multimedia (WMM)'),
("queuesize", coreapi.CONF_DATA_TYPE_STRING, '0:255 1:255 2:255 3:255',
'', 'queue size (0-4:size)'),
("cwmin", coreapi.CONF_DATA_TYPE_STRING, '0:32 1:32 2:16 3:8',
'', 'min contention window (0-4:minw)'),
("cwmax", coreapi.CONF_DATA_TYPE_STRING, '0:1024 1:1024 2:64 3:16',
'', 'max contention window (0-4:maxw)'),
("aifs", coreapi.CONF_DATA_TYPE_STRING, '0:2 1:2 2:2 3:1',
'', 'arbitration inter frame space (0-4:aifs)'),
("txop", coreapi.CONF_DATA_TYPE_STRING, '0:0 1:0 2:0 3:0',
'', 'txop (0-4:usec)'),
("retrylimit", coreapi.CONF_DATA_TYPE_STRING, '0:3 1:3 2:3 3:3',
'', 'retry limit (0-4:numretries)'),
]
_confmatrix_mac = _confmatrix_mac_base + _confmatrix_mac_extended
# PHY parameters from Universal PHY
_confmatrix_phy = EmaneUniversalModel._confmatrix
_confmatrix = _confmatrix_mac + _confmatrix_phy
# value groupings
_confgroups = "802.11 MAC Parameters:1-%d|Universal PHY Parameters:%d-%d" \
% (len(_confmatrix_mac), len(_confmatrix_mac) + 1, len(_confmatrix))
def buildnemxmlfiles(self, e, ifc):
''' Build the necessary nem, mac, and phy XMLs in the given path.
If an individual NEM has a nonstandard config, we need to build
that file also. Otherwise the WLAN-wide
nXXemane_ieee80211abgnem.xml, nXXemane_ieee80211abgemac.xml,
nXXemane_ieee80211abgphy.xml are used.
'''
values = e.getifcconfig(self.objid, self._name,
self.getdefaultvalues(), ifc)
if values is None:
return
nemdoc = e.xmldoc("nem")
nem = nemdoc.getElementsByTagName("nem").pop()
nem.setAttribute("name", "ieee80211abg NEM")
e.appendtransporttonem(nemdoc, nem, self.objid, ifc)
mactag = nemdoc.createElement("mac")
mactag.setAttribute("definition", self.macxmlname(ifc))
nem.appendChild(mactag)
phytag = nemdoc.createElement("phy")
phytag.setAttribute("definition", self.phyxmlname(ifc))
nem.appendChild(phytag)
e.xmlwrite(nemdoc, self.nemxmlname(ifc))
macdoc = e.xmldoc("mac")
mac = macdoc.getElementsByTagName("mac").pop()
mac.setAttribute("name", "ieee80211abg MAC")
mac.setAttribute("library", "ieee80211abgmaclayer")
names = self.getnames()
macnames = names[:len(self._confmatrix_mac)]
phynames = names[len(self._confmatrix_mac):]
# append all MAC options to macdoc
if 'EventService' in globals():
for macname in macnames:
mac9xnvpairlist = self.get9xmacparamequivalent(macname, values)
for nvpair in mac9xnvpairlist:
mac.appendChild(e.xmlparam(macdoc, nvpair[0], nvpair[1]))
else:
map( lambda n: mac.appendChild(e.xmlparam(macdoc, n, \
self.valueof(n, values))), macnames)
e.xmlwrite(macdoc, self.macxmlname(ifc))
phydoc = EmaneUniversalModel.getphydoc(e, self, values, phynames)
e.xmlwrite(phydoc, self.phyxmlname(ifc))
#
# TEMP HACK: Account for parameter convention change in EMANE 9.x
# This allows CORE to preserve the entry layout for the mac 'category' parameters
# and work with EMANE 9.x onwards.
#
def get9xmacparamequivalent(self, macname, values):
''' Generate a list of 80211abg mac parameters in 0.9.x layout for a given mac parameter
in 8.x layout.For mac category parameters, the list returned will contain the four
equivalent 9.x parameter and value pairs. Otherwise, the list returned will only
contain a single name and value pair.
'''
nvpairlist = []
macparmval = self.valueof(macname, values)
if macname in ["queuesize","aifs","cwmin","cwmax","txop","retrylimit"]:
for catval in macparmval.split():
idx_and_val = catval.split(":")
idx = int(idx_and_val[0])
val = idx_and_val[1]
# aifs and tx are in microseconds. Convert to seconds.
if macname in ["aifs","txop"]:
val = "%f" % (float(val)*(1e-6))
name9x = "%s%d" % (macname, idx)
nvpairlist.append([name9x, val])
else:
nvpairlist.append([macname, macparmval])
return nvpairlist
|
bsd-3-clause
|
[
3,
199,
3,
445,
5788,
199,
3,
1898,
334,
67,
9,
6542,
13,
7280,
314,
5088,
69,
316,
15878,
14,
199,
3,
1666,
314,
5113,
570,
5120,
315,
642,
4084,
14,
199,
3,
199,
3,
4132,
26,
1603,
3609,
437,
72,
828,
24588,
90,
665,
74,
3609,
17885,
14,
77,
14,
11326,
828,
24588,
90,
32,
656,
69,
316,
14,
957,
30,
199,
3,
199,
2344,
199,
73,
18777,
11366,
845,
371,
71,
14,
647,
26,
662,
6588,
37,
473,
29146,
1695,
996,
14,
845,
371,
71,
1402,
367,
445,
5788,
199,
2344,
199,
199,
646,
984,
199,
646,
1059,
199,
893,
26,
272,
687,
325,
1237,
10613,
14,
4368,
492,
6763,
3167,
199,
2590,
26,
272,
986,
199,
504,
6170,
14,
1246,
492,
6170,
1246,
199,
504,
6170,
14,
5559,
492,
627,
199,
504,
325,
1237,
69,
492,
662,
1237,
69,
1685,
199,
504,
17508,
492,
662,
1237,
69,
1358,
10959,
1685,
199,
199,
533,
662,
1237,
69,
41,
18777,
11366,
845,
371,
71,
1685,
8,
37,
1237,
69,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
2351,
12,
1559,
344,
275,
488,
12,
3376,
275,
756,
304,
267,
662,
1237,
69,
1685,
855,
826,
721,
277,
12,
2351,
12,
1559,
344,
12,
3376,
9,
339,
327,
1402,
536,
272,
485,
354,
275,
298,
69,
1237,
69,
63,
73,
18777,
11366,
845,
371,
71,
2,
272,
485,
11366,
845,
17153,
275,
283,
17,
413,
603,
66,
1190,
12,
18,
499,
603,
66,
1190,
12,
19,
959,
14,
21,
603,
66,
1190,
12,
20,
4119,
603,
66,
1190,
12,
21,
1227,
603,
66,
1190,
2584,
435,
971,
268,
283,
22,
1749,
603,
66,
1190,
12,
23,
3144,
603,
66,
1190,
12,
24,
6155,
603,
66,
1190,
12,
25,
5504,
603,
66,
1190,
12,
709,
8780,
603,
66,
1190,
12,
845,
9615,
603,
66,
1190,
2584,
435,
971,
268,
283,
713,
13470,
603,
66,
1190,
7,
272,
340,
283,
2390,
3167,
7,
315,
7992,
837,
267,
2748,
63,
515,
275,
1994,
2647,
15,
6251,
15,
69,
1237,
69,
15,
1652,
15,
992,
15,
3088,
15,
73,
18777,
11366,
845,
371,
71,
7,
272,
587,
26,
267,
2748,
63,
515,
275,
3286,
2647,
15,
6251,
15,
69,
1237,
69,
15,
992,
15,
73,
18777,
11366,
845,
371,
71,
15,
1652,
2,
339,
327,
13347,
2633,
272,
485,
2190,
3642,
63,
3088,
63,
1095,
275,
359,
267,
1689,
632,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
16,
297,
268,
283,
16,
1695,
996,
14,
845,
66,
334,
36,
2300,
51,
1454,
395,
17,
1695,
996,
14,
845,
66,
334,
36,
2300,
51,
1454,
26582,
435,
971,
268,
283,
18,
1695,
996,
14,
845,
65,
503,
486,
334,
3359,
17751,
395,
19,
1695,
996,
14,
845,
66,
15,
71,
334,
36,
2300,
51,
436,
1634,
17751,
3196,
283,
632,
659,
267,
1689,
4296,
12741,
27641,
632,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
4296,
8023,
27641,
818,
659,
267,
1689,
5590,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
708,
12,
283,
5279,
297,
268,
3260,
283,
988,
6033,
334,
77,
11218,
267,
1689,
5209,
65,
18161,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
20,
297,
485,
11366,
845,
17153,
12,
268,
283,
5209,
1810,
6634,
334,
20590,
11218,
267,
1689,
3029,
696,
18161,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
17,
297,
485,
11366,
845,
17153,
12,
268,
283,
23797,
6634,
334,
20590,
11218,
267,
1689,
2591,
17082,
4480,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
975,
12,
283,
16,
297,
268,
3260,
283,
50,
9730,
8765,
334,
2394,
11218,
267,
1689,
80,
1556,
11895,
2302,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
268,
1543,
83,
15,
73,
18777,
11366,
845,
80,
1556,
14,
1652,
7,
450,
2748,
63,
515,
12,
268,
3260,
283,
51,
568,
50,
15,
48,
2944,
15318,
570,
659,
267,
1689,
1659,
31215,
552,
461,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
4296,
15602,
6369,
3304,
659,
267,
1689,
1659,
2785,
4504,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
975,
12,
283,
709,
297,
268,
3260,
283,
1955,
402,
6369,
3304,
4645,
659,
272,
1622,
272,
327,
4497,
2633,
21399,
315,
662,
6588,
37,
378,
14,
24,
14,
17,
5591,
327,
3390,
26,
710,
2397,
1475,
367,
4637,
4126,
2633,
334,
1825,
890,
12,
282,
20985,
12,
5423,
9,
4898,
2896,
315,
272,
327,
662,
6588,
37,
1749,
14,
88,
12,
1325,
787,
3769,
17731,
367,
314,
900,
3769,
7037,
370,
4601,
9565,
315,
314,
272,
327,
445,
5788,
17160,
14,
437,
8603,
805,
334,
362,
25,
88,
3088,
8121,
6190,
9,
965,
2757,
3247,
370,
2291,
642,
14,
5591,
485,
2190,
3642,
63,
3088,
63,
10525,
275,
359,
267,
1689,
16240,
1410,
461,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
55,
73,
9047,
22578,
521,
2391,
334,
55,
3218,
11218,
267,
1689,
1825,
890,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
2299,
413,
26,
2299,
499,
26,
2299,
650,
26,
2299,
297,
268,
3260,
283,
1825,
1568,
334,
16,
13,
20,
26,
890,
11218,
267,
1689,
15346,
827,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
708,
413,
26,
708,
499,
26,
975,
650,
26,
24,
297,
268,
3260,
283,
827,
406,
9553,
4353,
334,
16,
13,
20,
26,
827,
87,
11218,
267,
1689,
15346,
988,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
7727,
413,
26,
7727,
499,
26,
772,
650,
26,
975,
297,
268,
3260,
283,
988,
406,
9553,
4353,
334,
16,
13,
20,
26,
988,
87,
11218,
267,
1689,
65,
20985,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283
] |
[
199,
3,
445,
5788,
199,
3,
1898,
334,
67,
9,
6542,
13,
7280,
314,
5088,
69,
316,
15878,
14,
199,
3,
1666,
314,
5113,
570,
5120,
315,
642,
4084,
14,
199,
3,
199,
3,
4132,
26,
1603,
3609,
437,
72,
828,
24588,
90,
665,
74,
3609,
17885,
14,
77,
14,
11326,
828,
24588,
90,
32,
656,
69,
316,
14,
957,
30,
199,
3,
199,
2344,
199,
73,
18777,
11366,
845,
371,
71,
14,
647,
26,
662,
6588,
37,
473,
29146,
1695,
996,
14,
845,
371,
71,
1402,
367,
445,
5788,
199,
2344,
199,
199,
646,
984,
199,
646,
1059,
199,
893,
26,
272,
687,
325,
1237,
10613,
14,
4368,
492,
6763,
3167,
199,
2590,
26,
272,
986,
199,
504,
6170,
14,
1246,
492,
6170,
1246,
199,
504,
6170,
14,
5559,
492,
627,
199,
504,
325,
1237,
69,
492,
662,
1237,
69,
1685,
199,
504,
17508,
492,
662,
1237,
69,
1358,
10959,
1685,
199,
199,
533,
662,
1237,
69,
41,
18777,
11366,
845,
371,
71,
1685,
8,
37,
1237,
69,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
2351,
12,
1559,
344,
275,
488,
12,
3376,
275,
756,
304,
267,
662,
1237,
69,
1685,
855,
826,
721,
277,
12,
2351,
12,
1559,
344,
12,
3376,
9,
339,
327,
1402,
536,
272,
485,
354,
275,
298,
69,
1237,
69,
63,
73,
18777,
11366,
845,
371,
71,
2,
272,
485,
11366,
845,
17153,
275,
283,
17,
413,
603,
66,
1190,
12,
18,
499,
603,
66,
1190,
12,
19,
959,
14,
21,
603,
66,
1190,
12,
20,
4119,
603,
66,
1190,
12,
21,
1227,
603,
66,
1190,
2584,
435,
971,
268,
283,
22,
1749,
603,
66,
1190,
12,
23,
3144,
603,
66,
1190,
12,
24,
6155,
603,
66,
1190,
12,
25,
5504,
603,
66,
1190,
12,
709,
8780,
603,
66,
1190,
12,
845,
9615,
603,
66,
1190,
2584,
435,
971,
268,
283,
713,
13470,
603,
66,
1190,
7,
272,
340,
283,
2390,
3167,
7,
315,
7992,
837,
267,
2748,
63,
515,
275,
1994,
2647,
15,
6251,
15,
69,
1237,
69,
15,
1652,
15,
992,
15,
3088,
15,
73,
18777,
11366,
845,
371,
71,
7,
272,
587,
26,
267,
2748,
63,
515,
275,
3286,
2647,
15,
6251,
15,
69,
1237,
69,
15,
992,
15,
73,
18777,
11366,
845,
371,
71,
15,
1652,
2,
339,
327,
13347,
2633,
272,
485,
2190,
3642,
63,
3088,
63,
1095,
275,
359,
267,
1689,
632,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
16,
297,
268,
283,
16,
1695,
996,
14,
845,
66,
334,
36,
2300,
51,
1454,
395,
17,
1695,
996,
14,
845,
66,
334,
36,
2300,
51,
1454,
26582,
435,
971,
268,
283,
18,
1695,
996,
14,
845,
65,
503,
486,
334,
3359,
17751,
395,
19,
1695,
996,
14,
845,
66,
15,
71,
334,
36,
2300,
51,
436,
1634,
17751,
3196,
283,
632,
659,
267,
1689,
4296,
12741,
27641,
632,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
4296,
8023,
27641,
818,
659,
267,
1689,
5590,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
708,
12,
283,
5279,
297,
268,
3260,
283,
988,
6033,
334,
77,
11218,
267,
1689,
5209,
65,
18161,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
20,
297,
485,
11366,
845,
17153,
12,
268,
283,
5209,
1810,
6634,
334,
20590,
11218,
267,
1689,
3029,
696,
18161,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
24,
12,
283,
17,
297,
485,
11366,
845,
17153,
12,
268,
283,
23797,
6634,
334,
20590,
11218,
267,
1689,
2591,
17082,
4480,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
975,
12,
283,
16,
297,
268,
3260,
283,
50,
9730,
8765,
334,
2394,
11218,
267,
1689,
80,
1556,
11895,
2302,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
268,
1543,
83,
15,
73,
18777,
11366,
845,
80,
1556,
14,
1652,
7,
450,
2748,
63,
515,
12,
268,
3260,
283,
51,
568,
50,
15,
48,
2944,
15318,
570,
659,
267,
1689,
1659,
31215,
552,
461,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
4296,
15602,
6369,
3304,
659,
267,
1689,
1659,
2785,
4504,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
17459,
975,
12,
283,
709,
297,
268,
3260,
283,
1955,
402,
6369,
3304,
4645,
659,
272,
1622,
272,
327,
4497,
2633,
21399,
315,
662,
6588,
37,
378,
14,
24,
14,
17,
5591,
327,
3390,
26,
710,
2397,
1475,
367,
4637,
4126,
2633,
334,
1825,
890,
12,
282,
20985,
12,
5423,
9,
4898,
2896,
315,
272,
327,
662,
6588,
37,
1749,
14,
88,
12,
1325,
787,
3769,
17731,
367,
314,
900,
3769,
7037,
370,
4601,
9565,
315,
314,
272,
327,
445,
5788,
17160,
14,
437,
8603,
805,
334,
362,
25,
88,
3088,
8121,
6190,
9,
965,
2757,
3247,
370,
2291,
642,
14,
5591,
485,
2190,
3642,
63,
3088,
63,
10525,
275,
359,
267,
1689,
16240,
1410,
461,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
16026,
12,
283,
16,
297,
268,
283,
3314,
12,
5195,
297,
283,
55,
73,
9047,
22578,
521,
2391,
334,
55,
3218,
11218,
267,
1689,
1825,
890,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
2299,
413,
26,
2299,
499,
26,
2299,
650,
26,
2299,
297,
268,
3260,
283,
1825,
1568,
334,
16,
13,
20,
26,
890,
11218,
267,
1689,
15346,
827,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
708,
413,
26,
708,
499,
26,
975,
650,
26,
24,
297,
268,
3260,
283,
827,
406,
9553,
4353,
334,
16,
13,
20,
26,
827,
87,
11218,
267,
1689,
15346,
988,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
283,
16,
26,
7727,
413,
26,
7727,
499,
26,
772,
650,
26,
975,
297,
268,
3260,
283,
988,
406,
9553,
4353,
334,
16,
13,
20,
26,
988,
87,
11218,
267,
1689,
65,
20985,
401,
6170,
1246,
14,
3103,
63,
3998,
63,
2711,
63,
5353,
12,
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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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
] |
CubicERP/odoo
|
addons/stock/tests/test_stock_flow.py
|
219
|
74767
|
# -*- coding: utf-8 -*-
from openerp.addons.stock.tests.common import TestStockCommon
from openerp.tools import mute_logger, float_round
class TestStockFlow(TestStockCommon):
@mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models')
def test_00_picking_create_and_transfer_quantity(self):
""" Basic stock operation on incoming and outgoing shipment. """
LotObj = self.env['stock.production.lot']
# ----------------------------------------------------------------------
# Create incoming shipment of product A, B, C, D
# ----------------------------------------------------------------------
# Product A ( 1 Unit ) , Product C ( 10 Unit )
# Product B ( 1 Unit ) , Product D ( 10 Unit )
# Product D ( 5 Unit )
# ----------------------------------------------------------------------
picking_in = self.PickingObj.create({
'partner_id': self.partner_delta_id,
'picking_type_id': self.picking_type_in})
self.MoveObj.create({
'name': self.productA.name,
'product_id': self.productA.id,
'product_uom_qty': 1,
'product_uom': self.productA.uom_id.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.productB.name,
'product_id': self.productB.id,
'product_uom_qty': 1,
'product_uom': self.productB.uom_id.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.productC.name,
'product_id': self.productC.id,
'product_uom_qty': 10,
'product_uom': self.productC.uom_id.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.productD.name,
'product_id': self.productD.id,
'product_uom_qty': 10,
'product_uom': self.productD.uom_id.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.productD.name,
'product_id': self.productD.id,
'product_uom_qty': 5,
'product_uom': self.productD.uom_id.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'draft', 'Wrong state of move line.')
# Confirm incoming shipment.
picking_in.action_confirm()
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
# ----------------------------------------------------------------------
# Replace pack operation of incoming shipments.
# ----------------------------------------------------------------------
picking_in.do_prepare_partial()
self.StockPackObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', picking_in.id)]).write({
'product_qty': 4.0})
self.StockPackObj.search([('product_id', '=', self.productB.id), ('picking_id', '=', picking_in.id)]).write({
'product_qty': 5.0})
self.StockPackObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', picking_in.id)]).write({
'product_qty': 5.0})
self.StockPackObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', picking_in.id)]).write({
'product_qty': 5.0})
lot2_productC = LotObj.create({'name': 'C Lot 2', 'product_id': self.productC.id})
self.StockPackObj.create({
'product_id': self.productC.id,
'product_qty': 2,
'product_uom_id': self.productC.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': picking_in.id,
'lot_id': lot2_productC.id})
self.StockPackObj.create({
'product_id': self.productD.id,
'product_qty': 2,
'product_uom_id': self.productD.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': picking_in.id})
# Check incoming shipment total quantity of pack operation
packs = self.StockPackObj.search([('picking_id', '=', picking_in.id)])
total_qty = [pack.product_qty for pack in packs]
self.assertEqual(sum(total_qty), 23, 'Wrong quantity in pack operation (%s found instead of 23)' % (sum(total_qty)))
# Transfer Incoming Shipment.
picking_in.do_transfer()
# ----------------------------------------------------------------------
# Check state, quantity and total moves of incoming shipment.
# ----------------------------------------------------------------------
# Check total no of move lines of incoming shipment.
self.assertEqual(len(picking_in.move_lines), 6, 'Wrong number of move lines.')
# Check incoming shipment state.
self.assertEqual(picking_in.state, 'done', 'Incoming shipment state should be done.')
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'done', 'Wrong state of move line.')
# Check product A done quantity must be 3 and 1
moves = self.MoveObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', picking_in.id)])
a_done_qty = [move.product_uom_qty for move in moves]
self.assertEqual(set(a_done_qty), set([1.0, 3.0]), 'Wrong move quantity for product A.')
# Check product B done quantity must be 4 and 1
moves = self.MoveObj.search([('product_id', '=', self.productB.id), ('picking_id', '=', picking_in.id)])
b_done_qty = [move.product_uom_qty for move in moves]
self.assertEqual(set(b_done_qty), set([4.0, 1.0]), 'Wrong move quantity for product B.')
# Check product C done quantity must be 7
c_done_qty = self.MoveObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', picking_in.id)], limit=1).product_uom_qty
self.assertEqual(c_done_qty, 7.0, 'Wrong move quantity of product C (%s found instead of 7)' % (c_done_qty))
# Check product D done quantity must be 7
d_done_qty = self.MoveObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', picking_in.id)], limit=1).product_uom_qty
self.assertEqual(d_done_qty, 7.0, 'Wrong move quantity of product D (%s found instead of 7)' % (d_done_qty))
# ----------------------------------------------------------------------
# Check Back order of Incoming shipment.
# ----------------------------------------------------------------------
# Check back order created or not.
back_order_in = self.PickingObj.search([('backorder_id', '=', picking_in.id)])
self.assertEqual(len(back_order_in), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(back_order_in.move_lines), 3, 'Wrong number of move lines.')
# Check back order should be created with 3 quantity of product C.
moves = self.MoveObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', back_order_in.id)])
product_c_qty = [move.product_uom_qty for move in moves]
self.assertEqual(sum(product_c_qty), 3.0, 'Wrong move quantity of product C (%s found instead of 3)' % (product_c_qty))
# Check back order should be created with 8 quantity of product D.
moves = self.MoveObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', back_order_in.id)])
product_d_qty = [move.product_uom_qty for move in moves]
self.assertEqual(sum(product_d_qty), 8.0, 'Wrong move quantity of product D (%s found instead of 8)' % (product_d_qty))
# ======================================================================
# Create Outgoing shipment with ...
# product A ( 10 Unit ) , product B ( 5 Unit )
# product C ( 3 unit ) , product D ( 10 Unit )
# ======================================================================
picking_out = self.PickingObj.create({
'partner_id': self.partner_agrolite_id,
'picking_type_id': self.picking_type_out})
self.MoveObj.create({
'name': self.productA.name,
'product_id': self.productA.id,
'product_uom_qty': 10,
'product_uom': self.productA.uom_id.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.productB.name,
'product_id': self.productB.id,
'product_uom_qty': 5,
'product_uom': self.productB.uom_id.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.productC.name,
'product_id': self.productC.id,
'product_uom_qty': 3,
'product_uom': self.productC.uom_id.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.productD.name,
'product_id': self.productD.id,
'product_uom_qty': 10,
'product_uom': self.productD.uom_id.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
# Confirm outgoing shipment.
picking_out.action_confirm()
for move in picking_out.move_lines:
self.assertEqual(move.state, 'confirmed', 'Wrong state of move line.')
# Product assign to outgoing shipments
picking_out.action_assign()
for move in picking_out.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
# Check availability for product A
aval_a_qty = self.MoveObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(aval_a_qty, 4.0, 'Wrong move quantity availability of product A (%s found instead of 4)' % (aval_a_qty))
# Check availability for product B
aval_b_qty = self.MoveObj.search([('product_id', '=', self.productB.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(aval_b_qty, 5.0, 'Wrong move quantity availability of product B (%s found instead of 5)' % (aval_b_qty))
# Check availability for product C
aval_c_qty = self.MoveObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(aval_c_qty, 3.0, 'Wrong move quantity availability of product C (%s found instead of 3)' % (aval_c_qty))
# Check availability for product D
aval_d_qty = self.MoveObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(aval_d_qty, 7.0, 'Wrong move quantity availability of product D (%s found instead of 7)' % (aval_d_qty))
# ----------------------------------------------------------------------
# Replace pack operation of outgoing shipment.
# ----------------------------------------------------------------------
picking_out.do_prepare_partial()
self.StockPackObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', picking_out.id)]).write({'product_qty': 2.0})
self.StockPackObj.search([('product_id', '=', self.productB.id), ('picking_id', '=', picking_out.id)]).write({'product_qty': 3.0})
self.StockPackObj.create({
'product_id': self.productB.id,
'product_qty': 2,
'product_uom_id': self.productB.uom_id.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location,
'picking_id': picking_out.id})
self.StockPackObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', picking_out.id)]).write({
'product_qty': 2.0, 'lot_id': lot2_productC.id})
self.StockPackObj.create({
'product_id': self.productC.id,
'product_qty': 3,
'product_uom_id': self.productC.uom_id.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location,
'picking_id': picking_out.id})
self.StockPackObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', picking_out.id)]).write({'product_qty': 6.0})
# Transfer picking.
picking_out.do_transfer()
# ----------------------------------------------------------------------
# Check state, quantity and total moves of outgoing shipment.
# ----------------------------------------------------------------------
# check outgoing shipment status.
self.assertEqual(picking_out.state, 'done', 'Wrong state of outgoing shipment.')
# check outgoing shipment total moves and and its state.
self.assertEqual(len(picking_out.move_lines), 5, 'Wrong number of move lines')
for move in picking_out.move_lines:
self.assertEqual(move.state, 'done', 'Wrong state of move line.')
back_order_out = self.PickingObj.search([('backorder_id', '=', picking_out.id)])
#------------------
# Check back order.
# -----------------
self.assertEqual(len(back_order_out), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(back_order_out.move_lines), 2, 'Wrong number of move lines')
# Check back order should be created with 8 quantity of product A.
product_a_qty = self.MoveObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', back_order_out.id)], limit=1).product_uom_qty
self.assertEqual(product_a_qty, 8.0, 'Wrong move quantity of product A (%s found instead of 8)' % (product_a_qty))
# Check back order should be created with 4 quantity of product D.
product_d_qty = self.MoveObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', back_order_out.id)], limit=1).product_uom_qty
self.assertEqual(product_d_qty, 4.0, 'Wrong move quantity of product D (%s found instead of 4)' % (product_d_qty))
#-----------------------------------------------------------------------
# Check stock location quant quantity and quantity available
# of product A, B, C, D
#-----------------------------------------------------------------------
# Check quants and available quantity for product A
quants = self.StockQuantObj.search([('product_id', '=', self.productA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 2.0, 'Expecting 2.0 Unit , got %.4f Unit on location stock!' % (sum(total_qty)))
self.assertEqual(self.productA.qty_available, 2.0, 'Wrong quantity available (%s found instead of 2.0)' % (self.productA.qty_available))
# Check quants and available quantity for product B
quants = self.StockQuantObj.search([('product_id', '=', self.productB.id), ('location_id', '=', self.stock_location)])
self.assertFalse(quants, 'No quant should found as outgoing shipment took everything out of stock.')
self.assertEqual(self.productB.qty_available, 0.0, 'Product B should have zero quantity available.')
# Check quants and available quantity for product C
quants = self.StockQuantObj.search([('product_id', '=', self.productC.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 2.0, 'Expecting 2.0 Unit, got %.4f Unit on location stock!' % (sum(total_qty)))
self.assertEqual(self.productC.qty_available, 2.0, 'Wrong quantity available (%s found instead of 2.0)' % (self.productC.qty_available))
# Check quants and available quantity for product D
quant = self.StockQuantObj.search([('product_id', '=', self.productD.id), ('location_id', '=', self.stock_location)], limit=1)
self.assertEqual(quant.qty, 1.0, 'Expecting 1.0 Unit , got %.4f Unit on location stock!' % (quant.qty))
self.assertEqual(self.productD.qty_available, 1.0, 'Wrong quantity available (%s found instead of 1.0)' % (self.productD.qty_available))
#-----------------------------------------------------------------------
# Back Order of Incoming shipment
#-----------------------------------------------------------------------
lot3_productC = LotObj.create({'name': 'Lot 3', 'product_id': self.productC.id})
lot4_productC = LotObj.create({'name': 'Lot 4', 'product_id': self.productC.id})
lot5_productC = LotObj.create({'name': 'Lot 5', 'product_id': self.productC.id})
lot6_productC = LotObj.create({'name': 'Lot 6', 'product_id': self.productC.id})
lot1_productD = LotObj.create({'name': 'Lot 1', 'product_id': self.productD.id})
lot2_productD = LotObj.create({'name': 'Lot 2', 'product_id': self.productD.id})
# Confirm back order of incoming shipment.
back_order_in.action_confirm()
self.assertEqual(back_order_in.state, 'assigned', 'Wrong state of incoming shipment back order.')
for move in back_order_in.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
# ----------------------------------------------------------------------
# Replace pack operation (Back order of Incoming shipment)
# ----------------------------------------------------------------------
back_order_in.do_prepare_partial()
packD = self.StockPackObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', back_order_in.id)])
self.assertEqual(len(packD), 1, 'Wrong number of pack operation.')
packD.write({'product_qty': 4, 'lot_id': lot1_productD.id})
self.StockPackObj.create({
'product_id': self.productD.id,
'product_qty': 4,
'product_uom_id': self.productD.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': back_order_in.id,
'lot_id': lot2_productD.id})
self.StockPackObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', back_order_in.id)], limit=1).write({'product_qty': 1, 'lot_id': lot3_productC.id})
self.StockPackObj.create({
'product_id': self.productC.id,
'product_qty': 1,
'product_uom_id': self.productC.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': back_order_in.id,
'lot_id': lot4_productC.id})
self.StockPackObj.create({
'product_id': self.productC.id,
'product_qty': 2,
'product_uom_id': self.productC.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': back_order_in.id,
'lot_id': lot5_productC.id})
self.StockPackObj.create({
'product_id': self.productC.id,
'product_qty': 2,
'product_uom_id': self.productC.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': back_order_in.id,
'lot_id': lot6_productC.id})
self.StockPackObj.create({
'product_id': self.productA.id,
'product_qty': 10,
'product_uom_id': self.productA.uom_id.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': back_order_in.id})
back_order_in.do_transfer()
# ----------------------------------------------------------------------
# Check state, quantity and total moves (Back order of Incoming shipment).
# ----------------------------------------------------------------------
# Check total no of move lines.
self.assertEqual(len(back_order_in.move_lines), 6, 'Wrong number of move lines')
# Check incoming shipment state must be 'Done'.
self.assertEqual(back_order_in.state, 'done', 'Wrong state of picking.')
# Check incoming shipment move lines state must be 'Done'.
for move in back_order_in.move_lines:
self.assertEqual(move.state, 'done', 'Wrong state of move lines.')
# Check product A done quantity must be 10
movesA = self.MoveObj.search([('product_id', '=', self.productA.id), ('picking_id', '=', back_order_in.id)])
self.assertEqual(movesA.product_uom_qty, 10, "Wrong move quantity of product A (%s found instead of 10)" % (movesA.product_uom_qty))
# Check product C done quantity must be 3.0, 1.0, 2.0
movesC = self.MoveObj.search([('product_id', '=', self.productC.id), ('picking_id', '=', back_order_in.id)])
c_done_qty = [move.product_uom_qty for move in movesC]
self.assertEqual(set(c_done_qty), set([3.0, 1.0, 2.0]), 'Wrong quantity of moves product C.')
# Check product D done quantity must be 5.0 and 3.0
movesD = self.MoveObj.search([('product_id', '=', self.productD.id), ('picking_id', '=', back_order_in.id)])
d_done_qty = [move.product_uom_qty for move in movesD]
self.assertEqual(set(d_done_qty), set([3.0, 5.0]), 'Wrong quantity of moves product D.')
# Check no back order is created.
self.assertFalse(self.PickingObj.search([('backorder_id', '=', back_order_in.id)]), "Should not create any back order.")
#-----------------------------------------------------------------------
# Check stock location quant quantity and quantity available
# of product A, B, C, D
#-----------------------------------------------------------------------
# Check quants and available quantity for product A.
quants = self.StockQuantObj.search([('product_id', '=', self.productA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 12.0, 'Wrong total stock location quantity (%s found instead of 12)' % (sum(total_qty)))
self.assertEqual(self.productA.qty_available, 12.0, 'Wrong quantity available (%s found instead of 12)' % (self.productA.qty_available))
# Check quants and available quantity for product B.
quants = self.StockQuantObj.search([('product_id', '=', self.productB.id), ('location_id', '=', self.stock_location)])
self.assertFalse(quants, 'No quant should found as outgoing shipment took everything out of stock')
self.assertEqual(self.productB.qty_available, 0.0, 'Total quantity in stock should be 0 as the backorder took everything out of stock')
# Check quants and available quantity for product C.
quants = self.StockQuantObj.search([('product_id', '=', self.productC.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 8.0, 'Wrong total stock location quantity (%s found instead of 8)' % (sum(total_qty)))
self.assertEqual(self.productC.qty_available, 8.0, 'Wrong quantity available (%s found instead of 8)' % (self.productC.qty_available))
# Check quants and available quantity for product D.
quants = self.StockQuantObj.search([('product_id', '=', self.productD.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 9.0, 'Wrong total stock location quantity (%s found instead of 9)' % (sum(total_qty)))
self.assertEqual(self.productD.qty_available, 9.0, 'Wrong quantity available (%s found instead of 9)' % (self.productD.qty_available))
#-----------------------------------------------------------------------
# Back order of Outgoing shipment
# ----------------------------------------------------------------------
back_order_out.do_prepare_partial()
back_order_out.do_transfer()
# Check stock location quants and available quantity for product A.
quants = self.StockQuantObj.search([('product_id', '=', self.productA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertGreaterEqual(float_round(sum(total_qty), precision_rounding=0.0001), 1, 'Total stock location quantity for product A should not be nagative.')
def test_10_pickings_transfer_with_different_uom(self):
""" Picking transfer with diffrent unit of meassure. """
# ----------------------------------------------------------------------
# Create incoming shipment of products DozA, SDozA, SDozARound, kgB, gB
# ----------------------------------------------------------------------
# DozA ( 10 Dozen ) , SDozA ( 10.5 SuperDozen )
# SDozARound ( 10.5 10.5 SuperDozenRound ) , kgB ( 0.020 kg )
# gB ( 525.3 g )
# ----------------------------------------------------------------------
picking_in_A = self.PickingObj.create({
'partner_id': self.partner_delta_id,
'picking_type_id': self.picking_type_in})
self.MoveObj.create({
'name': self.DozA.name,
'product_id': self.DozA.id,
'product_uom_qty': 10,
'product_uom': self.DozA.uom_id.id,
'picking_id': picking_in_A.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.SDozA.name,
'product_id': self.SDozA.id,
'product_uom_qty': 10.5,
'product_uom': self.SDozA.uom_id.id,
'picking_id': picking_in_A.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.SDozARound.name,
'product_id': self.SDozARound.id,
'product_uom_qty': 10.5,
'product_uom': self.SDozARound.uom_id.id,
'picking_id': picking_in_A.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.kgB.name,
'product_id': self.kgB.id,
'product_uom_qty': 0.020,
'product_uom': self.kgB.uom_id.id,
'picking_id': picking_in_A.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.gB.name,
'product_id': self.gB.id,
'product_uom_qty': 525.3,
'product_uom': self.gB.uom_id.id,
'picking_id': picking_in_A.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
# Check incoming shipment move lines state.
for move in picking_in_A.move_lines:
self.assertEqual(move.state, 'draft', 'Move state must be draft.')
# Confirm incoming shipment.
picking_in_A.action_confirm()
# Check incoming shipment move lines state.
for move in picking_in_A.move_lines:
self.assertEqual(move.state, 'assigned', 'Move state must be draft.')
picking_in_A.do_prepare_partial()
# ----------------------------------------------------
# Check pack operation quantity of incoming shipments.
# ----------------------------------------------------
PackSdozAround = self.StockPackObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_A.id)], limit=1)
self.assertEqual(PackSdozAround.product_qty, 11, 'Wrong quantity in pack operation (%s found instead of 11)' % (PackSdozAround.product_qty))
picking_in_A.do_transfer()
#-----------------------------------------------------------------------
# Check stock location quant quantity and quantity available
#-----------------------------------------------------------------------
# Check quants and available quantity for product DozA
quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 10, 'Expecting 10 Dozen , got %.4f Dozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.DozA.qty_available, 10, 'Wrong quantity available (%s found instead of 10)' % (self.DozA.qty_available))
# Check quants and available quantity for product SDozA
quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 10.5, 'Expecting 10.5 SDozen , got %.4f SDozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozA.qty_available, 10.5, 'Wrong quantity available (%s found instead of 10.5)' % (self.SDozA.qty_available))
# Check quants and available quantity for product SDozARound
quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 11, 'Expecting 11 SDozenRound , got %.4f SDozenRound on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozARound.qty_available, 11, 'Wrong quantity available (%s found instead of 11)' % (self.SDozARound.qty_available))
# Check quants and available quantity for product gB
quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 525.3, 'Expecting 525.3 gram , got %.4f gram on location stock!' % (sum(total_qty)))
self.assertEqual(self.gB.qty_available, 525.3, 'Wrong quantity available (%s found instead of 525.3' % (self.gB.qty_available))
# Check quants and available quantity for product kgB
quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 0.020, 'Expecting 0.020 kg , got %.4f kg on location stock!' % (sum(total_qty)))
self.assertEqual(self.kgB.qty_available, 0.020, 'Wrong quantity available (%s found instead of 0.020)' % (self.kgB.qty_available))
# ----------------------------------------------------------------------
# Create Incoming Shipment B
# ----------------------------------------------------------------------
picking_in_B = self.PickingObj.create({
'partner_id': self.partner_delta_id,
'picking_type_id': self.picking_type_in})
self.MoveObj.create({
'name': self.DozA.name,
'product_id': self.DozA.id,
'product_uom_qty': 120,
'product_uom': self.uom_unit.id,
'picking_id': picking_in_B.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.SDozA.name,
'product_id': self.SDozA.id,
'product_uom_qty': 1512,
'product_uom': self.uom_unit.id,
'picking_id': picking_in_B.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.SDozARound.name,
'product_id': self.SDozARound.id,
'product_uom_qty': 1584,
'product_uom': self.uom_unit.id,
'picking_id': picking_in_B.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.kgB.name,
'product_id': self.kgB.id,
'product_uom_qty': 20.0,
'product_uom': self.uom_gm.id,
'picking_id': picking_in_B.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
self.MoveObj.create({
'name': self.gB.name,
'product_id': self.gB.id,
'product_uom_qty': 0.525,
'product_uom': self.uom_kg.id,
'picking_id': picking_in_B.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
# Check incoming shipment move lines state.
for move in picking_in_B.move_lines:
self.assertEqual(move.state, 'draft', 'Wrong state of move line.')
# Confirm incoming shipment.
picking_in_B.action_confirm()
# Check incoming shipment move lines state.
for move in picking_in_B.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
picking_in_B.do_prepare_partial()
# ----------------------------------------------------------------------
# Check product quantity and unit of measure of pack operaation.
# ----------------------------------------------------------------------
# Check pack operation quantity and unit of measure for product DozA.
PackdozA = self.StockPackObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(PackdozA.product_qty, 120, 'Wrong quantity in pack operation (%s found instead of 120)' % (PackdozA.product_qty))
self.assertEqual(PackdozA.product_uom_id.id, self.uom_unit.id, 'Wrong uom in pack operation for product DozA.')
# Check pack operation quantity and unit of measure for product SDozA.
PackSdozA = self.StockPackObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(PackSdozA.product_qty, 1512, 'Wrong quantity in pack operation (%s found instead of 1512)' % (PackSdozA.product_qty))
self.assertEqual(PackSdozA.product_uom_id.id, self.uom_unit.id, 'Wrong uom in pack operation for product SDozA.')
# Check pack operation quantity and unit of measure for product SDozARound.
PackSdozAround = self.StockPackObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(PackSdozAround.product_qty, 1584, 'Wrong quantity in pack operation (%s found instead of 1584)' % (PackSdozAround.product_qty))
self.assertEqual(PackSdozAround.product_uom_id.id, self.uom_unit.id, 'Wrong uom in pack operation for product SDozARound.')
# Check pack operation quantity and unit of measure for product gB.
packgB = self.StockPackObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(packgB.product_qty, 525, 'Wrong quantity in pack operation (%s found instead of 525)' % (packgB.product_qty))
self.assertEqual(packgB.product_uom_id.id, self.uom_gm.id, 'Wrong uom in pack operation for product gB.')
# Check pack operation quantity and unit of measure for product kgB.
packkgB = self.StockPackObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(packkgB.product_qty, 20.0, 'Wrong quantity in pack operation (%s found instead of 20)' % (packkgB.product_qty))
self.assertEqual(packkgB.product_uom_id.id, self.uom_gm.id, 'Wrong uom in pack operation for product kgB')
# ----------------------------------------------------------------------
# Replace pack operation of incoming shipment.
# ----------------------------------------------------------------------
self.StockPackObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)]).write({
'product_qty': 0.020, 'product_uom_id': self.uom_kg.id})
self.StockPackObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id)]).write({
'product_qty': 525.3, 'product_uom_id': self.uom_gm.id})
self.StockPackObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)]).write({
'product_qty': 4, 'product_uom_id': self.uom_dozen.id})
self.StockPackObj.create({
'product_id': self.DozA.id,
'product_qty': 48,
'product_uom_id': self.uom_unit.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'picking_id': picking_in_B.id})
# Transfer product.
# -----------------
picking_in_B.do_transfer()
#-----------------------------------------------------------------------
# Check incoming shipment
#-----------------------------------------------------------------------
# Check incoming shipment state.
self.assertEqual(picking_in_B.state, 'done', 'Incoming shipment state should be done.')
# Check incoming shipment move lines state.
for move in picking_in_B.move_lines:
self.assertEqual(move.state, 'done', 'Wrong state of move line.')
# Check total done move lines for incoming shipment.
self.assertEqual(len(picking_in_B.move_lines), 6, 'Wrong number of move lines')
# Check product DozA done quantity.
moves_DozA = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(moves_DozA.product_uom_qty, 96, 'Wrong move quantity (%s found instead of 96)' % (moves_DozA.product_uom_qty))
self.assertEqual(moves_DozA.product_uom.id, self.uom_unit.id, 'Wrong uom in move for product DozA.')
# Check product SDozA done quantity.
moves_SDozA = self.MoveObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(moves_SDozA.product_uom_qty, 1512, 'Wrong move quantity (%s found instead of 1512)' % (moves_SDozA.product_uom_qty))
self.assertEqual(moves_SDozA.product_uom.id, self.uom_unit.id, 'Wrong uom in move for product SDozA.')
# Check product SDozARound done quantity.
moves_SDozARound = self.MoveObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(moves_SDozARound.product_uom_qty, 1584, 'Wrong move quantity (%s found instead of 1584)' % (moves_SDozARound.product_uom_qty))
self.assertEqual(moves_SDozARound.product_uom.id, self.uom_unit.id, 'Wrong uom in move for product SDozARound.')
# Check product kgB done quantity.
moves_kgB = self.MoveObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
self.assertEqual(moves_kgB.product_uom_qty, 20, 'Wrong quantity in move (%s found instead of 20)' % (moves_kgB.product_uom_qty))
self.assertEqual(moves_kgB.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product kgB.')
# Check two moves created for product gB with quantity (0.525 kg and 0.3 g)
moves_gB_kg = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id), ('product_uom', '=', self.uom_kg.id)], limit=1)
self.assertEqual(moves_gB_kg.product_uom_qty, 0.525, 'Wrong move quantity (%s found instead of 0.525)' % (moves_gB_kg.product_uom_qty))
self.assertEqual(moves_gB_kg.product_uom.id, self.uom_kg.id, 'Wrong uom in move for product gB.')
moves_gB_g = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id), ('product_uom', '=', self.uom_gm.id)], limit=1)
self.assertEqual(moves_gB_g.product_uom_qty, 0.3, 'Wrong move quantity (%s found instead of 0.3)' % (moves_gB_g.product_uom_qty))
self.assertEqual(moves_gB_g.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product gB.')
# ----------------------------------------------------------------------
# Check Back order of Incoming shipment.
# ----------------------------------------------------------------------
# Check back order created or not.
bo_in_B = self.PickingObj.search([('backorder_id', '=', picking_in_B.id)])
self.assertEqual(len(bo_in_B), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(bo_in_B.move_lines), 1, 'Wrong number of move lines')
# Check back order created with correct quantity and uom or not.
moves_DozA = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', bo_in_B.id)], limit=1)
self.assertEqual(moves_DozA.product_uom_qty, 24.0, 'Wrong move quantity (%s found instead of 0.525)' % (moves_DozA.product_uom_qty))
self.assertEqual(moves_DozA.product_uom.id, self.uom_unit.id, 'Wrong uom in move for product DozA.')
# ----------------------------------------------------------------------
# Check product stock location quantity and quantity available.
# ----------------------------------------------------------------------
# Check quants and available quantity for product DozA
quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 18, 'Expecting 18 Dozen , got %.4f Dozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.DozA.qty_available, 18, 'Wrong quantity available (%s found instead of 18)' % (self.DozA.qty_available))
# Check quants and available quantity for product SDozA
quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 21, 'Expecting 18 SDozen , got %.4f SDozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozA.qty_available, 21, 'Wrong quantity available (%s found instead of 21)' % (self.SDozA.qty_available))
# Check quants and available quantity for product SDozARound
quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 22, 'Expecting 22 SDozenRound , got %.4f SDozenRound on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozARound.qty_available, 22, 'Wrong quantity available (%s found instead of 22)' % (self.SDozARound.qty_available))
# Check quants and available quantity for product gB.
quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 1050.6, 'Expecting 1050.6 Gram , got %.4f Gram on location stock!' % (sum(total_qty)))
self.assertEqual(self.gB.qty_available, 1050.6, 'Wrong quantity available (%s found instead of 1050.6)' % (self.gB.qty_available))
# Check quants and available quantity for product kgB.
quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 0.040, 'Expecting 0.040 kg , got %.4f kg on location stock!' % (sum(total_qty)))
self.assertEqual(self.kgB.qty_available, 0.040, 'Wrong quantity available (%s found instead of 0.040)' % (self.kgB.qty_available))
# ----------------------------------------------------------------------
# Create outgoing shipment.
# ----------------------------------------------------------------------
before_out_quantity = self.kgB.qty_available
picking_out = self.PickingObj.create({
'partner_id': self.partner_agrolite_id,
'picking_type_id': self.picking_type_out})
self.MoveObj.create({
'name': self.kgB.name,
'product_id': self.kgB.id,
'product_uom_qty': 0.966,
'product_uom': self.uom_gm.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.kgB.name,
'product_id': self.kgB.id,
'product_uom_qty': 0.034,
'product_uom': self.uom_gm.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
picking_out.action_confirm()
picking_out.action_assign()
picking_out.do_prepare_partial()
picking_out.do_transfer()
# Check quantity difference after stock transfer.
quantity_diff = before_out_quantity - self.kgB.qty_available
self.assertEqual(float_round(quantity_diff, precision_rounding=0.0001), 0.001, 'Wrong quantity diffrence.')
self.assertEqual(self.kgB.qty_available, 0.039, 'Wrong quantity available (%s found instead of 0.039)' % (self.kgB.qty_available))
# ======================================================================
# Outgoing shipments.
# ======================================================================
# Create Outgoing shipment with ...
# product DozA ( 54 Unit ) , SDozA ( 288 Unit )
# product SDozRound ( 360 unit ) , product gB ( 0.503 kg )
# product kgB ( 19 g )
# ======================================================================
picking_out = self.PickingObj.create({
'partner_id': self.partner_agrolite_id,
'picking_type_id': self.picking_type_out})
self.MoveObj.create({
'name': self.DozA.name,
'product_id': self.DozA.id,
'product_uom_qty': 54,
'product_uom': self.uom_unit.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.SDozA.name,
'product_id': self.SDozA.id,
'product_uom_qty': 288,
'product_uom': self.uom_unit.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.SDozARound.name,
'product_id': self.SDozARound.id,
'product_uom_qty': 360,
'product_uom': self.uom_unit.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.gB.name,
'product_id': self.gB.id,
'product_uom_qty': 0.503,
'product_uom': self.uom_kg.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
self.MoveObj.create({
'name': self.kgB.name,
'product_id': self.kgB.id,
'product_uom_qty': 20,
'product_uom': self.uom_gm.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
# Confirm outgoing shipment.
picking_out.action_confirm()
for move in picking_out.move_lines:
self.assertEqual(move.state, 'confirmed', 'Wrong state of move line.')
# Assing product to outgoing shipments
picking_out.action_assign()
for move in picking_out.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
# Check product A available quantity
DozA_qty = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(DozA_qty, 4.5, 'Wrong move quantity availability (%s found instead of 4.5)' % (DozA_qty))
# Check product B available quantity
SDozA_qty = self.MoveObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(SDozA_qty, 2, 'Wrong move quantity availability (%s found instead of 2)' % (SDozA_qty))
# Check product C available quantity
SDozARound_qty = self.MoveObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(SDozARound_qty, 3, 'Wrong move quantity availability (%s found instead of 3)' % (SDozARound_qty))
# Check product D available quantity
gB_qty = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(gB_qty, 503, 'Wrong move quantity availability (%s found instead of 503)' % (gB_qty))
# Check product D available quantity
kgB_qty = self.MoveObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_out.id)], limit=1).availability
self.assertEqual(kgB_qty, 0.020, 'Wrong move quantity availability (%s found instead of 0.020)' % (kgB_qty))
picking_out.action_confirm()
picking_out.action_assign()
picking_out.do_prepare_partial()
picking_out.do_transfer()
# ----------------------------------------------------------------------
# Check product stock location quantity and quantity available.
# ----------------------------------------------------------------------
# Check quants and available quantity for product DozA
quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 13.5, 'Expecting 13.5 Dozen , got %.4f Dozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.DozA.qty_available, 13.5, 'Wrong quantity available (%s found instead of 13.5)' % (self.DozA.qty_available))
# Check quants and available quantity for product SDozA
quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 19, 'Expecting 19 SDozen , got %.4f SDozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozA.qty_available, 19, 'Wrong quantity available (%s found instead of 19)' % (self.SDozA.qty_available))
# Check quants and available quantity for product SDozARound
quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 19, 'Expecting 19 SDozRound , got %.4f SDozRound on location stock!' % (sum(total_qty)))
self.assertEqual(self.SDozARound.qty_available, 19, 'Wrong quantity available (%s found instead of 19)' % (self.SDozARound.qty_available))
# Check quants and available quantity for product gB.
quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(float_round(sum(total_qty), precision_rounding=0.0001), 547.6, 'Expecting 547.6 g , got %.4f g on location stock!' % (sum(total_qty)))
self.assertEqual(self.gB.qty_available, 547.6, 'Wrong quantity available (%s found instead of 547.6)' % (self.gB.qty_available))
# Check quants and available quantity for product kgB.
quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 0.019, 'Expecting 0.019 kg , got %.4f kg on location stock!' % (sum(total_qty)))
self.assertEqual(self.kgB.qty_available, 0.019, 'Wrong quantity available (%s found instead of 0.019)' % (self.kgB.qty_available))
# ----------------------------------------------------------------------
# Receipt back order of incoming shipment.
# ----------------------------------------------------------------------
bo_in_B.do_prepare_partial()
bo_in_B.do_transfer()
# Check quants and available quantity for product kgB.
quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 15.5, 'Expecting 15.5 Dozen , got %.4f Dozen on location stock!' % (sum(total_qty)))
self.assertEqual(self.DozA.qty_available, 15.5, 'Wrong quantity available (%s found instead of 15.5)' % (self.DozA.qty_available))
# -----------------------------------------
# Create product in kg and receive in ton.
# -----------------------------------------
productKG = self.ProductObj.create({'name': 'Product KG', 'uom_id': self.uom_kg.id, 'uom_po_id': self.uom_kg.id})
picking_in = self.PickingObj.create({
'partner_id': self.partner_delta_id,
'picking_type_id': self.picking_type_in})
self.MoveObj.create({
'name': productKG.name,
'product_id': productKG.id,
'product_uom_qty': 1.0,
'product_uom': self.uom_tone.id,
'picking_id': picking_in.id,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location})
# Check incoming shipment state.
self.assertEqual(picking_in.state, 'draft', 'Incoming shipment state should be draft.')
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'draft', 'Wrong state of move line.')
# Confirm incoming shipment.
picking_in.action_confirm()
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
picking_in.do_prepare_partial()
# Check pack operation quantity.
packKG = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_in.id)], limit=1)
self.assertEqual(packKG.product_qty, 1000, 'Wrong product quantity in pack operation (%s found instead of 1000)' % (packKG.product_qty))
self.assertEqual(packKG.product_uom_id.id, self.uom_kg.id, 'Wrong product uom in pack operation.')
# Transfer Incoming shipment.
picking_in.do_transfer()
#-----------------------------------------------------------------------
# Check incoming shipment after transfer.
#-----------------------------------------------------------------------
# Check incoming shipment state.
self.assertEqual(picking_in.state, 'done', 'Incoming shipment state should be done.')
# Check incoming shipment move lines state.
for move in picking_in.move_lines:
self.assertEqual(move.state, 'done', 'Wrong state of move lines.')
# Check total done move lines for incoming shipment.
self.assertEqual(len(picking_in.move_lines), 1, 'Wrong number of move lines')
# Check product DozA done quantity.
move = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_in.id)], limit=1)
self.assertEqual(move.product_uom_qty, 1, 'Wrong product quantity in done move.')
self.assertEqual(move.product_uom.id, self.uom_tone.id, 'Wrong unit of measure in done move.')
self.assertEqual(productKG.qty_available, 1000, 'Wrong quantity available of product (%s found instead of 1000)' % (productKG.qty_available))
picking_out = self.PickingObj.create({
'partner_id': self.partner_agrolite_id,
'picking_type_id': self.picking_type_out})
self.MoveObj.create({
'name': productKG.name,
'product_id': productKG.id,
'product_uom_qty': 2.5,
'product_uom': self.uom_gm.id,
'picking_id': picking_out.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location})
picking_out.action_confirm()
picking_out.action_assign()
picking_out.do_prepare_partial()
pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_out.id)], limit=1)
pack_opt.write({'product_qty': 0.5})
picking_out.do_transfer()
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
# Check total quantity stock location.
self.assertEqual(sum(total_qty), 999.9995, 'Expecting 999.9995 kg , got %.4f kg on location stock!' % (sum(total_qty)))
# Check Back order created or not.
#---------------------------------
bo_out_1 = self.PickingObj.search([('backorder_id', '=', picking_out.id)])
self.assertEqual(len(bo_out_1), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(bo_out_1.move_lines), 1, 'Wrong number of move lines')
moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_1.id)], limit=1)
# Check back order created with correct quantity and uom or not.
self.assertEqual(moves_KG.product_uom_qty, 2.0, 'Wrong move quantity (%s found instead of 2.0)' % (moves_KG.product_uom_qty))
self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product KG.')
bo_out_1.action_assign()
bo_out_1.do_prepare_partial()
pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_1.id)], limit=1)
pack_opt.write({'product_qty': 0.5})
bo_out_1.do_transfer()
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
# Check total quantity stock location.
self.assertEqual(sum(total_qty), 999.9990, 'Expecting 999.9990 kg , got %.4f kg on location stock!' % (sum(total_qty)))
# Check Back order created or not.
#---------------------------------
bo_out_2 = self.PickingObj.search([('backorder_id', '=', bo_out_1.id)])
self.assertEqual(len(bo_out_2), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(bo_out_2.move_lines), 1, 'Wrong number of move lines')
# Check back order created with correct move quantity and uom or not.
moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_2.id)], limit=1)
self.assertEqual(moves_KG.product_uom_qty, 1.5, 'Wrong move quantity (%s found instead of 1.5)' % (moves_KG.product_uom_qty))
self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product KG.')
bo_out_2.action_assign()
bo_out_2.do_prepare_partial()
pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_2.id)], limit=1)
pack_opt.write({'product_qty': 0.5})
bo_out_2.do_transfer()
# Check total quantity stock location of product KG.
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 999.9985, 'Expecting 999.9985 kg , got %.4f kg on location stock!' % (sum(total_qty)))
# Check Back order created or not.
#---------------------------------
bo_out_3 = self.PickingObj.search([('backorder_id', '=', bo_out_2.id)])
self.assertEqual(len(bo_out_3), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(bo_out_3.move_lines), 1, 'Wrong number of move lines')
# Check back order created with correct quantity and uom or not.
moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_3.id)], limit=1)
self.assertEqual(moves_KG.product_uom_qty, 1, 'Wrong move quantity (%s found instead of 1.0)' % (moves_KG.product_uom_qty))
self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product KG.')
bo_out_3.action_assign()
bo_out_3.do_prepare_partial()
pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_3.id)], limit=1)
pack_opt.write({'product_qty': 0.5})
bo_out_3.do_transfer()
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 999.9980, 'Expecting 999.9980 kg , got %.4f kg on location stock!' % (sum(total_qty)))
# Check Back order created or not.
#---------------------------------
bo_out_4 = self.PickingObj.search([('backorder_id', '=', bo_out_3.id)])
self.assertEqual(len(bo_out_4), 1, 'Back order should be created.')
# Check total move lines of back order.
self.assertEqual(len(bo_out_4.move_lines), 1, 'Wrong number of move lines')
# Check back order created with correct quantity and uom or not.
moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_4.id)], limit=1)
self.assertEqual(moves_KG.product_uom_qty, 0.5, 'Wrong move quantity (%s found instead of 0.5)' % (moves_KG.product_uom_qty))
self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong uom in move for product KG.')
bo_out_4.action_assign()
bo_out_4.do_prepare_partial()
pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_4.id)], limit=1)
pack_opt.write({'product_qty': 0.5})
bo_out_4.do_transfer()
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 999.9975, 'Expecting 999.9975 kg , got %.4f kg on location stock!' % (sum(total_qty)))
def test_20_create_inventory_with_different_uom(self):
"""Create inventory with different unit of measure."""
# ------------------------------------------------
# Test inventory with product A(Unit).
# ------------------------------------------------
inventory = self.InvObj.create({'name': 'Test',
'product_id': self.UnitA.id,
'filter': 'product'})
inventory.prepare_inventory()
self.assertFalse(inventory.line_ids, "Inventory line should not created.")
inventory_line = self.InvLineObj.create({
'inventory_id': inventory.id,
'product_id': self.UnitA.id,
'product_uom_id': self.uom_dozen.id,
'product_qty': 10,
'location_id': self.stock_location})
inventory.action_done()
# Check quantity available of product UnitA.
quants = self.StockQuantObj.search([('product_id', '=', self.UnitA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 120, 'Expecting 120 Units , got %.4f Units on location stock!' % (sum(total_qty)))
self.assertEqual(self.UnitA.qty_available, 120, 'Expecting 120 Units , got %.4f Units of quantity available!' % (self.UnitA.qty_available))
# Create Inventory again for product UnitA.
inventory = self.InvObj.create({'name': 'Test',
'product_id': self.UnitA.id,
'filter': 'product'})
inventory.prepare_inventory()
self.assertEqual(len(inventory.line_ids), 1, "One inventory line should be created.")
inventory_line = self.InvLineObj.search([('product_id', '=', self.UnitA.id), ('inventory_id', '=', inventory.id)], limit=1)
self.assertEqual(inventory_line.product_qty, 120, "Wrong product quantity in inventory line.")
# Modify the inventory line and set the quantity to 144 product on this new inventory.
inventory_line.write({'product_qty': 144})
inventory.action_done()
move = self.MoveObj.search([('product_id', '=', self.UnitA.id), ('inventory_id', '=', inventory.id)], limit=1)
self.assertEqual(move.product_uom_qty, 24, "Wrong move quantity of product UnitA.")
# Check quantity available of product UnitA.
quants = self.StockQuantObj.search([('product_id', '=', self.UnitA.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 144, 'Expecting 144 Units , got %.4f Units on location stock!' % (sum(total_qty)))
self.assertEqual(self.UnitA.qty_available, 144, 'Expecting 144 Units , got %.4f Units of quantity available!' % (self.UnitA.qty_available))
# ------------------------------------------------
# Test inventory with product KG.
# ------------------------------------------------
productKG = self.ProductObj.create({'name': 'Product KG', 'uom_id': self.uom_kg.id, 'uom_po_id': self.uom_kg.id})
inventory = self.InvObj.create({'name': 'Inventory Product KG',
'product_id': productKG.id,
'filter': 'product'})
inventory.prepare_inventory()
self.assertFalse(inventory.line_ids, "Inventory line should not created.")
inventory_line = self.InvLineObj.create({
'inventory_id': inventory.id,
'product_id': productKG.id,
'product_uom_id': self.uom_tone.id,
'product_qty': 5,
'location_id': self.stock_location})
inventory.action_done()
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 5000, 'Expecting 5000 kg , got %.4f kg on location stock!' % (sum(total_qty)))
self.assertEqual(productKG.qty_available, 5000, 'Expecting 5000 kg , got %.4f kg of quantity available!' % (productKG.qty_available))
# Create Inventory again.
inventory = self.InvObj.create({'name': 'Test',
'product_id': productKG.id,
'filter': 'product'})
inventory.prepare_inventory()
self.assertEqual(len(inventory.line_ids), 1, "One inventory line should be created.")
inventory_line = self.InvLineObj.search([('product_id', '=', productKG.id), ('inventory_id', '=', inventory.id)], limit=1)
self.assertEqual(inventory_line.product_qty, 5000, "Wrong product quantity in inventory line.")
# Modify the inventory line and set the quantity to 4000 product on this new inventory.
inventory_line.write({'product_qty': 4000})
inventory.action_done()
# Check inventory move quantity of product KG.
move = self.MoveObj.search([('product_id', '=', productKG.id), ('inventory_id', '=', inventory.id)], limit=1)
self.assertEqual(move.product_uom_qty, 1000, "Wrong move quantity of product KG.")
# Check quantity available of product KG.
quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
total_qty = [quant.qty for quant in quants]
self.assertEqual(sum(total_qty), 4000, 'Expecting 4000 kg , got %.4f on location stock!' % (sum(total_qty)))
self.assertEqual(productKG.qty_available, 4000, 'Expecting 4000 kg , got %.4f of quantity available!' % (productKG.qty_available))
#--------------------------------------------------------
# TEST PARTIAL INVENTORY WITH PACKS and LOTS
#---------------------------------------------------------
packproduct = self.ProductObj.create({'name': 'Pack Product', 'uom_id': self.uom_unit.id, 'uom_po_id': self.uom_unit.id})
lotproduct = self.ProductObj.create({'name': 'Lot Product', 'uom_id': self.uom_unit.id, 'uom_po_id': self.uom_unit.id})
inventory = self.InvObj.create({'name': 'Test Partial and Pack',
'filter': 'partial',
'location_id': self.stock_location})
inventory.prepare_inventory()
pack_obj = self.env['stock.quant.package']
lot_obj = self.env['stock.production.lot']
pack1 = pack_obj.create({'name': 'PACK00TEST1'})
pack2 = pack_obj.create({'name': 'PACK00TEST2'})
lot1 = lot_obj.create({'name': 'Lot001', 'product_id': lotproduct.id})
move = self.MoveObj.search([('product_id', '=', productKG.id), ('inventory_id', '=', inventory.id)], limit=1)
self.assertEqual(len(move), 0, "Partial filter should not create a lines upon prepare")
line_vals = []
line_vals += [{'location_id': self.stock_location, 'product_id': packproduct.id, 'product_qty': 10, 'product_uom_id': packproduct.uom_id.id}]
line_vals += [{'location_id': self.stock_location, 'product_id': packproduct.id, 'product_qty': 20, 'product_uom_id': packproduct.uom_id.id, 'package_id': pack1.id}]
line_vals += [{'location_id': self.stock_location, 'product_id': lotproduct.id, 'product_qty': 30, 'product_uom_id': lotproduct.uom_id.id, 'prod_lot_id': lot1.id}]
line_vals += [{'location_id': self.stock_location, 'product_id': lotproduct.id, 'product_qty': 25, 'product_uom_id': lotproduct.uom_id.id, 'prod_lot_id': False}]
inventory.write({'line_ids': [(0, 0, x) for x in line_vals]})
inventory.action_done()
self.assertEqual(packproduct.qty_available, 30, "Wrong qty available for packproduct")
self.assertEqual(lotproduct.qty_available, 55, "Wrong qty available for lotproduct")
quants = self.StockQuantObj.search([('product_id', '=', packproduct.id), ('location_id', '=', self.stock_location), ('package_id', '=', pack1.id)])
total_qty = sum([quant.qty for quant in quants])
self.assertEqual(total_qty, 20, 'Expecting 20 units on package 1 of packproduct, but we got %.4f on location stock!' % (total_qty))
#Create an inventory that will put the lots without lot to 0 and check that taking without pack will not take it from the pack
inventory2 = self.InvObj.create({'name': 'Test Partial Lot and Pack2',
'filter': 'partial',
'location_id': self.stock_location})
inventory2.prepare_inventory()
line_vals = []
line_vals += [{'location_id': self.stock_location, 'product_id': packproduct.id, 'product_qty': 20, 'product_uom_id': packproduct.uom_id.id}]
line_vals += [{'location_id': self.stock_location, 'product_id': lotproduct.id, 'product_qty': 0, 'product_uom_id': lotproduct.uom_id.id, 'prod_lot_id': False}]
line_vals += [{'location_id': self.stock_location, 'product_id': lotproduct.id, 'product_qty': 10, 'product_uom_id': lotproduct.uom_id.id, 'prod_lot_id': lot1.id}]
inventory2.write({'line_ids': [(0, 0, x) for x in line_vals]})
inventory2.action_done()
self.assertEqual(packproduct.qty_available, 40, "Wrong qty available for packproduct")
self.assertEqual(lotproduct.qty_available, 10, "Wrong qty available for lotproduct")
quants = self.StockQuantObj.search([('product_id', '=', lotproduct.id), ('location_id', '=', self.stock_location), ('lot_id', '=', lot1.id)])
total_qty = sum([quant.qty for quant in quants])
self.assertEqual(total_qty, 10, 'Expecting 0 units lot of lotproduct, but we got %.4f on location stock!' % (total_qty))
quants = self.StockQuantObj.search([('product_id', '=', lotproduct.id), ('location_id', '=', self.stock_location), ('lot_id', '=', False)])
total_qty = sum([quant.qty for quant in quants])
self.assertEqual(total_qty, 0, 'Expecting 0 units lot of lotproduct, but we got %.4f on location stock!' % (total_qty))
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
5166,
14,
10788,
14,
6088,
14,
2219,
14,
2330,
492,
1379,
17103,
7844,
199,
504,
5166,
14,
2537,
492,
333,
938,
63,
2921,
12,
2069,
63,
2363,
421,
199,
533,
1379,
17103,
5060,
8,
774,
17103,
7844,
304,
339,
768,
12423,
63,
2921,
360,
11267,
14,
10788,
14,
1095,
14,
723,
14,
723,
63,
1238,
297,
283,
11267,
14,
992,
358,
272,
347,
511,
63,
383,
63,
11463,
63,
981,
63,
460,
63,
9609,
63,
10577,
8,
277,
304,
267,
408,
10082,
10952,
3439,
641,
12467,
436,
21507,
15924,
434,
14,
408,
267,
491,
357,
5665,
275,
291,
14,
1813,
459,
6088,
14,
10777,
14,
1653,
418,
267,
327,
20359,
267,
327,
2790,
12467,
15924,
434,
402,
3336,
437,
12,
699,
12,
445,
12,
577,
267,
327,
20359,
267,
327,
257,
12705,
437,
334,
413,
12008,
776,
2360,
12705,
445,
334,
1616,
12008,
776,
267,
327,
257,
12705,
699,
334,
413,
12008,
776,
2360,
12705,
577,
334,
1616,
12008,
776,
267,
327,
257,
12705,
577,
334,
959,
12008,
776,
267,
327,
20359,
398,
12433,
63,
262,
275,
291,
14,
8587,
316,
5665,
14,
981,
2561,
288,
283,
3899,
63,
344,
356,
291,
14,
3899,
63,
3136,
63,
344,
12,
288,
283,
11463,
63,
466,
63,
344,
356,
291,
14,
11463,
63,
466,
63,
262,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
33,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
33,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
413,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
33,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
34,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
34,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
413,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
34,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
35,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
35,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
1616,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
35,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
36,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
36,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
1616,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
36,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
36,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
36,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
959,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
36,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
398,
327,
2670,
12467,
15924,
434,
4057,
2385,
1174,
14,
267,
367,
4057,
315,
12433,
63,
262,
14,
1185,
63,
1278,
26,
288,
291,
14,
629,
8,
1185,
14,
929,
12,
283,
7185,
297,
283,
14858,
1174,
402,
4057,
1004,
2659,
267,
327,
32112,
12467,
15924,
434,
14,
267,
12433,
63,
262,
14,
1287,
63,
9548,
342,
267,
327,
2670,
12467,
15924,
434,
4057,
2385,
1174,
14,
267,
367,
4057,
315,
12433,
63,
262,
14,
1185,
63,
1278,
26,
288,
291,
14,
629,
8,
1185,
14,
929,
12,
283,
12941,
297,
283,
14858,
1174,
402,
4057,
1004,
2659,
398,
327,
20359,
267,
327,
14402,
1706,
3439,
402,
12467,
15924,
1470,
14,
267,
327,
20359,
398,
12433,
63,
262,
14,
1117,
63,
6726,
63,
6672,
342,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
33,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
841,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
34,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
35,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
36,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
13918,
18,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
5166,
14,
10788,
14,
6088,
14,
2219,
14,
2330,
492,
1379,
17103,
7844,
199,
504,
5166,
14,
2537,
492,
333,
938,
63,
2921,
12,
2069,
63,
2363,
421,
199,
533,
1379,
17103,
5060,
8,
774,
17103,
7844,
304,
339,
768,
12423,
63,
2921,
360,
11267,
14,
10788,
14,
1095,
14,
723,
14,
723,
63,
1238,
297,
283,
11267,
14,
992,
358,
272,
347,
511,
63,
383,
63,
11463,
63,
981,
63,
460,
63,
9609,
63,
10577,
8,
277,
304,
267,
408,
10082,
10952,
3439,
641,
12467,
436,
21507,
15924,
434,
14,
408,
267,
491,
357,
5665,
275,
291,
14,
1813,
459,
6088,
14,
10777,
14,
1653,
418,
267,
327,
20359,
267,
327,
2790,
12467,
15924,
434,
402,
3336,
437,
12,
699,
12,
445,
12,
577,
267,
327,
20359,
267,
327,
257,
12705,
437,
334,
413,
12008,
776,
2360,
12705,
445,
334,
1616,
12008,
776,
267,
327,
257,
12705,
699,
334,
413,
12008,
776,
2360,
12705,
577,
334,
1616,
12008,
776,
267,
327,
257,
12705,
577,
334,
959,
12008,
776,
267,
327,
20359,
398,
12433,
63,
262,
275,
291,
14,
8587,
316,
5665,
14,
981,
2561,
288,
283,
3899,
63,
344,
356,
291,
14,
3899,
63,
3136,
63,
344,
12,
288,
283,
11463,
63,
466,
63,
344,
356,
291,
14,
11463,
63,
466,
63,
262,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
33,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
33,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
413,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
33,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
34,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
34,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
413,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
34,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
35,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
35,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
1616,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
35,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
36,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
36,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
1616,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
36,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
267,
291,
14,
10370,
5665,
14,
981,
2561,
288,
283,
354,
356,
291,
14,
2558,
36,
14,
354,
12,
288,
283,
2558,
63,
344,
356,
291,
14,
2558,
36,
14,
344,
12,
288,
283,
2558,
63,
7519,
63,
5643,
356,
959,
12,
288,
283,
2558,
63,
7519,
356,
291,
14,
2558,
36,
14,
7519,
63,
344,
14,
344,
12,
288,
283,
11463,
63,
344,
356,
12433,
63,
262,
14,
344,
12,
288,
283,
1985,
63,
344,
356,
291,
14,
17294,
63,
1985,
12,
288,
283,
1985,
63,
2614,
63,
344,
356,
291,
14,
6088,
63,
1985,
1552,
398,
327,
2670,
12467,
15924,
434,
4057,
2385,
1174,
14,
267,
367,
4057,
315,
12433,
63,
262,
14,
1185,
63,
1278,
26,
288,
291,
14,
629,
8,
1185,
14,
929,
12,
283,
7185,
297,
283,
14858,
1174,
402,
4057,
1004,
2659,
267,
327,
32112,
12467,
15924,
434,
14,
267,
12433,
63,
262,
14,
1287,
63,
9548,
342,
267,
327,
2670,
12467,
15924,
434,
4057,
2385,
1174,
14,
267,
367,
4057,
315,
12433,
63,
262,
14,
1185,
63,
1278,
26,
288,
291,
14,
629,
8,
1185,
14,
929,
12,
283,
12941,
297,
283,
14858,
1174,
402,
4057,
1004,
2659,
398,
327,
20359,
267,
327,
14402,
1706,
3439,
402,
12467,
15924,
1470,
14,
267,
327,
20359,
398,
12433,
63,
262,
14,
1117,
63,
6726,
63,
6672,
342,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
33,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
841,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
34,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
35,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
291,
14,
17103,
2305,
5665,
14,
1733,
8318,
2558,
63,
344,
297,
6291,
291,
14,
2558,
36,
14,
344,
395,
661,
11463,
63,
344,
297,
6291,
12433,
63,
262,
14,
344,
3948,
14,
952,
2561,
288,
283,
2558,
63,
5643,
356,
959,
14,
16,
1552,
267,
13918,
18,
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,
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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
] |
fpy171/django
|
tests/template_tests/test_smartif.py
|
580
|
2178
|
import unittest
from django.template.smartif import IfParser
class SmartIfTests(unittest.TestCase):
def assertCalcEqual(self, expected, tokens):
self.assertEqual(expected, IfParser(tokens).parse().eval({}))
# We only test things here that are difficult to test elsewhere
# Many other tests are found in the main tests for builtin template tags
# Test parsing via the printed parse tree
def test_not(self):
var = IfParser(["not", False]).parse()
self.assertEqual("(not (literal False))", repr(var))
self.assertTrue(var.eval({}))
self.assertFalse(IfParser(["not", True]).parse().eval({}))
def test_or(self):
var = IfParser([True, "or", False]).parse()
self.assertEqual("(or (literal True) (literal False))", repr(var))
self.assertTrue(var.eval({}))
def test_in(self):
list_ = [1, 2, 3]
self.assertCalcEqual(True, [1, 'in', list_])
self.assertCalcEqual(False, [1, 'in', None])
self.assertCalcEqual(False, [None, 'in', list_])
def test_not_in(self):
list_ = [1, 2, 3]
self.assertCalcEqual(False, [1, 'not', 'in', list_])
self.assertCalcEqual(True, [4, 'not', 'in', list_])
self.assertCalcEqual(False, [1, 'not', 'in', None])
self.assertCalcEqual(True, [None, 'not', 'in', list_])
def test_precedence(self):
# (False and False) or True == True <- we want this one, like Python
# False and (False or True) == False
self.assertCalcEqual(True, [False, 'and', False, 'or', True])
# True or (False and False) == True <- we want this one, like Python
# (True or False) and False == False
self.assertCalcEqual(True, [True, 'or', False, 'and', False])
# (1 or 1) == 2 -> False
# 1 or (1 == 2) -> True <- we want this one
self.assertCalcEqual(True, [1, 'or', 1, '==', 2])
self.assertCalcEqual(True, [True, '==', True, 'or', True, '==', False])
self.assertEqual("(or (and (== (literal 1) (literal 2)) (literal 3)) (literal 4))",
repr(IfParser([1, '==', 2, 'and', 3, 'or', 4]).parse()))
|
bsd-3-clause
|
[
646,
2882,
199,
199,
504,
1639,
14,
1160,
14,
24193,
9142,
492,
982,
2842,
421,
199,
533,
26017,
3917,
2925,
8,
2796,
14,
1746,
304,
339,
347,
702,
19511,
591,
8,
277,
12,
1420,
12,
4645,
304,
267,
291,
14,
629,
8,
2062,
12,
982,
2842,
8,
4504,
680,
1122,
1252,
2579,
24692,
430,
339,
327,
2136,
1454,
511,
7645,
2348,
626,
787,
29870,
370,
511,
25320,
272,
327,
15517,
1163,
2295,
787,
1911,
315,
314,
2446,
2295,
367,
6762,
1978,
3762,
272,
327,
1379,
6057,
4799,
314,
12487,
2198,
3123,
272,
347,
511,
63,
1397,
8,
277,
304,
267,
2729,
275,
982,
2842,
5234,
1397,
401,
756,
6575,
1122,
342,
267,
291,
14,
629,
18353,
1397,
334,
8939,
756,
430,
401,
4700,
8,
1391,
430,
267,
291,
14,
1815,
8,
1391,
14,
2579,
24692,
430,
398,
291,
14,
3334,
8,
3917,
2842,
5234,
1397,
401,
715,
6575,
1122,
1252,
2579,
24692,
430,
339,
347,
511,
63,
269,
8,
277,
304,
267,
2729,
275,
982,
2842,
779,
549,
12,
298,
269,
401,
756,
6575,
1122,
342,
267,
291,
14,
629,
18353,
269,
334,
8939,
715,
9,
334,
8939,
756,
430,
401,
4700,
8,
1391,
430,
267,
291,
14,
1815,
8,
1391,
14,
2579,
24692,
430,
339,
347,
511,
63,
262,
8,
277,
304,
267,
769,
63,
275,
359,
17,
12,
499,
12,
650,
61,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
17,
12,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
262,
297,
488,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
403,
12,
283,
262,
297,
769,
63,
566,
339,
347,
511,
63,
1397,
63,
262,
8,
277,
304,
267,
769,
63,
275,
359,
17,
12,
499,
12,
650,
61,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
20,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
1397,
297,
283,
262,
297,
488,
566,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
403,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
339,
347,
511,
63,
19571,
8,
277,
304,
267,
327,
334,
797,
436,
756,
9,
503,
715,
508,
715,
257,
25549,
781,
2934,
642,
1373,
12,
2839,
2018,
267,
327,
756,
436,
334,
797,
503,
715,
9,
508,
756,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
797,
12,
283,
460,
297,
756,
12,
283,
269,
297,
715,
566,
398,
327,
715,
503,
334,
797,
436,
756,
9,
508,
715,
257,
25549,
781,
2934,
642,
1373,
12,
2839,
2018,
267,
327,
334,
549,
503,
756,
9,
436,
756,
508,
756,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
549,
12,
283,
269,
297,
756,
12,
283,
460,
297,
756,
566,
398,
327,
334,
17,
503,
413,
9,
508,
499,
221,
1035,
756,
267,
327,
413,
503,
334,
17,
508,
499,
9,
221,
1035,
715,
257,
25549,
781,
2934,
642,
1373,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
17,
12,
283,
269,
297,
413,
12,
283,
389,
297,
499,
566,
398,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
549,
12,
283,
389,
297,
715,
12,
283,
269,
297,
715,
12,
283,
389,
297,
756,
566,
398,
291,
14,
629,
18353,
269,
334,
460,
334,
389,
334,
8939,
413,
9,
334,
8939,
499,
430,
334,
8939,
650,
430,
334,
8939,
841,
430,
401,
586,
4700,
8,
3917,
2842,
779,
17,
12,
283,
389,
297,
499,
12,
283,
460,
297,
650,
12,
283,
269,
297,
841,
6575,
1122,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
504,
1639,
14,
1160,
14,
24193,
9142,
492,
982,
2842,
421,
199,
533,
26017,
3917,
2925,
8,
2796,
14,
1746,
304,
339,
347,
702,
19511,
591,
8,
277,
12,
1420,
12,
4645,
304,
267,
291,
14,
629,
8,
2062,
12,
982,
2842,
8,
4504,
680,
1122,
1252,
2579,
24692,
430,
339,
327,
2136,
1454,
511,
7645,
2348,
626,
787,
29870,
370,
511,
25320,
272,
327,
15517,
1163,
2295,
787,
1911,
315,
314,
2446,
2295,
367,
6762,
1978,
3762,
272,
327,
1379,
6057,
4799,
314,
12487,
2198,
3123,
272,
347,
511,
63,
1397,
8,
277,
304,
267,
2729,
275,
982,
2842,
5234,
1397,
401,
756,
6575,
1122,
342,
267,
291,
14,
629,
18353,
1397,
334,
8939,
756,
430,
401,
4700,
8,
1391,
430,
267,
291,
14,
1815,
8,
1391,
14,
2579,
24692,
430,
398,
291,
14,
3334,
8,
3917,
2842,
5234,
1397,
401,
715,
6575,
1122,
1252,
2579,
24692,
430,
339,
347,
511,
63,
269,
8,
277,
304,
267,
2729,
275,
982,
2842,
779,
549,
12,
298,
269,
401,
756,
6575,
1122,
342,
267,
291,
14,
629,
18353,
269,
334,
8939,
715,
9,
334,
8939,
756,
430,
401,
4700,
8,
1391,
430,
267,
291,
14,
1815,
8,
1391,
14,
2579,
24692,
430,
339,
347,
511,
63,
262,
8,
277,
304,
267,
769,
63,
275,
359,
17,
12,
499,
12,
650,
61,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
17,
12,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
262,
297,
488,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
403,
12,
283,
262,
297,
769,
63,
566,
339,
347,
511,
63,
1397,
63,
262,
8,
277,
304,
267,
769,
63,
275,
359,
17,
12,
499,
12,
650,
61,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
20,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
267,
291,
14,
479,
19511,
591,
8,
797,
12,
359,
17,
12,
283,
1397,
297,
283,
262,
297,
488,
566,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
403,
12,
283,
1397,
297,
283,
262,
297,
769,
63,
566,
339,
347,
511,
63,
19571,
8,
277,
304,
267,
327,
334,
797,
436,
756,
9,
503,
715,
508,
715,
257,
25549,
781,
2934,
642,
1373,
12,
2839,
2018,
267,
327,
756,
436,
334,
797,
503,
715,
9,
508,
756,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
797,
12,
283,
460,
297,
756,
12,
283,
269,
297,
715,
566,
398,
327,
715,
503,
334,
797,
436,
756,
9,
508,
715,
257,
25549,
781,
2934,
642,
1373,
12,
2839,
2018,
267,
327,
334,
549,
503,
756,
9,
436,
756,
508,
756,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
549,
12,
283,
269,
297,
756,
12,
283,
460,
297,
756,
566,
398,
327,
334,
17,
503,
413,
9,
508,
499,
221,
1035,
756,
267,
327,
413,
503,
334,
17,
508,
499,
9,
221,
1035,
715,
257,
25549,
781,
2934,
642,
1373,
267,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
17,
12,
283,
269,
297,
413,
12,
283,
389,
297,
499,
566,
398,
291,
14,
479,
19511,
591,
8,
549,
12,
359,
549,
12,
283,
389,
297,
715,
12,
283,
269,
297,
715,
12,
283,
389,
297,
756,
566,
398,
291,
14,
629,
18353,
269,
334,
460,
334,
389,
334,
8939,
413,
9,
334,
8939,
499,
430,
334,
8939,
650,
430,
334,
8939,
841,
430,
401,
586,
4700,
8,
3917,
2842,
779,
17,
12,
283,
389,
297,
499,
12,
283,
460,
297,
650,
12,
283,
269,
297,
841,
6575,
1122,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
cuongnv23/ansible
|
test/units/modules/network/netscaler/test_netscaler_ssl_certkey.py
|
30
|
22156
|
# Copyright (c) 2017 Citrix Systems
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from ansible.compat.tests.mock import patch, Mock, MagicMock, call
from .netscaler_module import TestModule, nitro_base_patcher, set_module_args
import sys
if sys.version_info[:2] != (2, 6):
import requests
class TestNetscalerSSLCertkeyModule(TestModule):
@classmethod
def setUpClass(cls):
class MockException(Exception):
pass
cls.MockException = MockException
m = MagicMock()
cls.server_mock = MagicMock()
cls.server_mock.__class__ = MagicMock(add=Mock())
nssrc_modules_mock = {
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslcertkey': m,
'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslcertkey.sslcertkey': m,
}
cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock)
cls.nitro_base_patcher = nitro_base_patcher
@classmethod
def tearDownClass(cls):
cls.nitro_base_patcher.stop()
cls.nitro_specific_patcher.stop()
def setUp(self):
self.nitro_base_patcher.start()
self.nitro_specific_patcher.start()
# Setup minimal required arguments to pass AnsibleModule argument parsing
def tearDown(self):
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
def test_graceful_nitro_api_import_error(self):
# Stop nitro api patching to cause ImportError
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
self.nitro_base_patcher.stop()
self.nitro_specific_patcher.stop()
from ansible.modules.network.netscaler import netscaler_ssl_certkey
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertEqual(result['msg'], 'Could not load nitro python sdk')
def test_graceful_nitro_error_on_login(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
class MockException(Exception):
def __init__(self, *args, **kwargs):
self.errorcode = 0
self.message = ''
client_mock = Mock()
client_mock.login = Mock(side_effect=MockException)
m = Mock(return_value=client_mock)
with patch('ansible.modules.network.netscaler.netscaler_ssl_certkey.get_nitro_client', m):
with patch('ansible.modules.network.netscaler.netscaler_ssl_certkey.nitro_exception', MockException):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')
def test_graceful_no_connection_error(self):
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
class MockException(Exception):
pass
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.ConnectionError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
nitro_exception=MockException,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertTrue(result['msg'].startswith('Connection error'), msg='Connection error was not handled gracefully')
def test_graceful_login_error(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
if sys.version_info[:2] == (2, 6):
self.skipTest('requests library not available under python2.6')
class MockException(Exception):
pass
client_mock = Mock()
attrs = {'login.side_effect': requests.exceptions.SSLError}
client_mock.configure_mock(**attrs)
m = Mock(return_value=client_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
nitro_exception=MockException,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
def test_save_config_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[False, True]),
key_identical=Mock(side_effect=[True]),
ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
nitro_exception=self.MockException,
):
self.module = netscaler_ssl_certkey
self.exited()
self.assertIn(call.save_config(), client_mock.mock_calls)
def test_save_config_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
):
self.module = netscaler_ssl_certkey
self.exited()
self.assertIn(call.save_config(), client_mock.mock_calls)
def test_save_config_not_called_on_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[False, True]),
key_identical=Mock(side_effect=[True]),
ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
nitro_exception=self.MockException,
):
self.module = netscaler_ssl_certkey
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
def test_save_config_not_called_on_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
save_config=False,
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_mock = Mock()
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[True, False]),
ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
):
self.module = netscaler_ssl_certkey
self.exited()
self.assertNotIn(call.save_config(), client_mock.mock_calls)
def test_new_ssl_certkey_execution_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
key_exists=Mock(side_effect=[False, True]),
key_identical=Mock(side_effect=[True]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_has_calls([call.add()])
def test_modified_server_execution_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[True, True]),
key_identical=Mock(side_effect=[False, True]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_has_calls([call.update()])
def test_absent_server_execution_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[True, False]),
key_identical=Mock(side_effect=[False, True]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_has_calls([call.delete()])
def test_present_key_identical_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[True, True]),
key_identical=Mock(side_effect=[True, True]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_not_called()
def test_absent_server_noop_flow(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[False, False]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
self.exited()
ssl_certkey_proxy_mock.assert_not_called()
def test_present_server_failed_update(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
nitro_exception=self.MockException,
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[True, True]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertEqual(result['msg'], 'SSL certkey differs from configured')
self.assertTrue(result['failed'])
def test_present_server_failed_create(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
nitro_exception=self.MockException,
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[False, False]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertEqual(result['msg'], 'SSL certkey does not exist')
self.assertTrue(result['failed'])
def test_present_server_update_immutable_attribute(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
nitro_exception=self.MockException,
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=['domain']),
key_exists=Mock(side_effect=[True, True]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertEqual(result['msg'], 'Cannot update immutable attributes [\'domain\']')
self.assertTrue(result['failed'])
def test_absent_server_failed_delete(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
client_mock = Mock()
m = Mock(return_value=client_mock)
ssl_certkey_proxy_attrs = {
'diff_object.return_value': {},
}
ssl_certkey_proxy_mock = Mock()
ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
nitro_exception=self.MockException,
get_nitro_client=m,
diff_list=Mock(return_value={}),
get_immutables_intersection=Mock(return_value=[]),
key_exists=Mock(side_effect=[True, True]),
key_identical=Mock(side_effect=[False, False]),
ConfigProxy=config_proxy_mock,
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertEqual(result['msg'], 'SSL certkey still exists')
self.assertTrue(result['failed'])
def test_graceful_nitro_exception_state_present(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='present',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
class MockException(Exception):
def __init__(self, *args, **kwargs):
self.errorcode = 0
self.message = ''
m = Mock(side_effect=MockException)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
key_exists=m,
nitro_exception=MockException
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertTrue(
result['msg'].startswith('nitro exception'),
msg='Nitro exception not caught on operation absent'
)
def test_graceful_nitro_exception_state_absent(self):
set_module_args(dict(
nitro_user='user',
nitro_pass='pass',
nsip='1.1.1.1',
state='absent',
))
from ansible.modules.network.netscaler import netscaler_ssl_certkey
class MockException(Exception):
def __init__(self, *args, **kwargs):
self.errorcode = 0
self.message = ''
m = Mock(side_effect=MockException)
with patch.multiple(
'ansible.modules.network.netscaler.netscaler_ssl_certkey',
key_exists=m,
nitro_exception=MockException
):
self.module = netscaler_ssl_certkey
result = self.failed()
self.assertTrue(
result['msg'].startswith('nitro exception'),
msg='Nitro exception not caught on operation absent'
)
|
gpl-3.0
|
[
199,
3,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
12,
4420,
12,
10079,
12,
1240,
199,
504,
1275,
18860,
63,
578,
492,
1379,
2377,
12,
20107,
63,
1095,
63,
11238,
12,
663,
63,
578,
63,
589,
199,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
1137,
334,
18,
12,
1227,
304,
272,
492,
4145,
421,
199,
533,
1379,
2480,
11494,
5413,
14768,
498,
2377,
8,
774,
2377,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
398,
843,
14,
3346,
1726,
275,
4420,
1726,
398,
333,
275,
10079,
342,
267,
843,
14,
1000,
63,
1805,
275,
10079,
342,
267,
843,
14,
1000,
63,
1805,
855,
533,
363,
275,
10079,
8,
525,
29,
3346,
1012,
267,
302,
32231,
63,
3112,
63,
1805,
275,
469,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
356,
333,
12,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
14,
4266,
4736,
498,
356,
333,
12,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
14,
4266,
4736,
498,
14,
4266,
4736,
498,
356,
333,
12,
267,
789,
398,
843,
14,
18893,
63,
6100,
63,
11238,
275,
3371,
14,
807,
8,
1274,
14,
3112,
12,
302,
32231,
63,
3112,
63,
1805,
9,
267,
843,
14,
18893,
63,
1095,
63,
11238,
275,
20107,
63,
1095,
63,
11238,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
843,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
928,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
928,
342,
398,
327,
12439,
13460,
1415,
2368,
370,
986,
6953,
1423,
6057,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
339,
347,
511,
63,
20631,
1893,
63,
18893,
63,
1246,
63,
646,
63,
705,
8,
277,
304,
267,
327,
8015,
20107,
2986,
3371,
316,
370,
7675,
3545,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
267,
291,
14,
578,
275,
26067,
63,
4266,
63,
4736,
498,
267,
754,
275,
291,
14,
4892,
342,
267,
291,
14,
629,
8,
1099,
459,
1328,
995,
283,
6531,
440,
2248,
20107,
2366,
13628,
358,
339,
347,
511,
63,
20631,
1893,
63,
18893,
63,
705,
63,
265,
63,
2886,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
398,
1021,
4420,
1726,
8,
1726,
304,
288,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
355,
291,
14,
28857,
275,
378,
355,
291,
14,
1188,
275,
2125,
398,
1890,
63,
1805,
275,
4420,
342,
267,
1890,
63,
1805,
14,
2886,
275,
4420,
8,
2441,
63,
5881,
29,
3346,
1726,
9,
267,
333,
275,
4420,
8,
1107,
63,
585,
29,
1258,
63,
1805,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
4266,
63,
4736,
498,
14,
362,
63,
18893,
63,
1258,
297,
333,
304,
288,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
4266,
63,
4736,
498,
14,
18893,
63,
1971,
297,
4420,
1726,
304,
355,
291,
14,
578,
275,
26067,
63,
4266,
63,
4736,
498,
355,
754,
275,
291,
14,
4892,
342,
355,
291,
14,
1815,
8,
1099,
459,
1328,
2278,
2460,
360,
18893,
1919,
659,
1499,
534,
18893,
1919,
5309,
4676,
440,
8860,
7684,
358,
339,
347,
511,
63,
20631,
1893,
63,
889,
63,
2105,
63,
705,
8,
277,
304,
398,
340,
984,
14,
1023,
63,
815,
1491,
18,
61,
508,
334,
18,
12,
1227,
304,
288,
291,
14,
23809,
360,
6615,
3555,
440,
2808,
1334,
2366,
18,
14,
22,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
398,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
267
] |
[
3,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
12,
4420,
12,
10079,
12,
1240,
199,
504,
1275,
18860,
63,
578,
492,
1379,
2377,
12,
20107,
63,
1095,
63,
11238,
12,
663,
63,
578,
63,
589,
199,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
1137,
334,
18,
12,
1227,
304,
272,
492,
4145,
421,
199,
533,
1379,
2480,
11494,
5413,
14768,
498,
2377,
8,
774,
2377,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
398,
843,
14,
3346,
1726,
275,
4420,
1726,
398,
333,
275,
10079,
342,
267,
843,
14,
1000,
63,
1805,
275,
10079,
342,
267,
843,
14,
1000,
63,
1805,
855,
533,
363,
275,
10079,
8,
525,
29,
3346,
1012,
267,
302,
32231,
63,
3112,
63,
1805,
275,
469,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
356,
333,
12,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
14,
4266,
4736,
498,
356,
333,
12,
288,
283,
78,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
888,
14,
4266,
14,
4266,
4736,
498,
14,
4266,
4736,
498,
356,
333,
12,
267,
789,
398,
843,
14,
18893,
63,
6100,
63,
11238,
275,
3371,
14,
807,
8,
1274,
14,
3112,
12,
302,
32231,
63,
3112,
63,
1805,
9,
267,
843,
14,
18893,
63,
1095,
63,
11238,
275,
20107,
63,
1095,
63,
11238,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
843,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
928,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
928,
342,
398,
327,
12439,
13460,
1415,
2368,
370,
986,
6953,
1423,
6057,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
339,
347,
511,
63,
20631,
1893,
63,
18893,
63,
1246,
63,
646,
63,
705,
8,
277,
304,
267,
327,
8015,
20107,
2986,
3371,
316,
370,
7675,
3545,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
291,
14,
18893,
63,
1095,
63,
11238,
14,
2379,
342,
267,
291,
14,
18893,
63,
6100,
63,
11238,
14,
2379,
342,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
267,
291,
14,
578,
275,
26067,
63,
4266,
63,
4736,
498,
267,
754,
275,
291,
14,
4892,
342,
267,
291,
14,
629,
8,
1099,
459,
1328,
995,
283,
6531,
440,
2248,
20107,
2366,
13628,
358,
339,
347,
511,
63,
20631,
1893,
63,
18893,
63,
705,
63,
265,
63,
2886,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
398,
1021,
4420,
1726,
8,
1726,
304,
288,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
355,
291,
14,
28857,
275,
378,
355,
291,
14,
1188,
275,
2125,
398,
1890,
63,
1805,
275,
4420,
342,
267,
1890,
63,
1805,
14,
2886,
275,
4420,
8,
2441,
63,
5881,
29,
3346,
1726,
9,
267,
333,
275,
4420,
8,
1107,
63,
585,
29,
1258,
63,
1805,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
4266,
63,
4736,
498,
14,
362,
63,
18893,
63,
1258,
297,
333,
304,
288,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
4266,
63,
4736,
498,
14,
18893,
63,
1971,
297,
4420,
1726,
304,
355,
291,
14,
578,
275,
26067,
63,
4266,
63,
4736,
498,
355,
754,
275,
291,
14,
4892,
342,
355,
291,
14,
1815,
8,
1099,
459,
1328,
2278,
2460,
360,
18893,
1919,
659,
1499,
534,
18893,
1919,
5309,
4676,
440,
8860,
7684,
358,
339,
347,
511,
63,
20631,
1893,
63,
889,
63,
2105,
63,
705,
8,
277,
304,
398,
340,
984,
14,
1023,
63,
815,
1491,
18,
61,
508,
334,
18,
12,
1227,
304,
288,
291,
14,
23809,
360,
6615,
3555,
440,
2808,
1334,
2366,
18,
14,
22,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
20107,
63,
751,
534,
751,
297,
288,
20107,
63,
1529,
534,
1529,
297,
288,
302,
17839,
534,
17,
14,
17,
14,
17,
14,
17,
297,
288,
1174,
534,
1881,
297,
267,
5082,
267,
687,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
4266,
63,
4736,
498,
398,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
tinkhaven-organization/odoo
|
addons/google_account/__openerp__.py
|
312
|
1457
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Google Users',
'version': '1.0',
'category': 'Tools',
'description': """
The module adds google user in res user.
========================================
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com',
'depends': ['base_setup'],
'data': [
'google_account_data.xml',
],
'demo': [],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
13266,
20123,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
1918,
859,
9584,
6233,
922,
315,
522,
922,
14,
199,
2486,
763,
199,
7208,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
63,
2758,
995,
272,
283,
576,
356,
359,
267,
283,
3098,
63,
2048,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
13266,
20123,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
1918,
859,
9584,
6233,
922,
315,
522,
922,
14,
199,
2486,
763,
199,
7208,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
63,
2758,
995,
272,
283,
576,
356,
359,
267,
283,
3098,
63,
2048,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
"""Tests for ReParser-based message parser"""
from hangups import message_parser, hangouts_pb2
def parse_text(text):
parser = message_parser.ChatMessageParser()
return [(s.text, s.params) for s in parser.parse(text)]
def test_parse_linebreaks():
text = 'line1\nline2\r\nline3'
expected = [('line1', {}),
('\n', {'segment_type': hangouts_pb2.SEGMENT_TYPE_LINE_BREAK}),
('line2', {}),
('\n', {'segment_type': hangouts_pb2.SEGMENT_TYPE_LINE_BREAK}),
('line3', {})]
assert expected == parse_text(text)
def test_parse_autolinks():
text = 'www.google.com google.com/maps (https://en.wikipedia.org/wiki/Parenthesis_(disambiguation))'
expected = [('www.google.com', {'link_target': 'http://www.google.com'}),
(' ', {}),
('google.com/maps', {'link_target': 'http://google.com/maps'}),
(' (', {}),
('https://en.wikipedia.org/wiki/Parenthesis_(disambiguation)',
{'link_target': 'https://en.wikipedia.org/wiki/Parenthesis_(disambiguation)'}),
(')', {})]
assert expected == parse_text(text)
def test_parse_markdown():
text = 'Test **bold *bolditalic* bold** _italic_ not_italic_not ~~strike~~ [Google](www.google.com)'
expected = [('Test ', {}),
('bold ', {'is_bold': True}),
('bolditalic', {'is_bold': True, 'is_italic': True}),
(' bold', {'is_bold': True}),
(' ', {}),
('italic', {'is_italic': True}),
(' not_italic_not ', {}),
('strike', {'is_strikethrough': True}),
(' ', {}),
('Google', {'link_target': 'http://www.google.com'})]
assert expected == parse_text(text)
def test_parse_html():
text = ('Test <b>bold <i>bolditalic</i> bold</b> <em>italic</em> <del>strike</del>'
'<br>'
'<a href="google.com">Google</a>'
'<img src=\'https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg\'>')
expected = [('Test ', {}),
('bold ', {'is_bold': True}),
('bolditalic', {'is_bold': True, 'is_italic': True}),
(' bold', {'is_bold': True}),
(' ', {}),
('italic', {'is_italic': True}),
(' ', {}),
('strike', {'is_strikethrough': True}),
('\n', {'segment_type': hangouts_pb2.SEGMENT_TYPE_LINE_BREAK}),
('Google', {'link_target': 'http://google.com'}),
('https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg',
{'link_target': 'https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg'})]
assert expected == parse_text(text)
|
mit
|
[
624,
2925,
367,
799,
2842,
13,
6788,
1245,
1798,
624,
199,
199,
504,
30084,
15203,
492,
1245,
63,
2087,
12,
30084,
16816,
63,
3317,
18,
421,
199,
318,
2198,
63,
505,
8,
505,
304,
272,
1798,
275,
1245,
63,
2087,
14,
21954,
2209,
2842,
342,
272,
372,
3842,
83,
14,
505,
12,
308,
14,
1162,
9,
367,
308,
315,
1798,
14,
1122,
8,
505,
1874,
421,
199,
318,
511,
63,
1122,
63,
604,
18566,
837,
272,
1318,
275,
283,
604,
17,
60,
78,
604,
18,
60,
82,
60,
78,
604,
19,
7,
272,
1420,
275,
4274,
604,
17,
297,
8613,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
604,
18,
297,
8613,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
604,
19,
297,
1052,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
6898,
393,
2292,
83,
837,
272,
1318,
275,
283,
1544,
14,
3098,
14,
957,
6233,
14,
957,
15,
8919,
334,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
23089,
272,
1420,
275,
4274,
1544,
14,
3098,
14,
957,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
1544,
14,
3098,
14,
957,
1604,
355,
661,
1656,
8613,
355,
661,
3098,
14,
957,
15,
8919,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
3098,
14,
957,
15,
8919,
1604,
355,
661,
334,
297,
8613,
355,
661,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
3196,
326,
791,
1073,
63,
1375,
356,
283,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
9,
1604,
355,
334,
358,
297,
1052,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
15653,
837,
272,
1318,
275,
283,
774,
1011,
9771,
627,
23484,
1741,
17999,
10,
17268,
538,
485,
21843,
63,
440,
63,
21843,
63,
1397,
221,
1714,
26845,
1714,
359,
13266,
8738,
1544,
14,
3098,
14,
957,
3171,
272,
1420,
275,
4274,
774,
1656,
8613,
355,
661,
9771,
1656,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
23484,
1741,
17999,
297,
791,
374,
63,
9771,
356,
715,
12,
283,
374,
63,
21843,
356,
715,
8688,
355,
661,
17268,
297,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
21843,
297,
791,
374,
63,
21843,
356,
715,
8688,
355,
661,
440,
63,
21843,
63,
1397,
1656,
8613,
355,
661,
26845,
297,
791,
374,
63,
26845,
8304,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
13266,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
1544,
14,
3098,
14,
957,
936,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
1360,
837,
272,
1318,
275,
661,
774,
665,
66,
30,
9771,
665,
73,
30,
23484,
1741,
17999,
1108,
73,
30,
17268,
1108,
66,
30,
665,
5633,
30,
21843,
1108,
5633,
30,
665,
2264,
30,
26845,
1108,
2264,
3524,
288,
2650,
3289,
3524,
288,
2650,
65,
4369,
628,
3098,
14,
957,
1743,
13266,
1108,
65,
3524,
288,
2650,
4060,
2928,
25641,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
3985,
5971,
272,
1420,
275,
4274,
774,
1656,
8613,
355,
661,
9771,
1656,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
23484,
1741,
17999,
297,
791,
374,
63,
9771,
356,
715,
12,
283,
374,
63,
21843,
356,
715,
8688,
355,
661,
17268,
297,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
21843,
297,
791,
374,
63,
21843,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
26845,
297,
791,
374,
63,
26845,
8304,
356,
715,
8688,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
13266,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
3098,
14,
957,
1604,
355,
661,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
297,
326,
791,
1073,
63,
1375,
356,
283,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
936,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2925,
367,
799,
2842,
13,
6788,
1245,
1798,
624,
199,
199,
504,
30084,
15203,
492,
1245,
63,
2087,
12,
30084,
16816,
63,
3317,
18,
421,
199,
318,
2198,
63,
505,
8,
505,
304,
272,
1798,
275,
1245,
63,
2087,
14,
21954,
2209,
2842,
342,
272,
372,
3842,
83,
14,
505,
12,
308,
14,
1162,
9,
367,
308,
315,
1798,
14,
1122,
8,
505,
1874,
421,
199,
318,
511,
63,
1122,
63,
604,
18566,
837,
272,
1318,
275,
283,
604,
17,
60,
78,
604,
18,
60,
82,
60,
78,
604,
19,
7,
272,
1420,
275,
4274,
604,
17,
297,
8613,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
604,
18,
297,
8613,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
604,
19,
297,
1052,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
6898,
393,
2292,
83,
837,
272,
1318,
275,
283,
1544,
14,
3098,
14,
957,
6233,
14,
957,
15,
8919,
334,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
23089,
272,
1420,
275,
4274,
1544,
14,
3098,
14,
957,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
1544,
14,
3098,
14,
957,
1604,
355,
661,
1656,
8613,
355,
661,
3098,
14,
957,
15,
8919,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
3098,
14,
957,
15,
8919,
1604,
355,
661,
334,
297,
8613,
355,
661,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
3196,
326,
791,
1073,
63,
1375,
356,
283,
2859,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
4232,
828,
14925,
2531,
2297,
16902,
4086,
9,
1604,
355,
334,
358,
297,
1052,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
15653,
837,
272,
1318,
275,
283,
774,
1011,
9771,
627,
23484,
1741,
17999,
10,
17268,
538,
485,
21843,
63,
440,
63,
21843,
63,
1397,
221,
1714,
26845,
1714,
359,
13266,
8738,
1544,
14,
3098,
14,
957,
3171,
272,
1420,
275,
4274,
774,
1656,
8613,
355,
661,
9771,
1656,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
23484,
1741,
17999,
297,
791,
374,
63,
9771,
356,
715,
12,
283,
374,
63,
21843,
356,
715,
8688,
355,
661,
17268,
297,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
21843,
297,
791,
374,
63,
21843,
356,
715,
8688,
355,
661,
440,
63,
21843,
63,
1397,
1656,
8613,
355,
661,
26845,
297,
791,
374,
63,
26845,
8304,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
13266,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
1544,
14,
3098,
14,
957,
936,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
421,
199,
318,
511,
63,
1122,
63,
1360,
837,
272,
1318,
275,
661,
774,
665,
66,
30,
9771,
665,
73,
30,
23484,
1741,
17999,
1108,
73,
30,
17268,
1108,
66,
30,
665,
5633,
30,
21843,
1108,
5633,
30,
665,
2264,
30,
26845,
1108,
2264,
3524,
288,
2650,
3289,
3524,
288,
2650,
65,
4369,
628,
3098,
14,
957,
1743,
13266,
1108,
65,
3524,
288,
2650,
4060,
2928,
25641,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
3985,
5971,
272,
1420,
275,
4274,
774,
1656,
8613,
355,
661,
9771,
1656,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
23484,
1741,
17999,
297,
791,
374,
63,
9771,
356,
715,
12,
283,
374,
63,
21843,
356,
715,
8688,
355,
661,
17268,
297,
791,
374,
63,
9771,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
21843,
297,
791,
374,
63,
21843,
356,
715,
8688,
355,
661,
1656,
8613,
355,
661,
26845,
297,
791,
374,
63,
26845,
8304,
356,
715,
8688,
355,
17485,
78,
297,
791,
9255,
63,
466,
356,
30084,
16816,
63,
3317,
18,
14,
27001,
63,
2711,
63,
6174,
63,
14731,
8688,
355,
661,
13266,
297,
791,
1073,
63,
1375,
356,
283,
1014,
921,
3098,
14,
957,
1604,
355,
661,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
297,
326,
791,
1073,
63,
1375,
356,
283,
2859,
921,
5064,
14,
5319,
1036,
2391,
14,
1308,
15,
13961,
15,
287,
15,
24,
15,
1257,
15,
55,
29386,
13,
9733,
13,
86,
18,
14,
10273,
936,
1874,
272,
702,
1420,
508,
2198,
63,
505,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
RomainBrault/scikit-learn
|
sklearn/datasets/__init__.py
|
61
|
3734
|
"""
The :mod:`sklearn.datasets` module includes utilities to load datasets,
including methods to load and fetch popular reference datasets. It also
features some artificial data generators.
"""
from .base import load_breast_cancer
from .base import load_boston
from .base import load_diabetes
from .base import load_digits
from .base import load_files
from .base import load_iris
from .base import load_linnerud
from .base import load_sample_images
from .base import load_sample_image
from .base import load_wine
from .base import get_data_home
from .base import clear_data_home
from .covtype import fetch_covtype
from .kddcup99 import fetch_kddcup99
from .mlcomp import load_mlcomp
from .lfw import fetch_lfw_pairs
from .lfw import fetch_lfw_people
from .twenty_newsgroups import fetch_20newsgroups
from .twenty_newsgroups import fetch_20newsgroups_vectorized
from .mldata import fetch_mldata, mldata_filename
from .samples_generator import make_classification
from .samples_generator import make_multilabel_classification
from .samples_generator import make_hastie_10_2
from .samples_generator import make_regression
from .samples_generator import make_blobs
from .samples_generator import make_moons
from .samples_generator import make_circles
from .samples_generator import make_friedman1
from .samples_generator import make_friedman2
from .samples_generator import make_friedman3
from .samples_generator import make_low_rank_matrix
from .samples_generator import make_sparse_coded_signal
from .samples_generator import make_sparse_uncorrelated
from .samples_generator import make_spd_matrix
from .samples_generator import make_swiss_roll
from .samples_generator import make_s_curve
from .samples_generator import make_sparse_spd_matrix
from .samples_generator import make_gaussian_quantiles
from .samples_generator import make_biclusters
from .samples_generator import make_checkerboard
from .svmlight_format import load_svmlight_file
from .svmlight_format import load_svmlight_files
from .svmlight_format import dump_svmlight_file
from .olivetti_faces import fetch_olivetti_faces
from .species_distributions import fetch_species_distributions
from .california_housing import fetch_california_housing
from .rcv1 import fetch_rcv1
__all__ = ['clear_data_home',
'dump_svmlight_file',
'fetch_20newsgroups',
'fetch_20newsgroups_vectorized',
'fetch_lfw_pairs',
'fetch_lfw_people',
'fetch_mldata',
'fetch_olivetti_faces',
'fetch_species_distributions',
'fetch_california_housing',
'fetch_covtype',
'fetch_rcv1',
'fetch_kddcup99',
'get_data_home',
'load_boston',
'load_diabetes',
'load_digits',
'load_files',
'load_iris',
'load_breast_cancer',
'load_linnerud',
'load_mlcomp',
'load_sample_image',
'load_sample_images',
'load_svmlight_file',
'load_svmlight_files',
'load_wine',
'make_biclusters',
'make_blobs',
'make_circles',
'make_classification',
'make_checkerboard',
'make_friedman1',
'make_friedman2',
'make_friedman3',
'make_gaussian_quantiles',
'make_hastie_10_2',
'make_low_rank_matrix',
'make_moons',
'make_multilabel_classification',
'make_regression',
'make_s_curve',
'make_sparse_coded_signal',
'make_sparse_spd_matrix',
'make_sparse_uncorrelated',
'make_spd_matrix',
'make_swiss_roll',
'mldata_filename']
|
bsd-3-clause
|
[
624,
199,
1918,
520,
1494,
1705,
27993,
14,
12281,
64,
859,
6952,
15841,
370,
2248,
13148,
12,
199,
15768,
3102,
370,
2248,
436,
5267,
4560,
2238,
3659,
13148,
14,
2779,
2597,
199,
3179,
2005,
601,
32033,
666,
16952,
14,
199,
624,
199,
504,
1275,
1095,
492,
2248,
63,
10205,
1810,
63,
2425,
2247,
199,
504,
1275,
1095,
492,
2248,
63,
28275,
199,
504,
1275,
1095,
492,
2248,
63,
328,
26290,
199,
504,
1275,
1095,
492,
2248,
63,
7022,
199,
504,
1275,
1095,
492,
2248,
63,
1725,
199,
504,
1275,
1095,
492,
2248,
63,
11885,
199,
504,
1275,
1095,
492,
2248,
63,
472,
1372,
1181,
199,
504,
1275,
1095,
492,
2248,
63,
3271,
63,
4782,
199,
504,
1275,
1095,
492,
2248,
63,
3271,
63,
1569,
199,
504,
1275,
1095,
492,
2248,
63,
87,
1132,
199,
504,
1275,
1095,
492,
664,
63,
576,
63,
4219,
199,
504,
1275,
1095,
492,
5436,
63,
576,
63,
4219,
199,
504,
1275,
8695,
466,
492,
5267,
63,
8695,
466,
199,
504,
1275,
75,
617,
17500,
1020,
492,
5267,
63,
75,
617,
17500,
1020,
199,
504,
1275,
757,
863,
492,
2248,
63,
757,
863,
199,
504,
1275,
31624,
492,
5267,
63,
31624,
63,
7322,
199,
504,
1275,
31624,
492,
5267,
63,
31624,
63,
13562,
199,
504,
1275,
8122,
287,
369,
63,
13224,
2634,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
1275,
8122,
287,
369,
63,
13224,
2634,
492,
5267,
63,
1165,
13224,
2634,
63,
4106,
1759,
199,
504,
1275,
757,
576,
492,
5267,
63,
757,
576,
12,
19184,
576,
63,
1501,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
14368,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
3029,
1302,
63,
14368,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
72,
1810,
1873,
63,
709,
63,
18,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
12513,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
21893,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
573,
4654,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
6092,
2978,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
17,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
18,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
19,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
674,
63,
4648,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
15282,
63,
4653,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
324,
989,
2407,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
681,
68,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
3519,
19857,
63,
2827,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
83,
63,
11895,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
681,
68,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
22911,
63,
12316,
2978,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4492,
9170,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
6743,
3576,
199,
504,
1275,
16820,
4040,
63,
908,
492,
2248,
63,
16820,
4040,
63,
493,
199,
504,
1275,
16820,
4040,
63,
908,
492,
2248,
63,
16820,
4040,
63,
1725,
199,
504,
1275,
16820,
4040,
63,
908,
492,
5461,
63,
16820,
4040,
63,
493,
199,
504,
1275,
23711,
28350,
280,
63,
4309,
492,
5267,
63,
23711,
28350,
280,
63,
4309,
199,
504,
1275,
17168,
63,
5613,
492,
5267,
63,
17168,
63,
5613,
199,
504,
1275,
915,
73,
509,
22042,
63,
526,
4941,
492,
5267,
63,
915,
73,
509,
22042,
63,
526,
4941,
199,
504,
1275,
1195,
86,
17,
492,
5267,
63,
1195,
86,
17,
421,
199,
363,
452,
363,
275,
788,
3584,
63,
576,
63,
4219,
297,
1779,
283,
2724,
63,
16820,
4040,
63,
493,
297,
1779,
283,
3535,
63,
1165,
13224,
2634,
297,
1779,
283,
3535,
63,
1165,
13224,
2634,
63,
4106,
1759,
297,
1779,
283,
3535,
63,
31624,
63,
7322,
297,
1779,
283,
3535,
63,
31624,
63,
13562,
297,
1779,
283,
3535,
63,
757,
576,
297,
1779,
283,
3535,
63,
23711,
28350,
280,
63,
4309,
297,
1779,
283,
3535,
63,
17168,
63,
5613,
297,
1779,
283,
3535,
63,
915,
73,
509,
22042,
63,
526,
4941,
297,
1779,
283,
3535,
63,
8695,
466,
297,
1779,
283,
3535,
63,
1195,
86,
17,
297,
1779,
283,
3535,
63,
75,
617,
17500,
1020,
297,
1779,
283,
362,
63,
576,
63,
4219,
297,
1779,
283,
912,
63,
28275,
297,
1779,
283,
912,
63,
328,
26290,
297,
1779,
283,
912,
63,
7022,
297,
1779,
283,
912,
63,
1725,
297,
1779,
283,
912,
63,
11885,
297,
1779,
283,
912,
63,
10205,
1810,
63,
2425,
2247,
297,
1779,
283,
912,
63,
472,
1372,
1181,
297,
1779,
283,
912,
63,
757,
863,
297,
1779,
283,
912,
63,
3271,
63,
1569,
297,
1779,
283,
912,
63,
3271,
63,
4782,
297,
1779,
283,
912,
63,
16820,
4040,
63,
493,
297,
1779,
283,
912,
63,
16820,
4040,
63,
1725,
297,
1779,
283,
912,
63,
87,
1132,
297,
1779,
283,
1875,
63,
4492,
9170,
297,
1779,
283,
1875,
63,
21893,
297,
1779,
283,
1875,
63,
6092,
2978,
297,
1779,
283,
1875,
63,
14368,
297,
1779,
283,
1875,
63,
6743,
3576,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
17,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
18,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
19,
297,
1779,
283,
1875,
63,
22911,
63,
12316,
2978,
297,
1779,
283,
1875,
63,
72,
1810,
1873,
63,
709,
63,
18,
297,
1779,
283,
1875,
63,
674,
63,
4648,
63,
3642,
297,
1779,
283,
1875,
63,
573,
4654,
297,
1779,
283,
1875,
63,
3029,
1302,
63,
14368,
297,
1779,
283,
1875,
63,
12513,
297,
1779,
283,
1875,
63,
83,
63,
11895,
297,
1779,
283,
1875,
63,
4421,
63,
15282,
63,
4653,
297,
1779,
283,
1875,
63,
4421,
63,
681,
68,
63,
3642,
297,
1779,
283,
1875,
63,
4421,
63,
324,
989,
2407,
297,
1779,
283,
1875,
63,
681,
68,
63,
3642,
297,
1779,
283,
1875,
63,
3519,
19857,
63,
2827,
297,
1779,
283,
757,
576,
63,
1501,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
1918,
520,
1494,
1705,
27993,
14,
12281,
64,
859,
6952,
15841,
370,
2248,
13148,
12,
199,
15768,
3102,
370,
2248,
436,
5267,
4560,
2238,
3659,
13148,
14,
2779,
2597,
199,
3179,
2005,
601,
32033,
666,
16952,
14,
199,
624,
199,
504,
1275,
1095,
492,
2248,
63,
10205,
1810,
63,
2425,
2247,
199,
504,
1275,
1095,
492,
2248,
63,
28275,
199,
504,
1275,
1095,
492,
2248,
63,
328,
26290,
199,
504,
1275,
1095,
492,
2248,
63,
7022,
199,
504,
1275,
1095,
492,
2248,
63,
1725,
199,
504,
1275,
1095,
492,
2248,
63,
11885,
199,
504,
1275,
1095,
492,
2248,
63,
472,
1372,
1181,
199,
504,
1275,
1095,
492,
2248,
63,
3271,
63,
4782,
199,
504,
1275,
1095,
492,
2248,
63,
3271,
63,
1569,
199,
504,
1275,
1095,
492,
2248,
63,
87,
1132,
199,
504,
1275,
1095,
492,
664,
63,
576,
63,
4219,
199,
504,
1275,
1095,
492,
5436,
63,
576,
63,
4219,
199,
504,
1275,
8695,
466,
492,
5267,
63,
8695,
466,
199,
504,
1275,
75,
617,
17500,
1020,
492,
5267,
63,
75,
617,
17500,
1020,
199,
504,
1275,
757,
863,
492,
2248,
63,
757,
863,
199,
504,
1275,
31624,
492,
5267,
63,
31624,
63,
7322,
199,
504,
1275,
31624,
492,
5267,
63,
31624,
63,
13562,
199,
504,
1275,
8122,
287,
369,
63,
13224,
2634,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
1275,
8122,
287,
369,
63,
13224,
2634,
492,
5267,
63,
1165,
13224,
2634,
63,
4106,
1759,
199,
504,
1275,
757,
576,
492,
5267,
63,
757,
576,
12,
19184,
576,
63,
1501,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
14368,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
3029,
1302,
63,
14368,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
72,
1810,
1873,
63,
709,
63,
18,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
12513,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
21893,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
573,
4654,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
6092,
2978,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
17,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
18,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
70,
18906,
1237,
19,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
674,
63,
4648,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
15282,
63,
4653,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
324,
989,
2407,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
681,
68,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
3519,
19857,
63,
2827,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
83,
63,
11895,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4421,
63,
681,
68,
63,
3642,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
22911,
63,
12316,
2978,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
4492,
9170,
199,
504,
1275,
3356,
63,
4679,
492,
1852,
63,
6743,
3576,
199,
504,
1275,
16820,
4040,
63,
908,
492,
2248,
63,
16820,
4040,
63,
493,
199,
504,
1275,
16820,
4040,
63,
908,
492,
2248,
63,
16820,
4040,
63,
1725,
199,
504,
1275,
16820,
4040,
63,
908,
492,
5461,
63,
16820,
4040,
63,
493,
199,
504,
1275,
23711,
28350,
280,
63,
4309,
492,
5267,
63,
23711,
28350,
280,
63,
4309,
199,
504,
1275,
17168,
63,
5613,
492,
5267,
63,
17168,
63,
5613,
199,
504,
1275,
915,
73,
509,
22042,
63,
526,
4941,
492,
5267,
63,
915,
73,
509,
22042,
63,
526,
4941,
199,
504,
1275,
1195,
86,
17,
492,
5267,
63,
1195,
86,
17,
421,
199,
363,
452,
363,
275,
788,
3584,
63,
576,
63,
4219,
297,
1779,
283,
2724,
63,
16820,
4040,
63,
493,
297,
1779,
283,
3535,
63,
1165,
13224,
2634,
297,
1779,
283,
3535,
63,
1165,
13224,
2634,
63,
4106,
1759,
297,
1779,
283,
3535,
63,
31624,
63,
7322,
297,
1779,
283,
3535,
63,
31624,
63,
13562,
297,
1779,
283,
3535,
63,
757,
576,
297,
1779,
283,
3535,
63,
23711,
28350,
280,
63,
4309,
297,
1779,
283,
3535,
63,
17168,
63,
5613,
297,
1779,
283,
3535,
63,
915,
73,
509,
22042,
63,
526,
4941,
297,
1779,
283,
3535,
63,
8695,
466,
297,
1779,
283,
3535,
63,
1195,
86,
17,
297,
1779,
283,
3535,
63,
75,
617,
17500,
1020,
297,
1779,
283,
362,
63,
576,
63,
4219,
297,
1779,
283,
912,
63,
28275,
297,
1779,
283,
912,
63,
328,
26290,
297,
1779,
283,
912,
63,
7022,
297,
1779,
283,
912,
63,
1725,
297,
1779,
283,
912,
63,
11885,
297,
1779,
283,
912,
63,
10205,
1810,
63,
2425,
2247,
297,
1779,
283,
912,
63,
472,
1372,
1181,
297,
1779,
283,
912,
63,
757,
863,
297,
1779,
283,
912,
63,
3271,
63,
1569,
297,
1779,
283,
912,
63,
3271,
63,
4782,
297,
1779,
283,
912,
63,
16820,
4040,
63,
493,
297,
1779,
283,
912,
63,
16820,
4040,
63,
1725,
297,
1779,
283,
912,
63,
87,
1132,
297,
1779,
283,
1875,
63,
4492,
9170,
297,
1779,
283,
1875,
63,
21893,
297,
1779,
283,
1875,
63,
6092,
2978,
297,
1779,
283,
1875,
63,
14368,
297,
1779,
283,
1875,
63,
6743,
3576,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
17,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
18,
297,
1779,
283,
1875,
63,
70,
18906,
1237,
19,
297,
1779,
283,
1875,
63,
22911,
63,
12316,
2978,
297,
1779,
283,
1875,
63,
72,
1810,
1873,
63,
709,
63,
18,
297,
1779,
283,
1875,
63,
674,
63,
4648,
63,
3642,
297,
1779,
283,
1875,
63,
573,
4654,
297,
1779,
283,
1875,
63,
3029,
1302,
63,
14368,
297,
1779,
283,
1875,
63,
12513,
297,
1779,
283,
1875,
63,
83,
63,
11895,
297,
1779,
283,
1875,
63,
4421,
63,
15282,
63,
4653,
297,
1779,
283,
1875,
63,
4421,
63,
681,
68,
63,
3642,
297,
1779,
283,
1875,
63,
4421,
63,
324,
989,
2407,
297,
1779,
283,
1875,
63,
681,
68,
63,
3642,
297,
1779,
283,
1875,
63,
3519,
19857,
63,
2827,
297,
1779,
283,
757,
576,
63,
1501,
418,
199,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hortinstein/ghost_hortinstein.github.io
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-2.7/pygments/lexers/_asybuiltins.py
|
369
|
27319
|
# -*- coding: utf-8 -*-
"""
pygments.lexers._asybuiltins
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This file contains the asy-function names and asy-variable names of
Asymptote.
Do not edit the ASYFUNCNAME and ASYVARNAME sets by hand.
TODO: perl/python script in Asymptote SVN similar to asy-list.pl but only
for function and variable names.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
ASYFUNCNAME = set([
'AND',
'Arc',
'ArcArrow',
'ArcArrows',
'Arrow',
'Arrows',
'Automatic',
'AvantGarde',
'BBox',
'BWRainbow',
'BWRainbow2',
'Bar',
'Bars',
'BeginArcArrow',
'BeginArrow',
'BeginBar',
'BeginDotMargin',
'BeginMargin',
'BeginPenMargin',
'Blank',
'Bookman',
'Bottom',
'BottomTop',
'Bounds',
'Break',
'Broken',
'BrokenLog',
'Ceil',
'Circle',
'CircleBarIntervalMarker',
'Cos',
'Courier',
'CrossIntervalMarker',
'DefaultFormat',
'DefaultLogFormat',
'Degrees',
'Dir',
'DotMargin',
'DotMargins',
'Dotted',
'Draw',
'Drawline',
'Embed',
'EndArcArrow',
'EndArrow',
'EndBar',
'EndDotMargin',
'EndMargin',
'EndPenMargin',
'Fill',
'FillDraw',
'Floor',
'Format',
'Full',
'Gaussian',
'Gaussrand',
'Gaussrandpair',
'Gradient',
'Grayscale',
'Helvetica',
'Hermite',
'HookHead',
'InOutTicks',
'InTicks',
'J',
'Label',
'Landscape',
'Left',
'LeftRight',
'LeftTicks',
'Legend',
'Linear',
'Link',
'Log',
'LogFormat',
'Margin',
'Margins',
'Mark',
'MidArcArrow',
'MidArrow',
'NOT',
'NewCenturySchoolBook',
'NoBox',
'NoMargin',
'NoModifier',
'NoTicks',
'NoTicks3',
'NoZero',
'NoZeroFormat',
'None',
'OR',
'OmitFormat',
'OmitTick',
'OutTicks',
'Ox',
'Oy',
'Palatino',
'PaletteTicks',
'Pen',
'PenMargin',
'PenMargins',
'Pentype',
'Portrait',
'RadialShade',
'Rainbow',
'Range',
'Relative',
'Right',
'RightTicks',
'Rotate',
'Round',
'SQR',
'Scale',
'ScaleX',
'ScaleY',
'ScaleZ',
'Seascape',
'Shift',
'Sin',
'Slant',
'Spline',
'StickIntervalMarker',
'Straight',
'Symbol',
'Tan',
'TeXify',
'Ticks',
'Ticks3',
'TildeIntervalMarker',
'TimesRoman',
'Top',
'TrueMargin',
'UnFill',
'UpsideDown',
'Wheel',
'X',
'XEquals',
'XOR',
'XY',
'XYEquals',
'XYZero',
'XYgrid',
'XZEquals',
'XZZero',
'XZero',
'XZgrid',
'Y',
'YEquals',
'YXgrid',
'YZ',
'YZEquals',
'YZZero',
'YZero',
'YZgrid',
'Z',
'ZX',
'ZXgrid',
'ZYgrid',
'ZapfChancery',
'ZapfDingbats',
'_cputime',
'_draw',
'_eval',
'_image',
'_labelpath',
'_projection',
'_strokepath',
'_texpath',
'aCos',
'aSin',
'aTan',
'abort',
'abs',
'accel',
'acos',
'acosh',
'acot',
'acsc',
'add',
'addArrow',
'addMargins',
'addSaveFunction',
'addnode',
'addnodes',
'addpenarc',
'addpenline',
'addseg',
'adjust',
'alias',
'align',
'all',
'altitude',
'angabscissa',
'angle',
'angpoint',
'animate',
'annotate',
'anticomplementary',
'antipedal',
'apply',
'approximate',
'arc',
'arcarrowsize',
'arccircle',
'arcdir',
'arcfromcenter',
'arcfromfocus',
'arclength',
'arcnodesnumber',
'arcpoint',
'arcsubtended',
'arcsubtendedcenter',
'arctime',
'arctopath',
'array',
'arrow',
'arrow2',
'arrowbase',
'arrowbasepoints',
'arrowsize',
'asec',
'asin',
'asinh',
'ask',
'assert',
'asy',
'asycode',
'asydir',
'asyfigure',
'asyfilecode',
'asyinclude',
'asywrite',
'atan',
'atan2',
'atanh',
'atbreakpoint',
'atexit',
'atime',
'attach',
'attract',
'atupdate',
'autoformat',
'autoscale',
'autoscale3',
'axes',
'axes3',
'axialshade',
'axis',
'axiscoverage',
'azimuth',
'babel',
'background',
'bangles',
'bar',
'barmarksize',
'barsize',
'basealign',
'baseline',
'bbox',
'beep',
'begin',
'beginclip',
'begingroup',
'beginpoint',
'between',
'bevel',
'bezier',
'bezierP',
'bezierPP',
'bezierPPP',
'bezulate',
'bibliography',
'bibliographystyle',
'binarytree',
'binarytreeNode',
'binomial',
'binput',
'bins',
'bisector',
'bisectorpoint',
'blend',
'boutput',
'box',
'bqe',
'breakpoint',
'breakpoints',
'brick',
'buildRestoreDefaults',
'buildRestoreThunk',
'buildcycle',
'bulletcolor',
'canonical',
'canonicalcartesiansystem',
'cartesiansystem',
'case1',
'case2',
'case3',
'cbrt',
'cd',
'ceil',
'center',
'centerToFocus',
'centroid',
'cevian',
'change2',
'changecoordsys',
'checkSegment',
'checkconditionlength',
'checker',
'checklengths',
'checkposition',
'checktriangle',
'choose',
'circle',
'circlebarframe',
'circlemarkradius',
'circlenodesnumber',
'circumcenter',
'circumcircle',
'clamped',
'clear',
'clip',
'clipdraw',
'close',
'cmyk',
'code',
'colatitude',
'collect',
'collinear',
'color',
'colorless',
'colors',
'colorspace',
'comma',
'compassmark',
'complement',
'complementary',
'concat',
'concurrent',
'cone',
'conic',
'conicnodesnumber',
'conictype',
'conj',
'connect',
'containmentTree',
'contains',
'contour',
'contour3',
'controlSpecifier',
'convert',
'coordinates',
'coordsys',
'copy',
'cos',
'cosh',
'cot',
'countIntersections',
'cputime',
'crop',
'cropcode',
'cross',
'crossframe',
'crosshatch',
'crossmarksize',
'csc',
'cubicroots',
'curabscissa',
'curlSpecifier',
'curpoint',
'currentarrow',
'currentexitfunction',
'currentmomarrow',
'currentpolarconicroutine',
'curve',
'cut',
'cutafter',
'cutbefore',
'cyclic',
'cylinder',
'debugger',
'deconstruct',
'defaultdir',
'defaultformat',
'defaultpen',
'defined',
'degenerate',
'degrees',
'delete',
'deletepreamble',
'determinant',
'diagonal',
'diamond',
'diffdiv',
'dir',
'dirSpecifier',
'dirtime',
'display',
'distance',
'divisors',
'do_overpaint',
'dot',
'dotframe',
'dotsize',
'downcase',
'draw',
'drawAll',
'drawDoubleLine',
'drawFermion',
'drawGhost',
'drawGluon',
'drawMomArrow',
'drawPhoton',
'drawScalar',
'drawVertex',
'drawVertexBox',
'drawVertexBoxO',
'drawVertexBoxX',
'drawVertexO',
'drawVertexOX',
'drawVertexTriangle',
'drawVertexTriangleO',
'drawVertexX',
'drawarrow',
'drawarrow2',
'drawline',
'drawtick',
'duplicate',
'elle',
'ellipse',
'ellipsenodesnumber',
'embed',
'embed3',
'empty',
'enclose',
'end',
'endScript',
'endclip',
'endgroup',
'endl',
'endpoint',
'endpoints',
'eof',
'eol',
'equation',
'equations',
'erase',
'erasestep',
'erf',
'erfc',
'error',
'errorbar',
'errorbars',
'eval',
'excenter',
'excircle',
'exit',
'exitXasyMode',
'exitfunction',
'exp',
'expfactors',
'expi',
'expm1',
'exradius',
'extend',
'extension',
'extouch',
'fabs',
'factorial',
'fermat',
'fft',
'fhorner',
'figure',
'file',
'filecode',
'fill',
'filldraw',
'filloutside',
'fillrule',
'filltype',
'find',
'finite',
'finiteDifferenceJacobian',
'firstcut',
'firstframe',
'fit',
'fit2',
'fixedscaling',
'floor',
'flush',
'fmdefaults',
'fmod',
'focusToCenter',
'font',
'fontcommand',
'fontsize',
'foot',
'format',
'frac',
'frequency',
'fromCenter',
'fromFocus',
'fspline',
'functionshade',
'gamma',
'generate_random_backtrace',
'generateticks',
'gergonne',
'getc',
'getint',
'getpair',
'getreal',
'getstring',
'gettriple',
'gluon',
'gouraudshade',
'graph',
'graphic',
'gray',
'grestore',
'grid',
'grid3',
'gsave',
'halfbox',
'hatch',
'hdiffdiv',
'hermite',
'hex',
'histogram',
'history',
'hline',
'hprojection',
'hsv',
'hyperbola',
'hyperbolanodesnumber',
'hyperlink',
'hypot',
'identity',
'image',
'incenter',
'incentral',
'incircle',
'increasing',
'incrementposition',
'indexedTransform',
'indexedfigure',
'initXasyMode',
'initdefaults',
'input',
'inradius',
'insert',
'inside',
'integrate',
'interactive',
'interior',
'interp',
'interpolate',
'intersect',
'intersection',
'intersectionpoint',
'intersectionpoints',
'intersections',
'intouch',
'inverse',
'inversion',
'invisible',
'is3D',
'isDuplicate',
'isogonal',
'isogonalconjugate',
'isotomic',
'isotomicconjugate',
'isparabola',
'italic',
'item',
'key',
'kurtosis',
'kurtosisexcess',
'label',
'labelaxis',
'labelmargin',
'labelpath',
'labels',
'labeltick',
'labelx',
'labelx3',
'labely',
'labely3',
'labelz',
'labelz3',
'lastcut',
'latex',
'latitude',
'latticeshade',
'layer',
'layout',
'ldexp',
'leastsquares',
'legend',
'legenditem',
'length',
'lift',
'light',
'limits',
'line',
'linear',
'linecap',
'lineinversion',
'linejoin',
'linemargin',
'lineskip',
'linetype',
'linewidth',
'link',
'list',
'lm_enorm',
'lm_evaluate_default',
'lm_lmdif',
'lm_lmpar',
'lm_minimize',
'lm_print_default',
'lm_print_quiet',
'lm_qrfac',
'lm_qrsolv',
'locale',
'locate',
'locatefile',
'location',
'log',
'log10',
'log1p',
'logaxiscoverage',
'longitude',
'lookup',
'magnetize',
'makeNode',
'makedraw',
'makepen',
'map',
'margin',
'markangle',
'markangleradius',
'markanglespace',
'markarc',
'marker',
'markinterval',
'marknodes',
'markrightangle',
'markuniform',
'mass',
'masscenter',
'massformat',
'math',
'max',
'max3',
'maxbezier',
'maxbound',
'maxcoords',
'maxlength',
'maxratio',
'maxtimes',
'mean',
'medial',
'median',
'midpoint',
'min',
'min3',
'minbezier',
'minbound',
'minipage',
'minratio',
'mintimes',
'miterlimit',
'momArrowPath',
'momarrowsize',
'monotonic',
'multifigure',
'nativeformat',
'natural',
'needshipout',
'newl',
'newpage',
'newslide',
'newton',
'newtree',
'nextframe',
'nextnormal',
'nextpage',
'nib',
'nodabscissa',
'none',
'norm',
'normalvideo',
'notaknot',
'nowarn',
'numberpage',
'nurb',
'object',
'offset',
'onpath',
'opacity',
'opposite',
'orientation',
'orig_circlenodesnumber',
'orig_circlenodesnumber1',
'orig_draw',
'orig_ellipsenodesnumber',
'orig_ellipsenodesnumber1',
'orig_hyperbolanodesnumber',
'orig_parabolanodesnumber',
'origin',
'orthic',
'orthocentercenter',
'outformat',
'outline',
'outprefix',
'output',
'overloadedMessage',
'overwrite',
'pack',
'pad',
'pairs',
'palette',
'parabola',
'parabolanodesnumber',
'parallel',
'partialsum',
'path',
'path3',
'pattern',
'pause',
'pdf',
'pedal',
'periodic',
'perp',
'perpendicular',
'perpendicularmark',
'phantom',
'phi1',
'phi2',
'phi3',
'photon',
'piecewisestraight',
'point',
'polar',
'polarconicroutine',
'polargraph',
'polygon',
'postcontrol',
'postscript',
'pow10',
'ppoint',
'prc',
'prc0',
'precision',
'precontrol',
'prepend',
'print_random_addresses',
'project',
'projection',
'purge',
'pwhermite',
'quadrant',
'quadraticroots',
'quantize',
'quarticroots',
'quotient',
'radialshade',
'radians',
'radicalcenter',
'radicalline',
'radius',
'rand',
'randompath',
'rd',
'readline',
'realmult',
'realquarticroots',
'rectangle',
'rectangular',
'rectify',
'reflect',
'relabscissa',
'relative',
'relativedistance',
'reldir',
'relpoint',
'reltime',
'remainder',
'remark',
'removeDuplicates',
'rename',
'replace',
'report',
'resetdefaultpen',
'restore',
'restoredefaults',
'reverse',
'reversevideo',
'rf',
'rfind',
'rgb',
'rgba',
'rgbint',
'rms',
'rotate',
'rotateO',
'rotation',
'round',
'roundbox',
'roundedpath',
'roundrectangle',
'samecoordsys',
'sameside',
'sample',
'save',
'savedefaults',
'saveline',
'scale',
'scale3',
'scaleO',
'scaleT',
'scaleless',
'scientific',
'search',
'searchtree',
'sec',
'secondaryX',
'secondaryY',
'seconds',
'section',
'sector',
'seek',
'seekeof',
'segment',
'sequence',
'setpens',
'sgn',
'sgnd',
'sharpangle',
'sharpdegrees',
'shift',
'shiftless',
'shipout',
'shipout3',
'show',
'side',
'simeq',
'simpson',
'sin',
'single',
'sinh',
'size',
'size3',
'skewness',
'skip',
'slant',
'sleep',
'slope',
'slopefield',
'solve',
'solveBVP',
'sort',
'sourceline',
'sphere',
'split',
'sqrt',
'square',
'srand',
'standardizecoordsys',
'startScript',
'startTrembling',
'stdev',
'step',
'stickframe',
'stickmarksize',
'stickmarkspace',
'stop',
'straight',
'straightness',
'string',
'stripdirectory',
'stripextension',
'stripfile',
'strokepath',
'subdivide',
'subitem',
'subpath',
'substr',
'sum',
'surface',
'symmedial',
'symmedian',
'system',
'tab',
'tableau',
'tan',
'tangent',
'tangential',
'tangents',
'tanh',
'tell',
'tensionSpecifier',
'tensorshade',
'tex',
'texcolor',
'texify',
'texpath',
'texpreamble',
'texreset',
'texshipout',
'texsize',
'textpath',
'thick',
'thin',
'tick',
'tickMax',
'tickMax3',
'tickMin',
'tickMin3',
'ticklabelshift',
'ticklocate',
'tildeframe',
'tildemarksize',
'tile',
'tiling',
'time',
'times',
'title',
'titlepage',
'topbox',
'transform',
'transformation',
'transpose',
'tremble',
'trembleFuzz',
'tremble_circlenodesnumber',
'tremble_circlenodesnumber1',
'tremble_draw',
'tremble_ellipsenodesnumber',
'tremble_ellipsenodesnumber1',
'tremble_hyperbolanodesnumber',
'tremble_marknodes',
'tremble_markuniform',
'tremble_parabolanodesnumber',
'triangle',
'triangleAbc',
'triangleabc',
'triangulate',
'tricoef',
'tridiagonal',
'trilinear',
'trim',
'trueMagnetize',
'truepoint',
'tube',
'uncycle',
'unfill',
'uniform',
'unit',
'unitrand',
'unitsize',
'unityroot',
'unstraighten',
'upcase',
'updatefunction',
'uperiodic',
'upscale',
'uptodate',
'usepackage',
'usersetting',
'usetypescript',
'usleep',
'value',
'variance',
'variancebiased',
'vbox',
'vector',
'vectorfield',
'verbatim',
'view',
'vline',
'vperiodic',
'vprojection',
'warn',
'warning',
'windingnumber',
'write',
'xaxis',
'xaxis3',
'xaxis3At',
'xaxisAt',
'xequals',
'xinput',
'xlimits',
'xoutput',
'xpart',
'xscale',
'xscaleO',
'xtick',
'xtick3',
'xtrans',
'yaxis',
'yaxis3',
'yaxis3At',
'yaxisAt',
'yequals',
'ylimits',
'ypart',
'yscale',
'yscaleO',
'ytick',
'ytick3',
'ytrans',
'zaxis3',
'zaxis3At',
'zero',
'zero3',
'zlimits',
'zpart',
'ztick',
'ztick3',
'ztrans'
])
ASYVARNAME = set([
'AliceBlue',
'Align',
'Allow',
'AntiqueWhite',
'Apricot',
'Aqua',
'Aquamarine',
'Aspect',
'Azure',
'BeginPoint',
'Beige',
'Bisque',
'Bittersweet',
'Black',
'BlanchedAlmond',
'Blue',
'BlueGreen',
'BlueViolet',
'Both',
'Break',
'BrickRed',
'Brown',
'BurlyWood',
'BurntOrange',
'CCW',
'CW',
'CadetBlue',
'CarnationPink',
'Center',
'Centered',
'Cerulean',
'Chartreuse',
'Chocolate',
'Coeff',
'Coral',
'CornflowerBlue',
'Cornsilk',
'Crimson',
'Crop',
'Cyan',
'Dandelion',
'DarkBlue',
'DarkCyan',
'DarkGoldenrod',
'DarkGray',
'DarkGreen',
'DarkKhaki',
'DarkMagenta',
'DarkOliveGreen',
'DarkOrange',
'DarkOrchid',
'DarkRed',
'DarkSalmon',
'DarkSeaGreen',
'DarkSlateBlue',
'DarkSlateGray',
'DarkTurquoise',
'DarkViolet',
'DeepPink',
'DeepSkyBlue',
'DefaultHead',
'DimGray',
'DodgerBlue',
'Dotted',
'Draw',
'E',
'ENE',
'EPS',
'ESE',
'E_Euler',
'E_PC',
'E_RK2',
'E_RK3BS',
'Emerald',
'EndPoint',
'Euler',
'Fill',
'FillDraw',
'FireBrick',
'FloralWhite',
'ForestGreen',
'Fuchsia',
'Gainsboro',
'GhostWhite',
'Gold',
'Goldenrod',
'Gray',
'Green',
'GreenYellow',
'Honeydew',
'HookHead',
'Horizontal',
'HotPink',
'I',
'IgnoreAspect',
'IndianRed',
'Indigo',
'Ivory',
'JOIN_IN',
'JOIN_OUT',
'JungleGreen',
'Khaki',
'LM_DWARF',
'LM_MACHEP',
'LM_SQRT_DWARF',
'LM_SQRT_GIANT',
'LM_USERTOL',
'Label',
'Lavender',
'LavenderBlush',
'LawnGreen',
'LeftJustified',
'LeftSide',
'LemonChiffon',
'LightBlue',
'LightCoral',
'LightCyan',
'LightGoldenrodYellow',
'LightGreen',
'LightGrey',
'LightPink',
'LightSalmon',
'LightSeaGreen',
'LightSkyBlue',
'LightSlateGray',
'LightSteelBlue',
'LightYellow',
'Lime',
'LimeGreen',
'Linear',
'Linen',
'Log',
'Logarithmic',
'Magenta',
'Mahogany',
'Mark',
'MarkFill',
'Maroon',
'Max',
'MediumAquamarine',
'MediumBlue',
'MediumOrchid',
'MediumPurple',
'MediumSeaGreen',
'MediumSlateBlue',
'MediumSpringGreen',
'MediumTurquoise',
'MediumVioletRed',
'Melon',
'MidPoint',
'MidnightBlue',
'Min',
'MintCream',
'MistyRose',
'Moccasin',
'Move',
'MoveQuiet',
'Mulberry',
'N',
'NE',
'NNE',
'NNW',
'NW',
'NavajoWhite',
'Navy',
'NavyBlue',
'NoAlign',
'NoCrop',
'NoFill',
'NoSide',
'OldLace',
'Olive',
'OliveDrab',
'OliveGreen',
'Orange',
'OrangeRed',
'Orchid',
'Ox',
'Oy',
'PC',
'PaleGoldenrod',
'PaleGreen',
'PaleTurquoise',
'PaleVioletRed',
'PapayaWhip',
'Peach',
'PeachPuff',
'Periwinkle',
'Peru',
'PineGreen',
'Pink',
'Plum',
'PowderBlue',
'ProcessBlue',
'Purple',
'RK2',
'RK3',
'RK3BS',
'RK4',
'RK5',
'RK5DP',
'RK5F',
'RawSienna',
'Red',
'RedOrange',
'RedViolet',
'Rhodamine',
'RightJustified',
'RightSide',
'RosyBrown',
'RoyalBlue',
'RoyalPurple',
'RubineRed',
'S',
'SE',
'SSE',
'SSW',
'SW',
'SaddleBrown',
'Salmon',
'SandyBrown',
'SeaGreen',
'Seashell',
'Sepia',
'Sienna',
'Silver',
'SimpleHead',
'SkyBlue',
'SlateBlue',
'SlateGray',
'Snow',
'SpringGreen',
'SteelBlue',
'Suppress',
'SuppressQuiet',
'Tan',
'TeXHead',
'Teal',
'TealBlue',
'Thistle',
'Ticksize',
'Tomato',
'Turquoise',
'UnFill',
'VERSION',
'Value',
'Vertical',
'Violet',
'VioletRed',
'W',
'WNW',
'WSW',
'Wheat',
'White',
'WhiteSmoke',
'WildStrawberry',
'XYAlign',
'YAlign',
'Yellow',
'YellowGreen',
'YellowOrange',
'addpenarc',
'addpenline',
'align',
'allowstepping',
'angularsystem',
'animationdelay',
'appendsuffix',
'arcarrowangle',
'arcarrowfactor',
'arrow2sizelimit',
'arrowangle',
'arrowbarb',
'arrowdir',
'arrowfactor',
'arrowhookfactor',
'arrowlength',
'arrowsizelimit',
'arrowtexfactor',
'authorpen',
'axis',
'axiscoverage',
'axislabelfactor',
'background',
'backgroundcolor',
'backgroundpen',
'barfactor',
'barmarksizefactor',
'basealign',
'baselinetemplate',
'beveljoin',
'bigvertexpen',
'bigvertexsize',
'black',
'blue',
'bm',
'bottom',
'bp',
'brown',
'bullet',
'byfoci',
'byvertices',
'camerafactor',
'chartreuse',
'circlemarkradiusfactor',
'circlenodesnumberfactor',
'circleprecision',
'circlescale',
'cm',
'codefile',
'codepen',
'codeskip',
'colorPen',
'coloredNodes',
'coloredSegments',
'conditionlength',
'conicnodesfactor',
'count',
'cputimeformat',
'crossmarksizefactor',
'currentcoordsys',
'currentlight',
'currentpatterns',
'currentpen',
'currentpicture',
'currentposition',
'currentprojection',
'curvilinearsystem',
'cuttings',
'cyan',
'darkblue',
'darkbrown',
'darkcyan',
'darkgray',
'darkgreen',
'darkgrey',
'darkmagenta',
'darkolive',
'darkred',
'dashdotted',
'dashed',
'datepen',
'dateskip',
'debuggerlines',
'debugging',
'deepblue',
'deepcyan',
'deepgray',
'deepgreen',
'deepgrey',
'deepmagenta',
'deepred',
'default',
'defaultControl',
'defaultS',
'defaultbackpen',
'defaultcoordsys',
'defaultfilename',
'defaultformat',
'defaultmassformat',
'defaultpen',
'diagnostics',
'differentlengths',
'dot',
'dotfactor',
'dotframe',
'dotted',
'doublelinepen',
'doublelinespacing',
'down',
'duplicateFuzz',
'ellipsenodesnumberfactor',
'eps',
'epsgeo',
'epsilon',
'evenodd',
'extendcap',
'fermionpen',
'figureborder',
'figuremattpen',
'firstnode',
'firststep',
'foregroundcolor',
'fuchsia',
'fuzz',
'gapfactor',
'ghostpen',
'gluonamplitude',
'gluonpen',
'gluonratio',
'gray',
'green',
'grey',
'hatchepsilon',
'havepagenumber',
'heavyblue',
'heavycyan',
'heavygray',
'heavygreen',
'heavygrey',
'heavymagenta',
'heavyred',
'hline',
'hwratio',
'hyperbolanodesnumberfactor',
'identity4',
'ignore',
'inXasyMode',
'inch',
'inches',
'includegraphicscommand',
'inf',
'infinity',
'institutionpen',
'intMax',
'intMin',
'invert',
'invisible',
'itempen',
'itemskip',
'itemstep',
'labelmargin',
'landscape',
'lastnode',
'left',
'legendhskip',
'legendlinelength',
'legendmargin',
'legendmarkersize',
'legendmaxrelativewidth',
'legendvskip',
'lightblue',
'lightcyan',
'lightgray',
'lightgreen',
'lightgrey',
'lightmagenta',
'lightolive',
'lightred',
'lightyellow',
'linemargin',
'lm_infmsg',
'lm_shortmsg',
'longdashdotted',
'longdashed',
'magenta',
'magneticPoints',
'magneticRadius',
'mantissaBits',
'markangleradius',
'markangleradiusfactor',
'markanglespace',
'markanglespacefactor',
'mediumblue',
'mediumcyan',
'mediumgray',
'mediumgreen',
'mediumgrey',
'mediummagenta',
'mediumred',
'mediumyellow',
'middle',
'minDistDefault',
'minblockheight',
'minblockwidth',
'mincirclediameter',
'minipagemargin',
'minipagewidth',
'minvertexangle',
'miterjoin',
'mm',
'momarrowfactor',
'momarrowlength',
'momarrowmargin',
'momarrowoffset',
'momarrowpen',
'monoPen',
'morepoints',
'nCircle',
'newbulletcolor',
'ngraph',
'nil',
'nmesh',
'nobasealign',
'nodeMarginDefault',
'nodesystem',
'nomarker',
'nopoint',
'noprimary',
'nullpath',
'nullpen',
'numarray',
'ocgindex',
'oldbulletcolor',
'olive',
'orange',
'origin',
'overpaint',
'page',
'pageheight',
'pagemargin',
'pagenumberalign',
'pagenumberpen',
'pagenumberposition',
'pagewidth',
'paleblue',
'palecyan',
'palegray',
'palegreen',
'palegrey',
'palemagenta',
'palered',
'paleyellow',
'parabolanodesnumberfactor',
'perpfactor',
'phi',
'photonamplitude',
'photonpen',
'photonratio',
'pi',
'pink',
'plain',
'plus',
'preamblenodes',
'pt',
'purple',
'r3',
'r4a',
'r4b',
'randMax',
'realDigits',
'realEpsilon',
'realMax',
'realMin',
'red',
'relativesystem',
'reverse',
'right',
'roundcap',
'roundjoin',
'royalblue',
'salmon',
'saveFunctions',
'scalarpen',
'sequencereal',
'settings',
'shipped',
'signedtrailingzero',
'solid',
'springgreen',
'sqrtEpsilon',
'squarecap',
'squarepen',
'startposition',
'stdin',
'stdout',
'stepfactor',
'stepfraction',
'steppagenumberpen',
'stepping',
'stickframe',
'stickmarksizefactor',
'stickmarkspacefactor',
'textpen',
'ticksize',
'tildeframe',
'tildemarksizefactor',
'tinv',
'titlealign',
'titlepagepen',
'titlepageposition',
'titlepen',
'titleskip',
'top',
'trailingzero',
'treeLevelStep',
'treeMinNodeWidth',
'treeNodeStep',
'trembleAngle',
'trembleFrequency',
'trembleRandom',
'tremblingMode',
'undefined',
'unitcircle',
'unitsquare',
'up',
'urlpen',
'urlskip',
'version',
'vertexpen',
'vertexsize',
'viewportmargin',
'viewportsize',
'vline',
'white',
'wye',
'xformStack',
'yellow',
'ylabelwidth',
'zerotickfuzz',
'zerowinding'
])
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
5660,
10372,
272,
18294,
22935,
339,
961,
570,
3509,
314,
465,
89,
13,
1593,
1561,
436,
465,
89,
13,
1975,
1561,
402,
272,
437,
1786,
311,
475,
266,
14,
339,
4226,
440,
5283,
314,
4319,
57,
19587,
2339,
436,
4319,
57,
5568,
2339,
5951,
701,
4926,
14,
272,
3254,
26,
1126,
76,
15,
1548,
2884,
315,
437,
1786,
311,
475,
266,
24639,
8545,
370,
465,
89,
13,
513,
14,
1168,
1325,
1454,
272,
367,
805,
436,
1750,
1561,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
26222,
19587,
2339,
275,
663,
779,
272,
283,
3649,
297,
272,
283,
27604,
297,
272,
283,
27604,
17234,
297,
272,
283,
27604,
1596,
3838,
297,
272,
283,
17234,
297,
272,
283,
1596,
3838,
297,
272,
283,
3358,
3889,
297,
272,
283,
6651,
867,
39,
285,
271,
297,
272,
283,
34,
3532,
297,
272,
283,
18344,
1537,
262,
22856,
297,
272,
283,
18344,
1537,
262,
22856,
18,
297,
272,
283,
5281,
297,
272,
283,
34,
4291,
297,
272,
283,
5595,
27604,
17234,
297,
272,
283,
5595,
17234,
297,
272,
283,
5595,
5281,
297,
272,
283,
5595,
14004,
15182,
297,
272,
283,
5595,
15182,
297,
272,
283,
5595,
15597,
15182,
297,
272,
283,
28083,
297,
272,
283,
8696,
1237,
297,
272,
283,
22886,
297,
272,
283,
22886,
6105,
297,
272,
283,
23557,
297,
272,
283,
13948,
297,
272,
283,
30509,
297,
272,
283,
30509,
2445,
297,
272,
283,
24417,
382,
297,
272,
283,
24587,
297,
272,
283,
24587,
5281,
8227,
12825,
297,
272,
283,
26253,
297,
272,
283,
35,
567,
4446,
297,
272,
283,
14072,
8227,
12825,
297,
272,
283,
2698,
3484,
297,
272,
283,
2698,
2445,
3484,
297,
272,
283,
26135,
5710,
297,
272,
283,
3567,
297,
272,
283,
14004,
15182,
297,
272,
283,
14004,
15182,
83,
297,
272,
283,
14004,
471,
297,
272,
283,
9654,
297,
272,
283,
9654,
604,
297,
272,
283,
13200,
297,
272,
283,
3005,
27604,
17234,
297,
272,
283,
3005,
17234,
297,
272,
283,
3005,
5281,
297,
272,
283,
3005,
14004,
15182,
297,
272,
283,
3005,
15182,
297,
272,
283,
3005,
15597,
15182,
297,
272,
283,
12914,
297,
272,
283,
12914,
9654,
297,
272,
283,
38,
6367,
297,
272,
283,
3484,
297,
272,
283,
9042,
297,
272,
283,
26756,
297,
272,
283,
39,
23822,
3759,
297,
272,
283,
39,
23822,
3759,
3852,
297,
272,
283,
9942,
297,
272,
283,
39,
803,
3467,
297,
272,
283,
40,
25911,
297,
272,
283,
40,
281,
19130,
297,
272,
283,
8481,
11664,
297,
272,
283,
607,
2204,
26441,
297,
272,
283,
607,
26441,
297,
272,
283,
42,
297,
272,
283,
4314,
297,
272,
283,
44,
460,
3588,
297,
272,
283,
8185,
297,
272,
283,
8185,
9121,
297,
272,
283,
8185,
26441,
297,
272,
283,
23439,
297,
272,
283,
10608,
297,
272,
283,
3834,
297,
272,
283,
2445,
297,
272,
283,
2445,
3484,
297,
272,
283,
15182,
297,
272,
283,
15182,
83,
297,
272,
283,
6470,
297,
272,
283,
28735,
27604,
17234,
297,
272,
283,
28735,
17234,
297,
272,
283,
4609,
297,
272,
283,
4665,
22744,
18359,
51,
15089,
8696,
297,
272,
283,
1944,
3532,
297,
272,
283,
1944,
15182,
297,
272,
283,
1944,
23871,
297,
272,
283,
1944,
26441,
297,
272,
283,
1944,
26441,
19,
297,
272,
283,
1944,
8681,
297,
272,
283,
1944,
8681,
3484,
297,
272,
283,
403,
297,
272,
283,
726,
297,
272,
283,
47,
1147,
3484,
297,
272,
283,
47,
1147,
11763,
297,
272,
283,
2204,
26441,
297,
272,
283,
47,
88,
297,
272,
283,
47,
89,
297,
272,
283,
24666,
292,
10175,
297,
272,
283,
24500,
26441,
297,
272,
283,
15597,
297,
272,
283,
15597,
15182,
297,
272,
283,
15597,
15182,
83,
297,
272,
283,
15597,
466,
297,
272,
283,
4313,
29179,
297,
272,
283,
26647,
279,
23527,
271,
297,
272,
283,
1537,
262,
22856,
297,
272,
283,
4709,
297,
272,
283,
15277,
297,
272,
283,
9121,
297,
272,
283,
9121,
26441,
297,
272,
283,
32638,
297,
272,
283,
18579,
297,
272,
283,
18445,
50,
297,
272,
283,
9944,
297,
272,
283,
9944,
56,
297,
272,
283,
9944,
57,
297,
272,
283,
9944,
58,
297,
272,
283,
1513,
305,
696,
321,
297,
272,
283,
14379,
297,
272,
283,
30840,
297,
272,
283,
11592,
867,
297,
272,
283,
27558,
297,
272,
283,
51,
8284,
8227,
12825,
297,
272,
283,
933,
345,
1070,
297,
272,
283,
8169,
297,
272,
283,
52,
290,
297,
272,
283,
12589,
2021,
297,
272,
283,
26441,
297,
272,
283,
26441,
19,
297,
272,
283,
52,
24446,
8227,
12825,
297,
272,
283,
17687,
50,
21604,
297,
272,
283,
6105,
297,
272,
283,
549,
15182,
297,
272,
283,
1358,
12914,
297,
272,
283,
1721,
2441,
3514,
297,
272,
283,
25663,
297,
272,
283,
56,
297,
272,
283,
56,
13317,
297,
272,
283,
56,
726,
297,
272,
283,
8195,
297,
272,
283,
8195,
13317,
297,
272,
283,
8195,
8681,
297,
272,
283,
8195,
3825,
297,
272,
283,
56,
58,
13317,
297,
272,
283,
56,
58,
8681,
297,
272,
283,
56,
8681,
297,
272,
283,
56,
58,
3825,
297,
272,
283,
57,
297,
272,
283,
57,
13317,
297,
272,
283,
16936,
3825,
297,
272,
283,
26184,
297,
272,
283,
26184,
13317,
297,
272,
283,
26184,
8681,
297,
272,
283,
57,
8681,
297,
272,
283,
26184,
3825,
297,
272,
283,
58,
297,
272,
283,
15473,
297,
272,
283,
15473,
3825,
297,
272,
283,
58,
57,
3825,
297,
272,
283,
58,
439,
70,
1049,
18595,
994,
297,
272,
283,
58,
439,
70,
36,
316,
66,
1956,
297,
272,
2513,
3541,
521,
297,
272,
2513,
5485,
297,
272,
2513,
2579,
297,
272,
2513,
1569,
297,
272,
2513,
1302,
515,
297,
272,
2513,
16539,
297,
272,
2513,
11473,
515,
297,
272,
2513,
3858,
515,
297,
272,
283,
65,
26253,
297,
272,
283,
65,
30840,
297,
272,
283,
65,
52,
290,
297,
272,
283,
13845,
297,
272,
283,
2101,
297,
272,
283,
645,
6067,
297,
272,
283,
65,
5197,
297,
272,
283,
13286,
609,
297,
272,
283,
13286,
84,
297
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
5660,
10372,
272,
18294,
22935,
339,
961,
570,
3509,
314,
465,
89,
13,
1593,
1561,
436,
465,
89,
13,
1975,
1561,
402,
272,
437,
1786,
311,
475,
266,
14,
339,
4226,
440,
5283,
314,
4319,
57,
19587,
2339,
436,
4319,
57,
5568,
2339,
5951,
701,
4926,
14,
272,
3254,
26,
1126,
76,
15,
1548,
2884,
315,
437,
1786,
311,
475,
266,
24639,
8545,
370,
465,
89,
13,
513,
14,
1168,
1325,
1454,
272,
367,
805,
436,
1750,
1561,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
26222,
19587,
2339,
275,
663,
779,
272,
283,
3649,
297,
272,
283,
27604,
297,
272,
283,
27604,
17234,
297,
272,
283,
27604,
1596,
3838,
297,
272,
283,
17234,
297,
272,
283,
1596,
3838,
297,
272,
283,
3358,
3889,
297,
272,
283,
6651,
867,
39,
285,
271,
297,
272,
283,
34,
3532,
297,
272,
283,
18344,
1537,
262,
22856,
297,
272,
283,
18344,
1537,
262,
22856,
18,
297,
272,
283,
5281,
297,
272,
283,
34,
4291,
297,
272,
283,
5595,
27604,
17234,
297,
272,
283,
5595,
17234,
297,
272,
283,
5595,
5281,
297,
272,
283,
5595,
14004,
15182,
297,
272,
283,
5595,
15182,
297,
272,
283,
5595,
15597,
15182,
297,
272,
283,
28083,
297,
272,
283,
8696,
1237,
297,
272,
283,
22886,
297,
272,
283,
22886,
6105,
297,
272,
283,
23557,
297,
272,
283,
13948,
297,
272,
283,
30509,
297,
272,
283,
30509,
2445,
297,
272,
283,
24417,
382,
297,
272,
283,
24587,
297,
272,
283,
24587,
5281,
8227,
12825,
297,
272,
283,
26253,
297,
272,
283,
35,
567,
4446,
297,
272,
283,
14072,
8227,
12825,
297,
272,
283,
2698,
3484,
297,
272,
283,
2698,
2445,
3484,
297,
272,
283,
26135,
5710,
297,
272,
283,
3567,
297,
272,
283,
14004,
15182,
297,
272,
283,
14004,
15182,
83,
297,
272,
283,
14004,
471,
297,
272,
283,
9654,
297,
272,
283,
9654,
604,
297,
272,
283,
13200,
297,
272,
283,
3005,
27604,
17234,
297,
272,
283,
3005,
17234,
297,
272,
283,
3005,
5281,
297,
272,
283,
3005,
14004,
15182,
297,
272,
283,
3005,
15182,
297,
272,
283,
3005,
15597,
15182,
297,
272,
283,
12914,
297,
272,
283,
12914,
9654,
297,
272,
283,
38,
6367,
297,
272,
283,
3484,
297,
272,
283,
9042,
297,
272,
283,
26756,
297,
272,
283,
39,
23822,
3759,
297,
272,
283,
39,
23822,
3759,
3852,
297,
272,
283,
9942,
297,
272,
283,
39,
803,
3467,
297,
272,
283,
40,
25911,
297,
272,
283,
40,
281,
19130,
297,
272,
283,
8481,
11664,
297,
272,
283,
607,
2204,
26441,
297,
272,
283,
607,
26441,
297,
272,
283,
42,
297,
272,
283,
4314,
297,
272,
283,
44,
460,
3588,
297,
272,
283,
8185,
297,
272,
283,
8185,
9121,
297,
272,
283,
8185,
26441,
297,
272,
283,
23439,
297,
272,
283,
10608,
297,
272,
283,
3834,
297,
272,
283,
2445,
297,
272,
283,
2445,
3484,
297,
272,
283,
15182,
297,
272,
283,
15182,
83,
297,
272,
283,
6470,
297,
272,
283,
28735,
27604,
17234,
297,
272,
283,
28735,
17234,
297,
272,
283,
4609,
297,
272,
283,
4665,
22744,
18359,
51,
15089,
8696,
297,
272,
283,
1944,
3532,
297,
272,
283,
1944,
15182,
297,
272,
283,
1944,
23871,
297,
272,
283,
1944,
26441,
297,
272,
283,
1944,
26441,
19,
297,
272,
283,
1944,
8681,
297,
272,
283,
1944,
8681,
3484,
297,
272,
283,
403,
297,
272,
283,
726,
297,
272,
283,
47,
1147,
3484,
297,
272,
283,
47,
1147,
11763,
297,
272,
283,
2204,
26441,
297,
272,
283,
47,
88,
297,
272,
283,
47,
89,
297,
272,
283,
24666,
292,
10175,
297,
272,
283,
24500,
26441,
297,
272,
283,
15597,
297,
272,
283,
15597,
15182,
297,
272,
283,
15597,
15182,
83,
297,
272,
283,
15597,
466,
297,
272,
283,
4313,
29179,
297,
272,
283,
26647,
279,
23527,
271,
297,
272,
283,
1537,
262,
22856,
297,
272,
283,
4709,
297,
272,
283,
15277,
297,
272,
283,
9121,
297,
272,
283,
9121,
26441,
297,
272,
283,
32638,
297,
272,
283,
18579,
297,
272,
283,
18445,
50,
297,
272,
283,
9944,
297,
272,
283,
9944,
56,
297,
272,
283,
9944,
57,
297,
272,
283,
9944,
58,
297,
272,
283,
1513,
305,
696,
321,
297,
272,
283,
14379,
297,
272,
283,
30840,
297,
272,
283,
11592,
867,
297,
272,
283,
27558,
297,
272,
283,
51,
8284,
8227,
12825,
297,
272,
283,
933,
345,
1070,
297,
272,
283,
8169,
297,
272,
283,
52,
290,
297,
272,
283,
12589,
2021,
297,
272,
283,
26441,
297,
272,
283,
26441,
19,
297,
272,
283,
52,
24446,
8227,
12825,
297,
272,
283,
17687,
50,
21604,
297,
272,
283,
6105,
297,
272,
283,
549,
15182,
297,
272,
283,
1358,
12914,
297,
272,
283,
1721,
2441,
3514,
297,
272,
283,
25663,
297,
272,
283,
56,
297,
272,
283,
56,
13317,
297,
272,
283,
56,
726,
297,
272,
283,
8195,
297,
272,
283,
8195,
13317,
297,
272,
283,
8195,
8681,
297,
272,
283,
8195,
3825,
297,
272,
283,
56,
58,
13317,
297,
272,
283,
56,
58,
8681,
297,
272,
283,
56,
8681,
297,
272,
283,
56,
58,
3825,
297,
272,
283,
57,
297,
272,
283,
57,
13317,
297,
272,
283,
16936,
3825,
297,
272,
283,
26184,
297,
272,
283,
26184,
13317,
297,
272,
283,
26184,
8681,
297,
272,
283,
57,
8681,
297,
272,
283,
26184,
3825,
297,
272,
283,
58,
297,
272,
283,
15473,
297,
272,
283,
15473,
3825,
297,
272,
283,
58,
57,
3825,
297,
272,
283,
58,
439,
70,
1049,
18595,
994,
297,
272,
283,
58,
439,
70,
36,
316,
66,
1956,
297,
272,
2513,
3541,
521,
297,
272,
2513,
5485,
297,
272,
2513,
2579,
297,
272,
2513,
1569,
297,
272,
2513,
1302,
515,
297,
272,
2513,
16539,
297,
272,
2513,
11473,
515,
297,
272,
2513,
3858,
515,
297,
272,
283,
65,
26253,
297,
272,
283,
65,
30840,
297,
272,
283,
65,
52,
290,
297,
272,
283,
13845,
297,
272,
283,
2101,
297,
272,
283,
645,
6067,
297,
272,
283,
65,
5197,
297,
272,
283,
13286,
609,
297,
272,
283,
13286,
84,
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,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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
] |
hagurinLv1/huis-ui-creator
|
docs/generator/code_converter.py
|
3
|
5493
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/python
#
# doxy_preprocess.py
#
# creator: kan.k
# created: [2013-12-06 18:18:06+09:00]
# modified: [2013-12-10 19:29:12+09:00]
# description:
# Converting function notation.
# This is just easy made script to generate doc with less effort.
# 少ない手数で、ドキュメントを作ろうとするための簡易スクリプト。
#
import sys
import optparse
import os
class PlainDescriptionHelpFormatter(optparse.IndentedHelpFormatter):
def format_description(self, description):
if description:
if self.parser is not None:
return self.parser.expand_prog_name(description.strip()) + "\n"
else:
return description.strip() + "\n"
# return self._format_text(description) + "\n"
else:
return ""
parser = optparse.OptionParser(
formatter=PlainDescriptionHelpFormatter(),
usage="usage: %prog [options]",
description="""
Converting code.
""",
epilog=None
)
###################################
## Common arguments
###################################
parser.add_option(
"-v", "--verbose",
action='store_true',
dest='verbose',
help="verbose mode."
)
###################################
## Argument Check and Mapping
###################################
(options, args) = parser.parse_args(sys.argv)
infilepath = None
if len(args) > 1:
infilepath = args[1]
##@}
######################################################################
## Domestic classes
######################################################################
##@{
##@}
######################################################################
## Domestic functions
######################################################################
##@{
##@}
######################################################################
## Main Part
######################################################################
##@{
import re
func_decl_re = re.compile(r"""^
(\s*
(?:private\s*)?
(?:static\s*)?
(?:(?:get|set)\s*)?
) # preseeding white
(?:function\s*)?
(
([a-zA-Z_\$][a-zA-Z0-9_]*) # function, method or parameter name.
\(
(?:
[^\(\)\;]*
\(
[^\(\)\;]*
\)
)* # Counting parens.
[^\(\)\;]*
\) # function parameters part
) # function name and params
(?:\s*\:\s*
([a-zA-Z_][a-zA-Z0-9_]*) # return param types.
)?
(\s*
(?:\{|;) # function paren or decration end.
.*\s*) # trailing
$""", re.VERBOSE)
member_decl_re = re.compile(r"""^
(\s*
(?:private\s*)?
(?:static\s*)?
(?:(?:get|set)\s*)?
) # preseeding white
(
([a-zA-Z_\$][a-zA-Z0-9_]*) # member, method or parameter name.
) # member name and params
(?:\s*\:\s*
([a-zA-Z_][a-zA-Z0-9_]*) # return param types.
)?
(\s*
; # member decration end.
.*\s*) # trailing
$""", re.VERBOSE)
func_decl_start_re = re.compile(r"""^
(\s*
(?:private\s*)?
(?:static\s*)?
(?:(?:get|set)\s*)?
) # preseeding white
(?:function\s*)?
([a-zA-Z_\$][a-zA-Z0-9_]*) # function name
\(.*
""", re.VERBOSE)
func_decl_cancel_re = re.compile(r"""^
\s+(?:[^\s]+\s+)*
(?:\}|;)
""", re.VERBOSE)
linetomatch = ''
reference_re = re.compile(r"""^
/
(
//\s*<reference
)
""", re.VERBOSE)
fhin = sys.stdin
if infilepath is not None:
fhin = open(infilepath, 'r')
line = fhin.readline()
while line != '':
# print "fetching: %s" % line
m = member_decl_re.match(line)
if m is not None:
ms = m.groups()
if ms[3] is not None:
sys.stdout.write(ms[0] + ms[3] + " " + ms[1] + ms[4])
else:
sys.stdout.write(line)
# print "as member %s" % repr(ms)
line = fhin.readline()
continue
m = func_decl_start_re.match(line)
if m is not None:
# print repr(m)
linetomatch = line
# print "hoga"
m = func_decl_re.match(linetomatch)
while m is None and line != '':
# print repr(m)
line = fhin.readline()
linetomatch += line
m = func_decl_re.match(linetomatch)
# print "start %s" % linetomatch
# if func_decl_cancel_re.search(linetomatch):
# print "start match"
if m is None and func_decl_cancel_re.match(linetomatch):
# print "end match"
# print "break"
break
# print "end match"
# print "end"
if m is not None:
ms = m.groups()
if ms[3] is not None:
sys.stdout.write(ms[0] + ms[3] + " " + ms[1] + ms[4])
else:
sys.stdout.write(linetomatch)
# print "as func"
else:
sys.stdout.write(linetomatch)
# print "as regular"
else:
m = reference_re.match(line)
if m is not None:
ms = m.groups()
sys.stdout.write(ms[0])
else:
sys.stdout.write(line)
# print "as regular"
line = fhin.readline()
fhin.close()
##@}
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
198,
1117,
1702,
63,
17677,
14,
647,
199,
3,
198,
199,
3,
198,
9986,
26,
198,
29305,
14,
75,
199,
3,
198,
3966,
26,
198,
59,
6965,
13,
713,
13,
1690,
6155,
26,
1085,
26,
1690,
11,
1643,
26,
383,
61,
199,
3,
198,
5540,
26,
198,
59,
6965,
13,
713,
13,
709,
5851,
26,
1398,
26,
713,
11,
1643,
26,
383,
61,
199,
3,
198,
1802,
26,
199,
3,
755,
23258,
805,
15843,
14,
199,
3,
755,
961,
365,
2951,
8837,
6326,
2884,
370,
3550,
1382,
543,
6656,
28058,
14,
199,
3,
755,
7094,
109,
240,
4197,
104,
20724,
10862,
234,
12211,
31221,
23709,
5692,
232,
5573,
256,
5692,
99,
5692,
95,
23488,
23869,
17593,
21927,
5573,
236,
28075,
29472,
24549,
25871,
4197,
254,
5573,
224,
14741,
164,
109,
95,
13132,
25111,
5573,
108,
5692,
104,
5692,
246,
23869,
20061,
199,
3,
198,
199,
199,
646,
984,
199,
646,
8691,
199,
646,
747,
199,
199,
533,
510,
3993,
5831,
22779,
8,
2992,
1122,
14,
607,
14032,
22779,
304,
272,
347,
1475,
63,
1802,
8,
277,
12,
1369,
304,
267,
340,
1369,
26,
288,
340,
291,
14,
2087,
365,
440,
488,
26,
355,
372,
291,
14,
2087,
14,
4441,
63,
6595,
63,
354,
8,
1802,
14,
1913,
1012,
435,
1867,
78,
2,
288,
587,
26,
355,
372,
1369,
14,
1913,
342,
435,
1867,
78,
2,
288,
327,
372,
291,
423,
908,
63,
505,
8,
1802,
9,
435,
1867,
78,
2,
267,
587,
26,
288,
372,
3087,
199,
199,
2087,
275,
8691,
14,
14553,
8,
272,
9698,
29,
20711,
5831,
22779,
1062,
272,
4503,
628,
3807,
26,
450,
6595,
359,
1419,
11472,
272,
1369,
11916,
199,
7619,
1337,
1233,
14,
199,
7208,
272,
29850,
29,
403,
199,
9,
199,
199,
1371,
5680,
199,
309,
198,
7844,
2368,
199,
1371,
5680,
199,
199,
2087,
14,
525,
63,
1422,
8,
272,
3905,
86,
401,
4320,
3832,
401,
272,
1595,
534,
1617,
63,
2052,
297,
272,
2053,
534,
3832,
297,
272,
1720,
628,
3832,
818,
2122,
272,
776,
199,
199,
1371,
5680,
199,
309,
198,
5201,
2670,
436,
12340,
199,
1371,
5680,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
8,
1274,
14,
3020,
9,
199,
199,
262,
7218,
275,
488,
199,
692,
822,
8,
589,
9,
690,
413,
26,
272,
315,
7218,
275,
1249,
59,
17,
61,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
36,
1377,
11108,
3992,
199,
18022,
199,
309,
32,
91,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
36,
1377,
11108,
3423,
199,
18022,
199,
309,
32,
91,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
6756,
14320,
199,
18022,
199,
309,
32,
91,
199,
199,
646,
295,
199,
199,
1532,
63,
9427,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
199,
5169,
1593,
60,
83,
10,
5547,
199,
8,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
805,
12,
1083,
503,
2725,
536,
14,
523,
25445,
1362,
16697,
1362,
359,
12773,
2961,
2862,
27,
3672,
1362,
25445,
1362,
359,
12773,
2961,
2862,
27,
3672,
1362,
971,
9,
1362,
776,
10,
2476,
327,
14826,
316,
32029,
14,
1362,
359,
12773,
2961,
2862,
27,
3672,
523,
971,
9,
27503,
327,
805,
2633,
1777,
199,
9,
2476,
755,
327,
805,
536,
436,
1862,
523,
7558,
3427,
83,
7590,
3427,
83,
10,
272,
7287,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
3322,
327,
372,
1215,
2943,
14,
523,
24836,
199,
2961,
83,
10,
523,
7558,
3427,
91,
92,
27,
9,
19242,
327,
805,
13566,
503,
9700,
1754,
1284,
14,
199,
17910,
83,
13278,
22456,
327,
8520,
199,
4,
7208,
295,
14,
16075,
9,
199,
199,
1114,
63,
9427,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
8,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
3653,
12,
1083,
503,
2725,
536,
14,
199,
9,
2476,
755,
327,
3653,
536,
436,
1862,
523,
7558,
3427,
83,
7590,
3427,
83,
10,
272,
7287,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
3322,
327,
372,
1215,
2943,
14,
523,
24836,
199,
2961,
83,
10,
523,
8700,
32542,
327,
3653,
9700,
1754,
1284,
14,
199,
17910,
83,
13278,
22456,
327,
8520,
199,
4,
7208,
295,
14,
16075,
9,
421,
199,
1532,
63,
9427,
63,
928,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
5169,
1593,
60,
83,
10,
5547,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
805,
536,
523,
971,
19276,
199,
7208,
295,
14,
16075,
9,
421,
199,
1532,
63,
9427,
63,
6406,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
60,
83,
11,
5169,
16045,
83,
24621,
83,
11,
3342,
199,
15840,
22441,
27,
9,
199,
7208,
295,
14,
16075,
9,
199,
199,
472,
16876,
1431,
275,
2125,
199,
199,
4443,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
15,
199,
8,
523,
5001,
60,
83,
10,
28,
4443,
199,
9,
199,
7208,
295,
14,
16075,
9,
199,
199,
12853,
262,
275,
984
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
198,
1117,
1702,
63,
17677,
14,
647,
199,
3,
198,
199,
3,
198,
9986,
26,
198,
29305,
14,
75,
199,
3,
198,
3966,
26,
198,
59,
6965,
13,
713,
13,
1690,
6155,
26,
1085,
26,
1690,
11,
1643,
26,
383,
61,
199,
3,
198,
5540,
26,
198,
59,
6965,
13,
713,
13,
709,
5851,
26,
1398,
26,
713,
11,
1643,
26,
383,
61,
199,
3,
198,
1802,
26,
199,
3,
755,
23258,
805,
15843,
14,
199,
3,
755,
961,
365,
2951,
8837,
6326,
2884,
370,
3550,
1382,
543,
6656,
28058,
14,
199,
3,
755,
7094,
109,
240,
4197,
104,
20724,
10862,
234,
12211,
31221,
23709,
5692,
232,
5573,
256,
5692,
99,
5692,
95,
23488,
23869,
17593,
21927,
5573,
236,
28075,
29472,
24549,
25871,
4197,
254,
5573,
224,
14741,
164,
109,
95,
13132,
25111,
5573,
108,
5692,
104,
5692,
246,
23869,
20061,
199,
3,
198,
199,
199,
646,
984,
199,
646,
8691,
199,
646,
747,
199,
199,
533,
510,
3993,
5831,
22779,
8,
2992,
1122,
14,
607,
14032,
22779,
304,
272,
347,
1475,
63,
1802,
8,
277,
12,
1369,
304,
267,
340,
1369,
26,
288,
340,
291,
14,
2087,
365,
440,
488,
26,
355,
372,
291,
14,
2087,
14,
4441,
63,
6595,
63,
354,
8,
1802,
14,
1913,
1012,
435,
1867,
78,
2,
288,
587,
26,
355,
372,
1369,
14,
1913,
342,
435,
1867,
78,
2,
288,
327,
372,
291,
423,
908,
63,
505,
8,
1802,
9,
435,
1867,
78,
2,
267,
587,
26,
288,
372,
3087,
199,
199,
2087,
275,
8691,
14,
14553,
8,
272,
9698,
29,
20711,
5831,
22779,
1062,
272,
4503,
628,
3807,
26,
450,
6595,
359,
1419,
11472,
272,
1369,
11916,
199,
7619,
1337,
1233,
14,
199,
7208,
272,
29850,
29,
403,
199,
9,
199,
199,
1371,
5680,
199,
309,
198,
7844,
2368,
199,
1371,
5680,
199,
199,
2087,
14,
525,
63,
1422,
8,
272,
3905,
86,
401,
4320,
3832,
401,
272,
1595,
534,
1617,
63,
2052,
297,
272,
2053,
534,
3832,
297,
272,
1720,
628,
3832,
818,
2122,
272,
776,
199,
199,
1371,
5680,
199,
309,
198,
5201,
2670,
436,
12340,
199,
1371,
5680,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
8,
1274,
14,
3020,
9,
199,
199,
262,
7218,
275,
488,
199,
692,
822,
8,
589,
9,
690,
413,
26,
272,
315,
7218,
275,
1249,
59,
17,
61,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
36,
1377,
11108,
3992,
199,
18022,
199,
309,
32,
91,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
36,
1377,
11108,
3423,
199,
18022,
199,
309,
32,
91,
199,
199,
309,
32,
93,
421,
199,
18022,
199,
309,
198,
6756,
14320,
199,
18022,
199,
309,
32,
91,
199,
199,
646,
295,
199,
199,
1532,
63,
9427,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
199,
5169,
1593,
60,
83,
10,
5547,
199,
8,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
805,
12,
1083,
503,
2725,
536,
14,
523,
25445,
1362,
16697,
1362,
359,
12773,
2961,
2862,
27,
3672,
1362,
25445,
1362,
359,
12773,
2961,
2862,
27,
3672,
1362,
971,
9,
1362,
776,
10,
2476,
327,
14826,
316,
32029,
14,
1362,
359,
12773,
2961,
2862,
27,
3672,
523,
971,
9,
27503,
327,
805,
2633,
1777,
199,
9,
2476,
755,
327,
805,
536,
436,
1862,
523,
7558,
3427,
83,
7590,
3427,
83,
10,
272,
7287,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
3322,
327,
372,
1215,
2943,
14,
523,
24836,
199,
2961,
83,
10,
523,
7558,
3427,
91,
92,
27,
9,
19242,
327,
805,
13566,
503,
9700,
1754,
1284,
14,
199,
17910,
83,
13278,
22456,
327,
8520,
199,
4,
7208,
295,
14,
16075,
9,
199,
199,
1114,
63,
9427,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
8,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
3653,
12,
1083,
503,
2725,
536,
14,
199,
9,
2476,
755,
327,
3653,
536,
436,
1862,
523,
7558,
3427,
83,
7590,
3427,
83,
10,
272,
7287,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
3322,
327,
372,
1215,
2943,
14,
523,
24836,
199,
2961,
83,
10,
523,
8700,
32542,
327,
3653,
9700,
1754,
1284,
14,
199,
17910,
83,
13278,
22456,
327,
8520,
199,
4,
7208,
295,
14,
16075,
9,
421,
199,
1532,
63,
9427,
63,
928,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
2961,
83,
10,
199,
5169,
4239,
60,
83,
10,
5547,
199,
5169,
1986,
60,
83,
10,
5547,
199,
5169,
5169,
362,
92,
409,
2862,
83,
10,
5547,
199,
9,
15530,
327,
876,
5176,
316,
10424,
199,
5169,
1593,
60,
83,
10,
5547,
523,
7287,
65,
13,
6353,
13,
58,
18005,
4,
1527,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
9,
4519,
327,
805,
536,
523,
971,
19276,
199,
7208,
295,
14,
16075,
9,
421,
199,
1532,
63,
9427,
63,
6406,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
60,
83,
11,
5169,
16045,
83,
24621,
83,
11,
3342,
199,
15840,
22441,
27,
9,
199,
7208,
295,
14,
16075,
9,
199,
199,
472,
16876,
1431,
275,
2125,
199,
199,
4443,
63,
264,
275,
295,
14,
2014,
8,
82,
624,
62,
199,
15,
199,
8,
523,
5001,
60,
83,
10,
28,
4443,
199,
9,
199,
7208,
295,
14,
16075,
9,
199,
199,
12853,
262,
275,
984,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bqbn/addons-server
|
src/olympia/translations/tests/test_forms.py
|
8
|
4536
|
# -*- coding: utf-8 -*-
from django.forms import ModelForm
import pytest
from pyquery import PyQuery as pq
from olympia.amo.tests import TestCase
from olympia.translations import fields, forms
from olympia.translations.tests.testapp.models import TranslatedModel
class DummyForm(forms.TranslationFormMixin, ModelForm):
name = fields.TransField()
class Meta:
model = TranslatedModel
fields = '__all__'
class TestTranslationFormMixin(TestCase):
def test_default_locale(self):
obj = TranslatedModel()
obj.get_fallback = lambda: 'pl'
f = DummyForm(instance=obj)
assert f.fields['name'].default_locale == 'pl'
assert f.fields['name'].widget.default_locale == 'pl'
assert pq(f.as_p())('#id_name_0').attr('lang') == 'pl'
def test_error_display(self):
form = DummyForm(data={})
# Both name and default_locale should display errors as lists with no
# issues. Nothing about the underlying implementation should be shown
# (i.e., don't display an ugly [u'This field is required'] message).
# name is a translated field so data-lang is present.
expected = (
'<ul class="errorlist">'
'<li data-lang="en-us">This field is required.</li>'
'</ul>')
assert form.errors['name'].as_ul() == expected
# default_locale is a normal field so data-lang is absent.
expected = (
'<ul class="errorlist">'
'<li>This field is required.</li>'
'</ul>')
assert form.errors['default_locale'].as_ul() == expected
# When there are multiple errors, they should all be shown.
form.add_error('name', 'Error message about name')
form.add_error('default_locale', 'Error message about default_locale')
expected = (
'<ul class="errorlist">'
'<li data-lang="en-us">This field is required.</li>'
'<li>Error message about name</li>'
'</ul>')
assert form.errors['name'].as_ul() == expected
expected = (
'<ul class="errorlist">'
'<li>This field is required.</li>'
'<li>Error message about default_locale</li>'
'</ul>')
assert form.errors['default_locale'].as_ul() == expected
@pytest.mark.needs_locales_compilation
def test_error_display_with_unicode_chars(self):
# In french, the error message for required fields contain an accent.
# This used to break because some parts of the string we're building
# were str objects and not unicode.
with self.activate('fr'):
form = DummyForm(data={})
# Both name and default_locale should display errors as lists with
# no issues. Nothing about the underlying implementation should be
# shown (i.e., don't display an ugly [u'This field is required']
# message). name is a translated field so data-lang is present.
# Note that data-lang points to the language of the translation
# expected to be present, not the language of the message we're
# displaying to the user - that's why it's displaying a french
# message with a data-lang="en-us" attribute, it's not a bug.
expected = (
u'<ul class="errorlist">'
u'<li data-lang="en-us">Champ nécessaire.</li>'
u'</ul>')
assert form.errors['name'].as_ul() == expected
# default_locale is a normal field so data-lang is absent.
expected = (
u'<ul class="errorlist">'
u'<li>Champ nécessaire.</li>'
u'</ul>')
assert form.errors['default_locale'].as_ul() == expected
# When there are multiple errors, they should all be shown.
form.add_error('name', u'Errör about name')
form.add_error('default_locale', u'Errôr about default_locale')
expected = (
u'<ul class="errorlist">'
u'<li data-lang="en-us">Champ nécessaire.</li>'
u'<li>Errör about name</li>'
u'</ul>')
assert form.errors['name'].as_ul() == expected
expected = (
u'<ul class="errorlist">'
u'<li>Champ nécessaire.</li>'
u'<li>Errôr about default_locale</li>'
u'</ul>')
assert form.errors['default_locale'].as_ul() == expected
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
3351,
492,
28455,
199,
199,
646,
4613,
199,
504,
1134,
1131,
492,
1611,
3227,
465,
29158,
199,
199,
504,
312,
590,
311,
4674,
14,
4393,
14,
2219,
492,
7640,
199,
504,
312,
590,
311,
4674,
14,
13982,
492,
1504,
12,
4513,
199,
504,
312,
590,
311,
4674,
14,
13982,
14,
2219,
14,
19700,
14,
992,
492,
6266,
1776,
1685,
421,
199,
533,
9762,
2821,
8,
3351,
14,
18483,
2821,
4256,
12,
28455,
304,
272,
536,
275,
1504,
14,
3188,
792,
342,
339,
1021,
6288,
26,
267,
1402,
275,
6266,
1776,
1685,
267,
1504,
275,
2560,
452,
12217,
421,
199,
533,
1379,
18483,
2821,
4256,
8,
1746,
304,
339,
347,
511,
63,
885,
63,
5508,
8,
277,
304,
267,
1559,
275,
6266,
1776,
1685,
342,
267,
1559,
14,
362,
63,
10538,
275,
2400,
26,
283,
1168,
7,
398,
289,
275,
9762,
2821,
8,
842,
29,
1113,
9,
267,
702,
289,
14,
955,
459,
354,
2278,
885,
63,
5508,
508,
283,
1168,
7,
267,
702,
289,
14,
955,
459,
354,
2278,
3440,
14,
885,
63,
5508,
508,
283,
1168,
7,
267,
702,
29158,
8,
70,
14,
305,
63,
80,
1012,
7863,
344,
63,
354,
63,
16,
1959,
962,
360,
4159,
358,
508,
283,
1168,
7,
339,
347,
511,
63,
705,
63,
2918,
8,
277,
304,
267,
1824,
275,
9762,
2821,
8,
576,
21146,
267,
327,
17650,
536,
436,
849,
63,
5508,
1077,
2929,
2552,
465,
5548,
543,
949,
267,
327,
10876,
14,
20550,
3595,
314,
8793,
4514,
1077,
506,
9164,
267,
327,
334,
73,
14,
69,
2020,
2793,
1133,
2929,
376,
23761,
359,
85,
7,
2765,
901,
365,
1415,
418,
1245,
680,
267,
327,
536,
365,
282,
14598,
901,
880,
666,
13,
4159,
365,
3451,
14,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
267,
327,
849,
63,
5508,
365,
282,
3293,
901,
880,
666,
13,
4159,
365,
9552,
14,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
30,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
398,
327,
3979,
2337,
787,
3663,
2552,
12,
2985,
1077,
1006,
506,
9164,
14,
267,
1824,
14,
525,
63,
705,
360,
354,
297,
283,
547,
1245,
3595,
536,
358,
267,
1824,
14,
525,
63,
705,
360,
885,
63,
5508,
297,
283,
547,
1245,
3595,
849,
63,
5508,
358,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
2650,
317,
30,
547,
1245,
3595,
536,
1108,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
30,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
2650,
317,
30,
547,
1245,
3595,
849,
63,
5508,
1108,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
339,
768,
4462,
14,
1657,
14,
10065,
63,
24763,
63,
863,
13696,
272,
347,
511,
63,
705,
63,
2918,
63,
1045,
63,
2975,
63,
6574,
8,
277,
304,
267,
327,
1010,
289,
15148,
12,
314,
1125,
1245,
367,
1415,
1504,
1395,
376,
1066,
2946,
14,
267,
327,
961,
1202,
370,
2059,
2952,
2005,
4184,
402,
314,
1059,
781,
3984,
10015,
267,
327,
4898,
620,
2251,
436,
440,
2649,
14,
398,
543,
291,
14,
8222,
360,
4391,
735,
288,
1824,
275,
9762,
2821,
8,
576,
21146,
288,
327,
17650,
536,
436,
849,
63,
5508,
1077,
2929,
2552,
465,
5548,
543,
288,
327,
949,
10876,
14,
20550,
3595,
314,
8793,
4514,
1077,
506,
288,
327,
9164,
334,
73,
14,
69,
2020,
2793,
1133,
2929,
376,
23761,
359,
85,
7,
2765,
901,
365,
1415,
418,
288,
327,
1245,
680,
536,
365,
282,
14598,
901,
880,
666,
13,
4159,
365,
3451,
14,
288,
327,
3390,
626,
666,
13,
4159,
4501,
370,
314,
2637,
402,
314,
7761,
288,
327,
1420,
370,
506,
3451,
12,
440,
314,
2637,
402,
314,
1245,
781,
3984,
288,
327,
20589,
370,
314,
922,
446,
626,
1159,
10842,
652,
1159,
20589,
282,
289,
15148,
288,
327,
1245,
543,
282,
666,
13,
4159,
628,
287,
13,
527,
2,
2225,
12,
652,
1159,
440,
282,
6519,
14,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
288,
327,
849,
63,
5508,
365,
282,
3293,
901,
880,
666,
13,
4159,
365,
9552,
14,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
30,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
953,
327,
3979,
2337,
787,
3663,
2552,
12,
2985,
1077,
1006,
506,
9164,
14,
288,
1824,
14,
525,
63,
705,
360,
354,
297,
399,
7,
5432,
14614,
82,
3595,
536,
358,
288,
1824,
14,
525,
63,
705,
360,
885,
63,
5508,
297,
399,
7,
5432,
128,
113,
82,
3595,
849,
63,
5508,
358,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
7601,
317,
30,
5432,
14614,
82,
3595,
536,
1108,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
3351,
492,
28455,
199,
199,
646,
4613,
199,
504,
1134,
1131,
492,
1611,
3227,
465,
29158,
199,
199,
504,
312,
590,
311,
4674,
14,
4393,
14,
2219,
492,
7640,
199,
504,
312,
590,
311,
4674,
14,
13982,
492,
1504,
12,
4513,
199,
504,
312,
590,
311,
4674,
14,
13982,
14,
2219,
14,
19700,
14,
992,
492,
6266,
1776,
1685,
421,
199,
533,
9762,
2821,
8,
3351,
14,
18483,
2821,
4256,
12,
28455,
304,
272,
536,
275,
1504,
14,
3188,
792,
342,
339,
1021,
6288,
26,
267,
1402,
275,
6266,
1776,
1685,
267,
1504,
275,
2560,
452,
12217,
421,
199,
533,
1379,
18483,
2821,
4256,
8,
1746,
304,
339,
347,
511,
63,
885,
63,
5508,
8,
277,
304,
267,
1559,
275,
6266,
1776,
1685,
342,
267,
1559,
14,
362,
63,
10538,
275,
2400,
26,
283,
1168,
7,
398,
289,
275,
9762,
2821,
8,
842,
29,
1113,
9,
267,
702,
289,
14,
955,
459,
354,
2278,
885,
63,
5508,
508,
283,
1168,
7,
267,
702,
289,
14,
955,
459,
354,
2278,
3440,
14,
885,
63,
5508,
508,
283,
1168,
7,
267,
702,
29158,
8,
70,
14,
305,
63,
80,
1012,
7863,
344,
63,
354,
63,
16,
1959,
962,
360,
4159,
358,
508,
283,
1168,
7,
339,
347,
511,
63,
705,
63,
2918,
8,
277,
304,
267,
1824,
275,
9762,
2821,
8,
576,
21146,
267,
327,
17650,
536,
436,
849,
63,
5508,
1077,
2929,
2552,
465,
5548,
543,
949,
267,
327,
10876,
14,
20550,
3595,
314,
8793,
4514,
1077,
506,
9164,
267,
327,
334,
73,
14,
69,
2020,
2793,
1133,
2929,
376,
23761,
359,
85,
7,
2765,
901,
365,
1415,
418,
1245,
680,
267,
327,
536,
365,
282,
14598,
901,
880,
666,
13,
4159,
365,
3451,
14,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
267,
327,
849,
63,
5508,
365,
282,
3293,
901,
880,
666,
13,
4159,
365,
9552,
14,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
30,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
398,
327,
3979,
2337,
787,
3663,
2552,
12,
2985,
1077,
1006,
506,
9164,
14,
267,
1824,
14,
525,
63,
705,
360,
354,
297,
283,
547,
1245,
3595,
536,
358,
267,
1824,
14,
525,
63,
705,
360,
885,
63,
5508,
297,
283,
547,
1245,
3595,
849,
63,
5508,
358,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
2650,
317,
30,
547,
1245,
3595,
536,
1108,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
267,
1420,
275,
334,
288,
2650,
348,
1021,
628,
22326,
15603,
288,
2650,
317,
30,
2765,
901,
365,
1415,
9758,
317,
3524,
288,
2650,
317,
30,
547,
1245,
3595,
849,
63,
5508,
1108,
317,
3524,
288,
11936,
348,
5971,
267,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
339,
768,
4462,
14,
1657,
14,
10065,
63,
24763,
63,
863,
13696,
272,
347,
511,
63,
705,
63,
2918,
63,
1045,
63,
2975,
63,
6574,
8,
277,
304,
267,
327,
1010,
289,
15148,
12,
314,
1125,
1245,
367,
1415,
1504,
1395,
376,
1066,
2946,
14,
267,
327,
961,
1202,
370,
2059,
2952,
2005,
4184,
402,
314,
1059,
781,
3984,
10015,
267,
327,
4898,
620,
2251,
436,
440,
2649,
14,
398,
543,
291,
14,
8222,
360,
4391,
735,
288,
1824,
275,
9762,
2821,
8,
576,
21146,
288,
327,
17650,
536,
436,
849,
63,
5508,
1077,
2929,
2552,
465,
5548,
543,
288,
327,
949,
10876,
14,
20550,
3595,
314,
8793,
4514,
1077,
506,
288,
327,
9164,
334,
73,
14,
69,
2020,
2793,
1133,
2929,
376,
23761,
359,
85,
7,
2765,
901,
365,
1415,
418,
288,
327,
1245,
680,
536,
365,
282,
14598,
901,
880,
666,
13,
4159,
365,
3451,
14,
288,
327,
3390,
626,
666,
13,
4159,
4501,
370,
314,
2637,
402,
314,
7761,
288,
327,
1420,
370,
506,
3451,
12,
440,
314,
2637,
402,
314,
1245,
781,
3984,
288,
327,
20589,
370,
314,
922,
446,
626,
1159,
10842,
652,
1159,
20589,
282,
289,
15148,
288,
327,
1245,
543,
282,
666,
13,
4159,
628,
287,
13,
527,
2,
2225,
12,
652,
1159,
440,
282,
6519,
14,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
288,
327,
849,
63,
5508,
365,
282,
3293,
901,
880,
666,
13,
4159,
365,
9552,
14,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
30,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
885,
63,
5508,
2278,
305,
63,
348,
342,
508,
1420,
953,
327,
3979,
2337,
787,
3663,
2552,
12,
2985,
1077,
1006,
506,
9164,
14,
288,
1824,
14,
525,
63,
705,
360,
354,
297,
399,
7,
5432,
14614,
82,
3595,
536,
358,
288,
1824,
14,
525,
63,
705,
360,
885,
63,
5508,
297,
399,
7,
5432,
128,
113,
82,
3595,
849,
63,
5508,
358,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
355,
399,
7601,
317,
666,
13,
4159,
628,
287,
13,
527,
1743,
1049,
5282,
302,
5741,
670,
65,
3621,
9758,
317,
3524,
355,
399,
7601,
317,
30,
5432,
14614,
82,
3595,
536,
1108,
317,
3524,
355,
399,
29477,
348,
5971,
288,
702,
1824,
14,
2550,
459,
354,
2278,
305,
63,
348,
342,
508,
1420,
288,
1420,
275,
334,
355,
399,
7601,
348,
1021,
628,
22326,
15603,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dwightgunning/django
|
django/core/management/commands/showmigrations.py
|
440
|
4901
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.loader import MigrationLoader
class Command(BaseCommand):
help = "Shows all available migrations for the current project"
def add_arguments(self, parser):
parser.add_argument('app_labels', nargs='*',
help='App labels of applications to limit the output to.')
parser.add_argument('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
help='Nominates a database to synchronize. Defaults to the "default" database.')
formats = parser.add_mutually_exclusive_group()
formats.add_argument('--list', '-l', action='store_const', dest='format', const='list',
help='Shows a list of all migrations and which are applied.')
formats.add_argument('--plan', '-p', action='store_const', dest='format', const='plan',
help='Shows all migrations in the order they will be applied.')
parser.set_defaults(format='list')
def handle(self, *args, **options):
self.verbosity = options.get('verbosity')
# Get the database we're operating from
db = options.get('database')
connection = connections[db]
if options['format'] == "plan":
return self.show_plan(connection)
else:
return self.show_list(connection, options['app_labels'])
def show_list(self, connection, app_names=None):
"""
Shows a list of all migrations on the system, or only those of
some named apps.
"""
# Load migrations from disk/DB
loader = MigrationLoader(connection, ignore_no_migrations=True)
graph = loader.graph
# If we were passed a list of apps, validate it
if app_names:
invalid_apps = []
for app_name in app_names:
if app_name not in loader.migrated_apps:
invalid_apps.append(app_name)
if invalid_apps:
raise CommandError("No migrations present for: %s" % (", ".join(invalid_apps)))
# Otherwise, show all apps in alphabetic order
else:
app_names = sorted(loader.migrated_apps)
# For each app, print its migrations in order from oldest (roots) to
# newest (leaves).
for app_name in app_names:
self.stdout.write(app_name, self.style.MIGRATE_LABEL)
shown = set()
for node in graph.leaf_nodes(app_name):
for plan_node in graph.forwards_plan(node):
if plan_node not in shown and plan_node[0] == app_name:
# Give it a nice title if it's a squashed one
title = plan_node[1]
if graph.nodes[plan_node].replaces:
title += " (%s squashed migrations)" % len(graph.nodes[plan_node].replaces)
# Mark it as applied/unapplied
if plan_node in loader.applied_migrations:
self.stdout.write(" [X] %s" % title)
else:
self.stdout.write(" [ ] %s" % title)
shown.add(plan_node)
# If we didn't print anything, then a small message
if not shown:
self.stdout.write(" (no migrations)", self.style.MIGRATE_FAILURE)
def show_plan(self, connection):
"""
Shows all known migrations in the order they will be applied
"""
# Load migrations from disk/DB
loader = MigrationLoader(connection)
graph = loader.graph
targets = graph.leaf_nodes()
plan = []
seen = set()
# Generate the plan
for target in targets:
for migration in graph.forwards_plan(target):
if migration not in seen:
plan.append(graph.nodes[migration])
seen.add(migration)
# Output
def print_deps(migration):
out = []
for dep in migration.dependencies:
if dep[1] == "__first__":
roots = graph.root_nodes(dep[0])
dep = roots[0] if roots else (dep[0], "__first__")
out.append("%s.%s" % dep)
if out:
return " ... (%s)" % ", ".join(out)
return ""
for migration in plan:
deps = ""
if self.verbosity >= 2:
deps = print_deps(migration)
if (migration.app_label, migration.name) in loader.applied_migrations:
self.stdout.write("[X] %s%s" % (migration, deps))
else:
self.stdout.write("[ ] %s%s" % (migration, deps))
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
6947,
199,
504,
1639,
14,
697,
14,
7685,
14,
3422,
492,
12090,
5455,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
298,
6824,
83,
1006,
2808,
6180,
367,
314,
1453,
2199,
2,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
571,
63,
3512,
297,
9237,
534,
7693,
288,
1720,
534,
2640,
3628,
402,
13103,
370,
2304,
314,
1072,
370,
2659,
267,
1798,
14,
525,
63,
2094,
4517,
4659,
297,
1595,
534,
1617,
297,
2053,
534,
4659,
297,
849,
29,
3472,
63,
2846,
63,
12644,
12,
288,
1720,
534,
46,
676,
262,
2335,
282,
3050,
370,
31021,
14,
7827,
370,
314,
298,
885,
2,
3050,
2659,
398,
6752,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
267,
6752,
14,
525,
63,
2094,
4517,
513,
297,
2475,
76,
297,
1595,
534,
1617,
63,
1297,
297,
2053,
534,
908,
297,
950,
534,
513,
297,
288,
1720,
534,
6824,
83,
282,
769,
402,
1006,
6180,
436,
1314,
787,
6781,
2659,
267,
6752,
14,
525,
63,
2094,
4517,
5140,
297,
2475,
80,
297,
1595,
534,
1617,
63,
1297,
297,
2053,
534,
908,
297,
950,
534,
5140,
297,
288,
1720,
534,
6824,
83,
1006,
6180,
315,
314,
1865,
2985,
911,
506,
6781,
2659,
398,
1798,
14,
409,
63,
4322,
8,
908,
534,
513,
358,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
291,
14,
9833,
275,
1511,
14,
362,
360,
9833,
358,
398,
327,
2372,
314,
3050,
781,
3984,
17406,
687,
267,
1592,
275,
1511,
14,
362,
360,
4659,
358,
267,
1950,
275,
6947,
59,
697,
61,
398,
340,
1511,
459,
908,
418,
508,
298,
5140,
582,
288,
372,
291,
14,
2384,
63,
5140,
8,
2105,
9,
267,
587,
26,
288,
372,
291,
14,
2384,
63,
513,
8,
2105,
12,
1511,
459,
571,
63,
3512,
1105,
339,
347,
2498,
63,
513,
8,
277,
12,
1950,
12,
1145,
63,
1247,
29,
403,
304,
267,
408,
267,
12968,
83,
282,
769,
402,
1006,
6180,
641,
314,
2656,
12,
503,
1454,
5204,
402,
267,
2005,
4310,
8686,
14,
267,
408,
267,
327,
7190,
6180,
687,
4543,
15,
2846,
267,
5077,
275,
12090,
5455,
8,
2105,
12,
3686,
63,
889,
63,
7685,
29,
549,
9,
267,
3343,
275,
5077,
14,
2180,
267,
327,
982,
781,
4898,
3032,
282,
769,
402,
8686,
12,
4107,
652,
267,
340,
1145,
63,
1247,
26,
288,
3866,
63,
5181,
275,
942,
288,
367,
1145,
63,
354,
315,
1145,
63,
1247,
26,
355,
340,
1145,
63,
354,
440,
315,
5077,
14,
31544,
63,
5181,
26,
490,
3866,
63,
5181,
14,
740,
8,
571,
63,
354,
9,
288,
340,
3866,
63,
5181,
26,
355,
746,
14393,
480,
1944,
6180,
3451,
367,
26,
450,
83,
2,
450,
334,
401,
3680,
904,
8,
3197,
63,
5181,
1724,
267,
327,
6630,
12,
2498,
1006,
8686,
315,
23331,
764,
1865,
267,
587,
26,
288,
1145,
63,
1247,
275,
3355,
8,
3422,
14,
31544,
63,
5181,
9,
267,
327,
2104,
1924,
1145,
12,
870,
2399,
6180,
315,
1865,
687,
29493,
334,
12065,
9,
370,
267,
327,
29608,
334,
16554,
680,
267,
367,
1145,
63,
354,
315,
1145,
63,
1247,
26,
288,
291,
14,
2703,
14,
952,
8,
571,
63,
354,
12,
291,
14,
2487,
14,
22487,
16553,
63,
13837,
9,
288,
9164,
275,
663,
342,
288,
367,
1031,
315,
3343,
14,
8914,
63,
2415,
8,
571,
63,
354,
304,
355,
367,
8683,
63,
932,
315,
3343,
14,
19159,
63,
5140,
8,
932,
304,
490,
340,
8683,
63,
932,
440,
315,
9164,
436,
8683,
63,
932,
59,
16,
61,
508,
1145,
63,
354,
26,
717,
327,
25495,
652,
282,
14213,
2538,
340,
652,
1159,
282,
12345,
21189,
1373,
717,
2538,
275,
8683,
63,
932,
59,
17,
61,
717,
340,
3343,
14,
2415,
59,
5140,
63,
932,
1055,
1155,
5862,
26,
1169,
2538,
847,
298,
4366,
83,
12345,
21189,
6180,
2924,
450,
822,
8,
2180,
14,
2415,
59,
5140,
63,
932,
1055,
1155,
5862,
9,
717,
327,
7173,
652,
465,
6781,
15,
324,
17250,
717,
340,
8683,
63,
932,
315,
5077,
14,
17250,
63,
7685,
26,
1169,
291,
14,
2703,
14,
952,
480,
359,
56,
61,
450,
83,
2,
450,
2538,
9,
717,
587,
26,
1169,
291,
14,
2703,
14,
952,
480,
359,
1622,
450,
83,
2,
450,
2538,
9,
717,
9164,
14,
525,
8,
5140,
63,
932,
9,
288,
327,
982,
781,
9980,
1133,
870,
7003,
12,
2066,
282,
7425,
1245,
288,
340,
440,
9164,
26,
355,
291,
14,
2703,
14,
952,
480,
334,
889,
6180,
4186,
291,
14,
2487,
14,
22487,
16553,
63,
13989,
9,
339,
347,
2498,
63,
5140,
8,
277,
12,
1950,
304,
267,
408,
267,
12968,
83,
1006,
6040,
6180,
315,
314,
1865,
2985,
911,
506,
6781,
267,
408,
267,
327,
7190,
6180,
687,
4543,
15,
2846,
267,
5077,
275,
12090,
5455,
8,
2105,
9,
267,
3343,
275,
5077,
14,
2180,
267,
4545,
275,
3343,
14,
8914,
63,
2415,
342,
267,
8683,
275,
942,
267,
6775,
275,
663,
342,
398,
327,
7958,
314,
8683,
267,
367,
1347,
315,
4545,
26,
288,
367,
8367,
315,
3343,
14,
19159,
63,
5140,
8,
1375,
304,
355,
340,
8367,
440,
315,
6775,
26,
490,
8683,
14,
740,
8,
2180,
14,
2415,
59,
8998,
566,
490,
6775,
14,
525,
8,
8998,
9,
398,
327,
7242,
267,
347,
870,
63,
5846,
8,
8998,
304,
288,
734,
275,
942,
288,
367,
2657,
315,
8367,
14,
5714,
26,
355,
340,
2657,
59,
17,
61,
508,
4396,
2246,
5727,
490,
14361,
275,
3343,
14,
1231,
63,
2415,
8,
2601,
59,
16,
566,
490,
2657,
275,
14361,
59,
16,
61,
340,
14361,
587,
334,
2601,
59,
16,
467,
4396,
2246,
18617,
355,
734,
14,
740,
3647,
83,
4111,
83,
2,
450,
2657,
9,
288,
340,
734,
26,
355,
372,
298,
2263,
4366,
83,
2924,
450,
3872,
3680,
904,
8,
548,
9,
288,
372,
3087,
398,
367,
8367,
315,
8683,
26,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
6947,
199,
504,
1639,
14,
697,
14,
7685,
14,
3422,
492,
12090,
5455,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
298,
6824,
83,
1006,
2808,
6180,
367,
314,
1453,
2199,
2,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
571,
63,
3512,
297,
9237,
534,
7693,
288,
1720,
534,
2640,
3628,
402,
13103,
370,
2304,
314,
1072,
370,
2659,
267,
1798,
14,
525,
63,
2094,
4517,
4659,
297,
1595,
534,
1617,
297,
2053,
534,
4659,
297,
849,
29,
3472,
63,
2846,
63,
12644,
12,
288,
1720,
534,
46,
676,
262,
2335,
282,
3050,
370,
31021,
14,
7827,
370,
314,
298,
885,
2,
3050,
2659,
398,
6752,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
267,
6752,
14,
525,
63,
2094,
4517,
513,
297,
2475,
76,
297,
1595,
534,
1617,
63,
1297,
297,
2053,
534,
908,
297,
950,
534,
513,
297,
288,
1720,
534,
6824,
83,
282,
769,
402,
1006,
6180,
436,
1314,
787,
6781,
2659,
267,
6752,
14,
525,
63,
2094,
4517,
5140,
297,
2475,
80,
297,
1595,
534,
1617,
63,
1297,
297,
2053,
534,
908,
297,
950,
534,
5140,
297,
288,
1720,
534,
6824,
83,
1006,
6180,
315,
314,
1865,
2985,
911,
506,
6781,
2659,
398,
1798,
14,
409,
63,
4322,
8,
908,
534,
513,
358,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
291,
14,
9833,
275,
1511,
14,
362,
360,
9833,
358,
398,
327,
2372,
314,
3050,
781,
3984,
17406,
687,
267,
1592,
275,
1511,
14,
362,
360,
4659,
358,
267,
1950,
275,
6947,
59,
697,
61,
398,
340,
1511,
459,
908,
418,
508,
298,
5140,
582,
288,
372,
291,
14,
2384,
63,
5140,
8,
2105,
9,
267,
587,
26,
288,
372,
291,
14,
2384,
63,
513,
8,
2105,
12,
1511,
459,
571,
63,
3512,
1105,
339,
347,
2498,
63,
513,
8,
277,
12,
1950,
12,
1145,
63,
1247,
29,
403,
304,
267,
408,
267,
12968,
83,
282,
769,
402,
1006,
6180,
641,
314,
2656,
12,
503,
1454,
5204,
402,
267,
2005,
4310,
8686,
14,
267,
408,
267,
327,
7190,
6180,
687,
4543,
15,
2846,
267,
5077,
275,
12090,
5455,
8,
2105,
12,
3686,
63,
889,
63,
7685,
29,
549,
9,
267,
3343,
275,
5077,
14,
2180,
267,
327,
982,
781,
4898,
3032,
282,
769,
402,
8686,
12,
4107,
652,
267,
340,
1145,
63,
1247,
26,
288,
3866,
63,
5181,
275,
942,
288,
367,
1145,
63,
354,
315,
1145,
63,
1247,
26,
355,
340,
1145,
63,
354,
440,
315,
5077,
14,
31544,
63,
5181,
26,
490,
3866,
63,
5181,
14,
740,
8,
571,
63,
354,
9,
288,
340,
3866,
63,
5181,
26,
355,
746,
14393,
480,
1944,
6180,
3451,
367,
26,
450,
83,
2,
450,
334,
401,
3680,
904,
8,
3197,
63,
5181,
1724,
267,
327,
6630,
12,
2498,
1006,
8686,
315,
23331,
764,
1865,
267,
587,
26,
288,
1145,
63,
1247,
275,
3355,
8,
3422,
14,
31544,
63,
5181,
9,
267,
327,
2104,
1924,
1145,
12,
870,
2399,
6180,
315,
1865,
687,
29493,
334,
12065,
9,
370,
267,
327,
29608,
334,
16554,
680,
267,
367,
1145,
63,
354,
315,
1145,
63,
1247,
26,
288,
291,
14,
2703,
14,
952,
8,
571,
63,
354,
12,
291,
14,
2487,
14,
22487,
16553,
63,
13837,
9,
288,
9164,
275,
663,
342,
288,
367,
1031,
315,
3343,
14,
8914,
63,
2415,
8,
571,
63,
354,
304,
355,
367,
8683,
63,
932,
315,
3343,
14,
19159,
63,
5140,
8,
932,
304,
490,
340,
8683,
63,
932,
440,
315,
9164,
436,
8683,
63,
932,
59,
16,
61,
508,
1145,
63,
354,
26,
717,
327,
25495,
652,
282,
14213,
2538,
340,
652,
1159,
282,
12345,
21189,
1373,
717,
2538,
275,
8683,
63,
932,
59,
17,
61,
717,
340,
3343,
14,
2415,
59,
5140,
63,
932,
1055,
1155,
5862,
26,
1169,
2538,
847,
298,
4366,
83,
12345,
21189,
6180,
2924,
450,
822,
8,
2180,
14,
2415,
59,
5140,
63,
932,
1055,
1155,
5862,
9,
717,
327,
7173,
652,
465,
6781,
15,
324,
17250,
717,
340,
8683,
63,
932,
315,
5077,
14,
17250,
63,
7685,
26,
1169,
291,
14,
2703,
14,
952,
480,
359,
56,
61,
450,
83,
2,
450,
2538,
9,
717,
587,
26,
1169,
291,
14,
2703,
14,
952,
480,
359,
1622,
450,
83,
2,
450,
2538,
9,
717,
9164,
14,
525,
8,
5140,
63,
932,
9,
288,
327,
982,
781,
9980,
1133,
870,
7003,
12,
2066,
282,
7425,
1245,
288,
340,
440,
9164,
26,
355,
291,
14,
2703,
14,
952,
480,
334,
889,
6180,
4186,
291,
14,
2487,
14,
22487,
16553,
63,
13989,
9,
339,
347,
2498,
63,
5140,
8,
277,
12,
1950,
304,
267,
408,
267,
12968,
83,
1006,
6040,
6180,
315,
314,
1865,
2985,
911,
506,
6781,
267,
408,
267,
327,
7190,
6180,
687,
4543,
15,
2846,
267,
5077,
275,
12090,
5455,
8,
2105,
9,
267,
3343,
275,
5077,
14,
2180,
267,
4545,
275,
3343,
14,
8914,
63,
2415,
342,
267,
8683,
275,
942,
267,
6775,
275,
663,
342,
398,
327,
7958,
314,
8683,
267,
367,
1347,
315,
4545,
26,
288,
367,
8367,
315,
3343,
14,
19159,
63,
5140,
8,
1375,
304,
355,
340,
8367,
440,
315,
6775,
26,
490,
8683,
14,
740,
8,
2180,
14,
2415,
59,
8998,
566,
490,
6775,
14,
525,
8,
8998,
9,
398,
327,
7242,
267,
347,
870,
63,
5846,
8,
8998,
304,
288,
734,
275,
942,
288,
367,
2657,
315,
8367,
14,
5714,
26,
355,
340,
2657,
59,
17,
61,
508,
4396,
2246,
5727,
490,
14361,
275,
3343,
14,
1231,
63,
2415,
8,
2601,
59,
16,
566,
490,
2657,
275,
14361,
59,
16,
61,
340,
14361,
587,
334,
2601,
59,
16,
467,
4396,
2246,
18617,
355,
734,
14,
740,
3647,
83,
4111,
83,
2,
450,
2657,
9,
288,
340,
734,
26,
355,
372,
298,
2263,
4366,
83,
2924,
450,
3872,
3680,
904,
8,
548,
9,
288,
372,
3087,
398,
367,
8367,
315,
8683,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
stscieisenhamer/glue
|
glue/core/data_factories/excel.py
|
5
|
1367
|
from __future__ import absolute_import, division, print_function
import os
from glue.core.data_factories.helpers import has_extension
from glue.core.data_factories.pandas import panda_process
from glue.config import data_factory
__all__ = []
@data_factory(label="Excel", identifier=has_extension('xls xlsx'))
def panda_read_excel(path, sheet=None, **kwargs):
""" A factory for reading excel data using pandas.
:param path: path/to/file
:param sheet: The sheet to read. If `None`, all sheets are read.
:param kwargs: All other kwargs are passed to pandas.read_excel
:return: core.data.Data object.
"""
try:
import pandas as pd
except ImportError:
raise ImportError('Pandas is required for Excel input.')
try:
import xlrd
except ImportError:
raise ImportError('xlrd is required for Excel input.')
name = os.path.basename(path)
if '.xls' in name:
name = name.rsplit('.xls', 1)[0]
xl_workbook = xlrd.open_workbook(path)
if sheet is None:
sheet_names = xl_workbook.sheet_names()
else:
sheet_names = [sheet]
all_data = []
for sheet in sheet_names:
indf = pd.read_excel(path, sheet, **kwargs)
data = panda_process(indf)
data.label = "{0}:{1}".format(name, sheet)
all_data.append(data)
return all_data
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
199,
504,
6482,
310,
14,
1018,
14,
576,
63,
15406,
14,
7546,
492,
965,
63,
3435,
199,
504,
6482,
310,
14,
1018,
14,
576,
63,
15406,
14,
15718,
492,
299,
18328,
63,
1412,
199,
504,
6482,
310,
14,
888,
492,
666,
63,
3702,
421,
199,
363,
452,
363,
275,
942,
421,
199,
32,
576,
63,
3702,
8,
1302,
628,
920,
6067,
401,
5148,
29,
1989,
63,
3435,
360,
19023,
671,
478,
88,
1333,
199,
318,
299,
18328,
63,
739,
63,
28330,
8,
515,
12,
12083,
29,
403,
12,
1011,
958,
304,
272,
408,
437,
6434,
367,
7664,
444,
6067,
666,
1808,
10634,
14,
272,
520,
635,
931,
26,
931,
15,
475,
15,
493,
272,
520,
635,
12083,
26,
710,
12083,
370,
1586,
14,
982,
658,
403,
3559,
1006,
24405,
787,
1586,
14,
272,
520,
635,
2074,
26,
2900,
1163,
2074,
787,
3032,
370,
10634,
14,
739,
63,
28330,
272,
520,
1107,
26,
6170,
14,
576,
14,
1451,
909,
14,
272,
408,
339,
862,
26,
267,
492,
10634,
465,
6454,
272,
871,
3545,
26,
267,
746,
3545,
360,
48,
7683,
365,
1415,
367,
27832,
1324,
2659,
339,
862,
26,
267,
492,
25077,
6883,
272,
871,
3545,
26,
267,
746,
3545,
360,
15455,
6883,
365,
1415,
367,
27832,
1324,
2659,
339,
536,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
272,
340,
1987,
19023,
7,
315,
536,
26,
267,
536,
275,
536,
14,
13490,
5175,
19023,
297,
413,
2788,
16,
61,
339,
25077,
63,
30765,
275,
25077,
6883,
14,
1490,
63,
30765,
8,
515,
9,
339,
340,
12083,
365,
488,
26,
267,
12083,
63,
1247,
275,
25077,
63,
30765,
14,
5069,
63,
1247,
342,
272,
587,
26,
267,
12083,
63,
1247,
275,
359,
5069,
61,
339,
1006,
63,
576,
275,
942,
272,
367,
12083,
315,
12083,
63,
1247,
26,
267,
315,
1587,
275,
6454,
14,
739,
63,
28330,
8,
515,
12,
12083,
12,
1011,
958,
9,
267,
666,
275,
299,
18328,
63,
1412,
8,
688,
70,
9,
267,
666,
14,
1302,
275,
5310,
16,
16495,
17,
5469,
908,
8,
354,
12,
12083,
9,
267,
1006,
63,
576,
14,
740,
8,
576,
9,
339,
372,
1006,
63,
576,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
199,
504,
6482,
310,
14,
1018,
14,
576,
63,
15406,
14,
7546,
492,
965,
63,
3435,
199,
504,
6482,
310,
14,
1018,
14,
576,
63,
15406,
14,
15718,
492,
299,
18328,
63,
1412,
199,
504,
6482,
310,
14,
888,
492,
666,
63,
3702,
421,
199,
363,
452,
363,
275,
942,
421,
199,
32,
576,
63,
3702,
8,
1302,
628,
920,
6067,
401,
5148,
29,
1989,
63,
3435,
360,
19023,
671,
478,
88,
1333,
199,
318,
299,
18328,
63,
739,
63,
28330,
8,
515,
12,
12083,
29,
403,
12,
1011,
958,
304,
272,
408,
437,
6434,
367,
7664,
444,
6067,
666,
1808,
10634,
14,
272,
520,
635,
931,
26,
931,
15,
475,
15,
493,
272,
520,
635,
12083,
26,
710,
12083,
370,
1586,
14,
982,
658,
403,
3559,
1006,
24405,
787,
1586,
14,
272,
520,
635,
2074,
26,
2900,
1163,
2074,
787,
3032,
370,
10634,
14,
739,
63,
28330,
272,
520,
1107,
26,
6170,
14,
576,
14,
1451,
909,
14,
272,
408,
339,
862,
26,
267,
492,
10634,
465,
6454,
272,
871,
3545,
26,
267,
746,
3545,
360,
48,
7683,
365,
1415,
367,
27832,
1324,
2659,
339,
862,
26,
267,
492,
25077,
6883,
272,
871,
3545,
26,
267,
746,
3545,
360,
15455,
6883,
365,
1415,
367,
27832,
1324,
2659,
339,
536,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
272,
340,
1987,
19023,
7,
315,
536,
26,
267,
536,
275,
536,
14,
13490,
5175,
19023,
297,
413,
2788,
16,
61,
339,
25077,
63,
30765,
275,
25077,
6883,
14,
1490,
63,
30765,
8,
515,
9,
339,
340,
12083,
365,
488,
26,
267,
12083,
63,
1247,
275,
25077,
63,
30765,
14,
5069,
63,
1247,
342,
272,
587,
26,
267,
12083,
63,
1247,
275,
359,
5069,
61,
339,
1006,
63,
576,
275,
942,
272,
367,
12083,
315,
12083,
63,
1247,
26,
267,
315,
1587,
275,
6454,
14,
739,
63,
28330,
8,
515,
12,
12083,
12,
1011,
958,
9,
267,
666,
275,
299,
18328,
63,
1412,
8,
688,
70,
9,
267,
666,
14,
1302,
275,
5310,
16,
16495,
17,
5469,
908,
8,
354,
12,
12083,
9,
267,
1006,
63,
576,
14,
740,
8,
576,
9,
339,
372,
1006,
63,
576,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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.py
|
11180
|
1927
|
# system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts-by-pid.py [comm]\n";
for_comm = None
for_pid = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
try:
for_pid = int(sys.argv[1])
except:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if (for_comm and common_comm != for_comm) or \
(for_pid and common_pid != for_pid ):
return
try:
syscalls[common_comm][common_pid][id] += 1
except TypeError:
syscalls[common_comm][common_pid][id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events by comm/pid:\n\n",
print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
comm_keys = syscalls.keys()
for comm in comm_keys:
pid_keys = syscalls[comm].keys()
for pid in pid_keys:
print "\n%s [%d]\n" % (comm, pid),
id_keys = syscalls[comm][pid].keys()
for id, val in sorted(syscalls[comm][pid].iteritems(), \
key = lambda(k, v): (v, k), reverse = True):
print " %-38s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
shaananc/security-proj2
|
bindings/python/apidefs/gcc-LP64/ns3_module_stats.py
|
10
|
33153
|
from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers
def register_types(module):
root_module = module.get_root()
## data-output-interface.h: ns3::DataOutputCallback [class]
module.add_class('DataOutputCallback', allow_subclassing=True)
## data-calculator.h: ns3::StatisticalSummary [class]
module.add_class('StatisticalSummary', allow_subclassing=True)
## data-calculator.h: ns3::DataCalculator [class]
module.add_class('DataCalculator', parent=root_module['ns3::Object'])
## data-collector.h: ns3::DataCollector [class]
module.add_class('DataCollector', parent=root_module['ns3::Object'])
## data-output-interface.h: ns3::DataOutputInterface [class]
module.add_class('DataOutputInterface', parent=root_module['ns3::Object'])
## basic-data-calculators.h: ns3::MinMaxAvgTotalCalculator<unsigned int> [class]
module.add_class('MinMaxAvgTotalCalculator', template_parameters=['unsigned int'], parent=[root_module['ns3::DataCalculator'], root_module['ns3::StatisticalSummary']])
## omnet-data-output.h: ns3::OmnetDataOutput [class]
module.add_class('OmnetDataOutput', parent=root_module['ns3::DataOutputInterface'])
## packet-data-calculators.h: ns3::PacketSizeMinMaxAvgTotalCalculator [class]
module.add_class('PacketSizeMinMaxAvgTotalCalculator', parent=root_module['ns3::MinMaxAvgTotalCalculator< unsigned int >'])
## sqlite-data-output.h: ns3::SqliteDataOutput [class]
module.add_class('SqliteDataOutput', parent=root_module['ns3::DataOutputInterface'])
## time-data-calculators.h: ns3::TimeMinMaxAvgTotalCalculator [class]
module.add_class('TimeMinMaxAvgTotalCalculator', parent=root_module['ns3::DataCalculator'])
## basic-data-calculators.h: ns3::CounterCalculator<unsigned int> [class]
module.add_class('CounterCalculator', template_parameters=['unsigned int'], parent=root_module['ns3::DataCalculator'])
## packet-data-calculators.h: ns3::PacketCounterCalculator [class]
module.add_class('PacketCounterCalculator', parent=root_module['ns3::CounterCalculator< unsigned int >'])
typehandlers.add_type_alias('std::list< std::pair< std::string, std::string >, std::allocator< std::pair< std::string, std::string > > >', 'ns3::MetadataList')
typehandlers.add_type_alias('std::list< std::pair< std::string, std::string >, std::allocator< std::pair< std::string, std::string > > >*', 'ns3::MetadataList*')
typehandlers.add_type_alias('std::list< std::pair< std::string, std::string >, std::allocator< std::pair< std::string, std::string > > >&', 'ns3::MetadataList&')
typehandlers.add_type_alias('std::list< ns3::Ptr< ns3::DataCalculator >, std::allocator< ns3::Ptr< ns3::DataCalculator > > >', 'ns3::DataCalculatorList')
typehandlers.add_type_alias('std::list< ns3::Ptr< ns3::DataCalculator >, std::allocator< ns3::Ptr< ns3::DataCalculator > > >*', 'ns3::DataCalculatorList*')
typehandlers.add_type_alias('std::list< ns3::Ptr< ns3::DataCalculator >, std::allocator< ns3::Ptr< ns3::DataCalculator > > >&', 'ns3::DataCalculatorList&')
## Register a nested module for the namespace Config
nested_module = module.add_cpp_namespace('Config')
register_types_ns3_Config(nested_module)
## Register a nested module for the namespace FatalImpl
nested_module = module.add_cpp_namespace('FatalImpl')
register_types_ns3_FatalImpl(nested_module)
## Register a nested module for the namespace addressUtils
nested_module = module.add_cpp_namespace('addressUtils')
register_types_ns3_addressUtils(nested_module)
## Register a nested module for the namespace aodv
nested_module = module.add_cpp_namespace('aodv')
register_types_ns3_aodv(nested_module)
## Register a nested module for the namespace dot11s
nested_module = module.add_cpp_namespace('dot11s')
register_types_ns3_dot11s(nested_module)
## Register a nested module for the namespace flame
nested_module = module.add_cpp_namespace('flame')
register_types_ns3_flame(nested_module)
## Register a nested module for the namespace internal
nested_module = module.add_cpp_namespace('internal')
register_types_ns3_internal(nested_module)
## Register a nested module for the namespace olsr
nested_module = module.add_cpp_namespace('olsr')
register_types_ns3_olsr(nested_module)
def register_types_ns3_Config(module):
root_module = module.get_root()
def register_types_ns3_FatalImpl(module):
root_module = module.get_root()
def register_types_ns3_addressUtils(module):
root_module = module.get_root()
def register_types_ns3_aodv(module):
root_module = module.get_root()
def register_types_ns3_dot11s(module):
root_module = module.get_root()
def register_types_ns3_flame(module):
root_module = module.get_root()
def register_types_ns3_internal(module):
root_module = module.get_root()
def register_types_ns3_olsr(module):
root_module = module.get_root()
def register_methods(root_module):
register_Ns3DataOutputCallback_methods(root_module, root_module['ns3::DataOutputCallback'])
register_Ns3StatisticalSummary_methods(root_module, root_module['ns3::StatisticalSummary'])
register_Ns3DataCalculator_methods(root_module, root_module['ns3::DataCalculator'])
register_Ns3DataCollector_methods(root_module, root_module['ns3::DataCollector'])
register_Ns3DataOutputInterface_methods(root_module, root_module['ns3::DataOutputInterface'])
register_Ns3MinMaxAvgTotalCalculator__Unsigned_int_methods(root_module, root_module['ns3::MinMaxAvgTotalCalculator< unsigned int >'])
register_Ns3OmnetDataOutput_methods(root_module, root_module['ns3::OmnetDataOutput'])
register_Ns3PacketSizeMinMaxAvgTotalCalculator_methods(root_module, root_module['ns3::PacketSizeMinMaxAvgTotalCalculator'])
register_Ns3SqliteDataOutput_methods(root_module, root_module['ns3::SqliteDataOutput'])
register_Ns3TimeMinMaxAvgTotalCalculator_methods(root_module, root_module['ns3::TimeMinMaxAvgTotalCalculator'])
register_Ns3CounterCalculator__Unsigned_int_methods(root_module, root_module['ns3::CounterCalculator< unsigned int >'])
register_Ns3PacketCounterCalculator_methods(root_module, root_module['ns3::PacketCounterCalculator'])
return
def register_Ns3DataOutputCallback_methods(root_module, cls):
## data-output-interface.h: ns3::DataOutputCallback::DataOutputCallback() [constructor]
cls.add_constructor([])
## data-output-interface.h: ns3::DataOutputCallback::DataOutputCallback(ns3::DataOutputCallback const & arg0) [copy constructor]
cls.add_constructor([param('ns3::DataOutputCallback const &', 'arg0')])
## data-output-interface.h: void ns3::DataOutputCallback::OutputSingleton(std::string key, std::string variable, int val) [member function]
cls.add_method('OutputSingleton',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('int', 'val')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputCallback::OutputSingleton(std::string key, std::string variable, uint32_t val) [member function]
cls.add_method('OutputSingleton',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('uint32_t', 'val')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputCallback::OutputSingleton(std::string key, std::string variable, double val) [member function]
cls.add_method('OutputSingleton',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('double', 'val')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputCallback::OutputSingleton(std::string key, std::string variable, std::string val) [member function]
cls.add_method('OutputSingleton',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('std::string', 'val')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputCallback::OutputSingleton(std::string key, std::string variable, ns3::Time val) [member function]
cls.add_method('OutputSingleton',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('ns3::Time', 'val')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputCallback::OutputStatistic(std::string key, std::string variable, ns3::StatisticalSummary const * statSum) [member function]
cls.add_method('OutputStatistic',
'void',
[param('std::string', 'key'), param('std::string', 'variable'), param('ns3::StatisticalSummary const *', 'statSum')],
is_pure_virtual=True, is_virtual=True)
return
def register_Ns3StatisticalSummary_methods(root_module, cls):
## data-calculator.h: ns3::StatisticalSummary::StatisticalSummary() [constructor]
cls.add_constructor([])
## data-calculator.h: ns3::StatisticalSummary::StatisticalSummary(ns3::StatisticalSummary const & arg0) [copy constructor]
cls.add_constructor([param('ns3::StatisticalSummary const &', 'arg0')])
## data-calculator.h: long int ns3::StatisticalSummary::getCount() const [member function]
cls.add_method('getCount',
'long int',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getMax() const [member function]
cls.add_method('getMax',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getMean() const [member function]
cls.add_method('getMean',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getMin() const [member function]
cls.add_method('getMin',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getSqrSum() const [member function]
cls.add_method('getSqrSum',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getStddev() const [member function]
cls.add_method('getStddev',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getSum() const [member function]
cls.add_method('getSum',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: double ns3::StatisticalSummary::getVariance() const [member function]
cls.add_method('getVariance',
'double',
[],
is_pure_virtual=True, is_const=True, is_virtual=True)
return
def register_Ns3DataCalculator_methods(root_module, cls):
## data-calculator.h: ns3::DataCalculator::DataCalculator(ns3::DataCalculator const & arg0) [copy constructor]
cls.add_constructor([param('ns3::DataCalculator const &', 'arg0')])
## data-calculator.h: ns3::DataCalculator::DataCalculator() [constructor]
cls.add_constructor([])
## data-calculator.h: void ns3::DataCalculator::Disable() [member function]
cls.add_method('Disable',
'void',
[])
## data-calculator.h: void ns3::DataCalculator::Enable() [member function]
cls.add_method('Enable',
'void',
[])
## data-calculator.h: std::string ns3::DataCalculator::GetContext() const [member function]
cls.add_method('GetContext',
'std::string',
[],
is_const=True)
## data-calculator.h: bool ns3::DataCalculator::GetEnabled() const [member function]
cls.add_method('GetEnabled',
'bool',
[],
is_const=True)
## data-calculator.h: std::string ns3::DataCalculator::GetKey() const [member function]
cls.add_method('GetKey',
'std::string',
[],
is_const=True)
## data-calculator.h: void ns3::DataCalculator::Output(ns3::DataOutputCallback & callback) const [member function]
cls.add_method('Output',
'void',
[param('ns3::DataOutputCallback &', 'callback')],
is_pure_virtual=True, is_const=True, is_virtual=True)
## data-calculator.h: void ns3::DataCalculator::SetContext(std::string const context) [member function]
cls.add_method('SetContext',
'void',
[param('std::string const', 'context')])
## data-calculator.h: void ns3::DataCalculator::SetKey(std::string const key) [member function]
cls.add_method('SetKey',
'void',
[param('std::string const', 'key')])
## data-calculator.h: void ns3::DataCalculator::Start(ns3::Time const & startTime) [member function]
cls.add_method('Start',
'void',
[param('ns3::Time const &', 'startTime')],
is_virtual=True)
## data-calculator.h: void ns3::DataCalculator::Stop(ns3::Time const & stopTime) [member function]
cls.add_method('Stop',
'void',
[param('ns3::Time const &', 'stopTime')],
is_virtual=True)
## data-calculator.h: void ns3::DataCalculator::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3DataCollector_methods(root_module, cls):
## data-collector.h: ns3::DataCollector::DataCollector(ns3::DataCollector const & arg0) [copy constructor]
cls.add_constructor([param('ns3::DataCollector const &', 'arg0')])
## data-collector.h: ns3::DataCollector::DataCollector() [constructor]
cls.add_constructor([])
## data-collector.h: void ns3::DataCollector::AddDataCalculator(ns3::Ptr<ns3::DataCalculator> datac) [member function]
cls.add_method('AddDataCalculator',
'void',
[param('ns3::Ptr< ns3::DataCalculator >', 'datac')])
## data-collector.h: void ns3::DataCollector::AddMetadata(std::string key, std::string value) [member function]
cls.add_method('AddMetadata',
'void',
[param('std::string', 'key'), param('std::string', 'value')])
## data-collector.h: void ns3::DataCollector::AddMetadata(std::string key, double value) [member function]
cls.add_method('AddMetadata',
'void',
[param('std::string', 'key'), param('double', 'value')])
## data-collector.h: void ns3::DataCollector::AddMetadata(std::string key, uint32_t value) [member function]
cls.add_method('AddMetadata',
'void',
[param('std::string', 'key'), param('uint32_t', 'value')])
## data-collector.h: std::_List_iterator<ns3::Ptr<ns3::DataCalculator> > ns3::DataCollector::DataCalculatorBegin() [member function]
cls.add_method('DataCalculatorBegin',
'std::_List_iterator< ns3::Ptr< ns3::DataCalculator > >',
[])
## data-collector.h: std::_List_iterator<ns3::Ptr<ns3::DataCalculator> > ns3::DataCollector::DataCalculatorEnd() [member function]
cls.add_method('DataCalculatorEnd',
'std::_List_iterator< ns3::Ptr< ns3::DataCalculator > >',
[])
## data-collector.h: void ns3::DataCollector::DescribeRun(std::string experiment, std::string strategy, std::string input, std::string runID, std::string description="") [member function]
cls.add_method('DescribeRun',
'void',
[param('std::string', 'experiment'), param('std::string', 'strategy'), param('std::string', 'input'), param('std::string', 'runID'), param('std::string', 'description', default_value='""')])
## data-collector.h: std::string ns3::DataCollector::GetDescription() const [member function]
cls.add_method('GetDescription',
'std::string',
[],
is_const=True)
## data-collector.h: std::string ns3::DataCollector::GetExperimentLabel() const [member function]
cls.add_method('GetExperimentLabel',
'std::string',
[],
is_const=True)
## data-collector.h: std::string ns3::DataCollector::GetInputLabel() const [member function]
cls.add_method('GetInputLabel',
'std::string',
[],
is_const=True)
## data-collector.h: std::string ns3::DataCollector::GetRunLabel() const [member function]
cls.add_method('GetRunLabel',
'std::string',
[],
is_const=True)
## data-collector.h: std::string ns3::DataCollector::GetStrategyLabel() const [member function]
cls.add_method('GetStrategyLabel',
'std::string',
[],
is_const=True)
## data-collector.h: std::_List_iterator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > ns3::DataCollector::MetadataBegin() [member function]
cls.add_method('MetadataBegin',
'std::_List_iterator< std::pair< std::basic_string< char, std::char_traits< char >, std::allocator< char > >, std::basic_string< char, std::char_traits< char >, std::allocator< char > > > >',
[])
## data-collector.h: std::_List_iterator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > ns3::DataCollector::MetadataEnd() [member function]
cls.add_method('MetadataEnd',
'std::_List_iterator< std::pair< std::basic_string< char, std::char_traits< char >, std::allocator< char > >, std::basic_string< char, std::char_traits< char >, std::allocator< char > > > >',
[])
## data-collector.h: void ns3::DataCollector::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3DataOutputInterface_methods(root_module, cls):
## data-output-interface.h: ns3::DataOutputInterface::DataOutputInterface(ns3::DataOutputInterface const & arg0) [copy constructor]
cls.add_constructor([param('ns3::DataOutputInterface const &', 'arg0')])
## data-output-interface.h: ns3::DataOutputInterface::DataOutputInterface() [constructor]
cls.add_constructor([])
## data-output-interface.h: std::string ns3::DataOutputInterface::GetFilePrefix() const [member function]
cls.add_method('GetFilePrefix',
'std::string',
[],
is_const=True)
## data-output-interface.h: void ns3::DataOutputInterface::Output(ns3::DataCollector & dc) [member function]
cls.add_method('Output',
'void',
[param('ns3::DataCollector &', 'dc')],
is_pure_virtual=True, is_virtual=True)
## data-output-interface.h: void ns3::DataOutputInterface::SetFilePrefix(std::string const prefix) [member function]
cls.add_method('SetFilePrefix',
'void',
[param('std::string const', 'prefix')])
## data-output-interface.h: void ns3::DataOutputInterface::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3MinMaxAvgTotalCalculator__Unsigned_int_methods(root_module, cls):
## basic-data-calculators.h: ns3::MinMaxAvgTotalCalculator<unsigned int>::MinMaxAvgTotalCalculator(ns3::MinMaxAvgTotalCalculator<unsigned int> const & arg0) [copy constructor]
cls.add_constructor([param('ns3::MinMaxAvgTotalCalculator< unsigned int > const &', 'arg0')])
## basic-data-calculators.h: ns3::MinMaxAvgTotalCalculator<unsigned int>::MinMaxAvgTotalCalculator() [constructor]
cls.add_constructor([])
## basic-data-calculators.h: void ns3::MinMaxAvgTotalCalculator<unsigned int>::Output(ns3::DataOutputCallback & callback) const [member function]
cls.add_method('Output',
'void',
[param('ns3::DataOutputCallback &', 'callback')],
is_const=True, is_virtual=True)
## basic-data-calculators.h: void ns3::MinMaxAvgTotalCalculator<unsigned int>::Update(unsigned int const i) [member function]
cls.add_method('Update',
'void',
[param('unsigned int const', 'i')])
## basic-data-calculators.h: long int ns3::MinMaxAvgTotalCalculator<unsigned int>::getCount() const [member function]
cls.add_method('getCount',
'long int',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getMax() const [member function]
cls.add_method('getMax',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getMean() const [member function]
cls.add_method('getMean',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getMin() const [member function]
cls.add_method('getMin',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getSqrSum() const [member function]
cls.add_method('getSqrSum',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getStddev() const [member function]
cls.add_method('getStddev',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getSum() const [member function]
cls.add_method('getSum',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: double ns3::MinMaxAvgTotalCalculator<unsigned int>::getVariance() const [member function]
cls.add_method('getVariance',
'double',
[],
is_const=True, is_virtual=True)
## basic-data-calculators.h: void ns3::MinMaxAvgTotalCalculator<unsigned int>::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3OmnetDataOutput_methods(root_module, cls):
## omnet-data-output.h: ns3::OmnetDataOutput::OmnetDataOutput(ns3::OmnetDataOutput const & arg0) [copy constructor]
cls.add_constructor([param('ns3::OmnetDataOutput const &', 'arg0')])
## omnet-data-output.h: ns3::OmnetDataOutput::OmnetDataOutput() [constructor]
cls.add_constructor([])
## omnet-data-output.h: void ns3::OmnetDataOutput::Output(ns3::DataCollector & dc) [member function]
cls.add_method('Output',
'void',
[param('ns3::DataCollector &', 'dc')],
is_virtual=True)
## omnet-data-output.h: void ns3::OmnetDataOutput::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3PacketSizeMinMaxAvgTotalCalculator_methods(root_module, cls):
## packet-data-calculators.h: ns3::PacketSizeMinMaxAvgTotalCalculator::PacketSizeMinMaxAvgTotalCalculator(ns3::PacketSizeMinMaxAvgTotalCalculator const & arg0) [copy constructor]
cls.add_constructor([param('ns3::PacketSizeMinMaxAvgTotalCalculator const &', 'arg0')])
## packet-data-calculators.h: ns3::PacketSizeMinMaxAvgTotalCalculator::PacketSizeMinMaxAvgTotalCalculator() [constructor]
cls.add_constructor([])
## packet-data-calculators.h: void ns3::PacketSizeMinMaxAvgTotalCalculator::FrameUpdate(std::string path, ns3::Ptr<ns3::Packet const> packet, ns3::Mac48Address realto) [member function]
cls.add_method('FrameUpdate',
'void',
[param('std::string', 'path'), param('ns3::Ptr< ns3::Packet const >', 'packet'), param('ns3::Mac48Address', 'realto')])
## packet-data-calculators.h: void ns3::PacketSizeMinMaxAvgTotalCalculator::PacketUpdate(std::string path, ns3::Ptr<ns3::Packet const> packet) [member function]
cls.add_method('PacketUpdate',
'void',
[param('std::string', 'path'), param('ns3::Ptr< ns3::Packet const >', 'packet')])
## packet-data-calculators.h: void ns3::PacketSizeMinMaxAvgTotalCalculator::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3SqliteDataOutput_methods(root_module, cls):
## sqlite-data-output.h: ns3::SqliteDataOutput::SqliteDataOutput(ns3::SqliteDataOutput const & arg0) [copy constructor]
cls.add_constructor([param('ns3::SqliteDataOutput const &', 'arg0')])
## sqlite-data-output.h: ns3::SqliteDataOutput::SqliteDataOutput() [constructor]
cls.add_constructor([])
## sqlite-data-output.h: void ns3::SqliteDataOutput::Output(ns3::DataCollector & dc) [member function]
cls.add_method('Output',
'void',
[param('ns3::DataCollector &', 'dc')],
is_virtual=True)
## sqlite-data-output.h: void ns3::SqliteDataOutput::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3TimeMinMaxAvgTotalCalculator_methods(root_module, cls):
## time-data-calculators.h: ns3::TimeMinMaxAvgTotalCalculator::TimeMinMaxAvgTotalCalculator(ns3::TimeMinMaxAvgTotalCalculator const & arg0) [copy constructor]
cls.add_constructor([param('ns3::TimeMinMaxAvgTotalCalculator const &', 'arg0')])
## time-data-calculators.h: ns3::TimeMinMaxAvgTotalCalculator::TimeMinMaxAvgTotalCalculator() [constructor]
cls.add_constructor([])
## time-data-calculators.h: void ns3::TimeMinMaxAvgTotalCalculator::Output(ns3::DataOutputCallback & callback) const [member function]
cls.add_method('Output',
'void',
[param('ns3::DataOutputCallback &', 'callback')],
is_const=True, is_virtual=True)
## time-data-calculators.h: void ns3::TimeMinMaxAvgTotalCalculator::Update(ns3::Time const i) [member function]
cls.add_method('Update',
'void',
[param('ns3::Time const', 'i')])
## time-data-calculators.h: void ns3::TimeMinMaxAvgTotalCalculator::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3CounterCalculator__Unsigned_int_methods(root_module, cls):
## basic-data-calculators.h: ns3::CounterCalculator<unsigned int>::CounterCalculator(ns3::CounterCalculator<unsigned int> const & arg0) [copy constructor]
cls.add_constructor([param('ns3::CounterCalculator< unsigned int > const &', 'arg0')])
## basic-data-calculators.h: ns3::CounterCalculator<unsigned int>::CounterCalculator() [constructor]
cls.add_constructor([])
## basic-data-calculators.h: unsigned int ns3::CounterCalculator<unsigned int>::GetCount() const [member function]
cls.add_method('GetCount',
'unsigned int',
[],
is_const=True)
## basic-data-calculators.h: void ns3::CounterCalculator<unsigned int>::Output(ns3::DataOutputCallback & callback) const [member function]
cls.add_method('Output',
'void',
[param('ns3::DataOutputCallback &', 'callback')],
is_const=True, is_virtual=True)
## basic-data-calculators.h: void ns3::CounterCalculator<unsigned int>::Update() [member function]
cls.add_method('Update',
'void',
[])
## basic-data-calculators.h: void ns3::CounterCalculator<unsigned int>::Update(unsigned int const i) [member function]
cls.add_method('Update',
'void',
[param('unsigned int const', 'i')])
## basic-data-calculators.h: void ns3::CounterCalculator<unsigned int>::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_Ns3PacketCounterCalculator_methods(root_module, cls):
## packet-data-calculators.h: ns3::PacketCounterCalculator::PacketCounterCalculator(ns3::PacketCounterCalculator const & arg0) [copy constructor]
cls.add_constructor([param('ns3::PacketCounterCalculator const &', 'arg0')])
## packet-data-calculators.h: ns3::PacketCounterCalculator::PacketCounterCalculator() [constructor]
cls.add_constructor([])
## packet-data-calculators.h: void ns3::PacketCounterCalculator::FrameUpdate(std::string path, ns3::Ptr<ns3::Packet const> packet, ns3::Mac48Address realto) [member function]
cls.add_method('FrameUpdate',
'void',
[param('std::string', 'path'), param('ns3::Ptr< ns3::Packet const >', 'packet'), param('ns3::Mac48Address', 'realto')])
## packet-data-calculators.h: void ns3::PacketCounterCalculator::PacketUpdate(std::string path, ns3::Ptr<ns3::Packet const> packet) [member function]
cls.add_method('PacketUpdate',
'void',
[param('std::string', 'path'), param('ns3::Ptr< ns3::Packet const >', 'packet')])
## packet-data-calculators.h: void ns3::PacketCounterCalculator::DoDispose() [member function]
cls.add_method('DoDispose',
'void',
[],
visibility='protected', is_virtual=True)
return
def register_functions(root_module):
module = root_module
## data-calculator.h: bool ns3::isNaN(double x) [free function]
module.add_function('isNaN',
'bool',
[param('double', 'x')])
register_functions_ns3_Config(module.get_submodule('Config'), root_module)
register_functions_ns3_FatalImpl(module.get_submodule('FatalImpl'), root_module)
register_functions_ns3_addressUtils(module.get_submodule('addressUtils'), root_module)
register_functions_ns3_aodv(module.get_submodule('aodv'), root_module)
register_functions_ns3_dot11s(module.get_submodule('dot11s'), root_module)
register_functions_ns3_flame(module.get_submodule('flame'), root_module)
register_functions_ns3_internal(module.get_submodule('internal'), root_module)
register_functions_ns3_olsr(module.get_submodule('olsr'), root_module)
return
def register_functions_ns3_Config(module, root_module):
return
def register_functions_ns3_FatalImpl(module, root_module):
return
def register_functions_ns3_addressUtils(module, root_module):
return
def register_functions_ns3_aodv(module, root_module):
return
def register_functions_ns3_dot11s(module, root_module):
return
def register_functions_ns3_flame(module, root_module):
return
def register_functions_ns3_internal(module, root_module):
return
def register_functions_ns3_olsr(module, root_module):
return
|
gpl-2.0
|
[
504,
1134,
31297,
492,
5673,
12,
3814,
3034,
17111,
12,
1215,
12,
9151,
12,
7246,
533,
12,
14330,
199,
199,
318,
2274,
63,
1313,
8,
578,
304,
272,
1738,
63,
578,
275,
859,
14,
362,
63,
1231,
342,
2286,
925,
666,
13,
1199,
13,
3266,
14,
72,
26,
700,
19,
447,
32690,
2806,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
32690,
2806,
297,
2040,
63,
27904,
29,
549,
9,
272,
925,
666,
13,
28838,
14,
72,
26,
700,
19,
447,
3391,
30364,
10407,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
3391,
30364,
10407,
297,
2040,
63,
27904,
29,
549,
9,
272,
925,
666,
13,
28838,
14,
72,
26,
700,
19,
447,
1451,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1451,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
666,
13,
10946,
14,
72,
26,
700,
19,
447,
1451,
12852,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1451,
12852,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
666,
13,
1199,
13,
3266,
14,
72,
26,
700,
19,
447,
32690,
4267,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
32690,
4267,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
5678,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
29334,
16650,
7316,
20000,
28,
2244,
1109,
30,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
29334,
16650,
7316,
20000,
297,
1978,
63,
3214,
2968,
2244,
1109,
995,
1676,
1524,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
995,
1738,
63,
578,
459,
561,
19,
447,
3391,
30364,
10407,
12121,
272,
925,
30511,
846,
13,
576,
13,
1199,
14,
72,
26,
700,
19,
447,
29197,
846,
32690,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
29197,
846,
32690,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
32690,
4267,
1105,
272,
925,
3644,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
2726,
2320,
29334,
16650,
7316,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
2726,
2320,
29334,
16650,
7316,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
29334,
16650,
7316,
20000,
28,
7381,
1109,
12734,
272,
925,
11723,
13,
576,
13,
1199,
14,
72,
26,
700,
19,
447,
24614,
5333,
32690,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
24614,
5333,
32690,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
32690,
4267,
1105,
272,
925,
900,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
1366,
29334,
16650,
7316,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1366,
29334,
16650,
7316,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
1105,
272,
925,
5678,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
11348,
20000,
28,
2244,
1109,
30,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
11348,
20000,
297,
1978,
63,
3214,
2968,
2244,
1109,
995,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
1105,
272,
925,
3644,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
2726,
11348,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
2726,
11348,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
11348,
20000,
28,
7381,
1109,
12734,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
3445,
283,
561,
19,
447,
5142,
1296,
358,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
690,
7693,
283,
561,
19,
447,
5142,
1296,
13418,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
690,
16749,
283,
561,
19,
447,
5142,
1296,
25899,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
3445,
283,
561,
19,
447,
1451,
20000,
1296,
358,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
690,
7693,
283,
561,
19,
447,
1451,
20000,
1296,
13418,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
690,
16749,
283,
561,
19,
447,
1451,
20000,
1296,
25899,
2286,
925,
11828,
282,
6032,
859,
367,
314,
3231,
4094,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
2028,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
2028,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
481,
7539,
4748,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
27819,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
27819,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
2287,
7535,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
1562,
7535,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
1562,
7535,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
20510,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
12721,
358,
272,
2274,
63,
1313,
63,
561
] |
[
1134,
31297,
492,
5673,
12,
3814,
3034,
17111,
12,
1215,
12,
9151,
12,
7246,
533,
12,
14330,
199,
199,
318,
2274,
63,
1313,
8,
578,
304,
272,
1738,
63,
578,
275,
859,
14,
362,
63,
1231,
342,
2286,
925,
666,
13,
1199,
13,
3266,
14,
72,
26,
700,
19,
447,
32690,
2806,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
32690,
2806,
297,
2040,
63,
27904,
29,
549,
9,
272,
925,
666,
13,
28838,
14,
72,
26,
700,
19,
447,
3391,
30364,
10407,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
3391,
30364,
10407,
297,
2040,
63,
27904,
29,
549,
9,
272,
925,
666,
13,
28838,
14,
72,
26,
700,
19,
447,
1451,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1451,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
666,
13,
10946,
14,
72,
26,
700,
19,
447,
1451,
12852,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1451,
12852,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
666,
13,
1199,
13,
3266,
14,
72,
26,
700,
19,
447,
32690,
4267,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
32690,
4267,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1692,
1105,
272,
925,
5678,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
29334,
16650,
7316,
20000,
28,
2244,
1109,
30,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
29334,
16650,
7316,
20000,
297,
1978,
63,
3214,
2968,
2244,
1109,
995,
1676,
1524,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
995,
1738,
63,
578,
459,
561,
19,
447,
3391,
30364,
10407,
12121,
272,
925,
30511,
846,
13,
576,
13,
1199,
14,
72,
26,
700,
19,
447,
29197,
846,
32690,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
29197,
846,
32690,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
32690,
4267,
1105,
272,
925,
3644,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
2726,
2320,
29334,
16650,
7316,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
2726,
2320,
29334,
16650,
7316,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
29334,
16650,
7316,
20000,
28,
7381,
1109,
12734,
272,
925,
11723,
13,
576,
13,
1199,
14,
72,
26,
700,
19,
447,
24614,
5333,
32690,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
24614,
5333,
32690,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
32690,
4267,
1105,
272,
925,
900,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
1366,
29334,
16650,
7316,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
1366,
29334,
16650,
7316,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
1105,
272,
925,
5678,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
11348,
20000,
28,
2244,
1109,
30,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
11348,
20000,
297,
1978,
63,
3214,
2968,
2244,
1109,
995,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
1451,
20000,
1105,
272,
925,
3644,
13,
576,
13,
13494,
2750,
14,
72,
26,
700,
19,
447,
2726,
11348,
20000,
359,
533,
61,
272,
859,
14,
525,
63,
533,
360,
2726,
11348,
20000,
297,
1676,
29,
1231,
63,
578,
459,
561,
19,
447,
11348,
20000,
28,
7381,
1109,
12734,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
3445,
283,
561,
19,
447,
5142,
1296,
358,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
690,
7693,
283,
561,
19,
447,
5142,
1296,
13418,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
11623,
2418,
447,
14228,
28,
2418,
447,
3852,
28,
2418,
447,
875,
12,
2418,
447,
875,
690,
690,
690,
16749,
283,
561,
19,
447,
5142,
1296,
25899,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
3445,
283,
561,
19,
447,
1451,
20000,
1296,
358,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
690,
7693,
283,
561,
19,
447,
1451,
20000,
1296,
13418,
272,
14330,
14,
525,
63,
466,
63,
3620,
360,
1516,
447,
513,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
11623,
2418,
447,
14228,
28,
700,
19,
447,
2115,
28,
700,
19,
447,
1451,
20000,
690,
690,
690,
16749,
283,
561,
19,
447,
1451,
20000,
1296,
25899,
2286,
925,
11828,
282,
6032,
859,
367,
314,
3231,
4094,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
2028,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
2028,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
481,
7539,
4748,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
27819,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
27819,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
2287,
7535,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
1562,
7535,
358,
272,
2274,
63,
1313,
63,
561,
19,
63,
1562,
7535,
8,
6376,
63,
578,
9,
17635,
925,
11828,
282,
6032,
859,
367,
314,
3231,
20510,
2286,
6032,
63,
578,
275,
859,
14,
525,
63,
5910,
63,
3251,
360,
12721,
358,
272,
2274,
63,
1313,
63,
561,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Vvucinic/Wander
|
venv_2_7/lib/python2.7/site-packages/pexpect/spawnbase.py
|
13
|
19734
|
import codecs
import os
import sys
import re
import errno
from .exceptions import ExceptionPexpect, EOF, TIMEOUT
from .expect import Expecter, searcher_string, searcher_re
PY3 = (sys.version_info[0] >= 3)
text_type = str if PY3 else unicode
class _NullCoder(object):
"""Pass bytes through unchanged."""
@staticmethod
def encode(b, final=False):
return b
@staticmethod
def decode(b, final=False):
return b
class SpawnBase(object):
"""A base class providing the backwards-compatible spawn API for Pexpect.
This should not be instantiated directly: use :class:`pexpect.spawn` or
:class:`pexpect.fdpexpect.fdspawn`.
"""
encoding = None
pid = None
flag_eof = False
def __init__(self, timeout=30, maxread=2000, searchwindowsize=None,
logfile=None, encoding=None, codec_errors='strict'):
self.stdin = sys.stdin
self.stdout = sys.stdout
self.stderr = sys.stderr
self.searcher = None
self.ignorecase = False
self.before = None
self.after = None
self.match = None
self.match_index = None
self.terminated = True
self.exitstatus = None
self.signalstatus = None
# status returned by os.waitpid
self.status = None
# the child file descriptor is initially closed
self.child_fd = -1
self.timeout = timeout
self.delimiter = EOF
self.logfile = logfile
# input from child (read_nonblocking)
self.logfile_read = None
# output to send (send, sendline)
self.logfile_send = None
# max bytes to read at one time into buffer
self.maxread = maxread
# This is the read buffer. See maxread.
self.buffer = bytes() if (encoding is None) else text_type()
# Data before searchwindowsize point is preserved, but not searched.
self.searchwindowsize = searchwindowsize
# Delay used before sending data to child. Time in seconds.
# Most Linux machines don't like this to be below 0.03 (30 ms).
self.delaybeforesend = 0.05
# Used by close() to give kernel time to update process status.
# Time in seconds.
self.delayafterclose = 0.1
# Used by terminate() to give kernel time to update process status.
# Time in seconds.
self.delayafterterminate = 0.1
self.softspace = False
self.name = '<' + repr(self) + '>'
self.closed = True
# Unicode interface
self.encoding = encoding
self.codec_errors = codec_errors
if encoding is None:
# bytes mode (accepts some unicode for backwards compatibility)
self._encoder = self._decoder = _NullCoder()
self.string_type = bytes
self.crlf = b'\r\n'
if PY3:
self.allowed_string_types = (bytes, str)
self.linesep = os.linesep.encode('ascii')
def write_to_stdout(b):
try:
return sys.stdout.buffer.write(b)
except AttributeError:
# If stdout has been replaced, it may not have .buffer
return sys.stdout.write(b.decode('ascii', 'replace'))
self.write_to_stdout = write_to_stdout
else:
self.allowed_string_types = (basestring,) # analysis:ignore
self.linesep = os.linesep
self.write_to_stdout = sys.stdout.write
else:
# unicode mode
self._encoder = codecs.getincrementalencoder(encoding)(codec_errors)
self._decoder = codecs.getincrementaldecoder(encoding)(codec_errors)
self.string_type = text_type
self.crlf = u'\r\n'
self.allowed_string_types = (text_type, )
if PY3:
self.linesep = os.linesep
else:
self.linesep = os.linesep.decode('ascii')
# This can handle unicode in both Python 2 and 3
self.write_to_stdout = sys.stdout.write
def _log(self, s, direction):
if self.logfile is not None:
self.logfile.write(s)
self.logfile.flush()
second_log = self.logfile_send if (direction=='send') else self.logfile_read
if second_log is not None:
second_log.write(s)
second_log.flush()
# For backwards compatibility, in bytes mode (when encoding is None)
# unicode is accepted for send and expect. Unicode mode is strictly unicode
# only.
def _coerce_expect_string(self, s):
if self.encoding is None and not isinstance(s, bytes):
return s.encode('ascii')
return s
def _coerce_send_string(self, s):
if self.encoding is None and not isinstance(s, bytes):
return s.encode('utf-8')
return s
def read_nonblocking(self, size=1, timeout=None):
"""This reads data from the file descriptor.
This is a simple implementation suitable for a regular file. Subclasses using ptys or pipes should override it.
The timeout parameter is ignored.
"""
try:
s = os.read(self.child_fd, size)
except OSError as err:
if err.args[0] == errno.EIO:
# Linux-style EOF
self.flag_eof = True
raise EOF('End Of File (EOF). Exception style platform.')
raise
if s == b'':
# BSD-style EOF
self.flag_eof = True
raise EOF('End Of File (EOF). Empty string style platform.')
s = self._decoder.decode(s, final=False)
self._log(s, 'read')
return s
def _pattern_type_err(self, pattern):
raise TypeError('got {badtype} ({badobj!r}) as pattern, must be one'
' of: {goodtypes}, pexpect.EOF, pexpect.TIMEOUT'\
.format(badtype=type(pattern),
badobj=pattern,
goodtypes=', '.join([str(ast)\
for ast in self.allowed_string_types])
)
)
def compile_pattern_list(self, patterns):
'''This compiles a pattern-string or a list of pattern-strings.
Patterns must be a StringType, EOF, TIMEOUT, SRE_Pattern, or a list of
those. Patterns may also be None which results in an empty list (you
might do this if waiting for an EOF or TIMEOUT condition without
expecting any pattern).
This is used by expect() when calling expect_list(). Thus expect() is
nothing more than::
cpl = self.compile_pattern_list(pl)
return self.expect_list(cpl, timeout)
If you are using expect() within a loop it may be more
efficient to compile the patterns first and then call expect_list().
This avoid calls in a loop to compile_pattern_list()::
cpl = self.compile_pattern_list(my_pattern)
while some_condition:
...
i = self.expect_list(cpl, timeout)
...
'''
if patterns is None:
return []
if not isinstance(patterns, list):
patterns = [patterns]
# Allow dot to match \n
compile_flags = re.DOTALL
if self.ignorecase:
compile_flags = compile_flags | re.IGNORECASE
compiled_pattern_list = []
for idx, p in enumerate(patterns):
if isinstance(p, self.allowed_string_types):
p = self._coerce_expect_string(p)
compiled_pattern_list.append(re.compile(p, compile_flags))
elif p is EOF:
compiled_pattern_list.append(EOF)
elif p is TIMEOUT:
compiled_pattern_list.append(TIMEOUT)
elif isinstance(p, type(re.compile(''))):
compiled_pattern_list.append(p)
else:
self._pattern_type_err(p)
return compiled_pattern_list
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
'''This seeks through the stream until a pattern is matched. The
pattern is overloaded and may take several types. The pattern can be a
StringType, EOF, a compiled re, or a list of any of those types.
Strings will be compiled to re types. This returns the index into the
pattern list. If the pattern was not a list this returns index 0 on a
successful match. This may raise exceptions for EOF or TIMEOUT. To
avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the pattern
list. That will cause expect to match an EOF or TIMEOUT condition
instead of raising an exception.
If you pass a list of patterns and more than one matches, the first
match in the stream is chosen. If more than one pattern matches at that
point, the leftmost in the pattern list is chosen. For example::
# the input is 'foobar'
index = p.expect(['bar', 'foo', 'foobar'])
# returns 1('foo') even though 'foobar' is a "better" match
Please note, however, that buffering can affect this behavior, since
input arrives in unpredictable chunks. For example::
# the input is 'foobar'
index = p.expect(['foobar', 'foo'])
# returns 0('foobar') if all input is available at once,
# but returs 1('foo') if parts of the final 'bar' arrive late
When a match is found for the given pattern, the class instance
attribute *match* becomes an re.MatchObject result. Should an EOF
or TIMEOUT pattern match, then the match attribute will be an instance
of that exception class. The pairing before and after class
instance attributes are views of the data preceding and following
the matching pattern. On general exception, class attribute
*before* is all data received up to the exception, while *match* and
*after* attributes are value None.
When the keyword argument timeout is -1 (default), then TIMEOUT will
raise after the default value specified by the class timeout
attribute. When None, TIMEOUT will not be raised and may block
indefinitely until match.
When the keyword argument searchwindowsize is -1 (default), then the
value specified by the class maxread attribute is used.
A list entry may be EOF or TIMEOUT instead of a string. This will
catch these exceptions and return the index of the list entry instead
of raising the exception. The attribute 'after' will be set to the
exception type. The attribute 'match' will be None. This allows you to
write code like this::
index = p.expect(['good', 'bad', pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
do_something()
elif index == 1:
do_something_else()
elif index == 2:
do_some_other_thing()
elif index == 3:
do_something_completely_different()
instead of code like this::
try:
index = p.expect(['good', 'bad'])
if index == 0:
do_something()
elif index == 1:
do_something_else()
except EOF:
do_some_other_thing()
except TIMEOUT:
do_something_completely_different()
These two forms are equivalent. It all depends on what you want. You
can also just expect the EOF if you are waiting for all output of a
child to finish. For example::
p = pexpect.spawn('/bin/ls')
p.expect(pexpect.EOF)
print p.before
If you are trying to optimize for speed then see expect_list().
On Python 3.4, or Python 3.3 with asyncio installed, passing
``async=True`` will make this return an :mod:`asyncio` coroutine,
which you can yield from to get the same result that this method would
normally give directly. So, inside a coroutine, you can replace this code::
index = p.expect(patterns)
With this non-blocking form::
index = yield from p.expect(patterns, async=True)
'''
compiled_pattern_list = self.compile_pattern_list(pattern)
return self.expect_list(compiled_pattern_list,
timeout, searchwindowsize, async)
def expect_list(self, pattern_list, timeout=-1, searchwindowsize=-1,
async=False):
'''This takes a list of compiled regular expressions and returns the
index into the pattern_list that matched the child output. The list may
also contain EOF or TIMEOUT(which are not compiled regular
expressions). This method is similar to the expect() method except that
expect_list() does not recompile the pattern list on every call. This
may help if you are trying to optimize for speed, otherwise just use
the expect() method. This is called by expect().
Like :meth:`expect`, passing ``async=True`` will make this return an
asyncio coroutine.
'''
if timeout == -1:
timeout = self.timeout
exp = Expecter(self, searcher_re(pattern_list), searchwindowsize)
if async:
from .async import expect_async
return expect_async(exp, timeout)
else:
return exp.expect_loop(timeout)
def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1,
async=False):
'''This is similar to expect(), but uses plain string matching instead
of compiled regular expressions in 'pattern_list'. The 'pattern_list'
may be a string; a list or other sequence of strings; or TIMEOUT and
EOF.
This call might be faster than expect() for two reasons: string
searching is faster than RE matching and it is possible to limit the
search to just the end of the input buffer.
This method is also useful when you don't want to have to worry about
escaping regular expression characters that you want to match.
Like :meth:`expect`, passing ``async=True`` will make this return an
asyncio coroutine.
'''
if timeout == -1:
timeout = self.timeout
if (isinstance(pattern_list, self.allowed_string_types) or
pattern_list in (TIMEOUT, EOF)):
pattern_list = [pattern_list]
def prepare_pattern(pattern):
if pattern in (TIMEOUT, EOF):
return pattern
if isinstance(pattern, self.allowed_string_types):
return self._coerce_expect_string(pattern)
self._pattern_type_err(pattern)
try:
pattern_list = iter(pattern_list)
except TypeError:
self._pattern_type_err(pattern_list)
pattern_list = [prepare_pattern(p) for p in pattern_list]
exp = Expecter(self, searcher_string(pattern_list), searchwindowsize)
if async:
from .async import expect_async
return expect_async(exp, timeout)
else:
return exp.expect_loop(timeout)
def expect_loop(self, searcher, timeout=-1, searchwindowsize=-1):
'''This is the common loop used inside expect. The 'searcher' should be
an instance of searcher_re or searcher_string, which describes how and
what to search for in the input.
See expect() for other arguments, return value and exceptions. '''
exp = Expecter(self, searcher, searchwindowsize)
return exp.expect_loop(timeout)
def read(self, size=-1):
'''This reads at most "size" bytes from the file (less if the read hits
EOF before obtaining size bytes). If the size argument is negative or
omitted, read all data until EOF is reached. The bytes are returned as
a string object. An empty string is returned when EOF is encountered
immediately. '''
if size == 0:
return self.string_type()
if size < 0:
# delimiter default is EOF
self.expect(self.delimiter)
return self.before
# I could have done this more directly by not using expect(), but
# I deliberately decided to couple read() to expect() so that
# I would catch any bugs early and ensure consistant behavior.
# It's a little less efficient, but there is less for me to
# worry about if I have to later modify read() or expect().
# Note, it's OK if size==-1 in the regex. That just means it
# will never match anything in which case we stop only on EOF.
cre = re.compile(self._coerce_expect_string('.{%d}' % size), re.DOTALL)
# delimiter default is EOF
index = self.expect([cre, self.delimiter])
if index == 0:
### FIXME self.before should be ''. Should I assert this?
return self.after
return self.before
def readline(self, size=-1):
'''This reads and returns one entire line. The newline at the end of
line is returned as part of the string, unless the file ends without a
newline. An empty string is returned if EOF is encountered immediately.
This looks for a newline as a CR/LF pair (\\r\\n) even on UNIX because
this is what the pseudotty device returns. So contrary to what you may
expect you will receive newlines as \\r\\n.
If the size argument is 0 then an empty string is returned. In all
other cases the size argument is ignored, which is not standard
behavior for a file-like object. '''
if size == 0:
return self.string_type()
# delimiter default is EOF
index = self.expect([self.crlf, self.delimiter])
if index == 0:
return self.before + self.crlf
else:
return self.before
def __iter__(self):
'''This is to support iterators over a file-like object.
'''
return iter(self.readline, self.string_type())
def readlines(self, sizehint=-1):
'''This reads until EOF using readline() and returns a list containing
the lines thus read. The optional 'sizehint' argument is ignored.
Remember, because this reads until EOF that means the child
process should have closed its stdout. If you run this method on
a child that is still running with its stdout open then this
method will block until it timesout.'''
lines = []
while True:
line = self.readline()
if not line:
break
lines.append(line)
return lines
def fileno(self):
'''Expose file descriptor for a file-like interface
'''
return self.child_fd
def flush(self):
'''This does nothing. It is here to support the interface for a
File-like object. '''
pass
def isatty(self):
"""Overridden in subclass using tty"""
return False
# For 'with spawn(...) as child:'
def __enter__(self):
return self
def __exit__(self, etype, evalue, tb):
# We rely on subclasses to implement close(). If they don't, it's not
# clear what a context manager should do.
self.close()
|
artistic-2.0
|
[
646,
6010,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
7554,
199,
504,
1275,
3924,
492,
2186,
48,
4921,
12,
9027,
12,
29998,
199,
504,
1275,
4921,
492,
1316,
733,
351,
12,
2754,
281,
63,
875,
12,
2754,
281,
63,
264,
199,
199,
4521,
19,
275,
334,
1274,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
9,
199,
505,
63,
466,
275,
620,
340,
7843,
19,
587,
2649,
199,
199,
533,
485,
8849,
3034,
82,
8,
785,
304,
272,
408,
4986,
2783,
4012,
14874,
1041,
272,
768,
4639,
272,
347,
3752,
8,
66,
12,
4242,
29,
797,
304,
267,
372,
330,
339,
768,
4639,
272,
347,
4849,
8,
66,
12,
4242,
29,
797,
304,
267,
372,
330,
199,
199,
533,
17812,
3501,
1563,
8,
785,
304,
272,
408,
33,
1300,
1021,
13070,
314,
8552,
13,
6490,
15187,
3261,
367,
510,
4921,
14,
339,
961,
1077,
440,
506,
17544,
5370,
26,
675,
520,
533,
1705,
16531,
1764,
14,
10212,
64,
503,
272,
520,
533,
1705,
16531,
1764,
14,
2592,
16531,
1764,
14,
14240,
387,
3501,
2313,
272,
408,
272,
2644,
275,
488,
272,
4422,
275,
488,
272,
3305,
63,
11670,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2653,
29,
1216,
12,
1390,
739,
29,
8269,
12,
2754,
3806,
890,
29,
403,
12,
326,
17251,
29,
403,
12,
2644,
29,
403,
12,
9076,
63,
2550,
534,
4768,
735,
267,
291,
14,
6626,
275,
984,
14,
6626,
267,
291,
14,
2703,
275,
984,
14,
2703,
267,
291,
14,
3083,
275,
984,
14,
3083,
398,
291,
14,
24994,
275,
488,
267,
291,
14,
4247,
2546,
275,
756,
267,
291,
14,
5182,
275,
488,
267,
291,
14,
4399,
275,
488,
267,
291,
14,
1431,
275,
488,
267,
291,
14,
1431,
63,
1080,
275,
488,
267,
291,
14,
18375,
275,
715,
267,
291,
14,
2224,
1205,
275,
488,
267,
291,
14,
4653,
1205,
275,
488,
267,
327,
2004,
2138,
701,
747,
14,
2573,
3150,
267,
291,
14,
1205,
275,
488,
267,
327,
314,
1982,
570,
5872,
365,
22801,
6876,
267,
291,
14,
1739,
63,
2592,
275,
446,
17,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
15104,
275,
9027,
267,
291,
14,
12804,
275,
17251,
267,
327,
1324,
687,
1982,
334,
739,
63,
2865,
13091,
9,
267,
291,
14,
12804,
63,
739,
275,
488,
267,
327,
1072,
370,
3222,
334,
2254,
12,
3222,
604,
9,
267,
291,
14,
12804,
63,
2254,
275,
488,
267,
327,
1390,
2783,
370,
1586,
737,
1373,
900,
1901,
3335,
267,
291,
14,
988,
739,
275,
1390,
739,
267,
327,
961,
365,
314,
1586,
3335,
14,
1666,
1390,
739,
14,
267,
291,
14,
2738,
275,
2783,
342,
340,
334,
2991,
365,
488,
9,
587,
1318,
63,
466,
342,
267,
327,
3918,
2544,
2754,
3806,
890,
2376,
365,
17731,
12,
1325,
440,
17543,
14,
267,
291,
14,
1733,
3806,
890,
275,
2754,
3806,
890,
267,
327,
18464,
1187,
1202,
2544,
10209,
666,
370,
1982,
14,
4703,
315,
4696,
14,
267,
327,
17536,
10130,
20601,
2793,
1133,
2839,
642,
370,
506,
5084,
378,
14,
1644,
334,
1216,
6605,
680,
267,
291,
14,
5814,
5182,
2254,
275,
378,
14,
1717,
267,
327,
8051,
701,
4002,
342,
370,
8120,
5114,
900,
370,
1678,
2112,
2004,
14,
267,
327,
4703,
315,
4696,
14,
267,
291,
14,
5814,
4399,
1600,
275,
378,
14,
17,
267,
327,
8051,
701,
15095,
342,
370,
8120,
5114,
900,
370,
1678,
2112,
2004,
14,
267,
327,
4703,
315,
4696,
14,
267,
291,
14,
5814,
4399,
14478,
275,
378,
14,
17,
267,
291,
14,
4617,
2638,
275,
756,
267,
291,
14,
354,
275,
24958,
435,
4700,
8,
277,
9,
435,
21770,
267,
291,
14,
5938,
275,
715,
398,
327,
6140,
3217,
267,
291,
14,
2991,
275,
2644,
267,
291,
14,
9276,
63,
2550,
275,
9076,
63,
2550,
267,
340,
2644,
365,
488,
26,
288,
327,
2783,
818,
334,
27692,
2005,
2649,
367,
8552,
7163,
9,
288,
291,
423,
9347,
275,
291,
423,
8813,
275,
485,
8849,
3034,
82,
342,
288,
291,
14,
875,
63,
466,
275,
2783,
288,
291,
14,
1556,
276,
275,
330,
1154,
82,
60,
78,
7,
288,
340,
7843,
19,
26,
355,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
2394,
12,
620,
9,
355,
291,
14,
19254,
275,
747,
14,
19254,
14,
2143,
360,
4371,
358,
355,
347,
2218,
63,
475,
63,
2703,
8,
66,
304,
490,
862,
26,
717,
372,
984,
14,
2703,
14,
2738,
14,
952,
8,
66,
9,
490,
871,
4281,
26,
717,
327,
982,
3839,
965,
2757,
8717,
12,
652,
1443,
440,
1172,
1275,
2738,
717,
372,
984,
14,
2703,
14,
952,
8,
66,
14,
2708,
360,
4371,
297,
283,
1814,
1333,
355,
291,
14,
952,
63,
475,
63,
2703,
275,
2218,
63,
475,
63,
2703,
288,
587,
26,
355,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
17628,
4258,
221,
327,
11284,
26,
4247,
355,
291,
14,
19254,
275,
747,
14,
19254,
355,
291,
14,
952,
63,
475,
63,
2703,
275,
984,
14,
2703,
14,
952,
267,
587,
26,
288,
327,
2649,
818,
288,
291,
423,
9347,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
5130,
9276,
63,
2550,
9,
288,
291,
423,
8813,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
5130,
9276,
63,
2550,
9,
288,
291,
14,
875,
63,
466,
275,
1318,
63,
466,
288,
291,
14,
1556,
276,
275,
399,
1154,
82,
60,
78,
7,
288,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
505,
63,
466,
12,
776,
288,
340,
7843,
19,
26,
355,
291,
14,
19254,
275,
747,
14,
19254,
288,
587,
26,
355,
291,
14,
19254,
275,
747,
14,
19254,
14,
2708,
360,
4371,
358,
288,
327,
961,
883,
2429,
2649,
315,
3865,
2018,
499,
436,
650,
288,
291,
14,
952,
63,
475,
63,
2703,
275,
984,
14,
2703,
14,
952,
339,
347,
485,
793,
8,
277,
12,
308,
12,
7581,
304,
267,
340,
291,
14,
12804,
365,
440,
488,
26,
288,
291,
14,
12804,
14,
952,
8,
83,
9,
288,
291,
14,
12804,
14,
4939,
342,
267,
3499,
63,
793,
275,
291,
14,
12804,
63,
2254,
340,
334,
6874,
6803,
2254,
358,
587,
291,
14,
12804,
63,
739,
267,
340,
3499
] |
[
6010,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
7554,
199,
504,
1275,
3924,
492,
2186,
48,
4921,
12,
9027,
12,
29998,
199,
504,
1275,
4921,
492,
1316,
733,
351,
12,
2754,
281,
63,
875,
12,
2754,
281,
63,
264,
199,
199,
4521,
19,
275,
334,
1274,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
9,
199,
505,
63,
466,
275,
620,
340,
7843,
19,
587,
2649,
199,
199,
533,
485,
8849,
3034,
82,
8,
785,
304,
272,
408,
4986,
2783,
4012,
14874,
1041,
272,
768,
4639,
272,
347,
3752,
8,
66,
12,
4242,
29,
797,
304,
267,
372,
330,
339,
768,
4639,
272,
347,
4849,
8,
66,
12,
4242,
29,
797,
304,
267,
372,
330,
199,
199,
533,
17812,
3501,
1563,
8,
785,
304,
272,
408,
33,
1300,
1021,
13070,
314,
8552,
13,
6490,
15187,
3261,
367,
510,
4921,
14,
339,
961,
1077,
440,
506,
17544,
5370,
26,
675,
520,
533,
1705,
16531,
1764,
14,
10212,
64,
503,
272,
520,
533,
1705,
16531,
1764,
14,
2592,
16531,
1764,
14,
14240,
387,
3501,
2313,
272,
408,
272,
2644,
275,
488,
272,
4422,
275,
488,
272,
3305,
63,
11670,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2653,
29,
1216,
12,
1390,
739,
29,
8269,
12,
2754,
3806,
890,
29,
403,
12,
326,
17251,
29,
403,
12,
2644,
29,
403,
12,
9076,
63,
2550,
534,
4768,
735,
267,
291,
14,
6626,
275,
984,
14,
6626,
267,
291,
14,
2703,
275,
984,
14,
2703,
267,
291,
14,
3083,
275,
984,
14,
3083,
398,
291,
14,
24994,
275,
488,
267,
291,
14,
4247,
2546,
275,
756,
267,
291,
14,
5182,
275,
488,
267,
291,
14,
4399,
275,
488,
267,
291,
14,
1431,
275,
488,
267,
291,
14,
1431,
63,
1080,
275,
488,
267,
291,
14,
18375,
275,
715,
267,
291,
14,
2224,
1205,
275,
488,
267,
291,
14,
4653,
1205,
275,
488,
267,
327,
2004,
2138,
701,
747,
14,
2573,
3150,
267,
291,
14,
1205,
275,
488,
267,
327,
314,
1982,
570,
5872,
365,
22801,
6876,
267,
291,
14,
1739,
63,
2592,
275,
446,
17,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
15104,
275,
9027,
267,
291,
14,
12804,
275,
17251,
267,
327,
1324,
687,
1982,
334,
739,
63,
2865,
13091,
9,
267,
291,
14,
12804,
63,
739,
275,
488,
267,
327,
1072,
370,
3222,
334,
2254,
12,
3222,
604,
9,
267,
291,
14,
12804,
63,
2254,
275,
488,
267,
327,
1390,
2783,
370,
1586,
737,
1373,
900,
1901,
3335,
267,
291,
14,
988,
739,
275,
1390,
739,
267,
327,
961,
365,
314,
1586,
3335,
14,
1666,
1390,
739,
14,
267,
291,
14,
2738,
275,
2783,
342,
340,
334,
2991,
365,
488,
9,
587,
1318,
63,
466,
342,
267,
327,
3918,
2544,
2754,
3806,
890,
2376,
365,
17731,
12,
1325,
440,
17543,
14,
267,
291,
14,
1733,
3806,
890,
275,
2754,
3806,
890,
267,
327,
18464,
1187,
1202,
2544,
10209,
666,
370,
1982,
14,
4703,
315,
4696,
14,
267,
327,
17536,
10130,
20601,
2793,
1133,
2839,
642,
370,
506,
5084,
378,
14,
1644,
334,
1216,
6605,
680,
267,
291,
14,
5814,
5182,
2254,
275,
378,
14,
1717,
267,
327,
8051,
701,
4002,
342,
370,
8120,
5114,
900,
370,
1678,
2112,
2004,
14,
267,
327,
4703,
315,
4696,
14,
267,
291,
14,
5814,
4399,
1600,
275,
378,
14,
17,
267,
327,
8051,
701,
15095,
342,
370,
8120,
5114,
900,
370,
1678,
2112,
2004,
14,
267,
327,
4703,
315,
4696,
14,
267,
291,
14,
5814,
4399,
14478,
275,
378,
14,
17,
267,
291,
14,
4617,
2638,
275,
756,
267,
291,
14,
354,
275,
24958,
435,
4700,
8,
277,
9,
435,
21770,
267,
291,
14,
5938,
275,
715,
398,
327,
6140,
3217,
267,
291,
14,
2991,
275,
2644,
267,
291,
14,
9276,
63,
2550,
275,
9076,
63,
2550,
267,
340,
2644,
365,
488,
26,
288,
327,
2783,
818,
334,
27692,
2005,
2649,
367,
8552,
7163,
9,
288,
291,
423,
9347,
275,
291,
423,
8813,
275,
485,
8849,
3034,
82,
342,
288,
291,
14,
875,
63,
466,
275,
2783,
288,
291,
14,
1556,
276,
275,
330,
1154,
82,
60,
78,
7,
288,
340,
7843,
19,
26,
355,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
2394,
12,
620,
9,
355,
291,
14,
19254,
275,
747,
14,
19254,
14,
2143,
360,
4371,
358,
355,
347,
2218,
63,
475,
63,
2703,
8,
66,
304,
490,
862,
26,
717,
372,
984,
14,
2703,
14,
2738,
14,
952,
8,
66,
9,
490,
871,
4281,
26,
717,
327,
982,
3839,
965,
2757,
8717,
12,
652,
1443,
440,
1172,
1275,
2738,
717,
372,
984,
14,
2703,
14,
952,
8,
66,
14,
2708,
360,
4371,
297,
283,
1814,
1333,
355,
291,
14,
952,
63,
475,
63,
2703,
275,
2218,
63,
475,
63,
2703,
288,
587,
26,
355,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
17628,
4258,
221,
327,
11284,
26,
4247,
355,
291,
14,
19254,
275,
747,
14,
19254,
355,
291,
14,
952,
63,
475,
63,
2703,
275,
984,
14,
2703,
14,
952,
267,
587,
26,
288,
327,
2649,
818,
288,
291,
423,
9347,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
5130,
9276,
63,
2550,
9,
288,
291,
423,
8813,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
5130,
9276,
63,
2550,
9,
288,
291,
14,
875,
63,
466,
275,
1318,
63,
466,
288,
291,
14,
1556,
276,
275,
399,
1154,
82,
60,
78,
7,
288,
291,
14,
6541,
63,
875,
63,
1313,
275,
334,
505,
63,
466,
12,
776,
288,
340,
7843,
19,
26,
355,
291,
14,
19254,
275,
747,
14,
19254,
288,
587,
26,
355,
291,
14,
19254,
275,
747,
14,
19254,
14,
2708,
360,
4371,
358,
288,
327,
961,
883,
2429,
2649,
315,
3865,
2018,
499,
436,
650,
288,
291,
14,
952,
63,
475,
63,
2703,
275,
984,
14,
2703,
14,
952,
339,
347,
485,
793,
8,
277,
12,
308,
12,
7581,
304,
267,
340,
291,
14,
12804,
365,
440,
488,
26,
288,
291,
14,
12804,
14,
952,
8,
83,
9,
288,
291,
14,
12804,
14,
4939,
342,
267,
3499,
63,
793,
275,
291,
14,
12804,
63,
2254,
340,
334,
6874,
6803,
2254,
358,
587,
291,
14,
12804,
63,
739,
267,
340,
3499,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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