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
|
|---|---|---|---|---|---|---|---|---|
jorik041/scikit-learn
|
examples/svm/plot_svm_regression.py
|
249
|
1451
|
"""
===================================================================
Support Vector Regression (SVR) using linear and non-linear kernels
===================================================================
Toy example of 1D regression using linear, polynomial and RBF kernels.
"""
print(__doc__)
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
###############################################################################
# Generate sample data
X = np.sort(5 * np.random.rand(40, 1), axis=0)
y = np.sin(X).ravel()
###############################################################################
# Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))
###############################################################################
# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, y).predict(X)
y_lin = svr_lin.fit(X, y).predict(X)
y_poly = svr_poly.fit(X, y).predict(X)
###############################################################################
# look at the results
plt.scatter(X, y, c='k', label='data')
plt.hold('on')
plt.plot(X, y_rbf, c='g', label='RBF model')
plt.plot(X, y_lin, c='r', label='Linear model')
plt.plot(X, y_poly, c='b', label='Polynomial model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()
|
bsd-3-clause
|
[
624,
199,
5695,
5918,
199,
11532,
11388,
13262,
334,
4985,
50,
9,
1808,
7798,
436,
2222,
13,
6676,
26091,
199,
5695,
5918,
199,
199,
1378,
89,
2893,
402,
413,
36,
10864,
1808,
7798,
12,
11849,
436,
820,
12659,
26091,
14,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
2680,
465,
980,
199,
504,
6357,
14,
16820,
492,
14056,
50,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
11490,
199,
3,
7958,
2690,
666,
199,
56,
275,
980,
14,
3191,
8,
21,
627,
980,
14,
2355,
14,
3759,
8,
2167,
12,
413,
395,
3114,
29,
16,
9,
199,
89,
275,
980,
14,
5911,
8,
56,
680,
11186,
342,
199,
199,
11490,
199,
3,
2654,
11145,
370,
4545,
199,
89,
10345,
21,
61,
847,
650,
627,
334,
16,
14,
21,
446,
980,
14,
2355,
14,
3759,
8,
24,
430,
199,
199,
11490,
199,
3,
25971,
10864,
1402,
199,
2772,
82,
63,
25853,
275,
14056,
50,
8,
4989,
534,
25853,
297,
445,
29,
17,
69,
19,
12,
10169,
29,
16,
14,
17,
9,
199,
2772,
82,
63,
472,
275,
14056,
50,
8,
4989,
534,
6676,
297,
445,
29,
17,
69,
19,
9,
199,
2772,
82,
63,
6023,
275,
14056,
50,
8,
4989,
534,
6023,
297,
445,
29,
17,
69,
19,
12,
13666,
29,
18,
9,
199,
89,
63,
25853,
275,
308,
10922,
63,
25853,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
89,
63,
472,
275,
308,
10922,
63,
472,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
89,
63,
6023,
275,
308,
10922,
63,
6023,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
199,
11490,
199,
3,
3648,
737,
314,
2058,
199,
6003,
14,
13512,
8,
56,
12,
612,
12,
286,
534,
75,
297,
1768,
534,
576,
358,
199,
6003,
14,
12239,
360,
265,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
25853,
12,
286,
534,
71,
297,
1768,
534,
50,
12659,
1402,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
472,
12,
286,
534,
82,
297,
1768,
534,
10608,
1402,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
6023,
12,
286,
534,
66,
297,
1768,
534,
5858,
8887,
1402,
358,
199,
6003,
14,
14168,
360,
576,
358,
199,
6003,
14,
13849,
360,
1375,
358,
199,
6003,
14,
1213,
360,
11532,
11388,
13262,
358,
199,
6003,
14,
10231,
342,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
5695,
5918,
199,
11532,
11388,
13262,
334,
4985,
50,
9,
1808,
7798,
436,
2222,
13,
6676,
26091,
199,
5695,
5918,
199,
199,
1378,
89,
2893,
402,
413,
36,
10864,
1808,
7798,
12,
11849,
436,
820,
12659,
26091,
14,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
2680,
465,
980,
199,
504,
6357,
14,
16820,
492,
14056,
50,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
11490,
199,
3,
7958,
2690,
666,
199,
56,
275,
980,
14,
3191,
8,
21,
627,
980,
14,
2355,
14,
3759,
8,
2167,
12,
413,
395,
3114,
29,
16,
9,
199,
89,
275,
980,
14,
5911,
8,
56,
680,
11186,
342,
199,
199,
11490,
199,
3,
2654,
11145,
370,
4545,
199,
89,
10345,
21,
61,
847,
650,
627,
334,
16,
14,
21,
446,
980,
14,
2355,
14,
3759,
8,
24,
430,
199,
199,
11490,
199,
3,
25971,
10864,
1402,
199,
2772,
82,
63,
25853,
275,
14056,
50,
8,
4989,
534,
25853,
297,
445,
29,
17,
69,
19,
12,
10169,
29,
16,
14,
17,
9,
199,
2772,
82,
63,
472,
275,
14056,
50,
8,
4989,
534,
6676,
297,
445,
29,
17,
69,
19,
9,
199,
2772,
82,
63,
6023,
275,
14056,
50,
8,
4989,
534,
6023,
297,
445,
29,
17,
69,
19,
12,
13666,
29,
18,
9,
199,
89,
63,
25853,
275,
308,
10922,
63,
25853,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
89,
63,
472,
275,
308,
10922,
63,
472,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
89,
63,
6023,
275,
308,
10922,
63,
6023,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
199,
199,
11490,
199,
3,
3648,
737,
314,
2058,
199,
6003,
14,
13512,
8,
56,
12,
612,
12,
286,
534,
75,
297,
1768,
534,
576,
358,
199,
6003,
14,
12239,
360,
265,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
25853,
12,
286,
534,
71,
297,
1768,
534,
50,
12659,
1402,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
472,
12,
286,
534,
82,
297,
1768,
534,
10608,
1402,
358,
199,
6003,
14,
2798,
8,
56,
12,
612,
63,
6023,
12,
286,
534,
66,
297,
1768,
534,
5858,
8887,
1402,
358,
199,
6003,
14,
14168,
360,
576,
358,
199,
6003,
14,
13849,
360,
1375,
358,
199,
6003,
14,
1213,
360,
11532,
11388,
13262,
358,
199,
6003,
14,
10231,
342,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
adamchainz/ansible
|
lib/ansible/modules/cloud/cloudstack/cs_portforward.py
|
51
|
14301
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2015, René Moser <mail@renemoser.net>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: cs_portforward
short_description: Manages port forwarding rules on Apache CloudStack based clouds.
description:
- Create, update and remove port forwarding rules.
version_added: '2.0'
author: "René Moser (@resmo)"
options:
ip_address:
description:
- Public IP address the rule is assigned to.
required: true
vm:
description:
- Name of virtual machine which we make the port forwarding rule for.
- Required if C(state=present).
required: false
default: null
state:
description:
- State of the port forwarding rule.
required: false
default: 'present'
choices: [ 'present', 'absent' ]
protocol:
description:
- Protocol of the port forwarding rule.
required: false
default: 'tcp'
choices: [ 'tcp', 'udp' ]
public_port:
description:
- Start public port for this rule.
required: true
public_end_port:
description:
- End public port for this rule.
- If not specified equal C(public_port).
required: false
default: null
private_port:
description:
- Start private port for this rule.
required: true
private_end_port:
description:
- End private port for this rule.
- If not specified equal C(private_port).
required: false
default: null
open_firewall:
description:
- Whether the firewall rule for public port should be created, while creating the new rule.
- Use M(cs_firewall) for managing firewall rules.
required: false
default: false
vm_guest_ip:
description:
- VM guest NIC secondary IP address for the port forwarding rule.
required: false
default: false
network:
description:
- Name of the network.
required: false
default: null
version_added: "2.3"
vpc:
description:
- Name of the VPC.
required: false
default: null
version_added: "2.3"
domain:
description:
- Domain the C(vm) is related to.
required: false
default: null
account:
description:
- Account the C(vm) is related to.
required: false
default: null
project:
description:
- Name of the project the C(vm) is located in.
required: false
default: null
zone:
description:
- Name of the zone in which the virtual machine is in.
- If not set, default zone is used.
required: false
default: null
poll_async:
description:
- Poll async jobs until job has finished.
required: false
default: true
tags:
description:
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
- "To delete all tags, set a empty list e.g. C(tags: [])."
required: false
default: null
aliases: [ 'tag' ]
version_added: "2.4"
extends_documentation_fragment: cloudstack
'''
EXAMPLES = '''
# 1.2.3.4:80 -> web01:8080
- local_action:
module: cs_portforward
ip_address: 1.2.3.4
vm: web01
public_port: 80
private_port: 8080
# forward SSH and open firewall
- local_action:
module: cs_portforward
ip_address: '{{ public_ip }}'
vm: '{{ inventory_hostname }}'
public_port: '{{ ansible_ssh_port }}'
private_port: 22
open_firewall: true
# forward DNS traffic, but do not open firewall
- local_action:
module: cs_portforward
ip_address: 1.2.3.4
vm: '{{ inventory_hostname }}'
public_port: 53
private_port: 53
protocol: udp
# remove ssh port forwarding
- local_action:
module: cs_portforward
ip_address: 1.2.3.4
public_port: 22
private_port: 22
state: absent
'''
RETURN = '''
---
id:
description: UUID of the public IP address.
returned: success
type: string
sample: a6f7a5fc-43f8-11e5-a151-feff819cdc9f
ip_address:
description: Public IP address.
returned: success
type: string
sample: 1.2.3.4
protocol:
description: Protocol.
returned: success
type: string
sample: tcp
private_port:
description: Start port on the virtual machine's IP address.
returned: success
type: int
sample: 80
private_end_port:
description: End port on the virtual machine's IP address.
returned: success
type: int
public_port:
description: Start port on the public IP address.
returned: success
type: int
sample: 80
public_end_port:
description: End port on the public IP address.
returned: success
type: int
sample: 80
tags:
description: Tags related to the port forwarding.
returned: success
type: list
sample: []
vm_name:
description: Name of the virtual machine.
returned: success
type: string
sample: web-01
vm_display_name:
description: Display name of the virtual machine.
returned: success
type: string
sample: web-01
vm_guest_ip:
description: IP of the virtual machine.
returned: success
type: string
sample: 10.101.65.152
vpc:
description: Name of the VPC.
returned: success
type: string
sample: my_vpc
network:
description: Name of the network.
returned: success
type: string
sample: dmz
'''
# import cloudstack common
from ansible.module_utils.cloudstack import *
class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
def __init__(self, module):
super(AnsibleCloudStackPortforwarding, self).__init__(module)
self.returns = {
'virtualmachinedisplayname': 'vm_display_name',
'virtualmachinename': 'vm_name',
'ipaddress': 'ip_address',
'vmguestip': 'vm_guest_ip',
'publicip': 'public_ip',
'protocol': 'protocol',
}
# these values will be casted to int
self.returns_to_int = {
'publicport': 'public_port',
'publicendport': 'public_end_port',
'privateport': 'private_port',
'privateendport': 'private_end_port',
}
self.portforwarding_rule = None
def get_portforwarding_rule(self):
if not self.portforwarding_rule:
protocol = self.module.params.get('protocol')
public_port = self.module.params.get('public_port')
public_end_port = self.get_or_fallback('public_end_port', 'public_port')
private_port = self.module.params.get('private_port')
private_end_port = self.get_or_fallback('private_end_port', 'private_port')
args = {}
args['ipaddressid'] = self.get_ip_address(key='id')
args['account'] = self.get_account(key='name')
args['domainid'] = self.get_domain(key='id')
args['projectid'] = self.get_project(key='id')
portforwarding_rules = self.cs.listPortForwardingRules(**args)
if portforwarding_rules and 'portforwardingrule' in portforwarding_rules:
for rule in portforwarding_rules['portforwardingrule']:
if (protocol == rule['protocol'] and
public_port == int(rule['publicport'])):
self.portforwarding_rule = rule
break
return self.portforwarding_rule
def present_portforwarding_rule(self):
portforwarding_rule = self.get_portforwarding_rule()
if portforwarding_rule:
portforwarding_rule = self.update_portforwarding_rule(portforwarding_rule)
else:
portforwarding_rule = self.create_portforwarding_rule()
if portforwarding_rule:
portforwarding_rule = self.ensure_tags(resource=portforwarding_rule, resource_type='PortForwardingRule')
self.portforwarding_rule=portforwarding_rule
return portforwarding_rule
def create_portforwarding_rule(self):
args = {}
args['protocol'] = self.module.params.get('protocol')
args['publicport'] = self.module.params.get('public_port')
args['publicendport'] = self.get_or_fallback('public_end_port', 'public_port')
args['privateport'] = self.module.params.get('private_port')
args['privateendport'] = self.get_or_fallback('private_end_port', 'private_port')
args['openfirewall'] = self.module.params.get('open_firewall')
args['vmguestip'] = self.get_vm_guest_ip()
args['ipaddressid'] = self.get_ip_address(key='id')
args['virtualmachineid'] = self.get_vm(key='id')
args['account'] = self.get_account(key='name')
args['domainid'] = self.get_domain(key='id')
args['networkid'] = self.get_network(key='id')
portforwarding_rule = None
self.result['changed'] = True
if not self.module.check_mode:
portforwarding_rule = self.cs.createPortForwardingRule(**args)
poll_async = self.module.params.get('poll_async')
if poll_async:
portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule')
return portforwarding_rule
def update_portforwarding_rule(self, portforwarding_rule):
args = {}
args['protocol'] = self.module.params.get('protocol')
args['publicport'] = self.module.params.get('public_port')
args['publicendport'] = self.get_or_fallback('public_end_port', 'public_port')
args['privateport'] = self.module.params.get('private_port')
args['privateendport'] = self.get_or_fallback('private_end_port', 'private_port')
args['vmguestip'] = self.get_vm_guest_ip()
args['ipaddressid'] = self.get_ip_address(key='id')
args['virtualmachineid'] = self.get_vm(key='id')
args['networkid'] = self.get_network(key='id')
if self.has_changed(args, portforwarding_rule):
self.result['changed'] = True
if not self.module.check_mode:
# API broken in 4.2.1?, workaround using remove/create instead of update
# portforwarding_rule = self.cs.updatePortForwardingRule(**args)
self.absent_portforwarding_rule()
portforwarding_rule = self.cs.createPortForwardingRule(**args)
poll_async = self.module.params.get('poll_async')
if poll_async:
portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule')
return portforwarding_rule
def absent_portforwarding_rule(self):
portforwarding_rule = self.get_portforwarding_rule()
if portforwarding_rule:
self.result['changed'] = True
args = {}
args['id'] = portforwarding_rule['id']
if not self.module.check_mode:
res = self.cs.deletePortForwardingRule(**args)
poll_async = self.module.params.get('poll_async')
if poll_async:
self.poll_job(res, 'portforwardingrule')
return portforwarding_rule
def get_result(self, portforwarding_rule):
super(AnsibleCloudStackPortforwarding, self).get_result(portforwarding_rule)
network_name = self.get_network(key='name')
if network_name:
self.result['network'] = network_name
vpc_name = self.get_vpc(key='name')
if vpc_name:
self.result['vpc'] = vpc_name
if portforwarding_rule:
for search_key, return_key in self.returns_to_int.items():
if search_key in portforwarding_rule:
self.result[return_key] = int(portforwarding_rule[search_key])
return self.result
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
ip_address = dict(required=True),
protocol= dict(choices=['tcp', 'udp'], default='tcp'),
public_port = dict(type='int', required=True),
public_end_port = dict(type='int', default=None),
private_port = dict(type='int', required=True),
private_end_port = dict(type='int', default=None),
state = dict(choices=['present', 'absent'], default='present'),
open_firewall = dict(type='bool', default=False),
vm_guest_ip = dict(default=None),
vm = dict(default=None),
vpc = dict(default=None),
network = dict(default=None),
zone = dict(default=None),
domain = dict(default=None),
account = dict(default=None),
project = dict(default=None),
poll_async = dict(type='bool', default=True),
tags=dict(type='list', aliases=['tag'], default=None),
))
module = AnsibleModule(
argument_spec=argument_spec,
required_together=cs_required_together(),
supports_check_mode=True
)
try:
acs_pf = AnsibleCloudStackPortforwarding(module)
state = module.params.get('state')
if state in ['absent']:
pf_rule = acs_pf.absent_portforwarding_rule()
else:
pf_rule = acs_pf.present_portforwarding_rule()
result = acs_pf.get_result(pf_rule)
except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**result)
# import module snippets
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,
3,
199,
3,
334,
67,
9,
6900,
12,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7117,
63,
719,
6688,
199,
3612,
63,
1802,
26,
21612,
1844,
24119,
4713,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
1844,
24119,
4713,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
3384,
63,
1562,
26,
272,
1369,
26,
489,
446,
1684,
3531,
2287,
314,
2332,
365,
7943,
370,
14,
272,
1415,
26,
2549,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
5791,
6844,
1314,
781,
1852,
314,
1844,
24119,
2332,
367,
14,
489,
446,
11105,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
4113,
26,
272,
1369,
26,
489,
446,
11557,
402,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
359,
283,
8815,
297,
283,
15036,
7,
1622,
523,
4575,
63,
719,
26,
272,
1369,
26,
489,
446,
7707,
4575,
1844,
367,
642,
2332,
14,
272,
1415,
26,
2549,
523,
4575,
63,
500,
63,
719,
26,
272,
1369,
26,
489,
446,
9599,
4575,
1844,
367,
642,
2332,
14,
489,
446,
982,
440,
2013,
4472,
445,
8,
3455,
63,
719,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5726,
63,
719,
26,
272,
1369,
26,
489,
446,
7707,
5726,
1844,
367,
642,
2332,
14,
272,
1415,
26,
2549,
523,
5726,
63,
500,
63,
719,
26,
272,
1369,
26,
489,
446,
9599,
5726,
1844,
367,
642,
2332,
14,
489,
446,
982,
440,
2013,
4472,
445,
8,
4239,
63,
719,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1551,
63,
10794,
26,
272,
1369,
26,
489,
446,
7480,
314,
12042,
2332,
367,
4575,
1844,
1077,
506,
2737,
12,
1830,
6425,
314,
892,
2332,
14,
489,
446,
3645,
603,
8,
1259,
63,
10794,
9,
367,
28453,
12042,
4713,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
7525,
13980,
31265,
13851,
3531,
2287,
367,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
523,
2784,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2784,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
12830,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
19209,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
445,
8,
2611,
9,
365,
16180,
315,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
5791,
6844,
365,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
1415,
26,
3055,
272,
849,
26,
2549,
523,
3762,
26,
272,
1369,
26,
489,
446,
3820,
402,
3762,
14,
25204,
787,
282,
769,
402,
11196,
9445,
2883,
445,
8,
498,
9,
436,
445,
8,
585,
680,
489,
446,
298,
1378,
3145,
1006,
3762,
12,
663,
282,
2701,
769,
325,
14,
71,
14,
445,
8,
2969,
26,
3073,
2122,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
359,
283,
1450,
7,
1622,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
413,
14,
18,
14,
19,
14,
20,
26,
1257,
1035,
3330,
614,
26,
15844,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
719,
6688,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
4169,
26,
3330,
614,
272,
4575,
63,
719,
26,
5939,
272,
5726,
63,
719,
26,
30220,
199,
199,
3,
7568,
12027,
436,
1551,
12042,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
719,
6688,
272,
3384,
63,
1562,
26,
11400,
4575,
63,
711,
16339,
272,
4169
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
6900,
12,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7117,
63,
719,
6688,
199,
3612,
63,
1802,
26,
21612,
1844,
24119,
4713,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
1844,
24119,
4713,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
3384,
63,
1562,
26,
272,
1369,
26,
489,
446,
1684,
3531,
2287,
314,
2332,
365,
7943,
370,
14,
272,
1415,
26,
2549,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
5791,
6844,
1314,
781,
1852,
314,
1844,
24119,
2332,
367,
14,
489,
446,
11105,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
4113,
26,
272,
1369,
26,
489,
446,
11557,
402,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
359,
283,
8815,
297,
283,
15036,
7,
1622,
523,
4575,
63,
719,
26,
272,
1369,
26,
489,
446,
7707,
4575,
1844,
367,
642,
2332,
14,
272,
1415,
26,
2549,
523,
4575,
63,
500,
63,
719,
26,
272,
1369,
26,
489,
446,
9599,
4575,
1844,
367,
642,
2332,
14,
489,
446,
982,
440,
2013,
4472,
445,
8,
3455,
63,
719,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5726,
63,
719,
26,
272,
1369,
26,
489,
446,
7707,
5726,
1844,
367,
642,
2332,
14,
272,
1415,
26,
2549,
523,
5726,
63,
500,
63,
719,
26,
272,
1369,
26,
489,
446,
9599,
5726,
1844,
367,
642,
2332,
14,
489,
446,
982,
440,
2013,
4472,
445,
8,
4239,
63,
719,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1551,
63,
10794,
26,
272,
1369,
26,
489,
446,
7480,
314,
12042,
2332,
367,
4575,
1844,
1077,
506,
2737,
12,
1830,
6425,
314,
892,
2332,
14,
489,
446,
3645,
603,
8,
1259,
63,
10794,
9,
367,
28453,
12042,
4713,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
7525,
13980,
31265,
13851,
3531,
2287,
367,
314,
1844,
24119,
2332,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
523,
2784,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2784,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
12830,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
19209,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
445,
8,
2611,
9,
365,
4048,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
445,
8,
2611,
9,
365,
16180,
315,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
5791,
6844,
365,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
1415,
26,
3055,
272,
849,
26,
2549,
523,
3762,
26,
272,
1369,
26,
489,
446,
3820,
402,
3762,
14,
25204,
787,
282,
769,
402,
11196,
9445,
2883,
445,
8,
498,
9,
436,
445,
8,
585,
680,
489,
446,
298,
1378,
3145,
1006,
3762,
12,
663,
282,
2701,
769,
325,
14,
71,
14,
445,
8,
2969,
26,
3073,
2122,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
359,
283,
1450,
7,
1622,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
413,
14,
18,
14,
19,
14,
20,
26,
1257,
1035,
3330,
614,
26,
15844,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
719,
6688,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
4169,
26,
3330,
614,
272,
4575,
63,
719,
26,
5939,
272,
5726,
63,
719,
26,
30220,
199,
199,
3,
7568,
12027,
436,
1551,
12042,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
719,
6688,
272,
3384,
63,
1562,
26,
11400,
4575,
63,
711,
16339,
272,
4169,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
christophlsa/odoo
|
openerp/report/misc.py
|
458
|
1425
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from pychart import *
colorline = [color.T(r=((r+3) % 11)/10.0,
g=((g+6) % 11)/10.0,
b=((b+9) % 11)/10.0)
for r in range(11) for g in range(11) for b in range(11)]
def choice_colors(n):
if n:
return colorline[0:-1:len(colorline)/n]
return []
if __name__=='__main__':
print choice_colors(10)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
1134,
9019,
492,
627,
199,
199,
2326,
604,
275,
359,
2326,
14,
52,
8,
82,
31934,
82,
11,
19,
9,
450,
4119,
2447,
709,
14,
16,
12,
2151,
486,
31934,
71,
11,
22,
9,
450,
4119,
2447,
709,
14,
16,
12,
2151,
330,
31934,
66,
11,
25,
9,
450,
4119,
2447,
709,
14,
16,
9,
1467,
367,
519,
315,
1425,
8,
845,
9,
367,
486,
315,
1425,
8,
845,
9,
367,
330,
315,
1425,
8,
845,
1874,
199,
199,
318,
7141,
63,
7120,
8,
78,
304,
272,
340,
302,
26,
267,
372,
3164,
604,
59,
16,
6809,
17,
26,
552,
8,
2326,
604,
2447,
78,
61,
272,
372,
942,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
870,
7141,
63,
7120,
8,
709,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
504,
1134,
9019,
492,
627,
199,
199,
2326,
604,
275,
359,
2326,
14,
52,
8,
82,
31934,
82,
11,
19,
9,
450,
4119,
2447,
709,
14,
16,
12,
2151,
486,
31934,
71,
11,
22,
9,
450,
4119,
2447,
709,
14,
16,
12,
2151,
330,
31934,
66,
11,
25,
9,
450,
4119,
2447,
709,
14,
16,
9,
1467,
367,
519,
315,
1425,
8,
845,
9,
367,
486,
315,
1425,
8,
845,
9,
367,
330,
315,
1425,
8,
845,
1874,
199,
199,
318,
7141,
63,
7120,
8,
78,
304,
272,
340,
302,
26,
267,
372,
3164,
604,
59,
16,
6809,
17,
26,
552,
8,
2326,
604,
2447,
78,
61,
272,
372,
942,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
870,
7141,
63,
7120,
8,
709,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CoDEmanX/ArangoDB
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/Cookie.py
|
59
|
25449
|
#!/usr/bin/env python
#
####
# Copyright 2000 by Timothy O'Malley <timo@alum.mit.edu>
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# Timothy O'Malley not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR
# ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
####
#
# Id: Cookie.py,v 2.29 2000/08/23 05:28:49 timo Exp
# by Timothy O'Malley <timo@alum.mit.edu>
#
# Cookie.py is a Python module for the handling of HTTP
# cookies as a Python dictionary. See RFC 2109 for more
# information on cookies.
#
# The original idea to treat Cookies as a dictionary came from
# Dave Mitchell (davem@magnet.com) in 1995, when he released the
# first version of nscookie.py.
#
####
r"""
Here's a sample session to show how to use this module.
At the moment, this is the only documentation.
The Basics
----------
Importing is easy..
>>> import Cookie
Most of the time you start by creating a cookie. Cookies come in
three flavors, each with slightly different encoding semantics, but
more on that later.
>>> C = Cookie.SimpleCookie()
>>> C = Cookie.SerialCookie()
>>> C = Cookie.SmartCookie()
[Note: Long-time users of Cookie.py will remember using
Cookie.Cookie() to create an Cookie object. Although deprecated, it
is still supported by the code. See the Backward Compatibility notes
for more information.]
Once you've created your Cookie, you can add values just as if it were
a dictionary.
>>> C = Cookie.SmartCookie()
>>> C["fig"] = "newton"
>>> C["sugar"] = "wafer"
>>> C.output()
'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'
Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header. This is the
default behavior. You can change the header and printed
attributes by using the .output() function
>>> C = Cookie.SmartCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
>>> print C.output(header="Cookie:")
Cookie: rocky=road; Path=/cookie
>>> print C.output(attrs=[], header="Cookie:")
Cookie: rocky=road
The load() method of a Cookie extracts cookies from a string. In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.
>>> C = Cookie.SmartCookie()
>>> C.load("chips=ahoy; vienna=finger")
>>> C.output()
'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'
The load() method is darn-tootin smart about identifying cookies
within a string. Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.
>>> C = Cookie.SmartCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
>>> print C
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
Each element of the Cookie also supports all of the RFC 2109
Cookie attributes. Here's an example which sets the Path
attribute.
>>> C = Cookie.SmartCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
>>> print C
Set-Cookie: oreo=doublestuff; Path=/
Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.
>>> C = Cookie.SmartCookie()
>>> C["twix"] = "none for you"
>>> C["twix"].value
'none for you'
A Bit More Advanced
-------------------
As mentioned before, there are three different flavors of Cookie
objects, each with different encoding/decoding semantics. This
section briefly discusses the differences.
SimpleCookie
The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.
>>> C = Cookie.SimpleCookie()
>>> C["number"] = 7
>>> C["string"] = "seven"
>>> C["number"].value
'7'
>>> C["string"].value
'seven'
>>> C.output()
'Set-Cookie: number=7\r\nSet-Cookie: string=seven'
SerialCookie
The SerialCookie expects that all values should be serialized using
cPickle (or pickle, if cPickle isn't available). As a result of
serializing, SerialCookie can save almost any Python object to a
value, and recover the exact same object when the cookie has been
returned. (SerialCookie can yield some strange-looking cookie
values, however.)
>>> C = Cookie.SerialCookie()
>>> C["number"] = 7
>>> C["string"] = "seven"
>>> C["number"].value
7
>>> C["string"].value
'seven'
>>> C.output()
'Set-Cookie: number="I7\\012."\r\nSet-Cookie: string="S\'seven\'\\012p1\\012."'
Be warned, however, if SerialCookie cannot de-serialize a value (because
it isn't a valid pickle'd object), IT WILL RAISE AN EXCEPTION.
SmartCookie
The SmartCookie combines aspects of each of the other two flavors.
When setting a value in a dictionary-fashion, the SmartCookie will
serialize (ala cPickle) the value *if and only if* it isn't a
Python string. String objects are *not* serialized. Similarly,
when the load() method parses out values, it attempts to de-serialize
the value. If it fails, then it fallsback to treating the value
as a string.
>>> C = Cookie.SmartCookie()
>>> C["number"] = 7
>>> C["string"] = "seven"
>>> C["number"].value
7
>>> C["string"].value
'seven'
>>> C.output()
'Set-Cookie: number="I7\\012."\r\nSet-Cookie: string=seven'
Backwards Compatibility
-----------------------
In order to keep compatibilty with earlier versions of Cookie.py,
it is still possible to use Cookie.Cookie() to create a Cookie. In
fact, this simply returns a SmartCookie.
>>> C = Cookie.Cookie()
>>> print C.__class__.__name__
SmartCookie
Finis.
""" #"
# ^
# |----helps out font-lock
#
# Import our required modules
#
import string
try:
from cPickle import dumps, loads
except ImportError:
from pickle import dumps, loads
import re, warnings
__all__ = ["CookieError","BaseCookie","SimpleCookie","SerialCookie",
"SmartCookie","Cookie"]
_nulljoin = ''.join
_semispacejoin = '; '.join
_spacejoin = ' '.join
#
# Define an exception visible to External modules
#
class CookieError(Exception):
pass
# These quoting routines conform to the RFC2109 specification, which in
# turn references the character definitions from RFC2068. They provide
# a two-way quoting algorithm. Any non-text character is translated
# into a 4 character sequence: a forward-slash followed by the
# three-digit octal equivalent of the character. Any '\' or '"' is
# quoted with a preceeding '\' slash.
#
# These are taken from RFC2068 and RFC2109.
# _LegalChars is the list of chars which don't require "'s
# _Translator hash-table for fast quoting
#
_LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^_`|~"
_Translator = {
'\000' : '\\000', '\001' : '\\001', '\002' : '\\002',
'\003' : '\\003', '\004' : '\\004', '\005' : '\\005',
'\006' : '\\006', '\007' : '\\007', '\010' : '\\010',
'\011' : '\\011', '\012' : '\\012', '\013' : '\\013',
'\014' : '\\014', '\015' : '\\015', '\016' : '\\016',
'\017' : '\\017', '\020' : '\\020', '\021' : '\\021',
'\022' : '\\022', '\023' : '\\023', '\024' : '\\024',
'\025' : '\\025', '\026' : '\\026', '\027' : '\\027',
'\030' : '\\030', '\031' : '\\031', '\032' : '\\032',
'\033' : '\\033', '\034' : '\\034', '\035' : '\\035',
'\036' : '\\036', '\037' : '\\037',
'"' : '\\"', '\\' : '\\\\',
'\177' : '\\177', '\200' : '\\200', '\201' : '\\201',
'\202' : '\\202', '\203' : '\\203', '\204' : '\\204',
'\205' : '\\205', '\206' : '\\206', '\207' : '\\207',
'\210' : '\\210', '\211' : '\\211', '\212' : '\\212',
'\213' : '\\213', '\214' : '\\214', '\215' : '\\215',
'\216' : '\\216', '\217' : '\\217', '\220' : '\\220',
'\221' : '\\221', '\222' : '\\222', '\223' : '\\223',
'\224' : '\\224', '\225' : '\\225', '\226' : '\\226',
'\227' : '\\227', '\230' : '\\230', '\231' : '\\231',
'\232' : '\\232', '\233' : '\\233', '\234' : '\\234',
'\235' : '\\235', '\236' : '\\236', '\237' : '\\237',
'\240' : '\\240', '\241' : '\\241', '\242' : '\\242',
'\243' : '\\243', '\244' : '\\244', '\245' : '\\245',
'\246' : '\\246', '\247' : '\\247', '\250' : '\\250',
'\251' : '\\251', '\252' : '\\252', '\253' : '\\253',
'\254' : '\\254', '\255' : '\\255', '\256' : '\\256',
'\257' : '\\257', '\260' : '\\260', '\261' : '\\261',
'\262' : '\\262', '\263' : '\\263', '\264' : '\\264',
'\265' : '\\265', '\266' : '\\266', '\267' : '\\267',
'\270' : '\\270', '\271' : '\\271', '\272' : '\\272',
'\273' : '\\273', '\274' : '\\274', '\275' : '\\275',
'\276' : '\\276', '\277' : '\\277', '\300' : '\\300',
'\301' : '\\301', '\302' : '\\302', '\303' : '\\303',
'\304' : '\\304', '\305' : '\\305', '\306' : '\\306',
'\307' : '\\307', '\310' : '\\310', '\311' : '\\311',
'\312' : '\\312', '\313' : '\\313', '\314' : '\\314',
'\315' : '\\315', '\316' : '\\316', '\317' : '\\317',
'\320' : '\\320', '\321' : '\\321', '\322' : '\\322',
'\323' : '\\323', '\324' : '\\324', '\325' : '\\325',
'\326' : '\\326', '\327' : '\\327', '\330' : '\\330',
'\331' : '\\331', '\332' : '\\332', '\333' : '\\333',
'\334' : '\\334', '\335' : '\\335', '\336' : '\\336',
'\337' : '\\337', '\340' : '\\340', '\341' : '\\341',
'\342' : '\\342', '\343' : '\\343', '\344' : '\\344',
'\345' : '\\345', '\346' : '\\346', '\347' : '\\347',
'\350' : '\\350', '\351' : '\\351', '\352' : '\\352',
'\353' : '\\353', '\354' : '\\354', '\355' : '\\355',
'\356' : '\\356', '\357' : '\\357', '\360' : '\\360',
'\361' : '\\361', '\362' : '\\362', '\363' : '\\363',
'\364' : '\\364', '\365' : '\\365', '\366' : '\\366',
'\367' : '\\367', '\370' : '\\370', '\371' : '\\371',
'\372' : '\\372', '\373' : '\\373', '\374' : '\\374',
'\375' : '\\375', '\376' : '\\376', '\377' : '\\377'
}
_idmap = ''.join(chr(x) for x in xrange(256))
def _quote(str, LegalChars=_LegalChars,
idmap=_idmap, translate=string.translate):
#
# If the string does not need to be double-quoted,
# then just return the string. Otherwise, surround
# the string in doublequotes and precede quote (with a \)
# special characters.
#
if "" == translate(str, idmap, LegalChars):
return str
else:
return '"' + _nulljoin( map(_Translator.get, str, str) ) + '"'
# end _quote
_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].")
def _unquote(str):
# If there aren't any doublequotes,
# then there can't be any special characters. See RFC 2109.
if len(str) < 2:
return str
if str[0] != '"' or str[-1] != '"':
return str
# We have to assume that we must decode this string.
# Down to work.
# Remove the "s
str = str[1:-1]
# Check for special sequences. Examples:
# \012 --> \n
# \" --> "
#
i = 0
n = len(str)
res = []
while 0 <= i < n:
Omatch = _OctalPatt.search(str, i)
Qmatch = _QuotePatt.search(str, i)
if not Omatch and not Qmatch: # Neither matched
res.append(str[i:])
break
# else:
j = k = -1
if Omatch: j = Omatch.start(0)
if Qmatch: k = Qmatch.start(0)
if Qmatch and ( not Omatch or k < j ): # QuotePatt matched
res.append(str[i:k])
res.append(str[k+1])
i = k+2
else: # OctalPatt matched
res.append(str[i:j])
res.append( chr( int(str[j+1:j+4], 8) ) )
i = j+4
return _nulljoin(res)
# end _unquote
# The _getdate() routine is used to set the expiration time in
# the cookie's HTTP header. By default, _getdate() returns the
# current time in the appropriate "expires" format for a
# Set-Cookie header. The one optional argument is an offset from
# now, in seconds. For example, an offset of -3600 means "one hour ago".
# The offset may be a floating point number.
#
_weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
_monthname = [None,
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def _getdate(future=0, weekdayname=_weekdayname, monthname=_monthname):
from time import gmtime, time
now = time()
year, month, day, hh, mm, ss, wd, y, z = gmtime(now + future)
return "%s, %02d-%3s-%4d %02d:%02d:%02d GMT" % \
(weekdayname[wd], day, monthname[month], year, hh, mm, ss)
#
# A class to hold ONE key,value pair.
# In a cookie, each such pair may have several attributes.
# so this class is used to keep the attributes associated
# with the appropriate key,value pair.
# This class also includes a coded_value attribute, which
# is used to hold the network representation of the
# value. This is most useful when Python objects are
# pickled for network transit.
#
class Morsel(dict):
# RFC 2109 lists these attributes as reserved:
# path comment domain
# max-age secure version
#
# For historical reasons, these attributes are also reserved:
# expires
#
# This is an extension from Microsoft:
# httponly
#
# This dictionary provides a mapping from the lowercase
# variant on the left to the appropriate traditional
# formatting on the right.
_reserved = { "expires" : "expires",
"path" : "Path",
"comment" : "Comment",
"domain" : "Domain",
"max-age" : "Max-Age",
"secure" : "secure",
"httponly" : "httponly",
"version" : "Version",
}
def __init__(self):
# Set defaults
self.key = self.value = self.coded_value = None
# Set default attributes
for K in self._reserved:
dict.__setitem__(self, K, "")
# end __init__
def __setitem__(self, K, V):
K = K.lower()
if not K in self._reserved:
raise CookieError("Invalid Attribute %s" % K)
dict.__setitem__(self, K, V)
# end __setitem__
def isReservedKey(self, K):
return K.lower() in self._reserved
# end isReservedKey
def set(self, key, val, coded_val,
LegalChars=_LegalChars,
idmap=_idmap, translate=string.translate):
# First we verify that the key isn't a reserved word
# Second we make sure it only contains legal characters
if key.lower() in self._reserved:
raise CookieError("Attempt to set a reserved key: %s" % key)
if "" != translate(key, idmap, LegalChars):
raise CookieError("Illegal key value: %s" % key)
# It's a good key, so save it.
self.key = key
self.value = val
self.coded_value = coded_val
# end set
def output(self, attrs=None, header = "Set-Cookie:"):
return "%s %s" % ( header, self.OutputString(attrs) )
__str__ = output
def __repr__(self):
return '<%s: %s=%s>' % (self.__class__.__name__,
self.key, repr(self.value) )
def js_output(self, attrs=None):
# Print javascript
return """
<script type="text/javascript">
<!-- begin hiding
document.cookie = \"%s\";
// end hiding -->
</script>
""" % ( self.OutputString(attrs), )
# end js_output()
def OutputString(self, attrs=None):
# Build up our result
#
result = []
RA = result.append
# First, the key=value pair
RA("%s=%s" % (self.key, self.coded_value))
# Now add any defined attributes
if attrs is None:
attrs = self._reserved
items = self.items()
items.sort()
for K,V in items:
if V == "": continue
if K not in attrs: continue
if K == "expires" and type(V) == type(1):
RA("%s=%s" % (self._reserved[K], _getdate(V)))
elif K == "max-age" and type(V) == type(1):
RA("%s=%d" % (self._reserved[K], V))
elif K == "secure":
RA(str(self._reserved[K]))
elif K == "httponly":
RA(str(self._reserved[K]))
else:
RA("%s=%s" % (self._reserved[K], V))
# Return the result
return _semispacejoin(result)
# end OutputString
# end Morsel class
#
# Pattern for finding cookie
#
# This used to be strict parsing based on the RFC2109 and RFC2068
# specifications. I have since discovered that MSIE 3.0x doesn't
# follow the character rules outlined in those specs. As a
# result, the parsing rules here are less strict.
#
_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]"
_CookiePattern = re.compile(
r"(?x)" # This is a Verbose pattern
r"(?P<key>" # Start of group 'key'
""+ _LegalCharsPatt +"+?" # Any word of at least one letter, nongreedy
r")" # End of group 'key'
r"\s*=\s*" # Equal Sign
r"(?P<val>" # Start of group 'val'
r'"(?:[^\\"]|\\.)*"' # Any doublequoted string
r"|" # or
""+ _LegalCharsPatt +"*" # Any word or empty string
r")" # End of group 'val'
r"\s*;?" # Probably ending in a semi-colon
)
# At long last, here is the cookie class.
# Using this class is almost just like using a dictionary.
# See this module's docstring for example usage.
#
class BaseCookie(dict):
# A container class for a set of Morsels
#
def value_decode(self, val):
"""real_value, coded_value = value_decode(STRING)
Called prior to setting a cookie's value from the network
representation. The VALUE is the value read from HTTP
header.
Override this function to modify the behavior of cookies.
"""
return val, val
# end value_encode
def value_encode(self, val):
"""real_value, coded_value = value_encode(VALUE)
Called prior to setting a cookie's value from the dictionary
representation. The VALUE is the value being assigned.
Override this function to modify the behavior of cookies.
"""
strval = str(val)
return strval, strval
# end value_encode
def __init__(self, input=None):
if input: self.load(input)
# end __init__
def __set(self, key, real_value, coded_value):
"""Private method for setting a cookie's value"""
M = self.get(key, Morsel())
M.set(key, real_value, coded_value)
dict.__setitem__(self, key, M)
# end __set
def __setitem__(self, key, value):
"""Dictionary style assignment."""
rval, cval = self.value_encode(value)
self.__set(key, rval, cval)
# end __setitem__
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
"""Return a string suitable for HTTP."""
result = []
items = self.items()
items.sort()
for K,V in items:
result.append( V.output(attrs, header) )
return sep.join(result)
# end output
__str__ = output
def __repr__(self):
L = []
items = self.items()
items.sort()
for K,V in items:
L.append( '%s=%s' % (K,repr(V.value) ) )
return '<%s: %s>' % (self.__class__.__name__, _spacejoin(L))
def js_output(self, attrs=None):
"""Return a string suitable for JavaScript."""
result = []
items = self.items()
items.sort()
for K,V in items:
result.append( V.js_output(attrs) )
return _nulljoin(result)
# end js_output
def load(self, rawdata):
"""Load cookies from a string (presumably HTTP_COOKIE) or
from a dictionary. Loading cookies from a dictionary 'd'
is equivalent to calling:
map(Cookie.__setitem__, d.keys(), d.values())
"""
if type(rawdata) == type(""):
self.__ParseString(rawdata)
else:
self.update(rawdata)
return
# end load()
def __ParseString(self, str, patt=_CookiePattern):
i = 0 # Our starting point
n = len(str) # Length of string
M = None # current morsel
while 0 <= i < n:
# Start looking for a cookie
match = patt.search(str, i)
if not match: break # No more cookies
K,V = match.group("key"), match.group("val")
i = match.end(0)
# Parse the key, value in case it's metainfo
if K[0] == "$":
# We ignore attributes which pertain to the cookie
# mechanism as a whole. See RFC 2109.
# (Does anyone care?)
if M:
M[ K[1:] ] = V
elif K.lower() in Morsel._reserved:
if M:
M[ K ] = _unquote(V)
else:
rval, cval = self.value_decode(V)
self.__set(K, rval, cval)
M = self[K]
# end __ParseString
# end BaseCookie class
class SimpleCookie(BaseCookie):
"""SimpleCookie
SimpleCookie supports strings as cookie values. When setting
the value using the dictionary assignment notation, SimpleCookie
calls the builtin str() to convert the value to a string. Values
received from HTTP are kept as strings.
"""
def value_decode(self, val):
return _unquote( val ), val
def value_encode(self, val):
strval = str(val)
return strval, _quote( strval )
# end SimpleCookie
class SerialCookie(BaseCookie):
"""SerialCookie
SerialCookie supports arbitrary objects as cookie values. All
values are serialized (using cPickle) before being sent to the
client. All incoming values are assumed to be valid Pickle
representations. IF AN INCOMING VALUE IS NOT IN A VALID PICKLE
FORMAT, THEN AN EXCEPTION WILL BE RAISED.
Note: Large cookie values add overhead because they must be
retransmitted on every HTTP transaction.
Note: HTTP has a 2k limit on the size of a cookie. This class
does not check for this limit, so be careful!!!
"""
def __init__(self, input=None):
warnings.warn("SerialCookie class is insecure; do not use it",
DeprecationWarning)
BaseCookie.__init__(self, input)
# end __init__
def value_decode(self, val):
# This could raise an exception!
return loads( _unquote(val) ), val
def value_encode(self, val):
return val, _quote( dumps(val) )
# end SerialCookie
class SmartCookie(BaseCookie):
"""SmartCookie
SmartCookie supports arbitrary objects as cookie values. If the
object is a string, then it is quoted. If the object is not a
string, however, then SmartCookie will use cPickle to serialize
the object into a string representation.
Note: Large cookie values add overhead because they must be
retransmitted on every HTTP transaction.
Note: HTTP has a 2k limit on the size of a cookie. This class
does not check for this limit, so be careful!!!
"""
def __init__(self, input=None):
warnings.warn("Cookie/SmartCookie class is insecure; do not use it",
DeprecationWarning)
BaseCookie.__init__(self, input)
# end __init__
def value_decode(self, val):
strval = _unquote(val)
try:
return loads(strval), val
except:
return strval, val
def value_encode(self, val):
if type(val) == type(""):
return val, _quote(val)
else:
return val, _quote( dumps(val) )
# end SmartCookie
###########################################################
# Backwards Compatibility: Don't break any existing code!
# We provide Cookie() as an alias for SmartCookie()
Cookie = SmartCookie
#
###########################################################
def _test():
import doctest, Cookie
return doctest.testmod(Cookie)
if __name__ == "__main__":
_test()
#Local Variables:
#tab-width: 4
#end:
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
199,
381,
199,
3,
1898,
12293,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
4483,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
199,
3,
436,
2399,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
199,
3,
10009,
12,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
199,
3,
6866,
436,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
199,
3,
4245,
7468,
315,
21038,
3794,
12,
436,
626,
314,
536,
402,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
221,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
199,
3,
1126,
24522,
370,
4084,
402,
314,
2032,
1928,
2488,
12,
5313,
199,
3,
6791,
4983,
14,
199,
3,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
199,
3,
4141,
12,
6931,
11727,
5292,
2990,
1634,
3169,
199,
3,
2401,
3092,
12,
1621,
4825,
6461,
7000,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
199,
3,
9612,
12,
7043,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
199,
3,
13873,
30340,
1634,
5749,
4141,
14,
199,
3,
199,
381,
199,
3,
199,
3,
15418,
26,
14798,
14,
647,
12,
86,
499,
14,
1398,
12293,
15,
2036,
15,
1789,
22528,
26,
1651,
26,
1887,
3367,
573,
7910,
199,
3,
257,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
221,
14798,
14,
647,
365,
282,
2018,
859,
367,
314,
7252,
402,
3101,
199,
3,
221,
10049,
465,
282,
2018,
2600,
14,
221,
1666,
7329,
499,
6996,
367,
1655,
199,
3,
221,
2556,
641,
10049,
14,
199,
3,
199,
3,
221,
710,
3379,
16819,
370,
14312,
1849,
5635,
465,
282,
2600,
20382,
687,
199,
3,
221,
577,
811,
603,
9414,
1697,
334,
68,
811,
77,
32,
19902,
386,
14,
957,
9,
315,
9013,
21,
12,
1380,
946,
14286,
314,
199,
3,
221,
1642,
1015,
402,
700,
5306,
14,
647,
14,
199,
3,
199,
381,
199,
199,
82,
624,
199,
21741,
1159,
282,
2690,
2351,
370,
2498,
4212,
370,
675,
642,
859,
14,
199,
1271,
314,
12427,
12,
642,
365,
314,
1454,
3794,
14,
199,
199,
1918,
10082,
83,
199,
9460,
199,
199,
6295,
316,
365,
8837,
703,
8410,
1306,
492,
14798,
199,
199,
24625,
402,
314,
900,
1265,
1343,
701,
6425,
282,
5494,
14,
221,
1849,
5635,
11492,
315,
199,
10480,
23547,
12,
1924,
543,
18023,
3365,
2644,
19002,
12,
1325,
199,
6878,
641,
626,
2945,
14,
8410,
1306,
445,
275,
14798,
14,
3184,
7810,
342,
2043,
1306,
445,
275,
14798,
14,
3571,
7810,
342,
2043,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
199,
199,
59,
7443,
26,
19944,
13,
521,
4390,
402,
14798,
14,
647,
911,
21027,
1808,
199,
7810,
14,
7810,
342,
370,
1218,
376,
14798,
909,
14,
221,
4580,
15401,
5906,
12,
652,
199,
374,
5139,
3748,
701,
314,
1233,
14,
221,
1666,
314,
10257,
3079,
3599,
5880,
12681,
199,
509,
1655,
2556,
19784,
199,
199,
25690,
1265,
9064,
2737,
2195,
14798,
12,
1265,
883,
1050,
1338,
2951,
465,
340,
652,
4898,
199,
65,
2600,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
905,
592,
937,
275,
298,
1222,
1860,
2,
2043,
1306,
445,
905,
83,
21922,
937,
275,
298,
758,
2412,
2,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
6085,
29,
1222,
1860,
60,
82,
60,
78,
1084,
13,
7810,
26,
308,
21922,
29,
758,
2412,
7,
199,
199,
1944,
3548,
626,
314,
21834,
6025,
402,
282,
14798,
365,
314,
199,
11227,
5655,
1475,
367,
282,
2494,
13,
7810,
26,
1406,
14,
221,
961,
365,
314,
199,
885,
5953,
14,
221,
2047,
883,
1570,
314,
1406,
436,
12487,
199,
2987,
701,
1808,
314,
1275,
1199,
342,
805,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
905,
24892,
89,
937,
275,
298,
5063,
2,
2043,
1306,
445,
905,
24892,
89,
6611,
515,
937,
275,
3286,
5306,
2,
2043,
1306,
870,
445,
14,
1199,
8,
1291,
628,
7810,
9107,
2043,
14798,
26,
882,
346,
89,
29,
5063,
27,
6912,
13043,
5306,
2043,
1306,
870,
445,
14,
1199,
8,
3288,
6034,
1406,
628,
7810,
9107,
2043,
14798,
26,
882,
346,
89,
29,
5063,
199,
199,
1918,
2248,
342,
1083,
402,
282,
14798,
5536,
83,
10049,
687,
282,
1059,
14,
221,
1010,
282,
199,
21337,
2884,
12,
1265,
3955,
675,
642,
1083,
370,
5536,
314,
10049,
687,
314,
199,
2856,
63,
13665,
3734,
1750,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
14,
912,
480,
335,
6142,
29,
65,
526,
89,
27,
1321,
287,
3540,
29,
70,
7886,
531,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
682,
6142,
29,
65,
526,
89,
60,
82,
60,
78,
1084,
13,
7810,
26,
1321,
287,
3540,
29,
70,
7886,
7,
199,
199,
1918,
2248,
342,
1083,
365,
366,
1060,
13,
475,
357,
262,
11179,
3595,
21119,
10049,
199,
12541,
282,
1059,
14,
221,
21067,
68,
25101,
17370,
12,
6032,
18734,
761,
4654,
12,
436,
1163,
199,
10180,
20907,
5460,
886,
440,
3743,
1180,
652,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
14,
912,
360,
415,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
29,
15022,
2041,
2310,
1103,
11436,
289,
16603,
29,
1103,
11533,
9426,
10784,
2043,
1306,
870,
445,
2043,
2494,
13,
7810,
26,
10074,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
8178,
2041,
2310,
4451,
27,
289,
16603,
9529,
11533,
9426,
199,
199,
22321,
1819,
402,
314
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
199,
381,
199,
3,
1898,
12293,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
4483,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
199,
3,
436,
2399,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
199,
3,
10009,
12,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
199,
3,
6866,
436,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
199,
3,
4245,
7468,
315,
21038,
3794,
12,
436,
626,
314,
536,
402,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
221,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
199,
3,
1126,
24522,
370,
4084,
402,
314,
2032,
1928,
2488,
12,
5313,
199,
3,
6791,
4983,
14,
199,
3,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
199,
3,
4141,
12,
6931,
11727,
5292,
2990,
1634,
3169,
199,
3,
2401,
3092,
12,
1621,
4825,
6461,
7000,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
199,
3,
9612,
12,
7043,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
199,
3,
13873,
30340,
1634,
5749,
4141,
14,
199,
3,
199,
381,
199,
3,
199,
3,
15418,
26,
14798,
14,
647,
12,
86,
499,
14,
1398,
12293,
15,
2036,
15,
1789,
22528,
26,
1651,
26,
1887,
3367,
573,
7910,
199,
3,
257,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
221,
14798,
14,
647,
365,
282,
2018,
859,
367,
314,
7252,
402,
3101,
199,
3,
221,
10049,
465,
282,
2018,
2600,
14,
221,
1666,
7329,
499,
6996,
367,
1655,
199,
3,
221,
2556,
641,
10049,
14,
199,
3,
199,
3,
221,
710,
3379,
16819,
370,
14312,
1849,
5635,
465,
282,
2600,
20382,
687,
199,
3,
221,
577,
811,
603,
9414,
1697,
334,
68,
811,
77,
32,
19902,
386,
14,
957,
9,
315,
9013,
21,
12,
1380,
946,
14286,
314,
199,
3,
221,
1642,
1015,
402,
700,
5306,
14,
647,
14,
199,
3,
199,
381,
199,
199,
82,
624,
199,
21741,
1159,
282,
2690,
2351,
370,
2498,
4212,
370,
675,
642,
859,
14,
199,
1271,
314,
12427,
12,
642,
365,
314,
1454,
3794,
14,
199,
199,
1918,
10082,
83,
199,
9460,
199,
199,
6295,
316,
365,
8837,
703,
8410,
1306,
492,
14798,
199,
199,
24625,
402,
314,
900,
1265,
1343,
701,
6425,
282,
5494,
14,
221,
1849,
5635,
11492,
315,
199,
10480,
23547,
12,
1924,
543,
18023,
3365,
2644,
19002,
12,
1325,
199,
6878,
641,
626,
2945,
14,
8410,
1306,
445,
275,
14798,
14,
3184,
7810,
342,
2043,
1306,
445,
275,
14798,
14,
3571,
7810,
342,
2043,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
199,
199,
59,
7443,
26,
19944,
13,
521,
4390,
402,
14798,
14,
647,
911,
21027,
1808,
199,
7810,
14,
7810,
342,
370,
1218,
376,
14798,
909,
14,
221,
4580,
15401,
5906,
12,
652,
199,
374,
5139,
3748,
701,
314,
1233,
14,
221,
1666,
314,
10257,
3079,
3599,
5880,
12681,
199,
509,
1655,
2556,
19784,
199,
199,
25690,
1265,
9064,
2737,
2195,
14798,
12,
1265,
883,
1050,
1338,
2951,
465,
340,
652,
4898,
199,
65,
2600,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
905,
592,
937,
275,
298,
1222,
1860,
2,
2043,
1306,
445,
905,
83,
21922,
937,
275,
298,
758,
2412,
2,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
6085,
29,
1222,
1860,
60,
82,
60,
78,
1084,
13,
7810,
26,
308,
21922,
29,
758,
2412,
7,
199,
199,
1944,
3548,
626,
314,
21834,
6025,
402,
282,
14798,
365,
314,
199,
11227,
5655,
1475,
367,
282,
2494,
13,
7810,
26,
1406,
14,
221,
961,
365,
314,
199,
885,
5953,
14,
221,
2047,
883,
1570,
314,
1406,
436,
12487,
199,
2987,
701,
1808,
314,
1275,
1199,
342,
805,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
905,
24892,
89,
937,
275,
298,
5063,
2,
2043,
1306,
445,
905,
24892,
89,
6611,
515,
937,
275,
3286,
5306,
2,
2043,
1306,
870,
445,
14,
1199,
8,
1291,
628,
7810,
9107,
2043,
14798,
26,
882,
346,
89,
29,
5063,
27,
6912,
13043,
5306,
2043,
1306,
870,
445,
14,
1199,
8,
3288,
6034,
1406,
628,
7810,
9107,
2043,
14798,
26,
882,
346,
89,
29,
5063,
199,
199,
1918,
2248,
342,
1083,
402,
282,
14798,
5536,
83,
10049,
687,
282,
1059,
14,
221,
1010,
282,
199,
21337,
2884,
12,
1265,
3955,
675,
642,
1083,
370,
5536,
314,
10049,
687,
314,
199,
2856,
63,
13665,
3734,
1750,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
14,
912,
480,
335,
6142,
29,
65,
526,
89,
27,
1321,
287,
3540,
29,
70,
7886,
531,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
682,
6142,
29,
65,
526,
89,
60,
82,
60,
78,
1084,
13,
7810,
26,
1321,
287,
3540,
29,
70,
7886,
7,
199,
199,
1918,
2248,
342,
1083,
365,
366,
1060,
13,
475,
357,
262,
11179,
3595,
21119,
10049,
199,
12541,
282,
1059,
14,
221,
21067,
68,
25101,
17370,
12,
6032,
18734,
761,
4654,
12,
436,
1163,
199,
10180,
20907,
5460,
886,
440,
3743,
1180,
652,
14,
8410,
1306,
445,
275,
14798,
14,
29111,
7810,
342,
2043,
1306,
445,
14,
912,
360,
415,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
29,
15022,
2041,
2310,
1103,
11436,
289,
16603,
29,
1103,
11533,
9426,
10784,
2043,
1306,
870,
445,
2043,
2494,
13,
7810,
26,
10074,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
8178,
2041,
2310,
4451,
27,
289,
16603,
9529,
11533,
9426,
199,
199,
22321,
1819,
402,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
petrutlucian94/nova
|
plugins/xenserver/networking/etc/xensource/scripts/vif_rules.py
|
113
|
4858
|
#!/usr/bin/env python
# Copyright 2010-2011 OpenStack Foundation
# 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.
"""
This script is used to configure iptables, ebtables, and arptables rules on
XenServer hosts.
"""
import os
import sys
# This is written to Python 2.4, since that is what is available on XenServer
import simplejson as json
import novalib # noqa
def main(dom_id, command, only_this_vif=None):
xsls = novalib.execute_get_output('/usr/bin/xenstore-ls',
'/local/domain/%s/vm-data/networking' % dom_id)
macs = [line.split("=")[0].strip() for line in xsls.splitlines()]
for mac in macs:
xsread = novalib.execute_get_output('/usr/bin/xenstore-read',
'/local/domain/%s/vm-data/networking/%s' %
(dom_id, mac))
data = json.loads(xsread)
for ip in data['ips']:
if data["label"] == "public":
vif = "vif%s.0" % dom_id
else:
vif = "vif%s.1" % dom_id
if (only_this_vif is None) or (vif == only_this_vif):
params = dict(IP=ip['ip'], VIF=vif, MAC=data['mac'])
apply_ebtables_rules(command, params)
apply_arptables_rules(command, params)
apply_iptables_rules(command, params)
# A note about adding rules:
# Whenever we add any rule to iptables, arptables or ebtables we first
# delete the same rule to ensure the rule only exists once.
def apply_iptables_rules(command, params):
iptables = lambda *rule: novalib.execute('/sbin/iptables', *rule)
iptables('-D', 'FORWARD', '-m', 'physdev',
'--physdev-in', params['VIF'],
'-s', params['IP'],
'-j', 'ACCEPT')
if command == 'online':
iptables('-A', 'FORWARD', '-m', 'physdev',
'--physdev-in', params['VIF'],
'-s', params['IP'],
'-j', 'ACCEPT')
def apply_arptables_rules(command, params):
arptables = lambda *rule: novalib.execute('/sbin/arptables', *rule)
arptables('-D', 'FORWARD', '--opcode', 'Request',
'--in-interface', params['VIF'],
'--source-ip', params['IP'],
'--source-mac', params['MAC'],
'-j', 'ACCEPT')
arptables('-D', 'FORWARD', '--opcode', 'Reply',
'--in-interface', params['VIF'],
'--source-ip', params['IP'],
'--source-mac', params['MAC'],
'-j', 'ACCEPT')
if command == 'online':
arptables('-A', 'FORWARD', '--opcode', 'Request',
'--in-interface', params['VIF'],
'--source-mac', params['MAC'],
'-j', 'ACCEPT')
arptables('-A', 'FORWARD', '--opcode', 'Reply',
'--in-interface', params['VIF'],
'--source-ip', params['IP'],
'--source-mac', params['MAC'],
'-j', 'ACCEPT')
def apply_ebtables_rules(command, params):
ebtables = lambda *rule: novalib.execute("/sbin/ebtables", *rule)
ebtables('-D', 'FORWARD', '-p', '0806', '-o', params['VIF'],
'--arp-ip-dst', params['IP'],
'-j', 'ACCEPT')
ebtables('-D', 'FORWARD', '-p', '0800', '-o', params['VIF'],
'--ip-dst', params['IP'],
'-j', 'ACCEPT')
if command == 'online':
ebtables('-A', 'FORWARD', '-p', '0806',
'-o', params['VIF'],
'--arp-ip-dst', params['IP'],
'-j', 'ACCEPT')
ebtables('-A', 'FORWARD', '-p', '0800',
'-o', params['VIF'],
'--ip-dst', params['IP'],
'-j', 'ACCEPT')
ebtables('-D', 'FORWARD', '-s', '!', params['MAC'],
'-i', params['VIF'], '-j', 'DROP')
if command == 'online':
ebtables('-I', 'FORWARD', '1', '-s', '!', params['MAC'],
'-i', params['VIF'], '-j', 'DROP')
if __name__ == "__main__":
if len(sys.argv) < 3:
print ("usage: %s dom_id online|offline [vif]" %
os.path.basename(sys.argv[0]))
sys.exit(1)
else:
dom_id, command = sys.argv[1:3]
vif = len(sys.argv) == 4 and sys.argv[3] or None
main(dom_id, command, vif)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
2765,
2884,
365,
1202,
370,
7908,
29458,
12,
26669,
5987,
12,
436,
601,
541,
5921,
4713,
641,
199,
30643,
3120,
7057,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
3,
961,
365,
5313,
370,
2018,
499,
14,
20,
12,
3967,
626,
365,
4052,
365,
2808,
641,
30211,
3120,
199,
646,
13804,
465,
2022,
199,
199,
646,
949,
637,
1892,
221,
327,
8151,
421,
199,
318,
2446,
8,
4556,
63,
344,
12,
1414,
12,
1454,
63,
3749,
63,
14430,
29,
403,
304,
272,
12965,
478,
275,
949,
637,
1892,
14,
2526,
63,
362,
63,
1199,
2336,
2647,
15,
1393,
15,
13615,
1617,
13,
478,
297,
2892,
1994,
1832,
15,
2261,
3149,
83,
15,
2611,
13,
576,
15,
1200,
316,
7,
450,
8266,
63,
344,
9,
272,
610,
1259,
275,
359,
604,
14,
1294,
480,
29,
9981,
16,
1055,
1913,
342,
367,
1004,
315,
12965,
478,
14,
7644,
5106,
339,
367,
4497,
315,
610,
1259,
26,
267,
12965,
739,
275,
949,
637,
1892,
14,
2526,
63,
362,
63,
1199,
2336,
2647,
15,
1393,
15,
13615,
1617,
13,
739,
297,
2511,
1994,
1832,
15,
2261,
3149,
83,
15,
2611,
13,
576,
15,
1200,
316,
3149,
83,
7,
450,
2511,
334,
4556,
63,
344,
12,
4497,
430,
267,
666,
275,
2022,
14,
3640,
8,
7977,
739,
9,
267,
367,
3384,
315,
666,
459,
6142,
2565,
288,
340,
666,
905,
1302,
937,
508,
298,
3455,
582,
355,
15205,
275,
298,
14430,
5,
83,
14,
16,
2,
450,
8266,
63,
344,
288,
587,
26,
355,
15205,
275,
298,
14430,
5,
83,
14,
17,
2,
450,
8266,
63,
344,
953,
340,
334,
2118,
63,
3749,
63,
14430,
365,
488,
9,
503,
334,
14430,
508,
1454,
63,
3749,
63,
14430,
304,
355,
1862,
275,
1211,
8,
1772,
29,
711,
459,
711,
995,
812,
4656,
29,
14430,
12,
13347,
29,
576,
459,
3088,
1105,
355,
4838,
63,
2871,
5987,
63,
4423,
8,
1531,
12,
1862,
9,
355,
4838,
63,
285,
541,
5921,
63,
4423,
8,
1531,
12,
1862,
9,
355,
4838,
63,
23232,
63,
4423,
8,
1531,
12,
1862,
9,
421,
199,
3,
437,
5317,
3595,
7791,
4713,
26,
199,
3,
257,
3979,
5907,
781,
1050,
1263,
2332,
370,
29458,
12,
601,
541,
5921,
503,
26669,
5987,
781,
1642,
199,
3,
257,
3145,
314,
2011,
2332,
370,
4868,
314,
2332,
1454,
3495,
5403,
14,
421,
199,
318,
4838,
63,
23232,
63,
4423,
8,
1531,
12,
1862,
304,
272,
29458,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
2336,
21457,
15,
23232,
297,
627,
2200,
9,
339,
29458,
3654,
36,
297,
283,
29700,
297,
2475,
77,
297,
283,
26827,
2374,
297,
1467,
2850,
26827,
2374,
13,
262,
297,
1862,
459,
27890,
995,
1467,
2475,
83,
297,
1862,
459,
1772,
995,
1467,
2475,
74,
297,
283,
13089,
358,
272,
340,
1414,
508,
283,
15178,
356,
267,
29458,
3654,
33,
297,
283,
29700,
297,
2475,
77,
297,
283,
26827,
2374,
297,
326,
2850,
26827,
2374,
13,
262,
297,
1862,
459,
27890,
995,
326,
2475,
83,
297,
1862,
459,
1772,
995,
326,
2475,
74,
297,
283,
13089,
358,
421,
199,
318,
4838,
63,
285,
541,
5921,
63,
4423,
8,
1531,
12,
1862,
304,
272,
601,
541,
5921,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
2336,
21457,
15,
285,
541,
5921,
297,
627,
2200,
9,
339,
601,
541,
5921,
3654,
36,
297,
283,
29700,
297,
2850,
14325,
297,
283,
2017,
297,
1598,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
1598,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
1598,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
1598,
2475,
74,
297,
283,
13089,
358,
272,
601,
541,
5921,
3654,
36,
297,
283,
29700,
297,
2850,
14325,
297,
283,
14166,
297,
1598,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
1598,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
1598,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
1598,
2475,
74,
297,
283,
13089,
358,
272,
340,
1414,
508,
283,
15178,
356,
267,
601,
541,
5921,
3654,
33,
297,
283,
29700,
297,
2850,
14325,
297,
283,
2017,
297,
2116,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
2116,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
2116,
2475,
74,
297,
283,
13089,
358,
267,
601,
541,
5921,
3654,
33,
297,
283,
29700,
297,
2850,
14325,
297,
283,
14166,
297,
2116,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
2116,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
2116,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
2116,
2475,
74,
297,
283,
13089,
358,
421,
199,
318,
4838,
63,
2871,
5987,
63,
4423,
8,
1531,
12,
1862,
304,
272,
26669,
5987,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
4769,
21457,
15,
2871,
5987,
401,
627,
2200,
9,
339,
26669,
5987,
3654,
36,
297,
283,
29700,
297,
2475,
80,
297,
283,
16,
11901,
297,
2475,
79,
297,
1862,
459,
27890,
995,
1467,
2850,
12868,
13,
711,
13,
5119,
297,
1862,
459,
1772,
995,
1467,
2475,
74,
297,
283,
13089,
358,
272,
26669,
5987,
3654,
36,
297,
283,
29700,
297,
2475,
80,
297,
283,
25822,
297,
2475,
79,
297,
1862,
459,
27890,
995,
1467
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
2765,
2884,
365,
1202,
370,
7908,
29458,
12,
26669,
5987,
12,
436,
601,
541,
5921,
4713,
641,
199,
30643,
3120,
7057,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
3,
961,
365,
5313,
370,
2018,
499,
14,
20,
12,
3967,
626,
365,
4052,
365,
2808,
641,
30211,
3120,
199,
646,
13804,
465,
2022,
199,
199,
646,
949,
637,
1892,
221,
327,
8151,
421,
199,
318,
2446,
8,
4556,
63,
344,
12,
1414,
12,
1454,
63,
3749,
63,
14430,
29,
403,
304,
272,
12965,
478,
275,
949,
637,
1892,
14,
2526,
63,
362,
63,
1199,
2336,
2647,
15,
1393,
15,
13615,
1617,
13,
478,
297,
2892,
1994,
1832,
15,
2261,
3149,
83,
15,
2611,
13,
576,
15,
1200,
316,
7,
450,
8266,
63,
344,
9,
272,
610,
1259,
275,
359,
604,
14,
1294,
480,
29,
9981,
16,
1055,
1913,
342,
367,
1004,
315,
12965,
478,
14,
7644,
5106,
339,
367,
4497,
315,
610,
1259,
26,
267,
12965,
739,
275,
949,
637,
1892,
14,
2526,
63,
362,
63,
1199,
2336,
2647,
15,
1393,
15,
13615,
1617,
13,
739,
297,
2511,
1994,
1832,
15,
2261,
3149,
83,
15,
2611,
13,
576,
15,
1200,
316,
3149,
83,
7,
450,
2511,
334,
4556,
63,
344,
12,
4497,
430,
267,
666,
275,
2022,
14,
3640,
8,
7977,
739,
9,
267,
367,
3384,
315,
666,
459,
6142,
2565,
288,
340,
666,
905,
1302,
937,
508,
298,
3455,
582,
355,
15205,
275,
298,
14430,
5,
83,
14,
16,
2,
450,
8266,
63,
344,
288,
587,
26,
355,
15205,
275,
298,
14430,
5,
83,
14,
17,
2,
450,
8266,
63,
344,
953,
340,
334,
2118,
63,
3749,
63,
14430,
365,
488,
9,
503,
334,
14430,
508,
1454,
63,
3749,
63,
14430,
304,
355,
1862,
275,
1211,
8,
1772,
29,
711,
459,
711,
995,
812,
4656,
29,
14430,
12,
13347,
29,
576,
459,
3088,
1105,
355,
4838,
63,
2871,
5987,
63,
4423,
8,
1531,
12,
1862,
9,
355,
4838,
63,
285,
541,
5921,
63,
4423,
8,
1531,
12,
1862,
9,
355,
4838,
63,
23232,
63,
4423,
8,
1531,
12,
1862,
9,
421,
199,
3,
437,
5317,
3595,
7791,
4713,
26,
199,
3,
257,
3979,
5907,
781,
1050,
1263,
2332,
370,
29458,
12,
601,
541,
5921,
503,
26669,
5987,
781,
1642,
199,
3,
257,
3145,
314,
2011,
2332,
370,
4868,
314,
2332,
1454,
3495,
5403,
14,
421,
199,
318,
4838,
63,
23232,
63,
4423,
8,
1531,
12,
1862,
304,
272,
29458,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
2336,
21457,
15,
23232,
297,
627,
2200,
9,
339,
29458,
3654,
36,
297,
283,
29700,
297,
2475,
77,
297,
283,
26827,
2374,
297,
1467,
2850,
26827,
2374,
13,
262,
297,
1862,
459,
27890,
995,
1467,
2475,
83,
297,
1862,
459,
1772,
995,
1467,
2475,
74,
297,
283,
13089,
358,
272,
340,
1414,
508,
283,
15178,
356,
267,
29458,
3654,
33,
297,
283,
29700,
297,
2475,
77,
297,
283,
26827,
2374,
297,
326,
2850,
26827,
2374,
13,
262,
297,
1862,
459,
27890,
995,
326,
2475,
83,
297,
1862,
459,
1772,
995,
326,
2475,
74,
297,
283,
13089,
358,
421,
199,
318,
4838,
63,
285,
541,
5921,
63,
4423,
8,
1531,
12,
1862,
304,
272,
601,
541,
5921,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
2336,
21457,
15,
285,
541,
5921,
297,
627,
2200,
9,
339,
601,
541,
5921,
3654,
36,
297,
283,
29700,
297,
2850,
14325,
297,
283,
2017,
297,
1598,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
1598,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
1598,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
1598,
2475,
74,
297,
283,
13089,
358,
272,
601,
541,
5921,
3654,
36,
297,
283,
29700,
297,
2850,
14325,
297,
283,
14166,
297,
1598,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
1598,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
1598,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
1598,
2475,
74,
297,
283,
13089,
358,
272,
340,
1414,
508,
283,
15178,
356,
267,
601,
541,
5921,
3654,
33,
297,
283,
29700,
297,
2850,
14325,
297,
283,
2017,
297,
2116,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
2116,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
2116,
2475,
74,
297,
283,
13089,
358,
267,
601,
541,
5921,
3654,
33,
297,
283,
29700,
297,
2850,
14325,
297,
283,
14166,
297,
2116,
2850,
262,
13,
3266,
297,
1862,
459,
27890,
995,
2116,
2850,
1365,
13,
711,
297,
1862,
459,
1772,
995,
2116,
2850,
1365,
13,
3088,
297,
1862,
459,
9410,
995,
2116,
2475,
74,
297,
283,
13089,
358,
421,
199,
318,
4838,
63,
2871,
5987,
63,
4423,
8,
1531,
12,
1862,
304,
272,
26669,
5987,
275,
2400,
627,
2200,
26,
949,
637,
1892,
14,
2526,
4769,
21457,
15,
2871,
5987,
401,
627,
2200,
9,
339,
26669,
5987,
3654,
36,
297,
283,
29700,
297,
2475,
80,
297,
283,
16,
11901,
297,
2475,
79,
297,
1862,
459,
27890,
995,
1467,
2850,
12868,
13,
711,
13,
5119,
297,
1862,
459,
1772,
995,
1467,
2475,
74,
297,
283,
13089,
358,
272,
26669,
5987,
3654,
36,
297,
283,
29700,
297,
2475,
80,
297,
283,
25822,
297,
2475,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
pyokagan/gyp
|
test/cxxflags/gyptest-cxxflags.py
|
128
|
1034
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies the use of the environment during regeneration when the gyp file
changes, specifically via build of an executable with C++ flags specified by
CXXFLAGS.
In this test, gyp happens within a local environment, but build outside of it.
"""
import TestGyp
FORMATS = ('ninja',)
test = TestGyp.TestGyp(formats=FORMATS)
# We reset the environ after calling gyp. When the auto-regeneration happens,
# the same define should be reused anyway.
with TestGyp.LocalEnv({'CXXFLAGS': ''}):
test.run_gyp('cxxflags.gyp')
test.build('cxxflags.gyp')
expect = """\
No define
"""
test.run_built_executable('cxxflags', stdout=expect)
test.sleep()
with TestGyp.LocalEnv({'CXXFLAGS': '-DABC'}):
test.run_gyp('cxxflags.gyp')
test.build('cxxflags.gyp')
expect = """\
With define
"""
test.run_built_executable('cxxflags', stdout=expect)
test.pass_test()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
314,
675,
402,
314,
3734,
5309,
1295,
27976,
1380,
314,
4902,
570,
199,
6627,
12,
22543,
4799,
1900,
402,
376,
7286,
543,
445,
4176,
3285,
2013,
701,
199,
26180,
14,
199,
199,
607,
642,
511,
12,
4902,
10986,
4453,
282,
2257,
3734,
12,
1325,
1900,
9682,
402,
652,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
14019,
275,
661,
8675,
9538,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
29,
14019,
9,
199,
199,
3,
2136,
5305,
314,
6160,
2410,
6358,
4902,
14,
3979,
314,
2599,
13,
1135,
27976,
10986,
12,
199,
3,
314,
2011,
5627,
1077,
506,
24826,
15988,
14,
199,
1045,
25688,
14,
5339,
7744,
3252,
26180,
356,
28174,
304,
523,
511,
14,
1065,
63,
6179,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
396,
14,
1506,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
4921,
275,
9638,
199,
1944,
5627,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11859,
1949,
1550,
297,
3839,
29,
4921,
9,
199,
199,
396,
14,
4532,
342,
199,
199,
1045,
25688,
14,
5339,
7744,
3252,
26180,
356,
2475,
36,
8390,
936,
304,
523,
511,
14,
1065,
63,
6179,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
396,
14,
1506,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
4921,
275,
9638,
199,
3007,
5627,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11859,
1949,
1550,
297,
3839,
29,
4921,
9,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
314,
675,
402,
314,
3734,
5309,
1295,
27976,
1380,
314,
4902,
570,
199,
6627,
12,
22543,
4799,
1900,
402,
376,
7286,
543,
445,
4176,
3285,
2013,
701,
199,
26180,
14,
199,
199,
607,
642,
511,
12,
4902,
10986,
4453,
282,
2257,
3734,
12,
1325,
1900,
9682,
402,
652,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
14019,
275,
661,
8675,
9538,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
29,
14019,
9,
199,
199,
3,
2136,
5305,
314,
6160,
2410,
6358,
4902,
14,
3979,
314,
2599,
13,
1135,
27976,
10986,
12,
199,
3,
314,
2011,
5627,
1077,
506,
24826,
15988,
14,
199,
1045,
25688,
14,
5339,
7744,
3252,
26180,
356,
28174,
304,
523,
511,
14,
1065,
63,
6179,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
396,
14,
1506,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
4921,
275,
9638,
199,
1944,
5627,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11859,
1949,
1550,
297,
3839,
29,
4921,
9,
199,
199,
396,
14,
4532,
342,
199,
199,
1045,
25688,
14,
5339,
7744,
3252,
26180,
356,
2475,
36,
8390,
936,
304,
523,
511,
14,
1065,
63,
6179,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
396,
14,
1506,
360,
11859,
1949,
1550,
14,
6179,
358,
199,
199,
4921,
275,
9638,
199,
3007,
5627,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
11859,
1949,
1550,
297,
3839,
29,
4921,
9,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
epam-mooc/edx-platform
|
cms/djangoapps/contentstore/features/course-settings.py
|
13
|
7232
|
# pylint: disable=C0111
# pylint: disable=W0621
from lettuce import world, step
from terrain.steps import reload_the_page
from selenium.webdriver.common.keys import Keys
from common import type_in_codemirror, upload_file
from django.conf import settings
from nose.tools import assert_true, assert_false, assert_equal # pylint: disable=E0611
TEST_ROOT = settings.COMMON_TEST_DATA_ROOT
COURSE_START_DATE_CSS = "#course-start-date"
COURSE_END_DATE_CSS = "#course-end-date"
ENROLLMENT_START_DATE_CSS = "#course-enrollment-start-date"
ENROLLMENT_END_DATE_CSS = "#course-enrollment-end-date"
COURSE_START_TIME_CSS = "#course-start-time"
COURSE_END_TIME_CSS = "#course-end-time"
ENROLLMENT_START_TIME_CSS = "#course-enrollment-start-time"
ENROLLMENT_END_TIME_CSS = "#course-enrollment-end-time"
DUMMY_TIME = "15:30"
DEFAULT_TIME = "00:00"
############### ACTIONS ####################
@step('I select Schedule and Details$')
def test_i_select_schedule_and_details(step):
world.click_course_settings()
link_css = 'li.nav-course-settings-schedule a'
world.css_click(link_css)
world.wait_for_requirejs(
["jquery", "js/models/course",
"js/models/settings/course_details", "js/views/settings/main"])
@step('I have set course dates$')
def test_i_have_set_course_dates(step):
step.given('I have opened a new course in Studio')
step.given('I select Schedule and Details')
step.given('And I set course dates')
@step('And I set course dates$')
def test_and_i_set_course_dates(step):
set_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
set_date_or_time(COURSE_END_DATE_CSS, '12/26/2013')
set_date_or_time(ENROLLMENT_START_DATE_CSS, '12/1/2013')
set_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013')
set_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
set_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME)
@step('And I clear all the dates except start$')
def test_and_i_clear_all_the_dates_except_start(step):
set_date_or_time(COURSE_END_DATE_CSS, '')
set_date_or_time(ENROLLMENT_START_DATE_CSS, '')
set_date_or_time(ENROLLMENT_END_DATE_CSS, '')
@step('Then I see cleared dates$')
def test_then_i_see_cleared_dates(step):
verify_date_or_time(COURSE_END_DATE_CSS, '')
verify_date_or_time(ENROLLMENT_START_DATE_CSS, '')
verify_date_or_time(ENROLLMENT_END_DATE_CSS, '')
verify_date_or_time(COURSE_END_TIME_CSS, '')
verify_date_or_time(ENROLLMENT_START_TIME_CSS, '')
verify_date_or_time(ENROLLMENT_END_TIME_CSS, '')
# Verify course start date (required) and time still there
verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
@step('I clear the course start date$')
def test_i_clear_the_course_start_date(step):
set_date_or_time(COURSE_START_DATE_CSS, '')
@step('I receive a warning about course start date$')
def test_i_receive_a_warning_about_course_start_date(step):
assert_true(world.css_has_text('.message-error', 'The course must have an assigned start date.'))
assert_true('error' in world.css_find(COURSE_START_DATE_CSS).first._element.get_attribute('class'))
assert_true('error' in world.css_find(COURSE_START_TIME_CSS).first._element.get_attribute('class'))
@step('the previously set start date is shown$')
def test_the_previously_set_start_date_is_shown(step):
verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
@step('Given I have tried to clear the course start$')
def test_i_have_tried_to_clear_the_course_start(step):
step.given("I have set course dates")
step.given("I clear the course start date")
step.given("I receive a warning about course start date")
@step('I have entered a new course start date$')
def test_i_have_entered_a_new_course_start_date(step):
set_date_or_time(COURSE_START_DATE_CSS, '12/22/2013')
@step('The warning about course start date goes away$')
def test_the_warning_about_course_start_date_goes_away(step):
assert world.is_css_not_present('.message-error')
assert_false('error' in world.css_find(COURSE_START_DATE_CSS).first._element.get_attribute('class'))
assert_false('error' in world.css_find(COURSE_START_TIME_CSS).first._element.get_attribute('class'))
@step('my new course start date is shown$')
def new_course_start_date_is_shown(step):
verify_date_or_time(COURSE_START_DATE_CSS, '12/22/2013')
# Time should have stayed from before attempt to clear date.
verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
@step('I change fields$')
def test_i_change_fields(step):
set_date_or_time(COURSE_START_DATE_CSS, '7/7/7777')
set_date_or_time(COURSE_END_DATE_CSS, '7/7/7777')
set_date_or_time(ENROLLMENT_START_DATE_CSS, '7/7/7777')
set_date_or_time(ENROLLMENT_END_DATE_CSS, '7/7/7777')
@step('I change the course overview')
def test_change_course_overview(_step):
type_in_codemirror(0, "<h1>Overview</h1>")
@step('I click the "Upload Course Image" button')
def click_upload_button(_step):
button_css = '.action-upload-image'
world.css_click(button_css)
@step('I upload a new course image$')
def upload_new_course_image(_step):
upload_file('image.jpg', sub_path="uploads")
@step('I should see the new course image$')
def i_see_new_course_image(_step):
img_css = '#course-image'
images = world.css_find(img_css)
assert len(images) == 1
img = images[0]
expected_src = '/c4x/MITx/999/asset/image.jpg'
# Don't worry about the domain in the URL
success_func = lambda _: img['src'].endswith(expected_src)
world.wait_for(success_func)
@step('the image URL should be present in the field')
def image_url_present(_step):
field_css = '#course-image-url'
expected_value = '/c4x/MITx/999/asset/image.jpg'
assert world.css_value(field_css) == expected_value
############### HELPER METHODS ####################
def set_date_or_time(css, date_or_time):
"""
Sets date or time field.
"""
world.css_fill(css, date_or_time)
e = world.css_find(css).first
# hit Enter to apply the changes
e._element.send_keys(Keys.ENTER)
def verify_date_or_time(css, date_or_time):
"""
Verifies date or time field.
"""
# We need to wait for JavaScript to fill in the field, so we use
# css_has_value(), which first checks that the field is not blank
assert_true(world.css_has_value(css, date_or_time))
@step('I do not see the changes')
@step('I see the set dates')
def i_see_the_set_dates(_step):
"""
Ensure that each field has the value set in `test_and_i_set_course_dates`.
"""
verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013')
verify_date_or_time(COURSE_END_DATE_CSS, '12/26/2013')
verify_date_or_time(ENROLLMENT_START_DATE_CSS, '12/01/2013')
verify_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013')
verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME)
# Unset times get set to 12 AM once the corresponding date has been set.
verify_date_or_time(COURSE_END_TIME_CSS, DEFAULT_TIME)
verify_date_or_time(ENROLLMENT_START_TIME_CSS, DEFAULT_TIME)
verify_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME)
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
2044,
6322,
14,
5895,
492,
13101,
63,
1589,
63,
1606,
199,
504,
19481,
14,
17946,
14,
2330,
14,
1612,
492,
17276,
199,
504,
2863,
492,
730,
63,
262,
63,
600,
12324,
12,
5802,
63,
493,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
12,
702,
63,
3910,
12,
702,
63,
1452,
221,
327,
4287,
26,
3507,
29,
37,
1690,
845,
199,
199,
2864,
63,
5441,
275,
2202,
14,
21637,
63,
2864,
63,
3998,
63,
5441,
199,
199,
15552,
63,
7363,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
928,
13,
602,
2,
199,
15552,
63,
3902,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
500,
13,
602,
2,
199,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
928,
13,
602,
2,
199,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
500,
13,
602,
2,
199,
199,
15552,
63,
7363,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
928,
13,
521,
2,
199,
15552,
63,
3902,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
500,
13,
521,
2,
199,
742,
14881,
4479,
63,
7363,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
928,
13,
521,
2,
199,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
500,
13,
521,
2,
199,
199,
26778,
63,
4961,
275,
298,
1046,
26,
1216,
2,
199,
3472,
63,
4961,
275,
298,
383,
26,
383,
2,
421,
199,
516,
14776,
437,
19560,
21905,
381,
199,
32,
2926,
360,
41,
3504,
24317,
436,
15621,
9988,
199,
318,
511,
63,
73,
63,
2416,
63,
7211,
63,
460,
63,
5087,
8,
2926,
304,
272,
6701,
14,
4891,
63,
1972,
63,
1751,
342,
272,
2142,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
1751,
13,
7211,
282,
7,
272,
6701,
14,
3919,
63,
4891,
8,
1073,
63,
3919,
9,
272,
6701,
14,
2573,
63,
509,
63,
4365,
3596,
8,
267,
2097,
22324,
401,
298,
3596,
15,
992,
15,
1972,
401,
268,
298,
3596,
15,
992,
15,
1751,
15,
1972,
63,
5087,
401,
298,
3596,
15,
4196,
15,
1751,
15,
973,
3135,
421,
199,
32,
2926,
360,
41,
1172,
663,
2518,
10831,
9988,
199,
318,
511,
63,
73,
63,
7804,
63,
409,
63,
1972,
63,
9356,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
282,
892,
2518,
315,
13225,
358,
272,
3650,
14,
11809,
360,
41,
3504,
24317,
436,
15621,
358,
272,
3650,
14,
11809,
360,
3325,
473,
663,
2518,
10831,
358,
421,
199,
32,
2926,
360,
3325,
473,
663,
2518,
10831,
9988,
199,
318,
511,
63,
460,
63,
73,
63,
409,
63,
1972,
63,
9356,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
1165,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
283,
713,
15,
1479,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
17,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
283,
713,
15,
709,
15,
6965,
358,
339,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
421,
199,
32,
2926,
360,
3325,
473,
5436,
1006,
314,
10831,
871,
1343,
9988,
199,
318,
511,
63,
460,
63,
73,
63,
3584,
63,
452,
63,
1589,
63,
9356,
63,
2590,
63,
928,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
421,
199,
32,
2926,
360,
28226,
473,
1937,
20518,
10831,
9988,
199,
318,
511,
63,
12726,
63,
73,
63,
3239,
63,
2265,
2899,
63,
9356,
8,
2926,
304,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
339,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
4961,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
4961,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
12,
4074,
339,
327,
7635,
2518,
1343,
1434,
334,
2427,
9,
436,
900,
5139,
2337,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
1165,
15,
6965,
358,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
421,
199,
32,
2926,
360,
41,
5436,
314,
2518,
1343,
1434,
9988,
199,
318,
511,
63,
73,
63,
3584,
63,
1589,
63,
1972,
63,
928,
63,
602,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
421,
199,
32,
2926,
360,
41,
9128,
282,
5721,
3595,
2518,
1343,
1434,
9988,
199,
318,
511,
63,
73,
63,
9391,
63,
65,
63,
3764,
63,
10254,
63,
1972,
63,
928,
63,
602,
8,
2926,
304,
272,
702,
63,
2052,
8,
7617,
14,
3919,
63,
1989,
63,
505,
5175,
1188,
13
] |
[
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
2044,
6322,
14,
5895,
492,
13101,
63,
1589,
63,
1606,
199,
504,
19481,
14,
17946,
14,
2330,
14,
1612,
492,
17276,
199,
504,
2863,
492,
730,
63,
262,
63,
600,
12324,
12,
5802,
63,
493,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
12,
702,
63,
3910,
12,
702,
63,
1452,
221,
327,
4287,
26,
3507,
29,
37,
1690,
845,
199,
199,
2864,
63,
5441,
275,
2202,
14,
21637,
63,
2864,
63,
3998,
63,
5441,
199,
199,
15552,
63,
7363,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
928,
13,
602,
2,
199,
15552,
63,
3902,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
500,
13,
602,
2,
199,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
928,
13,
602,
2,
199,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
500,
13,
602,
2,
199,
199,
15552,
63,
7363,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
928,
13,
521,
2,
199,
15552,
63,
3902,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
500,
13,
521,
2,
199,
742,
14881,
4479,
63,
7363,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
928,
13,
521,
2,
199,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
275,
5426,
1972,
13,
12214,
13,
500,
13,
521,
2,
199,
199,
26778,
63,
4961,
275,
298,
1046,
26,
1216,
2,
199,
3472,
63,
4961,
275,
298,
383,
26,
383,
2,
421,
199,
516,
14776,
437,
19560,
21905,
381,
199,
32,
2926,
360,
41,
3504,
24317,
436,
15621,
9988,
199,
318,
511,
63,
73,
63,
2416,
63,
7211,
63,
460,
63,
5087,
8,
2926,
304,
272,
6701,
14,
4891,
63,
1972,
63,
1751,
342,
272,
2142,
63,
3919,
275,
283,
317,
14,
10927,
13,
1972,
13,
1751,
13,
7211,
282,
7,
272,
6701,
14,
3919,
63,
4891,
8,
1073,
63,
3919,
9,
272,
6701,
14,
2573,
63,
509,
63,
4365,
3596,
8,
267,
2097,
22324,
401,
298,
3596,
15,
992,
15,
1972,
401,
268,
298,
3596,
15,
992,
15,
1751,
15,
1972,
63,
5087,
401,
298,
3596,
15,
4196,
15,
1751,
15,
973,
3135,
421,
199,
32,
2926,
360,
41,
1172,
663,
2518,
10831,
9988,
199,
318,
511,
63,
73,
63,
7804,
63,
409,
63,
1972,
63,
9356,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
1172,
12123,
282,
892,
2518,
315,
13225,
358,
272,
3650,
14,
11809,
360,
41,
3504,
24317,
436,
15621,
358,
272,
3650,
14,
11809,
360,
3325,
473,
663,
2518,
10831,
358,
421,
199,
32,
2926,
360,
3325,
473,
663,
2518,
10831,
9988,
199,
318,
511,
63,
460,
63,
73,
63,
409,
63,
1972,
63,
9356,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
1165,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
283,
713,
15,
1479,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
17,
15,
6965,
358,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
283,
713,
15,
709,
15,
6965,
358,
339,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
421,
199,
32,
2926,
360,
3325,
473,
5436,
1006,
314,
10831,
871,
1343,
9988,
199,
318,
511,
63,
460,
63,
73,
63,
3584,
63,
452,
63,
1589,
63,
9356,
63,
2590,
63,
928,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
272,
663,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
421,
199,
32,
2926,
360,
28226,
473,
1937,
20518,
10831,
9988,
199,
318,
511,
63,
12726,
63,
73,
63,
3239,
63,
2265,
2899,
63,
9356,
8,
2926,
304,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
5390,
63,
14391,
12,
4074,
339,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
3902,
63,
4961,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
7363,
63,
4961,
63,
14391,
12,
4074,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
742,
14881,
4479,
63,
3902,
63,
4961,
63,
14391,
12,
4074,
339,
327,
7635,
2518,
1343,
1434,
334,
2427,
9,
436,
900,
5139,
2337,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
283,
713,
15,
1165,
15,
6965,
358,
272,
4911,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
4961,
63,
14391,
12,
577,
22472,
63,
4961,
9,
421,
199,
32,
2926,
360,
41,
5436,
314,
2518,
1343,
1434,
9988,
199,
318,
511,
63,
73,
63,
3584,
63,
1589,
63,
1972,
63,
928,
63,
602,
8,
2926,
304,
272,
663,
63,
602,
63,
269,
63,
521,
8,
15552,
63,
7363,
63,
5390,
63,
14391,
12,
4074,
421,
199,
32,
2926,
360,
41,
9128,
282,
5721,
3595,
2518,
1343,
1434,
9988,
199,
318,
511,
63,
73,
63,
9391,
63,
65,
63,
3764,
63,
10254,
63,
1972,
63,
928,
63,
602,
8,
2926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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
zulumarketing/html2pdf
|
xhtml2pdf/w3c/cssDOMElementInterface.py
|
1
|
4314
|
#!/usr/bin/env python
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##~ Copyright (C) 2002-2004 TechGame Networks, LLC.
##~
##~ This library is free software; you can redistribute it and/or
##~ modify it under the terms of the BSD style License as found in the
##~ LICENSE file included with this distribution.
##
## Modified by Dirk Holtwick <holtwick@web.de>, 2007-2008
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try:
from . import css #python 3
except Exception:
import css #python 2
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class CSSDOMElementInterface(css.CSSElementInterfaceAbstract):
"""An implementation of css.CSSElementInterfaceAbstract for xml.dom Element Nodes"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Constants / Variables / Etc.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
style = None
_pseudoStateHandlerLookup = {
'first-child':
lambda self: not bool(self.getPreviousSibling()),
'not-first-child':
lambda self: bool(self.getPreviousSibling()),
'last-child':
lambda self: not bool(self.getNextSibling()),
'not-last-child':
lambda self: bool(self.getNextSibling()),
'middle-child':
lambda self: not bool(self.getPreviousSibling()) and not bool(self.getNextSibling()),
'not-middle-child':
lambda self: bool(self.getPreviousSibling()) or bool(self.getNextSibling()),
# XXX 'first-line':
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self, domElement, cssParser=None):
self.domElement = domElement
# print self.domElement.attributes
if cssParser is not None:
self.onCSSParserVisit(cssParser)
def onCSSParserVisit(self, cssParser):
styleSrc = self.getStyleAttr()
if styleSrc:
style = cssParser.parse_inline(styleSrc)
self.setInlineStyle(style)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def matchesNode(self, namespace_tagName):
namespace,tagName = namespace_tagName
if tagName not in ('*', self.domElement.tagName):
return False
if namespace in (None, '', '*'):
# matches any namespace
return True
else: # full compare
return namespace == self.domElement.namespaceURI
def getAttr(self, name, default=NotImplemented):
attrValue = self.domElement.attributes.get(name)
if attrValue is not None:
return attrValue.value
else:
return default
def getIdAttr(self):
return self.getAttr('id', '')
def getClassAttr(self):
return self.getAttr('class', '')
def getStyleAttr(self):
return self.getAttr('style', None)
def inPseudoState(self, name, params=()):
handler = self._pseudoStateHandlerLookup.get(name, lambda self: False)
return handler(self)
def iterXMLParents(self, includeSelf=False):
klass = self.__class__
current = self.domElement
if not includeSelf:
current = current.parentNode
while (current is not None) and (current.nodeType == current.ELEMENT_NODE):
yield klass(current)
current = current.parentNode
def getPreviousSibling(self):
sibling = self.domElement.previousSibling
while sibling:
if sibling.nodeType == sibling.ELEMENT_NODE:
return sibling
else:
sibling = sibling.previousSibling
return None
def getNextSibling(self):
sibling = self.domElement.nextSibling
while sibling:
if sibling.nodeType == sibling.ELEMENT_NODE:
return sibling
else:
sibling = sibling.nextSibling
return None
def getInlineStyle(self):
return self.style
def setInlineStyle(self, style):
self.style = style
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
309,
30642,
9753,
2878,
199,
309,
94,
1898,
334,
35,
9,
14790,
13,
15431,
221,
5773,
335,
11454,
17138,
12,
20376,
14,
199,
309,
94,
199,
309,
94,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
94,
2811,
652,
1334,
314,
2895,
402,
314,
6289,
3449,
844,
465,
1911,
315,
314,
199,
309,
94,
5113,
570,
5120,
543,
642,
4084,
14,
199,
309,
199,
309,
221,
22016,
701,
25866,
75,
869,
393,
8122,
2000,
665,
24588,
8122,
2000,
32,
2520,
14,
271,
6244,
10219,
13,
9300,
199,
309,
30642,
9753,
2878,
199,
199,
3,
30642,
9753,
2878,
199,
32169,
24339,
199,
3,
30642,
9753,
2878,
199,
199,
893,
26,
272,
687,
1275,
492,
11431,
327,
1548,
650,
199,
2590,
2186,
26,
272,
492,
11431,
327,
1548,
499,
199,
199,
3,
30642,
9753,
2878,
199,
32169,
22659,
852,
199,
3,
30642,
9753,
2878,
199,
199,
533,
15750,
10462,
2162,
4267,
8,
3919,
14,
3298,
899,
968,
4267,
8458,
304,
272,
408,
2493,
4514,
402,
11431,
14,
3298,
899,
968,
4267,
8458,
367,
2748,
14,
4556,
6566,
23836,
624,
339,
327,
30642,
9753,
2878,
272,
15259,
22296,
1182,
17198,
1182,
662,
3641,
14,
272,
327,
30642,
9753,
2878,
339,
3449,
275,
488,
339,
485,
22490,
2223,
2461,
7521,
275,
469,
267,
283,
2246,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
18021,
16016,
4000,
267,
283,
1397,
13,
2246,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
18021,
16016,
4000,
398,
283,
2019,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
267,
283,
1397,
13,
2019,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
398,
283,
14885,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
18021,
16016,
1012,
436,
440,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
267,
283,
1397,
13,
14885,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
18021,
16016,
1012,
503,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
398,
327,
5787,
283,
2246,
13,
604,
356,
339,
789,
339,
327,
30642,
9753,
2878,
272,
15259,
22659,
852,
272,
327,
30642,
9753,
2878,
339,
347,
636,
826,
721,
277,
12,
8266,
2162,
12,
11431,
2842,
29,
403,
304,
267,
291,
14,
4556,
2162,
275,
8266,
2162,
267,
327,
870,
291,
14,
4556,
2162,
14,
2987,
267,
340,
11431,
2842,
365,
440,
488,
26,
288,
291,
14,
265,
14391,
2842,
15087,
8,
3919,
2842,
9,
2378,
347,
641,
14391,
2842,
15087,
8,
277,
12,
11431,
2842,
304,
267,
3449,
21261,
275,
291,
14,
362,
6609,
7144,
342,
267,
340,
3449,
21261,
26,
288,
3449,
275,
11431,
2842,
14,
1122,
63,
6460,
8,
2487,
21261,
9,
288,
291,
14,
409,
10307,
6609,
8,
2487,
9,
2378,
327,
30642,
9753,
2878,
339,
347,
4450,
1716,
8,
277,
12,
3231,
63,
20183,
304,
267,
3231,
12,
20183,
275,
3231,
63,
20183,
267,
340,
1947,
985,
440,
315,
661,
7693,
291,
14,
4556,
2162,
14,
20183,
304,
288,
372,
756,
267,
340,
3231,
315,
334,
403,
12,
3260,
6438,
735,
288,
327,
4450,
1263,
3231,
288,
372,
715,
267,
587,
26,
327,
2615,
6540,
288,
372,
3231,
508,
291,
14,
4556,
2162,
14,
27855,
2378,
347,
664,
7144,
8,
277,
12,
536,
12,
849,
29,
14278,
304,
267,
1921,
1110,
275,
291,
14,
4556,
2162,
14,
2987,
14,
362,
8,
354,
9,
267,
340,
1921,
1110,
365,
440,
488,
26,
288,
372,
1921,
1110,
14,
585,
267,
587,
26,
288,
372,
849,
2378,
347,
664,
1304,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
344,
297,
4074,
2378,
347,
664,
2543,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
533,
297,
4074,
2378,
347,
664,
6609,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
2487,
297,
488,
9,
2378,
347,
315,
23414,
2223,
8,
277,
12,
536,
12,
1862,
23603,
267,
3016,
275,
291,
423,
22490,
2223,
2461,
7521,
14,
362,
8,
354,
12,
2400,
291,
26,
756,
9,
267,
372,
3016,
8,
277,
9,
2378,
347,
2740,
4317,
6652,
83,
8,
277,
12,
2387,
12887,
29,
797,
304,
267,
8531,
275,
291,
855,
533,
363,
267,
1453,
275,
291,
14,
4556,
2162,
267,
340,
440,
2387,
12887,
26,
288,
1453,
275,
1453,
14,
24899,
267,
1830,
334,
1818,
365,
440,
488,
9,
436,
334,
1818,
14,
12412,
508,
1453,
14,
12535,
63,
8063,
304,
288,
1995,
8531,
8,
1818,
9,
288,
1453,
275,
1453,
14,
24899,
2378,
347,
664,
18021,
16016,
8,
277,
304,
267,
24238,
275,
291,
14,
4556,
2162,
14,
6352,
16016,
267,
1830,
24238,
26,
288,
340,
24238,
14,
12412,
508,
24238,
14,
12535,
63,
8063,
26,
355,
372,
24238,
288,
587,
26,
355,
24238,
275,
24238,
14,
6352,
16016,
267,
372,
488,
2378,
347,
664,
5765,
16016,
8,
277,
304,
267,
24238,
275,
291,
14,
4556,
2162,
14,
30336,
267,
1830,
24238,
26,
288,
340,
24238,
14,
12412,
508,
24238,
14,
12535,
63,
8063,
26,
355,
372,
24238,
288,
587,
26,
355,
24238,
275,
24238,
14,
30336,
267,
372,
488,
2378,
347,
664,
10307,
6609,
8,
277,
304,
267,
372,
291,
14,
2487,
2378,
347,
663,
10307,
6609,
8,
277,
12,
3449,
304,
267,
291,
14,
2487,
275,
3449,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
309,
30642,
9753,
2878,
199,
309,
94,
1898,
334,
35,
9,
14790,
13,
15431,
221,
5773,
335,
11454,
17138,
12,
20376,
14,
199,
309,
94,
199,
309,
94,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
94,
2811,
652,
1334,
314,
2895,
402,
314,
6289,
3449,
844,
465,
1911,
315,
314,
199,
309,
94,
5113,
570,
5120,
543,
642,
4084,
14,
199,
309,
199,
309,
221,
22016,
701,
25866,
75,
869,
393,
8122,
2000,
665,
24588,
8122,
2000,
32,
2520,
14,
271,
6244,
10219,
13,
9300,
199,
309,
30642,
9753,
2878,
199,
199,
3,
30642,
9753,
2878,
199,
32169,
24339,
199,
3,
30642,
9753,
2878,
199,
199,
893,
26,
272,
687,
1275,
492,
11431,
327,
1548,
650,
199,
2590,
2186,
26,
272,
492,
11431,
327,
1548,
499,
199,
199,
3,
30642,
9753,
2878,
199,
32169,
22659,
852,
199,
3,
30642,
9753,
2878,
199,
199,
533,
15750,
10462,
2162,
4267,
8,
3919,
14,
3298,
899,
968,
4267,
8458,
304,
272,
408,
2493,
4514,
402,
11431,
14,
3298,
899,
968,
4267,
8458,
367,
2748,
14,
4556,
6566,
23836,
624,
339,
327,
30642,
9753,
2878,
272,
15259,
22296,
1182,
17198,
1182,
662,
3641,
14,
272,
327,
30642,
9753,
2878,
339,
3449,
275,
488,
339,
485,
22490,
2223,
2461,
7521,
275,
469,
267,
283,
2246,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
18021,
16016,
4000,
267,
283,
1397,
13,
2246,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
18021,
16016,
4000,
398,
283,
2019,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
267,
283,
1397,
13,
2019,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
398,
283,
14885,
13,
1739,
356,
288,
2400,
291,
26,
440,
2155,
8,
277,
14,
362,
18021,
16016,
1012,
436,
440,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
267,
283,
1397,
13,
14885,
13,
1739,
356,
288,
2400,
291,
26,
2155,
8,
277,
14,
362,
18021,
16016,
1012,
503,
2155,
8,
277,
14,
362,
5765,
16016,
4000,
398,
327,
5787,
283,
2246,
13,
604,
356,
339,
789,
339,
327,
30642,
9753,
2878,
272,
15259,
22659,
852,
272,
327,
30642,
9753,
2878,
339,
347,
636,
826,
721,
277,
12,
8266,
2162,
12,
11431,
2842,
29,
403,
304,
267,
291,
14,
4556,
2162,
275,
8266,
2162,
267,
327,
870,
291,
14,
4556,
2162,
14,
2987,
267,
340,
11431,
2842,
365,
440,
488,
26,
288,
291,
14,
265,
14391,
2842,
15087,
8,
3919,
2842,
9,
2378,
347,
641,
14391,
2842,
15087,
8,
277,
12,
11431,
2842,
304,
267,
3449,
21261,
275,
291,
14,
362,
6609,
7144,
342,
267,
340,
3449,
21261,
26,
288,
3449,
275,
11431,
2842,
14,
1122,
63,
6460,
8,
2487,
21261,
9,
288,
291,
14,
409,
10307,
6609,
8,
2487,
9,
2378,
327,
30642,
9753,
2878,
339,
347,
4450,
1716,
8,
277,
12,
3231,
63,
20183,
304,
267,
3231,
12,
20183,
275,
3231,
63,
20183,
267,
340,
1947,
985,
440,
315,
661,
7693,
291,
14,
4556,
2162,
14,
20183,
304,
288,
372,
756,
267,
340,
3231,
315,
334,
403,
12,
3260,
6438,
735,
288,
327,
4450,
1263,
3231,
288,
372,
715,
267,
587,
26,
327,
2615,
6540,
288,
372,
3231,
508,
291,
14,
4556,
2162,
14,
27855,
2378,
347,
664,
7144,
8,
277,
12,
536,
12,
849,
29,
14278,
304,
267,
1921,
1110,
275,
291,
14,
4556,
2162,
14,
2987,
14,
362,
8,
354,
9,
267,
340,
1921,
1110,
365,
440,
488,
26,
288,
372,
1921,
1110,
14,
585,
267,
587,
26,
288,
372,
849,
2378,
347,
664,
1304,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
344,
297,
4074,
2378,
347,
664,
2543,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
533,
297,
4074,
2378,
347,
664,
6609,
7144,
8,
277,
304,
267,
372,
291,
14,
31068,
360,
2487,
297,
488,
9,
2378,
347,
315,
23414,
2223,
8,
277,
12,
536,
12,
1862,
23603,
267,
3016,
275,
291,
423,
22490,
2223,
2461,
7521,
14,
362,
8,
354,
12,
2400,
291,
26,
756,
9,
267,
372,
3016,
8,
277,
9,
2378,
347,
2740,
4317,
6652,
83,
8,
277,
12,
2387,
12887,
29,
797,
304,
267,
8531,
275,
291,
855,
533,
363,
267,
1453,
275,
291,
14,
4556,
2162,
267,
340,
440,
2387,
12887,
26,
288,
1453,
275,
1453,
14,
24899,
267,
1830,
334,
1818,
365,
440,
488,
9,
436,
334,
1818,
14,
12412,
508,
1453,
14,
12535,
63,
8063,
304,
288,
1995,
8531,
8,
1818,
9,
288,
1453,
275,
1453,
14,
24899,
2378,
347,
664,
18021,
16016,
8,
277,
304,
267,
24238,
275,
291,
14,
4556,
2162,
14,
6352,
16016,
267,
1830,
24238,
26,
288,
340,
24238,
14,
12412,
508,
24238,
14,
12535,
63,
8063,
26,
355,
372,
24238,
288,
587,
26,
355,
24238,
275,
24238,
14,
6352,
16016,
267,
372,
488,
2378,
347,
664,
5765,
16016,
8,
277,
304,
267,
24238,
275,
291,
14,
4556,
2162,
14,
30336,
267,
1830,
24238,
26,
288,
340,
24238,
14,
12412,
508,
24238,
14,
12535,
63,
8063,
26,
355,
372,
24238,
288,
587,
26,
355,
24238,
275,
24238,
14,
30336,
267,
372,
488,
2378,
347,
664,
10307,
6609,
8,
277,
304,
267,
372,
291,
14,
2487,
2378,
347,
663,
10307,
6609,
8,
277,
12,
3449,
304,
267,
291,
14,
2487,
275,
3449,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
RandallDW/Aruba_plugin
|
plugins/org.python.pydev/pysrc/_pydevd_bundle/pydevd_utils.py
|
1
|
7871
|
from __future__ import nested_scopes
import traceback
import os
try:
from urllib import quote
except:
from urllib.parse import quote # @UnresolvedImport
import inspect
from _pydevd_bundle.pydevd_constants import IS_PY3K
import sys
from _pydev_bundle import pydev_log
def save_main_module(file, module_name):
# patch provided by: Scott Schlesier - when script is run, it does not
# use globals from pydevd:
# This will prevent the pydevd script from contaminating the namespace for the script to be debugged
# pretend pydevd is not the main module, and
# convince the file to be debugged that it was loaded as main
sys.modules[module_name] = sys.modules['__main__']
sys.modules[module_name].__name__ = module_name
from imp import new_module
m = new_module('__main__')
sys.modules['__main__'] = m
if hasattr(sys.modules[module_name], '__loader__'):
setattr(m, '__loader__', getattr(sys.modules[module_name], '__loader__'))
m.__file__ = file
return m
def to_number(x):
if is_string(x):
try:
n = float(x)
return n
except ValueError:
pass
l = x.find('(')
if l != -1:
y = x[0:l-1]
#print y
try:
n = float(y)
return n
except ValueError:
pass
return None
def compare_object_attrs(x, y):
try:
if x == y:
return 0
x_num = to_number(x)
y_num = to_number(y)
if x_num is not None and y_num is not None:
if x_num - y_num<0:
return -1
else:
return 1
if '__len__' == x:
return -1
if '__len__' == y:
return 1
return x.__cmp__(y)
except:
if IS_PY3K:
return (to_string(x) > to_string(y)) - (to_string(x) < to_string(y))
else:
return cmp(to_string(x), to_string(y))
def cmp_to_key(mycmp):
'Convert a cmp= function into a key= function'
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return mycmp(self.obj, other.obj) < 0
def __gt__(self, other):
return mycmp(self.obj, other.obj) > 0
def __eq__(self, other):
return mycmp(self.obj, other.obj) == 0
def __le__(self, other):
return mycmp(self.obj, other.obj) <= 0
def __ge__(self, other):
return mycmp(self.obj, other.obj) >= 0
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
return K
if IS_PY3K:
def is_string(x):
return isinstance(x, str)
else:
def is_string(x):
return isinstance(x, basestring)
def to_string(x):
if is_string(x):
return x
else:
return str(x)
def print_exc():
if traceback:
traceback.print_exc()
if IS_PY3K:
def quote_smart(s, safe='/'):
return quote(s, safe)
else:
def quote_smart(s, safe='/'):
if isinstance(s, unicode):
s = s.encode('utf-8')
return quote(s, safe)
def get_clsname_for_code(code, frame):
clsname = None
if len(code.co_varnames) > 0:
# We are checking the first argument of the function
# (`self` or `cls` for methods).
first_arg_name = code.co_varnames[0]
if first_arg_name in frame.f_locals:
first_arg_obj = frame.f_locals[first_arg_name]
if inspect.isclass(first_arg_obj): # class method
first_arg_class = first_arg_obj
else: # instance method
first_arg_class = first_arg_obj.__class__
func_name = code.co_name
if hasattr(first_arg_class, func_name):
method = getattr(first_arg_class, func_name)
func_code = None
if hasattr(method, 'func_code'): # Python2
func_code = method.func_code
elif hasattr(method, '__code__'): # Python3
func_code = method.__code__
if func_code and func_code == code:
clsname = first_arg_class.__name__
return clsname
def _get_project_roots(project_roots_cache=[]):
# Note: the project_roots_cache is the same instance among the many calls to the method
if not project_roots_cache:
roots = os.getenv('IDE_PROJECT_ROOTS', '').split(os.pathsep)
pydev_log.debug("IDE_PROJECT_ROOTS %s\n" % roots)
new_roots = []
for root in roots:
new_roots.append(os.path.normcase(root))
project_roots_cache.append(new_roots)
return project_roots_cache[-1] # returns the project roots with case normalized
def _get_library_roots(library_roots_cache=[]):
# Note: the project_roots_cache is the same instance among the many calls to the method
if not library_roots_cache:
roots = os.getenv('LIBRARY_ROOTS', '').split(os.pathsep)
pydev_log.debug("LIBRARY_ROOTS %s\n" % roots)
new_roots = []
for root in roots:
new_roots.append(os.path.normcase(root))
library_roots_cache.append(new_roots)
return library_roots_cache[-1] # returns the project roots with case normalized
def not_in_project_roots(filename, filename_to_not_in_scope_cache={}):
# Note: the filename_to_not_in_scope_cache is the same instance among the many calls to the method
try:
return filename_to_not_in_scope_cache[filename]
except:
project_roots = _get_project_roots()
original_filename = filename
if not os.path.isabs(filename) and not filename.startswith('<'):
filename = os.path.abspath(filename)
filename = os.path.normcase(filename)
for root in project_roots:
if filename.startswith(root):
filename_to_not_in_scope_cache[original_filename] = False
break
else: # for else (only called if the break wasn't reached).
filename_to_not_in_scope_cache[original_filename] = True
if not filename_to_not_in_scope_cache[original_filename]:
# additional check if interpreter is situated in a project directory
library_roots = _get_library_roots()
for root in library_roots:
if root != '' and filename.startswith(root):
filename_to_not_in_scope_cache[original_filename] = True
# at this point it must be loaded.
return filename_to_not_in_scope_cache[original_filename]
def is_filter_enabled():
return os.getenv('PYDEVD_FILTERS') is not None
def is_filter_libraries():
is_filter = os.getenv('PYDEVD_FILTER_LIBRARIES') is not None
pydev_log.debug("PYDEVD_FILTER_LIBRARIES %s\n" % is_filter)
return is_filter
def _get_stepping_filters(filters_cache=[]):
if not filters_cache:
filters = os.getenv('PYDEVD_FILTERS', '').split(';')
pydev_log.debug("PYDEVD_FILTERS %s\n" % filters)
new_filters = []
for new_filter in filters:
new_filters.append(new_filter)
filters_cache.append(new_filters)
return filters_cache[-1]
def is_ignored_by_filter(filename, filename_to_ignored_by_filters_cache={}):
try:
return filename_to_ignored_by_filters_cache[filename]
except:
import fnmatch
for stepping_filter in _get_stepping_filters():
if fnmatch.fnmatch(filename, stepping_filter):
pydev_log.debug("File %s ignored by filter %s" % (filename, stepping_filter))
filename_to_ignored_by_filters_cache[filename] = True
break
else:
filename_to_ignored_by_filters_cache[filename] = False
return filename_to_ignored_by_filters_cache[filename]
|
epl-1.0
|
[
504,
636,
2443,
363,
492,
6032,
63,
14129,
199,
646,
5190,
199,
646,
747,
199,
199,
893,
26,
272,
687,
4011,
492,
6313,
199,
2590,
26,
272,
687,
4011,
14,
1122,
492,
6313,
221,
327,
768,
1358,
13697,
6295,
199,
199,
646,
6485,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5559,
492,
2281,
63,
4521,
19,
43,
199,
646,
984,
199,
504,
485,
23996,
63,
6469,
492,
29240,
63,
793,
199,
199,
318,
3354,
63,
973,
63,
578,
8,
493,
12,
859,
63,
354,
304,
272,
327,
3371,
2741,
701,
26,
428,
331,
6215,
22985,
274,
338,
281,
446,
1380,
2884,
365,
1255,
12,
652,
1630,
440,
272,
327,
675,
7992,
687,
29240,
68,
26,
272,
327,
961,
911,
7981,
314,
29240,
68,
2884,
687,
13770,
32374,
1958,
314,
3231,
367,
314,
2884,
370,
506,
3105,
3046,
272,
327,
27830,
29240,
68,
365,
440,
314,
2446,
859,
12,
436,
272,
327,
8260,
2855,
314,
570,
370,
506,
3105,
3046,
626,
652,
1990,
6511,
465,
2446,
272,
984,
14,
3112,
59,
578,
63,
354,
61,
275,
984,
14,
3112,
13742,
973,
17501,
272,
984,
14,
3112,
59,
578,
63,
354,
17979,
354,
363,
275,
859,
63,
354,
272,
687,
1742,
492,
892,
63,
578,
339,
333,
275,
892,
63,
578,
10714,
973,
13766,
272,
984,
14,
3112,
13742,
973,
17501,
275,
333,
272,
340,
2688,
8,
1274,
14,
3112,
59,
578,
63,
354,
467,
2560,
3422,
12168,
267,
5371,
8,
77,
12,
2560,
3422,
7500,
2519,
8,
1274,
14,
3112,
59,
578,
63,
354,
467,
2560,
3422,
363,
1333,
272,
333,
855,
493,
363,
275,
570,
339,
372,
333,
421,
199,
318,
370,
63,
1955,
8,
88,
304,
272,
340,
365,
63,
875,
8,
88,
304,
267,
862,
26,
288,
302,
275,
2069,
8,
88,
9,
288,
372,
302,
267,
871,
1722,
26,
288,
986,
398,
634,
275,
671,
14,
1623,
14097,
358,
267,
340,
634,
1137,
446,
17,
26,
288,
612,
275,
671,
59,
16,
26,
76,
13,
17,
61,
288,
327,
1361,
612,
288,
862,
26,
355,
302,
275,
2069,
8,
89,
9,
355,
372,
302,
288,
871,
1722,
26,
355,
986,
272,
372,
488,
199,
199,
318,
6540,
63,
785,
63,
3288,
8,
88,
12,
612,
304,
272,
862,
26,
267,
340,
671,
508,
612,
26,
288,
372,
378,
267,
671,
63,
1507,
275,
370,
63,
1955,
8,
88,
9,
267,
612,
63,
1507,
275,
370,
63,
1955,
8,
89,
9,
267,
340,
671,
63,
1507,
365,
440,
488,
436,
612,
63,
1507,
365,
440,
488,
26,
288,
340,
671,
63,
1507,
446,
612,
63,
1507,
28,
16,
26,
355,
372,
446,
17,
288,
587,
26,
355,
372,
413,
267,
340,
2560,
552,
12217,
508,
671,
26,
288,
372,
446,
17,
267,
340,
2560,
552,
12217,
508,
612,
26,
288,
372,
413,
398,
372,
671,
855,
5730,
721,
89,
9,
272,
871,
26,
267,
340,
2281,
63,
4521,
19,
43,
26,
288,
372,
334,
475,
63,
875,
8,
88,
9,
690,
370,
63,
875,
8,
89,
430,
446,
334,
475,
63,
875,
8,
88,
9,
665,
370,
63,
875,
8,
89,
430,
267,
587,
26,
288,
372,
10467,
8,
475,
63,
875,
8,
88,
395,
370,
63,
875,
8,
89,
430,
199,
199,
318,
10467,
63,
475,
63,
498,
8,
1662,
5730,
304,
272,
283,
7306,
282,
10467,
29,
805,
1901,
282,
790,
29,
805,
7,
272,
1021,
1804,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
1559,
12,
627,
589,
304,
288,
291,
14,
1113,
275,
1559,
267,
347,
636,
4116,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
665,
378,
267,
347,
636,
3308,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
690,
378,
267,
347,
636,
4077,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
508,
378,
267,
347,
636,
274,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
2695,
378,
267,
347,
636,
303,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
2356,
378,
267,
347,
636,
685,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
1137,
378,
272,
372,
1804,
199,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
347,
365,
63,
875,
8,
88,
304,
267,
372,
1228,
8,
88,
12,
620,
9,
199,
199,
2836,
26,
272,
347,
365,
63,
875,
8,
88,
304,
267,
372,
1228,
8,
88,
12,
7116,
9,
199,
199,
318,
370,
63,
875,
8,
88,
304,
272,
340,
365,
63,
875,
8,
88,
304,
267,
372,
671,
272,
587,
26,
267,
372,
620,
8,
88,
9,
199,
199,
318,
870,
63,
2804,
837,
272,
340,
5190,
26,
267,
5190,
14,
1361,
63,
2804,
342,
199,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
347,
6313,
63,
7853,
8,
83,
12,
5048,
8805,
735,
267,
372,
6313,
8,
83,
12,
5048,
9,
199,
2836,
26,
272,
347,
6313,
63,
7853,
8,
83,
12,
5048,
8805,
735,
267,
340,
1228,
8,
83,
12,
2649,
304,
288,
308,
275,
221,
308,
14,
2143,
360,
1624,
13,
24,
358,
398,
372,
6313,
8,
83,
12,
5048,
9,
421,
199,
318,
664,
63,
1886,
354,
63,
509,
63,
600,
8,
600,
12,
2787,
304,
272,
843,
354,
275,
488,
272,
340,
822,
8,
600,
14,
331,
63,
1391,
1247,
9,
690,
378,
26,
267,
327,
2136,
787,
7907,
314,
1642,
1423,
402,
314,
805,
267,
327,
13493,
277,
64,
503,
658,
1886,
64,
367,
3102,
680,
267,
1642,
63,
1273,
63,
354,
275,
1233,
14,
331,
63,
1391,
1247,
59,
16,
61,
267,
340,
1642,
63,
1273,
63,
354,
315,
2787,
14,
70,
63,
9350,
26,
288,
1642,
63,
1273,
63,
1113,
275,
2787,
14,
70,
63,
9350,
59,
2246,
63,
1273,
63,
354,
61,
288,
340,
6485,
14,
28450,
8,
2246,
63,
1273,
63,
1113,
304,
221,
327,
1021,
1083,
355,
1642,
63,
1273,
63,
533
] |
[
636,
2443,
363,
492,
6032,
63,
14129,
199,
646,
5190,
199,
646,
747,
199,
199,
893,
26,
272,
687,
4011,
492,
6313,
199,
2590,
26,
272,
687,
4011,
14,
1122,
492,
6313,
221,
327,
768,
1358,
13697,
6295,
199,
199,
646,
6485,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5559,
492,
2281,
63,
4521,
19,
43,
199,
646,
984,
199,
504,
485,
23996,
63,
6469,
492,
29240,
63,
793,
199,
199,
318,
3354,
63,
973,
63,
578,
8,
493,
12,
859,
63,
354,
304,
272,
327,
3371,
2741,
701,
26,
428,
331,
6215,
22985,
274,
338,
281,
446,
1380,
2884,
365,
1255,
12,
652,
1630,
440,
272,
327,
675,
7992,
687,
29240,
68,
26,
272,
327,
961,
911,
7981,
314,
29240,
68,
2884,
687,
13770,
32374,
1958,
314,
3231,
367,
314,
2884,
370,
506,
3105,
3046,
272,
327,
27830,
29240,
68,
365,
440,
314,
2446,
859,
12,
436,
272,
327,
8260,
2855,
314,
570,
370,
506,
3105,
3046,
626,
652,
1990,
6511,
465,
2446,
272,
984,
14,
3112,
59,
578,
63,
354,
61,
275,
984,
14,
3112,
13742,
973,
17501,
272,
984,
14,
3112,
59,
578,
63,
354,
17979,
354,
363,
275,
859,
63,
354,
272,
687,
1742,
492,
892,
63,
578,
339,
333,
275,
892,
63,
578,
10714,
973,
13766,
272,
984,
14,
3112,
13742,
973,
17501,
275,
333,
272,
340,
2688,
8,
1274,
14,
3112,
59,
578,
63,
354,
467,
2560,
3422,
12168,
267,
5371,
8,
77,
12,
2560,
3422,
7500,
2519,
8,
1274,
14,
3112,
59,
578,
63,
354,
467,
2560,
3422,
363,
1333,
272,
333,
855,
493,
363,
275,
570,
339,
372,
333,
421,
199,
318,
370,
63,
1955,
8,
88,
304,
272,
340,
365,
63,
875,
8,
88,
304,
267,
862,
26,
288,
302,
275,
2069,
8,
88,
9,
288,
372,
302,
267,
871,
1722,
26,
288,
986,
398,
634,
275,
671,
14,
1623,
14097,
358,
267,
340,
634,
1137,
446,
17,
26,
288,
612,
275,
671,
59,
16,
26,
76,
13,
17,
61,
288,
327,
1361,
612,
288,
862,
26,
355,
302,
275,
2069,
8,
89,
9,
355,
372,
302,
288,
871,
1722,
26,
355,
986,
272,
372,
488,
199,
199,
318,
6540,
63,
785,
63,
3288,
8,
88,
12,
612,
304,
272,
862,
26,
267,
340,
671,
508,
612,
26,
288,
372,
378,
267,
671,
63,
1507,
275,
370,
63,
1955,
8,
88,
9,
267,
612,
63,
1507,
275,
370,
63,
1955,
8,
89,
9,
267,
340,
671,
63,
1507,
365,
440,
488,
436,
612,
63,
1507,
365,
440,
488,
26,
288,
340,
671,
63,
1507,
446,
612,
63,
1507,
28,
16,
26,
355,
372,
446,
17,
288,
587,
26,
355,
372,
413,
267,
340,
2560,
552,
12217,
508,
671,
26,
288,
372,
446,
17,
267,
340,
2560,
552,
12217,
508,
612,
26,
288,
372,
413,
398,
372,
671,
855,
5730,
721,
89,
9,
272,
871,
26,
267,
340,
2281,
63,
4521,
19,
43,
26,
288,
372,
334,
475,
63,
875,
8,
88,
9,
690,
370,
63,
875,
8,
89,
430,
446,
334,
475,
63,
875,
8,
88,
9,
665,
370,
63,
875,
8,
89,
430,
267,
587,
26,
288,
372,
10467,
8,
475,
63,
875,
8,
88,
395,
370,
63,
875,
8,
89,
430,
199,
199,
318,
10467,
63,
475,
63,
498,
8,
1662,
5730,
304,
272,
283,
7306,
282,
10467,
29,
805,
1901,
282,
790,
29,
805,
7,
272,
1021,
1804,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
1559,
12,
627,
589,
304,
288,
291,
14,
1113,
275,
1559,
267,
347,
636,
4116,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
665,
378,
267,
347,
636,
3308,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
690,
378,
267,
347,
636,
4077,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
508,
378,
267,
347,
636,
274,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
2695,
378,
267,
347,
636,
303,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
2356,
378,
267,
347,
636,
685,
721,
277,
12,
1163,
304,
288,
372,
3002,
5730,
8,
277,
14,
1113,
12,
1163,
14,
1113,
9,
1137,
378,
272,
372,
1804,
199,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
347,
365,
63,
875,
8,
88,
304,
267,
372,
1228,
8,
88,
12,
620,
9,
199,
199,
2836,
26,
272,
347,
365,
63,
875,
8,
88,
304,
267,
372,
1228,
8,
88,
12,
7116,
9,
199,
199,
318,
370,
63,
875,
8,
88,
304,
272,
340,
365,
63,
875,
8,
88,
304,
267,
372,
671,
272,
587,
26,
267,
372,
620,
8,
88,
9,
199,
199,
318,
870,
63,
2804,
837,
272,
340,
5190,
26,
267,
5190,
14,
1361,
63,
2804,
342,
199,
199,
692,
2281,
63,
4521,
19,
43,
26,
272,
347,
6313,
63,
7853,
8,
83,
12,
5048,
8805,
735,
267,
372,
6313,
8,
83,
12,
5048,
9,
199,
2836,
26,
272,
347,
6313,
63,
7853,
8,
83,
12,
5048,
8805,
735,
267,
340,
1228,
8,
83,
12,
2649,
304,
288,
308,
275,
221,
308,
14,
2143,
360,
1624,
13,
24,
358,
398,
372,
6313,
8,
83,
12,
5048,
9,
421,
199,
318,
664,
63,
1886,
354,
63,
509,
63,
600,
8,
600,
12,
2787,
304,
272,
843,
354,
275,
488,
272,
340,
822,
8,
600,
14,
331,
63,
1391,
1247,
9,
690,
378,
26,
267,
327,
2136,
787,
7907,
314,
1642,
1423,
402,
314,
805,
267,
327,
13493,
277,
64,
503,
658,
1886,
64,
367,
3102,
680,
267,
1642,
63,
1273,
63,
354,
275,
1233,
14,
331,
63,
1391,
1247,
59,
16,
61,
267,
340,
1642,
63,
1273,
63,
354,
315,
2787,
14,
70,
63,
9350,
26,
288,
1642,
63,
1273,
63,
1113,
275,
2787,
14,
70,
63,
9350,
59,
2246,
63,
1273,
63,
354,
61,
288,
340,
6485,
14,
28450,
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
] |
girving/tensorflow
|
tensorflow/contrib/gan/python/eval/python/sliced_wasserstein.py
|
43
|
1211
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Model evaluation tools for TFGAN."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.gan.python.eval.python import sliced_wasserstein_impl
# pylint: disable=wildcard-import
from tensorflow.contrib.gan.python.eval.python.sliced_wasserstein_impl import *
# pylint: enable=wildcard-import
from tensorflow.python.util.all_util import remove_undocumented
__all__ = sliced_wasserstein_impl.__all__
remove_undocumented(__name__, __all__)
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1685,
11735,
7249,
367,
21721,
39,
879,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
24975,
14,
1548,
14,
2579,
14,
1548,
492,
6014,
68,
63,
10274,
332,
1597,
262,
63,
5472,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
199,
504,
3228,
14,
2828,
14,
24975,
14,
1548,
14,
2579,
14,
1548,
14,
5224,
68,
63,
10274,
332,
1597,
262,
63,
5472,
492,
627,
199,
3,
4287,
26,
4756,
29,
16692,
13,
646,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
363,
452,
363,
275,
6014,
68,
63,
10274,
332,
1597,
262,
63,
5472,
855,
452,
363,
199,
2168,
63,
30107,
12546,
3460,
354,
3108,
636,
452,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1685,
11735,
7249,
367,
21721,
39,
879,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
24975,
14,
1548,
14,
2579,
14,
1548,
492,
6014,
68,
63,
10274,
332,
1597,
262,
63,
5472,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
199,
504,
3228,
14,
2828,
14,
24975,
14,
1548,
14,
2579,
14,
1548,
14,
5224,
68,
63,
10274,
332,
1597,
262,
63,
5472,
492,
627,
199,
3,
4287,
26,
4756,
29,
16692,
13,
646,
199,
504,
3228,
14,
1548,
14,
1974,
14,
452,
63,
1974,
492,
2813,
63,
30107,
12546,
199,
199,
363,
452,
363,
275,
6014,
68,
63,
10274,
332,
1597,
262,
63,
5472,
855,
452,
363,
199,
2168,
63,
30107,
12546,
3460,
354,
3108,
636,
452,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
pbjr23/django-projects
|
mysite/settings.py
|
1
|
1989
|
"""
Django settings for mysite project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!7_)*hjqmi8c8krb!nys^h7woe+*agqke2ma^*c9dn-72d5a$a'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/home/prakhar/prj/django-projects/mysite/sqlite3.db',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'EST'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
|
gpl-2.0
|
[
624,
199,
9323,
2202,
367,
3002,
2124,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
646,
747,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
14597,
23,
63,
3342,
72,
74,
81,
2664,
24,
67,
24,
75,
4848,
1,
78,
588,
62,
72,
23,
2027,
69,
11,
10,
643,
81,
415,
18,
391,
62,
10,
67,
25,
4272,
13,
2819,
68,
21,
65,
4,
65,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
7433,
63,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
942,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
283,
1662,
2124,
14,
3603,
7,
199,
199,
16828,
63,
24051,
275,
283,
1662,
2124,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
1994,
4219,
15,
80,
345,
75,
8210,
15,
2700,
74,
15,
1176,
13,
6776,
15,
1662,
2124,
15,
10659,
19,
14,
697,
297,
272,
789,
199,
93,
199,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
1719,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
9323,
2202,
367,
3002,
2124,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
646,
747,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
14597,
23,
63,
3342,
72,
74,
81,
2664,
24,
67,
24,
75,
4848,
1,
78,
588,
62,
72,
23,
2027,
69,
11,
10,
643,
81,
415,
18,
391,
62,
10,
67,
25,
4272,
13,
2819,
68,
21,
65,
4,
65,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
7433,
63,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
942,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
9,
199,
199,
5441,
63,
18125,
275,
283,
1662,
2124,
14,
3603,
7,
199,
199,
16828,
63,
24051,
275,
283,
1662,
2124,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
1994,
4219,
15,
80,
345,
75,
8210,
15,
2700,
74,
15,
1176,
13,
6776,
15,
1662,
2124,
15,
10659,
19,
14,
697,
297,
272,
789,
199,
93,
199,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
1719,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sdecoder/CMDS-HDFS
|
common/build/contrib/hod/testing/helper.py
|
182
|
1122
|
#Licensed to the Apache Software Foundation (ASF) under one
#or more contributor license agreements. See the NOTICE file
#distributed with this work for additional information
#regarding copyright ownership. The ASF licenses this file
#to you under the Apache License, Version 2.0 (the
#"License"); you may not use this file except in compliance
#with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
import sys
sampleText = "Hello World!"
if __name__=="__main__":
args = sys.argv[1:]
if args[0] == "1":
# print sample text to stderr
sys.stdout.write(sampleText)
elif args[0] == "2":
# print sample text to stderr
sys.stderr.write(sampleText)
# Add any other helper programs here, with different values for args[0]
pass
|
apache-2.0
|
[
3,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
3271,
1872,
275,
298,
6257,
13064,
9539,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
523,
1249,
275,
984,
14,
3020,
59,
17,
2938,
523,
340,
1249,
59,
16,
61,
508,
298,
17,
582,
272,
327,
870,
2690,
1318,
370,
4635,
272,
984,
14,
2703,
14,
952,
8,
3271,
1872,
9,
819,
916,
1249,
59,
16,
61,
508,
298,
18,
582,
272,
327,
870,
2690,
1318,
370,
4635,
5591,
984,
14,
3083,
14,
952,
8,
3271,
1872,
9,
819,
327,
2654,
1263,
1163,
5922,
18572,
2348,
12,
543,
3365,
1338,
367,
1249,
59,
16,
61,
523,
986,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
3271,
1872,
275,
298,
6257,
13064,
9539,
199,
199,
692,
636,
354,
363,
11800,
363,
973,
5727,
523,
1249,
275,
984,
14,
3020,
59,
17,
2938,
523,
340,
1249,
59,
16,
61,
508,
298,
17,
582,
272,
327,
870,
2690,
1318,
370,
4635,
272,
984,
14,
2703,
14,
952,
8,
3271,
1872,
9,
819,
916,
1249,
59,
16,
61,
508,
298,
18,
582,
272,
327,
870,
2690,
1318,
370,
4635,
5591,
984,
14,
3083,
14,
952,
8,
3271,
1872,
9,
819,
327,
2654,
1263,
1163,
5922,
18572,
2348,
12,
543,
3365,
1338,
367,
1249,
59,
16,
61,
523,
986,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
w495/scrapy
|
scrapy/utils/trackref.py
|
120
|
2081
|
"""This module provides some functions and classes to record and report
references to live object instances.
If you want live objects for a particular class to be tracked, you only have to
subclass from object_ref (instead of object).
About performance: This library has a minimal performance impact when enabled,
and no performance penalty at all when disabled (as object_ref becomes just an
alias to object in that case).
"""
from __future__ import print_function
import weakref
from time import time
from operator import itemgetter
from collections import defaultdict
import six
NoneType = type(None)
live_refs = defaultdict(weakref.WeakKeyDictionary)
class object_ref(object):
"""Inherit from this class (instead of object) to a keep a record of live
instances"""
__slots__ = ()
def __new__(cls, *args, **kwargs):
obj = object.__new__(cls)
live_refs[cls][obj] = time()
return obj
def format_live_refs(ignore=NoneType):
"""Return a tabular representation of tracked objects"""
s = "Live References\n\n"
now = time()
for cls, wdict in sorted(six.iteritems(live_refs),
key=lambda x: x[0].__name__):
if not wdict:
continue
if issubclass(cls, ignore):
continue
oldest = min(six.itervalues(wdict))
s += "%-30s %6d oldest: %ds ago\n" % (
cls.__name__, len(wdict), now - oldest
)
return s
def print_live_refs(*a, **kw):
"""Print tracked objects"""
print(format_live_refs(*a, **kw))
def get_oldest(class_name):
"""Get the oldest object for a specific class name"""
for cls, wdict in six.iteritems(live_refs):
if cls.__name__ == class_name:
if not wdict:
break
return min(six.iteritems(wdict), key=itemgetter(1))[0]
def iter_all(class_name):
"""Iterate over all objects of the same class by its class name"""
for cls, wdict in six.iteritems(live_refs):
if cls.__name__ == class_name:
return six.iterkeys(wdict)
|
bsd-3-clause
|
[
624,
2765,
859,
6571,
2005,
3423,
436,
3992,
370,
2777,
436,
3622,
199,
12635,
370,
12166,
909,
4454,
14,
199,
199,
3917,
1265,
2934,
12166,
2251,
367,
282,
6770,
1021,
370,
506,
23268,
12,
1265,
1454,
1172,
370,
199,
6083,
687,
909,
63,
1121,
334,
23145,
402,
909,
680,
199,
199,
18816,
10238,
26,
961,
3555,
965,
282,
13460,
10238,
25568,
1380,
5223,
12,
199,
460,
949,
10238,
21251,
737,
1006,
1380,
6980,
334,
305,
909,
63,
1121,
15410,
2951,
376,
199,
3620,
370,
909,
315,
626,
1930,
680,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
13852,
199,
504,
900,
492,
900,
199,
504,
4182,
492,
1242,
7416,
199,
504,
5055,
492,
10018,
199,
646,
3816,
421,
199,
26855,
275,
730,
8,
403,
9,
199,
6442,
63,
7655,
275,
10018,
8,
21330,
14,
18889,
1197,
11728,
9,
421,
199,
533,
909,
63,
1121,
8,
785,
304,
272,
408,
23542,
687,
642,
1021,
334,
23145,
402,
909,
9,
370,
282,
4215,
282,
2777,
402,
12166,
272,
4454,
624,
339,
636,
7257,
363,
275,
6248,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
1559,
275,
909,
855,
1222,
721,
1886,
9,
267,
12166,
63,
7655,
59,
1886,
1527,
1113,
61,
275,
900,
342,
267,
372,
1559,
421,
199,
318,
1475,
63,
6442,
63,
7655,
8,
4247,
29,
26855,
304,
272,
408,
1767,
282,
5174,
2238,
6025,
402,
23268,
2251,
624,
272,
308,
275,
298,
17458,
14504,
60,
78,
60,
78,
2,
272,
3063,
275,
900,
342,
272,
367,
843,
12,
336,
807,
315,
3355,
8,
4174,
14,
4611,
8,
6442,
63,
7655,
395,
2490,
790,
29,
2734,
671,
26,
671,
59,
16,
17979,
354,
18580,
267,
340,
440,
336,
807,
26,
288,
1980,
267,
340,
11602,
8,
1886,
12,
3686,
304,
288,
1980,
267,
29493,
275,
1748,
8,
4174,
14,
13012,
8,
87,
807,
430,
267,
308,
847,
18301,
1216,
83,
450,
22,
68,
257,
29493,
26,
450,
795,
20313,
60,
78,
2,
450,
334,
288,
843,
855,
354,
3108,
822,
8,
87,
807,
395,
3063,
446,
29493,
267,
776,
272,
372,
308,
421,
199,
318,
870,
63,
6442,
63,
7655,
2031,
65,
12,
1011,
829,
304,
272,
408,
5375,
23268,
2251,
624,
272,
870,
8,
908,
63,
6442,
63,
7655,
2031,
65,
12,
1011,
829,
430,
421,
199,
318,
664,
63,
393,
2614,
8,
533,
63,
354,
304,
272,
408,
1002,
314,
29493,
909,
367,
282,
2488,
1021,
536,
624,
272,
367,
843,
12,
336,
807,
315,
3816,
14,
4611,
8,
6442,
63,
7655,
304,
267,
340,
843,
855,
354,
363,
508,
1021,
63,
354,
26,
288,
340,
440,
336,
807,
26,
355,
2059,
288,
372,
1748,
8,
4174,
14,
4611,
8,
87,
807,
395,
790,
29,
20832,
8,
17,
11515,
16,
61,
421,
199,
318,
2740,
63,
452,
8,
533,
63,
354,
304,
272,
408,
3315,
323,
1806,
1006,
2251,
402,
314,
2011,
1021,
701,
2399,
1021,
536,
624,
272,
367,
843,
12,
336,
807,
315,
3816,
14,
4611,
8,
6442,
63,
7655,
304,
267,
340,
843,
855,
354,
363,
508,
1021,
63,
354,
26,
288,
372,
3816,
14,
16007,
8,
87,
807,
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
] |
[
2765,
859,
6571,
2005,
3423,
436,
3992,
370,
2777,
436,
3622,
199,
12635,
370,
12166,
909,
4454,
14,
199,
199,
3917,
1265,
2934,
12166,
2251,
367,
282,
6770,
1021,
370,
506,
23268,
12,
1265,
1454,
1172,
370,
199,
6083,
687,
909,
63,
1121,
334,
23145,
402,
909,
680,
199,
199,
18816,
10238,
26,
961,
3555,
965,
282,
13460,
10238,
25568,
1380,
5223,
12,
199,
460,
949,
10238,
21251,
737,
1006,
1380,
6980,
334,
305,
909,
63,
1121,
15410,
2951,
376,
199,
3620,
370,
909,
315,
626,
1930,
680,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
13852,
199,
504,
900,
492,
900,
199,
504,
4182,
492,
1242,
7416,
199,
504,
5055,
492,
10018,
199,
646,
3816,
421,
199,
26855,
275,
730,
8,
403,
9,
199,
6442,
63,
7655,
275,
10018,
8,
21330,
14,
18889,
1197,
11728,
9,
421,
199,
533,
909,
63,
1121,
8,
785,
304,
272,
408,
23542,
687,
642,
1021,
334,
23145,
402,
909,
9,
370,
282,
4215,
282,
2777,
402,
12166,
272,
4454,
624,
339,
636,
7257,
363,
275,
6248,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
1559,
275,
909,
855,
1222,
721,
1886,
9,
267,
12166,
63,
7655,
59,
1886,
1527,
1113,
61,
275,
900,
342,
267,
372,
1559,
421,
199,
318,
1475,
63,
6442,
63,
7655,
8,
4247,
29,
26855,
304,
272,
408,
1767,
282,
5174,
2238,
6025,
402,
23268,
2251,
624,
272,
308,
275,
298,
17458,
14504,
60,
78,
60,
78,
2,
272,
3063,
275,
900,
342,
272,
367,
843,
12,
336,
807,
315,
3355,
8,
4174,
14,
4611,
8,
6442,
63,
7655,
395,
2490,
790,
29,
2734,
671,
26,
671,
59,
16,
17979,
354,
18580,
267,
340,
440,
336,
807,
26,
288,
1980,
267,
340,
11602,
8,
1886,
12,
3686,
304,
288,
1980,
267,
29493,
275,
1748,
8,
4174,
14,
13012,
8,
87,
807,
430,
267,
308,
847,
18301,
1216,
83,
450,
22,
68,
257,
29493,
26,
450,
795,
20313,
60,
78,
2,
450,
334,
288,
843,
855,
354,
3108,
822,
8,
87,
807,
395,
3063,
446,
29493,
267,
776,
272,
372,
308,
421,
199,
318,
870,
63,
6442,
63,
7655,
2031,
65,
12,
1011,
829,
304,
272,
408,
5375,
23268,
2251,
624,
272,
870,
8,
908,
63,
6442,
63,
7655,
2031,
65,
12,
1011,
829,
430,
421,
199,
318,
664,
63,
393,
2614,
8,
533,
63,
354,
304,
272,
408,
1002,
314,
29493,
909,
367,
282,
2488,
1021,
536,
624,
272,
367,
843,
12,
336,
807,
315,
3816,
14,
4611,
8,
6442,
63,
7655,
304,
267,
340,
843,
855,
354,
363,
508,
1021,
63,
354,
26,
288,
340,
440,
336,
807,
26,
355,
2059,
288,
372,
1748,
8,
4174,
14,
4611,
8,
87,
807,
395,
790,
29,
20832,
8,
17,
11515,
16,
61,
421,
199,
318,
2740,
63,
452,
8,
533,
63,
354,
304,
272,
408,
3315,
323,
1806,
1006,
2251,
402,
314,
2011,
1021,
701,
2399,
1021,
536,
624,
272,
367,
843,
12,
336,
807,
315,
3816,
14,
4611,
8,
6442,
63,
7655,
304,
267,
340,
843,
855,
354,
363,
508,
1021,
63,
354,
26,
288,
372,
3816,
14,
16007,
8,
87,
807,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pevzi/django-debug-toolbar
|
tests/panels/test_logging.py
|
4
|
2678
|
# coding: utf-8
from __future__ import absolute_import, unicode_literals
import logging
from debug_toolbar.panels.logging import (
MESSAGE_IF_STRING_REPRESENTATION_INVALID, collector,
)
from ..base import BaseTestCase
class LoggingPanelTestCase(BaseTestCase):
def setUp(self):
super(LoggingPanelTestCase, self).setUp()
self.panel = self.toolbar.get_panel_by_id('LoggingPanel')
self.logger = logging.getLogger(__name__)
collector.clear_collection()
# Assume the root logger has been configured with level=DEBUG.
# Previously DDT forcefully set this itself to 0 (NOTSET).
logging.root.setLevel(logging.DEBUG)
def test_happy_case(self):
self.logger.info('Nothing to see here, move along!')
self.panel.process_response(self.request, self.response)
self.panel.generate_stats(self.request, self.response)
records = self.panel.get_stats()['records']
self.assertEqual(1, len(records))
self.assertEqual('Nothing to see here, move along!',
records[0]['message'])
def test_formatting(self):
self.logger.info('There are %d %s', 5, 'apples')
self.panel.process_response(self.request, self.response)
self.panel.generate_stats(self.request, self.response)
records = self.panel.get_stats()['records']
self.assertEqual(1, len(records))
self.assertEqual('There are 5 apples',
records[0]['message'])
def test_insert_content(self):
"""
Test that the panel only inserts content after generate_stats and
not the process_response.
"""
self.logger.info('café')
self.panel.process_response(self.request, self.response)
# ensure the panel does not have content yet.
self.assertNotIn('café', self.panel.content)
self.panel.generate_stats(self.request, self.response)
# ensure the panel renders correctly.
self.assertIn('café', self.panel.content)
def test_failing_formatting(self):
class BadClass(object):
def __str__(self):
raise Exception('Please not stringify me!')
# should not raise exception, but fail silently
self.logger.debug('This class is misbehaving: %s', BadClass())
self.panel.process_response(self.request, self.response)
self.panel.generate_stats(self.request, self.response)
records = self.panel.get_stats()['records']
self.assertEqual(1, len(records))
self.assertEqual(MESSAGE_IF_STRING_REPRESENTATION_INVALID,
records[0]['message'])
|
bsd-3-clause
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
2050,
199,
199,
504,
3105,
63,
13951,
14,
31929,
14,
4806,
492,
334,
272,
603,
1608,
2962,
63,
4656,
63,
5353,
63,
907,
27160,
63,
9692,
12,
14910,
12,
199,
9,
199,
199,
504,
2508,
1095,
492,
3523,
1746,
421,
199,
533,
19928,
10185,
1746,
8,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14054,
10185,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
7885,
275,
291,
14,
13951,
14,
362,
63,
7885,
63,
991,
63,
344,
360,
14054,
10185,
358,
267,
291,
14,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
14910,
14,
3584,
63,
3627,
342,
398,
327,
16269,
314,
1738,
2512,
965,
2757,
7526,
543,
2166,
29,
5287,
14,
267,
327,
26902,
590,
577,
7438,
3542,
5836,
663,
642,
6337,
370,
378,
334,
4609,
3597,
680,
267,
2050,
14,
1231,
14,
13548,
8,
4806,
14,
5287,
9,
339,
347,
511,
63,
72,
18869,
63,
2546,
8,
277,
304,
267,
291,
14,
2921,
14,
815,
360,
19627,
370,
1937,
2348,
12,
4057,
3180,
10916,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
360,
19627,
370,
1937,
2348,
12,
4057,
3180,
12389,
586,
5767,
59,
16,
2733,
1188,
1105,
339,
347,
511,
63,
20034,
8,
277,
304,
267,
291,
14,
2921,
14,
815,
360,
10924,
787,
450,
68,
450,
83,
297,
959,
12,
283,
571,
2978,
358,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
360,
10924,
787,
959,
1145,
2978,
297,
586,
5767,
59,
16,
2733,
1188,
1105,
339,
347,
511,
63,
3176,
63,
1317,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
12748,
1454,
28203,
1564,
2410,
3550,
63,
3200,
436,
267,
440,
314,
2112,
63,
1310,
14,
267,
408,
267,
291,
14,
2921,
14,
815,
360,
27956,
5741,
358,
267,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
327,
4868,
314,
12748,
1630,
440,
1172,
1564,
5966,
14,
267,
291,
14,
8795,
360,
27956,
5741,
297,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
327,
4868,
314,
12748,
3795,
83,
6657,
14,
267,
291,
14,
4080,
360,
27956,
5741,
297,
291,
14,
7885,
14,
1317,
9,
339,
347,
511,
63,
25299,
63,
20034,
8,
277,
304,
267,
1021,
8857,
2543,
8,
785,
304,
288,
347,
636,
495,
721,
277,
304,
355,
746,
2186,
360,
8254,
440,
1059,
2021,
562,
10916,
398,
327,
1077,
440,
746,
1919,
12,
1325,
2449,
18030,
267,
291,
14,
2921,
14,
1757,
360,
2765,
1021,
365,
3201,
25599,
5519,
26,
450,
83,
297,
8857,
2543,
1012,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
8,
8272,
63,
4656,
63,
5353,
63,
907,
27160,
63,
9692,
12,
586,
5767,
59,
16,
2733,
1188,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
646,
2050,
199,
199,
504,
3105,
63,
13951,
14,
31929,
14,
4806,
492,
334,
272,
603,
1608,
2962,
63,
4656,
63,
5353,
63,
907,
27160,
63,
9692,
12,
14910,
12,
199,
9,
199,
199,
504,
2508,
1095,
492,
3523,
1746,
421,
199,
533,
19928,
10185,
1746,
8,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14054,
10185,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
7885,
275,
291,
14,
13951,
14,
362,
63,
7885,
63,
991,
63,
344,
360,
14054,
10185,
358,
267,
291,
14,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
14910,
14,
3584,
63,
3627,
342,
398,
327,
16269,
314,
1738,
2512,
965,
2757,
7526,
543,
2166,
29,
5287,
14,
267,
327,
26902,
590,
577,
7438,
3542,
5836,
663,
642,
6337,
370,
378,
334,
4609,
3597,
680,
267,
2050,
14,
1231,
14,
13548,
8,
4806,
14,
5287,
9,
339,
347,
511,
63,
72,
18869,
63,
2546,
8,
277,
304,
267,
291,
14,
2921,
14,
815,
360,
19627,
370,
1937,
2348,
12,
4057,
3180,
10916,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
360,
19627,
370,
1937,
2348,
12,
4057,
3180,
12389,
586,
5767,
59,
16,
2733,
1188,
1105,
339,
347,
511,
63,
20034,
8,
277,
304,
267,
291,
14,
2921,
14,
815,
360,
10924,
787,
450,
68,
450,
83,
297,
959,
12,
283,
571,
2978,
358,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
360,
10924,
787,
959,
1145,
2978,
297,
586,
5767,
59,
16,
2733,
1188,
1105,
339,
347,
511,
63,
3176,
63,
1317,
8,
277,
304,
267,
408,
267,
1379,
626,
314,
12748,
1454,
28203,
1564,
2410,
3550,
63,
3200,
436,
267,
440,
314,
2112,
63,
1310,
14,
267,
408,
267,
291,
14,
2921,
14,
815,
360,
27956,
5741,
358,
267,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
327,
4868,
314,
12748,
1630,
440,
1172,
1564,
5966,
14,
267,
291,
14,
8795,
360,
27956,
5741,
297,
291,
14,
7885,
14,
1317,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
327,
4868,
314,
12748,
3795,
83,
6657,
14,
267,
291,
14,
4080,
360,
27956,
5741,
297,
291,
14,
7885,
14,
1317,
9,
339,
347,
511,
63,
25299,
63,
20034,
8,
277,
304,
267,
1021,
8857,
2543,
8,
785,
304,
288,
347,
636,
495,
721,
277,
304,
355,
746,
2186,
360,
8254,
440,
1059,
2021,
562,
10916,
398,
327,
1077,
440,
746,
1919,
12,
1325,
2449,
18030,
267,
291,
14,
2921,
14,
1757,
360,
2765,
1021,
365,
3201,
25599,
5519,
26,
450,
83,
297,
8857,
2543,
1012,
398,
291,
14,
7885,
14,
1412,
63,
1310,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
291,
14,
7885,
14,
4208,
63,
3200,
8,
277,
14,
1069,
12,
291,
14,
1310,
9,
267,
5767,
275,
291,
14,
7885,
14,
362,
63,
3200,
12047,
6502,
418,
398,
291,
14,
629,
8,
17,
12,
822,
8,
6502,
430,
267,
291,
14,
629,
8,
8272,
63,
4656,
63,
5353,
63,
907,
27160,
63,
9692,
12,
586,
5767,
59,
16,
2733,
1188,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CloudWareChile/OpenChile
|
openerp/addons/multi_company/__init__.py
|
886
|
1054
|
# -*- 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/>.
#
##############################################################################
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
elijah513/scrapy
|
tests/test_http_cookies.py
|
94
|
2499
|
from six.moves.urllib.parse import urlparse
from unittest import TestCase
from scrapy.http import Request, Response
from scrapy.http.cookies import WrappedRequest, WrappedResponse
class WrappedRequestTest(TestCase):
def setUp(self):
self.request = Request("http://www.example.com/page.html",
headers={"Content-Type": "text/html"})
self.wrapped = WrappedRequest(self.request)
def test_get_full_url(self):
self.assertEqual(self.wrapped.get_full_url(), self.request.url)
def test_get_host(self):
self.assertEqual(self.wrapped.get_host(), urlparse(self.request.url).netloc)
def test_get_type(self):
self.assertEqual(self.wrapped.get_type(), urlparse(self.request.url).scheme)
def test_is_unverifiable(self):
self.assertFalse(self.wrapped.is_unverifiable())
self.assertFalse(self.wrapped.unverifiable)
def test_is_unverifiable2(self):
self.request.meta['is_unverifiable'] = True
self.assertTrue(self.wrapped.is_unverifiable())
self.assertTrue(self.wrapped.unverifiable)
def test_get_origin_req_host(self):
self.assertEqual(self.wrapped.get_origin_req_host(), 'www.example.com')
def test_has_header(self):
self.assertTrue(self.wrapped.has_header('content-type'))
self.assertFalse(self.wrapped.has_header('xxxxx'))
def test_get_header(self):
self.assertEqual(self.wrapped.get_header('content-type'), 'text/html')
self.assertEqual(self.wrapped.get_header('xxxxx', 'def'), 'def')
def test_header_items(self):
self.assertEqual(self.wrapped.header_items(),
[('Content-Type', ['text/html'])])
def test_add_unredirected_header(self):
self.wrapped.add_unredirected_header('hello', 'world')
self.assertEqual(self.request.headers['hello'], b'world')
class WrappedResponseTest(TestCase):
def setUp(self):
self.response = Response("http://www.example.com/page.html",
headers={"Content-TYpe": "text/html"})
self.wrapped = WrappedResponse(self.response)
def test_info(self):
self.assert_(self.wrapped.info() is self.wrapped)
def test_getheaders(self):
self.assertEqual(self.wrapped.getheaders('content-type'), ['text/html'])
def test_get_all(self):
# get_all result must be native string
self.assertEqual(self.wrapped.get_all('content-type'), ['text/html'])
|
bsd-3-clause
|
[
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
199,
504,
2882,
492,
7640,
199,
199,
504,
18918,
14,
1014,
492,
4784,
12,
7232,
199,
504,
18918,
14,
1014,
14,
7792,
492,
20322,
1915,
2017,
12,
20322,
1915,
2364,
421,
199,
533,
20322,
1915,
2017,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1069,
275,
4784,
480,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1606,
14,
1360,
401,
3044,
2323,
8871,
2714,
13,
804,
582,
298,
505,
15,
1360,
5984,
267,
291,
14,
9130,
275,
20322,
1915,
2017,
8,
277,
14,
1069,
9,
339,
347,
511,
63,
362,
63,
2861,
63,
633,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
2861,
63,
633,
1062,
291,
14,
1069,
14,
633,
9,
339,
347,
511,
63,
362,
63,
1102,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1102,
1062,
7097,
8,
277,
14,
1069,
14,
633,
680,
12652,
9,
339,
347,
511,
63,
362,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
466,
1062,
7097,
8,
277,
14,
1069,
14,
633,
680,
5512,
9,
339,
347,
511,
63,
374,
63,
324,
422,
1903,
461,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
374,
63,
324,
422,
1903,
461,
1012,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
324,
422,
1903,
461,
9,
339,
347,
511,
63,
374,
63,
324,
422,
1903,
461,
18,
8,
277,
304,
267,
291,
14,
1069,
14,
2024,
459,
374,
63,
324,
422,
1903,
461,
418,
275,
715,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
374,
63,
324,
422,
1903,
461,
1012,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
324,
422,
1903,
461,
9,
339,
347,
511,
63,
362,
63,
6493,
63,
2103,
63,
1102,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
6493,
63,
2103,
63,
1102,
1062,
283,
1544,
14,
2694,
14,
957,
358,
339,
347,
511,
63,
1989,
63,
1291,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
1989,
63,
1291,
360,
1317,
13,
466,
1333,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
1989,
63,
1291,
360,
5336,
88,
1333,
339,
347,
511,
63,
362,
63,
1291,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1291,
360,
1317,
13,
466,
659,
283,
505,
15,
1360,
358,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1291,
360,
5336,
88,
297,
283,
318,
659,
283,
318,
358,
339,
347,
511,
63,
1291,
63,
1744,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
1291,
63,
1744,
1062,
586,
4274,
2714,
13,
804,
297,
788,
505,
15,
1360,
31161,
339,
347,
511,
63,
525,
63,
324,
264,
12080,
63,
1291,
8,
277,
304,
267,
291,
14,
9130,
14,
525,
63,
324,
264,
12080,
63,
1291,
360,
5006,
297,
283,
7617,
358,
267,
291,
14,
629,
8,
277,
14,
1069,
14,
2139,
459,
5006,
995,
330,
7,
7617,
358,
421,
199,
533,
20322,
1915,
2364,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1310,
275,
7232,
480,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1606,
14,
1360,
401,
639,
2323,
8871,
2714,
13,
2099,
321,
582,
298,
505,
15,
1360,
5984,
267,
291,
14,
9130,
275,
20322,
1915,
2364,
8,
277,
14,
1310,
9,
339,
347,
511,
63,
815,
8,
277,
304,
267,
291,
14,
479,
2531,
277,
14,
9130,
14,
815,
342,
365,
291,
14,
9130,
9,
339,
347,
511,
63,
19958,
83,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
19958,
83,
360,
1317,
13,
466,
659,
788,
505,
15,
1360,
1105,
339,
347,
511,
63,
362,
63,
452,
8,
277,
304,
267,
327,
664,
63,
452,
754,
1471,
506,
5438,
1059,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
452,
360,
1317,
13,
466,
659,
788,
505,
15,
1360,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3816,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
199,
504,
2882,
492,
7640,
199,
199,
504,
18918,
14,
1014,
492,
4784,
12,
7232,
199,
504,
18918,
14,
1014,
14,
7792,
492,
20322,
1915,
2017,
12,
20322,
1915,
2364,
421,
199,
533,
20322,
1915,
2017,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1069,
275,
4784,
480,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1606,
14,
1360,
401,
3044,
2323,
8871,
2714,
13,
804,
582,
298,
505,
15,
1360,
5984,
267,
291,
14,
9130,
275,
20322,
1915,
2017,
8,
277,
14,
1069,
9,
339,
347,
511,
63,
362,
63,
2861,
63,
633,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
2861,
63,
633,
1062,
291,
14,
1069,
14,
633,
9,
339,
347,
511,
63,
362,
63,
1102,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1102,
1062,
7097,
8,
277,
14,
1069,
14,
633,
680,
12652,
9,
339,
347,
511,
63,
362,
63,
466,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
466,
1062,
7097,
8,
277,
14,
1069,
14,
633,
680,
5512,
9,
339,
347,
511,
63,
374,
63,
324,
422,
1903,
461,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
374,
63,
324,
422,
1903,
461,
1012,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
324,
422,
1903,
461,
9,
339,
347,
511,
63,
374,
63,
324,
422,
1903,
461,
18,
8,
277,
304,
267,
291,
14,
1069,
14,
2024,
459,
374,
63,
324,
422,
1903,
461,
418,
275,
715,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
374,
63,
324,
422,
1903,
461,
1012,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
324,
422,
1903,
461,
9,
339,
347,
511,
63,
362,
63,
6493,
63,
2103,
63,
1102,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
6493,
63,
2103,
63,
1102,
1062,
283,
1544,
14,
2694,
14,
957,
358,
339,
347,
511,
63,
1989,
63,
1291,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
9130,
14,
1989,
63,
1291,
360,
1317,
13,
466,
1333,
267,
291,
14,
3334,
8,
277,
14,
9130,
14,
1989,
63,
1291,
360,
5336,
88,
1333,
339,
347,
511,
63,
362,
63,
1291,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1291,
360,
1317,
13,
466,
659,
283,
505,
15,
1360,
358,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
1291,
360,
5336,
88,
297,
283,
318,
659,
283,
318,
358,
339,
347,
511,
63,
1291,
63,
1744,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
1291,
63,
1744,
1062,
586,
4274,
2714,
13,
804,
297,
788,
505,
15,
1360,
31161,
339,
347,
511,
63,
525,
63,
324,
264,
12080,
63,
1291,
8,
277,
304,
267,
291,
14,
9130,
14,
525,
63,
324,
264,
12080,
63,
1291,
360,
5006,
297,
283,
7617,
358,
267,
291,
14,
629,
8,
277,
14,
1069,
14,
2139,
459,
5006,
995,
330,
7,
7617,
358,
421,
199,
533,
20322,
1915,
2364,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1310,
275,
7232,
480,
1014,
921,
1544,
14,
2694,
14,
957,
15,
1606,
14,
1360,
401,
639,
2323,
8871,
2714,
13,
2099,
321,
582,
298,
505,
15,
1360,
5984,
267,
291,
14,
9130,
275,
20322,
1915,
2364,
8,
277,
14,
1310,
9,
339,
347,
511,
63,
815,
8,
277,
304,
267,
291,
14,
479,
2531,
277,
14,
9130,
14,
815,
342,
365,
291,
14,
9130,
9,
339,
347,
511,
63,
19958,
83,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
19958,
83,
360,
1317,
13,
466,
659,
788,
505,
15,
1360,
1105,
339,
347,
511,
63,
362,
63,
452,
8,
277,
304,
267,
327,
664,
63,
452,
754,
1471,
506,
5438,
1059,
267,
291,
14,
629,
8,
277,
14,
9130,
14,
362,
63,
452,
360,
1317,
13,
466,
659,
788,
505,
15,
1360,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
google/contentbox
|
third_party/django/contrib/auth/__init__.py
|
97
|
5361
|
import re
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.utils.module_loading import import_by_path
from django.middleware.csrf import rotate_token
from .signals import user_logged_in, user_logged_out, user_login_failed
SESSION_KEY = '_auth_user_id'
BACKEND_SESSION_KEY = '_auth_user_backend'
REDIRECT_FIELD_NAME = 'next'
def load_backend(path):
return import_by_path(path)()
def get_backends():
backends = []
for backend_path in settings.AUTHENTICATION_BACKENDS:
backends.append(load_backend(backend_path))
if not backends:
raise ImproperlyConfigured('No authentication backends have been defined. Does AUTHENTICATION_BACKENDS contain anything?')
return backends
def _clean_credentials(credentials):
"""
Cleans a dictionary of credentials of potentially sensitive info before
sending to less secure functions.
Not comprehensive - intended for user_login_failed signal
"""
SENSITIVE_CREDENTIALS = re.compile('api|token|key|secret|password|signature', re.I)
CLEANSED_SUBSTITUTE = '********************'
for key in credentials:
if SENSITIVE_CREDENTIALS.search(key):
credentials[key] = CLEANSED_SUBSTITUTE
return credentials
def authenticate(**credentials):
"""
If the given credentials are valid, return a User object.
"""
for backend in get_backends():
try:
user = backend.authenticate(**credentials)
except TypeError:
# This backend doesn't accept these credentials as arguments. Try the next one.
continue
except PermissionDenied:
# This backend says to stop in our tracks - this user should not be allowed in at all.
return None
if user is None:
continue
# Annotate the user object with the path of the backend.
user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
return user
# The credentials supplied are invalid to all backends, fire signal
user_login_failed.send(sender=__name__,
credentials=_clean_credentials(credentials))
def login(request, user):
"""
Persist a user id and a backend in the request. This way a user doesn't
have to reauthenticate on every request. Note that data set during
the anonymous session is retained when the user logs in.
"""
if user is None:
user = request.user
# TODO: It would be nice to support different login methods, like signed cookies.
if SESSION_KEY in request.session:
if request.session[SESSION_KEY] != user.pk:
# To avoid reusing another user's session, create a new, empty
# session if the existing session corresponds to a different
# authenticated user.
request.session.flush()
else:
request.session.cycle_key()
request.session[SESSION_KEY] = user.pk
request.session[BACKEND_SESSION_KEY] = user.backend
if hasattr(request, 'user'):
request.user = user
rotate_token(request)
user_logged_in.send(sender=user.__class__, request=request, user=user)
def logout(request):
"""
Removes the authenticated user's ID from the request and flushes their
session data.
"""
# Dispatch the signal before the user is logged out so the receivers have a
# chance to find out *who* logged out.
user = getattr(request, 'user', None)
if hasattr(user, 'is_authenticated') and not user.is_authenticated():
user = None
user_logged_out.send(sender=user.__class__, request=request, user=user)
# remember language choice saved to session
language = request.session.get('django_language')
request.session.flush()
if language is not None:
request.session['django_language'] = language
if hasattr(request, 'user'):
from django.contrib.auth.models import AnonymousUser
request.user = AnonymousUser()
def get_user_model():
"""
Returns the User model that is active in this project.
"""
from django.db.models import get_model
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
except ValueError:
raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
user_model = get_model(app_label, model_name)
if user_model is None:
raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL)
return user_model
def get_user(request):
"""
Returns the user model instance associated with the given request session.
If no user is retrieved an instance of `AnonymousUser` is returned.
"""
from .models import AnonymousUser
try:
user_id = request.session[SESSION_KEY]
backend_path = request.session[BACKEND_SESSION_KEY]
assert backend_path in settings.AUTHENTICATION_BACKENDS
backend = load_backend(backend_path)
user = backend.get_user(user_id) or AnonymousUser()
except (KeyError, AssertionError):
user = AnonymousUser()
return user
def get_permission_codename(action, opts):
"""
Returns the codename of the permission for the specified action.
"""
return '%s_%s' % (action, opts.model_name)
|
apache-2.0
|
[
646,
295,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
23724,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
991,
63,
515,
199,
504,
1639,
14,
5754,
14,
10088,
492,
20071,
63,
1418,
199,
199,
504,
1275,
10458,
492,
922,
63,
12419,
63,
262,
12,
922,
63,
12419,
63,
548,
12,
922,
63,
2886,
63,
4892,
199,
199,
12763,
63,
3078,
275,
2513,
1178,
63,
751,
63,
344,
7,
199,
18145,
63,
12763,
63,
3078,
275,
2513,
1178,
63,
751,
63,
4620,
7,
199,
19747,
63,
8609,
63,
2339,
275,
283,
2184,
7,
421,
199,
318,
2248,
63,
4620,
8,
515,
304,
272,
372,
492,
63,
991,
63,
515,
8,
515,
16315,
421,
199,
318,
664,
63,
7765,
837,
272,
14745,
275,
942,
272,
367,
4865,
63,
515,
315,
2202,
14,
29599,
63,
28988,
26,
267,
14745,
14,
740,
8,
912,
63,
4620,
8,
4620,
63,
515,
430,
272,
340,
440,
14745,
26,
267,
746,
11897,
360,
1944,
6299,
14745,
1172,
2757,
3247,
14,
12078,
7560,
20987,
2594,
63,
28988,
1395,
7003,
18478,
272,
372,
14745,
421,
199,
318,
485,
3118,
63,
6942,
8,
6942,
304,
272,
408,
272,
445,
274,
796,
282,
2600,
402,
6235,
402,
18994,
18423,
2256,
2544,
272,
10209,
370,
6656,
11153,
3423,
14,
339,
2832,
1013,
22868,
3398,
446,
11619,
367,
922,
63,
2886,
63,
4892,
4673,
272,
408,
272,
428,
8456,
649,
5399,
63,
30553,
8246,
51,
275,
295,
14,
2014,
360,
1246,
92,
1418,
92,
498,
92,
4731,
92,
2060,
92,
5233,
297,
295,
14,
41,
9,
272,
445,
906,
879,
10934,
63,
6348,
8895,
275,
283,
3096,
1116,
7,
272,
367,
790,
315,
6235,
26,
267,
340,
428,
8456,
649,
5399,
63,
30553,
8246,
51,
14,
1733,
8,
498,
304,
288,
6235,
59,
498,
61,
275,
445,
906,
879,
10934,
63,
6348,
8895,
272,
372,
6235,
421,
199,
318,
12895,
3682,
6942,
304,
272,
408,
272,
982,
314,
1627,
6235,
787,
1686,
12,
372,
282,
2876,
909,
14,
272,
408,
272,
367,
4865,
315,
664,
63,
7765,
837,
267,
862,
26,
288,
922,
275,
4865,
14,
13975,
3682,
6942,
9,
267,
871,
3146,
26,
288,
327,
961,
4865,
3181,
1133,
4729,
3520,
6235,
465,
2368,
14,
7649,
314,
2163,
1373,
14,
288,
1980,
267,
871,
23724,
26,
288,
327,
961,
4865,
20065,
370,
3631,
315,
4154,
18917,
446,
642,
922,
1077,
440,
506,
4370,
315,
737,
1006,
14,
288,
372,
488,
267,
340,
922,
365,
488,
26,
288,
1980,
267,
327,
1626,
1397,
323,
314,
922,
909,
543,
314,
931,
402,
314,
4865,
14,
267,
922,
14,
4620,
275,
2071,
83,
4111,
83,
2,
450,
334,
4620,
855,
578,
3108,
4865,
855,
533,
4914,
354,
3368,
267,
372,
922,
339,
327,
710,
6235,
6841,
787,
3866,
370,
1006,
14745,
12,
8344,
4673,
272,
922,
63,
2886,
63,
4892,
14,
2254,
8,
8114,
18971,
354,
3108,
288,
6235,
3699,
3118,
63,
6942,
8,
6942,
430,
421,
199,
318,
4676,
8,
1069,
12,
922,
304,
272,
408,
272,
3492,
11734,
282,
922,
1305,
436,
282,
4865,
315,
314,
1056,
14,
961,
4340,
282,
922,
3181,
1133,
272,
1172,
370,
295,
13975,
641,
4036,
1056,
14,
3390,
626,
666,
663,
5309,
272,
314,
16535,
2351,
365,
30403,
1380,
314,
922,
9610,
315,
14,
272,
408,
272,
340,
922,
365,
488,
26,
267,
922,
275,
1056,
14,
751,
272,
327,
3254,
26,
2779,
3955,
506,
14213,
370,
2291,
3365,
4676,
3102,
12,
2839,
10514,
10049,
14,
272,
340,
428,
9577,
63,
3078,
315,
1056,
14,
1730,
26,
267,
340,
1056,
14,
1730,
59,
12763,
63,
3078,
61,
1137,
922,
14,
2051,
26,
288,
327,
4005,
5126,
295,
4941,
4573,
922,
1159,
2351,
12,
1218,
282,
892,
12,
2701,
288,
327,
2351,
340,
314,
3411,
2351,
13718,
370,
282,
3365,
288,
327,
15082,
922,
14,
288,
1056,
14,
1730,
14,
4939,
342,
272,
587,
26,
267,
1056,
14,
1730,
14,
7612,
63,
498,
342,
272,
1056,
14,
1730,
59,
12763,
63,
3078,
61,
275,
922,
14,
2051,
272,
1056,
14,
1730,
59,
18145,
63,
12763,
63,
3078,
61,
275,
922,
14,
4620,
272,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
1056,
14,
751,
275,
922,
272,
20071,
63,
1418,
8,
1069,
9,
272,
922,
63,
12419,
63,
262,
14,
2254,
8,
8114,
29,
751,
855,
533,
3108,
1056,
29,
1069,
12,
922,
29,
751,
9,
421,
199,
318,
22079,
8,
1069,
304,
272,
408,
272,
23169,
314,
15082,
922,
1159,
2870,
687,
314,
1056,
436,
8976,
397,
3932,
272,
2351,
666,
14,
272,
408,
272,
327,
28626,
314,
4673,
2544,
314,
922,
365,
10367,
734,
880,
314,
13035,
83,
1172,
282,
272,
327,
22044,
370,
2342,
734,
627,
11345,
10,
10367,
734,
14,
272,
922,
275,
2519,
8,
1069,
12,
283,
751,
297,
488,
9,
272,
340,
2688,
8,
751,
12,
283,
374,
63,
12177,
358,
436,
440,
922,
14,
374,
63,
12177,
837,
267,
922,
275,
488,
272,
922,
63,
12419,
63,
548,
14,
2254,
8,
8114,
29,
751,
855,
533,
3108,
1056,
29,
1069,
12,
922,
29,
751,
9,
339,
327,
21027,
2637,
7141,
6290,
370,
2351,
272,
2637,
275,
1056,
14,
1730,
14,
362,
360,
1176,
63,
3671,
358,
339,
1056,
14,
1730,
14,
4939,
342,
339,
340,
2637,
365,
440,
488,
26,
267,
1056,
14,
1730,
459,
1176,
63,
3671,
418,
275,
2637,
339,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
267,
1056,
14,
751,
275,
29952,
342,
421,
199,
318,
664,
63,
751,
63,
1238,
837,
272,
408,
272,
1803,
314,
2876,
1402,
626,
365,
4702,
315,
642,
2199,
14,
272,
408,
272,
687,
1639,
14,
697,
14,
992,
492,
664,
63,
1238,
339,
862,
26,
267,
1145,
63,
1302,
12,
1402,
63,
354,
275,
2202,
14,
5580,
63,
3791,
63,
11429,
14,
1294,
7563,
272,
871,
1722,
26,
267,
746,
11897,
480,
5580,
63,
3791,
63,
11429,
1471,
506,
402,
314,
1824,
283,
571,
63,
1302,
14,
1238,
63,
354,
9859,
272,
922,
63,
1238,
275,
664,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354
] |
[
295,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
23724,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
991,
63,
515,
199,
504,
1639,
14,
5754,
14,
10088,
492,
20071,
63,
1418,
199,
199,
504,
1275,
10458,
492,
922,
63,
12419,
63,
262,
12,
922,
63,
12419,
63,
548,
12,
922,
63,
2886,
63,
4892,
199,
199,
12763,
63,
3078,
275,
2513,
1178,
63,
751,
63,
344,
7,
199,
18145,
63,
12763,
63,
3078,
275,
2513,
1178,
63,
751,
63,
4620,
7,
199,
19747,
63,
8609,
63,
2339,
275,
283,
2184,
7,
421,
199,
318,
2248,
63,
4620,
8,
515,
304,
272,
372,
492,
63,
991,
63,
515,
8,
515,
16315,
421,
199,
318,
664,
63,
7765,
837,
272,
14745,
275,
942,
272,
367,
4865,
63,
515,
315,
2202,
14,
29599,
63,
28988,
26,
267,
14745,
14,
740,
8,
912,
63,
4620,
8,
4620,
63,
515,
430,
272,
340,
440,
14745,
26,
267,
746,
11897,
360,
1944,
6299,
14745,
1172,
2757,
3247,
14,
12078,
7560,
20987,
2594,
63,
28988,
1395,
7003,
18478,
272,
372,
14745,
421,
199,
318,
485,
3118,
63,
6942,
8,
6942,
304,
272,
408,
272,
445,
274,
796,
282,
2600,
402,
6235,
402,
18994,
18423,
2256,
2544,
272,
10209,
370,
6656,
11153,
3423,
14,
339,
2832,
1013,
22868,
3398,
446,
11619,
367,
922,
63,
2886,
63,
4892,
4673,
272,
408,
272,
428,
8456,
649,
5399,
63,
30553,
8246,
51,
275,
295,
14,
2014,
360,
1246,
92,
1418,
92,
498,
92,
4731,
92,
2060,
92,
5233,
297,
295,
14,
41,
9,
272,
445,
906,
879,
10934,
63,
6348,
8895,
275,
283,
3096,
1116,
7,
272,
367,
790,
315,
6235,
26,
267,
340,
428,
8456,
649,
5399,
63,
30553,
8246,
51,
14,
1733,
8,
498,
304,
288,
6235,
59,
498,
61,
275,
445,
906,
879,
10934,
63,
6348,
8895,
272,
372,
6235,
421,
199,
318,
12895,
3682,
6942,
304,
272,
408,
272,
982,
314,
1627,
6235,
787,
1686,
12,
372,
282,
2876,
909,
14,
272,
408,
272,
367,
4865,
315,
664,
63,
7765,
837,
267,
862,
26,
288,
922,
275,
4865,
14,
13975,
3682,
6942,
9,
267,
871,
3146,
26,
288,
327,
961,
4865,
3181,
1133,
4729,
3520,
6235,
465,
2368,
14,
7649,
314,
2163,
1373,
14,
288,
1980,
267,
871,
23724,
26,
288,
327,
961,
4865,
20065,
370,
3631,
315,
4154,
18917,
446,
642,
922,
1077,
440,
506,
4370,
315,
737,
1006,
14,
288,
372,
488,
267,
340,
922,
365,
488,
26,
288,
1980,
267,
327,
1626,
1397,
323,
314,
922,
909,
543,
314,
931,
402,
314,
4865,
14,
267,
922,
14,
4620,
275,
2071,
83,
4111,
83,
2,
450,
334,
4620,
855,
578,
3108,
4865,
855,
533,
4914,
354,
3368,
267,
372,
922,
339,
327,
710,
6235,
6841,
787,
3866,
370,
1006,
14745,
12,
8344,
4673,
272,
922,
63,
2886,
63,
4892,
14,
2254,
8,
8114,
18971,
354,
3108,
288,
6235,
3699,
3118,
63,
6942,
8,
6942,
430,
421,
199,
318,
4676,
8,
1069,
12,
922,
304,
272,
408,
272,
3492,
11734,
282,
922,
1305,
436,
282,
4865,
315,
314,
1056,
14,
961,
4340,
282,
922,
3181,
1133,
272,
1172,
370,
295,
13975,
641,
4036,
1056,
14,
3390,
626,
666,
663,
5309,
272,
314,
16535,
2351,
365,
30403,
1380,
314,
922,
9610,
315,
14,
272,
408,
272,
340,
922,
365,
488,
26,
267,
922,
275,
1056,
14,
751,
272,
327,
3254,
26,
2779,
3955,
506,
14213,
370,
2291,
3365,
4676,
3102,
12,
2839,
10514,
10049,
14,
272,
340,
428,
9577,
63,
3078,
315,
1056,
14,
1730,
26,
267,
340,
1056,
14,
1730,
59,
12763,
63,
3078,
61,
1137,
922,
14,
2051,
26,
288,
327,
4005,
5126,
295,
4941,
4573,
922,
1159,
2351,
12,
1218,
282,
892,
12,
2701,
288,
327,
2351,
340,
314,
3411,
2351,
13718,
370,
282,
3365,
288,
327,
15082,
922,
14,
288,
1056,
14,
1730,
14,
4939,
342,
272,
587,
26,
267,
1056,
14,
1730,
14,
7612,
63,
498,
342,
272,
1056,
14,
1730,
59,
12763,
63,
3078,
61,
275,
922,
14,
2051,
272,
1056,
14,
1730,
59,
18145,
63,
12763,
63,
3078,
61,
275,
922,
14,
4620,
272,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
1056,
14,
751,
275,
922,
272,
20071,
63,
1418,
8,
1069,
9,
272,
922,
63,
12419,
63,
262,
14,
2254,
8,
8114,
29,
751,
855,
533,
3108,
1056,
29,
1069,
12,
922,
29,
751,
9,
421,
199,
318,
22079,
8,
1069,
304,
272,
408,
272,
23169,
314,
15082,
922,
1159,
2870,
687,
314,
1056,
436,
8976,
397,
3932,
272,
2351,
666,
14,
272,
408,
272,
327,
28626,
314,
4673,
2544,
314,
922,
365,
10367,
734,
880,
314,
13035,
83,
1172,
282,
272,
327,
22044,
370,
2342,
734,
627,
11345,
10,
10367,
734,
14,
272,
922,
275,
2519,
8,
1069,
12,
283,
751,
297,
488,
9,
272,
340,
2688,
8,
751,
12,
283,
374,
63,
12177,
358,
436,
440,
922,
14,
374,
63,
12177,
837,
267,
922,
275,
488,
272,
922,
63,
12419,
63,
548,
14,
2254,
8,
8114,
29,
751,
855,
533,
3108,
1056,
29,
1069,
12,
922,
29,
751,
9,
339,
327,
21027,
2637,
7141,
6290,
370,
2351,
272,
2637,
275,
1056,
14,
1730,
14,
362,
360,
1176,
63,
3671,
358,
339,
1056,
14,
1730,
14,
4939,
342,
339,
340,
2637,
365,
440,
488,
26,
267,
1056,
14,
1730,
459,
1176,
63,
3671,
418,
275,
2637,
339,
340,
2688,
8,
1069,
12,
283,
751,
735,
267,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
267,
1056,
14,
751,
275,
29952,
342,
421,
199,
318,
664,
63,
751,
63,
1238,
837,
272,
408,
272,
1803,
314,
2876,
1402,
626,
365,
4702,
315,
642,
2199,
14,
272,
408,
272,
687,
1639,
14,
697,
14,
992,
492,
664,
63,
1238,
339,
862,
26,
267,
1145,
63,
1302,
12,
1402,
63,
354,
275,
2202,
14,
5580,
63,
3791,
63,
11429,
14,
1294,
7563,
272,
871,
1722,
26,
267,
746,
11897,
480,
5580,
63,
3791,
63,
11429,
1471,
506,
402,
314,
1824,
283,
571,
63,
1302,
14,
1238,
63,
354,
9859,
272,
922,
63,
1238,
275,
664,
63,
1238,
8,
571,
63,
1302,
12,
1402,
63,
354,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
joergdietrich/astropy
|
astropy/config/paths.py
|
3
|
10745
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
""" This module contains functions to determine where configuration and
data/cache files used by Astropy should be placed.
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from ..extern import six
from ..utils.decorators import wraps
import os
import shutil
import sys
__all__ = ['get_config_dir', 'get_cache_dir', 'set_temp_config',
'set_temp_cache']
def _find_home():
""" Locates and return the home directory (or best approximation) on this
system.
Raises
------
OSError
If the home directory cannot be located - usually means you are running
Astropy on some obscure platform that doesn't have standard home
directories.
"""
# this is used below to make fix up encoding issues that sometimes crop up
# in py2.x but not in py3.x
if six.PY2:
decodepath = lambda pth: pth.decode(sys.getfilesystemencoding())
else:
decodepath = lambda pth: pth
# First find the home directory - this is inspired by the scheme ipython
# uses to identify "home"
if os.name == 'posix':
# Linux, Unix, AIX, OS X
if 'HOME' in os.environ:
homedir = decodepath(os.environ['HOME'])
else:
raise OSError('Could not find unix home directory to search for '
'astropy config dir')
elif os.name == 'nt': # This is for all modern Windows (NT or after)
if 'MSYSTEM' in os.environ and os.environ.get('HOME'):
# Likely using an msys shell; use whatever it is using for its
# $HOME directory
homedir = decodepath(os.environ['HOME'])
# Next try for a network home
elif 'HOMESHARE' in os.environ:
homedir = decodepath(os.environ['HOMESHARE'])
# See if there's a local home
elif 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ:
homedir = os.path.join(os.environ['HOMEDRIVE'],
os.environ['HOMEPATH'])
homedir = decodepath(homedir)
# Maybe a user profile?
elif 'USERPROFILE' in os.environ:
homedir = decodepath(os.path.join(os.environ['USERPROFILE']))
else:
try:
from ..extern.six.moves import winreg as wreg
shell_folders = r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, shell_folders)
homedir = wreg.QueryValueEx(key, 'Personal')[0]
homedir = decodepath(homedir)
key.Close()
except Exception:
# As a final possible resort, see if HOME is present
if 'HOME' in os.environ:
homedir = decodepath(os.environ['HOME'])
else:
raise OSError('Could not find windows home directory to '
'search for astropy config dir')
else:
# for other platforms, try HOME, although it probably isn't there
if 'HOME' in os.environ:
homedir = decodepath(os.environ['HOME'])
else:
raise OSError('Could not find a home directory to search for '
'astropy config dir - are you on an unspported '
'platform?')
return homedir
def get_config_dir(create=True):
"""
Determines the Astropy configuration directory name and creates the
directory if it doesn't exist.
This directory is typically ``$HOME/.astropy/config``, but if the
XDG_CONFIG_HOME environment variable is set and the
``$XDG_CONFIG_HOME/astropy`` directory exists, it will be that directory.
If neither exists, the former will be created and symlinked to the latter.
Returns
-------
configdir : str
The absolute path to the configuration directory.
"""
# symlink will be set to this if the directory is created
linkto = None
# If using set_temp_config, that overrides all
if set_temp_config._temp_path is not None:
xch = set_temp_config._temp_path
config_path = os.path.join(xch, 'astropy')
if not os.path.exists(config_path):
os.mkdir(config_path)
return os.path.abspath(config_path)
# first look for XDG_CONFIG_HOME
xch = os.environ.get('XDG_CONFIG_HOME')
if xch is not None and os.path.exists(xch):
xchpth = os.path.join(xch, 'astropy')
if not os.path.islink(xchpth):
if os.path.exists(xchpth):
return os.path.abspath(xchpth)
else:
linkto = xchpth
return os.path.abspath(_find_or_create_astropy_dir('config', linkto))
def get_cache_dir():
"""
Determines the Astropy cache directory name and creates the directory if it
doesn't exist.
This directory is typically ``$HOME/.astropy/cache``, but if the
XDG_CACHE_HOME environment variable is set and the
``$XDG_CACHE_HOME/astropy`` directory exists, it will be that directory.
If neither exists, the former will be created and symlinked to the latter.
Returns
-------
cachedir : str
The absolute path to the cache directory.
"""
# symlink will be set to this if the directory is created
linkto = None
# If using set_temp_cache, that overrides all
if set_temp_cache._temp_path is not None:
xch = set_temp_cache._temp_path
cache_path = os.path.join(xch, 'astropy')
if not os.path.exists(cache_path):
os.mkdir(cache_path)
return os.path.abspath(cache_path)
# first look for XDG_CACHE_HOME
xch = os.environ.get('XDG_CACHE_HOME')
if xch is not None and os.path.exists(xch):
xchpth = os.path.join(xch, 'astropy')
if not os.path.islink(xchpth):
if os.path.exists(xchpth):
return os.path.abspath(xchpth)
else:
linkto = xchpth
return os.path.abspath(_find_or_create_astropy_dir('cache', linkto))
class _SetTempPath(object):
_temp_path = None
_default_path_getter = None
def __init__(self, path=None, delete=False):
if path is not None:
path = os.path.abspath(path)
self._path = path
self._delete = delete
self._prev_path = self.__class__._temp_path
def __enter__(self):
self.__class__._temp_path = self._path
return self._default_path_getter()
def __exit__(self, *args):
self.__class__._temp_path = self._prev_path
if self._delete and self._path is not None:
shutil.rmtree(self._path)
def __call__(self, func):
"""Implements use as a decorator."""
@wraps(func)
def wrapper(*args, **kwargs):
with self:
func(*args, **kwargs)
return wrapper
class set_temp_config(_SetTempPath):
"""
Context manager to set a temporary path for the Astropy config, primarily
for use with testing.
If the path set by this context manager does not already exist it will be
created, if possible.
This may also be used as a decorator on a function to set the config path
just within that function.
Parameters
----------
path : str, optional
The directory (which must exist) in which to find the Astropy config
files, or create them if they do not already exist. If None, this
restores the config path to the user's default config path as returned
by `get_config_dir` as though this context manager were not in effect
(this is useful for testing). In this case the ``delete`` argument is
always ignored.
delete : bool, optional
If True, cleans up the temporary directory after exiting the temp
context (default: False).
"""
_default_path_getter = staticmethod(get_config_dir)
def __enter__(self):
# Special case for the config case, where we need to reset all the
# cached config objects
from .configuration import _cfgobjs
path = super(set_temp_config, self).__enter__()
_cfgobjs.clear()
return path
def __exit__(self, *args):
from .configuration import _cfgobjs
super(set_temp_config, self).__exit__(*args)
_cfgobjs.clear()
class set_temp_cache(_SetTempPath):
"""
Context manager to set a temporary path for the Astropy download cache,
primarily for use with testing (though there may be other applications
for setting a different cache directory, for example to switch to a cache
dedicated to large files).
If the path set by this context manager does not already exist it will be
created, if possible.
This may also be used as a decorator on a function to set the cache path
just within that function.
Parameters
----------
path : str
The directory (which must exist) in which to find the Astropy cache
files, or create them if they do not already exist. If None, this
restores the cache path to the user's default cache path as returned
by `get_cache_dir` as though this context manager were not in effect
(this is useful for testing). In this case the ``delete`` argument is
always ignored.
delete : bool, optional
If True, cleans up the temporary directory after exiting the temp
context (default: False).
"""
_default_path_getter = staticmethod(get_cache_dir)
def _find_or_create_astropy_dir(dirnm, linkto):
innerdir = os.path.join(_find_home(), '.astropy')
maindir = os.path.join(_find_home(), '.astropy', dirnm)
if not os.path.exists(maindir):
# first create .astropy dir if needed
if not os.path.exists(innerdir):
try:
os.mkdir(innerdir)
except OSError:
if not os.path.isdir(innerdir):
raise
elif not os.path.isdir(innerdir):
msg = 'Intended Astropy directory {0} is actually a file.'
raise IOError(msg.format(innerdir))
try:
os.mkdir(maindir)
except OSError:
if not os.path.isdir(maindir):
raise
if (not sys.platform.startswith('win') and
linkto is not None and
not os.path.exists(linkto)):
os.symlink(maindir, linkto)
elif not os.path.isdir(maindir):
msg = 'Intended Astropy {0} directory {1} is actually a file.'
raise IOError(msg.format(dirnm, maindir))
return os.path.abspath(maindir)
|
bsd-3-clause
|
[
3,
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
624,
961,
859,
3509,
3423,
370,
6705,
2382,
2897,
436,
199,
576,
15,
1637,
1584,
1202,
701,
31986,
7537,
1077,
506,
15090,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
9,
199,
199,
504,
2508,
18587,
492,
3816,
199,
504,
2508,
1208,
14,
11582,
492,
14018,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
421,
199,
363,
452,
363,
275,
788,
362,
63,
888,
63,
694,
297,
283,
362,
63,
1637,
63,
694,
297,
283,
409,
63,
808,
63,
888,
297,
1779,
283,
409,
63,
808,
63,
1637,
418,
421,
199,
318,
485,
1623,
63,
4219,
837,
272,
408,
6263,
2335,
436,
372,
314,
5629,
2082,
334,
269,
5526,
22772,
9,
641,
642,
272,
2656,
14,
339,
6218,
272,
21397,
272,
6440,
267,
982,
314,
5629,
2082,
3913,
506,
16180,
446,
9987,
4910,
1265,
787,
3879,
267,
31986,
7537,
641,
2005,
2607,
551,
608,
4298,
626,
3181,
1133,
1172,
4465,
5629,
267,
6602,
14,
272,
408,
2378,
327,
642,
365,
1202,
5084,
370,
1852,
5325,
1536,
2644,
10876,
626,
15026,
18366,
1536,
272,
327,
315,
1134,
18,
14,
88,
1325,
440,
315,
1134,
19,
14,
88,
272,
340,
3816,
14,
4521,
18,
26,
267,
4849,
515,
275,
2400,
25504,
26,
25504,
14,
2708,
8,
1274,
14,
23462,
32255,
1012,
272,
587,
26,
267,
4849,
515,
275,
2400,
25504,
26,
25504,
339,
327,
7758,
2342,
314,
5629,
2082,
446,
642,
365,
315,
8721,
581,
701,
314,
5687,
284,
1548,
272,
327,
4440,
370,
10405,
298,
4219,
2,
272,
340,
747,
14,
354,
508,
283,
9228,
356,
267,
327,
10130,
12,
13074,
12,
437,
3867,
12,
4403,
1323,
267,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
587,
26,
288,
746,
6440,
360,
6531,
440,
2342,
16572,
5629,
2082,
370,
2754,
367,
283,
2079,
283,
1810,
7537,
1101,
2935,
358,
272,
916,
747,
14,
354,
508,
283,
343,
356,
221,
327,
961,
365,
367,
1006,
818,
11641,
5417,
334,
12460,
503,
2410,
9,
267,
340,
283,
3053,
57,
9757,
7,
315,
747,
14,
2314,
436,
747,
14,
2314,
14,
362,
360,
9524,
735,
288,
327,
491,
3258,
7742,
1808,
376,
333,
1274,
5218,
27,
675,
15685,
652,
365,
1808,
367,
2399,
288,
327,
2672,
9524,
2082,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
327,
16840,
862,
367,
282,
2784,
5629,
267,
916,
283,
2979,
22076,
40,
8693,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
2979,
22076,
40,
8693,
1105,
267,
327,
1666,
340,
2337,
1159,
282,
2257,
5629,
267,
916,
283,
2979,
45,
1149,
50,
5399,
7,
315,
747,
14,
2314,
436,
283,
9524,
3243,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
2979,
45,
1149,
50,
5399,
995,
3521,
747,
14,
2314,
459,
9524,
3243,
1105,
288,
5629,
694,
275,
4849,
515,
8,
4219,
694,
9,
267,
327,
23038,
282,
922,
4690,
31,
267,
916,
283,
3791,
16632,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
3791,
16632,
5156,
267,
587,
26,
288,
862,
26,
355,
687,
2508,
18587,
14,
4174,
14,
4912,
492,
30748,
465,
336,
1135,
355,
5218,
63,
15171,
275,
519,
7,
10337,
60,
12940,
60,
8647,
60,
5639,
3353,
60,
4527,
22732,
60,
8529,
29121,
83,
7,
355,
790,
275,
336,
1135,
14,
28144,
8,
87,
1135,
14,
23802,
63,
14211,
63,
3791,
12,
5218,
63,
15171,
9,
2234,
5629,
694,
275,
336,
1135,
14,
3227,
1110,
920,
8,
498,
12,
283,
7344,
279,
5832,
16,
61,
355,
5629,
694,
275,
4849,
515,
8,
4219,
694,
9,
355,
790,
14,
4724,
342,
288,
871,
2186,
26,
355,
327,
3709,
282,
4242,
3962,
522,
361,
12,
1937,
340,
7781,
3635,
365,
3451,
355,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
490,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
355,
587,
26,
490,
746,
6440,
360,
6531,
440,
2342,
10061,
5629,
2082,
370,
283,
3303,
283,
1733,
367,
28753,
1101,
2935,
358,
272,
587,
26,
267,
327,
367,
1163,
10677,
12,
862,
7781,
3635,
12,
22160,
652,
8646,
5712,
1133,
2337,
267,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
587,
26,
288,
746,
6440,
360,
6531,
440,
2342,
282,
5629,
2082,
370,
2754,
367,
283,
2079,
283,
1810,
7537,
1101,
2935,
446,
787,
1265,
641,
376,
625,
681,
2315,
283,
2079,
283,
3246,
18478,
272,
372,
5629,
694,
421,
199,
318,
664,
63,
888,
63,
694,
8,
981,
29,
549,
304,
272,
408,
272,
22391,
314,
31986,
7537,
2897,
2082,
536,
436,
8491,
314,
272,
2082,
340,
652,
3181,
1133,
2187,
14,
339,
961,
2082,
365,
13609,
1124,
4,
9524,
8083,
1810,
7537,
15,
888,
4542,
1325,
340,
314,
272,
1323,
29173,
63,
5569,
63,
9524,
3734,
1750,
365,
663,
436,
314,
272,
1124,
4,
18184,
39,
63,
5569,
63,
9524,
15,
1810,
7537,
1040,
2082,
3495,
12,
652,
911,
506,
626,
2082,
14,
272,
982,
15564,
3495,
12,
314,
26610,
911,
506,
2737,
436,
4678,
12751,
370,
314,
19045,
14,
339,
1803,
272,
5514,
272,
1101,
694,
520,
620,
267,
710,
3679,
931,
370,
314,
2897,
2082,
14,
339,
408,
339,
327,
15296,
911,
506,
663,
370,
642,
340,
314,
2082,
365,
2737,
272,
2142,
475,
275,
488,
339,
327,
982,
1808,
663,
63,
808,
63,
888,
12,
626,
10580,
1006,
272,
340,
663,
63,
808,
63,
888,
423,
808,
63,
515,
365,
440,
488,
26,
267,
671,
335,
275,
663,
63,
808,
63,
888,
423,
808,
63,
515,
267,
1101,
63,
515,
275,
747,
14,
515,
14,
904,
8,
88,
335,
12,
283,
1810,
7537,
358,
267,
340,
440,
747,
14,
515,
14,
2444,
8
] |
[
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
624,
961,
859,
3509,
3423,
370,
6705,
2382,
2897,
436,
199,
576,
15,
1637,
1584,
1202,
701,
31986,
7537,
1077,
506,
15090,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
9,
199,
199,
504,
2508,
18587,
492,
3816,
199,
504,
2508,
1208,
14,
11582,
492,
14018,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
421,
199,
363,
452,
363,
275,
788,
362,
63,
888,
63,
694,
297,
283,
362,
63,
1637,
63,
694,
297,
283,
409,
63,
808,
63,
888,
297,
1779,
283,
409,
63,
808,
63,
1637,
418,
421,
199,
318,
485,
1623,
63,
4219,
837,
272,
408,
6263,
2335,
436,
372,
314,
5629,
2082,
334,
269,
5526,
22772,
9,
641,
642,
272,
2656,
14,
339,
6218,
272,
21397,
272,
6440,
267,
982,
314,
5629,
2082,
3913,
506,
16180,
446,
9987,
4910,
1265,
787,
3879,
267,
31986,
7537,
641,
2005,
2607,
551,
608,
4298,
626,
3181,
1133,
1172,
4465,
5629,
267,
6602,
14,
272,
408,
2378,
327,
642,
365,
1202,
5084,
370,
1852,
5325,
1536,
2644,
10876,
626,
15026,
18366,
1536,
272,
327,
315,
1134,
18,
14,
88,
1325,
440,
315,
1134,
19,
14,
88,
272,
340,
3816,
14,
4521,
18,
26,
267,
4849,
515,
275,
2400,
25504,
26,
25504,
14,
2708,
8,
1274,
14,
23462,
32255,
1012,
272,
587,
26,
267,
4849,
515,
275,
2400,
25504,
26,
25504,
339,
327,
7758,
2342,
314,
5629,
2082,
446,
642,
365,
315,
8721,
581,
701,
314,
5687,
284,
1548,
272,
327,
4440,
370,
10405,
298,
4219,
2,
272,
340,
747,
14,
354,
508,
283,
9228,
356,
267,
327,
10130,
12,
13074,
12,
437,
3867,
12,
4403,
1323,
267,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
587,
26,
288,
746,
6440,
360,
6531,
440,
2342,
16572,
5629,
2082,
370,
2754,
367,
283,
2079,
283,
1810,
7537,
1101,
2935,
358,
272,
916,
747,
14,
354,
508,
283,
343,
356,
221,
327,
961,
365,
367,
1006,
818,
11641,
5417,
334,
12460,
503,
2410,
9,
267,
340,
283,
3053,
57,
9757,
7,
315,
747,
14,
2314,
436,
747,
14,
2314,
14,
362,
360,
9524,
735,
288,
327,
491,
3258,
7742,
1808,
376,
333,
1274,
5218,
27,
675,
15685,
652,
365,
1808,
367,
2399,
288,
327,
2672,
9524,
2082,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
327,
16840,
862,
367,
282,
2784,
5629,
267,
916,
283,
2979,
22076,
40,
8693,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
2979,
22076,
40,
8693,
1105,
267,
327,
1666,
340,
2337,
1159,
282,
2257,
5629,
267,
916,
283,
2979,
45,
1149,
50,
5399,
7,
315,
747,
14,
2314,
436,
283,
9524,
3243,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
2979,
45,
1149,
50,
5399,
995,
3521,
747,
14,
2314,
459,
9524,
3243,
1105,
288,
5629,
694,
275,
4849,
515,
8,
4219,
694,
9,
267,
327,
23038,
282,
922,
4690,
31,
267,
916,
283,
3791,
16632,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
3791,
16632,
5156,
267,
587,
26,
288,
862,
26,
355,
687,
2508,
18587,
14,
4174,
14,
4912,
492,
30748,
465,
336,
1135,
355,
5218,
63,
15171,
275,
519,
7,
10337,
60,
12940,
60,
8647,
60,
5639,
3353,
60,
4527,
22732,
60,
8529,
29121,
83,
7,
355,
790,
275,
336,
1135,
14,
28144,
8,
87,
1135,
14,
23802,
63,
14211,
63,
3791,
12,
5218,
63,
15171,
9,
2234,
5629,
694,
275,
336,
1135,
14,
3227,
1110,
920,
8,
498,
12,
283,
7344,
279,
5832,
16,
61,
355,
5629,
694,
275,
4849,
515,
8,
4219,
694,
9,
355,
790,
14,
4724,
342,
288,
871,
2186,
26,
355,
327,
3709,
282,
4242,
3962,
522,
361,
12,
1937,
340,
7781,
3635,
365,
3451,
355,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
490,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
355,
587,
26,
490,
746,
6440,
360,
6531,
440,
2342,
10061,
5629,
2082,
370,
283,
3303,
283,
1733,
367,
28753,
1101,
2935,
358,
272,
587,
26,
267,
327,
367,
1163,
10677,
12,
862,
7781,
3635,
12,
22160,
652,
8646,
5712,
1133,
2337,
267,
340,
283,
9524,
7,
315,
747,
14,
2314,
26,
288,
5629,
694,
275,
4849,
515,
8,
736,
14,
2314,
459,
9524,
1105,
267,
587,
26,
288,
746,
6440,
360,
6531,
440,
2342,
282,
5629,
2082,
370,
2754,
367,
283,
2079,
283,
1810,
7537,
1101,
2935,
446,
787,
1265,
641,
376,
625,
681,
2315,
283,
2079,
283,
3246,
18478,
272,
372,
5629,
694,
421,
199,
318,
664,
63,
888,
63,
694,
8,
981,
29,
549,
304,
272,
408,
272,
22391,
314,
31986,
7537,
2897,
2082,
536,
436,
8491,
314,
272,
2082,
340,
652,
3181,
1133,
2187,
14,
339,
961,
2082,
365,
13609,
1124,
4,
9524,
8083,
1810,
7537,
15,
888,
4542,
1325,
340,
314,
272,
1323,
29173,
63,
5569,
63,
9524,
3734,
1750,
365,
663,
436,
314,
272,
1124,
4,
18184,
39,
63,
5569,
63,
9524,
15,
1810,
7537,
1040,
2082,
3495,
12,
652,
911,
506,
626,
2082,
14,
272,
982,
15564,
3495,
12,
314,
26610,
911,
506,
2737,
436,
4678,
12751,
370,
314,
19045,
14,
339,
1803,
272,
5514,
272,
1101,
694,
520,
620,
267,
710,
3679,
931,
370,
314,
2897,
2082,
14,
339,
408,
339,
327,
15296,
911,
506,
663,
370,
642,
340,
314,
2082,
365,
2737,
272,
2142,
475,
275,
488,
339,
327,
982,
1808,
663,
63,
808,
63,
888,
12,
626,
10580,
1006,
272,
340,
663,
63,
808,
63,
888,
423,
808,
63,
515,
365,
440,
488,
26,
267,
671,
335,
275,
663,
63,
808,
63,
888,
423,
808,
63,
515,
267,
1101,
63,
515,
275,
747,
14,
515,
14,
904,
8,
88,
335,
12,
283,
1810,
7537,
358,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kevin1024/vcrpy
|
vcr/stubs/httpx_stubs.py
|
1
|
5330
|
import functools
import logging
from unittest.mock import patch, MagicMock
import httpx
from vcr.request import Request as VcrRequest
from vcr.errors import CannotOverwriteExistingCassetteException
_logger = logging.getLogger(__name__)
def _transform_headers(httpx_reponse):
"""
Some headers can appear multiple times, like "Set-Cookie".
Therefore transform to every header key to list of values.
"""
out = {}
for key, var in httpx_reponse.headers.raw:
decoded_key = key.decode("utf-8")
out.setdefault(decoded_key, [])
out[decoded_key].append(var.decode("utf-8"))
return out
def _to_serialized_response(httpx_reponse):
return {
"status_code": httpx_reponse.status_code,
"http_version": httpx_reponse.http_version,
"headers": _transform_headers(httpx_reponse),
"content": httpx_reponse.content.decode("utf-8", "ignore"),
}
def _from_serialized_headers(headers):
"""
httpx accepts headers as list of tuples of header key and value.
"""
header_list = []
for key, values in headers.items():
for v in values:
header_list.append((key, v))
return header_list
@patch("httpx.Response.close", MagicMock())
@patch("httpx.Response.read", MagicMock())
def _from_serialized_response(request, serialized_response, history=None):
content = serialized_response.get("content").encode()
response = httpx.Response(
status_code=serialized_response.get("status_code"),
request=request,
http_version=serialized_response.get("http_version"),
headers=_from_serialized_headers(serialized_response.get("headers")),
content=content,
history=history or [],
)
response._content = content
return response
def _make_vcr_request(httpx_request, **kwargs):
body = httpx_request.read().decode("utf-8")
uri = str(httpx_request.url)
headers = dict(httpx_request.headers)
return VcrRequest(httpx_request.method, uri, body, headers)
def _shared_vcr_send(cassette, real_send, *args, **kwargs):
real_request = args[1]
vcr_request = _make_vcr_request(real_request, **kwargs)
if cassette.can_play_response_for(vcr_request):
return vcr_request, _play_responses(cassette, real_request, vcr_request, args[0], kwargs)
if cassette.write_protected and cassette.filter_request(vcr_request):
raise CannotOverwriteExistingCassetteException(cassette=cassette, failed_request=vcr_request)
_logger.info("%s not in cassette, sending to real server", vcr_request)
return vcr_request, None
def _record_responses(cassette, vcr_request, real_response):
for past_real_response in real_response.history:
past_vcr_request = _make_vcr_request(past_real_response.request)
cassette.append(past_vcr_request, _to_serialized_response(past_real_response))
if real_response.history:
# If there was a redirection keep we want the request which will hold the
# final redirect value
vcr_request = _make_vcr_request(real_response.request)
cassette.append(vcr_request, _to_serialized_response(real_response))
return real_response
def _play_responses(cassette, request, vcr_request, client, kwargs):
history = []
allow_redirects = kwargs.get("allow_redirects", True)
vcr_response = cassette.play_response(vcr_request)
response = _from_serialized_response(request, vcr_response)
while allow_redirects and 300 <= response.status_code <= 399:
next_url = response.headers.get("location")
if not next_url:
break
vcr_request = VcrRequest("GET", next_url, None, dict(response.headers))
vcr_request = cassette.find_requests_with_most_matches(vcr_request)[0][0]
history.append(response)
# add cookies from response to session cookie store
client.cookies.extract_cookies(response)
vcr_response = cassette.play_response(vcr_request)
response = _from_serialized_response(vcr_request, vcr_response, history)
return response
async def _async_vcr_send(cassette, real_send, *args, **kwargs):
vcr_request, response = _shared_vcr_send(cassette, real_send, *args, **kwargs)
if response:
# add cookies from response to session cookie store
args[0].cookies.extract_cookies(response)
return response
real_response = await real_send(*args, **kwargs)
return _record_responses(cassette, vcr_request, real_response)
def async_vcr_send(cassette, real_send):
@functools.wraps(real_send)
def _inner_send(*args, **kwargs):
return _async_vcr_send(cassette, real_send, *args, **kwargs)
return _inner_send
def _sync_vcr_send(cassette, real_send, *args, **kwargs):
vcr_request, response = _shared_vcr_send(cassette, real_send, *args, **kwargs)
if response:
# add cookies from response to session cookie store
args[0].cookies.extract_cookies(response)
return response
real_response = real_send(*args, **kwargs)
return _record_responses(cassette, vcr_request, real_response)
def sync_vcr_send(cassette, real_send):
@functools.wraps(real_send)
def _inner_send(*args, **kwargs):
return _sync_vcr_send(cassette, real_send, *args, **kwargs)
return _inner_send
|
mit
|
[
646,
9143,
199,
646,
2050,
199,
504,
2882,
14,
1805,
492,
3371,
12,
10079,
199,
199,
646,
1455,
88,
199,
504,
373,
1556,
14,
1069,
492,
4784,
465,
812,
1556,
2017,
199,
504,
373,
1556,
14,
2550,
492,
18435,
5674,
952,
23490,
35,
6562,
266,
1726,
421,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
4711,
63,
2139,
8,
1014,
88,
63,
264,
732,
304,
272,
408,
272,
6601,
2323,
883,
7468,
3663,
5431,
12,
2839,
298,
1084,
13,
7810,
1674,
272,
21039,
5793,
370,
4036,
1406,
790,
370,
769,
402,
1338,
14,
272,
408,
339,
734,
275,
1052,
272,
367,
790,
12,
2729,
315,
1455,
88,
63,
264,
732,
14,
2139,
14,
1773,
26,
267,
11203,
63,
498,
275,
790,
14,
2708,
480,
1624,
13,
24,
531,
267,
734,
14,
5486,
8,
16167,
63,
498,
12,
3073,
267,
734,
59,
16167,
63,
498,
1055,
740,
8,
1391,
14,
2708,
480,
1624,
13,
24,
2237,
272,
372,
734,
421,
199,
318,
485,
475,
63,
8397,
63,
1310,
8,
1014,
88,
63,
264,
732,
304,
272,
372,
469,
267,
298,
1205,
63,
600,
582,
1455,
88,
63,
264,
732,
14,
1205,
63,
600,
12,
267,
298,
1014,
63,
1023,
582,
1455,
88,
63,
264,
732,
14,
1014,
63,
1023,
12,
267,
298,
2139,
582,
485,
4711,
63,
2139,
8,
1014,
88,
63,
264,
732,
395,
267,
298,
1317,
582,
1455,
88,
63,
264,
732,
14,
1317,
14,
2708,
480,
1624,
13,
24,
401,
298,
4247,
1288,
272,
789,
421,
199,
318,
485,
504,
63,
8397,
63,
2139,
8,
2139,
304,
272,
408,
272,
1455,
88,
11479,
2323,
465,
769,
402,
6346,
402,
1406,
790,
436,
574,
14,
272,
408,
339,
1406,
63,
513,
275,
942,
272,
367,
790,
12,
1338,
315,
2323,
14,
1744,
837,
267,
367,
373,
315,
1338,
26,
288,
1406,
63,
513,
14,
740,
1332,
498,
12,
373,
430,
272,
372,
1406,
63,
513,
421,
199,
32,
2068,
480,
1014,
88,
14,
2364,
14,
1600,
401,
10079,
1012,
199,
32,
2068,
480,
1014,
88,
14,
2364,
14,
739,
401,
10079,
1012,
199,
318,
485,
504,
63,
8397,
63,
1310,
8,
1069,
12,
6380,
63,
1310,
12,
7994,
29,
403,
304,
272,
1564,
275,
6380,
63,
1310,
14,
362,
480,
1317,
3471,
2143,
342,
272,
1177,
275,
1455,
88,
14,
2364,
8,
267,
2004,
63,
600,
29,
8397,
63,
1310,
14,
362,
480,
1205,
63,
600,
1288,
267,
1056,
29,
1069,
12,
267,
1455,
63,
1023,
29,
8397,
63,
1310,
14,
362,
480,
1014,
63,
1023,
1288,
267,
2323,
3699,
504,
63,
8397,
63,
2139,
8,
8397,
63,
1310,
14,
362,
480,
2139,
8150,
267,
1564,
29,
1317,
12,
267,
7994,
29,
5570,
503,
990,
272,
776,
272,
1177,
423,
1317,
275,
1564,
272,
372,
1177,
421,
199,
318,
485,
1875,
63,
86,
1556,
63,
1069,
8,
1014,
88,
63,
1069,
12,
1011,
958,
304,
272,
2396,
275,
1455,
88,
63,
1069,
14,
739,
1252,
2708,
480,
1624,
13,
24,
531,
272,
5108,
275,
620,
8,
1014,
88,
63,
1069,
14,
633,
9,
272,
2323,
275,
1211,
8,
1014,
88,
63,
1069,
14,
2139,
9,
272,
372,
812,
1556,
2017,
8,
1014,
88,
63,
1069,
14,
765,
12,
5108,
12,
2396,
12,
2323,
9,
421,
199,
318,
485,
5555,
63,
86,
1556,
63,
2254,
8,
67,
6562,
266,
12,
3363,
63,
2254,
12,
627,
589,
12,
1011,
958,
304,
272,
3363,
63,
1069,
275,
1249,
59,
17,
61,
339,
373,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
3093,
63,
1069,
12,
1011,
958,
9,
339,
340,
286,
6562,
266,
14,
2425,
63,
2802,
63,
1310,
63,
509,
8,
86,
1556,
63,
1069,
304,
267,
372,
373,
1556,
63,
1069,
12,
485,
2802,
63,
10360,
8,
67,
6562,
266,
12,
3363,
63,
1069,
12,
373,
1556,
63,
1069,
12,
1249,
59,
16,
467,
2074,
9,
339,
340,
286,
6562,
266,
14,
952,
63,
6798,
436,
286,
6562,
266,
14,
1541,
63,
1069,
8,
86,
1556,
63,
1069,
304,
267,
746,
18435,
5674,
952,
23490,
35,
6562,
266,
1726,
8,
67,
6562,
266,
29,
67,
6562,
266,
12,
3405,
63,
1069,
29,
86,
1556,
63,
1069,
9,
339,
485,
2921,
14,
815,
3647,
83,
440,
315,
286,
6562,
266,
12,
10209,
370,
3363,
1654,
401,
373,
1556,
63,
1069,
9,
272,
372,
373,
1556,
63,
1069,
12,
488,
421,
199,
318,
485,
3059,
63,
10360,
8,
67,
6562,
266,
12,
373,
1556,
63,
1069,
12,
3363,
63,
1310,
304,
272,
367,
13541,
63,
3093,
63,
1310,
315,
3363,
63,
1310,
14,
5570,
26,
267,
13541,
63,
86,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
18597,
63,
3093,
63,
1310,
14,
1069,
9,
267,
286,
6562,
266,
14,
740,
8,
18597,
63,
86,
1556,
63,
1069,
12,
485,
475,
63,
8397,
63,
1310,
8,
18597,
63,
3093,
63,
1310,
430,
339,
340,
3363,
63,
1310,
14,
5570,
26,
267,
327,
982,
2337,
1990,
282,
23713,
4215,
781,
2934,
314,
1056,
1314,
911,
10266,
314,
267,
327,
4242,
4660,
574,
267,
373,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
3093,
63,
1310,
14,
1069,
9,
339,
286,
6562,
266,
14,
740,
8,
86,
1556,
63,
1069,
12,
485,
475,
63,
8397,
63,
1310,
8,
3093,
63,
1310,
430,
272,
372,
3363,
63,
1310,
421,
199,
318,
485,
2802,
63,
10360,
8,
67,
6562,
266,
12,
1056,
12,
373,
1556,
63,
1069,
12,
1890,
12,
2074,
304,
272,
7994,
275,
942,
272,
2040,
63,
13607,
275,
2074,
14,
362,
480,
3306,
63,
13607,
401,
715,
9,
272,
373,
1556,
63,
1310,
275,
286,
6562,
266,
14,
2802,
63,
1310,
8,
86,
1556,
63,
1069,
9,
272,
1177,
275,
485,
504,
63,
8397,
63,
1310,
8,
1069,
12,
373,
1556,
63,
1310,
9,
339,
1830,
2040,
63,
13607,
436,
9601,
2695,
1177,
14,
1205,
63,
600,
2695,
650,
1020,
26,
267,
2163,
63,
633,
275,
1177,
14,
2139,
14,
362,
480,
1985,
531,
267,
340,
440,
2163,
63,
633,
26,
288,
2059,
398,
373,
1556,
63,
1069,
275,
812,
1556,
2017,
480,
2970,
401,
2163,
63,
633,
12
] |
[
9143,
199,
646,
2050,
199,
504,
2882,
14,
1805,
492,
3371,
12,
10079,
199,
199,
646,
1455,
88,
199,
504,
373,
1556,
14,
1069,
492,
4784,
465,
812,
1556,
2017,
199,
504,
373,
1556,
14,
2550,
492,
18435,
5674,
952,
23490,
35,
6562,
266,
1726,
421,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
4711,
63,
2139,
8,
1014,
88,
63,
264,
732,
304,
272,
408,
272,
6601,
2323,
883,
7468,
3663,
5431,
12,
2839,
298,
1084,
13,
7810,
1674,
272,
21039,
5793,
370,
4036,
1406,
790,
370,
769,
402,
1338,
14,
272,
408,
339,
734,
275,
1052,
272,
367,
790,
12,
2729,
315,
1455,
88,
63,
264,
732,
14,
2139,
14,
1773,
26,
267,
11203,
63,
498,
275,
790,
14,
2708,
480,
1624,
13,
24,
531,
267,
734,
14,
5486,
8,
16167,
63,
498,
12,
3073,
267,
734,
59,
16167,
63,
498,
1055,
740,
8,
1391,
14,
2708,
480,
1624,
13,
24,
2237,
272,
372,
734,
421,
199,
318,
485,
475,
63,
8397,
63,
1310,
8,
1014,
88,
63,
264,
732,
304,
272,
372,
469,
267,
298,
1205,
63,
600,
582,
1455,
88,
63,
264,
732,
14,
1205,
63,
600,
12,
267,
298,
1014,
63,
1023,
582,
1455,
88,
63,
264,
732,
14,
1014,
63,
1023,
12,
267,
298,
2139,
582,
485,
4711,
63,
2139,
8,
1014,
88,
63,
264,
732,
395,
267,
298,
1317,
582,
1455,
88,
63,
264,
732,
14,
1317,
14,
2708,
480,
1624,
13,
24,
401,
298,
4247,
1288,
272,
789,
421,
199,
318,
485,
504,
63,
8397,
63,
2139,
8,
2139,
304,
272,
408,
272,
1455,
88,
11479,
2323,
465,
769,
402,
6346,
402,
1406,
790,
436,
574,
14,
272,
408,
339,
1406,
63,
513,
275,
942,
272,
367,
790,
12,
1338,
315,
2323,
14,
1744,
837,
267,
367,
373,
315,
1338,
26,
288,
1406,
63,
513,
14,
740,
1332,
498,
12,
373,
430,
272,
372,
1406,
63,
513,
421,
199,
32,
2068,
480,
1014,
88,
14,
2364,
14,
1600,
401,
10079,
1012,
199,
32,
2068,
480,
1014,
88,
14,
2364,
14,
739,
401,
10079,
1012,
199,
318,
485,
504,
63,
8397,
63,
1310,
8,
1069,
12,
6380,
63,
1310,
12,
7994,
29,
403,
304,
272,
1564,
275,
6380,
63,
1310,
14,
362,
480,
1317,
3471,
2143,
342,
272,
1177,
275,
1455,
88,
14,
2364,
8,
267,
2004,
63,
600,
29,
8397,
63,
1310,
14,
362,
480,
1205,
63,
600,
1288,
267,
1056,
29,
1069,
12,
267,
1455,
63,
1023,
29,
8397,
63,
1310,
14,
362,
480,
1014,
63,
1023,
1288,
267,
2323,
3699,
504,
63,
8397,
63,
2139,
8,
8397,
63,
1310,
14,
362,
480,
2139,
8150,
267,
1564,
29,
1317,
12,
267,
7994,
29,
5570,
503,
990,
272,
776,
272,
1177,
423,
1317,
275,
1564,
272,
372,
1177,
421,
199,
318,
485,
1875,
63,
86,
1556,
63,
1069,
8,
1014,
88,
63,
1069,
12,
1011,
958,
304,
272,
2396,
275,
1455,
88,
63,
1069,
14,
739,
1252,
2708,
480,
1624,
13,
24,
531,
272,
5108,
275,
620,
8,
1014,
88,
63,
1069,
14,
633,
9,
272,
2323,
275,
1211,
8,
1014,
88,
63,
1069,
14,
2139,
9,
272,
372,
812,
1556,
2017,
8,
1014,
88,
63,
1069,
14,
765,
12,
5108,
12,
2396,
12,
2323,
9,
421,
199,
318,
485,
5555,
63,
86,
1556,
63,
2254,
8,
67,
6562,
266,
12,
3363,
63,
2254,
12,
627,
589,
12,
1011,
958,
304,
272,
3363,
63,
1069,
275,
1249,
59,
17,
61,
339,
373,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
3093,
63,
1069,
12,
1011,
958,
9,
339,
340,
286,
6562,
266,
14,
2425,
63,
2802,
63,
1310,
63,
509,
8,
86,
1556,
63,
1069,
304,
267,
372,
373,
1556,
63,
1069,
12,
485,
2802,
63,
10360,
8,
67,
6562,
266,
12,
3363,
63,
1069,
12,
373,
1556,
63,
1069,
12,
1249,
59,
16,
467,
2074,
9,
339,
340,
286,
6562,
266,
14,
952,
63,
6798,
436,
286,
6562,
266,
14,
1541,
63,
1069,
8,
86,
1556,
63,
1069,
304,
267,
746,
18435,
5674,
952,
23490,
35,
6562,
266,
1726,
8,
67,
6562,
266,
29,
67,
6562,
266,
12,
3405,
63,
1069,
29,
86,
1556,
63,
1069,
9,
339,
485,
2921,
14,
815,
3647,
83,
440,
315,
286,
6562,
266,
12,
10209,
370,
3363,
1654,
401,
373,
1556,
63,
1069,
9,
272,
372,
373,
1556,
63,
1069,
12,
488,
421,
199,
318,
485,
3059,
63,
10360,
8,
67,
6562,
266,
12,
373,
1556,
63,
1069,
12,
3363,
63,
1310,
304,
272,
367,
13541,
63,
3093,
63,
1310,
315,
3363,
63,
1310,
14,
5570,
26,
267,
13541,
63,
86,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
18597,
63,
3093,
63,
1310,
14,
1069,
9,
267,
286,
6562,
266,
14,
740,
8,
18597,
63,
86,
1556,
63,
1069,
12,
485,
475,
63,
8397,
63,
1310,
8,
18597,
63,
3093,
63,
1310,
430,
339,
340,
3363,
63,
1310,
14,
5570,
26,
267,
327,
982,
2337,
1990,
282,
23713,
4215,
781,
2934,
314,
1056,
1314,
911,
10266,
314,
267,
327,
4242,
4660,
574,
267,
373,
1556,
63,
1069,
275,
485,
1875,
63,
86,
1556,
63,
1069,
8,
3093,
63,
1310,
14,
1069,
9,
339,
286,
6562,
266,
14,
740,
8,
86,
1556,
63,
1069,
12,
485,
475,
63,
8397,
63,
1310,
8,
3093,
63,
1310,
430,
272,
372,
3363,
63,
1310,
421,
199,
318,
485,
2802,
63,
10360,
8,
67,
6562,
266,
12,
1056,
12,
373,
1556,
63,
1069,
12,
1890,
12,
2074,
304,
272,
7994,
275,
942,
272,
2040,
63,
13607,
275,
2074,
14,
362,
480,
3306,
63,
13607,
401,
715,
9,
272,
373,
1556,
63,
1310,
275,
286,
6562,
266,
14,
2802,
63,
1310,
8,
86,
1556,
63,
1069,
9,
272,
1177,
275,
485,
504,
63,
8397,
63,
1310,
8,
1069,
12,
373,
1556,
63,
1310,
9,
339,
1830,
2040,
63,
13607,
436,
9601,
2695,
1177,
14,
1205,
63,
600,
2695,
650,
1020,
26,
267,
2163,
63,
633,
275,
1177,
14,
2139,
14,
362,
480,
1985,
531,
267,
340,
440,
2163,
63,
633,
26,
288,
2059,
398,
373,
1556,
63,
1069,
275,
812,
1556,
2017,
480,
2970,
401,
2163,
63,
633,
12,
0
] |
[
1,
1,
1,
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d_midterm2
|
static/Brython3.1.1-20150328-091302/Lib/site-packages/pygame/event.py
|
603
|
19086
|
#!/usr/bin/env python
'''Pygame module for interacting with events and queues.
Pygame handles all it's event messaging through an event queue. The routines
in this module help you manage that event queue. The input queue is heavily
dependent on the pygame display module. If the display has not been
initialized and a video mode not set, the event queue will not really work.
The queue is a regular queue of Event objects, there are a variety of ways
to access the events it contains. From simply checking for the existance of
events, to grabbing them directly off the stack.
All events have a type identifier. This event type is in between the values
of NOEVENT and NUMEVENTS. All user defined events can have the value of
USEREVENT or higher. It is recommended make sure your event id's follow this
system.
To get the state of various input devices, you can forego the event queue
and access the input devices directly with their appropriate modules; mouse,
key, and joystick. If you use this method, remember that pygame requires some
form of communication with the system window manager and other parts of the
platform. To keep pygame in synch with the system, you will need to call
pygame.event.pump() to keep everything current. You'll want to call this
function usually once per game loop.
The event queue offers some simple filtering. This can help performance
slightly by blocking certain event types from the queue, use the
pygame.event.set_allowed() and pygame.event.set_blocked() to work with
this filtering. All events default to allowed.
Joysticks will not send any events until the device has been initialized.
An Event object contains an event type and a readonly set of member data.
The Event object contains no method functions, just member data. Event
objects are retrieved from the pygame event queue. You can create your
own new events with the pygame.event.Event() function.
Your program must take steps to keep the event queue from overflowing. If the
program is not clearing or getting all events off the queue at regular
intervals, it can overflow. When the queue overflows an exception is thrown.
All Event objects contain an event type identifier in the Event.type member.
You may also get full access to the Event's member data through the Event.dict
method. All other member lookups will be passed through to the Event's
dictionary values.
While debugging and experimenting, you can print the Event objects for a
quick display of its type and members. Events that come from the system
will have a guaranteed set of member items based on the type. Here is a
list of the Event members that are defined with each type.
QUIT
(none)
ACTIVEEVENT
gain, state
KEYDOWN
unicode, key, mod
KEYUP
key, mod
MOUSEMOTION
pos, rel, buttons
MOUSEBUTTONUP
pos, button
MOUSEBUTTONDOWN
pos, button
JOYAXISMOTION
joy, axis, value
JOYBALLMOTION
joy, ball, rel
JOYHATMOTION
joy, hat, value
JOYBUTTONUP
joy, button
JOYBUTTONDOWN
joy, button
VIDEORESIZE
size, w, h
VIDEOEXPOSE
(none)
USEREVENT
code
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
from copy import copy
#from ctypes import * #brython
from SDL import *
import pygame.base
import pygame.locals
import pygame.display
def pump():
'''Internally process pygame event handlers.
For each frame of your game, you will need to make some sort of call to
the event queue. This ensures your program can internally interact with
the rest of the operating system. If you are not using other event
functions in your game, you should call pygame.event.pump() to allow
pygame to handle internal actions.
This function is not necessary if your program is consistently processing
events on the queue through the other pygame.event functions.
There are important things that must be dealt with internally in the event
queue. The main window may need to be repainted or respond to the system.
If you fail to make a call to the event queue for too long, the system may
decide your program has locked up.
'''
pygame.display._video_init_check()
SDL_PumpEvents()
def get(typelist=None):
'''Get events from the queue.
pygame.event.get(): return Eventlist
pygame.event.get(type): return Eventlist
pygame.event.get(typelist): return Eventlist
This will get all the messages and remove them from the queue. If a type
or sequence of types is given only those messages will be removed from the
queue.
If you are only taking specific events from the queue, be aware that the
queue could eventually fill up with the events you are not interested.
:Parameters:
`typelist` : int or sequence of int
Event type or list of event types that can be returned.
:rtype: list of `Event`
'''
pygame.display._video_init_check()
if typelist is None:
mask = SDL_ALLEVENTS
else:
if hasattr(typelist, '__len__'):
mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
else:
mask = int(typelist)
SDL_PumpEvents()
events = []
new_events = SDL_PeepEvents(1, SDL_GETEVENT, mask)
while new_events:
events.append(Event(0, sdl_event=new_events[0]))
new_events = SDL_PeepEvents(1, SDL_GETEVENT, mask)
return events
def poll():
'''Get a single event from the queue.
Returns a single event from the queue. If the event queue is empty an event
of type pygame.NOEVENT will be returned immediately. The returned event is
removed from the queue.
:rtype: Event
'''
pygame.display._video_init_check()
event = SDL_PollEventAndReturn()
if event:
return Event(0, sdl_event=event, keep_userdata=True)
else:
return Event(pygame.locals.NOEVENT)
def wait():
'''Wait for a single event from the queue.
Returns a single event from the queue. If the queue is empty this function
will wait until one is created. While the program is waiting it will sleep
in an idle state. This is important for programs that want to share the
system with other applications.
:rtype: Event
'''
pygame.display._video_init_check()
return Event(0, sdl_event=SDL_WaitEventAndReturn())
def peek(typelist=None):
'''Test if event types are waiting on the queue.
Returns true if there are any events of the given type waiting on the
queue. If a sequence of event types is passed, this will return True if
any of those events are on the queue.
:Parameters:
`typelist` : int or sequence of int
Event type or list of event types to look for.
:rtype: bool
'''
pygame.display._video_init_check()
if typelist is None:
mask = SDL_ALLEVENTS
else:
if hasattr(typelist, '__len__'):
mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
else:
mask = SDL_EVENTMASK(int(typelist))
SDL_PumpEvents()
events = SDL_PeepEvents(1, SDL_PEEKEVENT, mask)
if typelist is None:
if events:
return Event(0, sdl_event=events[0], keep_userdata=True)
else:
return Event(pygame.locals.NOEVENT) # XXX deviation from pygame
return len(events) > 0
def clear(typelist=None):
'''Remove all events from the queue.
Remove all events or events of a specific type from the queue. This has the
same effect as `get` except nothing is returned. This can be slightly more
effecient when clearing a full event queue.
:Parameters:
`typelist` : int or sequence of int
Event type or list of event types to remove.
'''
pygame.display._video_init_check()
if typelist is None:
mask = SDL_ALLEVENTS
else:
if hasattr(typelist, '__len__'):
mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
else:
mask = int(typelist)
SDL_PumpEvents()
events = []
new_events = SDL_PeepEvents(1, SDL_GETEVENT, mask)
while new_events:
new_events = SDL_PeepEvents(1, SDL_GETEVENT, mask)
_event_names = {
SDL_ACTIVEEVENT: 'ActiveEvent',
SDL_KEYDOWN: 'KeyDown',
SDL_KEYUP: 'KeyUp',
SDL_MOUSEMOTION: 'MouseMotion',
SDL_MOUSEBUTTONDOWN:'MouseButtonDown',
SDL_MOUSEBUTTONUP: 'MouseButtonUp',
SDL_JOYAXISMOTION: 'JoyAxisMotion',
SDL_JOYBALLMOTION: 'JoyBallMotion',
SDL_JOYHATMOTION: 'JoyHatMotion',
SDL_JOYBUTTONUP: 'JoyButtonUp',
SDL_JOYBUTTONDOWN: 'JoyButtonDown',
SDL_QUIT: 'Quit',
SDL_SYSWMEVENT: 'SysWMEvent',
SDL_VIDEORESIZE: 'VideoResize',
SDL_VIDEOEXPOSE: 'VideoExpose',
SDL_NOEVENT: 'NoEvent'
}
def event_name(event_type):
'''Get the string name from an event id.
Pygame uses integer ids to represent the event types. If you want to
report these types to the user they should be converted to strings. This
will return a the simple name for an event type. The string is in the
CamelCase style.
:Parameters:
- `event_type`: int
:rtype: str
'''
if event_type >= SDL_USEREVENT and event_type < SDL_NUMEVENTS:
return 'UserEvent'
return _event_names.get(event_type, 'Unknown')
def set_blocked(typelist):
'''Control which events are allowed on the queue.
The given event types are not allowed to appear on the event queue. By
default all events can be placed on the queue. It is safe to disable an
event type multiple times.
If None is passed as the argument, this has the opposite effect and none of
the event types are allowed to be placed on the queue.
:note: events posted with `post` will not be blocked.
:Parameters:
`typelist` : int or sequence of int or None
Event type or list of event types to disallow.
'''
pygame.display._video_init_check()
if typelist is None:
SDL_EventState(SDL_ALLEVENTS, SDL_IGNORE)
elif hasattr(typelist, '__len__'):
for val in typelist:
SDL_EventState(val, SDL_IGNORE)
else:
SDL_EventState(typelist, SDL_IGNORE)
def set_allowed(typelist):
'''Control which events are allowed on the queue.
The given event types are allowed to appear on the event queue. By default
all events can be placed on the queue. It is safe to enable an event type
multiple times.
If None is passed as the argument, this has the opposite effect and all of
the event types are allowed to be placed on the queue.
:Parameters:
`typelist` : int or sequence of int or None
Event type or list of event types to disallow.
'''
pygame.display._video_init_check()
if typelist is None:
SDL_EventState(SDL_ALLEVENTS, SDL_ENABLE)
elif hasattr(typelist, '__len__'):
for val in typelist:
SDL_EventState(val, SDL_ENABLE)
else:
SDL_EventState(typelist, SDL_ENABLE)
def get_blocked(typelist):
'''Test if a type of event is blocked from the queue.
Returns true if the given event type is blocked from the queue.
:Parameters:
- `event_type`: int
:rtype: int
'''
pygame.display._video_init_check()
if typelist == None:
return SDL_EventState(SDL_ALLEVENTS, SDL_QUERY) == SDL_ENABLE
elif hasattr(typelist, '__len__'): # XXX undocumented behaviour
for val in typelist:
if SDL_EventState(val, SDL_QUERY) == SDL_ENABLE:
return True
return False
else:
return SDL_EventState(typelist, SDL_QUERY) == SDL_ENABLE
def set_grab(grab):
'''Control the sharing of input devices with other applications.
When your program runs in a windowed environment, it will share the mouse
and keyboard devices with other applications that have focus. If your
program sets the event grab to True, it will lock all input into your
program.
It is best to not always grab the input, since it prevents the user from
doing other things on their system.
:Parameters:
- `grab`: bool
'''
pygame.display._video_init_check()
if grab:
SDL_WM_GrabInput(SDL_GRAB_ON)
else:
SDL_WM_GrabInput(SDL_GRAB_OFF)
def get_grab():
'''Test if the program is sharing input devices.
Returns true when the input events are grabbed for this application. Use
`set_grab` to control this state.
:rtype: bool
'''
pygame.display._video_init_check()
return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON
_USEROBJECT_CHECK1 = int(0xdeadbeef) # signed
_USEROBJECT_CHECK2 = 0xfeedf00d
_user_event_objects = {}
_user_event_nextid = 1
def post(event):
'''Place a new event on the queue.
This places a new event at the end of the event queue. These Events will
later be retrieved from the other queue functions.
This is usually used for placing pygame.USEREVENT events on the queue.
Although any type of event can be placed, if using the sytem event types
your program should be sure to create the standard attributes with
appropriate values.
:Parameters:
`event` : Event
Event to add to the queue.
'''
global _user_event_nextid
pygame.display._video_init_check()
sdl_event = SDL_Event(event.type)
sdl_event.user.code = _USEROBJECT_CHECK1
sdl_event.user.data1 = c_void_p(_USEROBJECT_CHECK2)
sdl_event.user.data2 = c_void_p(_user_event_nextid)
_user_event_objects[_user_event_nextid] = event
_user_event_nextid += 1
SDL_PushEvent(sdl_event)
class Event:
def __init__(self, event_type, event_dict=None, sdl_event=None,
keep_userdata=False, **attributes):
'''Create a new event object.
Creates a new event with the given type. The event is created with the
given attributes and values. The attributes can come from a dictionary
argument, or as string keys from a dictionary.
The given attributes will be readonly attributes on the new event
object itself. These are the only attributes on the Event object,
there are no methods attached to Event objects.
:Parameters:
`event_type` : int
Event type to create
`event_dict` : dict
Dictionary of attributes to assign.
`sdl_event` : `SDL_Event`
Construct a Pygame event from the given SDL_Event; used
internally.
`keep_userdata` : bool
Used internally.
`attributes` : additional keyword arguments
Additional attributes to assign to the event.
'''
if sdl_event:
uevent = cast(pointer(sdl_event), POINTER(SDL_UserEvent)).contents
if uevent.code == _USEROBJECT_CHECK1 and \
uevent.data1 == _USEROBJECT_CHECK2 and \
uevent.data2 in _user_event_objects:
# An event that was posted; grab dict from local store.
id = sdl_event.data2
for key, value in _user_event_objects[id].__dict__.items():
setattr(self, key, value)
# Free memory unless just peeking
if not keep_userdata:
del _user_event_objects[id]
else:
# Standard SDL event
self.type = sdl_event.type
if self.type == SDL_QUIT:
pass
elif self.type == SDL_ACTIVEEVENT:
self.gain = sdl_event.gain
self.state = sdl_event.state
elif self.type == SDL_KEYDOWN:
self.unicode = sdl_event.keysym.unicode
self.key = sdl_event.keysym.sym
self.mod = sdl_event.keysym.mod
elif self.type == SDL_KEYUP:
self.key = sdl_event.keysym.sym
self.mod = sdl_event.keysym.mod
elif self.type == SDL_MOUSEMOTION:
self.pos = (sdl_event.x, sdl_event.y)
self.rel = (sdl_event.xrel, sdl_event.yrel)
self.buttons = (sdl_event.state & SDL_BUTTON(1) != 0,
sdl_event.state & SDL_BUTTON(2) != 0,
sdl_event.state & SDL_BUTTON(3) != 0)
elif self.type in (SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP):
self.pos = (sdl_event.x, sdl_event.y)
self.button = sdl_event.button
elif self.type == SDL_JOYAXISMOTION:
self.joy = sdl_event.which
self.axis = sdl_event.axis
self.value = sdl_event.value / 32767.0
elif self.type == SDL_JOYBALLMOTION:
self.joy = sdl_event.which
self.ball = sdl_event.ball
self.rel = (sdl_event.xrel, sdl_event.yrel)
elif self.type == SDL_JOYHATMOTION:
self.joy = sdl_event.which
self.hat = sdl_event.hat
hx = hy = 0
if sdl_event.value & SDL_HAT_UP:
hy = 1
if sdl_event.value & SDL_HAT_DOWN:
hy = -1
if sdl_event.value & SDL_HAT_RIGHT:
hx = 1
if sdl_event.value & SDL_HAT_LEFT:
hx = -1
self.value = (hx, hy)
elif self.type in (SDL_JOYBUTTONUP, SDL_JOYBUTTONDOWN):
self.joy = sdl_event.which
self.button = sdl_event.button
elif self.type == SDL_VIDEORESIZE:
self.size = (sdl_event.w, sdl_event.h)
self.w = sdl_event.w
self.h = sdl_event.h
elif self.type == SDL_VIDEOEXPOSE:
pass
elif self.type == SDL_SYSWMEVENT:
pass ### XXX: not implemented
elif self.type >= SDL_USEREVENT and self.type < SDL_NUMEVENTS:
self.code = sdl_event.code
else:
# Create an event (not from event queue)
self.type = event_type
if event_dict:
for key, value in event_dict.items():
setattr(self, key, value)
for key, value in attributes.items():
setattr(self, key, value)
# Bizarre undocumented but used by some people.
self.dict = self.__dict__
def __repr__(self):
d = copy(self.__dict__)
del d['type']
return '<Event(%d-%s %r)>' % \
(self.type, event_name(self.type), d)
def __nonzero__(self):
return self.type != SDL_NOEVENT
EventType = Event
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2713,
5097,
859,
367,
17232,
316,
543,
4474,
436,
21366,
14,
199,
199,
2713,
5097,
10022,
1006,
652,
1159,
1566,
30429,
4012,
376,
1566,
4126,
14,
710,
14975,
199,
262,
642,
859,
1720,
1265,
9635,
626,
1566,
4126,
14,
710,
1324,
4126,
365,
946,
1214,
3444,
199,
7106,
641,
314,
9193,
2929,
859,
14,
982,
314,
2929,
965,
440,
2757,
199,
12486,
436,
282,
3991,
818,
440,
663,
12,
314,
1566,
4126,
911,
440,
7710,
1736,
14,
523,
199,
1918,
4126,
365,
282,
5578,
4126,
402,
6763,
2251,
12,
2337,
787,
282,
32246,
402,
15217,
199,
475,
2879,
314,
4474,
652,
3509,
14,
11606,
9329,
7907,
367,
314,
444,
73,
611,
402,
199,
4368,
12,
370,
1999,
2501,
316,
3062,
5370,
2331,
314,
3464,
14,
523,
199,
2422,
4474,
1172,
282,
730,
5148,
14,
961,
1566,
730,
365,
315,
3382,
314,
1338,
199,
1618,
4825,
8193,
436,
11576,
8193,
51,
14,
2900,
922,
3247,
4474,
883,
1172,
314,
574,
402,
199,
3791,
8193,
503,
10948,
14,
2779,
365,
14318,
1852,
3238,
2195,
1566,
1305,
1159,
2035,
642,
199,
2253,
14,
523,
199,
1378,
664,
314,
1174,
402,
7750,
1324,
7256,
12,
1265,
883,
11257,
1939,
314,
1566,
4126,
199,
460,
2879,
314,
1324,
7256,
5370,
543,
3932,
5827,
4621,
27,
12817,
12,
199,
498,
12,
436,
5225,
89,
18043,
14,
982,
1265,
675,
642,
1083,
12,
21027,
626,
9193,
5074,
2005,
199,
964,
402,
23506,
543,
314,
2656,
4353,
5256,
436,
1163,
4184,
402,
314,
199,
3246,
14,
4005,
4215,
9193,
315,
308,
5654,
543,
314,
2656,
12,
1265,
911,
1929,
370,
1240,
199,
22278,
14,
1430,
14,
29547,
342,
370,
4215,
8137,
1453,
14,
2047,
7171,
2934,
370,
1240,
642,
199,
1593,
9987,
5403,
1126,
9219,
4438,
14,
523,
199,
1918,
1566,
4126,
32563,
2005,
3486,
14545,
14,
961,
883,
1720,
10238,
199,
83,
4040,
590,
701,
14592,
9842,
1566,
2943,
687,
314,
4126,
12,
675,
314,
199,
22278,
14,
1430,
14,
409,
63,
6541,
342,
436,
9193,
14,
1430,
14,
409,
63,
17726,
342,
370,
1736,
543,
199,
3749,
14545,
14,
2900,
4474,
849,
370,
4370,
14,
523,
199,
5691,
89,
18043,
83,
911,
440,
3222,
1263,
4474,
5133,
314,
2243,
965,
2757,
10038,
14,
199,
199,
2493,
6763,
909,
3509,
376,
1566,
730,
436,
282,
6863,
663,
402,
3653,
666,
14,
199,
1918,
6763,
909,
3509,
949,
1083,
3423,
12,
2951,
3653,
666,
14,
6763,
199,
1462,
787,
12396,
687,
314,
9193,
1566,
4126,
14,
2047,
883,
1218,
2195,
199,
944,
892,
4474,
543,
314,
9193,
14,
1430,
14,
2390,
342,
805,
14,
199,
199,
14398,
2240,
1471,
5452,
7124,
370,
4215,
314,
1566,
4126,
687,
15784,
316,
14,
982,
314,
199,
6815,
365,
440,
5436,
316,
503,
10232,
1006,
4474,
2331,
314,
4126,
737,
5578,
199,
18574,
12,
652,
883,
15784,
14,
221,
3979,
314,
4126,
15784,
83,
376,
1919,
365,
14031,
14,
523,
199,
2422,
6763,
2251,
1395,
376,
1566,
730,
5148,
315,
314,
6763,
14,
466,
3653,
14,
199,
5556,
1443,
2597,
664,
2615,
2879,
370,
314,
6763,
1159,
3653,
666,
4012,
314,
6763,
14,
807,
199,
765,
14,
2900,
1163,
3653,
16807,
911,
506,
3032,
4012,
370,
314,
6763,
1159,
199,
9086,
1338,
14,
523,
199,
25215,
10201,
436,
11805,
316,
12,
1265,
883,
870,
314,
6763,
2251,
367,
282,
199,
13239,
2929,
402,
2399,
730,
436,
7556,
14,
27982,
626,
11492,
687,
314,
2656,
199,
14117,
1172,
282,
17334,
663,
402,
3653,
2974,
4079,
641,
314,
730,
14,
11842,
365,
282,
199,
513,
402,
314,
6763,
7556,
626,
787,
3247,
543,
1924,
730,
14,
199,
199,
2328,
649,
3515,
272,
334,
3592,
9,
199,
10401,
8193,
755,
272,
15334,
12,
1174,
199,
3078,
8819,
755,
272,
2649,
12,
790,
12,
3413,
199,
3078,
2160,
260,
272,
790,
12,
3413,
199,
25571,
27235,
1075,
755,
272,
2086,
12,
4668,
12,
15766,
199,
25571,
13272,
2160,
14821,
2086,
12,
5528,
199,
25571,
13272,
8819,
23855,
2086,
12,
5528,
199,
15465,
57,
9839,
1311,
27235,
1075,
263,
272,
5225,
89,
12,
3114,
12,
574,
199,
15465,
57,
34,
1761,
27235,
1075,
14821,
5225,
89,
12,
330,
452,
12,
4668,
199,
15465,
57,
40,
619,
27235,
1075,
420,
272,
5225,
89,
12,
394,
292,
12,
574,
199,
15465,
57,
13272,
2160,
3515,
272,
5225,
89,
12,
5528,
199,
15465,
57,
13272,
8819,
263,
272,
5225,
89,
12,
5528,
199,
5437,
37,
726,
654,
11025,
3515,
272,
1568,
12,
336,
12,
394,
199,
20142,
1438,
3064,
3515,
272,
334,
3592,
9,
199,
3791,
8193,
3322,
272,
1233,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
504,
1331,
492,
1331,
199,
3,
504,
5577,
492,
627,
221,
327,
66,
23196,
199,
199,
504,
14314,
492,
627,
199,
646,
9193,
14,
1095,
199,
646,
9193,
14,
9350,
199,
646,
9193,
14,
2918,
199,
199,
318,
31741,
837,
272,
1449,
607,
1203,
1183,
2112,
9193,
1566,
8297,
14,
339,
2104,
1924,
2787,
402,
2195,
9219,
12,
1265,
911,
1929,
370,
1852,
2005,
4069,
402,
1240,
370,
272,
314,
1566,
4126,
14,
961,
15620,
2195,
2240,
883,
14448,
17232,
543,
272,
314,
4618,
402,
314,
17406,
2656,
14,
982,
1265,
787,
440,
1808,
1163,
1566,
272,
3423,
315,
2195,
9219,
12,
1265,
1077,
1240,
9193,
14,
1430,
14,
29547,
342,
370,
2040,
272,
9193,
370,
2429,
5007,
5445,
14,
339,
961,
805,
365,
440,
5784,
340,
2195,
2240,
365,
12137,
590,
6661,
272,
4474,
641,
314,
4126,
4012,
314,
1163,
9193,
14,
1430,
3423,
14,
489,
272,
6006,
787,
11012,
7645,
626,
1471,
506,
477,
4478,
543,
14448,
315,
314,
1566,
272,
4126,
14,
710,
2446,
4353,
1443,
1929,
370,
506,
295,
387,
9082,
503,
22722,
370,
314,
2656,
14,
272,
982,
1265,
2449,
370,
1852,
282,
1240,
370,
314,
1566,
4126,
367,
4634,
1846,
12,
314,
2656,
1443,
272,
19822,
2195,
2240,
965,
14233,
1536,
14,
272,
1449,
272,
9193,
14,
2918,
423,
3722,
63,
826,
63,
1074,
342,
272,
14314,
63,
48,
1220,
11770,
342,
199,
199,
318,
664,
8,
466,
513,
29,
403,
304,
272,
1449,
1002,
4474,
687
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2713,
5097,
859,
367,
17232,
316,
543,
4474,
436,
21366,
14,
199,
199,
2713,
5097,
10022,
1006,
652,
1159,
1566,
30429,
4012,
376,
1566,
4126,
14,
710,
14975,
199,
262,
642,
859,
1720,
1265,
9635,
626,
1566,
4126,
14,
710,
1324,
4126,
365,
946,
1214,
3444,
199,
7106,
641,
314,
9193,
2929,
859,
14,
982,
314,
2929,
965,
440,
2757,
199,
12486,
436,
282,
3991,
818,
440,
663,
12,
314,
1566,
4126,
911,
440,
7710,
1736,
14,
523,
199,
1918,
4126,
365,
282,
5578,
4126,
402,
6763,
2251,
12,
2337,
787,
282,
32246,
402,
15217,
199,
475,
2879,
314,
4474,
652,
3509,
14,
11606,
9329,
7907,
367,
314,
444,
73,
611,
402,
199,
4368,
12,
370,
1999,
2501,
316,
3062,
5370,
2331,
314,
3464,
14,
523,
199,
2422,
4474,
1172,
282,
730,
5148,
14,
961,
1566,
730,
365,
315,
3382,
314,
1338,
199,
1618,
4825,
8193,
436,
11576,
8193,
51,
14,
2900,
922,
3247,
4474,
883,
1172,
314,
574,
402,
199,
3791,
8193,
503,
10948,
14,
2779,
365,
14318,
1852,
3238,
2195,
1566,
1305,
1159,
2035,
642,
199,
2253,
14,
523,
199,
1378,
664,
314,
1174,
402,
7750,
1324,
7256,
12,
1265,
883,
11257,
1939,
314,
1566,
4126,
199,
460,
2879,
314,
1324,
7256,
5370,
543,
3932,
5827,
4621,
27,
12817,
12,
199,
498,
12,
436,
5225,
89,
18043,
14,
982,
1265,
675,
642,
1083,
12,
21027,
626,
9193,
5074,
2005,
199,
964,
402,
23506,
543,
314,
2656,
4353,
5256,
436,
1163,
4184,
402,
314,
199,
3246,
14,
4005,
4215,
9193,
315,
308,
5654,
543,
314,
2656,
12,
1265,
911,
1929,
370,
1240,
199,
22278,
14,
1430,
14,
29547,
342,
370,
4215,
8137,
1453,
14,
2047,
7171,
2934,
370,
1240,
642,
199,
1593,
9987,
5403,
1126,
9219,
4438,
14,
523,
199,
1918,
1566,
4126,
32563,
2005,
3486,
14545,
14,
961,
883,
1720,
10238,
199,
83,
4040,
590,
701,
14592,
9842,
1566,
2943,
687,
314,
4126,
12,
675,
314,
199,
22278,
14,
1430,
14,
409,
63,
6541,
342,
436,
9193,
14,
1430,
14,
409,
63,
17726,
342,
370,
1736,
543,
199,
3749,
14545,
14,
2900,
4474,
849,
370,
4370,
14,
523,
199,
5691,
89,
18043,
83,
911,
440,
3222,
1263,
4474,
5133,
314,
2243,
965,
2757,
10038,
14,
199,
199,
2493,
6763,
909,
3509,
376,
1566,
730,
436,
282,
6863,
663,
402,
3653,
666,
14,
199,
1918,
6763,
909,
3509,
949,
1083,
3423,
12,
2951,
3653,
666,
14,
6763,
199,
1462,
787,
12396,
687,
314,
9193,
1566,
4126,
14,
2047,
883,
1218,
2195,
199,
944,
892,
4474,
543,
314,
9193,
14,
1430,
14,
2390,
342,
805,
14,
199,
199,
14398,
2240,
1471,
5452,
7124,
370,
4215,
314,
1566,
4126,
687,
15784,
316,
14,
982,
314,
199,
6815,
365,
440,
5436,
316,
503,
10232,
1006,
4474,
2331,
314,
4126,
737,
5578,
199,
18574,
12,
652,
883,
15784,
14,
221,
3979,
314,
4126,
15784,
83,
376,
1919,
365,
14031,
14,
523,
199,
2422,
6763,
2251,
1395,
376,
1566,
730,
5148,
315,
314,
6763,
14,
466,
3653,
14,
199,
5556,
1443,
2597,
664,
2615,
2879,
370,
314,
6763,
1159,
3653,
666,
4012,
314,
6763,
14,
807,
199,
765,
14,
2900,
1163,
3653,
16807,
911,
506,
3032,
4012,
370,
314,
6763,
1159,
199,
9086,
1338,
14,
523,
199,
25215,
10201,
436,
11805,
316,
12,
1265,
883,
870,
314,
6763,
2251,
367,
282,
199,
13239,
2929,
402,
2399,
730,
436,
7556,
14,
27982,
626,
11492,
687,
314,
2656,
199,
14117,
1172,
282,
17334,
663,
402,
3653,
2974,
4079,
641,
314,
730,
14,
11842,
365,
282,
199,
513,
402,
314,
6763,
7556,
626,
787,
3247,
543,
1924,
730,
14,
199,
199,
2328,
649,
3515,
272,
334,
3592,
9,
199,
10401,
8193,
755,
272,
15334,
12,
1174,
199,
3078,
8819,
755,
272,
2649,
12,
790,
12,
3413,
199,
3078,
2160,
260,
272,
790,
12,
3413,
199,
25571,
27235,
1075,
755,
272,
2086,
12,
4668,
12,
15766,
199,
25571,
13272,
2160,
14821,
2086,
12,
5528,
199,
25571,
13272,
8819,
23855,
2086,
12,
5528,
199,
15465,
57,
9839,
1311,
27235,
1075,
263,
272,
5225,
89,
12,
3114,
12,
574,
199,
15465,
57,
34,
1761,
27235,
1075,
14821,
5225,
89,
12,
330,
452,
12,
4668,
199,
15465,
57,
40,
619,
27235,
1075,
420,
272,
5225,
89,
12,
394,
292,
12,
574,
199,
15465,
57,
13272,
2160,
3515,
272,
5225,
89,
12,
5528,
199,
15465,
57,
13272,
8819,
263,
272,
5225,
89,
12,
5528,
199,
5437,
37,
726,
654,
11025,
3515,
272,
1568,
12,
336,
12,
394,
199,
20142,
1438,
3064,
3515,
272,
334,
3592,
9,
199,
3791,
8193,
3322,
272,
1233,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
504,
1331,
492,
1331,
199,
3,
504,
5577,
492,
627,
221,
327,
66,
23196,
199,
199,
504,
14314,
492,
627,
199,
646,
9193,
14,
1095,
199,
646,
9193,
14,
9350,
199,
646,
9193,
14,
2918,
199,
199,
318,
31741,
837,
272,
1449,
607,
1203,
1183,
2112,
9193,
1566,
8297,
14,
339,
2104,
1924,
2787,
402,
2195,
9219,
12,
1265,
911,
1929,
370,
1852,
2005,
4069,
402,
1240,
370,
272,
314,
1566,
4126,
14,
961,
15620,
2195,
2240,
883,
14448,
17232,
543,
272,
314,
4618,
402,
314,
17406,
2656,
14,
982,
1265,
787,
440,
1808,
1163,
1566,
272,
3423,
315,
2195,
9219,
12,
1265,
1077,
1240,
9193,
14,
1430,
14,
29547,
342,
370,
2040,
272,
9193,
370,
2429,
5007,
5445,
14,
339,
961,
805,
365,
440,
5784,
340,
2195,
2240,
365,
12137,
590,
6661,
272,
4474,
641,
314,
4126,
4012,
314,
1163,
9193,
14,
1430,
3423,
14,
489,
272,
6006,
787,
11012,
7645,
626,
1471,
506,
477,
4478,
543,
14448,
315,
314,
1566,
272,
4126,
14,
710,
2446,
4353,
1443,
1929,
370,
506,
295,
387,
9082,
503,
22722,
370,
314,
2656,
14,
272,
982,
1265,
2449,
370,
1852,
282,
1240,
370,
314,
1566,
4126,
367,
4634,
1846,
12,
314,
2656,
1443,
272,
19822,
2195,
2240,
965,
14233,
1536,
14,
272,
1449,
272,
9193,
14,
2918,
423,
3722,
63,
826,
63,
1074,
342,
272,
14314,
63,
48,
1220,
11770,
342,
199,
199,
318,
664,
8,
466,
513,
29,
403,
304,
272,
1449,
1002,
4474,
687,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
radicalbit/ambari
|
ambari-server/src/main/resources/stacks/HDP/2.0.6.GlusterFS/services/YARN/package/scripts/params.py
|
1
|
6959
|
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Ambari Agent
"""
from resource_management import *
import status_params
# server configurations
config = Script.get_config()
tmp_dir = Script.get_tmp_dir()
config_dir = "/etc/hadoop/conf"
mapred_user = status_params.mapred_user
yarn_user = status_params.yarn_user
hdfs_user = config['configurations']['hadoop-env']['hdfs_user']
smokeuser = config['configurations']['cluster-env']['smokeuser']
security_enabled = config['configurations']['cluster-env']['security_enabled']
smoke_user_keytab = config['configurations']['cluster-env']['smokeuser_keytab']
yarn_executor_container_group = config['configurations']['yarn-site']['yarn.nodemanager.linux-container-executor.group']
kinit_path_local = functions.get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
rm_hosts = config['clusterHostInfo']['rm_host']
rm_host = rm_hosts[0]
rm_port = config['configurations']['yarn-site']['yarn.resourcemanager.webapp.address'].split(':')[-1]
rm_https_port = "8090"
rm_nodes_exclude_path = config['configurations']['yarn-site']['yarn.resourcemanager.nodes.exclude-path']
java64_home = config['hostLevelParams']['java_home']
hadoop_ssl_enabled = default("/configurations/core-site/hadoop.ssl.enabled", False)
hadoop_libexec_dir = '/usr/lib/hadoop/libexec'
hadoop_yarn_home = '/usr/lib/hadoop-yarn'
yarn_heapsize = config['configurations']['yarn-env']['yarn_heapsize']
resourcemanager_heapsize = config['configurations']['yarn-env']['resourcemanager_heapsize']
nodemanager_heapsize = config['configurations']['yarn-env']['nodemanager_heapsize']
apptimelineserver_heapsize = default("/configurations/yarn-env/apptimelineserver_heapsize", 1024)
ats_leveldb_dir = config['configurations']['yarn-site']['yarn.timeline-service.leveldb-timeline-store.path']
yarn_log_dir_prefix = config['configurations']['yarn-env']['yarn_log_dir_prefix']
yarn_pid_dir_prefix = status_params.yarn_pid_dir_prefix
mapred_pid_dir_prefix = status_params.mapred_pid_dir_prefix
mapred_log_dir_prefix = config['configurations']['mapred-env']['mapred_log_dir_prefix']
mapred_env_sh_template = config['configurations']['mapred-env']['content']
yarn_env_sh_template = config['configurations']['yarn-env']['content']
if len(rm_hosts) > 1:
additional_rm_host = rm_hosts[1]
rm_webui_address = format("{rm_host}:{rm_port},{additional_rm_host}:{rm_port}")
rm_webui_https_address = format("{rm_host}:{rm_https_port},{additional_rm_host}:{rm_https_port}")
else:
rm_webui_address = format("{rm_host}:{rm_port}")
rm_webui_https_address = format("{rm_host}:{rm_https_port}")
nm_webui_address = config['configurations']['yarn-site']['yarn.nodemanager.webapp.address']
hs_webui_address = config['configurations']['mapred-site']['mapreduce.jobhistory.webapp.address']
nm_local_dirs = config['configurations']['yarn-site']['yarn.nodemanager.local-dirs']
nm_log_dirs = config['configurations']['yarn-site']['yarn.nodemanager.log-dirs']
hadoop_mapred2_jar_location = "/usr/lib/hadoop-mapreduce"
distrAppJarName = "hadoop-yarn-applications-distributedshell-2.*.jar"
hadoopMapredExamplesJarName = "hadoop-mapreduce-examples-2.*.jar"
yarn_pid_dir = status_params.yarn_pid_dir
mapred_pid_dir = status_params.mapred_pid_dir
mapred_log_dir = format("{mapred_log_dir_prefix}/{mapred_user}")
yarn_log_dir = format("{yarn_log_dir_prefix}/{yarn_user}")
mapred_job_summary_log = format("{mapred_log_dir_prefix}/{mapred_user}/hadoop-mapreduce.jobsummary.log")
yarn_job_summary_log = format("{yarn_log_dir_prefix}/{yarn_user}/hadoop-mapreduce.jobsummary.log")
mapred_bin = "/usr/lib/hadoop-mapreduce/sbin"
yarn_bin = "/usr/lib/hadoop-yarn/sbin"
user_group = config['configurations']['cluster-env']['user_group']
limits_conf_dir = "/etc/security/limits.d"
hadoop_conf_dir = "/etc/hadoop/conf"
yarn_container_bin = "/usr/lib/hadoop-yarn/bin"
#exclude file
exclude_hosts = default("/clusterHostInfo/decom_nm_hosts", [])
exclude_file_path = config['configurations']['yarn-site']['yarn.resourcemanager.nodes.exclude-path']
nm_hosts = default("/clusterHostInfo/nm_hosts", [])
#incude file
include_file_path = default("/configurations/yarn-site/yarn.resourcemanager.nodes.include-path", None)
include_hosts = None
manage_include_files = default("/configurations/yarn-site/manage.include.files", False)
if include_file_path and manage_include_files:
include_hosts = list(set(nm_hosts) - set(exclude_hosts))
hostname = config['hostname']
if security_enabled:
nm_principal_name = config['configurations']['yarn-site']['nodemanager_principal_name']
nodemanager_keytab = config['configurations']['yarn-site']['nodemanager_keytab']
nodemanager_principal_name = nm_principal_name.replace('_HOST',hostname.lower())
nm_kinit_cmd = format("{kinit_path_local} -kt {nodemanager_keytab} {nodemanager_principal_name};")
else:
nm_kinit_cmd = ""
yarn_log_aggregation_enabled = config['configurations']['yarn-site']['yarn.log-aggregation-enable']
yarn_nm_app_log_dir = config['configurations']['yarn-site']['yarn.nodemanager.remote-app-log-dir']
mapreduce_jobhistory_intermediate_done_dir = config['configurations']['mapred-site']['mapreduce.jobhistory.intermediate-done-dir']
mapreduce_jobhistory_done_dir = config['configurations']['mapred-site']['mapreduce.jobhistory.done-dir']
#for create_hdfs_directory
hostname = config["hostname"]
hdfs_user_keytab = config['configurations']['hadoop-env']['hdfs_user_keytab']
import functools
#create partial functions with common arguments for every HdfsDirectory call
#to create hdfs directory we need to call params.HdfsDirectory in code
HdfsDirectory = functools.partial(
HdfsDirectory,
conf_dir=hadoop_conf_dir,
hdfs_user=hdfs_user,
security_enabled = security_enabled,
keytab = hdfs_user_keytab,
kinit_path_local = kinit_path_local
)
update_files_only = default("/commandParams/update_files_only", False)
hadoop_bin = "/usr/lib/hadoop/sbin"
mapred_tt_group = default("/configurations/mapred-site/mapreduce.tasktracker.group", user_group)
#taskcontroller.cfg
mapred_local_dir = "/tmp/hadoop-mapred/mapred/local"
hdfs_log_dir_prefix = config['configurations']['hadoop-env']['hdfs_log_dir_prefix']
min_user_id = config['configurations']['yarn-env']['min_user_id']
|
apache-2.0
|
[
624,
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
29209,
759,
19866,
199,
199,
624,
199,
199,
504,
2073,
63,
8110,
492,
627,
199,
646,
2004,
63,
1162,
199,
199,
3,
1654,
13422,
199,
888,
275,
14914,
14,
362,
63,
888,
342,
199,
2791,
63,
694,
275,
14914,
14,
362,
63,
2791,
63,
694,
342,
199,
199,
888,
63,
694,
275,
3286,
6839,
15,
15449,
15,
2190,
2,
199,
199,
1130,
581,
63,
751,
275,
2004,
63,
1162,
14,
1130,
581,
63,
751,
199,
89,
1060,
63,
751,
275,
2004,
63,
1162,
14,
89,
1060,
63,
751,
199,
19055,
63,
751,
275,
1101,
459,
10057,
2545,
15449,
13,
1813,
2545,
19055,
63,
751,
418,
199,
199,
30697,
751,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
30697,
751,
418,
199,
4416,
63,
3827,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
4416,
63,
3827,
418,
199,
30697,
63,
751,
63,
498,
2902,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
30697,
751,
63,
498,
2902,
418,
199,
89,
1060,
63,
13471,
63,
3600,
63,
923,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
932,
2609,
14,
5135,
13,
3600,
13,
13471,
14,
923,
418,
199,
75,
826,
63,
515,
63,
1832,
275,
3423,
14,
362,
63,
75,
826,
63,
515,
8,
885,
2336,
10057,
15,
2570,
23920,
13,
1813,
15,
5904,
63,
1733,
63,
3771,
297,
488,
430,
199,
5682,
63,
5146,
275,
1101,
459,
4201,
4965,
2354,
2545,
5682,
63,
1102,
418,
199,
5682,
63,
1102,
275,
14267,
63,
5146,
59,
16,
61,
199,
5682,
63,
719,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
1927,
2609,
14,
22632,
14,
1562,
2278,
1294,
32694,
17,
61,
199,
5682,
63,
2859,
63,
719,
275,
298,
1257,
2710,
2,
199,
5682,
63,
2415,
63,
5473,
63,
515,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
1927,
2609,
14,
2415,
14,
5473,
13,
515,
418,
199,
199,
6138,
772,
63,
4219,
275,
1101,
459,
1102,
4670,
6007,
2545,
6138,
63,
4219,
418,
199,
15449,
63,
4266,
63,
3827,
275,
849,
4769,
10057,
15,
1018,
13,
2124,
15,
15449,
14,
4266,
14,
3827,
401,
756,
9,
199,
199,
15449,
63,
773,
1628,
63,
694,
275,
1994,
2647,
15,
773,
15,
15449,
15,
773,
1628,
7,
199,
15449,
63,
89,
1060,
63,
4219,
275,
1994,
2647,
15,
773,
15,
15449,
13,
89,
1060,
7,
199,
89,
1060,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
89,
1060,
63,
12492,
890,
418,
199,
1927,
2609,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
1927,
2609,
63,
12492,
890,
418,
199,
932,
2609,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
932,
2609,
63,
12492,
890,
418,
199,
571,
19369,
1000,
63,
12492,
890,
275,
849,
4769,
10057,
15,
89,
1060,
13,
1813,
15,
571,
19369,
1000,
63,
12492,
890,
401,
6619,
9,
199,
1956,
63,
6972,
457,
66,
63,
694,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
19369,
13,
1364,
14,
6972,
457,
66,
13,
19369,
13,
1617,
14,
515,
418,
199,
89,
1060,
63,
793,
63,
694,
63,
1861,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
89,
1060,
63,
793,
63,
694,
63,
1861,
418,
199,
89,
1060,
63,
3150,
63,
694,
63,
1861,
275,
2004,
63,
1162,
14,
89,
1060,
63,
3150,
63,
694,
63,
1861,
199,
1130,
581,
63,
3150,
63,
694,
63,
1861,
275,
2004,
63,
1162,
14,
1130,
581,
63,
3150,
63,
694,
63,
1861,
199,
1130,
581,
63,
793,
63,
694,
63,
1861,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
1813,
2545,
1130,
581,
63,
793,
63,
694,
63,
1861,
418,
199,
1130,
581,
63,
1813,
63,
609,
63,
1160,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
1813,
2545,
1317,
418,
199,
89,
1060,
63,
1813,
63,
609,
63,
1160,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
1317,
418,
199,
199,
692,
822,
8,
5682,
63,
5146,
9,
690,
413,
26,
523,
4722,
63,
5682,
63,
1102,
275,
14267,
63,
5146,
59,
17,
61,
523,
14267,
63,
31991,
73,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
719,
31016,
8460,
63,
5682,
63,
1102,
16495,
5682,
63,
719,
15412,
523,
14267,
63,
31991,
73,
63,
2859,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
31016,
8460,
63,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
15412,
199,
2836,
26,
523,
14267,
63,
31991,
73,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
719,
15412,
523,
14267,
63,
31991,
73,
63,
2859,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
15412,
199,
199,
10756,
63,
31991,
73,
63,
1562,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
932,
2609,
14,
22632,
14,
1562,
418,
199,
4213,
63,
31991,
73,
63,
1562,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
2124,
2545,
28658,
14,
2423,
5570,
14,
22632,
14,
1562,
418,
199,
199,
10756,
63,
1832
] |
[
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
29209,
759,
19866,
199,
199,
624,
199,
199,
504,
2073,
63,
8110,
492,
627,
199,
646,
2004,
63,
1162,
199,
199,
3,
1654,
13422,
199,
888,
275,
14914,
14,
362,
63,
888,
342,
199,
2791,
63,
694,
275,
14914,
14,
362,
63,
2791,
63,
694,
342,
199,
199,
888,
63,
694,
275,
3286,
6839,
15,
15449,
15,
2190,
2,
199,
199,
1130,
581,
63,
751,
275,
2004,
63,
1162,
14,
1130,
581,
63,
751,
199,
89,
1060,
63,
751,
275,
2004,
63,
1162,
14,
89,
1060,
63,
751,
199,
19055,
63,
751,
275,
1101,
459,
10057,
2545,
15449,
13,
1813,
2545,
19055,
63,
751,
418,
199,
199,
30697,
751,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
30697,
751,
418,
199,
4416,
63,
3827,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
4416,
63,
3827,
418,
199,
30697,
63,
751,
63,
498,
2902,
275,
1101,
459,
10057,
2545,
4201,
13,
1813,
2545,
30697,
751,
63,
498,
2902,
418,
199,
89,
1060,
63,
13471,
63,
3600,
63,
923,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
932,
2609,
14,
5135,
13,
3600,
13,
13471,
14,
923,
418,
199,
75,
826,
63,
515,
63,
1832,
275,
3423,
14,
362,
63,
75,
826,
63,
515,
8,
885,
2336,
10057,
15,
2570,
23920,
13,
1813,
15,
5904,
63,
1733,
63,
3771,
297,
488,
430,
199,
5682,
63,
5146,
275,
1101,
459,
4201,
4965,
2354,
2545,
5682,
63,
1102,
418,
199,
5682,
63,
1102,
275,
14267,
63,
5146,
59,
16,
61,
199,
5682,
63,
719,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
1927,
2609,
14,
22632,
14,
1562,
2278,
1294,
32694,
17,
61,
199,
5682,
63,
2859,
63,
719,
275,
298,
1257,
2710,
2,
199,
5682,
63,
2415,
63,
5473,
63,
515,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
1927,
2609,
14,
2415,
14,
5473,
13,
515,
418,
199,
199,
6138,
772,
63,
4219,
275,
1101,
459,
1102,
4670,
6007,
2545,
6138,
63,
4219,
418,
199,
15449,
63,
4266,
63,
3827,
275,
849,
4769,
10057,
15,
1018,
13,
2124,
15,
15449,
14,
4266,
14,
3827,
401,
756,
9,
199,
199,
15449,
63,
773,
1628,
63,
694,
275,
1994,
2647,
15,
773,
15,
15449,
15,
773,
1628,
7,
199,
15449,
63,
89,
1060,
63,
4219,
275,
1994,
2647,
15,
773,
15,
15449,
13,
89,
1060,
7,
199,
89,
1060,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
89,
1060,
63,
12492,
890,
418,
199,
1927,
2609,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
1927,
2609,
63,
12492,
890,
418,
199,
932,
2609,
63,
12492,
890,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
932,
2609,
63,
12492,
890,
418,
199,
571,
19369,
1000,
63,
12492,
890,
275,
849,
4769,
10057,
15,
89,
1060,
13,
1813,
15,
571,
19369,
1000,
63,
12492,
890,
401,
6619,
9,
199,
1956,
63,
6972,
457,
66,
63,
694,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
19369,
13,
1364,
14,
6972,
457,
66,
13,
19369,
13,
1617,
14,
515,
418,
199,
89,
1060,
63,
793,
63,
694,
63,
1861,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
89,
1060,
63,
793,
63,
694,
63,
1861,
418,
199,
89,
1060,
63,
3150,
63,
694,
63,
1861,
275,
2004,
63,
1162,
14,
89,
1060,
63,
3150,
63,
694,
63,
1861,
199,
1130,
581,
63,
3150,
63,
694,
63,
1861,
275,
2004,
63,
1162,
14,
1130,
581,
63,
3150,
63,
694,
63,
1861,
199,
1130,
581,
63,
793,
63,
694,
63,
1861,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
1813,
2545,
1130,
581,
63,
793,
63,
694,
63,
1861,
418,
199,
1130,
581,
63,
1813,
63,
609,
63,
1160,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
1813,
2545,
1317,
418,
199,
89,
1060,
63,
1813,
63,
609,
63,
1160,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
1813,
2545,
1317,
418,
199,
199,
692,
822,
8,
5682,
63,
5146,
9,
690,
413,
26,
523,
4722,
63,
5682,
63,
1102,
275,
14267,
63,
5146,
59,
17,
61,
523,
14267,
63,
31991,
73,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
719,
31016,
8460,
63,
5682,
63,
1102,
16495,
5682,
63,
719,
15412,
523,
14267,
63,
31991,
73,
63,
2859,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
31016,
8460,
63,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
15412,
199,
2836,
26,
523,
14267,
63,
31991,
73,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
719,
15412,
523,
14267,
63,
31991,
73,
63,
2859,
63,
1562,
275,
1475,
13076,
5682,
63,
1102,
16495,
5682,
63,
2859,
63,
719,
15412,
199,
199,
10756,
63,
31991,
73,
63,
1562,
275,
1101,
459,
10057,
2545,
89,
1060,
13,
2124,
2545,
89,
1060,
14,
932,
2609,
14,
22632,
14,
1562,
418,
199,
4213,
63,
31991,
73,
63,
1562,
275,
1101,
459,
10057,
2545,
1130,
581,
13,
2124,
2545,
28658,
14,
2423,
5570,
14,
22632,
14,
1562,
418,
199,
199,
10756,
63,
1832,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Jeff-Tian/mybnb
|
Python27/Lib/test/buffer_tests.py
|
12
|
10782
|
# Tests that work for both bytes and buffer objects.
# See PEP 3137.
import struct
import sys
class MixinBytesBufferCommonTests(object):
"""Tests that work for both bytes and buffer objects.
See PEP 3137.
"""
def marshal(self, x):
"""Convert x into the appropriate type for these tests."""
raise RuntimeError('test class must provide a marshal method')
def test_islower(self):
self.assertFalse(self.marshal(b'').islower())
self.assertTrue(self.marshal(b'a').islower())
self.assertFalse(self.marshal(b'A').islower())
self.assertFalse(self.marshal(b'\n').islower())
self.assertTrue(self.marshal(b'abc').islower())
self.assertFalse(self.marshal(b'aBc').islower())
self.assertTrue(self.marshal(b'abc\n').islower())
self.assertRaises(TypeError, self.marshal(b'abc').islower, 42)
def test_isupper(self):
self.assertFalse(self.marshal(b'').isupper())
self.assertFalse(self.marshal(b'a').isupper())
self.assertTrue(self.marshal(b'A').isupper())
self.assertFalse(self.marshal(b'\n').isupper())
self.assertTrue(self.marshal(b'ABC').isupper())
self.assertFalse(self.marshal(b'AbC').isupper())
self.assertTrue(self.marshal(b'ABC\n').isupper())
self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42)
def test_istitle(self):
self.assertFalse(self.marshal(b'').istitle())
self.assertFalse(self.marshal(b'a').istitle())
self.assertTrue(self.marshal(b'A').istitle())
self.assertFalse(self.marshal(b'\n').istitle())
self.assertTrue(self.marshal(b'A Titlecased Line').istitle())
self.assertTrue(self.marshal(b'A\nTitlecased Line').istitle())
self.assertTrue(self.marshal(b'A Titlecased, Line').istitle())
self.assertFalse(self.marshal(b'Not a capitalized String').istitle())
self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle())
self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle())
self.assertFalse(self.marshal(b'NOT').istitle())
self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42)
def test_isspace(self):
self.assertFalse(self.marshal(b'').isspace())
self.assertFalse(self.marshal(b'a').isspace())
self.assertTrue(self.marshal(b' ').isspace())
self.assertTrue(self.marshal(b'\t').isspace())
self.assertTrue(self.marshal(b'\r').isspace())
self.assertTrue(self.marshal(b'\n').isspace())
self.assertTrue(self.marshal(b' \t\r\n').isspace())
self.assertFalse(self.marshal(b' \t\r\na').isspace())
self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42)
def test_isalpha(self):
self.assertFalse(self.marshal(b'').isalpha())
self.assertTrue(self.marshal(b'a').isalpha())
self.assertTrue(self.marshal(b'A').isalpha())
self.assertFalse(self.marshal(b'\n').isalpha())
self.assertTrue(self.marshal(b'abc').isalpha())
self.assertFalse(self.marshal(b'aBc123').isalpha())
self.assertFalse(self.marshal(b'abc\n').isalpha())
self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42)
def test_isalnum(self):
self.assertFalse(self.marshal(b'').isalnum())
self.assertTrue(self.marshal(b'a').isalnum())
self.assertTrue(self.marshal(b'A').isalnum())
self.assertFalse(self.marshal(b'\n').isalnum())
self.assertTrue(self.marshal(b'123abc456').isalnum())
self.assertTrue(self.marshal(b'a1b3c').isalnum())
self.assertFalse(self.marshal(b'aBc000 ').isalnum())
self.assertFalse(self.marshal(b'abc\n').isalnum())
self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42)
def test_isdigit(self):
self.assertFalse(self.marshal(b'').isdigit())
self.assertFalse(self.marshal(b'a').isdigit())
self.assertTrue(self.marshal(b'0').isdigit())
self.assertTrue(self.marshal(b'0123456789').isdigit())
self.assertFalse(self.marshal(b'0123456789a').isdigit())
self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42)
def test_lower(self):
self.assertEqual(b'hello', self.marshal(b'HeLLo').lower())
self.assertEqual(b'hello', self.marshal(b'hello').lower())
self.assertRaises(TypeError, self.marshal(b'hello').lower, 42)
def test_upper(self):
self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper())
self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper())
self.assertRaises(TypeError, self.marshal(b'hello').upper, 42)
def test_capitalize(self):
self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize())
self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize())
self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize())
self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize())
self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize())
self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42)
def test_ljust(self):
self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10))
self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6))
self.assertEqual(b'abc', self.marshal(b'abc').ljust(3))
self.assertEqual(b'abc', self.marshal(b'abc').ljust(2))
self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').ljust)
def test_rjust(self):
self.assertEqual(b' abc', self.marshal(b'abc').rjust(10))
self.assertEqual(b' abc', self.marshal(b'abc').rjust(6))
self.assertEqual(b'abc', self.marshal(b'abc').rjust(3))
self.assertEqual(b'abc', self.marshal(b'abc').rjust(2))
self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').rjust)
def test_center(self):
self.assertEqual(b' abc ', self.marshal(b'abc').center(10))
self.assertEqual(b' abc ', self.marshal(b'abc').center(6))
self.assertEqual(b'abc', self.marshal(b'abc').center(3))
self.assertEqual(b'abc', self.marshal(b'abc').center(2))
self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').center)
def test_swapcase(self):
self.assertEqual(b'hEllO CoMPuTErS',
self.marshal(b'HeLLo cOmpUteRs').swapcase())
self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42)
def test_zfill(self):
self.assertEqual(b'123', self.marshal(b'123').zfill(2))
self.assertEqual(b'123', self.marshal(b'123').zfill(3))
self.assertEqual(b'0123', self.marshal(b'123').zfill(4))
self.assertEqual(b'+123', self.marshal(b'+123').zfill(3))
self.assertEqual(b'+123', self.marshal(b'+123').zfill(4))
self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5))
self.assertEqual(b'-123', self.marshal(b'-123').zfill(3))
self.assertEqual(b'-123', self.marshal(b'-123').zfill(4))
self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5))
self.assertEqual(b'000', self.marshal(b'').zfill(3))
self.assertEqual(b'34', self.marshal(b'34').zfill(1))
self.assertEqual(b'0034', self.marshal(b'34').zfill(4))
self.assertRaises(TypeError, self.marshal(b'123').zfill)
def test_expandtabs(self):
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4))
self.assertEqual(b'abc\r\nab def\ng hi',
self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4))
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi',
self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4))
self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1))
self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)
# This test is only valid when sizeof(int) == sizeof(void*) == 4.
if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
self.assertRaises(OverflowError,
self.marshal(b'\ta\n\tb').expandtabs, sys.maxint)
def test_title(self):
self.assertEqual(b' Hello ', self.marshal(b' hello ').title())
self.assertEqual(b'Hello ', self.marshal(b'hello ').title())
self.assertEqual(b'Hello ', self.marshal(b'Hello ').title())
self.assertEqual(b'Format This As Title String',
self.marshal(b'fOrMaT thIs aS titLe String').title())
self.assertEqual(b'Format,This-As*Title;String',
self.marshal(b'fOrMaT,thIs-aS*titLe;String').title())
self.assertEqual(b'Getint', self.marshal(b'getInt').title())
self.assertRaises(TypeError, self.marshal(b'hello').title, 42)
def test_splitlines(self):
self.assertEqual([b'abc', b'def', b'', b'ghi'],
self.marshal(b'abc\ndef\n\rghi').splitlines())
self.assertEqual([b'abc', b'def', b'', b'ghi'],
self.marshal(b'abc\ndef\n\r\nghi').splitlines())
self.assertEqual([b'abc', b'def', b'ghi'],
self.marshal(b'abc\ndef\r\nghi').splitlines())
self.assertEqual([b'abc', b'def', b'ghi'],
self.marshal(b'abc\ndef\r\nghi\n').splitlines())
self.assertEqual([b'abc', b'def', b'ghi', b''],
self.marshal(b'abc\ndef\r\nghi\n\r').splitlines())
self.assertEqual([b'', b'abc', b'def', b'ghi', b''],
self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines())
self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'],
self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(1))
self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42)
|
apache-2.0
|
[
3,
6496,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
202,
199,
3,
1666,
13663,
650,
7498,
14,
2999,
199,
646,
2702,
202,
199,
646,
984,
2999,
199,
533,
28438,
5571,
3299,
7844,
2925,
8,
785,
304,
1128,
408,
2925,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
1128,
1666,
13663,
650,
7498,
14,
1128,
408,
2958,
347,
21985,
8,
277,
12,
671,
304,
1039,
408,
7306,
671,
1901,
314,
5827,
730,
367,
3520,
2295,
1041,
1039,
746,
6064,
360,
396,
1021,
1471,
5647,
282,
21985,
1083,
358,
2958,
347,
511,
63,
374,
2325,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
2325,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
12,
5685,
9,
2958,
347,
511,
63,
374,
4142,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
8390,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
5583,
35,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
8390,
60,
78,
1959,
374,
4142,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4142,
12,
5685,
9,
2958,
347,
511,
63,
631,
5776,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
60,
78,
6888,
32738,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
12,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
282,
17094,
1759,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
60,
502,
16881,
2546,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
306,
65,
16881,
2546,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
4609,
1959,
631,
5776,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
631,
5776,
12,
5685,
9,
2958,
347,
511,
63,
23360,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
23360,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
27274,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
84,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
82,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
78,
1959,
23360,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
3540,
1959,
23360,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
23360,
12,
5685,
9,
2958,
347,
511,
63,
374,
4468,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
4288,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
4468,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
12,
5685,
9,
2958,
347,
511,
63,
28235,
1507,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
28235,
1507,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
4288,
3175,
11419,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
17,
66,
19,
67,
1959,
28235,
1507,
1012,
1039,
291,
14,
3334,
8,
277,
14
] |
[
6496,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
202,
199,
3,
1666,
13663,
650,
7498,
14,
2999,
199,
646,
2702,
202,
199,
646,
984,
2999,
199,
533,
28438,
5571,
3299,
7844,
2925,
8,
785,
304,
1128,
408,
2925,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
1128,
1666,
13663,
650,
7498,
14,
1128,
408,
2958,
347,
21985,
8,
277,
12,
671,
304,
1039,
408,
7306,
671,
1901,
314,
5827,
730,
367,
3520,
2295,
1041,
1039,
746,
6064,
360,
396,
1021,
1471,
5647,
282,
21985,
1083,
358,
2958,
347,
511,
63,
374,
2325,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
1959,
374,
2325,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
2325,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
12,
5685,
9,
2958,
347,
511,
63,
374,
4142,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
8390,
1959,
374,
4142,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
5583,
35,
1959,
374,
4142,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
8390,
60,
78,
1959,
374,
4142,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4142,
12,
5685,
9,
2958,
347,
511,
63,
631,
5776,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
60,
78,
6888,
32738,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
12,
7030,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
282,
17094,
1759,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
60,
502,
16881,
2546,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
306,
65,
16881,
2546,
2624,
1959,
631,
5776,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
4609,
1959,
631,
5776,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
631,
5776,
12,
5685,
9,
2958,
347,
511,
63,
23360,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
23360,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
27274,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
84,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
82,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
23360,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
78,
1959,
23360,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
3540,
1959,
23360,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
23360,
12,
5685,
9,
2958,
347,
511,
63,
374,
4468,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4468,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
4288,
1959,
374,
4468,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
4468,
1012,
1039,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
12,
5685,
9,
2958,
347,
511,
63,
28235,
1507,
8,
277,
304,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
28235,
1507,
1012,
1039,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
4288,
3175,
11419,
1959,
28235,
1507,
1012,
1039,
291,
14,
1815,
8,
277,
14,
18376,
8,
66,
7,
65,
17,
66,
19,
67,
1959,
28235,
1507,
1012,
1039,
291,
14,
3334,
8,
277,
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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# Portions (c) Copyright 1999 by Dragon Systems, Inc.
#
# This sample macro file was created for my talk to the Boston Voice Users
# group on November 9, 1999. It is explained in my PowerPoint slides.
#
# natspeak_sample6.py
#
# This macro file demonstrates how to write application specific code. We
# define two commands. "demo sample six" can only be spoken to the NatSpeak
# main window. "demo sample six font" can only be spoken to the NatSpeak
# font dialog. We make the second command exclusive so that all other
# commands are disabled when thefont dialog is active.
#
import natlink
from natlinkutils import *
class ThisGrammar(GrammarBase):
gramSpec = """
<mainRule> exported = demo sample six [ main ];
<fontRule> exported = demo sample six font;
"""
def gotBegin(self,moduleInfo):
windowId = matchWindow(moduleInfo,'natspeak','Dragon')
if windowId:
self.activate('mainRule',window=windowId,noError=1)
windowId = matchWindow(moduleInfo,'natspeak','Font')
if windowId:
self.activate('fontRule',exclusive=1,noError=1)
else:
self.deactivate('fontRule',noError=1)
self.setExclusive(0)
def initialize(self):
self.load(self.gramSpec)
def gotResults_mainRule(self,words,fullResults):
natlink.playString('Saw <mainRule>')
def gotResults_fontRule(self,words,fullResults):
natlink.playString('Saw <fontRule>')
thisGrammar = ThisGrammar()
thisGrammar.initialize()
def unload():
global thisGrammar
if thisGrammar: thisGrammar.unload()
thisGrammar = None
|
mit
|
[
3,
199,
3,
2018,
10444,
293,
8466,
367,
577,
2527,
265,
653,
292,
300,
1183,
51,
8556,
316,
199,
3,
257,
334,
67,
9,
1898,
21300,
701,
7135,
352,
598,
3857,
199,
3,
257,
20825,
334,
67,
9,
1898,
21300,
701,
577,
2527,
265,
15285,
12,
3277,
14,
199,
3,
199,
3,
961,
2690,
9559,
570,
1990,
2737,
367,
3002,
22811,
370,
314,
8226,
32665,
1885,
20123,
199,
3,
1572,
641,
3091,
432,
976,
1749,
12,
21300,
14,
221,
2779,
365,
1437,
23918,
315,
3002,
18879,
3428,
27498,
3424,
14,
199,
3,
199,
3,
302,
1956,
8556,
63,
3271,
22,
14,
647,
199,
3,
199,
3,
961,
9559,
570,
23789,
31216,
4212,
370,
2218,
4223,
2488,
1233,
14,
221,
2136,
199,
3,
5627,
2877,
3718,
14,
221,
298,
8768,
2690,
3816,
2,
883,
1454,
506,
25664,
917,
370,
314,
653,
292,
51,
8556,
199,
3,
2446,
4353,
14,
221,
298,
8768,
2690,
3816,
5023,
2,
883,
1454,
506,
25664,
917,
370,
314,
653,
292,
51,
8556,
199,
3,
5023,
9592,
14,
221,
2136,
1852,
314,
3499,
1414,
13914,
880,
626,
1006,
1163,
199,
3,
3718,
787,
6980,
1380,
314,
4246,
9592,
365,
4702,
14,
199,
3,
199,
199,
646,
13872,
1073,
199,
504,
13872,
1073,
1208,
492,
627,
199,
199,
533,
961,
27119,
8,
27119,
1563,
304,
339,
1999,
77,
5307,
275,
408,
267,
665,
973,
5065,
30,
16629,
275,
14779,
2690,
3816,
359,
2446,
1622,
27,
267,
665,
4246,
5065,
30,
16629,
275,
14779,
2690,
3816,
5023,
27,
272,
408,
339,
347,
4788,
5595,
8,
277,
12,
578,
2354,
304,
267,
4353,
1304,
275,
1336,
4301,
8,
578,
2354,
2584,
78,
1956,
8556,
1673,
20287,
265,
358,
267,
340,
4353,
1304,
26,
288,
291,
14,
8222,
360,
973,
5065,
297,
3806,
29,
3806,
1304,
12,
889,
547,
29,
17,
9,
267,
4353,
1304,
275,
1336,
4301,
8,
578,
2354,
2584,
78,
1956,
8556,
1673,
6986,
358,
267,
340,
4353,
1304,
26,
288,
291,
14,
8222,
360,
4246,
5065,
297,
12730,
29,
17,
12,
889,
547,
29,
17,
9,
267,
587,
26,
288,
291,
14,
24891,
360,
4246,
5065,
297,
889,
547,
29,
17,
9,
288,
291,
14,
409,
26281,
8,
16,
9,
5493,
347,
8265,
8,
277,
304,
267,
291,
14,
912,
8,
277,
14,
1679,
5307,
9,
339,
347,
4788,
6579,
63,
973,
5065,
8,
277,
12,
3148,
12,
2861,
6579,
304,
267,
13872,
1073,
14,
2802,
1558,
360,
51,
10084,
665,
973,
5065,
5971,
339,
347,
4788,
6579,
63,
4246,
5065,
8,
277,
12,
3148,
12,
2861,
6579,
304,
267,
13872,
1073,
14,
2802,
1558,
360,
51,
10084,
665,
4246,
5065,
5971,
199,
199,
3749,
27119,
275,
961,
27119,
342,
199,
3749,
27119,
14,
8489,
342,
199,
199,
318,
625,
912,
837,
272,
2288,
642,
27119,
272,
340,
642,
27119,
26,
642,
27119,
14,
25477,
342,
272,
642,
27119,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2018,
10444,
293,
8466,
367,
577,
2527,
265,
653,
292,
300,
1183,
51,
8556,
316,
199,
3,
257,
334,
67,
9,
1898,
21300,
701,
7135,
352,
598,
3857,
199,
3,
257,
20825,
334,
67,
9,
1898,
21300,
701,
577,
2527,
265,
15285,
12,
3277,
14,
199,
3,
199,
3,
961,
2690,
9559,
570,
1990,
2737,
367,
3002,
22811,
370,
314,
8226,
32665,
1885,
20123,
199,
3,
1572,
641,
3091,
432,
976,
1749,
12,
21300,
14,
221,
2779,
365,
1437,
23918,
315,
3002,
18879,
3428,
27498,
3424,
14,
199,
3,
199,
3,
302,
1956,
8556,
63,
3271,
22,
14,
647,
199,
3,
199,
3,
961,
9559,
570,
23789,
31216,
4212,
370,
2218,
4223,
2488,
1233,
14,
221,
2136,
199,
3,
5627,
2877,
3718,
14,
221,
298,
8768,
2690,
3816,
2,
883,
1454,
506,
25664,
917,
370,
314,
653,
292,
51,
8556,
199,
3,
2446,
4353,
14,
221,
298,
8768,
2690,
3816,
5023,
2,
883,
1454,
506,
25664,
917,
370,
314,
653,
292,
51,
8556,
199,
3,
5023,
9592,
14,
221,
2136,
1852,
314,
3499,
1414,
13914,
880,
626,
1006,
1163,
199,
3,
3718,
787,
6980,
1380,
314,
4246,
9592,
365,
4702,
14,
199,
3,
199,
199,
646,
13872,
1073,
199,
504,
13872,
1073,
1208,
492,
627,
199,
199,
533,
961,
27119,
8,
27119,
1563,
304,
339,
1999,
77,
5307,
275,
408,
267,
665,
973,
5065,
30,
16629,
275,
14779,
2690,
3816,
359,
2446,
1622,
27,
267,
665,
4246,
5065,
30,
16629,
275,
14779,
2690,
3816,
5023,
27,
272,
408,
339,
347,
4788,
5595,
8,
277,
12,
578,
2354,
304,
267,
4353,
1304,
275,
1336,
4301,
8,
578,
2354,
2584,
78,
1956,
8556,
1673,
20287,
265,
358,
267,
340,
4353,
1304,
26,
288,
291,
14,
8222,
360,
973,
5065,
297,
3806,
29,
3806,
1304,
12,
889,
547,
29,
17,
9,
267,
4353,
1304,
275,
1336,
4301,
8,
578,
2354,
2584,
78,
1956,
8556,
1673,
6986,
358,
267,
340,
4353,
1304,
26,
288,
291,
14,
8222,
360,
4246,
5065,
297,
12730,
29,
17,
12,
889,
547,
29,
17,
9,
267,
587,
26,
288,
291,
14,
24891,
360,
4246,
5065,
297,
889,
547,
29,
17,
9,
288,
291,
14,
409,
26281,
8,
16,
9,
5493,
347,
8265,
8,
277,
304,
267,
291,
14,
912,
8,
277,
14,
1679,
5307,
9,
339,
347,
4788,
6579,
63,
973,
5065,
8,
277,
12,
3148,
12,
2861,
6579,
304,
267,
13872,
1073,
14,
2802,
1558,
360,
51,
10084,
665,
973,
5065,
5971,
339,
347,
4788,
6579,
63,
4246,
5065,
8,
277,
12,
3148,
12,
2861,
6579,
304,
267,
13872,
1073,
14,
2802,
1558,
360,
51,
10084,
665,
4246,
5065,
5971,
199,
199,
3749,
27119,
275,
961,
27119,
342,
199,
3749,
27119,
14,
8489,
342,
199,
199,
318,
625,
912,
837,
272,
2288,
642,
27119,
272,
340,
642,
27119,
26,
642,
27119,
14,
25477,
342,
272,
642,
27119,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
junbochen/pylearn2
|
pylearn2/config/yaml_parse.py
|
37
|
16430
|
"""Support code for YAML parsing of experiment descriptions."""
import yaml
from pylearn2.utils import serial
from pylearn2.utils.exc import reraise_as
from pylearn2.utils.string_utils import preprocess
from pylearn2.utils.call_check import checked_call
from pylearn2.utils.string_utils import match
from collections import namedtuple
import logging
import warnings
import re
from theano.compat import six
SCIENTIFIC_NOTATION_REGEXP = r'^[\-\+]?(\d+\.?\d*|\d*\.?\d+)?[eE][\-\+]?\d+$'
is_initialized = False
additional_environ = None
logger = logging.getLogger(__name__)
# Lightweight container for initial YAML evaluation.
#
# This is intended as a robust, forward-compatible intermediate representation
# for either internal consumption or external consumption by another tool e.g.
# hyperopt.
#
# We've included a slot for positionals just in case, though they are
# unsupported by the instantiation mechanism as yet.
BaseProxy = namedtuple('BaseProxy', ['callable', 'positionals',
'keywords', 'yaml_src'])
class Proxy(BaseProxy):
"""
An intermediate representation between initial YAML parse and object
instantiation.
Parameters
----------
callable : callable
The function/class to call to instantiate this node.
positionals : iterable
Placeholder for future support for positional arguments (`*args`).
keywords : dict-like
A mapping from keywords to arguments (`**kwargs`), which may be
`Proxy`s or `Proxy`s nested inside `dict` or `list` instances.
Keys must be strings that are valid Python variable names.
yaml_src : str
The YAML source that created this node, if available.
Notes
-----
This is intended as a robust, forward-compatible intermediate
representation for either internal consumption or external consumption
by another tool e.g. hyperopt.
This particular class mainly exists to override `BaseProxy`'s `__hash__`
(to avoid hashing unhashable namedtuple elements).
"""
__slots__ = []
def __hash__(self):
"""
Return a hash based on the object ID (to avoid hashing unhashable
namedtuple elements).
"""
return hash(id(self))
def do_not_recurse(value):
"""
Function symbol used for wrapping an unpickled object (which should
not be recursively expanded). This is recognized and respected by the
instantiation parser. Implementationally, no-op (returns the value
passed in as an argument).
Parameters
----------
value : object
The value to be returned.
Returns
-------
value : object
The same object passed in as an argument.
"""
return value
def _instantiate_proxy_tuple(proxy, bindings=None):
"""
Helper function for `_instantiate` that handles objects of the `Proxy`
class.
Parameters
----------
proxy : Proxy object
A `Proxy` object that.
bindings : dict, opitonal
A dictionary mapping previously instantiated `Proxy` objects
to their instantiated values.
Returns
-------
obj : object
The result object from recursively instantiating the object DAG.
"""
if proxy in bindings:
return bindings[proxy]
else:
# Respect do_not_recurse by just un-packing it (same as calling).
if proxy.callable == do_not_recurse:
obj = proxy.keywords['value']
else:
# TODO: add (requested) support for positionals (needs to be added
# to checked_call also).
if len(proxy.positionals) > 0:
raise NotImplementedError('positional arguments not yet '
'supported in proxy instantiation')
kwargs = dict((k, _instantiate(v, bindings))
for k, v in six.iteritems(proxy.keywords))
obj = checked_call(proxy.callable, kwargs)
try:
obj.yaml_src = proxy.yaml_src
except AttributeError: # Some classes won't allow this.
pass
bindings[proxy] = obj
return bindings[proxy]
def _instantiate(proxy, bindings=None):
"""
Instantiate a (hierarchy of) Proxy object(s).
Parameters
----------
proxy : object
A `Proxy` object or list/dict/literal. Strings are run through
`preprocess`.
bindings : dict, opitonal
A dictionary mapping previously instantiated `Proxy` objects
to their instantiated values.
Returns
-------
obj : object
The result object from recursively instantiating the object DAG.
Notes
-----
This should not be considered part of the stable, public API.
"""
if bindings is None:
bindings = {}
if isinstance(proxy, Proxy):
return _instantiate_proxy_tuple(proxy, bindings)
elif isinstance(proxy, dict):
# Recurse on the keys too, for backward compatibility.
# Is the key instantiation feature ever actually used, by anyone?
return dict((_instantiate(k, bindings), _instantiate(v, bindings))
for k, v in six.iteritems(proxy))
elif isinstance(proxy, list):
return [_instantiate(v, bindings) for v in proxy]
# In the future it might be good to consider a dict argument that provides
# a type->callable mapping for arbitrary transformations like this.
elif isinstance(proxy, six.string_types):
return preprocess(proxy)
else:
return proxy
def load(stream, environ=None, instantiate=True, **kwargs):
"""
Loads a YAML configuration from a string or file-like object.
Parameters
----------
stream : str or object
Either a string containing valid YAML or a file-like object
supporting the .read() interface.
environ : dict, optional
A dictionary used for ${FOO} substitutions in addition to
environment variables. If a key appears both in `os.environ`
and this dictionary, the value in this dictionary is used.
instantiate : bool, optional
If `False`, do not actually instantiate the objects but instead
produce a nested hierarchy of `Proxy` objects.
Returns
-------
graph : dict or object
The dictionary or object (if the top-level element specified
a Python object to instantiate), or a nested hierarchy of
`Proxy` objects.
Notes
-----
Other keyword arguments are passed on to `yaml.load`.
"""
global is_initialized
global additional_environ
if not is_initialized:
initialize()
additional_environ = environ
if isinstance(stream, six.string_types):
string = stream
else:
string = stream.read()
proxy_graph = yaml.load(string, **kwargs)
if instantiate:
return _instantiate(proxy_graph)
else:
return proxy_graph
def load_path(path, environ=None, instantiate=True, **kwargs):
"""
Convenience function for loading a YAML configuration from a file.
Parameters
----------
path : str
The path to the file to load on disk.
environ : dict, optional
A dictionary used for ${FOO} substitutions in addition to
environment variables. If a key appears both in `os.environ`
and this dictionary, the value in this dictionary is used.
instantiate : bool, optional
If `False`, do not actually instantiate the objects but instead
produce a nested hierarchy of `Proxy` objects.
Returns
-------
graph : dict or object
The dictionary or object (if the top-level element specified
a Python object to instantiate), or a nested hierarchy of
`Proxy` objects.
Notes
-----
Other keyword arguments are passed on to `yaml.load`.
"""
with open(path, 'r') as f:
content = ''.join(f.readlines())
# This is apparently here to avoid the odd instance where a file gets
# loaded as Unicode instead (see 03f238c6d). It's rare instance where
# basestring is not the right call.
if not isinstance(content, str):
raise AssertionError("Expected content to be of type str, got " +
str(type(content)))
return load(content, instantiate=instantiate, environ=environ, **kwargs)
def try_to_import(tag_suffix):
"""
.. todo::
WRITEME
"""
components = tag_suffix.split('.')
modulename = '.'.join(components[:-1])
try:
exec('import %s' % modulename)
except ImportError as e:
# We know it's an ImportError, but is it an ImportError related to
# this path,
# or did the module we're importing have an unrelated ImportError?
# and yes, this test can still have false positives, feel free to
# improve it
pieces = modulename.split('.')
str_e = str(e)
found = True in [piece.find(str(e)) != -1 for piece in pieces]
if found:
# The yaml file is probably to blame.
# Report the problem with the full module path from the YAML
# file
reraise_as(ImportError("Could not import %s; ImportError was %s" %
(modulename, str_e)))
else:
pcomponents = components[:-1]
assert len(pcomponents) >= 1
j = 1
while j <= len(pcomponents):
modulename = '.'.join(pcomponents[:j])
try:
exec('import %s' % modulename)
except Exception:
base_msg = 'Could not import %s' % modulename
if j > 1:
modulename = '.'.join(pcomponents[:j - 1])
base_msg += ' but could import %s' % modulename
reraise_as(ImportError(base_msg + '. Original exception: '
+ str(e)))
j += 1
try:
obj = eval(tag_suffix)
except AttributeError as e:
try:
# Try to figure out what the wrong field name was
# If we fail to do it, just fall back to giving the usual
# attribute error
pieces = tag_suffix.split('.')
module = '.'.join(pieces[:-1])
field = pieces[-1]
candidates = dir(eval(module))
msg = ('Could not evaluate %s. ' % tag_suffix +
'Did you mean ' + match(field, candidates) + '? ' +
'Original error was ' + str(e))
except Exception:
warnings.warn("Attempt to decipher AttributeError failed")
reraise_as(AttributeError('Could not evaluate %s. ' % tag_suffix +
'Original error was ' + str(e)))
reraise_as(AttributeError(msg))
return obj
def initialize():
"""
Initialize the configuration system by installing YAML handlers.
Automatically done on first call to load() specified in this file.
"""
global is_initialized
# Add the custom multi-constructor
yaml.add_multi_constructor('!obj:', multi_constructor_obj)
yaml.add_multi_constructor('!pkl:', multi_constructor_pkl)
yaml.add_multi_constructor('!import:', multi_constructor_import)
yaml.add_constructor('!import', constructor_import)
yaml.add_constructor("!float", constructor_float)
pattern = re.compile(SCIENTIFIC_NOTATION_REGEXP)
yaml.add_implicit_resolver('!float', pattern)
is_initialized = True
###############################################################################
# Callbacks used by PyYAML
def multi_constructor_obj(loader, tag_suffix, node):
"""
Callback used by PyYAML when a "!obj:" tag is encountered.
See PyYAML documentation for details on the call signature.
"""
yaml_src = yaml.serialize(node)
construct_mapping(node)
mapping = loader.construct_mapping(node)
assert hasattr(mapping, 'keys')
assert hasattr(mapping, 'values')
for key in mapping.keys():
if not isinstance(key, six.string_types):
message = "Received non string object (%s) as " \
"key in mapping." % str(key)
raise TypeError(message)
if '.' not in tag_suffix:
# TODO: I'm not sure how this was ever working without eval().
callable = eval(tag_suffix)
else:
callable = try_to_import(tag_suffix)
rval = Proxy(callable=callable, yaml_src=yaml_src, positionals=(),
keywords=mapping)
return rval
def multi_constructor_pkl(loader, tag_suffix, node):
"""
Callback used by PyYAML when a "!pkl:" tag is encountered.
"""
global additional_environ
if tag_suffix != "" and tag_suffix != u"":
raise AssertionError('Expected tag_suffix to be "" but it is "'
+ tag_suffix +
'": Put space between !pkl: and the filename.')
mapping = loader.construct_yaml_str(node)
obj = serial.load(preprocess(mapping, additional_environ))
proxy = Proxy(callable=do_not_recurse, positionals=(),
keywords={'value': obj}, yaml_src=yaml.serialize(node))
return proxy
def multi_constructor_import(loader, tag_suffix, node):
"""
Callback used by PyYAML when a "!import:" tag is encountered.
"""
if '.' not in tag_suffix:
raise yaml.YAMLError("!import: tag suffix contains no '.'")
return try_to_import(tag_suffix)
def constructor_import(loader, node):
"""
Callback used by PyYAML when a "!import <str>" tag is encountered.
This tag exects a (quoted) string as argument.
"""
value = loader.construct_scalar(node)
if '.' not in value:
raise yaml.YAMLError("import tag suffix contains no '.'")
return try_to_import(value)
def constructor_float(loader, node):
"""
Callback used by PyYAML when a "!float <str>" tag is encountered.
This tag exects a (quoted) string as argument.
"""
value = loader.construct_scalar(node)
return float(value)
def construct_mapping(node, deep=False):
# This is a modified version of yaml.BaseConstructor.construct_mapping
# in which a repeated key raises a ConstructorError
if not isinstance(node, yaml.nodes.MappingNode):
const = yaml.constructor
message = "expected a mapping node, but found"
raise const.ConstructorError(None, None,
"%s %s " % (message, node.id),
node.start_mark)
mapping = {}
constructor = yaml.constructor.BaseConstructor()
for key_node, value_node in node.value:
key = constructor.construct_object(key_node, deep=False)
try:
hash(key)
except TypeError as exc:
const = yaml.constructor
reraise_as(const.ConstructorError("while constructing a mapping",
node.start_mark,
"found unacceptable key (%s)" %
(exc, key_node.start_mark)))
if key in mapping:
const = yaml.constructor
raise const.ConstructorError("while constructing a mapping",
node.start_mark,
"found duplicate key (%s)" % key)
value = constructor.construct_object(value_node, deep=False)
mapping[key] = value
return mapping
if __name__ == "__main__":
initialize()
# Demonstration of how to specify objects, reference them
# later in the configuration, etc.
yamlfile = """{
"corruptor" : !obj:pylearn2.corruption.GaussianCorruptor &corr {
"corruption_level" : 0.9
},
"dae" : !obj:pylearn2.models.autoencoder.DenoisingAutoencoder {
"nhid" : 20,
"nvis" : 30,
"act_enc" : null,
"act_dec" : null,
"tied_weights" : true,
# we could have also just put the corruptor definition here
"corruptor" : *corr
}
}"""
# yaml.load can take a string or a file object
loaded = yaml.load(yamlfile)
logger.info(loaded)
# These two things should be the same object
assert loaded['corruptor'] is loaded['dae'].corruptor
|
bsd-3-clause
|
[
624,
11532,
1233,
367,
18916,
6057,
402,
11805,
18714,
1041,
199,
646,
8864,
199,
504,
27959,
18,
14,
1208,
492,
3012,
199,
504,
27959,
18,
14,
1208,
14,
2804,
492,
24139,
63,
305,
199,
504,
27959,
18,
14,
1208,
14,
875,
63,
1208,
492,
23351,
199,
504,
27959,
18,
14,
1208,
14,
1250,
63,
1074,
492,
7923,
63,
1250,
199,
504,
27959,
18,
14,
1208,
14,
875,
63,
1208,
492,
1336,
199,
504,
5055,
492,
12863,
199,
646,
2050,
199,
646,
3598,
199,
646,
295,
199,
199,
504,
14377,
14,
5819,
492,
3816,
199,
199,
29424,
1309,
14456,
63,
4609,
2594,
63,
10710,
48,
275,
519,
4289,
7023,
2696,
11,
11843,
2961,
68,
11,
4537,
8995,
68,
10,
6113,
68,
10,
4537,
8995,
68,
19544,
59,
20565,
30679,
2696,
11,
22426,
68,
11,
12913,
199,
199,
374,
63,
12486,
275,
756,
199,
8460,
63,
2314,
275,
488,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
29684,
3463,
3970,
367,
2536,
18916,
11735,
14,
199,
3,
199,
3,
961,
365,
11619,
465,
282,
23399,
12,
7568,
13,
6490,
13197,
6025,
199,
3,
367,
1902,
5007,
13447,
15052,
503,
5957,
13447,
15052,
701,
4573,
4744,
325,
14,
71,
14,
199,
3,
10342,
2992,
14,
199,
3,
199,
3,
2136,
9064,
5120,
282,
9348,
367,
3421,
2551,
2951,
315,
1930,
12,
10617,
2985,
787,
199,
3,
16313,
701,
314,
26621,
14729,
465,
5966,
14,
199,
1563,
4936,
275,
12863,
360,
1563,
4936,
297,
788,
8296,
297,
283,
3124,
2551,
297,
3660,
283,
7511,
297,
283,
5963,
63,
2164,
1105,
421,
199,
533,
12373,
8,
1563,
4936,
304,
272,
408,
272,
1626,
13197,
6025,
3382,
2536,
18916,
2198,
436,
909,
272,
26621,
14,
339,
3897,
272,
4143,
272,
4550,
520,
4550,
267,
710,
805,
15,
533,
370,
1240,
370,
17321,
642,
1031,
14,
272,
3421,
2551,
520,
6076,
267,
10902,
4302,
367,
6466,
2291,
367,
11333,
2368,
13493,
10,
589,
14963,
272,
7681,
520,
1211,
13,
2930,
267,
437,
4412,
687,
7681,
370,
2368,
13493,
538,
958,
29984,
1314,
1443,
506,
267,
658,
4936,
64,
83,
503,
658,
4936,
64,
83,
6032,
6272,
658,
807,
64,
503,
658,
513,
64,
4454,
14,
267,
17276,
1471,
506,
3326,
626,
787,
1686,
2018,
1750,
1561,
14,
272,
8864,
63,
2164,
520,
620,
267,
710,
18916,
1350,
626,
2737,
642,
1031,
12,
340,
2808,
14,
339,
8144,
272,
9063,
272,
961,
365,
11619,
465,
282,
23399,
12,
7568,
13,
6490,
13197,
272,
6025,
367,
1902,
5007,
13447,
15052,
503,
5957,
13447,
15052,
272,
701,
4573,
4744,
325,
14,
71,
14,
10342,
2992,
14,
339,
961,
6770,
1021,
27580,
3495,
370,
221,
4278,
658,
1563,
4936,
19097,
83,
26856,
2227,
29341,
272,
334,
475,
5126,
25223,
625,
24596,
12863,
4008,
680,
272,
408,
272,
636,
7257,
363,
275,
942,
339,
347,
636,
2227,
721,
277,
304,
267,
408,
267,
1432,
282,
2631,
4079,
641,
314,
909,
2870,
334,
475,
5126,
25223,
625,
24596,
267,
12863,
4008,
680,
267,
408,
267,
372,
2631,
8,
344,
8,
277,
430,
421,
199,
318,
886,
63,
1397,
63,
25786,
8,
585,
304,
272,
408,
272,
6801,
5272,
1202,
367,
19696,
376,
625,
20428,
909,
334,
6777,
1077,
272,
440,
506,
15035,
11507,
680,
961,
365,
18054,
436,
522,
1043,
701,
314,
272,
26621,
1798,
14,
24425,
1183,
12,
949,
13,
411,
334,
5808,
314,
574,
272,
3032,
315,
465,
376,
1423,
680,
339,
3897,
272,
4143,
272,
574,
520,
909,
267,
710,
574,
370,
506,
2138,
14,
339,
1803,
272,
5514,
272,
574,
520,
909,
267,
710,
2011,
909,
3032,
315,
465,
376,
1423,
14,
272,
408,
272,
372,
574,
421,
199,
318,
485,
3615,
18973,
63,
3280,
63,
2960,
8,
3280,
12,
17792,
29,
403,
304,
272,
408,
272,
11642,
805,
367,
18494,
3615,
18973,
64,
626,
10022,
2251,
402,
314,
658,
4936,
64,
272,
1021,
14,
339,
3897,
272,
4143,
272,
4566,
520,
12373,
909,
267,
437,
658,
4936,
64,
909,
626,
14,
272,
17792,
520,
1211,
12,
1687,
390,
8125,
267,
437,
2600,
4412,
10889,
17544,
658,
4936,
64,
2251,
267,
370,
3932,
17544,
1338,
14,
339,
1803,
272,
5514,
272,
1559,
520,
909,
267,
710,
754,
909,
687,
15035,
9034,
1958,
314,
909,
19666,
14,
272,
408,
272,
340,
4566,
315,
17792,
26,
267,
372,
17792,
59,
3280,
61,
272,
587,
26,
267,
327,
3591,
1764,
886,
63,
1397,
63,
25786,
701,
2951,
625,
13,
1389,
316,
652,
334,
7191,
465,
6358,
680,
267,
340,
4566,
14,
8296,
508,
886,
63,
1397,
63,
25786,
26,
288,
1559,
275,
4566,
14,
7511,
459,
585,
418,
267,
587,
26,
288,
327,
3254,
26,
1050,
334,
11151,
9,
2291,
367,
3421,
2551,
334,
10065,
370,
506,
3483,
288,
327,
370,
7923,
63,
1250,
2597,
680,
288,
340,
822,
8,
3280,
14,
3124,
2551,
9,
690,
378,
26,
355,
746,
4279,
360,
17867,
2368,
440,
5966,
283,
5101,
283,
4946,
315,
4566,
26621,
358,
288,
2074,
275,
1211,
1332,
75,
12,
485,
3615,
18973,
8,
86,
12,
17792,
430,
2079,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
3280,
14,
7511,
430,
288,
1559,
275,
7923,
63,
1250,
8,
3280,
14,
8296,
12,
2074,
9,
267,
862,
26,
288,
1559,
14,
5963,
63,
2164,
275,
4566,
14,
5963,
63,
2164,
267,
871,
4281,
26,
221,
327,
6601,
3992,
7859,
1133,
2040,
642,
14,
288,
986,
267,
17792,
59,
3280,
61,
275,
1559,
267,
372,
17792,
59,
3280,
61,
421,
199,
318,
485,
3615,
18973,
8,
3280,
12,
17792,
29,
403,
304,
272,
408,
272,
32092,
282,
334,
14861,
402,
9,
12373,
909,
8,
83,
680,
339,
3897,
272,
4143,
272,
4566,
520,
909,
267,
437,
658,
4936,
64,
909,
503,
769,
15,
807,
15,
8939,
14,
24361,
787,
1255,
4012,
267,
658,
17677,
2313,
272,
17792,
520,
1211,
12,
1687,
390,
8125,
267,
437,
2600,
4412,
10889,
17544,
658,
4936,
64,
2251,
267,
370,
3932,
17544,
1338,
14,
339,
1803,
272,
5514,
272,
1559,
520,
909,
267,
710,
754,
909,
687,
15035,
9034,
1958,
314,
909,
19666,
14,
339,
8144,
272,
9063,
272,
961,
1077,
440,
506,
8652,
1777,
402,
314,
17830,
12,
4575,
3261,
14,
272,
408,
272,
340,
17792
] |
[
11532,
1233,
367,
18916,
6057,
402,
11805,
18714,
1041,
199,
646,
8864,
199,
504,
27959,
18,
14,
1208,
492,
3012,
199,
504,
27959,
18,
14,
1208,
14,
2804,
492,
24139,
63,
305,
199,
504,
27959,
18,
14,
1208,
14,
875,
63,
1208,
492,
23351,
199,
504,
27959,
18,
14,
1208,
14,
1250,
63,
1074,
492,
7923,
63,
1250,
199,
504,
27959,
18,
14,
1208,
14,
875,
63,
1208,
492,
1336,
199,
504,
5055,
492,
12863,
199,
646,
2050,
199,
646,
3598,
199,
646,
295,
199,
199,
504,
14377,
14,
5819,
492,
3816,
199,
199,
29424,
1309,
14456,
63,
4609,
2594,
63,
10710,
48,
275,
519,
4289,
7023,
2696,
11,
11843,
2961,
68,
11,
4537,
8995,
68,
10,
6113,
68,
10,
4537,
8995,
68,
19544,
59,
20565,
30679,
2696,
11,
22426,
68,
11,
12913,
199,
199,
374,
63,
12486,
275,
756,
199,
8460,
63,
2314,
275,
488,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
29684,
3463,
3970,
367,
2536,
18916,
11735,
14,
199,
3,
199,
3,
961,
365,
11619,
465,
282,
23399,
12,
7568,
13,
6490,
13197,
6025,
199,
3,
367,
1902,
5007,
13447,
15052,
503,
5957,
13447,
15052,
701,
4573,
4744,
325,
14,
71,
14,
199,
3,
10342,
2992,
14,
199,
3,
199,
3,
2136,
9064,
5120,
282,
9348,
367,
3421,
2551,
2951,
315,
1930,
12,
10617,
2985,
787,
199,
3,
16313,
701,
314,
26621,
14729,
465,
5966,
14,
199,
1563,
4936,
275,
12863,
360,
1563,
4936,
297,
788,
8296,
297,
283,
3124,
2551,
297,
3660,
283,
7511,
297,
283,
5963,
63,
2164,
1105,
421,
199,
533,
12373,
8,
1563,
4936,
304,
272,
408,
272,
1626,
13197,
6025,
3382,
2536,
18916,
2198,
436,
909,
272,
26621,
14,
339,
3897,
272,
4143,
272,
4550,
520,
4550,
267,
710,
805,
15,
533,
370,
1240,
370,
17321,
642,
1031,
14,
272,
3421,
2551,
520,
6076,
267,
10902,
4302,
367,
6466,
2291,
367,
11333,
2368,
13493,
10,
589,
14963,
272,
7681,
520,
1211,
13,
2930,
267,
437,
4412,
687,
7681,
370,
2368,
13493,
538,
958,
29984,
1314,
1443,
506,
267,
658,
4936,
64,
83,
503,
658,
4936,
64,
83,
6032,
6272,
658,
807,
64,
503,
658,
513,
64,
4454,
14,
267,
17276,
1471,
506,
3326,
626,
787,
1686,
2018,
1750,
1561,
14,
272,
8864,
63,
2164,
520,
620,
267,
710,
18916,
1350,
626,
2737,
642,
1031,
12,
340,
2808,
14,
339,
8144,
272,
9063,
272,
961,
365,
11619,
465,
282,
23399,
12,
7568,
13,
6490,
13197,
272,
6025,
367,
1902,
5007,
13447,
15052,
503,
5957,
13447,
15052,
272,
701,
4573,
4744,
325,
14,
71,
14,
10342,
2992,
14,
339,
961,
6770,
1021,
27580,
3495,
370,
221,
4278,
658,
1563,
4936,
19097,
83,
26856,
2227,
29341,
272,
334,
475,
5126,
25223,
625,
24596,
12863,
4008,
680,
272,
408,
272,
636,
7257,
363,
275,
942,
339,
347,
636,
2227,
721,
277,
304,
267,
408,
267,
1432,
282,
2631,
4079,
641,
314,
909,
2870,
334,
475,
5126,
25223,
625,
24596,
267,
12863,
4008,
680,
267,
408,
267,
372,
2631,
8,
344,
8,
277,
430,
421,
199,
318,
886,
63,
1397,
63,
25786,
8,
585,
304,
272,
408,
272,
6801,
5272,
1202,
367,
19696,
376,
625,
20428,
909,
334,
6777,
1077,
272,
440,
506,
15035,
11507,
680,
961,
365,
18054,
436,
522,
1043,
701,
314,
272,
26621,
1798,
14,
24425,
1183,
12,
949,
13,
411,
334,
5808,
314,
574,
272,
3032,
315,
465,
376,
1423,
680,
339,
3897,
272,
4143,
272,
574,
520,
909,
267,
710,
574,
370,
506,
2138,
14,
339,
1803,
272,
5514,
272,
574,
520,
909,
267,
710,
2011,
909,
3032,
315,
465,
376,
1423,
14,
272,
408,
272,
372,
574,
421,
199,
318,
485,
3615,
18973,
63,
3280,
63,
2960,
8,
3280,
12,
17792,
29,
403,
304,
272,
408,
272,
11642,
805,
367,
18494,
3615,
18973,
64,
626,
10022,
2251,
402,
314,
658,
4936,
64,
272,
1021,
14,
339,
3897,
272,
4143,
272,
4566,
520,
12373,
909,
267,
437,
658,
4936,
64,
909,
626,
14,
272,
17792,
520,
1211,
12,
1687,
390,
8125,
267,
437,
2600,
4412,
10889,
17544,
658,
4936,
64,
2251,
267,
370,
3932,
17544,
1338,
14,
339,
1803,
272,
5514,
272,
1559,
520,
909,
267,
710,
754,
909,
687,
15035,
9034,
1958,
314,
909,
19666,
14,
272,
408,
272,
340,
4566,
315,
17792,
26,
267,
372,
17792,
59,
3280,
61,
272,
587,
26,
267,
327,
3591,
1764,
886,
63,
1397,
63,
25786,
701,
2951,
625,
13,
1389,
316,
652,
334,
7191,
465,
6358,
680,
267,
340,
4566,
14,
8296,
508,
886,
63,
1397,
63,
25786,
26,
288,
1559,
275,
4566,
14,
7511,
459,
585,
418,
267,
587,
26,
288,
327,
3254,
26,
1050,
334,
11151,
9,
2291,
367,
3421,
2551,
334,
10065,
370,
506,
3483,
288,
327,
370,
7923,
63,
1250,
2597,
680,
288,
340,
822,
8,
3280,
14,
3124,
2551,
9,
690,
378,
26,
355,
746,
4279,
360,
17867,
2368,
440,
5966,
283,
5101,
283,
4946,
315,
4566,
26621,
358,
288,
2074,
275,
1211,
1332,
75,
12,
485,
3615,
18973,
8,
86,
12,
17792,
430,
2079,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
3280,
14,
7511,
430,
288,
1559,
275,
7923,
63,
1250,
8,
3280,
14,
8296,
12,
2074,
9,
267,
862,
26,
288,
1559,
14,
5963,
63,
2164,
275,
4566,
14,
5963,
63,
2164,
267,
871,
4281,
26,
221,
327,
6601,
3992,
7859,
1133,
2040,
642,
14,
288,
986,
267,
17792,
59,
3280,
61,
275,
1559,
267,
372,
17792,
59,
3280,
61,
421,
199,
318,
485,
3615,
18973,
8,
3280,
12,
17792,
29,
403,
304,
272,
408,
272,
32092,
282,
334,
14861,
402,
9,
12373,
909,
8,
83,
680,
339,
3897,
272,
4143,
272,
4566,
520,
909,
267,
437,
658,
4936,
64,
909,
503,
769,
15,
807,
15,
8939,
14,
24361,
787,
1255,
4012,
267,
658,
17677,
2313,
272,
17792,
520,
1211,
12,
1687,
390,
8125,
267,
437,
2600,
4412,
10889,
17544,
658,
4936,
64,
2251,
267,
370,
3932,
17544,
1338,
14,
339,
1803,
272,
5514,
272,
1559,
520,
909,
267,
710,
754,
909,
687,
15035,
9034,
1958,
314,
909,
19666,
14,
339,
8144,
272,
9063,
272,
961,
1077,
440,
506,
8652,
1777,
402,
314,
17830,
12,
4575,
3261,
14,
272,
408,
272,
340,
17792,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maestrano/openerp
|
openerp/tests/test_ir_filters.py
|
63
|
10677
|
# -*- coding: utf-8 -*-
import functools
from openerp import exceptions
from . import common
class Fixtures(object):
def __init__(self, *args):
self.fixtures = args
def __call__(self, fn):
@functools.wraps(fn)
def wrapper(case):
for model, vars in self.fixtures:
case.registry(model).create(
case.cr, common.ADMIN_USER_ID, vars, {})
fn(case)
return wrapper
def fixtures(*args):
return Fixtures(*args)
def noid(d):
""" Removes `id` key from a dict so we don't have to keep these things
around when trying to match
"""
if 'id' in d: del d['id']
return d
class TestGetFilters(common.TransactionCase):
USER_ID = 3
USER = (3, u'Demo User')
@fixtures(
('ir.filters', dict(name='a', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='b', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='c', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='d', user_id=USER_ID, model_id='ir.filters')),
)
def test_own_filters(self):
filters = self.registry('ir.filters').get_filters(
self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', is_default=False, user_id=self.USER, domain='[]', context='{}'),
dict(name='b', is_default=False, user_id=self.USER, domain='[]', context='{}'),
dict(name='c', is_default=False, user_id=self.USER, domain='[]', context='{}'),
dict(name='d', is_default=False, user_id=self.USER, domain='[]', context='{}'),
])
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='c', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='d', user_id=False, model_id='ir.filters')),
)
def test_global_filters(self):
filters = self.registry('ir.filters').get_filters(
self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', is_default=False, user_id=False, domain='[]', context='{}'),
dict(name='b', is_default=False, user_id=False, domain='[]', context='{}'),
dict(name='c', is_default=False, user_id=False, domain='[]', context='{}'),
dict(name='d', is_default=False, user_id=False, domain='[]', context='{}'),
])
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', user_id=common.ADMIN_USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='c', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='d', user_id=common.ADMIN_USER_ID, model_id='ir.filters')),
)
def test_no_third_party_filters(self):
filters = self.registry('ir.filters').get_filters(
self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', is_default=False, user_id=False, domain='[]', context='{}'),
dict(name='c', is_default=False, user_id=self.USER, domain='[]', context='{}'),
])
class TestOwnDefaults(common.TransactionCase):
USER_ID = 3
USER = (3, u'Demo User')
def test_new_no_filter(self):
"""
When creating a @is_default filter with no existing filter, that new
filter gets the default flag
"""
Filters = self.registry('ir.filters')
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'a',
'model_id': 'ir.filters',
'user_id': self.USER_ID,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=self.USER, is_default=True,
domain='[]', context='{}')
])
@fixtures(
('ir.filters', dict(name='a', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='b', user_id=USER_ID, model_id='ir.filters')),
)
def test_new_filter_not_default(self):
"""
When creating a @is_default filter with existing non-default filters,
the new filter gets the flag
"""
Filters = self.registry('ir.filters')
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'c',
'model_id': 'ir.filters',
'user_id': self.USER_ID,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=self.USER, is_default=False, domain='[]', context='{}'),
dict(name='b', user_id=self.USER, is_default=False, domain='[]', context='{}'),
dict(name='c', user_id=self.USER, is_default=True, domain='[]', context='{}'),
])
@fixtures(
('ir.filters', dict(name='a', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='b', is_default=True, user_id=USER_ID, model_id='ir.filters')),
)
def test_new_filter_existing_default(self):
"""
When creating a @is_default filter where an existing filter is already
@is_default, the flag should be *moved* from the old to the new filter
"""
Filters = self.registry('ir.filters')
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'c',
'model_id': 'ir.filters',
'user_id': self.USER_ID,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=self.USER, is_default=False, domain='[]', context='{}'),
dict(name='b', user_id=self.USER, is_default=False, domain='[]', context='{}'),
dict(name='c', user_id=self.USER, is_default=True, domain='[]', context='{}'),
])
@fixtures(
('ir.filters', dict(name='a', user_id=USER_ID, model_id='ir.filters')),
('ir.filters', dict(name='b', is_default=True, user_id=USER_ID, model_id='ir.filters')),
)
def test_update_filter_set_default(self):
"""
When updating an existing filter to @is_default, if an other filter
already has the flag the flag should be moved
"""
Filters = self.registry('ir.filters')
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'a',
'model_id': 'ir.filters',
'user_id': self.USER_ID,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=self.USER, is_default=True, domain='[]', context='{}'),
dict(name='b', user_id=self.USER, is_default=False, domain='[]', context='{}'),
])
class TestGlobalDefaults(common.TransactionCase):
USER_ID = 3
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', user_id=False, model_id='ir.filters')),
)
def test_new_filter_not_default(self):
"""
When creating a @is_default filter with existing non-default filters,
the new filter gets the flag
"""
Filters = self.registry('ir.filters')
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'c',
'model_id': 'ir.filters',
'user_id': False,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=False, is_default=False, domain='[]', context='{}'),
dict(name='b', user_id=False, is_default=False, domain='[]', context='{}'),
dict(name='c', user_id=False, is_default=True, domain='[]', context='{}'),
])
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', is_default=True, user_id=False, model_id='ir.filters')),
)
def test_new_filter_existing_default(self):
"""
When creating a @is_default filter where an existing filter is already
@is_default, an error should be generated
"""
Filters = self.registry('ir.filters')
with self.assertRaises(exceptions.Warning):
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'c',
'model_id': 'ir.filters',
'user_id': False,
'is_default': True,
})
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', is_default=True, user_id=False, model_id='ir.filters')),
)
def test_update_filter_set_default(self):
"""
When updating an existing filter to @is_default, if an other filter
already has the flag an error should be generated
"""
Filters = self.registry('ir.filters')
with self.assertRaises(exceptions.Warning):
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'a',
'model_id': 'ir.filters',
'user_id': False,
'is_default': True,
})
@fixtures(
('ir.filters', dict(name='a', user_id=False, model_id='ir.filters')),
('ir.filters', dict(name='b', is_default=True, user_id=False, model_id='ir.filters')),
)
def test_update_default_filter(self):
"""
Replacing the current default global filter should not generate any error
"""
Filters = self.registry('ir.filters')
context_value = "{'some_key': True}"
Filters.create_or_replace(self.cr, self.USER_ID, {
'name': 'b',
'model_id': 'ir.filters',
'user_id': False,
'context': context_value,
'is_default': True,
})
filters = Filters.get_filters(self.cr, self.USER_ID, 'ir.filters')
self.assertItemsEqual(map(noid, filters), [
dict(name='a', user_id=False, is_default=False, domain='[]', context='{}'),
dict(name='b', user_id=False, is_default=True, domain='[]', context=context_value),
])
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
9143,
199,
199,
504,
5166,
492,
4967,
199,
504,
1275,
492,
2863,
199,
199,
533,
31574,
6969,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
8769,
275,
1249,
339,
347,
636,
1250,
721,
277,
12,
4325,
304,
267,
768,
17869,
14,
13582,
8,
2324,
9,
267,
347,
4975,
8,
2546,
304,
288,
367,
1402,
12,
6802,
315,
291,
14,
8769,
26,
355,
1930,
14,
5189,
8,
1238,
680,
981,
8,
490,
1930,
14,
1556,
12,
2863,
14,
14288,
63,
3791,
63,
998,
12,
6802,
12,
5009,
953,
4325,
8,
2546,
9,
267,
372,
4975,
199,
318,
15188,
2031,
589,
304,
272,
372,
31574,
6969,
2031,
589,
9,
199,
199,
318,
949,
344,
8,
68,
304,
272,
408,
23169,
658,
344,
64,
790,
687,
282,
1211,
880,
781,
2793,
1133,
1172,
370,
4215,
3520,
7645,
272,
6818,
1380,
9936,
370,
1336,
272,
408,
272,
340,
283,
344,
7,
315,
366,
26,
2150,
366,
459,
344,
418,
272,
372,
366,
199,
199,
533,
1379,
1002,
18053,
8,
2330,
14,
10161,
1538,
304,
272,
13044,
63,
998,
275,
650,
272,
13044,
275,
334,
19,
12,
399,
7,
21493,
2876,
358,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
944,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
66,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
68,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
2966,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
66,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
68,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
2330,
14,
14288,
63,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
2330,
14,
14288,
63,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
889,
63,
11470,
63,
7522,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
199,
199,
533,
1379,
28492,
16986,
8,
2330,
14,
10161,
1538,
304,
272,
13044,
63,
998,
275,
650,
272,
13044,
275,
334,
19,
12,
399
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
9143,
199,
199,
504,
5166,
492,
4967,
199,
504,
1275,
492,
2863,
199,
199,
533,
31574,
6969,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
8769,
275,
1249,
339,
347,
636,
1250,
721,
277,
12,
4325,
304,
267,
768,
17869,
14,
13582,
8,
2324,
9,
267,
347,
4975,
8,
2546,
304,
288,
367,
1402,
12,
6802,
315,
291,
14,
8769,
26,
355,
1930,
14,
5189,
8,
1238,
680,
981,
8,
490,
1930,
14,
1556,
12,
2863,
14,
14288,
63,
3791,
63,
998,
12,
6802,
12,
5009,
953,
4325,
8,
2546,
9,
267,
372,
4975,
199,
318,
15188,
2031,
589,
304,
272,
372,
31574,
6969,
2031,
589,
9,
199,
199,
318,
949,
344,
8,
68,
304,
272,
408,
23169,
658,
344,
64,
790,
687,
282,
1211,
880,
781,
2793,
1133,
1172,
370,
4215,
3520,
7645,
272,
6818,
1380,
9936,
370,
1336,
272,
408,
272,
340,
283,
344,
7,
315,
366,
26,
2150,
366,
459,
344,
418,
272,
372,
366,
199,
199,
533,
1379,
1002,
18053,
8,
2330,
14,
10161,
1538,
304,
272,
13044,
63,
998,
275,
650,
272,
13044,
275,
334,
19,
12,
399,
7,
21493,
2876,
358,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
944,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
66,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
68,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
2966,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
66,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
68,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
339,
768,
8769,
8,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
65,
297,
922,
63,
344,
29,
797,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
66,
297,
922,
63,
344,
29,
2330,
14,
14288,
63,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
67,
297,
922,
63,
344,
29,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
267,
661,
723,
14,
4273,
297,
1211,
8,
354,
534,
68,
297,
922,
63,
344,
29,
2330,
14,
14288,
63,
3791,
63,
998,
12,
1402,
63,
344,
534,
723,
14,
4273,
3855,
272,
776,
272,
347,
511,
63,
889,
63,
11470,
63,
7522,
63,
4273,
8,
277,
304,
267,
4766,
275,
291,
14,
5189,
360,
723,
14,
4273,
1959,
362,
63,
4273,
8,
288,
291,
14,
1556,
12,
291,
14,
3791,
63,
998,
12,
283,
723,
14,
4273,
358,
398,
291,
14,
19673,
8,
1130,
8,
889,
344,
12,
4766,
395,
359,
288,
1211,
8,
354,
534,
65,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
797,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
288,
1211,
8,
354,
534,
67,
297,
365,
63,
885,
29,
797,
12,
922,
63,
344,
29,
277,
14,
3791,
12,
2881,
30845,
4300,
1067,
534,
2440,
659,
267,
4794,
199,
199,
533,
1379,
28492,
16986,
8,
2330,
14,
10161,
1538,
304,
272,
13044,
63,
998,
275,
650,
272,
13044,
275,
334,
19,
12,
399,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OneBitSoftware/jwtSample
|
src/Spa/env1/Lib/site-packages/gunicorn/management/commands/run_gunicorn.py
|
38
|
3258
|
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from gunicorn.app.djangoapp import DjangoApplicationCommand
from gunicorn.config import make_settings
# monkey patch django.
# This patch make sure that we use real threads to get the ident which
# is going to happen if we are using gevent or eventlet.
try:
from django.db.backends import BaseDatabaseWrapper, DatabaseError
if "validate_thread_sharing" in BaseDatabaseWrapper.__dict__:
import thread
_get_ident = thread.get_ident
__old__init__ = BaseDatabaseWrapper.__init__
def _init(self, *args, **kwargs):
__old__init__(self, *args, **kwargs)
self._thread_ident = _get_ident()
def _validate_thread_sharing(self):
if (not self.allow_thread_sharing
and self._thread_ident != _get_ident()):
raise DatabaseError("DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
% (self.alias, self._thread_ident, _get_ident()))
BaseDatabaseWrapper.__init__ = _init
BaseDatabaseWrapper.validate_thread_sharing = _validate_thread_sharing
except ImportError:
pass
def make_options():
g_settings = make_settings(ignore=("version"))
keys = g_settings.keys()
def sorter(k):
return (g_settings[k].section, g_settings[k].order)
opts = [
make_option('--adminmedia', dest='admin_media_path', default='',
help='Specifies the directory from which to serve admin media.')
]
for k in keys:
if k in ('pythonpath', 'django_settings',):
continue
setting = g_settings[k]
if not setting.cli:
continue
args = tuple(setting.cli)
kwargs = {
"dest": setting.name,
"metavar": setting.meta or None,
"action": setting.action or "store",
"type": setting.type or "string",
"default": None,
"help": "%s [%s]" % (setting.short, setting.default)
}
if kwargs["action"] != "store":
kwargs.pop("type")
opts.append(make_option(*args, **kwargs))
return tuple(opts)
GUNICORN_OPTIONS = make_options()
class Command(BaseCommand):
option_list = BaseCommand.option_list + GUNICORN_OPTIONS
help = "Starts a fully-functional Web server using gunicorn."
args = '[optional port number, or ipaddr:port or unix:/path/to/sockfile]'
# Validation is called explicitly each time the server is reloaded.
requires_model_validation = False
def handle(self, addrport=None, *args, **options):
if args:
raise CommandError('Usage is run_gunicorn %s' % self.args)
if addrport:
options['bind'] = addrport
admin_media_path = options.pop('admin_media_path', '')
DjangoApplicationCommand(options, admin_media_path).run()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
446,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
486,
29067,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
12840,
367,
1655,
2556,
14,
199,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
486,
29067,
14,
571,
14,
1176,
571,
492,
5634,
5039,
3110,
199,
504,
486,
29067,
14,
888,
492,
1852,
63,
1751,
199,
199,
3,
14198,
3371,
1639,
14,
199,
3,
961,
3371,
1852,
3238,
626,
781,
675,
3363,
7183,
370,
664,
314,
12893,
1314,
199,
3,
365,
9995,
370,
5992,
340,
781,
787,
1808,
23386,
503,
21819,
14,
199,
893,
26,
272,
687,
1639,
14,
697,
14,
7765,
492,
29103,
4590,
12,
27728,
339,
340,
298,
3502,
63,
2671,
63,
29122,
2,
315,
29103,
4590,
855,
807,
10651,
267,
492,
2462,
267,
485,
362,
63,
5425,
275,
2462,
14,
362,
63,
5425,
398,
636,
1753,
363,
826,
363,
275,
29103,
4590,
855,
826,
363,
398,
347,
485,
826,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
636,
1753,
363,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
291,
423,
2671,
63,
5425,
275,
485,
362,
63,
5425,
342,
398,
347,
485,
3502,
63,
2671,
63,
29122,
8,
277,
304,
288,
340,
334,
1397,
291,
14,
3306,
63,
2671,
63,
29122,
355,
436,
291,
423,
2671,
63,
5425,
1137,
485,
362,
63,
5425,
5109,
490,
746,
27728,
480,
7243,
4590,
2251,
2737,
315,
282,
298,
717,
298,
2671,
883,
1454,
506,
1202,
315,
626,
2011,
2462,
14,
710,
909,
298,
717,
298,
1045,
5162,
1543,
83,
7,
1990,
2737,
315,
2462,
1305,
450,
83,
436,
642,
365,
298,
717,
298,
2671,
1305,
450,
83,
2122,
717,
450,
334,
277,
14,
3620,
12,
291,
423,
2671,
63,
5425,
12,
485,
362,
63,
5425,
4059,
398,
29103,
4590,
855,
826,
363,
275,
485,
826,
267,
29103,
4590,
14,
3502,
63,
2671,
63,
29122,
275,
485,
3502,
63,
2671,
63,
29122,
199,
2590,
3545,
26,
272,
986,
421,
199,
318,
1852,
63,
1419,
837,
272,
486,
63,
1751,
275,
1852,
63,
1751,
8,
4247,
15387,
1023,
2237,
339,
2883,
275,
486,
63,
1751,
14,
1612,
342,
339,
347,
308,
3968,
8,
75,
304,
267,
372,
334,
71,
63,
1751,
59,
75,
1055,
2792,
12,
486,
63,
1751,
59,
75,
1055,
1648,
9,
339,
3999,
275,
359,
267,
1852,
63,
1422,
4517,
2113,
4603,
297,
2053,
534,
2113,
63,
4603,
63,
515,
297,
849,
4581,
267,
1720,
534,
6154,
5604,
314,
2082,
687,
1314,
370,
14062,
4628,
5898,
2659,
272,
1622,
339,
367,
1022,
315,
2883,
26,
267,
340,
1022,
315,
661,
1548,
515,
297,
283,
1176,
63,
1751,
297,
304,
288,
1980,
398,
4260,
275,
486,
63,
1751,
59,
75,
61,
267,
340,
440,
4260,
14,
2764,
26,
288,
1980,
398,
1249,
275,
2008,
8,
6031,
14,
2764,
9,
398,
2074,
275,
469,
288,
298,
2614,
582,
4260,
14,
354,
12,
288,
298,
23303,
582,
4260,
14,
2024,
503,
488,
12,
288,
298,
1287,
582,
4260,
14,
1287,
503,
298,
1617,
401,
288,
298,
466,
582,
4260,
14,
466,
503,
298,
875,
401,
288,
298,
885,
582,
488,
12,
288,
298,
3437,
582,
2071,
83,
8978,
83,
8480,
450,
334,
6031,
14,
3612,
12,
4260,
14,
885,
9,
267,
789,
267,
340,
2074,
905,
1287,
937,
1137,
298,
1617,
582,
288,
2074,
14,
1935,
480,
466,
531,
398,
3999,
14,
740,
8,
1875,
63,
1422,
2031,
589,
12,
1011,
958,
430,
339,
372,
2008,
8,
3291,
9,
199,
199,
39,
11580,
32080,
63,
8808,
275,
1852,
63,
1419,
342,
421,
199,
533,
5817,
8,
25150,
304,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
598,
11580,
32080,
63,
8808,
272,
1720,
275,
298,
32142,
282,
9999,
13,
15481,
6001,
1654,
1808,
486,
29067,
2122,
272,
1249,
275,
6730,
4144,
1844,
1329,
12,
503,
21249,
26,
719,
503,
16572,
11254,
515,
15,
475,
15,
5096,
493,
6616,
339,
327,
19381,
365,
2797,
7662,
1924,
900,
314,
1654,
365,
31848,
14,
272,
5074,
63,
1238,
63,
6136,
275,
756,
339,
347,
2429,
8,
277,
12,
5552,
719,
29,
403,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
1249,
26,
288,
746,
14393,
360,
7692,
365,
1255,
63,
71,
29067,
450,
83,
7,
450,
291,
14,
589,
9,
398,
340,
5552,
719,
26,
288,
1511,
459,
3409,
418,
275,
5552,
719,
398,
4628,
63,
4603,
63,
515,
275,
1511,
14,
1935,
360,
2113,
63,
4603,
63,
515,
297,
4074,
267,
5634,
5039,
3110,
8,
1419,
12,
4628,
63,
4603,
63,
515,
680,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
446,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
486,
29067,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
12840,
367,
1655,
2556,
14,
199,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
199,
504,
486,
29067,
14,
571,
14,
1176,
571,
492,
5634,
5039,
3110,
199,
504,
486,
29067,
14,
888,
492,
1852,
63,
1751,
199,
199,
3,
14198,
3371,
1639,
14,
199,
3,
961,
3371,
1852,
3238,
626,
781,
675,
3363,
7183,
370,
664,
314,
12893,
1314,
199,
3,
365,
9995,
370,
5992,
340,
781,
787,
1808,
23386,
503,
21819,
14,
199,
893,
26,
272,
687,
1639,
14,
697,
14,
7765,
492,
29103,
4590,
12,
27728,
339,
340,
298,
3502,
63,
2671,
63,
29122,
2,
315,
29103,
4590,
855,
807,
10651,
267,
492,
2462,
267,
485,
362,
63,
5425,
275,
2462,
14,
362,
63,
5425,
398,
636,
1753,
363,
826,
363,
275,
29103,
4590,
855,
826,
363,
398,
347,
485,
826,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
636,
1753,
363,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
291,
423,
2671,
63,
5425,
275,
485,
362,
63,
5425,
342,
398,
347,
485,
3502,
63,
2671,
63,
29122,
8,
277,
304,
288,
340,
334,
1397,
291,
14,
3306,
63,
2671,
63,
29122,
355,
436,
291,
423,
2671,
63,
5425,
1137,
485,
362,
63,
5425,
5109,
490,
746,
27728,
480,
7243,
4590,
2251,
2737,
315,
282,
298,
717,
298,
2671,
883,
1454,
506,
1202,
315,
626,
2011,
2462,
14,
710,
909,
298,
717,
298,
1045,
5162,
1543,
83,
7,
1990,
2737,
315,
2462,
1305,
450,
83,
436,
642,
365,
298,
717,
298,
2671,
1305,
450,
83,
2122,
717,
450,
334,
277,
14,
3620,
12,
291,
423,
2671,
63,
5425,
12,
485,
362,
63,
5425,
4059,
398,
29103,
4590,
855,
826,
363,
275,
485,
826,
267,
29103,
4590,
14,
3502,
63,
2671,
63,
29122,
275,
485,
3502,
63,
2671,
63,
29122,
199,
2590,
3545,
26,
272,
986,
421,
199,
318,
1852,
63,
1419,
837,
272,
486,
63,
1751,
275,
1852,
63,
1751,
8,
4247,
15387,
1023,
2237,
339,
2883,
275,
486,
63,
1751,
14,
1612,
342,
339,
347,
308,
3968,
8,
75,
304,
267,
372,
334,
71,
63,
1751,
59,
75,
1055,
2792,
12,
486,
63,
1751,
59,
75,
1055,
1648,
9,
339,
3999,
275,
359,
267,
1852,
63,
1422,
4517,
2113,
4603,
297,
2053,
534,
2113,
63,
4603,
63,
515,
297,
849,
4581,
267,
1720,
534,
6154,
5604,
314,
2082,
687,
1314,
370,
14062,
4628,
5898,
2659,
272,
1622,
339,
367,
1022,
315,
2883,
26,
267,
340,
1022,
315,
661,
1548,
515,
297,
283,
1176,
63,
1751,
297,
304,
288,
1980,
398,
4260,
275,
486,
63,
1751,
59,
75,
61,
267,
340,
440,
4260,
14,
2764,
26,
288,
1980,
398,
1249,
275,
2008,
8,
6031,
14,
2764,
9,
398,
2074,
275,
469,
288,
298,
2614,
582,
4260,
14,
354,
12,
288,
298,
23303,
582,
4260,
14,
2024,
503,
488,
12,
288,
298,
1287,
582,
4260,
14,
1287,
503,
298,
1617,
401,
288,
298,
466,
582,
4260,
14,
466,
503,
298,
875,
401,
288,
298,
885,
582,
488,
12,
288,
298,
3437,
582,
2071,
83,
8978,
83,
8480,
450,
334,
6031,
14,
3612,
12,
4260,
14,
885,
9,
267,
789,
267,
340,
2074,
905,
1287,
937,
1137,
298,
1617,
582,
288,
2074,
14,
1935,
480,
466,
531,
398,
3999,
14,
740,
8,
1875,
63,
1422,
2031,
589,
12,
1011,
958,
430,
339,
372,
2008,
8,
3291,
9,
199,
199,
39,
11580,
32080,
63,
8808,
275,
1852,
63,
1419,
342,
421,
199,
533,
5817,
8,
25150,
304,
272,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
598,
11580,
32080,
63,
8808,
272,
1720,
275,
298,
32142,
282,
9999,
13,
15481,
6001,
1654,
1808,
486,
29067,
2122,
272,
1249,
275,
6730,
4144,
1844,
1329,
12,
503,
21249,
26,
719,
503,
16572,
11254,
515,
15,
475,
15,
5096,
493,
6616,
339,
327,
19381,
365,
2797,
7662,
1924,
900,
314,
1654,
365,
31848,
14,
272,
5074,
63,
1238,
63,
6136,
275,
756,
339,
347,
2429,
8,
277,
12,
5552,
719,
29,
403,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
1249,
26,
288,
746,
14393,
360,
7692,
365,
1255,
63,
71,
29067,
450,
83,
7,
450,
291,
14,
589,
9,
398,
340,
5552,
719,
26,
288,
1511,
459,
3409,
418,
275,
5552,
719,
398,
4628,
63,
4603,
63,
515,
275,
1511,
14,
1935,
360,
2113,
63,
4603,
63,
515,
297,
4074,
267,
5634,
5039,
3110,
8,
1419,
12,
4628,
63,
4603,
63,
515,
680,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0
] |
keedio/hue
|
desktop/core/ext-py/Django-1.6.10/django/core/management/base.py
|
104
|
15912
|
"""
Base classes for writing management commands (named commands which can
be executed through ``django-admin.py`` or ``manage.py``).
"""
from __future__ import unicode_literals
import os
import sys
from optparse import make_option, OptionParser
import django
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style
from django.utils.encoding import force_str
from django.utils.six import StringIO
class CommandError(Exception):
"""
Exception class indicating a problem while executing a management
command.
If this exception is raised during the execution of a management
command, it will be caught and turned into a nicely-printed error
message to the appropriate output stream (i.e., stderr); as a
result, raising this exception (with a sensible description of the
error) is the preferred way to indicate that something has gone
wrong in the execution of a command.
"""
pass
def handle_default_options(options):
"""
Include any default options that all commands should accept here
so that ManagementUtility can handle them before searching for
user commands.
"""
if options.settings:
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
if options.pythonpath:
sys.path.insert(0, options.pythonpath)
class OutputWrapper(object):
"""
Wrapper around stdout/stderr
"""
def __init__(self, out, style_func=None, ending='\n'):
self._out = out
self.style_func = None
if hasattr(out, 'isatty') and out.isatty():
self.style_func = style_func
self.ending = ending
def __getattr__(self, name):
return getattr(self._out, name)
def write(self, msg, style_func=None, ending=None):
ending = self.ending if ending is None else ending
if ending and not msg.endswith(ending):
msg += ending
style_func = [f for f in (style_func, self.style_func, lambda x:x)
if f is not None][0]
self._out.write(force_str(style_func(msg)))
class BaseCommand(object):
"""
The base class from which all management commands ultimately
derive.
Use this class if you want access to all of the mechanisms which
parse the command-line arguments and work out what code to call in
response; if you don't need to change any of that behavior,
consider using one of the subclasses defined in this file.
If you are interested in overriding/customizing various aspects of
the command-parsing and -execution behavior, the normal flow works
as follows:
1. ``django-admin.py`` or ``manage.py`` loads the command class
and calls its ``run_from_argv()`` method.
2. The ``run_from_argv()`` method calls ``create_parser()`` to get
an ``OptionParser`` for the arguments, parses them, performs
any environment changes requested by options like
``pythonpath``, and then calls the ``execute()`` method,
passing the parsed arguments.
3. The ``execute()`` method attempts to carry out the command by
calling the ``handle()`` method with the parsed arguments; any
output produced by ``handle()`` will be printed to standard
output and, if the command is intended to produce a block of
SQL statements, will be wrapped in ``BEGIN`` and ``COMMIT``.
4. If ``handle()`` or ``execute()`` raised any exception (e.g.
``CommandError``), ``run_from_argv()`` will instead print an error
message to ``stderr``.
Thus, the ``handle()`` method is typically the starting point for
subclasses; many built-in commands and command types either place
all of their logic in ``handle()``, or perform some additional
parsing work in ``handle()`` and then delegate from it to more
specialized methods as needed.
Several attributes affect behavior at various steps along the way:
``args``
A string listing the arguments accepted by the command,
suitable for use in help messages; e.g., a command which takes
a list of application names might set this to '<appname
appname ...>'.
``can_import_settings``
A boolean indicating whether the command needs to be able to
import Django settings; if ``True``, ``execute()`` will verify
that this is possible before proceeding. Default value is
``True``.
``help``
A short description of the command, which will be printed in
help messages.
``option_list``
This is the list of ``optparse`` options which will be fed
into the command's ``OptionParser`` for parsing arguments.
``output_transaction``
A boolean indicating whether the command outputs SQL
statements; if ``True``, the output will automatically be
wrapped with ``BEGIN;`` and ``COMMIT;``. Default value is
``False``.
``requires_model_validation``
A boolean; if ``True``, validation of installed models will be
performed prior to executing the command. Default value is
``True``. To validate an individual application's models
rather than all applications' models, call
``self.validate(app)`` from ``handle()``, where ``app`` is the
application's Python module.
``leave_locale_alone``
A boolean indicating whether the locale set in settings should be
preserved during the execution of the command instead of being
forcibly set to 'en-us'.
Default value is ``False``.
Make sure you know what you are doing if you decide to change the value
of this option in your custom command if it creates database content
that is locale-sensitive and such content shouldn't contain any
translations (like it happens e.g. with django.contrim.auth
permissions) as making the locale differ from the de facto default
'en-us' might cause unintended effects.
This option can't be False when the can_import_settings option is set
to False too because attempting to set the locale needs access to
settings. This condition will generate a CommandError.
"""
# Metadata about this command.
option_list = (
make_option('-v', '--verbosity', action='store', dest='verbosity', default='1',
type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output'),
make_option('--settings',
help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'),
make_option('--pythonpath',
help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".'),
make_option('--traceback', action='store_true',
help='Raise on exception'),
)
help = ''
args = ''
# Configuration shortcuts that alter various logic.
can_import_settings = True
requires_model_validation = True
output_transaction = False # Whether to wrap the output in a "BEGIN; COMMIT;"
leave_locale_alone = False
def __init__(self):
self.style = color_style()
def get_version(self):
"""
Return the Django version, which should be correct for all
built-in Django commands. User-supplied commands should
override this method.
"""
return django.get_version()
def usage(self, subcommand):
"""
Return a brief description of how to use this command, by
default from the attribute ``self.help``.
"""
usage = '%%prog %s [options] %s' % (subcommand, self.args)
if self.help:
return '%s\n\n%s' % (usage, self.help)
else:
return usage
def create_parser(self, prog_name, subcommand):
"""
Create and return the ``OptionParser`` which will be used to
parse the arguments to this command.
"""
return OptionParser(prog=prog_name,
usage=self.usage(subcommand),
version=self.get_version(),
option_list=self.option_list)
def print_help(self, prog_name, subcommand):
"""
Print the help message for this command, derived from
``self.usage()``.
"""
parser = self.create_parser(prog_name, subcommand)
parser.print_help()
def run_from_argv(self, argv):
"""
Set up any environment changes requested (e.g., Python path
and Django settings), then run this command. If the
command raises a ``CommandError``, intercept it and print it sensibly
to stderr. If the ``--traceback`` option is present or the raised
``Exception`` is not ``CommandError``, raise it.
"""
parser = self.create_parser(argv[0], argv[1])
options, args = parser.parse_args(argv[2:])
handle_default_options(options)
try:
self.execute(*args, **options.__dict__)
except Exception as e:
if options.traceback or not isinstance(e, CommandError):
raise
# self.stderr is not guaranteed to be set here
stderr = getattr(self, 'stderr', OutputWrapper(sys.stderr, self.style.ERROR))
stderr.write('%s: %s' % (e.__class__.__name__, e))
sys.exit(1)
def execute(self, *args, **options):
"""
Try to execute this command, performing model validation if
needed (as controlled by the attribute
``self.requires_model_validation``, except if force-skipped).
"""
self.stdout = OutputWrapper(options.get('stdout', sys.stdout))
self.stderr = OutputWrapper(options.get('stderr', sys.stderr), self.style.ERROR)
if self.can_import_settings:
from django.conf import settings
saved_locale = None
if not self.leave_locale_alone:
# Only mess with locales if we can assume we have a working
# settings file, because django.utils.translation requires settings
# (The final saying about whether the i18n machinery is active will be
# found in the value of the USE_I18N setting)
if not self.can_import_settings:
raise CommandError("Incompatible values of 'leave_locale_alone' "
"(%s) and 'can_import_settings' (%s) command "
"options." % (self.leave_locale_alone,
self.can_import_settings))
# Switch to US English, because django-admin.py creates database
# content like permissions, and those shouldn't contain any
# translations.
from django.utils import translation
saved_locale = translation.get_language()
translation.activate('en-us')
try:
if self.requires_model_validation and not options.get('skip_validation'):
self.validate()
output = self.handle(*args, **options)
if output:
if self.output_transaction:
# This needs to be imported here, because it relies on
# settings.
from django.db import connections, DEFAULT_DB_ALIAS
connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
if connection.ops.start_transaction_sql():
self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()))
self.stdout.write(output)
if self.output_transaction:
self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;"))
finally:
if saved_locale is not None:
translation.activate(saved_locale)
def validate(self, app=None, display_num_errors=False):
"""
Validates the given app, raising CommandError for any errors.
If app is None, then this will validate all installed apps.
"""
from django.core.management.validation import get_validation_errors
s = StringIO()
num_errors = get_validation_errors(s, app)
if num_errors:
s.seek(0)
error_text = s.read()
raise CommandError("One or more models did not validate:\n%s" % error_text)
if display_num_errors:
self.stdout.write("%s error%s found" % (num_errors, '' if num_errors == 1 else 's'))
def handle(self, *args, **options):
"""
The actual logic of the command. Subclasses must implement
this method.
"""
raise NotImplementedError()
class AppCommand(BaseCommand):
"""
A management command which takes one or more installed application
names as arguments, and does something with each of them.
Rather than implementing ``handle()``, subclasses must implement
``handle_app()``, which will be called once for each application.
"""
args = '<appname appname ...>'
def handle(self, *app_labels, **options):
from django.db import models
if not app_labels:
raise CommandError('Enter at least one appname.')
try:
app_list = [models.get_app(app_label) for app_label in app_labels]
except (ImproperlyConfigured, ImportError) as e:
raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)
output = []
for app in app_list:
app_output = self.handle_app(app, **options)
if app_output:
output.append(app_output)
return '\n'.join(output)
def handle_app(self, app, **options):
"""
Perform the command's actions for ``app``, which will be the
Python module corresponding to an application name given on
the command line.
"""
raise NotImplementedError()
class LabelCommand(BaseCommand):
"""
A management command which takes one or more arbitrary arguments
(labels) on the command line, and does something with each of
them.
Rather than implementing ``handle()``, subclasses must implement
``handle_label()``, which will be called once for each label.
If the arguments should be names of installed applications, use
``AppCommand`` instead.
"""
args = '<label label ...>'
label = 'label'
def handle(self, *labels, **options):
if not labels:
raise CommandError('Enter at least one %s.' % self.label)
output = []
for label in labels:
label_output = self.handle_label(label, **options)
if label_output:
output.append(label_output)
return '\n'.join(output)
def handle_label(self, label, **options):
"""
Perform the command's actions for ``label``, which will be the
string as given on the command line.
"""
raise NotImplementedError()
class NoArgsCommand(BaseCommand):
"""
A command which takes no arguments on the command line.
Rather than implementing ``handle()``, subclasses must implement
``handle_noargs()``; ``handle()`` itself is overridden to ensure
no arguments are passed to the command.
Attempting to pass arguments will raise ``CommandError``.
"""
args = ''
def handle(self, *args, **options):
if args:
raise CommandError("Command doesn't accept any arguments")
return self.handle_noargs(**options)
def handle_noargs(self, **options):
"""
Perform this command's actions.
"""
raise NotImplementedError()
|
apache-2.0
|
[
624,
199,
1563,
3992,
367,
3575,
10041,
3718,
334,
4579,
3718,
1314,
883,
199,
1235,
7934,
4012,
1124,
1176,
13,
2113,
14,
647,
1040,
503,
1124,
9053,
14,
647,
20008,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
199,
504,
8691,
492,
1852,
63,
1422,
12,
13491,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
4174,
492,
5228,
421,
199,
533,
14393,
8,
1726,
304,
272,
408,
272,
2186,
1021,
9297,
282,
5160,
1830,
14043,
282,
10041,
272,
1414,
14,
339,
982,
642,
1919,
365,
4915,
5309,
314,
6451,
402,
282,
10041,
272,
1414,
12,
652,
911,
506,
15604,
436,
19136,
1901,
282,
14213,
590,
13,
27131,
1125,
272,
1245,
370,
314,
5827,
1072,
2547,
334,
73,
14,
69,
2020,
4635,
2736,
465,
282,
272,
754,
12,
17026,
642,
1919,
334,
1045,
282,
27962,
1369,
402,
314,
272,
1125,
9,
365,
314,
14388,
4340,
370,
6623,
626,
6020,
965,
21737,
272,
6835,
315,
314,
6451,
402,
282,
1414,
14,
339,
408,
272,
986,
421,
199,
318,
2429,
63,
885,
63,
1419,
8,
1419,
304,
272,
408,
272,
15783,
1263,
849,
1511,
626,
1006,
3718,
1077,
4729,
2348,
272,
880,
626,
8259,
17505,
883,
2429,
3062,
2544,
18112,
367,
272,
922,
3718,
14,
339,
408,
272,
340,
1511,
14,
1751,
26,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
1511,
14,
1751,
272,
340,
1511,
14,
1548,
515,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1511,
14,
1548,
515,
9,
421,
199,
533,
7242,
4590,
8,
785,
304,
272,
408,
272,
21947,
6818,
3839,
15,
3083,
272,
408,
272,
347,
636,
826,
721,
277,
12,
734,
12,
3449,
63,
1532,
29,
403,
12,
13401,
17115,
78,
735,
267,
291,
423,
548,
275,
734,
267,
291,
14,
2487,
63,
1532,
275,
488,
267,
340,
2688,
8,
548,
12,
283,
21122,
358,
436,
734,
14,
21122,
837,
288,
291,
14,
2487,
63,
1532,
275,
3449,
63,
1532,
267,
291,
14,
3219,
275,
13401,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
423,
548,
12,
536,
9,
339,
347,
2218,
8,
277,
12,
1499,
12,
3449,
63,
1532,
29,
403,
12,
13401,
29,
403,
304,
267,
13401,
275,
291,
14,
3219,
340,
13401,
365,
488,
587,
13401,
267,
340,
13401,
436,
440,
1499,
14,
4130,
8,
3219,
304,
288,
1499,
847,
13401,
267,
3449,
63,
1532,
275,
359,
70,
367,
289,
315,
334,
2487,
63,
1532,
12,
291,
14,
2487,
63,
1532,
12,
2400,
671,
26,
88,
9,
1993,
340,
289,
365,
440,
488,
1527,
16,
61,
267,
291,
423,
548,
14,
952,
8,
3990,
63,
495,
8,
2487,
63,
1532,
8,
1328,
1724,
421,
199,
533,
22239,
8,
785,
304,
272,
408,
272,
710,
1300,
1021,
687,
1314,
1006,
10041,
3718,
221,
1141,
77,
13824,
272,
23519,
14,
339,
3645,
642,
1021,
340,
1265,
2934,
2879,
370,
1006,
402,
314,
562,
10832,
706,
1314,
272,
2198,
314,
1414,
13,
604,
2368,
436,
1736,
734,
4052,
1233,
370,
1240,
315,
272,
1177,
27,
340,
1265,
2793,
1133,
1929,
370,
1570,
1263,
402,
626,
5953,
12,
272,
11201,
1808,
1373,
402,
314,
9180,
3247,
315,
642,
570,
14,
339,
982,
1265,
787,
22201,
315,
18972,
15,
4229,
9147,
7750,
17435,
83,
402,
272,
314,
1414,
13,
11059,
436,
446,
9416,
5953,
12,
314,
3293,
6369,
5419,
272,
465,
11924,
26,
339,
413,
14,
1124,
1176,
13,
2113,
14,
647,
1040,
503,
1124,
9053,
14,
647,
1040,
14404,
314,
1414,
1021,
2126,
436,
4882,
2399,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
14,
339,
499,
14,
710,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
4882,
1124,
981,
63,
2087,
8497,
370,
664,
2126,
376,
1124,
14553,
1040,
367,
314,
2368,
12,
19953,
3062,
12,
18628,
2126,
1263,
3734,
4493,
5839,
701,
1511,
2839,
2126,
1124,
1548,
515,
4542,
436,
2066,
4882,
314,
1124,
2526,
8497,
1083,
12,
2126,
9476,
314,
4565,
2368,
14,
339,
650,
14,
710,
1124,
2526,
8497,
1083,
12454,
370,
25176,
734,
314,
1414,
701,
2126,
6358,
314,
1124,
2479,
8497,
1083,
543,
314,
4565,
2368,
27,
1263,
2126,
1072,
13584,
701,
1124,
2479,
8497,
911,
506,
12487,
370,
4465,
2126,
1072,
436,
12,
340,
314,
1414,
365,
11619,
370,
7389,
282,
1853,
402,
2126,
5385,
9834,
12,
911,
506,
8072,
315,
1124,
15947,
1040,
436,
1124,
23446,
4345,
339,
841,
14,
982,
1124,
2479,
8497,
503,
1124,
2526,
8497,
4915,
1263,
1919,
334,
69,
14,
71,
14,
2126,
1124,
31542,
1040,
395,
1124,
1065,
63,
504,
63,
3020,
8497,
911,
221,
3140,
870,
376,
1125,
2126,
1245,
370,
1124,
3083,
4345,
339,
20227,
12,
314,
1124,
2479,
8497,
1083,
365,
13609,
314,
6617,
2376,
367,
272,
9180,
27,
5002,
6137,
13,
262,
3718,
436,
1414,
2943,
1902,
4192,
272,
1006,
402,
3932,
9661,
315,
1124,
2479,
22524,
503,
5147,
2005,
4722,
272,
6057,
1736,
315,
1124,
2479,
8497,
436,
2066,
13080,
687,
652,
370,
1655,
272,
27877,
3102,
465,
4346,
14,
339,
3240,
422,
279,
3004,
12787,
5953,
737,
7750,
7124,
3180,
314,
4340,
26,
339,
1124,
589,
1040,
267,
437,
1059,
13778,
314,
2368,
10226,
701,
314,
1414,
12,
267,
11233,
367,
675,
315,
1720,
3788,
27,
325,
14,
71,
2020,
282,
1414,
1314,
6181,
267,
282,
769,
402,
4223,
1561,
5594,
663,
642,
370,
2650,
21653,
267,
20268,
2263,
22936,
339,
1124,
2425,
63,
646,
63,
1751,
1040,
267,
437,
5046,
9297,
3775,
314,
1414,
4839,
370,
506,
7688,
370,
267,
492,
5634,
2202,
27,
340,
1124,
549,
4542,
1124,
2526,
8497,
911,
4911,
267,
626,
642,
365,
3962,
2544,
20320,
316,
14,
3758,
574,
365,
267,
1124,
549,
4345,
339,
1124,
3437,
1040,
267,
437,
3974,
1369,
402,
314,
1414,
12,
1314,
911,
506,
12487,
315,
267,
1720,
3788,
14,
339,
1124,
1422,
63,
513,
1040,
267,
961,
365,
314,
769,
402,
1124,
2992,
1122,
1040,
1511,
1314,
911,
506,
23036
] |
[
199,
1563,
3992,
367,
3575,
10041,
3718,
334,
4579,
3718,
1314,
883,
199,
1235,
7934,
4012,
1124,
1176,
13,
2113,
14,
647,
1040,
503,
1124,
9053,
14,
647,
20008,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
199,
504,
8691,
492,
1852,
63,
1422,
12,
13491,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
4174,
492,
5228,
421,
199,
533,
14393,
8,
1726,
304,
272,
408,
272,
2186,
1021,
9297,
282,
5160,
1830,
14043,
282,
10041,
272,
1414,
14,
339,
982,
642,
1919,
365,
4915,
5309,
314,
6451,
402,
282,
10041,
272,
1414,
12,
652,
911,
506,
15604,
436,
19136,
1901,
282,
14213,
590,
13,
27131,
1125,
272,
1245,
370,
314,
5827,
1072,
2547,
334,
73,
14,
69,
2020,
4635,
2736,
465,
282,
272,
754,
12,
17026,
642,
1919,
334,
1045,
282,
27962,
1369,
402,
314,
272,
1125,
9,
365,
314,
14388,
4340,
370,
6623,
626,
6020,
965,
21737,
272,
6835,
315,
314,
6451,
402,
282,
1414,
14,
339,
408,
272,
986,
421,
199,
318,
2429,
63,
885,
63,
1419,
8,
1419,
304,
272,
408,
272,
15783,
1263,
849,
1511,
626,
1006,
3718,
1077,
4729,
2348,
272,
880,
626,
8259,
17505,
883,
2429,
3062,
2544,
18112,
367,
272,
922,
3718,
14,
339,
408,
272,
340,
1511,
14,
1751,
26,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
1511,
14,
1751,
272,
340,
1511,
14,
1548,
515,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1511,
14,
1548,
515,
9,
421,
199,
533,
7242,
4590,
8,
785,
304,
272,
408,
272,
21947,
6818,
3839,
15,
3083,
272,
408,
272,
347,
636,
826,
721,
277,
12,
734,
12,
3449,
63,
1532,
29,
403,
12,
13401,
17115,
78,
735,
267,
291,
423,
548,
275,
734,
267,
291,
14,
2487,
63,
1532,
275,
488,
267,
340,
2688,
8,
548,
12,
283,
21122,
358,
436,
734,
14,
21122,
837,
288,
291,
14,
2487,
63,
1532,
275,
3449,
63,
1532,
267,
291,
14,
3219,
275,
13401,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
423,
548,
12,
536,
9,
339,
347,
2218,
8,
277,
12,
1499,
12,
3449,
63,
1532,
29,
403,
12,
13401,
29,
403,
304,
267,
13401,
275,
291,
14,
3219,
340,
13401,
365,
488,
587,
13401,
267,
340,
13401,
436,
440,
1499,
14,
4130,
8,
3219,
304,
288,
1499,
847,
13401,
267,
3449,
63,
1532,
275,
359,
70,
367,
289,
315,
334,
2487,
63,
1532,
12,
291,
14,
2487,
63,
1532,
12,
2400,
671,
26,
88,
9,
1993,
340,
289,
365,
440,
488,
1527,
16,
61,
267,
291,
423,
548,
14,
952,
8,
3990,
63,
495,
8,
2487,
63,
1532,
8,
1328,
1724,
421,
199,
533,
22239,
8,
785,
304,
272,
408,
272,
710,
1300,
1021,
687,
1314,
1006,
10041,
3718,
221,
1141,
77,
13824,
272,
23519,
14,
339,
3645,
642,
1021,
340,
1265,
2934,
2879,
370,
1006,
402,
314,
562,
10832,
706,
1314,
272,
2198,
314,
1414,
13,
604,
2368,
436,
1736,
734,
4052,
1233,
370,
1240,
315,
272,
1177,
27,
340,
1265,
2793,
1133,
1929,
370,
1570,
1263,
402,
626,
5953,
12,
272,
11201,
1808,
1373,
402,
314,
9180,
3247,
315,
642,
570,
14,
339,
982,
1265,
787,
22201,
315,
18972,
15,
4229,
9147,
7750,
17435,
83,
402,
272,
314,
1414,
13,
11059,
436,
446,
9416,
5953,
12,
314,
3293,
6369,
5419,
272,
465,
11924,
26,
339,
413,
14,
1124,
1176,
13,
2113,
14,
647,
1040,
503,
1124,
9053,
14,
647,
1040,
14404,
314,
1414,
1021,
2126,
436,
4882,
2399,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
14,
339,
499,
14,
710,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
4882,
1124,
981,
63,
2087,
8497,
370,
664,
2126,
376,
1124,
14553,
1040,
367,
314,
2368,
12,
19953,
3062,
12,
18628,
2126,
1263,
3734,
4493,
5839,
701,
1511,
2839,
2126,
1124,
1548,
515,
4542,
436,
2066,
4882,
314,
1124,
2526,
8497,
1083,
12,
2126,
9476,
314,
4565,
2368,
14,
339,
650,
14,
710,
1124,
2526,
8497,
1083,
12454,
370,
25176,
734,
314,
1414,
701,
2126,
6358,
314,
1124,
2479,
8497,
1083,
543,
314,
4565,
2368,
27,
1263,
2126,
1072,
13584,
701,
1124,
2479,
8497,
911,
506,
12487,
370,
4465,
2126,
1072,
436,
12,
340,
314,
1414,
365,
11619,
370,
7389,
282,
1853,
402,
2126,
5385,
9834,
12,
911,
506,
8072,
315,
1124,
15947,
1040,
436,
1124,
23446,
4345,
339,
841,
14,
982,
1124,
2479,
8497,
503,
1124,
2526,
8497,
4915,
1263,
1919,
334,
69,
14,
71,
14,
2126,
1124,
31542,
1040,
395,
1124,
1065,
63,
504,
63,
3020,
8497,
911,
221,
3140,
870,
376,
1125,
2126,
1245,
370,
1124,
3083,
4345,
339,
20227,
12,
314,
1124,
2479,
8497,
1083,
365,
13609,
314,
6617,
2376,
367,
272,
9180,
27,
5002,
6137,
13,
262,
3718,
436,
1414,
2943,
1902,
4192,
272,
1006,
402,
3932,
9661,
315,
1124,
2479,
22524,
503,
5147,
2005,
4722,
272,
6057,
1736,
315,
1124,
2479,
8497,
436,
2066,
13080,
687,
652,
370,
1655,
272,
27877,
3102,
465,
4346,
14,
339,
3240,
422,
279,
3004,
12787,
5953,
737,
7750,
7124,
3180,
314,
4340,
26,
339,
1124,
589,
1040,
267,
437,
1059,
13778,
314,
2368,
10226,
701,
314,
1414,
12,
267,
11233,
367,
675,
315,
1720,
3788,
27,
325,
14,
71,
2020,
282,
1414,
1314,
6181,
267,
282,
769,
402,
4223,
1561,
5594,
663,
642,
370,
2650,
21653,
267,
20268,
2263,
22936,
339,
1124,
2425,
63,
646,
63,
1751,
1040,
267,
437,
5046,
9297,
3775,
314,
1414,
4839,
370,
506,
7688,
370,
267,
492,
5634,
2202,
27,
340,
1124,
549,
4542,
1124,
2526,
8497,
911,
4911,
267,
626,
642,
365,
3962,
2544,
20320,
316,
14,
3758,
574,
365,
267,
1124,
549,
4345,
339,
1124,
3437,
1040,
267,
437,
3974,
1369,
402,
314,
1414,
12,
1314,
911,
506,
12487,
315,
267,
1720,
3788,
14,
339,
1124,
1422,
63,
513,
1040,
267,
961,
365,
314,
769,
402,
1124,
2992,
1122,
1040,
1511,
1314,
911,
506,
23036,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wiki2014/Learning-Summary
|
alps/build/tools/releasetools/test_rangelib.py
|
1
|
5541
|
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import unittest
from rangelib import RangeSet
class RangeSetTest(unittest.TestCase):
def test_union(self):
self.assertEqual(RangeSet("10-19 30-34").union(RangeSet("18-29")),
RangeSet("10-34"))
self.assertEqual(RangeSet("10-19 30-34").union(RangeSet("22 32")),
RangeSet("10-19 22 30-34"))
def test_intersect(self):
self.assertEqual(RangeSet("10-19 30-34").intersect(RangeSet("18-32")),
RangeSet("18-19 30-32"))
self.assertEqual(RangeSet("10-19 30-34").intersect(RangeSet("22-28")),
RangeSet(""))
def test_subtract(self):
self.assertEqual(RangeSet("10-19 30-34").subtract(RangeSet("18-32")),
RangeSet("10-17 33-34"))
self.assertEqual(RangeSet("10-19 30-34").subtract(RangeSet("22-28")),
RangeSet("10-19 30-34"))
def test_overlaps(self):
self.assertTrue(RangeSet("10-19 30-34").overlaps(RangeSet("18-32")))
self.assertFalse(RangeSet("10-19 30-34").overlaps(RangeSet("22-28")))
def test_size(self):
self.assertEqual(RangeSet("10-19 30-34").size(), 15)
self.assertEqual(RangeSet("").size(), 0)
def test_map_within(self):
self.assertEqual(RangeSet("0-9").map_within(RangeSet("3-4")),
RangeSet("3-4"))
self.assertEqual(RangeSet("10-19").map_within(RangeSet("13-14")),
RangeSet("3-4"))
self.assertEqual(
RangeSet("10-19 30-39").map_within(RangeSet("17-19 30-32")),
RangeSet("7-12"))
self.assertEqual(
RangeSet("10-19 30-39").map_within(RangeSet("12-13 17-19 30-32")),
RangeSet("2-3 7-12"))
def test_first(self):
self.assertEqual(RangeSet("0-9").first(1), RangeSet("0"))
self.assertEqual(RangeSet("10-19").first(5), RangeSet("10-14"))
self.assertEqual(RangeSet("10-19").first(15), RangeSet("10-19"))
self.assertEqual(RangeSet("10-19 30-39").first(3), RangeSet("10-12"))
self.assertEqual(RangeSet("10-19 30-39").first(15),
RangeSet("10-19 30-34"))
self.assertEqual(RangeSet("10-19 30-39").first(30),
RangeSet("10-19 30-39"))
self.assertEqual(RangeSet("0-9").first(0), RangeSet(""))
def test_extend(self):
self.assertEqual(RangeSet("0-9").extend(1), RangeSet("0-10"))
self.assertEqual(RangeSet("10-19").extend(15), RangeSet("0-34"))
self.assertEqual(RangeSet("10-19 30-39").extend(4), RangeSet("6-23 26-43"))
self.assertEqual(RangeSet("10-19 30-39").extend(10), RangeSet("0-49"))
def test_equality(self):
self.assertTrue(RangeSet("") == RangeSet(""))
self.assertTrue(RangeSet("3") == RangeSet("3"))
self.assertTrue(RangeSet("3 5") == RangeSet("5 3"))
self.assertTrue(
RangeSet("10-19 30-39") == RangeSet("30-32 10-14 33-39 15-19"))
self.assertTrue(RangeSet("") != RangeSet("3"))
self.assertTrue(RangeSet("10-19") != RangeSet("10-19 20"))
self.assertFalse(RangeSet(""))
self.assertTrue(RangeSet("3"))
def test_init(self):
self.assertIsNotNone(RangeSet(""))
self.assertIsNotNone(RangeSet("3"))
self.assertIsNotNone(RangeSet("3 5"))
self.assertIsNotNone(RangeSet("10 19 30-39"))
with self.assertRaises(AssertionError):
RangeSet(data=[0])
def test_str(self):
self.assertEqual(str(RangeSet("0-9")), "0-9")
self.assertEqual(str(RangeSet("2-10 12")), "2-10 12")
self.assertEqual(str(RangeSet("11 2-10 12 1 0")), "0-12")
self.assertEqual(str(RangeSet("")), "empty")
def test_to_string_raw(self):
self.assertEqual(RangeSet("0-9").to_string_raw(), "2,0,10")
self.assertEqual(RangeSet("2-10 12").to_string_raw(), "4,2,11,12,13")
self.assertEqual(RangeSet("11 2-10 12 1 0").to_string_raw(), "2,0,13")
with self.assertRaises(AssertionError):
RangeSet("").to_string_raw()
def test_monotonic(self):
self.assertTrue(RangeSet("0-9").monotonic)
self.assertTrue(RangeSet("2-9").monotonic)
self.assertTrue(RangeSet("2-9 30 31 35").monotonic)
self.assertTrue(RangeSet("").monotonic)
self.assertTrue(RangeSet("0-4 5-9").monotonic)
self.assertFalse(RangeSet("5-9 0-4").monotonic)
self.assertFalse(RangeSet("258768-259211 196604").monotonic)
self.assertTrue(RangeSet(data=[0, 10]).monotonic)
self.assertTrue(RangeSet(data=[0, 10, 15, 20]).monotonic)
self.assertTrue(RangeSet(data=[2, 9, 30, 31, 31, 32, 35, 36]).monotonic)
self.assertTrue(RangeSet(data=[0, 5, 5, 10]).monotonic)
self.assertFalse(RangeSet(data=[5, 10, 0, 5]).monotonic)
def test_next_item(self):
self.assertEqual(
list(RangeSet("0-9").next_item()),
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
self.assertEqual(
list(RangeSet("10-19 3-5").next_item()),
[3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
self.assertEqual(
list(RangeSet("10-19 3 5 7").next_item()),
[3, 5, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
|
gpl-3.0
|
[
3,
199,
3,
1898,
334,
35,
9,
6900,
710,
14694,
3232,
5800,
7290,
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,
3,
199,
199,
646,
2882,
199,
199,
504,
1425,
773,
492,
13114,
1084,
199,
199,
533,
13114,
1084,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
63,
8888,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
8888,
8,
4709,
1084,
480,
1085,
13,
1398,
8150,
2151,
13114,
1084,
480,
709,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
8888,
8,
4709,
1084,
480,
1081,
4337,
8150,
2151,
13114,
1084,
480,
709,
13,
1167,
6928,
4233,
13,
1082,
2237,
819,
347,
511,
63,
23149,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
23149,
8,
4709,
1084,
480,
1085,
13,
708,
8150,
2151,
13114,
1084,
480,
1085,
13,
1167,
4233,
13,
708,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
23149,
8,
4709,
1084,
480,
1081,
13,
1651,
8150,
2151,
13114,
1084,
31348,
819,
347,
511,
63,
25719,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
25719,
8,
4709,
1084,
480,
1085,
13,
708,
8150,
2151,
13114,
1084,
480,
709,
13,
1196,
9404,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
25719,
8,
4709,
1084,
480,
1081,
13,
1651,
8150,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
2237,
819,
347,
511,
63,
20798,
8,
277,
304,
272,
291,
14,
1815,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
20798,
8,
4709,
1084,
480,
1085,
13,
708,
13324,
272,
291,
14,
3334,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
20798,
8,
4709,
1084,
480,
1081,
13,
1651,
13324,
819,
347,
511,
63,
890,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
890,
1062,
4114,
9,
272,
291,
14,
629,
8,
4709,
1084,
25639,
890,
1062,
378,
9,
819,
347,
511,
63,
1130,
63,
12541,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
19,
13,
20,
8150,
2151,
13114,
1084,
480,
19,
13,
20,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
969,
13,
1079,
8150,
2151,
13114,
1084,
480,
19,
13,
20,
2237,
272,
291,
14,
629,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
1196,
13,
1167,
4233,
13,
708,
8150,
267,
13114,
1084,
480,
23,
13,
713,
2237,
272,
291,
14,
629,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
713,
13,
969,
5557,
13,
1167,
4233,
13,
708,
8150,
267,
13114,
1084,
480,
18,
13,
19,
1520,
13,
713,
2237,
819,
347,
511,
63,
2246,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2246,
8,
17,
395,
13114,
1084,
480,
16,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2246,
8,
21,
395,
13114,
1084,
480,
709,
13,
1079,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2246,
8,
1046,
395,
13114,
1084,
480,
709,
13,
1167,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
19,
395,
13114,
1084,
480,
709,
13,
713,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
1046,
395,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
1216,
395,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2246,
8,
16,
395,
13114,
1084,
31348,
819,
347,
511,
63,
2880,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2880,
8,
17,
395,
13114,
1084,
480,
16,
13,
709,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2880,
8,
1046,
395,
13114,
1084,
480,
16,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2880,
8,
20,
395,
13114,
1084,
480,
22,
13,
1789,
7875,
13,
2824,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2880,
8,
709,
395,
13114,
1084,
480,
16,
13,
1887,
2237,
819,
347,
511,
63,
20982,
8,
277,
304,
272,
291,
14,
1815,
8,
4709,
1084,
10804,
508,
13114,
1084,
31348,
272,
291,
14,
1815,
8,
4709,
1084,
480,
19,
531,
508,
13114,
1084,
480,
19,
2237,
272,
291,
14,
1815,
8,
4709,
1084,
480,
19,
959,
531,
508,
13114,
1084,
480,
21,
650,
2237,
272,
291,
14,
1815,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
531,
508,
13114,
1084,
480,
1216,
13,
708,
1616,
13,
1079,
9404,
13,
1355,
4114,
13,
1167,
2237,
272,
291,
14,
1815,
8,
4709
] |
[
199,
3,
1898,
334,
35,
9,
6900,
710,
14694,
3232,
5800,
7290,
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,
3,
199,
199,
646,
2882,
199,
199,
504,
1425,
773,
492,
13114,
1084,
199,
199,
533,
13114,
1084,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
63,
8888,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
8888,
8,
4709,
1084,
480,
1085,
13,
1398,
8150,
2151,
13114,
1084,
480,
709,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
8888,
8,
4709,
1084,
480,
1081,
4337,
8150,
2151,
13114,
1084,
480,
709,
13,
1167,
6928,
4233,
13,
1082,
2237,
819,
347,
511,
63,
23149,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
23149,
8,
4709,
1084,
480,
1085,
13,
708,
8150,
2151,
13114,
1084,
480,
1085,
13,
1167,
4233,
13,
708,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
23149,
8,
4709,
1084,
480,
1081,
13,
1651,
8150,
2151,
13114,
1084,
31348,
819,
347,
511,
63,
25719,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
25719,
8,
4709,
1084,
480,
1085,
13,
708,
8150,
2151,
13114,
1084,
480,
709,
13,
1196,
9404,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
25719,
8,
4709,
1084,
480,
1081,
13,
1651,
8150,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
2237,
819,
347,
511,
63,
20798,
8,
277,
304,
272,
291,
14,
1815,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
20798,
8,
4709,
1084,
480,
1085,
13,
708,
13324,
272,
291,
14,
3334,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
20798,
8,
4709,
1084,
480,
1081,
13,
1651,
13324,
819,
347,
511,
63,
890,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
3471,
890,
1062,
4114,
9,
272,
291,
14,
629,
8,
4709,
1084,
25639,
890,
1062,
378,
9,
819,
347,
511,
63,
1130,
63,
12541,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
19,
13,
20,
8150,
2151,
13114,
1084,
480,
19,
13,
20,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
969,
13,
1079,
8150,
2151,
13114,
1084,
480,
19,
13,
20,
2237,
272,
291,
14,
629,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
1196,
13,
1167,
4233,
13,
708,
8150,
267,
13114,
1084,
480,
23,
13,
713,
2237,
272,
291,
14,
629,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
1130,
63,
12541,
8,
4709,
1084,
480,
713,
13,
969,
5557,
13,
1167,
4233,
13,
708,
8150,
267,
13114,
1084,
480,
18,
13,
19,
1520,
13,
713,
2237,
819,
347,
511,
63,
2246,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2246,
8,
17,
395,
13114,
1084,
480,
16,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2246,
8,
21,
395,
13114,
1084,
480,
709,
13,
1079,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2246,
8,
1046,
395,
13114,
1084,
480,
709,
13,
1167,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
19,
395,
13114,
1084,
480,
709,
13,
713,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
1046,
395,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2246,
8,
1216,
395,
2151,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2246,
8,
16,
395,
13114,
1084,
31348,
819,
347,
511,
63,
2880,
8,
277,
304,
272,
291,
14,
629,
8,
4709,
1084,
480,
16,
13,
25,
3471,
2880,
8,
17,
395,
13114,
1084,
480,
16,
13,
709,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
3471,
2880,
8,
1046,
395,
13114,
1084,
480,
16,
13,
1082,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2880,
8,
20,
395,
13114,
1084,
480,
22,
13,
1789,
7875,
13,
2824,
2237,
272,
291,
14,
629,
8,
4709,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
3471,
2880,
8,
709,
395,
13114,
1084,
480,
16,
13,
1887,
2237,
819,
347,
511,
63,
20982,
8,
277,
304,
272,
291,
14,
1815,
8,
4709,
1084,
10804,
508,
13114,
1084,
31348,
272,
291,
14,
1815,
8,
4709,
1084,
480,
19,
531,
508,
13114,
1084,
480,
19,
2237,
272,
291,
14,
1815,
8,
4709,
1084,
480,
19,
959,
531,
508,
13114,
1084,
480,
21,
650,
2237,
272,
291,
14,
1815,
8,
267,
13114,
1084,
480,
709,
13,
1167,
4233,
13,
1355,
531,
508,
13114,
1084,
480,
1216,
13,
708,
1616,
13,
1079,
9404,
13,
1355,
4114,
13,
1167,
2237,
272,
291,
14,
1815,
8,
4709,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CythonAI/1.1.0-0001
|
src/feed_scanner.py
|
4
|
3087
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from likers_graber_protocol import likers_graber_protocol
from new_auto_mod_unfollow2 import new_auto_mod_unfollow2
from recent_feed import get_media_id_recent_feed
from user_feed import get_media_id_user_feed
def feed_scanner(self):
#This is to limit how many people do you want to put into list before
##The bot start to check their profile one by one and start following them
limit = random.randint(51, 90)
while len(self.user_info_list) < limit:
#First the bot try to collect media id on your recent feed
get_media_id_recent_feed(self)
#If your account is old enough, there will be 24 photos on your recent feed
if len(self.media_on_feed) > 23:
#Select the media on your recent feed randomly
chooser = random.randint(0, len(self.media_on_feed) - 1)
#The bot will save the owner of the media name and use it to try checking his/her profile
self.current_user = self.media_on_feed[chooser]["node"]["owner"][
"id"]
self.current_id = self.media_on_feed[chooser]["node"]["owner"][
"id"]
#If your account is new, and you don't following anyone, your recent feed will be empty
else:
#If your recent feed is empty, then you start collecting media id by hashtag
self.is_by_tag = True
get_media_id_user_feed(self)
max_media = 0
while len(self.media_on_feed) > 5 and max_media < 5:
chooser = random.randint(0, len(self.media_on_feed) - 1)
self.current_id = self.media_on_feed[chooser]["node"]["owner"][
"id"]
self.follow(self.current_id)
self.media_on_feed[chooser] = None
max_media += 1
time.sleep(30)
self.is_by_tag = False
self.media_on_feed = []
if len(self.user_info_list) < 10000:
for index in range(len(self.ex_user_list)):
if self.ex_user_list[index][0] in self.current_user:
print(
'============================== \nUpss ' +
self.current_user +
' is already in ex user list... \n=============================='
)
break
else:
likers_graber_protocol(self)
self.ex_user_list.append([self.current_user, self.current_id])
self.user_list = []
self.media_by_user = []
self.media_on_feed = []
if len(self.ex_user_list) > 20:
chooser = random.randint(0, len(self.ex_user_list) - 1)
self.current_user = self.ex_user_list[chooser][0]
self.current_id = self.ex_user_list[chooser][1]
print('Trying to unfollow : ' + self.current_user)
new_auto_mod_unfollow2(self)
del self.ex_user_list[chooser]
time.sleep(random.randint(15, 22))
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2196,
199,
646,
900,
199,
199,
504,
1212,
75,
1192,
63,
926,
605,
63,
3922,
492,
1212,
75,
1192,
63,
926,
605,
63,
3922,
199,
504,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
492,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
199,
504,
8058,
63,
3871,
492,
664,
63,
4603,
63,
344,
63,
14951,
63,
3871,
199,
504,
922,
63,
3871,
492,
664,
63,
4603,
63,
344,
63,
751,
63,
3871,
421,
199,
318,
4733,
63,
16378,
8,
277,
304,
272,
327,
2765,
365,
370,
2304,
4212,
5002,
13135,
886,
1265,
2934,
370,
5324,
1901,
769,
2544,
272,
925,
1918,
5888,
1343,
370,
1104,
3932,
4690,
1373,
701,
1373,
436,
1343,
2569,
3062,
272,
2304,
275,
2196,
14,
8393,
8,
2869,
12,
9137,
9,
272,
1830,
822,
8,
277,
14,
751,
63,
815,
63,
513,
9,
665,
2304,
26,
267,
327,
7147,
314,
5888,
862,
370,
8775,
5898,
1305,
641,
2195,
8058,
4733,
267,
664,
63,
4603,
63,
344,
63,
14951,
63,
3871,
8,
277,
9,
267,
327,
3917,
2195,
2933,
365,
2269,
8321,
12,
2337,
911,
506,
5504,
3945,
17278,
641,
2195,
8058,
4733,
267,
340,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
690,
6546,
26,
288,
327,
5446,
314,
5898,
641,
2195,
8058,
4733,
19311,
288,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
446,
413,
9,
288,
327,
1918,
5888,
911,
3354,
314,
5771,
402,
314,
5898,
536,
436,
675,
652,
370,
862,
7907,
17049,
15,
2523,
4690,
288,
291,
14,
1818,
63,
751,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
355,
298,
344,
937,
288,
291,
14,
1818,
63,
344,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
355,
298,
344,
937,
398,
327,
3917,
2195,
2933,
365,
892,
12,
436,
1265,
2793,
1133,
2569,
29165,
12,
2195,
8058,
4733,
911,
506,
2701,
267,
587,
26,
288,
327,
3917,
2195,
8058,
4733,
365,
2701,
12,
2066,
1265,
1343,
32223,
5898,
1305,
701,
2631,
1450,
288,
291,
14,
374,
63,
991,
63,
1450,
275,
715,
288,
664,
63,
4603,
63,
344,
63,
751,
63,
3871,
8,
277,
9,
288,
1390,
63,
4603,
275,
378,
288,
1830,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
690,
959,
436,
1390,
63,
4603,
665,
959,
26,
355,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
446,
413,
9,
355,
291,
14,
1818,
63,
344,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
490,
298,
344,
937,
355,
291,
14,
7207,
8,
277,
14,
1818,
63,
344,
9,
355,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
61,
275,
488,
355,
1390,
63,
4603,
847,
413,
355,
900,
14,
4532,
8,
1216,
9,
288,
291,
14,
374,
63,
991,
63,
1450,
275,
756,
288,
291,
14,
4603,
63,
265,
63,
3871,
275,
942,
267,
340,
822,
8,
277,
14,
751,
63,
815,
63,
513,
9,
665,
11630,
26,
288,
367,
1478,
315,
1425,
8,
552,
8,
277,
14,
476,
63,
751,
63,
513,
2298,
355,
340,
291,
14,
476,
63,
751,
63,
513,
59,
1080,
1527,
16,
61,
315,
291,
14,
1818,
63,
751,
26,
490,
870,
8,
717,
283,
1280,
17224,
971,
78,
1721,
385,
283,
435,
717,
291,
14,
1818,
63,
751,
435,
717,
283,
365,
2575,
315,
444,
922,
769,
1396,
971,
78,
1280,
5769,
6803,
490,
776,
490,
2059,
288,
587,
26,
355,
1212,
75,
1192,
63,
926,
605,
63,
3922,
8,
277,
9,
355,
291,
14,
476,
63,
751,
63,
513,
14,
740,
779,
277,
14,
1818,
63,
751,
12,
291,
14,
1818,
63,
344,
566,
288,
291,
14,
751,
63,
513,
275,
942,
288,
291,
14,
4603,
63,
991,
63,
751,
275,
942,
288,
291,
14,
4603,
63,
265,
63,
3871,
275,
942,
398,
340,
822,
8,
277,
14,
476,
63,
751,
63,
513,
9,
690,
3388,
26,
288,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
476,
63,
751,
63,
513,
9,
446,
413,
9,
288,
291,
14,
1818,
63,
751,
275,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
1527,
16,
61,
288,
291,
14,
1818,
63,
344,
275,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
1527,
17,
61,
288,
870,
360,
27693,
370,
625,
7207,
520,
283,
435,
291,
14,
1818,
63,
751,
9,
288,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
8,
277,
9,
288,
2150,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
61,
267,
900,
14,
4532,
8,
2355,
14,
8393,
8,
1046,
12,
6928,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2196,
199,
646,
900,
199,
199,
504,
1212,
75,
1192,
63,
926,
605,
63,
3922,
492,
1212,
75,
1192,
63,
926,
605,
63,
3922,
199,
504,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
492,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
199,
504,
8058,
63,
3871,
492,
664,
63,
4603,
63,
344,
63,
14951,
63,
3871,
199,
504,
922,
63,
3871,
492,
664,
63,
4603,
63,
344,
63,
751,
63,
3871,
421,
199,
318,
4733,
63,
16378,
8,
277,
304,
272,
327,
2765,
365,
370,
2304,
4212,
5002,
13135,
886,
1265,
2934,
370,
5324,
1901,
769,
2544,
272,
925,
1918,
5888,
1343,
370,
1104,
3932,
4690,
1373,
701,
1373,
436,
1343,
2569,
3062,
272,
2304,
275,
2196,
14,
8393,
8,
2869,
12,
9137,
9,
272,
1830,
822,
8,
277,
14,
751,
63,
815,
63,
513,
9,
665,
2304,
26,
267,
327,
7147,
314,
5888,
862,
370,
8775,
5898,
1305,
641,
2195,
8058,
4733,
267,
664,
63,
4603,
63,
344,
63,
14951,
63,
3871,
8,
277,
9,
267,
327,
3917,
2195,
2933,
365,
2269,
8321,
12,
2337,
911,
506,
5504,
3945,
17278,
641,
2195,
8058,
4733,
267,
340,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
690,
6546,
26,
288,
327,
5446,
314,
5898,
641,
2195,
8058,
4733,
19311,
288,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
446,
413,
9,
288,
327,
1918,
5888,
911,
3354,
314,
5771,
402,
314,
5898,
536,
436,
675,
652,
370,
862,
7907,
17049,
15,
2523,
4690,
288,
291,
14,
1818,
63,
751,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
355,
298,
344,
937,
288,
291,
14,
1818,
63,
344,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
355,
298,
344,
937,
398,
327,
3917,
2195,
2933,
365,
892,
12,
436,
1265,
2793,
1133,
2569,
29165,
12,
2195,
8058,
4733,
911,
506,
2701,
267,
587,
26,
288,
327,
3917,
2195,
8058,
4733,
365,
2701,
12,
2066,
1265,
1343,
32223,
5898,
1305,
701,
2631,
1450,
288,
291,
14,
374,
63,
991,
63,
1450,
275,
715,
288,
664,
63,
4603,
63,
344,
63,
751,
63,
3871,
8,
277,
9,
288,
1390,
63,
4603,
275,
378,
288,
1830,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
690,
959,
436,
1390,
63,
4603,
665,
959,
26,
355,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
4603,
63,
265,
63,
3871,
9,
446,
413,
9,
355,
291,
14,
1818,
63,
344,
275,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
7541,
932,
6611,
4597,
9210,
490,
298,
344,
937,
355,
291,
14,
7207,
8,
277,
14,
1818,
63,
344,
9,
355,
291,
14,
4603,
63,
265,
63,
3871,
59,
31123,
61,
275,
488,
355,
1390,
63,
4603,
847,
413,
355,
900,
14,
4532,
8,
1216,
9,
288,
291,
14,
374,
63,
991,
63,
1450,
275,
756,
288,
291,
14,
4603,
63,
265,
63,
3871,
275,
942,
267,
340,
822,
8,
277,
14,
751,
63,
815,
63,
513,
9,
665,
11630,
26,
288,
367,
1478,
315,
1425,
8,
552,
8,
277,
14,
476,
63,
751,
63,
513,
2298,
355,
340,
291,
14,
476,
63,
751,
63,
513,
59,
1080,
1527,
16,
61,
315,
291,
14,
1818,
63,
751,
26,
490,
870,
8,
717,
283,
1280,
17224,
971,
78,
1721,
385,
283,
435,
717,
291,
14,
1818,
63,
751,
435,
717,
283,
365,
2575,
315,
444,
922,
769,
1396,
971,
78,
1280,
5769,
6803,
490,
776,
490,
2059,
288,
587,
26,
355,
1212,
75,
1192,
63,
926,
605,
63,
3922,
8,
277,
9,
355,
291,
14,
476,
63,
751,
63,
513,
14,
740,
779,
277,
14,
1818,
63,
751,
12,
291,
14,
1818,
63,
344,
566,
288,
291,
14,
751,
63,
513,
275,
942,
288,
291,
14,
4603,
63,
991,
63,
751,
275,
942,
288,
291,
14,
4603,
63,
265,
63,
3871,
275,
942,
398,
340,
822,
8,
277,
14,
476,
63,
751,
63,
513,
9,
690,
3388,
26,
288,
2468,
13041,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
277,
14,
476,
63,
751,
63,
513,
9,
446,
413,
9,
288,
291,
14,
1818,
63,
751,
275,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
1527,
16,
61,
288,
291,
14,
1818,
63,
344,
275,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
1527,
17,
61,
288,
870,
360,
27693,
370,
625,
7207,
520,
283,
435,
291,
14,
1818,
63,
751,
9,
288,
892,
63,
2495,
63,
1494,
63,
324,
7207,
18,
8,
277,
9,
288,
2150,
291,
14,
476,
63,
751,
63,
513,
59,
31123,
61,
267,
900,
14,
4532,
8,
2355,
14,
8393,
8,
1046,
12,
6928,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dntt1/youtube-dl
|
youtube_dl/extractor/tf1.py
|
59
|
2239
|
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
class TF1IE(InfoExtractor):
"""TF1 uses the wat.tv player."""
_VALID_URL = r'https?://(?:(?:videos|www|lci)\.tf1|(?:www\.)?(?:tfou|ushuaiatv|histoire|tvbreizh))\.fr/(?:[^/]+/)*(?P<id>[^/?#.]+)'
_TESTS = [{
'url': 'http://videos.tf1.fr/auto-moto/citroen-grand-c4-picasso-2013-presentation-officielle-8062060.html',
'info_dict': {
'id': '10635995',
'ext': 'mp4',
'title': 'Citroën Grand C4 Picasso 2013 : présentation officielle',
'description': 'Vidéo officielle du nouveau Citroën Grand C4 Picasso, lancé à l\'automne 2013.',
},
'params': {
# Sometimes wat serves the whole file with the --test option
'skip_download': True,
},
}, {
'url': 'http://www.tfou.fr/chuggington/videos/le-grand-mysterioso-chuggington-7085291-739.html',
'info_dict': {
'id': 'le-grand-mysterioso-chuggington-7085291-739',
'ext': 'mp4',
'title': 'Le grand Mystérioso - Chuggington',
'description': 'Le grand Mystérioso - Emery rêve qu\'un article lui soit consacré dans le journal.',
'upload_date': '20150103',
},
'params': {
# Sometimes wat serves the whole file with the --test option
'skip_download': True,
},
'skip': 'HTTP Error 410: Gone',
}, {
'url': 'http://www.tf1.fr/tf1/koh-lanta/videos/replay-koh-lanta-22-mai-2015.html',
'only_matching': True,
}, {
'url': 'http://lci.tf1.fr/sept-a-huit/videos/sept-a-huit-du-24-mai-2015-8611550.html',
'only_matching': True,
}, {
'url': 'http://www.tf1.fr/hd1/documentaire/videos/mylene-farmer-d-une-icone.html',
'only_matching': True,
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
wat_id = self._html_search_regex(
r'(["\'])(?:https?:)?//www\.wat\.tv/embedframe/.*?(?P<id>\d{8})\1',
webpage, 'wat id', group='id')
return self.url_result('wat:%s' % wat_id, 'Wat')
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
21721,
17,
4332,
8,
18283,
304,
272,
408,
6145,
17,
4440,
314,
336,
292,
14,
6993,
7748,
1041,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
5169,
11418,
92,
1544,
92,
76,
559,
31477,
3249,
17,
92,
5169,
1544,
20316,
5169,
84,
545,
85,
92,
2084,
1458,
73,
292,
86,
92,
72,
7133,
3621,
92,
6993,
10205,
565,
72,
430,
4537,
4391,
32576,
26285,
15,
3342,
2229,
48,
28,
344,
13489,
10197,
31827,
29716,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
11418,
14,
3249,
17,
14,
4391,
15,
2495,
13,
77,
3459,
15,
67,
12691,
287,
13,
22655,
13,
67,
20,
13,
12475,
15923,
13,
6965,
13,
31993,
13,
1618,
4294,
352,
274,
13,
11901,
1165,
2259,
14,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
7357,
1276,
14732,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
35,
12691,
128,
105,
78,
598,
3759,
445,
20,
510,
530,
15923,
6171,
520,
5448,
5741,
1150,
425,
402,
4294,
352,
274,
297,
288,
283,
1802,
356,
283,
54,
344,
5741,
79,
402,
4294,
352,
274,
15776,
302,
810,
432,
3844,
445,
12691,
128,
105,
78,
598,
3759,
445,
20,
510,
530,
15923,
12,
634,
18595,
5741,
26031,
634,
3985,
6898,
676,
685,
6171,
3130,
267,
1660,
267,
283,
1162,
356,
469,
288,
327,
30094,
336,
292,
23739,
314,
8852,
570,
543,
314,
1553,
396,
945,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
84,
545,
85,
14,
4391,
15,
335,
1518,
1540,
1860,
15,
11418,
15,
274,
13,
22655,
13,
23726,
6236,
736,
79,
13,
335,
1518,
1540,
1860,
13,
23,
17494,
16319,
13,
32257,
14,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
274,
13,
22655,
13,
23726,
6236,
736,
79,
13,
335,
1518,
1540,
1860,
13,
23,
17494,
16319,
13,
32257,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
26881,
4932,
270,
5741,
322,
736,
79,
446,
2799,
1518,
1540,
1860,
297,
288,
283,
1802,
356,
283,
2553,
26881,
4932,
270,
5741,
322,
736,
79,
446,
662,
278,
651,
519,
28413,
432,
2173,
3985,
324,
9772,
634,
1907,
880,
390,
13447,
645,
82,
5741,
366,
796,
1026,
9605,
3130,
288,
283,
5064,
63,
602,
356,
283,
7806,
28399,
297,
267,
1660,
267,
283,
1162,
356,
469,
288,
327,
30094,
336,
292,
23739,
314,
8852,
570,
543,
314,
1553,
396,
945,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
1660,
267,
283,
2759,
356,
283,
2856,
4520,
32321,
26,
598,
368,
297,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3249,
17,
14,
4391,
15,
3249,
17,
15,
7697,
72,
13,
1502,
502,
15,
11418,
15,
19540,
13,
7697,
72,
13,
1502,
502,
13,
1081,
13,
391,
73,
13,
7806,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
76,
559,
14,
3249,
17,
14,
4391,
15,
261,
541,
13,
65,
13,
72,
4993,
15,
11418,
15,
261,
541,
13,
65,
13,
72,
4993,
13,
2033,
13,
1194,
13,
391,
73,
13,
7806,
13,
1184,
845,
16859,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3249,
17,
14,
4391,
15,
7952,
17,
15,
3554,
65,
3621,
15,
11418,
15,
1662,
23630,
13,
15315,
2626,
13,
68,
13,
11474,
13,
530,
368,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
336,
292,
63,
344,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
21731,
3212,
1105,
5169,
2859,
31,
26,
5547,
501,
1544,
4537,
87,
292,
4537,
6993,
15,
6427,
1943,
15,
6697,
2229,
48,
28,
344,
3072,
68,
91,
24,
30446,
17,
297,
288,
9248,
12,
283,
87,
292,
1305,
297,
1572,
534,
344,
358,
267,
372,
291,
14,
633,
63,
1099,
360,
87,
292,
2689,
83,
7,
450,
336,
292,
63,
344,
12,
283,
55,
292,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
21721,
17,
4332,
8,
18283,
304,
272,
408,
6145,
17,
4440,
314,
336,
292,
14,
6993,
7748,
1041,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
5169,
11418,
92,
1544,
92,
76,
559,
31477,
3249,
17,
92,
5169,
1544,
20316,
5169,
84,
545,
85,
92,
2084,
1458,
73,
292,
86,
92,
72,
7133,
3621,
92,
6993,
10205,
565,
72,
430,
4537,
4391,
32576,
26285,
15,
3342,
2229,
48,
28,
344,
13489,
10197,
31827,
29716,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
11418,
14,
3249,
17,
14,
4391,
15,
2495,
13,
77,
3459,
15,
67,
12691,
287,
13,
22655,
13,
67,
20,
13,
12475,
15923,
13,
6965,
13,
31993,
13,
1618,
4294,
352,
274,
13,
11901,
1165,
2259,
14,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
7357,
1276,
14732,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
35,
12691,
128,
105,
78,
598,
3759,
445,
20,
510,
530,
15923,
6171,
520,
5448,
5741,
1150,
425,
402,
4294,
352,
274,
297,
288,
283,
1802,
356,
283,
54,
344,
5741,
79,
402,
4294,
352,
274,
15776,
302,
810,
432,
3844,
445,
12691,
128,
105,
78,
598,
3759,
445,
20,
510,
530,
15923,
12,
634,
18595,
5741,
26031,
634,
3985,
6898,
676,
685,
6171,
3130,
267,
1660,
267,
283,
1162,
356,
469,
288,
327,
30094,
336,
292,
23739,
314,
8852,
570,
543,
314,
1553,
396,
945,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
84,
545,
85,
14,
4391,
15,
335,
1518,
1540,
1860,
15,
11418,
15,
274,
13,
22655,
13,
23726,
6236,
736,
79,
13,
335,
1518,
1540,
1860,
13,
23,
17494,
16319,
13,
32257,
14,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
274,
13,
22655,
13,
23726,
6236,
736,
79,
13,
335,
1518,
1540,
1860,
13,
23,
17494,
16319,
13,
32257,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
26881,
4932,
270,
5741,
322,
736,
79,
446,
2799,
1518,
1540,
1860,
297,
288,
283,
1802,
356,
283,
2553,
26881,
4932,
270,
5741,
322,
736,
79,
446,
662,
278,
651,
519,
28413,
432,
2173,
3985,
324,
9772,
634,
1907,
880,
390,
13447,
645,
82,
5741,
366,
796,
1026,
9605,
3130,
288,
283,
5064,
63,
602,
356,
283,
7806,
28399,
297,
267,
1660,
267,
283,
1162,
356,
469,
288,
327,
30094,
336,
292,
23739,
314,
8852,
570,
543,
314,
1553,
396,
945,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
1660,
267,
283,
2759,
356,
283,
2856,
4520,
32321,
26,
598,
368,
297,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3249,
17,
14,
4391,
15,
3249,
17,
15,
7697,
72,
13,
1502,
502,
15,
11418,
15,
19540,
13,
7697,
72,
13,
1502,
502,
13,
1081,
13,
391,
73,
13,
7806,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
76,
559,
14,
3249,
17,
14,
4391,
15,
261,
541,
13,
65,
13,
72,
4993,
15,
11418,
15,
261,
541,
13,
65,
13,
72,
4993,
13,
2033,
13,
1194,
13,
391,
73,
13,
7806,
13,
1184,
845,
16859,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3249,
17,
14,
4391,
15,
7952,
17,
15,
3554,
65,
3621,
15,
11418,
15,
1662,
23630,
13,
15315,
2626,
13,
68,
13,
11474,
13,
530,
368,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
336,
292,
63,
344,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
21731,
3212,
1105,
5169,
2859,
31,
26,
5547,
501,
1544,
4537,
87,
292,
4537,
6993,
15,
6427,
1943,
15,
6697,
2229,
48,
28,
344,
3072,
68,
91,
24,
30446,
17,
297,
288,
9248,
12,
283,
87,
292,
1305,
297,
1572,
534,
344,
358,
267,
372,
291,
14,
633,
63,
1099,
360,
87,
292,
2689,
83,
7,
450,
336,
292,
63,
344,
12,
283,
55,
292,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
softelnet/sponge
|
sponge-remote-api-integration-tests/examples/remote-api-server/remote_api_security.py
|
1
|
1483
|
"""
Sponge Knowledge Base
Remote API security
"""
from org.openksavi.sponge.remoteapi.server.security import User
# Simple access configuration: role -> knowledge base names regexps.
ROLES_TO_KB = { "admin":[".*"], "guest":["example"], "anonymous":["example"]}
# Simple access configuration: role -> event names regexps.
ROLES_TO_SEND_EVENT = { "admin":[".*"], "guest":[".*"], "anonymous":[]}
ROLES_TO_SUBSCRIBE_EVENT = { "admin":[".*"], "guest":[".*"], "anonymous":[".*"]}
class RemoteApiCanUseKnowledgeBase(Action):
def onCall(self, userContext, kbName):
return remoteApiServer.canAccessResource(ROLES_TO_KB, userContext, kbName)
class RemoteApiCanSendEvent(Action):
def onCall(self, userContext, eventName):
return remoteApiServer.canAccessResource(ROLES_TO_SEND_EVENT, userContext, eventName)
class RemoteApiCanSubscribeEvent(Action):
def onCall(self, userContext, eventName):
return remoteApiServer.canAccessResource(ROLES_TO_SUBSCRIBE_EVENT, userContext, eventName)
def onStartup():
# Set up users.
securityService = remoteApiServer.service.securityService
securityService.addUser(User("john", "f4f28d85c27f6038bbdd2c8c73c4c2d2ca21350b368431b641999d3f6e1a38a474bae4b6856556532b30fc36a72272be4922ebe3d3b720ee3224b6bb7ced79b4", ["admin"]))
securityService.addUser(User("joe", "babe834270d043648d757e2db838429a3eedd455cb9cd64b22b8e3914e1b4dd5f98fdd12f7fbd4556b45f82bf79f7d8e66798827a303bdac65eb93da75da9fc3", ["guest"]))
|
apache-2.0
|
[
624,
199,
51,
678,
303,
1804,
23504,
3523,
199,
6713,
3261,
6391,
199,
624,
199,
199,
504,
5981,
14,
1490,
75,
2231,
433,
14,
83,
678,
303,
14,
3846,
1246,
14,
1000,
14,
4416,
492,
2876,
199,
199,
3,
5870,
2879,
2897,
26,
4719,
1035,
29105,
1300,
1561,
5163,
1190,
14,
199,
6245,
654,
63,
2566,
63,
12780,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2694,
2255,
298,
12628,
582,
905,
2694,
27635,
199,
3,
5870,
2879,
2897,
26,
4719,
1035,
1566,
1561,
5163,
1190,
14,
199,
6245,
654,
63,
2566,
63,
20469,
63,
8193,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2795,
2255,
298,
12628,
582,
8607,
93,
199,
6245,
654,
63,
2566,
63,
6348,
51,
27448,
37,
63,
8193,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2795,
2255,
298,
12628,
582,
905,
2795,
27635,
199,
199,
533,
17283,
7394,
6049,
6119,
43,
23504,
1563,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
19932,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
12780,
12,
922,
2998,
12,
19932,
985,
9,
199,
199,
533,
17283,
7394,
6049,
6795,
2390,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
1566,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
20469,
63,
8193,
12,
922,
2998,
12,
1566,
985,
9,
199,
199,
533,
17283,
7394,
6049,
2610,
5355,
2390,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
1566,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
6348,
51,
27448,
37,
63,
8193,
12,
922,
2998,
12,
1566,
985,
9,
199,
199,
318,
641,
18515,
837,
272,
327,
2494,
1536,
4390,
14,
272,
6391,
3167,
275,
3982,
7394,
3120,
14,
1364,
14,
4416,
3167,
272,
6391,
3167,
14,
525,
1899,
8,
1899,
480,
20216,
401,
298,
70,
20,
70,
1651,
68,
2426,
67,
1465,
70,
22,
14273,
2501,
617,
18,
67,
24,
67,
2898,
67,
20,
67,
18,
68,
18,
696,
14271,
1400,
66,
1344,
1349,
2192,
66,
15233,
5637,
68,
19,
70,
22,
69,
17,
65,
1703,
65,
13818,
28363,
20,
66,
2333,
1367,
1229,
2182,
708,
66,
1216,
3003,
1344,
65,
24109,
2819,
1235,
1887,
1081,
69,
1235,
19,
68,
19,
66,
18386,
1024,
708,
1194,
66,
22,
2501,
23,
6867,
1965,
66,
20,
401,
2097,
2113,
13045,
272,
6391,
3167,
14,
525,
1899,
8,
1899,
480,
20241,
401,
298,
66,
7570,
31230,
13299,
68,
5882,
10552,
68,
32339,
69,
18,
697,
2658,
1349,
1398,
65,
19,
69,
31151,
13267,
2894,
25,
2866,
772,
66,
1081,
66,
24,
69,
1355,
1079,
69,
17,
66,
20,
617,
21,
70,
2905,
70,
617,
713,
70,
23,
17108,
13267,
22,
66,
2322,
70,
2564,
4361,
1965,
70,
23,
68,
24,
69,
1272,
1965,
1299,
1465,
65,
11810,
3691,
645,
2182,
2871,
3129,
983,
2194,
983,
25,
3003,
19,
401,
2097,
10409,
13045,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
51,
678,
303,
1804,
23504,
3523,
199,
6713,
3261,
6391,
199,
624,
199,
199,
504,
5981,
14,
1490,
75,
2231,
433,
14,
83,
678,
303,
14,
3846,
1246,
14,
1000,
14,
4416,
492,
2876,
199,
199,
3,
5870,
2879,
2897,
26,
4719,
1035,
29105,
1300,
1561,
5163,
1190,
14,
199,
6245,
654,
63,
2566,
63,
12780,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2694,
2255,
298,
12628,
582,
905,
2694,
27635,
199,
3,
5870,
2879,
2897,
26,
4719,
1035,
1566,
1561,
5163,
1190,
14,
199,
6245,
654,
63,
2566,
63,
20469,
63,
8193,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2795,
2255,
298,
12628,
582,
8607,
93,
199,
6245,
654,
63,
2566,
63,
6348,
51,
27448,
37,
63,
8193,
275,
469,
298,
2113,
582,
905,
2795,
2255,
298,
10409,
582,
905,
2795,
2255,
298,
12628,
582,
905,
2795,
27635,
199,
199,
533,
17283,
7394,
6049,
6119,
43,
23504,
1563,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
19932,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
12780,
12,
922,
2998,
12,
19932,
985,
9,
199,
199,
533,
17283,
7394,
6049,
6795,
2390,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
1566,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
20469,
63,
8193,
12,
922,
2998,
12,
1566,
985,
9,
199,
199,
533,
17283,
7394,
6049,
2610,
5355,
2390,
8,
3310,
304,
272,
347,
641,
2176,
8,
277,
12,
922,
2998,
12,
1566,
985,
304,
267,
372,
3982,
7394,
3120,
14,
2425,
3946,
4031,
8,
6245,
654,
63,
2566,
63,
6348,
51,
27448,
37,
63,
8193,
12,
922,
2998,
12,
1566,
985,
9,
199,
199,
318,
641,
18515,
837,
272,
327,
2494,
1536,
4390,
14,
272,
6391,
3167,
275,
3982,
7394,
3120,
14,
1364,
14,
4416,
3167,
272,
6391,
3167,
14,
525,
1899,
8,
1899,
480,
20216,
401,
298,
70,
20,
70,
1651,
68,
2426,
67,
1465,
70,
22,
14273,
2501,
617,
18,
67,
24,
67,
2898,
67,
20,
67,
18,
68,
18,
696,
14271,
1400,
66,
1344,
1349,
2192,
66,
15233,
5637,
68,
19,
70,
22,
69,
17,
65,
1703,
65,
13818,
28363,
20,
66,
2333,
1367,
1229,
2182,
708,
66,
1216,
3003,
1344,
65,
24109,
2819,
1235,
1887,
1081,
69,
1235,
19,
68,
19,
66,
18386,
1024,
708,
1194,
66,
22,
2501,
23,
6867,
1965,
66,
20,
401,
2097,
2113,
13045,
272,
6391,
3167,
14,
525,
1899,
8,
1899,
480,
20241,
401,
298,
66,
7570,
31230,
13299,
68,
5882,
10552,
68,
32339,
69,
18,
697,
2658,
1349,
1398,
65,
19,
69,
31151,
13267,
2894,
25,
2866,
772,
66,
1081,
66,
24,
69,
1355,
1079,
69,
17,
66,
20,
617,
21,
70,
2905,
70,
617,
713,
70,
23,
17108,
13267,
22,
66,
2322,
70,
2564,
4361,
1965,
70,
23,
68,
24,
69,
1272,
1965,
1299,
1465,
65,
11810,
3691,
645,
2182,
2871,
3129,
983,
2194,
983,
25,
3003,
19,
401,
2097,
10409,
13045,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bratsche/Neutron-Drive
|
google_appengine/lib/django_1_2/tests/modeltests/ordering/tests.py
|
92
|
4309
|
from datetime import datetime
from operator import attrgetter
from django.test import TestCase
from models import Article
class OrderingTests(TestCase):
def test_basic(self):
a1 = Article.objects.create(
headline="Article 1", pub_date=datetime(2005, 7, 26)
)
a2 = Article.objects.create(
headline="Article 2", pub_date=datetime(2005, 7, 27)
)
a3 = Article.objects.create(
headline="Article 3", pub_date=datetime(2005, 7, 27)
)
a4 = Article.objects.create(
headline="Article 4", pub_date=datetime(2005, 7, 28)
)
# By default, Article.objects.all() orders by pub_date descending, then
# headline ascending.
self.assertQuerysetEqual(
Article.objects.all(), [
"Article 4",
"Article 2",
"Article 3",
"Article 1",
],
attrgetter("headline")
)
# Override ordering with order_by, which is in the same format as the
# ordering attribute in models.
self.assertQuerysetEqual(
Article.objects.order_by("headline"), [
"Article 1",
"Article 2",
"Article 3",
"Article 4",
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.order_by("pub_date", "-headline"), [
"Article 1",
"Article 3",
"Article 2",
"Article 4",
],
attrgetter("headline")
)
# Only the last order_by has any effect (since they each override any
# previous ordering).
self.assertQuerysetEqual(
Article.objects.order_by("id"), [
"Article 1",
"Article 2",
"Article 3",
"Article 4",
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.order_by("id").order_by("-headline"), [
"Article 4",
"Article 3",
"Article 2",
"Article 1",
],
attrgetter("headline")
)
# Use the 'stop' part of slicing notation to limit the results.
self.assertQuerysetEqual(
Article.objects.order_by("headline")[:2], [
"Article 1",
"Article 2",
],
attrgetter("headline")
)
# Use the 'stop' and 'start' parts of slicing notation to offset the
# result list.
self.assertQuerysetEqual(
Article.objects.order_by("headline")[1:3], [
"Article 2",
"Article 3",
],
attrgetter("headline")
)
# Getting a single item should work too:
self.assertEqual(Article.objects.all()[0], a4)
# Use '?' to order randomly.
self.assertEqual(
len(list(Article.objects.order_by("?"))), 4
)
# Ordering can be reversed using the reverse() method on a queryset.
# This allows you to extract things like "the last two items" (reverse
# and then take the first two).
self.assertQuerysetEqual(
Article.objects.all().reverse()[:2], [
"Article 1",
"Article 3",
],
attrgetter("headline")
)
# Ordering can be based on fields included from an 'extra' clause
self.assertQuerysetEqual(
Article.objects.extra(select={"foo": "pub_date"}, order_by=["foo", "headline"]), [
"Article 1",
"Article 2",
"Article 3",
"Article 4",
],
attrgetter("headline")
)
# If the extra clause uses an SQL keyword for a name, it will be
# protected by quoting.
self.assertQuerysetEqual(
Article.objects.extra(select={"order": "pub_date"}, order_by=["order", "headline"]), [
"Article 1",
"Article 2",
"Article 3",
"Article 4",
],
attrgetter("headline")
)
|
bsd-3-clause
|
[
504,
2197,
492,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1709,
492,
8281,
421,
199,
533,
9240,
316,
2925,
8,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
413,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7875,
9,
267,
776,
267,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
499,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
8087,
9,
267,
776,
267,
282,
19,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
650,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
8087,
9,
267,
776,
267,
282,
20,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
841,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7294,
9,
267,
776,
398,
327,
4885,
849,
12,
8281,
14,
1462,
14,
452,
342,
15460,
701,
7974,
63,
602,
27524,
12,
2066,
267,
327,
21250,
24525,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
452,
1062,
359,
355,
298,
7221,
841,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
413,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
11041,
7794,
543,
1865,
63,
991,
12,
1314,
365,
315,
314,
2011,
1475,
465,
314,
267,
327,
7794,
2225,
315,
1709,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
5645,
63,
602,
401,
3905,
11268,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
5972,
314,
2061,
1865,
63,
991,
965,
1263,
7763,
334,
8585,
2985,
1924,
4278,
1263,
267,
327,
4136,
7794,
680,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
344,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
344,
3471,
1648,
63,
991,
6096,
11268,
1288,
359,
355,
298,
7221,
841,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
413,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
3645,
314,
283,
2379,
7,
1777,
402,
23647,
15843,
370,
2304,
314,
2058,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
531,
1491,
18,
467,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
3645,
314,
283,
2379,
7,
436,
283,
928,
7,
4184,
402,
23647,
15843,
370,
3268,
314,
267,
327,
754,
769,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
9981,
17,
26,
19,
467,
359,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
20703,
282,
2849,
1242,
1077,
1736,
4634,
26,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
3430,
16,
467,
282,
20,
9,
398,
327,
3645,
15539,
370,
1865,
19311,
14,
267,
291,
14,
629,
8,
288,
822,
8,
513,
8,
7221,
14,
1462,
14,
1648,
63,
991,
480,
31,
2237,
395,
841,
267,
776,
398,
327,
9240,
316,
883,
506,
10822,
1808,
314,
3837,
342,
1083,
641,
282,
7594,
14,
267,
327,
961,
6127,
1265,
370,
5536,
7645,
2839,
298,
1589,
2061,
2877,
2974,
2,
334,
4471,
267,
327,
436,
2066,
5452,
314,
1642,
2877,
680,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
452,
1252,
4471,
20523,
18,
467,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
650,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
9240,
316,
883,
506,
4079,
641,
1504,
5120,
687,
376,
283,
2911,
7,
8502,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
2911,
8,
2416,
8871,
1421,
582,
298,
5645,
63,
602,
6018,
1865,
63,
991,
6270,
1421,
401,
298,
11268,
10252,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
982,
314,
2402,
8502,
4440,
376,
5385,
4252,
367,
282,
536,
12,
652,
911,
506,
267,
327,
17819,
701,
18593,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
2911,
8,
2416,
8871,
1648,
582,
298,
5645,
63,
602,
6018,
1865,
63,
991,
6270,
1648,
401,
298,
11268,
10252,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2197,
492,
2197,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1709,
492,
8281,
421,
199,
533,
9240,
316,
2925,
8,
1746,
304,
272,
347,
511,
63,
4316,
8,
277,
304,
267,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
413,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7875,
9,
267,
776,
267,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
499,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
8087,
9,
267,
776,
267,
282,
19,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
650,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
8087,
9,
267,
776,
267,
282,
20,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
7221,
841,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
1520,
12,
7294,
9,
267,
776,
398,
327,
4885,
849,
12,
8281,
14,
1462,
14,
452,
342,
15460,
701,
7974,
63,
602,
27524,
12,
2066,
267,
327,
21250,
24525,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
452,
1062,
359,
355,
298,
7221,
841,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
413,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
11041,
7794,
543,
1865,
63,
991,
12,
1314,
365,
315,
314,
2011,
1475,
465,
314,
267,
327,
7794,
2225,
315,
1709,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
5645,
63,
602,
401,
3905,
11268,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
5972,
314,
2061,
1865,
63,
991,
965,
1263,
7763,
334,
8585,
2985,
1924,
4278,
1263,
267,
327,
4136,
7794,
680,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
344,
1288,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
344,
3471,
1648,
63,
991,
6096,
11268,
1288,
359,
355,
298,
7221,
841,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
413,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
3645,
314,
283,
2379,
7,
1777,
402,
23647,
15843,
370,
2304,
314,
2058,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
531,
1491,
18,
467,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
3645,
314,
283,
2379,
7,
436,
283,
928,
7,
4184,
402,
23647,
15843,
370,
3268,
314,
267,
327,
754,
769,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
1648,
63,
991,
480,
11268,
9981,
17,
26,
19,
467,
359,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
20703,
282,
2849,
1242,
1077,
1736,
4634,
26,
267,
291,
14,
629,
8,
7221,
14,
1462,
14,
452,
3430,
16,
467,
282,
20,
9,
398,
327,
3645,
15539,
370,
1865,
19311,
14,
267,
291,
14,
629,
8,
288,
822,
8,
513,
8,
7221,
14,
1462,
14,
1648,
63,
991,
480,
31,
2237,
395,
841,
267,
776,
398,
327,
9240,
316,
883,
506,
10822,
1808,
314,
3837,
342,
1083,
641,
282,
7594,
14,
267,
327,
961,
6127,
1265,
370,
5536,
7645,
2839,
298,
1589,
2061,
2877,
2974,
2,
334,
4471,
267,
327,
436,
2066,
5452,
314,
1642,
2877,
680,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
452,
1252,
4471,
20523,
18,
467,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
650,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
9240,
316,
883,
506,
4079,
641,
1504,
5120,
687,
376,
283,
2911,
7,
8502,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
2911,
8,
2416,
8871,
1421,
582,
298,
5645,
63,
602,
6018,
1865,
63,
991,
6270,
1421,
401,
298,
11268,
10252,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
398,
327,
982,
314,
2402,
8502,
4440,
376,
5385,
4252,
367,
282,
536,
12,
652,
911,
506,
267,
327,
17819,
701,
18593,
14,
267,
291,
14,
7108,
8,
288,
8281,
14,
1462,
14,
2911,
8,
2416,
8871,
1648,
582,
298,
5645,
63,
602,
6018,
1865,
63,
991,
6270,
1648,
401,
298,
11268,
10252,
359,
355,
298,
7221,
413,
401,
355,
298,
7221,
499,
401,
355,
298,
7221,
650,
401,
355,
298,
7221,
841,
401,
288,
2156,
288,
21829,
480,
11268,
531,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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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
] |
tgetzoya/project-euler-python
|
problems/pe11.py
|
1
|
4396
|
# In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
#
# 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
# 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
# 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
# 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
# 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
# 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
# 32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
# 67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
# 24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
# 21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
# 78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
# 16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
# 86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
# 19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
# 04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
# 88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
# 04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
# 20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
# 20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
# 01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
#
# The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
#
# What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
#
def val_left(x, y, grid):
if x + 3 < 20:
return grid[x][y] * grid[x + 1][y] * grid[x + 2][y] * grid[x + 3][y];
else:
return -1
def val_down(x, y, grid):
if y + 3 < 20:
return grid[x][y] * grid[x][y + 1] * grid[x][y + 1] * grid[x][y + 1];
else:
return -1
def diag_right(x, y, grid):
if x + 3 < 20 and y + 3 < 20:
return grid[x][y] * grid[x + 1][y + 1] * grid[x + 2][y + 2] * grid[x + 3][y + 3];
else:
return -1
def diag_left(x, y, grid):
if x - 3 >= 0 and y + 3 < 20:
return grid[x][y] * grid[x - 1][y + 1] * grid[x - 2][y + 2] * grid[x - 3][y + 3];
else:
return -1
def run():
grid = [[8, 2, 22, 97, 38, 15, 00, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 0, 56, 62, 00],
[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65],
[52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91],
[22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80],
[24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50],
[32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70],
[67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21],
[24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72],
[21, 36, 23, 9, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95],
[78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 3, 80, 4, 62, 16, 14, 9, 53, 56, 92],
[16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57],
[86, 56, 00, 48, 35, 71, 89, 7, 5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],
[19, 80, 81, 68, 5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 4, 89, 55, 40],
[4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],
[88, 36, 68, 87, 57, 62, 20, 72, 3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],
[4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36],
[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16],
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]]
greatest = -1
for y in range(0, 20):
for x in range(0, 20):
val = max([val_left(x, y, grid), val_down(x, y, grid), diag_left(x, y, grid), diag_right(x, y, grid)])
if val > greatest:
print("{},{} -> {}".format(x, y, greatest))
greatest = val
return greatest
|
bsd-2-clause
|
[
3,
1010,
314,
3388,
128,
246,
1165,
6068,
5084,
12,
11648,
5579,
3180,
282,
16788,
1004,
1172,
2757,
11584,
315,
8992,
14,
199,
3,
199,
3,
19363,
12497,
6928,
15997,
10448,
4114,
8733,
6335,
8733,
13098,
28527,
22528,
24937,
14679,
14589,
3144,
5238,
8375,
21358,
19363,
199,
3,
12260,
12260,
8806,
6335,
5557,
19071,
6155,
12699,
5212,
10513,
5557,
6335,
16096,
11851,
14610,
9615,
28527,
12001,
16202,
8733,
199,
3,
19071,
12260,
7105,
18525,
12766,
13734,
4329,
7349,
18969,
17245,
6335,
13296,
13564,
10523,
4233,
30569,
12260,
4944,
8780,
11738,
199,
3,
14589,
10045,
16102,
6546,
28527,
5212,
4119,
5685,
14610,
5504,
10851,
12001,
17163,
4337,
12001,
17245,
6877,
12497,
8780,
21358,
199,
3,
6928,
7105,
3193,
17245,
8026,
13296,
13668,
17838,
13385,
20140,
8780,
13470,
6928,
6335,
6335,
7294,
14157,
9404,
4944,
5939,
199,
3,
5504,
10954,
4337,
5212,
8806,
30569,
10416,
12497,
10868,
13098,
9404,
13564,
14679,
8780,
8264,
3388,
8685,
5557,
3144,
5238,
199,
3,
4337,
16096,
19071,
7294,
5049,
6546,
13296,
1616,
7875,
10448,
6335,
13296,
8155,
13470,
10045,
14157,
6155,
10448,
5049,
10045,
199,
3,
13296,
7875,
3388,
10851,
12497,
16202,
3144,
3388,
16102,
13668,
18729,
10551,
13668,
19363,
6335,
21358,
14157,
12260,
18729,
7829,
199,
3,
5504,
12766,
13713,
22528,
14157,
18525,
8806,
7875,
15997,
5557,
14679,
14679,
15580,
20582,
4329,
10523,
8177,
17838,
13668,
15323,
199,
3,
7829,
8780,
6546,
21798,
13098,
8733,
14646,
10868,
3388,
10416,
8685,
4329,
8733,
17017,
9404,
15997,
8177,
7105,
9404,
16102,
199,
3,
14679,
5557,
13564,
7294,
6928,
13098,
7105,
13296,
4114,
18729,
30569,
5939,
28527,
16202,
3193,
4329,
21798,
13564,
12001,
20140,
199,
3,
3193,
10551,
22528,
5685,
15580,
8685,
7105,
10954,
12766,
13713,
10523,
5504,
8733,
5557,
13470,
5504,
8780,
7349,
16412,
12699,
199,
3,
10300,
12001,
8733,
9615,
8685,
17245,
17838,
24937,
22528,
10868,
10868,
6877,
10868,
5212,
7829,
13713,
8026,
13470,
5557,
13713,
199,
3,
5851,
5939,
19071,
10851,
22528,
18729,
10954,
14610,
7294,
18525,
20140,
4944,
10300,
14589,
5557,
8375,
28527,
17838,
12766,
6335,
199,
3,
28527,
14589,
19363,
20582,
15997,
8685,
8806,
3193,
24937,
15997,
12699,
4337,
3193,
7875,
7875,
13734,
9404,
8087,
16096,
14157,
199,
3,
10523,
8780,
10851,
10513,
12699,
16202,
3388,
15323,
30569,
12426,
9404,
13296,
12426,
12766,
3144,
4337,
13668,
18969,
13564,
14610,
199,
3,
28527,
5685,
3193,
18525,
10448,
5661,
10551,
4119,
5504,
18729,
15323,
6155,
19363,
12426,
7349,
4337,
6335,
16202,
14646,
8780,
199,
3,
3388,
14610,
8780,
13385,
15323,
4233,
6546,
10523,
8177,
16202,
8806,
14610,
18051,
13296,
8155,
16412,
9720,
28527,
8780,
3193,
199,
3,
3388,
18525,
8685,
7349,
14679,
7105,
9137,
17163,
9720,
7105,
12260,
17245,
9615,
10300,
19071,
3193,
6546,
12699,
22528,
13470,
199,
3,
17163,
10045,
13470,
17245,
20582,
8026,
13470,
14610,
3193,
20140,
9404,
9615,
17017,
11851,
14589,
17163,
17838,
5851,
13296,
9615,
199,
3,
199,
3,
710,
3336,
402,
3520,
5579,
365,
7875,
13333,
246,
13668,
13333,
246,
14679,
13333,
246,
4329,
275,
413,
2277,
1184,
2534,
14,
199,
3,
199,
3,
14791,
365,
314,
486,
622,
270,
3336,
402,
11648,
24113,
5579,
315,
314,
2011,
7581,
334,
384,
12,
3224,
12,
3602,
12,
2451,
12,
503,
8348,
265,
1183,
9,
315,
314,
3388,
128,
246,
1165,
6068,
31,
199,
3,
199,
199,
318,
1139,
63,
3039,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
435,
413,
1527,
89,
61,
627,
6068,
59,
88,
435,
499,
1527,
89,
61,
627,
6068,
59,
88,
435,
650,
1527,
89,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
1139,
63,
2110,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
8348,
63,
1019,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
435,
650,
665,
3388,
436,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
435,
413,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
435,
499,
1527,
89,
435,
499,
61,
627,
6068,
59,
88,
435,
650,
1527,
89,
435,
650,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
8348,
63,
3039,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
446,
650,
2356,
378,
436,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
446,
413,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
446,
499,
1527,
89,
435,
499,
61,
627,
6068,
59,
88,
446,
650,
1527,
89,
435,
650,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
1255,
837,
272,
6068,
275,
3474,
24,
12,
499,
12,
6928,
12,
15997,
12,
10448,
12,
4114,
12,
8733,
12,
6335,
12,
378,
12,
13098,
12,
841,
12,
959,
12,
1520,
12,
14679,
12,
14589,
12,
3144,
12,
5238,
12,
8375,
12,
21358,
12,
1695,
467,
288,
359,
1887,
12,
12260,
12,
8806,
12,
6335,
12,
5557,
12,
19071,
12,
6155,
12,
12699,
12,
5212,
12,
10513,
12,
5557,
12,
6335,
12,
16096,
12,
11851,
12,
14610,
12,
9615,
12,
378,
12,
12001,
12,
16202,
12,
8733,
467,
288,
359,
2835,
12,
12260,
12,
7105,
12,
18525,
12,
12766,
12,
13734,
12,
4329,
12,
7349,
12,
18969,
12,
17245,
12,
6335,
12,
13296,
12,
13564,
12,
10523,
12,
4233,
12,
650,
12,
12260,
12,
4944,
12,
8780,
12,
11738,
467,
288,
359,
2528,
12,
10045,
12,
16102,
12,
6546,
12,
841,
12,
5212,
12,
4119,
12,
5685,
12,
14610,
12,
5504,
12,
10851,
12,
12001,
12,
413,
12,
4337,
12,
12001,
12,
17245,
12,
6877,
12,
499,
12,
8780,
12,
21358,
467,
288,
359,
1081,
12,
7105,
12,
3193,
12,
17245,
12,
8026,
12,
13296,
12,
13668,
12,
17838,
12,
13385,
12,
20140,
12,
8780,
12,
13470,
12,
6928,
12,
6335,
12,
6335,
12,
7294,
12,
14157,
12,
9404,
12,
4944,
12
] |
[
1010,
314,
3388,
128,
246,
1165,
6068,
5084,
12,
11648,
5579,
3180,
282,
16788,
1004,
1172,
2757,
11584,
315,
8992,
14,
199,
3,
199,
3,
19363,
12497,
6928,
15997,
10448,
4114,
8733,
6335,
8733,
13098,
28527,
22528,
24937,
14679,
14589,
3144,
5238,
8375,
21358,
19363,
199,
3,
12260,
12260,
8806,
6335,
5557,
19071,
6155,
12699,
5212,
10513,
5557,
6335,
16096,
11851,
14610,
9615,
28527,
12001,
16202,
8733,
199,
3,
19071,
12260,
7105,
18525,
12766,
13734,
4329,
7349,
18969,
17245,
6335,
13296,
13564,
10523,
4233,
30569,
12260,
4944,
8780,
11738,
199,
3,
14589,
10045,
16102,
6546,
28527,
5212,
4119,
5685,
14610,
5504,
10851,
12001,
17163,
4337,
12001,
17245,
6877,
12497,
8780,
21358,
199,
3,
6928,
7105,
3193,
17245,
8026,
13296,
13668,
17838,
13385,
20140,
8780,
13470,
6928,
6335,
6335,
7294,
14157,
9404,
4944,
5939,
199,
3,
5504,
10954,
4337,
5212,
8806,
30569,
10416,
12497,
10868,
13098,
9404,
13564,
14679,
8780,
8264,
3388,
8685,
5557,
3144,
5238,
199,
3,
4337,
16096,
19071,
7294,
5049,
6546,
13296,
1616,
7875,
10448,
6335,
13296,
8155,
13470,
10045,
14157,
6155,
10448,
5049,
10045,
199,
3,
13296,
7875,
3388,
10851,
12497,
16202,
3144,
3388,
16102,
13668,
18729,
10551,
13668,
19363,
6335,
21358,
14157,
12260,
18729,
7829,
199,
3,
5504,
12766,
13713,
22528,
14157,
18525,
8806,
7875,
15997,
5557,
14679,
14679,
15580,
20582,
4329,
10523,
8177,
17838,
13668,
15323,
199,
3,
7829,
8780,
6546,
21798,
13098,
8733,
14646,
10868,
3388,
10416,
8685,
4329,
8733,
17017,
9404,
15997,
8177,
7105,
9404,
16102,
199,
3,
14679,
5557,
13564,
7294,
6928,
13098,
7105,
13296,
4114,
18729,
30569,
5939,
28527,
16202,
3193,
4329,
21798,
13564,
12001,
20140,
199,
3,
3193,
10551,
22528,
5685,
15580,
8685,
7105,
10954,
12766,
13713,
10523,
5504,
8733,
5557,
13470,
5504,
8780,
7349,
16412,
12699,
199,
3,
10300,
12001,
8733,
9615,
8685,
17245,
17838,
24937,
22528,
10868,
10868,
6877,
10868,
5212,
7829,
13713,
8026,
13470,
5557,
13713,
199,
3,
5851,
5939,
19071,
10851,
22528,
18729,
10954,
14610,
7294,
18525,
20140,
4944,
10300,
14589,
5557,
8375,
28527,
17838,
12766,
6335,
199,
3,
28527,
14589,
19363,
20582,
15997,
8685,
8806,
3193,
24937,
15997,
12699,
4337,
3193,
7875,
7875,
13734,
9404,
8087,
16096,
14157,
199,
3,
10523,
8780,
10851,
10513,
12699,
16202,
3388,
15323,
30569,
12426,
9404,
13296,
12426,
12766,
3144,
4337,
13668,
18969,
13564,
14610,
199,
3,
28527,
5685,
3193,
18525,
10448,
5661,
10551,
4119,
5504,
18729,
15323,
6155,
19363,
12426,
7349,
4337,
6335,
16202,
14646,
8780,
199,
3,
3388,
14610,
8780,
13385,
15323,
4233,
6546,
10523,
8177,
16202,
8806,
14610,
18051,
13296,
8155,
16412,
9720,
28527,
8780,
3193,
199,
3,
3388,
18525,
8685,
7349,
14679,
7105,
9137,
17163,
9720,
7105,
12260,
17245,
9615,
10300,
19071,
3193,
6546,
12699,
22528,
13470,
199,
3,
17163,
10045,
13470,
17245,
20582,
8026,
13470,
14610,
3193,
20140,
9404,
9615,
17017,
11851,
14589,
17163,
17838,
5851,
13296,
9615,
199,
3,
199,
3,
710,
3336,
402,
3520,
5579,
365,
7875,
13333,
246,
13668,
13333,
246,
14679,
13333,
246,
4329,
275,
413,
2277,
1184,
2534,
14,
199,
3,
199,
3,
14791,
365,
314,
486,
622,
270,
3336,
402,
11648,
24113,
5579,
315,
314,
2011,
7581,
334,
384,
12,
3224,
12,
3602,
12,
2451,
12,
503,
8348,
265,
1183,
9,
315,
314,
3388,
128,
246,
1165,
6068,
31,
199,
3,
199,
199,
318,
1139,
63,
3039,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
435,
413,
1527,
89,
61,
627,
6068,
59,
88,
435,
499,
1527,
89,
61,
627,
6068,
59,
88,
435,
650,
1527,
89,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
1139,
63,
2110,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
1527,
89,
435,
413,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
8348,
63,
1019,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
435,
650,
665,
3388,
436,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
435,
413,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
435,
499,
1527,
89,
435,
499,
61,
627,
6068,
59,
88,
435,
650,
1527,
89,
435,
650,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
8348,
63,
3039,
8,
88,
12,
612,
12,
6068,
304,
272,
340,
671,
446,
650,
2356,
378,
436,
612,
435,
650,
665,
3388,
26,
267,
372,
6068,
59,
88,
1527,
89,
61,
627,
6068,
59,
88,
446,
413,
1527,
89,
435,
413,
61,
627,
6068,
59,
88,
446,
499,
1527,
89,
435,
499,
61,
627,
6068,
59,
88,
446,
650,
1527,
89,
435,
650,
11566,
272,
587,
26,
267,
372,
446,
17,
421,
199,
318,
1255,
837,
272,
6068,
275,
3474,
24,
12,
499,
12,
6928,
12,
15997,
12,
10448,
12,
4114,
12,
8733,
12,
6335,
12,
378,
12,
13098,
12,
841,
12,
959,
12,
1520,
12,
14679,
12,
14589,
12,
3144,
12,
5238,
12,
8375,
12,
21358,
12,
1695,
467,
288,
359,
1887,
12,
12260,
12,
8806,
12,
6335,
12,
5557,
12,
19071,
12,
6155,
12,
12699,
12,
5212,
12,
10513,
12,
5557,
12,
6335,
12,
16096,
12,
11851,
12,
14610,
12,
9615,
12,
378,
12,
12001,
12,
16202,
12,
8733,
467,
288,
359,
2835,
12,
12260,
12,
7105,
12,
18525,
12,
12766,
12,
13734,
12,
4329,
12,
7349,
12,
18969,
12,
17245,
12,
6335,
12,
13296,
12,
13564,
12,
10523,
12,
4233,
12,
650,
12,
12260,
12,
4944,
12,
8780,
12,
11738,
467,
288,
359,
2528,
12,
10045,
12,
16102,
12,
6546,
12,
841,
12,
5212,
12,
4119,
12,
5685,
12,
14610,
12,
5504,
12,
10851,
12,
12001,
12,
413,
12,
4337,
12,
12001,
12,
17245,
12,
6877,
12,
499,
12,
8780,
12,
21358,
467,
288,
359,
1081,
12,
7105,
12,
3193,
12,
17245,
12,
8026,
12,
13296,
12,
13668,
12,
17838,
12,
13385,
12,
20140,
12,
8780,
12,
13470,
12,
6928,
12,
6335,
12,
6335,
12,
7294,
12,
14157,
12,
9404,
12,
4944,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
evilhero/mylar
|
lib/requests/packages/chardet/langthaimodel.py
|
2930
|
11275
|
######################## 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
# The following result for thai was collected from a limited sample (1M).
# Character Mapping Table:
TIS620CharToOrderMap = (
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,182,106,107,100,183,184,185,101, 94,186,187,108,109,110,111, # 40
188,189,190, 89, 95,112,113,191,192,193,194,253,253,253,253,253, # 50
253, 64, 72, 73,114, 74,115,116,102, 81,201,117, 90,103, 78, 82, # 60
96,202, 91, 79, 84,104,105, 97, 98, 92,203,253,253,253,253,253, # 70
209,210,211,212,213, 88,214,215,216,217,218,219,220,118,221,222,
223,224, 99, 85, 83,225,226,227,228,229,230,231,232,233,234,235,
236, 5, 30,237, 24,238, 75, 8, 26, 52, 34, 51,119, 47, 58, 57,
49, 53, 55, 43, 20, 19, 44, 14, 48, 3, 17, 25, 39, 62, 31, 54,
45, 9, 16, 2, 61, 15,239, 12, 42, 46, 18, 21, 76, 4, 66, 63,
22, 10, 1, 36, 23, 13, 40, 27, 32, 35, 86,240,241,242,243,244,
11, 28, 41, 29, 33,245, 50, 37, 6, 7, 67, 77, 38, 93,246,247,
68, 56, 59, 65, 69, 60, 70, 80, 71, 87,248,249,250,251,252,253,
)
# Model Table:
# total sequences: 100%
# first 512 sequences: 92.6386%
# first 1024 sequences:7.3177%
# rest sequences: 1.0230%
# negative sequences: 0.0436%
ThaiLangModel = (
0,1,3,3,3,3,0,0,3,3,0,3,3,0,3,3,3,3,3,3,3,3,0,0,3,3,3,0,3,3,3,3,
0,3,3,0,0,0,1,3,0,3,3,2,3,3,0,1,2,3,3,3,3,0,2,0,2,0,0,3,2,1,2,2,
3,0,3,3,2,3,0,0,3,3,0,3,3,0,3,3,3,3,3,3,3,3,3,0,3,2,3,0,2,2,2,3,
0,2,3,0,0,0,0,1,0,1,2,3,1,1,3,2,2,0,1,1,0,0,1,0,0,0,0,0,0,0,1,1,
3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,3,3,2,3,2,3,3,2,2,2,
3,1,2,3,0,3,3,2,2,1,2,3,3,1,2,0,1,3,0,1,0,0,1,0,0,0,0,0,0,0,1,1,
3,3,2,2,3,3,3,3,1,2,3,3,3,3,3,2,2,2,2,3,3,2,2,3,3,2,2,3,2,3,2,2,
3,3,1,2,3,1,2,2,3,3,1,0,2,1,0,0,3,1,2,1,0,0,1,0,0,0,0,0,0,1,0,1,
3,3,3,3,3,3,2,2,3,3,3,3,2,3,2,2,3,3,2,2,3,2,2,2,2,1,1,3,1,2,1,1,
3,2,1,0,2,1,0,1,0,1,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,
3,3,3,2,3,2,3,3,2,2,3,2,3,3,2,3,1,1,2,3,2,2,2,3,2,2,2,2,2,1,2,1,
2,2,1,1,3,3,2,1,0,1,2,2,0,1,3,0,0,0,1,1,0,0,0,0,0,2,3,0,0,2,1,1,
3,3,2,3,3,2,0,0,3,3,0,3,3,0,2,2,3,1,2,2,1,1,1,0,2,2,2,0,2,2,1,1,
0,2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,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,1,1,0,0,2,1,0,0,1,0,0,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,2,0,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
)
TIS620ThaiModel = {
'charToOrderMap': TIS620CharToOrderMap,
'precedenceMatrix': ThaiLangModel,
'mTypicalPositiveRatio': 0.926386,
'keepEnglishLetter': False,
'charsetName': "TIS-620"
}
# flake8: noqa
|
gpl-3.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,
710,
2569,
754,
367,
294,
5789,
1990,
13736,
687,
282,
13988,
2690,
334,
17,
45,
680,
199,
199,
3,
17660,
12340,
6957,
26,
199,
52,
1311,
22085,
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,
12894,
12,
7357,
12,
7555,
12,
1960,
12,
12363,
12,
10078,
12,
10233,
12,
4893,
12,
18729,
12,
11656,
12,
11775,
12,
8079,
12,
6996,
12,
6019,
12,
6673,
12,
221,
327,
6335,
199,
11501,
12,
11370,
12,
12205,
12,
17838,
12,
16102,
12,
6094,
12,
9225,
12,
12632,
12,
5756,
12,
13015,
12,
10860,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
5049,
12,
15323,
12,
18525,
12,
7636,
12,
9720,
12,
7680,
12,
7524,
12,
7759,
12,
19071,
12,
1797,
12,
7362,
12,
9137,
12,
8845,
12,
14679,
12,
18051,
12,
221,
327,
5212,
199,
15580,
12,
4999,
12,
21358,
12,
13734,
12,
8264,
12,
6785,
12,
7320,
12,
15997,
12,
16096,
12,
20140,
12,
11341,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
11303,
12,
12725,
12,
12832,
12,
11722,
12,
14271,
12,
10523,
12,
6886,
12,
7842,
12,
9669,
12,
9335,
12,
9252,
12,
8867,
12,
11174,
12,
7906,
12,
11564,
12,
9485,
12,
199,
11583,
12,
8731,
12,
8806,
12,
16412,
12,
20582,
12,
10932,
12,
11085,
12,
11385,
12,
12048,
12,
11182,
12,
9687,
12,
11921,
12,
8001,
12,
10034,
12,
5533,
12,
8276,
12,
199,
10008,
12,
221,
959,
12,
4233,
12,
10638,
12,
5504,
12,
12332,
12,
13098,
12,
221,
1695,
12,
7875,
12,
14589,
12,
8177,
12,
8026,
12,
7119,
12,
10954,
12,
13713,
12,
12699,
12,
199,
12260,
12,
13564,
12,
12766,
12,
11851,
12,
3388,
12,
5851,
12,
10868,
12,
4329,
12,
9615,
12,
221,
650,
12,
5557,
12,
5661,
12,
10551,
12,
16202,
12,
7105,
12,
13470,
12,
199,
10416,
12,
221,
1749,
12,
3193,
12,
221,
499,
12,
17017,
12,
4114,
12,
9803,
12,
3144,
12,
5685,
12,
12426,
12,
6155,
12,
7829,
12,
14646,
12,
221,
841,
12,
14157,
12,
13668,
12,
199,
6928,
12,
1616,
12,
221,
413,
12,
8780,
12,
6546,
12,
4944,
12,
6335,
12,
8087,
12,
4337,
12,
8685,
12,
10300,
12,
9873,
12,
13571,
12,
13212,
12,
13440,
12,
11603,
12,
199,
4119,
12,
7294,
12,
13385,
12,
7349,
12,
9404,
12,
11677,
12,
5238,
12,
6877,
12,
221,
1227,
12,
221,
1520,
12,
13296,
12,
8375,
12,
10448,
12,
18969,
12,
11440,
12,
11717,
12,
199,
10851,
12,
12001,
12,
8155,
12,
11738,
12,
14610,
12,
5212,
12,
10045,
12,
5939,
12,
17245,
12,
10513,
12,
11242,
12,
11032,
12,
7991,
12,
12140,
12,
6390,
12,
3781,
12,
199,
9,
199,
199,
3,
5822,
6957,
26,
199,
3,
3141,
8013,
26,
2948,
5,
199,
3,
1642,
10574,
8013,
26,
20140,
14,
2766,
1184,
5,
199,
3,
1642,
6619,
8013,
26,
23,
14,
2192,
1138,
5,
199,
3,
4618,
221,
8013,
26,
258,
413,
14,
996,
1216,
5,
199,
3,
6946,
8013,
26,
221,
378,
14,
966,
1344,
5,
199,
52,
17945,
29723,
275,
334,
199,
16,
12,
17,
12,
19,
12,
19,
12,
19,
12,
19,
12,
16,
12,
16,
12,
19,
12,
19,
12,
16,
12,
19,
12,
19,
12,
16,
12,
19,
12,
19,
12,
19,
12,
19,
12,
19,
12,
19,
12,
19,
12,
19,
12,
16,
12,
16,
12,
19,
12,
19,
12,
19,
12,
16,
12,
19,
12,
19,
12,
19,
12,
19,
12,
199,
16
] |
[
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,
710,
2569,
754,
367,
294,
5789,
1990,
13736,
687,
282,
13988,
2690,
334,
17,
45,
680,
199,
199,
3,
17660,
12340,
6957,
26,
199,
52,
1311,
22085,
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,
12894,
12,
7357,
12,
7555,
12,
1960,
12,
12363,
12,
10078,
12,
10233,
12,
4893,
12,
18729,
12,
11656,
12,
11775,
12,
8079,
12,
6996,
12,
6019,
12,
6673,
12,
221,
327,
6335,
199,
11501,
12,
11370,
12,
12205,
12,
17838,
12,
16102,
12,
6094,
12,
9225,
12,
12632,
12,
5756,
12,
13015,
12,
10860,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
5049,
12,
15323,
12,
18525,
12,
7636,
12,
9720,
12,
7680,
12,
7524,
12,
7759,
12,
19071,
12,
1797,
12,
7362,
12,
9137,
12,
8845,
12,
14679,
12,
18051,
12,
221,
327,
5212,
199,
15580,
12,
4999,
12,
21358,
12,
13734,
12,
8264,
12,
6785,
12,
7320,
12,
15997,
12,
16096,
12,
20140,
12,
11341,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
11303,
12,
12725,
12,
12832,
12,
11722,
12,
14271,
12,
10523,
12,
6886,
12,
7842,
12,
9669,
12,
9335,
12,
9252,
12,
8867,
12,
11174,
12,
7906,
12,
11564,
12,
9485,
12,
199,
11583,
12,
8731,
12,
8806,
12,
16412,
12,
20582,
12,
10932,
12,
11085,
12,
11385,
12,
12048,
12,
11182,
12,
9687,
12,
11921,
12,
8001,
12,
10034,
12,
5533,
12,
8276,
12,
199,
10008,
12,
221,
959,
12,
4233,
12,
10638,
12,
5504,
12,
12332,
12,
13098,
12,
221,
1695,
12,
7875,
12,
14589,
12,
8177,
12,
8026,
12,
7119,
12,
10954,
12,
13713,
12,
12699,
12,
199,
12260,
12,
13564,
12,
12766,
12,
11851,
12,
3388,
12,
5851,
12,
10868,
12,
4329,
12,
9615,
12,
221,
650,
12,
5557,
12,
5661,
12,
10551,
12,
16202,
12,
7105,
12,
13470,
12,
199,
10416,
12,
221,
1749,
12,
3193,
12,
221,
499,
12,
17017,
12,
4114,
12,
9803,
12,
3144,
12,
5685,
12,
12426,
12,
6155,
12,
7829,
12,
14646,
12,
221,
841,
12,
14157,
12,
13668,
12,
199,
6928,
12,
1616,
12,
221,
413,
12,
8780,
12,
6546,
12,
4944,
12,
6335,
12,
8087,
12,
4337,
12,
8685,
12,
10300,
12,
9873,
12,
13571,
12,
13212,
12,
13440,
12,
11603,
12,
199,
4119,
12,
7294,
12,
13385,
12,
7349,
12,
9404,
12,
11677,
12,
5238,
12,
6877,
12,
221,
1227,
12,
221,
1520,
12,
13296,
12,
8375,
12,
10448,
12,
18969,
12,
11440,
12,
11717,
12,
199,
10851,
12,
12001,
12,
8155,
12,
11738,
12,
14610,
12,
5212,
12,
10045,
12,
5939,
12,
17245,
12,
10513,
12,
11242,
12,
11032,
12,
7991,
12,
12140,
12,
6390,
12,
3781,
12,
199,
9,
199,
199,
3,
5822,
6957,
26,
199,
3,
3141,
8013,
26,
2948,
5,
199,
3,
1642,
10574,
8013,
26,
20140,
14,
2766,
1184,
5,
199,
3,
1642,
6619,
8013,
26,
23,
14,
2192,
1138,
5,
199,
3,
4618,
221,
8013,
26,
258,
413,
14,
996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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
savoirfairelinux/OpenUpgrade
|
addons/website_blog/__init__.py
|
373
|
1036
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import controllers
import models
import wizard
|
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,
6171,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
27325,
199,
646,
1709,
199,
646,
12262,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6171,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
27325,
199,
646,
1709,
199,
646,
12262,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
maxandersen/jenkins-job-builder
|
jenkins_jobs/modules/publishers.py
|
1
|
186200
|
# Copyright 2012 Hewlett-Packard Development Company, L.P.
# Copyright 2012 Varnish Software AS
# Copyright 2013-2014 Antoine "hashar" Musso
# Copyright 2013-2014 Wikimedia Foundation 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.
"""
Publishers define actions that the Jenkins job should perform after
the build is complete.
**Component**: publishers
:Macro: publisher
:Entry Point: jenkins_jobs.publishers
"""
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.modules import hudson_model
from jenkins_jobs.modules.helpers import build_trends_publisher
from jenkins_jobs.modules.helpers import findbugs_settings
from jenkins_jobs.errors import JenkinsJobsException
import logging
import pkg_resources
import sys
import six
import random
def archive(parser, xml_parent, data):
"""yaml: archive
Archive build artifacts
:arg str artifacts: path specifier for artifacts to archive
:arg str excludes: path specifier for artifacts to exclude
:arg bool latest-only: only keep the artifacts from the latest
successful build
:arg bool allow-empty: pass the build if no artifacts are
found (default false)
:arg bool fingerprint: fingerprint all archived artifacts (default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/archive001.yaml
:language: yaml
"""
logger = logging.getLogger("%s:archive" % __name__)
archiver = XML.SubElement(xml_parent, 'hudson.tasks.ArtifactArchiver')
artifacts = XML.SubElement(archiver, 'artifacts')
artifacts.text = data['artifacts']
if 'excludes' in data:
excludes = XML.SubElement(archiver, 'excludes')
excludes.text = data['excludes']
latest = XML.SubElement(archiver, 'latestOnly')
# backward compatibility
latest_only = data.get('latest_only', False)
if 'latest_only' in data:
logger.warn('latest_only is deprecated please use latest-only')
if 'latest-only' in data:
latest_only = data['latest-only']
if latest_only:
latest.text = 'true'
else:
latest.text = 'false'
if 'allow-empty' in data:
empty = XML.SubElement(archiver, 'allowEmptyArchive')
# Default behavior is to fail the build.
empty.text = str(data.get('allow-empty', False)).lower()
if 'fingerprint' in data:
fingerprint = XML.SubElement(archiver, 'fingerprint')
fingerprint.text = str(data.get('fingerprint', False)).lower()
def blame_upstream(parser, xml_parent, data):
"""yaml: blame-upstream
Notify upstream commiters when build fails
Requires the Jenkins :jenkins-wiki:`Blame upstream commiters Plugin
<Blame+Upstream+Committers+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/blame001.yaml
:language: yaml
"""
XML.SubElement(xml_parent,
'hudson.plugins.blame__upstream__commiters.'
'BlameUpstreamCommitersPublisher')
def jclouds(parser, xml_parent, data):
"""yaml: JClouds Cloud Storage Settings
provides a way to store artifacts on JClouds supported storage providers.
Requires the Jenkins `JClouds Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/JClouds+Plugin>`_
JClouds Cloud Storage Settings must be configured for the Jenkins instance.
:arg str profile: preconfigured storage profile (required)
:arg str files: files to upload (regex) (required)
:arg str basedir: the source file path (relative to workspace, Optional)
:arg str container: the destination container name (required)
:arg bool hierarchy: keep hierarchy (default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/jclouds001.yaml
"""
deployer = XML.SubElement(xml_parent,
'jenkins.plugins.jclouds.blobstore.'
'BlobStorePublisher')
if 'profile' not in data:
raise JenkinsJobsException('profile parameter is missing')
XML.SubElement(deployer, 'profileName').text = data.get('profile')
entries = XML.SubElement(deployer, 'entries')
deployer_entry = XML.SubElement(entries,
'jenkins.plugins.jclouds.blobstore.'
'BlobStoreEntry')
try:
XML.SubElement(deployer_entry, 'container').text = data['container']
XML.SubElement(deployer_entry, 'path').text = data.get('basedir', '')
XML.SubElement(deployer_entry, 'sourceFile').text = data['files']
except KeyError as e:
raise JenkinsJobsException("blobstore requires '%s' to be set"
% e.args[0])
XML.SubElement(deployer_entry, 'keepHierarchy').text = str(
data.get('hierarchy', False)).lower()
def campfire(parser, xml_parent, data):
"""yaml: campfire
Send build notifications to Campfire rooms.
Requires the Jenkins :jenkins-wiki:`Campfire Plugin <Campfire+Plugin>`.
Campfire notifications global default values must be configured for
the Jenkins instance. Default values will be used if no specific
values are specified for each job, so all config params are optional.
:arg str subdomain: override the default campfire subdomain
:arg str token: override the default API token
:arg bool ssl: override the default 'use SSL'
:arg str room: override the default room name
Example:
.. literalinclude:: /../../tests/publishers/fixtures/campfire001.yaml
:language: yaml
"""
root = XML.SubElement(xml_parent,
'hudson.plugins.campfire.'
'CampfireNotifier')
campfire = XML.SubElement(root, 'campfire')
if ('subdomain' in data and data['subdomain']):
subdomain = XML.SubElement(campfire, 'subdomain')
subdomain.text = data['subdomain']
if ('token' in data and data['token']):
token = XML.SubElement(campfire, 'token')
token.text = data['token']
if ('ssl' in data):
ssl = XML.SubElement(campfire, 'ssl')
ssl.text = str(data['ssl']).lower()
if ('room' in data and data['room']):
room = XML.SubElement(root, 'room')
name = XML.SubElement(room, 'name')
name.text = data['room']
XML.SubElement(room, 'campfire reference="../../campfire"')
def emotional_jenkins(parser, xml_parent, data):
"""yaml: emotional-jenkins
Emotional Jenkins.
Requires the Jenkins :jenkins-wiki:`Emotional Jenkins Plugin
<Emotional+Jenkins+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/emotional-jenkins.yaml
:language: yaml
"""
XML.SubElement(xml_parent,
'org.jenkinsci.plugins.emotional__jenkins.'
'EmotionalJenkinsPublisher')
def trigger_parameterized_builds(parser, xml_parent, data):
"""yaml: trigger-parameterized-builds
Trigger parameterized builds of other jobs.
Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin
<Parameterized+Trigger+Plugin>`.
Use of the `node-label-name` or `node-label` parameters
requires the Jenkins :jenkins-wiki:`NodeLabel Parameter Plugin
<NodeLabel+Parameter+Plugin>`.
Note: 'node-parameters' overrides the Node that the triggered
project is tied to.
:arg str project: name of the job to trigger
:arg str predefined-parameters: parameters to pass to the other
job (optional)
:arg bool current-parameters: Whether to include the parameters passed
to the current build to the triggered job (optional)
:arg bool node-parameters: Use the same Node for the triggered builds
that was used for this build. (optional)
:arg bool svn-revision: Pass svn revision to the triggered job (optional)
:arg bool git-revision: Pass git revision to the other job (optional)
:arg str condition: when to trigger the other job (default 'ALWAYS')
:arg str property-file: Use properties from file (optional)
:arg bool fail-on-missing: Blocks the triggering of the downstream jobs
if any of the files are not found in the workspace (default 'False')
:arg str restrict-matrix-project: Filter that restricts the subset
of the combinations that the downstream project will run (optional)
:arg str node-label-name: Specify the Name for the NodeLabel parameter.
(optional)
:arg str node-label: Specify the Node for the NodeLabel parameter.
(optional)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/trigger_parameterized_builds001.yaml
:language: yaml
"""
tbuilder = XML.SubElement(xml_parent,
'hudson.plugins.parameterizedtrigger.'
'BuildTrigger')
configs = XML.SubElement(tbuilder, 'configs')
for project_def in data:
tconfig = XML.SubElement(configs,
'hudson.plugins.parameterizedtrigger.'
'BuildTriggerConfig')
tconfigs = XML.SubElement(tconfig, 'configs')
if ('predefined-parameters' in project_def
or 'git-revision' in project_def
or 'property-file' in project_def
or 'current-parameters' in project_def
or 'node-parameters' in project_def
or 'svn-revision' in project_def
or 'restrict-matrix-project' in project_def
or 'node-label-name' in project_def
or 'node-label' in project_def):
if 'predefined-parameters' in project_def:
params = XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'PredefinedBuildParameters')
properties = XML.SubElement(params, 'properties')
properties.text = project_def['predefined-parameters']
if 'git-revision' in project_def and project_def['git-revision']:
params = XML.SubElement(tconfigs,
'hudson.plugins.git.'
'GitRevisionBuildParameters')
properties = XML.SubElement(params, 'combineQueuedCommits')
properties.text = 'false'
if 'property-file' in project_def and project_def['property-file']:
params = XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'FileBuildParameters')
properties = XML.SubElement(params, 'propertiesFile')
properties.text = project_def['property-file']
failOnMissing = XML.SubElement(params, 'failTriggerOnMissing')
failOnMissing.text = str(project_def.get('fail-on-missing',
False)).lower()
if ('current-parameters' in project_def
and project_def['current-parameters']):
XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'CurrentBuildParameters')
if ('node-parameters' in project_def
and project_def['node-parameters']):
XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'NodeParameters')
if 'svn-revision' in project_def and project_def['svn-revision']:
XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'SubversionRevisionBuildParameters')
if ('restrict-matrix-project' in project_def
and project_def['restrict-matrix-project']):
subset = XML.SubElement(tconfigs,
'hudson.plugins.parameterizedtrigger.'
'matrix.MatrixSubsetBuildParameters')
XML.SubElement(subset, 'filter').text = \
project_def['restrict-matrix-project']
if ('node-label-name' in project_def or
'node-label' in project_def):
params = XML.SubElement(tconfigs,
'org.jvnet.jenkins.plugins.'
'nodelabelparameter.'
'parameterizedtrigger.'
'NodeLabelBuildParameter')
name = XML.SubElement(params, 'name')
if 'node-label-name' in project_def:
name.text = project_def['node-label-name']
label = XML.SubElement(params, 'nodeLabel')
if 'node-label' in project_def:
label.text = project_def['node-label']
else:
tconfigs.set('class', 'java.util.Collections$EmptyList')
projects = XML.SubElement(tconfig, 'projects')
projects.text = project_def['project']
condition = XML.SubElement(tconfig, 'condition')
condition.text = project_def.get('condition', 'ALWAYS')
trigger_with_no_params = XML.SubElement(tconfig,
'triggerWithNoParameters')
trigger_with_no_params.text = 'false'
def trigger(parser, xml_parent, data):
"""yaml: trigger
Trigger non-parametrised builds of other jobs.
:arg str project: name of the job to trigger
:arg str threshold: when to trigger the other job (default 'SUCCESS'),
alternatives: SUCCESS, UNSTABLE, FAILURE
Example:
.. literalinclude:: /../../tests/publishers/fixtures/trigger_success.yaml
:language: yaml
"""
tconfig = XML.SubElement(xml_parent, 'hudson.tasks.BuildTrigger')
childProjects = XML.SubElement(tconfig, 'childProjects')
childProjects.text = data['project']
tthreshold = XML.SubElement(tconfig, 'threshold')
threshold = data.get('threshold', 'SUCCESS')
supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
if threshold not in supported_thresholds:
raise JenkinsJobsException("threshold must be one of %s" %
", ".join(supported_thresholds))
tname = XML.SubElement(tthreshold, 'name')
tname.text = hudson_model.THRESHOLDS[threshold]['name']
tordinal = XML.SubElement(tthreshold, 'ordinal')
tordinal.text = hudson_model.THRESHOLDS[threshold]['ordinal']
tcolor = XML.SubElement(tthreshold, 'color')
tcolor.text = hudson_model.THRESHOLDS[threshold]['color']
def clone_workspace(parser, xml_parent, data):
"""yaml: clone-workspace
Archive the workspace from builds of one project and reuse them as the SCM
source for another project.
Requires the Jenkins :jenkins-wiki:`Clone Workspace SCM Plugin
<Clone+Workspace+SCM+Plugin>`.
:arg str workspace-glob: Files to include in cloned workspace
:arg str workspace-exclude-glob: Files to exclude from cloned workspace
:arg str criteria: Criteria for build to be archived. Can be 'any',
'not failed', or 'successful'. (default: any )
:arg str archive-method: Choose the method to use for archiving the
workspace. Can be 'tar' or 'zip'. (default: tar)
:arg bool override-default-excludes: Override default ant excludes.
(default: false)
Minimal example:
.. literalinclude::
/../../tests/publishers/fixtures/clone-workspace001.yaml
:language: yaml
Full example:
.. literalinclude::
/../../tests/publishers/fixtures/clone-workspace002.yaml
:language: yaml
"""
cloneworkspace = XML.SubElement(
xml_parent,
'hudson.plugins.cloneworkspace.CloneWorkspacePublisher',
{'plugin': 'clone-workspace-scm'})
XML.SubElement(
cloneworkspace,
'workspaceGlob').text = data.get('workspace-glob', None)
if 'workspace-exclude-glob' in data:
XML.SubElement(
cloneworkspace,
'workspaceExcludeGlob').text = data['workspace-exclude-glob']
criteria_list = ['Any', 'Not Failed', 'Successful']
criteria = data.get('criteria', 'Any').title()
if 'criteria' in data and criteria not in criteria_list:
raise JenkinsJobsException(
'clone-workspace criteria must be one of: '
+ ', '.join(criteria_list))
else:
XML.SubElement(cloneworkspace, 'criteria').text = criteria
archive_list = ['TAR', 'ZIP']
archive_method = data.get('archive-method', 'TAR').upper()
if 'archive-method' in data and archive_method not in archive_list:
raise JenkinsJobsException(
'clone-workspace archive-method must be one of: '
+ ', '.join(archive_list))
else:
XML.SubElement(cloneworkspace, 'archiveMethod').text = archive_method
override_default_excludes_str = str(
data.get('override-default-excludes', False)).lower()
override_default_excludes_elem = XML.SubElement(
cloneworkspace, 'overrideDefaultExcludes')
override_default_excludes_elem.text = override_default_excludes_str
def cloverphp(parser, xml_parent, data):
"""yaml: cloverphp
Capture code coverage reports from PHPUnit
Requires the Jenkins :jenkins-wiki:`Clover PHP Plugin <Clover+PHP+Plugin>`.
Your job definition should pass to PHPUnit the --coverage-clover option
pointing to a file in the workspace (ex: clover-coverage.xml). The filename
has to be filled in the `xml-location` field.
:arg str xml-location: Path to the coverage XML file generated by PHPUnit
using --coverage-clover. Relative to workspace. (required)
:arg dict html: When existent, whether the plugin should generate a HTML
report. Note that PHPUnit already provide a HTML report via its
--cover-html option which can be set in your builder (optional):
* **dir** (str): Directory where HTML report will be generated relative
to workspace. (required in `html` dict).
* **archive** (bool): Whether to archive HTML reports (default True).
:arg list metric-targets: List of metric targets to reach, must be one of
**healthy**, **unhealthy** and **failing**. Each metric target can takes
two parameters:
* **method** Target for method coverage
* **statement** Target for statements coverage
Whenever a metric target is not filled in, the Jenkins plugin can fill in
defaults for you (as of v0.3.3 of the plugin the healthy target will have
method: 70 and statement: 80 if both are left empty). Jenkins Job Builder
will mimic that feature to ensure clean configuration diff.
Minimal example:
.. literalinclude:: /../../tests/publishers/fixtures/cloverphp001.yaml
:language: yaml
Full example:
.. literalinclude:: /../../tests/publishers/fixtures/cloverphp002.yaml
:language: yaml
"""
cloverphp = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.cloverphp.CloverPHPPublisher')
# The plugin requires clover XML file to parse
if 'xml-location' not in data:
raise JenkinsJobsException('xml-location must be set')
# Whether HTML publishing has been checked
html_publish = False
# By default, disableArchiving = false. Note that we use
# reversed logic.
html_archive = True
if 'html' in data:
html_publish = True
html_dir = data['html'].get('dir', None)
html_archive = data['html'].get('archive', html_archive)
if html_dir is None:
# No point in going further, the plugin would not work
raise JenkinsJobsException('htmldir is required in a html block')
XML.SubElement(cloverphp, 'publishHtmlReport').text = \
str(html_publish).lower()
if html_publish:
XML.SubElement(cloverphp, 'reportDir').text = html_dir
XML.SubElement(cloverphp, 'xmlLocation').text = data.get('xml-location')
XML.SubElement(cloverphp, 'disableArchiving').text = \
str(not html_archive).lower()
# Handle targets
# Plugin v0.3.3 will fill defaults for us whenever healthy targets are both
# blanks.
default_metrics = {
'healthy': {'method': 70, 'statement': 80}
}
allowed_metrics = ['healthy', 'unhealthy', 'failing']
metrics = data.get('metric-targets', [])
# list of dicts to dict
metrics = dict(kv for m in metrics for kv in m.items())
# Populate defaults whenever nothing has been filled by user.
for default in default_metrics.keys():
if metrics.get(default, None) is None:
metrics[default] = default_metrics[default]
# The plugin would at least define empty targets so make sure
# we output them all in the XML regardless of what the user
# has or has not entered.
for target in allowed_metrics:
cur_target = XML.SubElement(cloverphp, target + 'Target')
for t_type in ['method', 'statement']:
val = metrics.get(target, {}).get(t_type)
if val is None or type(val) != int:
continue
if val < 0 or val > 100:
raise JenkinsJobsException(
"Publisher cloverphp metric target %s:%s = %s "
"is not in valid range 0-100." % (target, t_type, val))
XML.SubElement(cur_target, t_type + 'Coverage').text = str(val)
def coverage(parser, xml_parent, data):
"""yaml: coverage
WARNING: The coverage function is deprecated. Instead, use the
cobertura function to generate a cobertura coverage report.
Requires the Jenkins :jenkins-wiki:`Cobertura Coverage Plugin
<Cobertura+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/coverage001.yaml
:language: yaml
"""
logger = logging.getLogger(__name__)
logger.warn("Coverage function is deprecated. Switch to cobertura.")
cobertura = XML.SubElement(xml_parent,
'hudson.plugins.cobertura.CoberturaPublisher')
XML.SubElement(cobertura, 'coberturaReportFile').text = '**/coverage.xml'
XML.SubElement(cobertura, 'onlyStable').text = 'false'
healthy = XML.SubElement(cobertura, 'healthyTarget')
targets = XML.SubElement(healthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'CONDITIONAL'
XML.SubElement(entry, 'int').text = '70'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'LINE'
XML.SubElement(entry, 'int').text = '80'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'METHOD'
XML.SubElement(entry, 'int').text = '80'
unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
targets = XML.SubElement(unhealthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'CONDITIONAL'
XML.SubElement(entry, 'int').text = '0'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'LINE'
XML.SubElement(entry, 'int').text = '0'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'METHOD'
XML.SubElement(entry, 'int').text = '0'
failing = XML.SubElement(cobertura, 'failingTarget')
targets = XML.SubElement(failing, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'CONDITIONAL'
XML.SubElement(entry, 'int').text = '0'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'LINE'
XML.SubElement(entry, 'int').text = '0'
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
).text = 'METHOD'
XML.SubElement(entry, 'int').text = '0'
XML.SubElement(cobertura, 'sourceEncoding').text = 'ASCII'
def cobertura(parser, xml_parent, data):
"""yaml: cobertura
Generate a cobertura coverage report.
Requires the Jenkins :jenkins-wiki:`Cobertura Coverage Plugin
<Cobertura+Plugin>`.
:arg str report-file: This is a file name pattern that can be used
to locate the cobertura xml report files (optional)
:arg bool only-stable: Include only stable builds (default false)
:arg bool fail-no-reports: fail builds if no coverage reports are found
(default false)
:arg bool fail-unhealthy: Unhealthy projects will be failed
(default false)
:arg bool fail-unstable: Unstable projects will be failed (default false)
:arg bool health-auto-update: Auto update threshold for health on
successful build (default false)
:arg bool stability-auto-update: Auto update threshold for stability on
successful build (default false)
:arg bool zoom-coverage-chart: Zoom the coverage chart and crop area below
the minimum and above the maximum coverage
of the past reports (default false)
:arg str source-encoding: Override the source encoding (default ASCII)
:arg dict targets:
:targets: (packages, files, classes, method, line, conditional)
* **healthy** (`int`): Healthy threshold (default 0)
* **unhealthy** (`int`): Unhealthy threshold (default 0)
* **failing** (`int`): Failing threshold (default 0)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/cobertura001.yaml
:language: yaml
"""
cobertura = XML.SubElement(xml_parent,
'hudson.plugins.cobertura.CoberturaPublisher')
XML.SubElement(cobertura, 'coberturaReportFile').text = data.get(
'report-file', '**/coverage.xml')
XML.SubElement(cobertura, 'onlyStable').text = str(
data.get('only-stable', False)).lower()
XML.SubElement(cobertura, 'failUnhealthy').text = str(
data.get('fail-unhealthy', False)).lower()
XML.SubElement(cobertura, 'failUnstable').text = str(
data.get('fail-unstable', False)).lower()
XML.SubElement(cobertura, 'autoUpdateHealth').text = str(
data.get('health-auto-update', False)).lower()
XML.SubElement(cobertura, 'autoUpdateStability').text = str(
data.get('stability-auto-update', False)).lower()
XML.SubElement(cobertura, 'zoomCoverageChart').text = str(
data.get('zoom-coverage-chart', False)).lower()
XML.SubElement(cobertura, 'failNoReports').text = str(
data.get('fail-no-reports', False)).lower()
healthy = XML.SubElement(cobertura, 'healthyTarget')
targets = XML.SubElement(healthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry,
'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('healthy', 0))
unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
targets = XML.SubElement(unhealthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('unhealthy',
0))
failing = XML.SubElement(cobertura, 'failingTarget')
targets = XML.SubElement(failing, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('failing', 0))
XML.SubElement(cobertura, 'sourceEncoding').text = data.get(
'source-encoding', 'ASCII')
def jacoco(parser, xml_parent, data):
"""yaml: jacoco
Generate a JaCoCo coverage report.
Requires the Jenkins :jenkins-wiki:`JaCoCo Plugin <JaCoCo+Plugin>`.
:arg str exec-pattern: This is a file name pattern that can be used to
locate the jacoco report files (default
``**/**.exec``)
:arg str class-pattern: This is a file name pattern that can be used
to locate class files (default ``**/classes``)
:arg str source-pattern: This is a file name pattern that can be used
to locate source files (default ``**/src/main/java``)
:arg bool update-build-status: Update the build according to the results
(default False)
:arg str inclusion-pattern: This is a file name pattern that can be used
to include certain class files (optional)
:arg str exclusion-pattern: This is a file name pattern that can be used
to exclude certain class files (optional)
:arg dict targets:
:targets: (instruction, branch, complexity, line, method, class)
* **healthy** (`int`): Healthy threshold (default 0)
* **unhealthy** (`int`): Unhealthy threshold (default 0)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/jacoco001.yaml
:language: yaml
"""
jacoco = XML.SubElement(xml_parent,
'hudson.plugins.jacoco.JacocoPublisher')
XML.SubElement(jacoco, 'execPattern').text = data.get(
'exec-pattern', '**/**.exec')
XML.SubElement(jacoco, 'classPattern').text = data.get(
'class-pattern', '**/classes')
XML.SubElement(jacoco, 'sourcePattern').text = data.get(
'source-pattern', '**/src/main/java')
XML.SubElement(jacoco, 'changeBuildStatus').text = data.get(
'update-build-status', False)
XML.SubElement(jacoco, 'inclusionPattern').text = data.get(
'inclusion-pattern', '')
XML.SubElement(jacoco, 'exclusionPattern').text = data.get(
'exclusion-pattern', '')
itemsList = ['instruction',
'branch',
'complexity',
'line',
'method',
'class']
for item in data['targets']:
item_name = next(iter(item.keys()))
if item_name not in itemsList:
raise JenkinsJobsException("item entered is not valid must be "
"one of: %s" % ",".join(itemsList))
item_values = item.get(item_name, 0)
XML.SubElement(jacoco,
'maximum' +
item_name.capitalize() +
'Coverage').text = str(item_values.get('healthy', 0))
XML.SubElement(jacoco,
'minimum' +
item_name.capitalize() +
'Coverage').text = str(item_values.get('unhealthy', 0))
def ftp(parser, xml_parent, data):
"""yaml: ftp
Upload files via FTP.
Requires the Jenkins :jenkins-wiki:`Publish over FTP Plugin
<Publish+Over+FTP+Plugin>`.
:arg str site: name of the ftp site
:arg str target: destination directory
:arg bool target-is-date-format: whether target is a date format. If true,
raw text should be quoted (default false)
:arg bool clean-remote: should the remote directory be deleted before
transferring files (default false)
:arg str source: source path specifier
:arg str excludes: excluded file pattern (optional)
:arg str remove-prefix: prefix to remove from uploaded file paths
(optional)
:arg bool fail-on-error: fail the build if an error occurs (default false).
:arg bool flatten: only create files on the server, don't create
directories (default false).
Example:
.. literalinclude:: /../../tests/publishers/fixtures/ftp001.yaml
:language: yaml
"""
console_prefix = 'FTP: '
plugin_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisherPlugin'
publisher_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisher'
transfer_tag = 'jenkins.plugins.publish__over__ftp.BapFtpTransfer'
plugin_reference_tag = 'jenkins.plugins.publish_over_ftp.' \
'BapFtpPublisherPlugin'
(_, transfer_node) = base_publish_over(xml_parent,
data,
console_prefix,
plugin_tag,
publisher_tag,
transfer_tag,
plugin_reference_tag)
XML.SubElement(transfer_node, 'asciiMode').text = 'false'
def junit(parser, xml_parent, data):
"""yaml: junit
Publish JUnit test results.
:arg str results: results filename
:arg bool keep-long-stdio: Retain long standard output/error in test
results (default true).
:arg bool test-stability: Add historical information about test
results stability (default false).
Requires the Jenkins :jenkins-wiki:`Test stability Plugin
<Test+stability+plugin>`.
:arg bool claim-build: Allow claiming of failed tests (default false)
Requires the Jenkins :jenkins-wiki:`Claim Plugin <Claim+plugin>`.
Minimal example using defaults:
.. literalinclude:: /../../tests/publishers/fixtures/junit001.yaml
:language: yaml
Full example:
.. literalinclude:: /../../tests/publishers/fixtures/junit002.yaml
:language: yaml
"""
junitresult = XML.SubElement(xml_parent,
'hudson.tasks.junit.JUnitResultArchiver')
XML.SubElement(junitresult, 'testResults').text = data['results']
XML.SubElement(junitresult, 'keepLongStdio').text = str(
data.get('keep-long-stdio', True)).lower()
datapublisher = XML.SubElement(junitresult, 'testDataPublishers')
if str(data.get('test-stability', False)).lower() == 'true':
XML.SubElement(datapublisher,
'de.esailors.jenkins.teststability'
'.StabilityTestDataPublisher')
if str(data.get('claim-build', False)).lower() == 'true':
XML.SubElement(datapublisher,
'hudson.plugins.claim.ClaimTestDataPublisher')
def xunit(parser, xml_parent, data):
"""yaml: xunit
Publish tests results. Requires the Jenkins :jenkins-wiki:`xUnit Plugin
<xUnit+Plugin>`.
:arg str thresholdmode: whether thresholds represents an absolute \
number of tests or a percentage. Either 'number' or 'percent', will \
default to 'number' if omitted.
:arg dict thresholds: list containing the thresholds for both \
'failed' and 'skipped' tests. Each entry should in turn have a \
list of "threshold name: values". The threshold names are \
'unstable', 'unstablenew', 'failure', 'failurenew'. Omitting a \
value will resort on xUnit default value (should be 0).
:arg int test-time-margin: Give the report time margin value (default to \
3000) in ms, before to fail if not new (unless the option 'Fail the build \
if test results were not updated this run' is checked).
:arg dict types: per framework configuration. The key should be \
one of the internal types we support:\
'aunit', 'boosttest', 'checktype', 'cpptest', 'cppunit', 'ctest', \
'embunit', 'fpcunit', 'junit', 'mstest', 'nunit', 'phpunit', 'tusar', \
'unittest', 'valgrind'.
The 'custom' type is not supported.
Each framework type can be configured using the following parameters:
:arg str pattern: An Ant pattern to look for Junit result files, \
relative to the workspace root.
:arg bool requireupdate: fail the build whenever fresh tests \
results have not been found (default: true).
:arg bool deleteoutput: delete temporary JUnit files (default: true)
:arg bool skip-if-no-test-files: Skip parsing this xUnit type report if \
there are no test reports files (default: false).
:arg bool stoponerror: Fail the build whenever an error occur during \
a result file processing (default: true).
Example:
.. literalinclude:: /../../tests/publishers/fixtures/xunit001.yaml
:language: yaml
"""
logger = logging.getLogger(__name__)
xunit = XML.SubElement(xml_parent, 'xunit')
# Map our internal types to the XML element names used by Jenkins plugin
types_to_plugin_types = {
'aunit': 'AUnitJunitHudsonTestType',
'boosttest': 'BoostTestJunitHudsonTestType',
'checktype': 'CheckType',
'cpptest': 'CppTestJunitHudsonTestType',
'cppunit': 'CppUnitJunitHudsonTestType',
'ctest': 'CTestType',
'embunit': 'EmbUnitType', # since plugin v1.84
'fpcunit': 'FPCUnitJunitHudsonTestType',
'junit': 'JUnitType',
'mstest': 'MSTestJunitHudsonTestType',
'nunit': 'NUnitJunitHudsonTestType',
'phpunit': 'PHPUnitJunitHudsonTestType',
'tusar': 'TUSARJunitHudsonTestType',
'unittest': 'UnitTestJunitHudsonTestType',
'valgrind': 'ValgrindJunitHudsonTestType',
# FIXME should implement the 'custom' type
}
implemented_types = types_to_plugin_types.keys() # shortcut
# Unit framework we are going to generate xml for
supported_types = []
for configured_type in data['types']:
type_name = next(iter(configured_type.keys()))
if type_name not in implemented_types:
logger.warn("Requested xUnit type '%s' is not yet supported",
type_name)
else:
# Append for generation
supported_types.append(configured_type)
# Generate XML for each of the supported framework types
xmltypes = XML.SubElement(xunit, 'types')
for supported_type in supported_types:
framework_name = next(iter(supported_type.keys()))
xmlframework = XML.SubElement(xmltypes,
types_to_plugin_types[framework_name])
XML.SubElement(xmlframework, 'pattern').text = \
supported_type[framework_name].get('pattern', '')
XML.SubElement(xmlframework, 'failIfNotNew').text = \
str(supported_type[framework_name].get(
'requireupdate', True)).lower()
XML.SubElement(xmlframework, 'deleteOutputFiles').text = \
str(supported_type[framework_name].get(
'deleteoutput', True)).lower()
XML.SubElement(xmlframework, 'skipNoTestFiles').text = \
str(supported_type[framework_name].get(
'skip-if-no-test-files', False)).lower()
XML.SubElement(xmlframework, 'stopProcessingIfError').text = \
str(supported_type[framework_name].get(
'stoponerror', True)).lower()
xmlthresholds = XML.SubElement(xunit, 'thresholds')
if 'thresholds' in data:
for t in data['thresholds']:
if not ('failed' in t or 'skipped' in t):
logger.warn(
"Unrecognized threshold, should be 'failed' or 'skipped'")
continue
elname = "org.jenkinsci.plugins.xunit.threshold.%sThreshold" \
% next(iter(t.keys())).title()
el = XML.SubElement(xmlthresholds, elname)
for threshold_name, threshold_value in \
next(iter(t.values())).items():
# Normalize and craft the element name for this threshold
elname = "%sThreshold" % threshold_name.lower().replace(
'new', 'New')
XML.SubElement(el, elname).text = threshold_value
# Whether to use percent of exact number of tests.
# Thresholdmode is either:
# - 1 : absolute (number of tests), default.
# - 2 : relative (percentage of tests)
thresholdmode = '1'
if 'percent' == data.get('thresholdmode', 'number'):
thresholdmode = '2'
XML.SubElement(xunit, 'thresholdMode').text = \
thresholdmode
extra_config = XML.SubElement(xunit, 'extraConfiguration')
XML.SubElement(extra_config, 'testTimeMargin').text = \
str(data.get('test-time-margin', '3000'))
def _violations_add_entry(xml_parent, name, data):
vmin = data.get('min', 10)
vmax = data.get('max', 999)
vunstable = data.get('unstable', 999)
pattern = data.get('pattern', None)
entry = XML.SubElement(xml_parent, 'entry')
XML.SubElement(entry, 'string').text = name
tconfig = XML.SubElement(entry, 'hudson.plugins.violations.TypeConfig')
XML.SubElement(tconfig, 'type').text = name
XML.SubElement(tconfig, 'min').text = str(vmin)
XML.SubElement(tconfig, 'max').text = str(vmax)
XML.SubElement(tconfig, 'unstable').text = str(vunstable)
XML.SubElement(tconfig, 'usePattern').text = 'false'
if pattern:
XML.SubElement(tconfig, 'pattern').text = pattern
else:
XML.SubElement(tconfig, 'pattern')
def violations(parser, xml_parent, data):
"""yaml: violations
Publish code style violations.
Requires the Jenkins :jenkins-wiki:`Violations Plugin <Violations>`.
The violations component accepts any number of dictionaries keyed
by the name of the violations system. The dictionary has the
following values:
:arg int min: sunny threshold
:arg int max: stormy threshold
:arg int unstable: unstable threshold
:arg str pattern: report filename pattern
Any system without a dictionary provided will use default values.
Valid systems are:
checkstyle, codenarc, cpd, cpplint, csslint, findbugs, fxcop,
gendarme, jcreport, jslint, pep8, perlcritic, pmd, pylint,
simian, stylecop
Example:
.. literalinclude:: /../../tests/publishers/fixtures/violations001.yaml
:language: yaml
"""
violations = XML.SubElement(xml_parent,
'hudson.plugins.violations.'
'ViolationsPublisher')
config = XML.SubElement(violations, 'config')
suppressions = XML.SubElement(config, 'suppressions',
{'class': 'tree-set'})
XML.SubElement(suppressions, 'no-comparator')
configs = XML.SubElement(config, 'typeConfigs')
XML.SubElement(configs, 'no-comparator')
for name in ['checkstyle',
'codenarc',
'cpd',
'cpplint',
'csslint',
'findbugs',
'fxcop',
'gendarme',
'jcreport',
'jslint',
'pep8',
'perlcritic',
'pmd',
'pylint',
'simian',
'stylecop']:
_violations_add_entry(configs, name, data.get(name, {}))
XML.SubElement(config, 'limit').text = '100'
XML.SubElement(config, 'sourcePathPattern')
XML.SubElement(config, 'fauxProjectPath')
XML.SubElement(config, 'encoding').text = 'default'
def findbugs(parser, xml_parent, data):
"""yaml: findbugs
FindBugs reporting for builds
Requires the Jenkins :jenkins-wiki:`FindBugs Plugin
<FindBugs+Plugin>`.
:arg str pattern: specifies the generated raw FindBugs XML report files,
such as \*\*/findbugs.xml or \*\*/findbugsXml.xml.
(Optional)
:arg bool rank-priority: Use rank as priority (default: false)
:arg str include-files: Comma separated list of files to include.
(Optional)
:arg str exclude-files: Comma separated list of files to exclude.
(Optional)
:arg bool can-run-on-failed: Weather or not to run plug-in on failed builds
(default: false)
:arg bool should-detect-modules: Determines if Ant or Maven modules should
be detected for all files that contain
warnings. (default: false)
:arg int healthy: Sunny threshold (optional)
:arg int unhealthy: Stormy threshold (optional)
:arg str health-threshold: Threshold priority for health status
('low', 'normal' or 'high', defaulted to 'low')
:arg bool dont-compute-new: If set to false, computes new warnings based on
the reference build (default true)
:arg bool use-delta-values: Use delta for new warnings. (Default: false)
:arg bool use-previous-build-as-reference: If set then the number of new
warnings will always be calculated based on the previous build. Otherwise
the reference build. (Default: false)
:arg bool use-stable-build-as-reference: The number of new warnings will be
calculated based on the last stable build, allowing reverts of unstable
builds where the number of warnings was decreased. (default false)
:arg dict thresholds:
:thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
Minimal Example:
.. literalinclude:: /../../tests/reporters/fixtures/findbugs-minimal.yaml
Full Example:
.. literalinclude:: /../../tests/publishers/fixtures/findbugs01.yaml
"""
findbugs = XML.SubElement(xml_parent,
'hudson.plugins.findbugs.FindBugsPublisher')
findbugs.set('plugin', 'findbugs')
findbugs_settings(findbugs, data)
build_trends_publisher('[FINDBUGS] ', findbugs, data)
def checkstyle(parser, xml_parent, data):
"""yaml: checkstyle
Publish trend reports with Checkstyle.
Requires the Jenkins :jenkins-wiki:`Checkstyle Plugin <Checkstyle+Plugin>`.
The checkstyle component accepts a dictionary with the
following values:
:arg str pattern: Report filename pattern (optional)
:arg bool can-run-on-failed: Also runs for failed builds, instead of just
stable or unstable builds (default false)
:arg bool should-detect-modules: Determines if Ant or Maven modules should
be detected for all files that contain warnings (default false)
:arg int healthy: Sunny threshold (optional)
:arg int unhealthy: Stormy threshold (optional)
:arg str health-threshold: Threshold priority for health status
('low', 'normal' or 'high', defaulted to 'low')
:arg dict thresholds: Mark build as failed or unstable if the number of
errors exceeds a threshold. (optional)
:thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
:arg str default-encoding: Encoding for parsing or showing files (optional)
:arg bool do-not-resolve-relative-paths: (default false)
:arg bool dont-compute-new: If set to false, computes new warnings based on
the reference build (default true)
:arg bool use-stable-build-as-reference: The number of new warnings will be
calculated based on the last stable build, allowing reverts of unstable
builds where the number of warnings was decreased. (default false)
:arg bool use-delta-values: If set then the number of new warnings is
calculated by subtracting the total number of warnings of the current
build from the reference build.
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/checkstyle004.yaml
:language: yaml
Full example:
.. literalinclude:: /../../tests/publishers/fixtures/checkstyle006.yaml
:language: yaml
"""
def convert_settings(lookup, data):
"""Helper to convert settings from one key to another
"""
for old_key, value in data.items():
if old_key in lookup:
# Insert value if key does not already exists
data.setdefault(lookup[old_key], value)
del data[old_key]
xml_element = XML.SubElement(xml_parent,
'hudson.plugins.checkstyle.'
'CheckStylePublisher')
# Convert old style yaml to new style
convert_settings({
'unHealthy': 'unhealthy',
'healthThreshold': 'health-threshold',
'defaultEncoding': 'default-encoding',
'canRunOnFailed': 'can-run-on-failed',
'shouldDetectModules': 'should-detect-modules'
}, data)
threshold_data = data.get('thresholds', {})
for threshold in ['unstable', 'failed']:
convert_settings({
'totalAll': 'total-all',
'totalHigh': 'total-high',
'totalNormal': 'total-normal',
'totalLow': 'total-low'
}, threshold_data.get(threshold, {}))
build_trends_publisher('[CHECKSTYLE] ', xml_element, data)
def scp(parser, xml_parent, data):
"""yaml: scp
Upload files via SCP
Requires the Jenkins :jenkins-wiki:`SCP Plugin <SCP+plugin>`.
When writing a publisher macro, it is important to keep in mind that
Jenkins uses Ant's `SCP Task
<https://ant.apache.org/manual/Tasks/scp.html>`_ via the Jenkins `SCP
Plugin <https://wiki.jenkins-ci.org/display/JENKINS/SCP+plugin>`_ which
relies on `FileSet <https://ant.apache.org/manual/Types/fileset.html>`_
and `DirSet <https://ant.apache.org/manual/Types/dirset.html>`_ patterns.
The relevant piece of documentation is excerpted below:
Source points to files which will be uploaded. You can use ant
includes syntax, eg. ``folder/dist/*.jar``. Path is constructed from
workspace root. Note that you cannot point files outside the workspace
directory. For example providing: ``../myfile.txt`` won't work...
Destination points to destination folder on remote site. It will be
created if doesn't exists and relative to root repository path. You
can define multiple blocks of source/destination pairs.
This means that absolute paths, e.g., ``/var/log/**`` will not work and
will fail to compile. All paths need to be relative to the directory that
the publisher runs and the paths have to be contained inside of that
directory. The relative working directory is usually::
/home/jenkins/workspace/${JOB_NAME}
:arg str site: name of the scp site
:arg str target: destination directory
:arg str source: source path specifier
:arg bool keep-hierarchy: keep the file hierarchy when uploading
(default false)
:arg bool copy-after-failure: copy files even if the job fails
(default false)
:arg bool copy-console: copy the console log (default false); if
specified, omit 'source'
Example:
.. literalinclude:: /../../tests/publishers/fixtures/scp001.yaml
:language: yaml
"""
site = data['site']
scp = XML.SubElement(xml_parent,
'be.certipost.hudson.plugin.SCPRepositoryPublisher')
XML.SubElement(scp, 'siteName').text = site
entries = XML.SubElement(scp, 'entries')
for entry in data['files']:
entry_e = XML.SubElement(entries, 'be.certipost.hudson.plugin.Entry')
XML.SubElement(entry_e, 'filePath').text = entry['target']
XML.SubElement(entry_e, 'sourceFile').text = entry.get('source', '')
if entry.get('keep-hierarchy', False):
XML.SubElement(entry_e, 'keepHierarchy').text = 'true'
else:
XML.SubElement(entry_e, 'keepHierarchy').text = 'false'
if entry.get('copy-console', False):
XML.SubElement(entry_e, 'copyConsoleLog').text = 'true'
else:
XML.SubElement(entry_e, 'copyConsoleLog').text = 'false'
if entry.get('copy-after-failure', False):
XML.SubElement(entry_e, 'copyAfterFailure').text = 'true'
else:
XML.SubElement(entry_e, 'copyAfterFailure').text = 'false'
def ssh(parser, xml_parent, data):
"""yaml: ssh
Upload files via SCP.
Requires the Jenkins :jenkins-wiki:`Publish over SSH Plugin
<Publish+Over+SSH+Plugin>`.
:arg str site: name of the ssh site
:arg str target: destination directory
:arg bool target-is-date-format: whether target is a date format. If true,
raw text should be quoted (default false)
:arg bool clean-remote: should the remote directory be deleted before
transferring files (default false)
:arg str source: source path specifier
:arg str command: a command to execute on the remote server (optional)
:arg int timeout: timeout in milliseconds for the Exec command (optional)
:arg bool use-pty: run the exec command in pseudo TTY (default false)
:arg str excludes: excluded file pattern (optional)
:arg str remove-prefix: prefix to remove from uploaded file paths
(optional)
:arg bool fail-on-error: fail the build if an error occurs (default false).
:arg bool always-publish-from-master: transfer the files through the master
before being sent to the remote server (defaults false)
:arg bool flatten: only create files on the server, don't create
directories (default false).
Example:
.. literalinclude:: /../../tests/publishers/fixtures/ssh001.yaml
:language: yaml
"""
console_prefix = 'SSH: '
plugin_tag = 'jenkins.plugins.publish__over__ssh.BapSshPublisherPlugin'
publisher_tag = 'jenkins.plugins.publish__over__ssh.BapSshPublisher'
transfer_tag = 'jenkins.plugins.publish__over__ssh.BapSshTransfer'
plugin_reference_tag = 'jenkins.plugins.publish_over_ssh.' \
'BapSshPublisherPlugin'
base_publish_over(xml_parent,
data,
console_prefix,
plugin_tag,
publisher_tag,
transfer_tag,
plugin_reference_tag)
def pipeline(parser, xml_parent, data):
"""yaml: pipeline
Specify a downstream project in a pipeline.
Requires the Jenkins :jenkins-wiki:`Build Pipeline Plugin
<Build+Pipeline+Plugin>`.
:arg str project: the name of the downstream project
:arg str predefined-parameters: parameters to pass to the other
job (optional)
:arg bool current-parameters: Whether to include the parameters passed
to the current build to the triggered job (optional)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/pipeline002.yaml
:language: yaml
You can build pipeline jobs that are re-usable in different pipelines by
using a :ref:`job-template` to define the pipeline jobs,
and variable substitution to specify the name of
the downstream job in the pipeline.
Job-specific substitutions are useful here (see :ref:`project`).
See 'samples/pipeline.yaml' for an example pipeline implementation.
"""
if 'project' in data and data['project'] != '':
pippub = XML.SubElement(xml_parent,
'au.com.centrumsystems.hudson.plugin.'
'buildpipeline.trigger.BuildPipelineTrigger')
configs = XML.SubElement(pippub, 'configs')
if 'predefined-parameters' in data:
params = XML.SubElement(configs,
'hudson.plugins.parameterizedtrigger.'
'PredefinedBuildParameters')
properties = XML.SubElement(params, 'properties')
properties.text = data['predefined-parameters']
if ('current-parameters' in data
and data['current-parameters']):
XML.SubElement(configs,
'hudson.plugins.parameterizedtrigger.'
'CurrentBuildParameters')
XML.SubElement(pippub, 'downstreamProjectNames').text = data['project']
def email(parser, xml_parent, data):
"""yaml: email
Email notifications on build failure.
:arg str recipients: Recipient email addresses (optional)
:arg bool notify-every-unstable-build: Send an email for every
unstable build (default true)
:arg bool send-to-individuals: Send an email to the individual
who broke the build (default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/email001.yaml
:language: yaml
"""
# TODO: raise exception if this is applied to a maven job
mailer = XML.SubElement(xml_parent,
'hudson.tasks.Mailer')
XML.SubElement(mailer, 'recipients').text = data.get('recipients', '')
# Note the logic reversal (included here to match the GUI
if data.get('notify-every-unstable-build', True):
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
else:
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
XML.SubElement(mailer, 'sendToIndividuals').text = str(
data.get('send-to-individuals', False)).lower()
def claim_build(parser, xml_parent, data):
"""yaml: claim-build
Claim build failures
Requires the Jenkins :jenkins-wiki:`Claim Plugin <Claim+plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/claim-build001.yaml
:language: yaml
"""
XML.SubElement(xml_parent, 'hudson.plugins.claim.ClaimPublisher')
def base_email_ext(parser, xml_parent, data, ttype):
trigger = XML.SubElement(xml_parent,
'hudson.plugins.emailext.plugins.trigger.'
+ ttype)
email = XML.SubElement(trigger, 'email')
XML.SubElement(email, 'recipientList').text = ''
XML.SubElement(email, 'subject').text = '$PROJECT_DEFAULT_SUBJECT'
XML.SubElement(email, 'body').text = '$PROJECT_DEFAULT_CONTENT'
if 'send-to' in data:
XML.SubElement(email, 'sendToDevelopers').text = \
str('developers' in data['send-to']).lower()
XML.SubElement(email, 'sendToRequester').text = \
str('requester' in data['send-to']).lower()
XML.SubElement(email, 'includeCulprits').text = \
str('culprits' in data['send-to']).lower()
XML.SubElement(email, 'sendToRecipientList').text = \
str('recipients' in data['send-to']).lower()
else:
XML.SubElement(email, 'sendToRequester').text = 'false'
XML.SubElement(email, 'sendToDevelopers').text = 'false'
XML.SubElement(email, 'includeCulprits').text = 'false'
XML.SubElement(email, 'sendToRecipientList').text = 'true'
def email_ext(parser, xml_parent, data):
"""yaml: email-ext
Extend Jenkin's built in email notification
Requires the Jenkins :jenkins-wiki:`Email-ext Plugin
<Email-ext+plugin>`.
:arg str recipients: Comma separated list of emails
:arg str reply-to: Comma separated list of emails that should be in
the Reply-To header for this project (default $DEFAULT_REPLYTO)
:arg str content-type: The content type of the emails sent. If not set, the
Jenkins plugin uses the value set on the main configuration page.
Possible values: 'html', 'text' or 'default' (default 'default')
:arg str subject: Subject for the email, can include variables like
${BUILD_NUMBER} or even groovy or javascript code
:arg str body: Content for the body of the email, can include variables
like ${BUILD_NUMBER}, but the real magic is using groovy or
javascript to hook into the Jenkins API itself
:arg bool attach-build-log: Include build log in the email (default false)
:arg str attachments: pattern of files to include as attachment (optional)
:arg bool always: Send an email for every result (default false)
:arg bool unstable: Send an email for an unstable result (default false)
:arg bool first-failure: Send an email for just the first failure
(default false)
:arg bool not-built: Send an email if not built (default false)
:arg bool aborted: Send an email if the build is aborted (default false)
:arg bool regression: Send an email if there is a regression
(default false)
:arg bool failure: Send an email if the build fails (default true)
:arg bool second-failure: Send an email for the second failure
(default false)
:arg bool improvement: Send an email if the build improves (default false)
:arg bool still-failing: Send an email if the build is still failing
(default false)
:arg bool success: Send an email for a successful build (default false)
:arg bool fixed: Send an email if the build is fixed (default false)
:arg bool still-unstable: Send an email if the build is still unstable
(default false)
:arg bool pre-build: Send an email before the build (default false)
:arg str presend-script: A Groovy script executed prior sending the mail.
(default '')
:arg bool save-output: Save email content to workspace (default false)
:arg str matrix-trigger: If using matrix projects, when to trigger
:matrix-trigger values:
* **both**
* **only-parent**
* **only-configurations**
:arg list send-to: list of recipients from the predefined groups
:send-to values:
* **developers** (disabled by default)
* **requester** (disabled by default)
* **culprits** (disabled by default)
* **recipients** (enabled by default)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/email-ext001.yaml
:language: yaml
"""
emailext = XML.SubElement(xml_parent,
'hudson.plugins.emailext.ExtendedEmailPublisher')
if 'recipients' in data:
XML.SubElement(emailext, 'recipientList').text = data['recipients']
else:
XML.SubElement(emailext, 'recipientList').text = '$DEFAULT_RECIPIENTS'
ctrigger = XML.SubElement(emailext, 'configuredTriggers')
if data.get('always', False):
base_email_ext(parser, ctrigger, data, 'AlwaysTrigger')
if data.get('unstable', False):
base_email_ext(parser, ctrigger, data, 'UnstableTrigger')
if data.get('first-failure', False):
base_email_ext(parser, ctrigger, data, 'FirstFailureTrigger')
if data.get('not-built', False):
base_email_ext(parser, ctrigger, data, 'NotBuiltTrigger')
if data.get('aborted', False):
base_email_ext(parser, ctrigger, data, 'AbortedTrigger')
if data.get('regression', False):
base_email_ext(parser, ctrigger, data, 'RegressionTrigger')
if data.get('failure', True):
base_email_ext(parser, ctrigger, data, 'FailureTrigger')
if data.get('second-failure', False):
base_email_ext(parser, ctrigger, data, 'SecondFailureTrigger')
if data.get('improvement', False):
base_email_ext(parser, ctrigger, data, 'ImprovementTrigger')
if data.get('still-failing', False):
base_email_ext(parser, ctrigger, data, 'StillFailingTrigger')
if data.get('success', False):
base_email_ext(parser, ctrigger, data, 'SuccessTrigger')
if data.get('fixed', False):
base_email_ext(parser, ctrigger, data, 'FixedTrigger')
if data.get('still-unstable', False):
base_email_ext(parser, ctrigger, data, 'StillUnstableTrigger')
if data.get('pre-build', False):
base_email_ext(parser, ctrigger, data, 'PreBuildTrigger')
content_type_mime = {
'text': 'text/plain',
'html': 'text/html',
'default': 'default',
}
ctype = data.get('content-type', 'default')
if ctype not in content_type_mime:
raise JenkinsJobsException('email-ext content type must be one of: %s'
% ', '.join(content_type_mime.keys()))
XML.SubElement(emailext, 'contentType').text = content_type_mime[ctype]
XML.SubElement(emailext, 'defaultSubject').text = data.get(
'subject', '$DEFAULT_SUBJECT')
XML.SubElement(emailext, 'defaultContent').text = data.get(
'body', '$DEFAULT_CONTENT')
XML.SubElement(emailext, 'attachmentsPattern').text = data.get(
'attachments', '')
XML.SubElement(emailext, 'presendScript').text = data.get(
'presend-script', '')
XML.SubElement(emailext, 'attachBuildLog').text = \
str(data.get('attach-build-log', False)).lower()
XML.SubElement(emailext, 'saveOutput').text = \
str(data.get('save-output', False)).lower()
XML.SubElement(emailext, 'replyTo').text = data.get('reply-to',
'$DEFAULT_REPLYTO')
matrix_dict = {'both': 'BOTH',
'only-configurations': 'ONLY_CONFIGURATIONS',
'only-parent': 'ONLY_PARENT'}
matrix_trigger = data.get('matrix-trigger', None)
# If none defined, then do not create entry
if matrix_trigger is not None:
if matrix_trigger not in matrix_dict:
raise JenkinsJobsException("matrix-trigger entered is not valid, "
"must be one of: %s" %
", ".join(matrix_dict.keys()))
XML.SubElement(emailext, 'matrixTriggerMode').text = \
matrix_dict.get(matrix_trigger)
def fingerprint(parser, xml_parent, data):
"""yaml: fingerprint
Fingerprint files to track them across builds
:arg str files: files to fingerprint, follows the @includes of Ant fileset
(default blank)
:arg bool record-artifacts: fingerprint all archived artifacts
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/fingerprint001.yaml
:language: yaml
"""
finger = XML.SubElement(xml_parent, 'hudson.tasks.Fingerprinter')
XML.SubElement(finger, 'targets').text = data.get('files', '')
XML.SubElement(finger, 'recordBuildArtifacts').text = str(data.get(
'record-artifacts', False)).lower()
def aggregate_tests(parser, xml_parent, data):
"""yaml: aggregate-tests
Aggregate downstream test results
:arg bool include-failed-builds: whether to include failed builds
Example:
.. literalinclude::
/../../tests/publishers/fixtures/aggregate-tests001.yaml
:language: yaml
"""
agg = XML.SubElement(xml_parent,
'hudson.tasks.test.AggregatedTestResultPublisher')
XML.SubElement(agg, 'includeFailedBuilds').text = str(data.get(
'include-failed-builds', False)).lower()
def aggregate_flow_tests(parser, xml_parent, data):
"""yaml: aggregate-flow-tests
Aggregate downstream test results in a Build Flow job.
Requires the Jenkins `Build Flow Test Aggregator Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/
Build+Flow+Test+Aggregator+Plugin>`_
Example:
.. literalinclude:: \
/../../tests/publishers/fixtures/aggregate-flow-tests.yaml
:language: yaml
"""
XML.SubElement(xml_parent,
'org.zeroturnaround.jenkins.'
'flowbuildtestaggregator.FlowTestAggregator')
def cppcheck(parser, xml_parent, data):
"""yaml: cppcheck
Cppcheck result publisher
Requires the Jenkins :jenkins-wiki:`Cppcheck Plugin <Cppcheck+Plugin>`.
:arg str pattern: file pattern for cppcheck xml report
for more optional parameters see the example
Example:
.. literalinclude:: /../../tests/publishers/fixtures/cppcheck001.yaml
:language: yaml
"""
cppextbase = XML.SubElement(xml_parent,
'org.jenkinsci.plugins.cppcheck.'
'CppcheckPublisher')
cppext = XML.SubElement(cppextbase, 'cppcheckConfig')
XML.SubElement(cppext, 'pattern').text = data['pattern']
XML.SubElement(cppext, 'ignoreBlankFiles').text = \
str(data.get('ignoreblankfiles', False)).lower()
csev = XML.SubElement(cppext, 'configSeverityEvaluation')
thrsh = data.get('thresholds', {})
XML.SubElement(csev, 'threshold').text = str(thrsh.get('unstable', ''))
XML.SubElement(csev, 'newThreshold').text = \
str(thrsh.get('new-unstable', ''))
XML.SubElement(csev, 'failureThreshold').text = \
str(thrsh.get('failure', ''))
XML.SubElement(csev, 'newFailureThreshold').text = \
str(thrsh.get('new-failure', ''))
XML.SubElement(csev, 'healthy').text = str(thrsh.get('healthy', ''))
XML.SubElement(csev, 'unHealthy').text = str(thrsh.get('unhealthy', ''))
sev = thrsh.get('severity', {})
XML.SubElement(csev, 'severityError').text = \
str(sev.get('error', True)).lower()
XML.SubElement(csev, 'severityWarning').text = \
str(sev.get('warning', True)).lower()
XML.SubElement(csev, 'severityStyle').text = \
str(sev.get('style', True)).lower()
XML.SubElement(csev, 'severityPerformance').text = \
str(sev.get('performance', True)).lower()
XML.SubElement(csev, 'severityInformation').text = \
str(sev.get('information', True)).lower()
graph = data.get('graph', {})
cgraph = XML.SubElement(cppext, 'configGraph')
x, y = graph.get('xysize', [500, 200])
XML.SubElement(cgraph, 'xSize').text = str(x)
XML.SubElement(cgraph, 'ySize').text = str(y)
gdisplay = graph.get('display', {})
XML.SubElement(cgraph, 'displayAllErrors').text = \
str(gdisplay.get('sum', True)).lower()
XML.SubElement(cgraph, 'displayErrorSeverity').text = \
str(gdisplay.get('error', False)).lower()
XML.SubElement(cgraph, 'displayWarningSeverity').text = \
str(gdisplay.get('warning', False)).lower()
XML.SubElement(cgraph, 'displayStyleSeverity').text = \
str(gdisplay.get('style', False)).lower()
XML.SubElement(cgraph, 'displayPerformanceSeverity').text = \
str(gdisplay.get('performance', False)).lower()
XML.SubElement(cgraph, 'displayInformationSeverity').text = \
str(gdisplay.get('information', False)).lower()
def logparser(parser, xml_parent, data):
"""yaml: logparser
Requires the Jenkins :jenkins-wiki:`Log Parser Plugin <Log+Parser+Plugin>`.
:arg str parse-rules: full path to parse rules
:arg bool unstable-on-warning: mark build unstable on warning
:arg bool fail-on-error: mark build failed on error
Example:
.. literalinclude:: /../../tests/publishers/fixtures/logparser001.yaml
:language: yaml
"""
clog = XML.SubElement(xml_parent,
'hudson.plugins.logparser.LogParserPublisher')
XML.SubElement(clog, 'unstableOnWarning').text = \
str(data.get('unstable-on-warning', False)).lower()
XML.SubElement(clog, 'failBuildOnError').text = \
str(data.get('fail-on-error', False)).lower()
# v1.08: this must be the full path, the name of the rules is not enough
XML.SubElement(clog, 'parsingRulesPath').text = data.get('parse-rules', '')
def copy_to_master(parser, xml_parent, data):
"""yaml: copy-to-master
Copy files to master from slave
Requires the Jenkins :jenkins-wiki:`Copy To Slave Plugin
<Copy+To+Slave+Plugin>`.
:arg list includes: list of file patterns to copy
:arg list excludes: list of file patterns to exclude
:arg string destination: absolute path into which the files will be copied.
If left blank they will be copied into the
workspace of the current job
Example:
.. literalinclude::
/../../tests/publishers/fixtures/copy-to-master001.yaml
:language: yaml
"""
p = 'com.michelin.cio.hudson.plugins.copytoslave.CopyToMasterNotifier'
cm = XML.SubElement(xml_parent, p)
XML.SubElement(cm, 'includes').text = ','.join(data.get('includes', ['']))
XML.SubElement(cm, 'excludes').text = ','.join(data.get('excludes', ['']))
XML.SubElement(cm, 'destinationFolder').text = \
data.get('destination', '')
if data.get('destination', ''):
XML.SubElement(cm, 'overrideDestinationFolder').text = 'true'
def jira(parser, xml_parent, data):
"""yaml: jira
Update relevant JIRA issues
Requires the Jenkins :jenkins-wiki:`JIRA Plugin <JIRA+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/jira001.yaml
:language: yaml
"""
XML.SubElement(xml_parent, 'hudson.plugins.jira.JiraIssueUpdater')
def groovy_postbuild(parser, xml_parent, data):
"""yaml: groovy-postbuild
Execute a groovy script.
Requires the Jenkins :jenkins-wiki:`Groovy Postbuild Plugin
<Groovy+Postbuild+Plugin>`.
Please pay attention on version of plugin you have installed.
There were incompatible changes between 1.x and 2.x. Please see
:jenkins-wiki:`home page <Groovy+Postbuild+Plugin>` of this plugin
for full information including migration process.
:arg str script: The groovy script to execute
:arg list classpath: List of additional classpaths (>=1.6)
:arg str on-failure: In case of script failure leave build as it is
for "nothing" option, mark build as unstable
for "unstable" and mark job as failure for "failed"
(default is "nothing")
:arg bool matrix-parent: Run script for matrix parent only (>=1.9)
(default false)
:arg bool sandbox: Execute script inside of groovy sandbox (>=2.0)
(default false)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/groovy-postbuild001.yaml
:language: yaml
"""
logger = logging.getLogger("%s:groovy-postbuild" % __name__)
# Backward compatibility with old format
if isinstance(data, six.string_types):
logger.warn(
"You use depricated configuration, please follow documentation "
"to change configuration. It is not going to be supported in "
"future releases!"
)
data = {
'script': data,
}
# There are incompatible changes, we need to know version
info = parser.registry.get_plugin_info('groovy-postbuild')
version = pkg_resources.parse_version(info.get('version', "0"))
# Version specific predicates
matrix_parent_support = version >= pkg_resources.parse_version("1.9")
security_plugin_support = version >= pkg_resources.parse_version("2.0")
extra_classpath_support = version >= pkg_resources.parse_version("1.6")
root_tag = (
'org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder'
)
groovy = XML.SubElement(xml_parent, root_tag)
behavior = data.get('on-failure')
XML.SubElement(groovy, 'behavior').text = {
'unstable': '1',
'failed': '2',
}.get(behavior, '0')
if matrix_parent_support:
XML.SubElement(
groovy,
'runForMatrixParent',
).text = str(data.get('matrix-parent', False)).lower()
classpaths = data.get('classpath', list())
if security_plugin_support:
script = XML.SubElement(groovy, 'script')
XML.SubElement(script, 'script').text = data.get('script')
XML.SubElement(script, 'sandbox').text = str(
data.get('sandbox', False)
).lower()
if classpaths:
classpath = XML.SubElement(script, 'classpath')
for path in classpaths:
script_path = XML.SubElement(classpath, 'entry')
XML.SubElement(script_path, 'url').text = path
else:
XML.SubElement(groovy, 'groovyScript').text = data.get('script')
if extra_classpath_support and classpaths:
classpath = XML.SubElement(groovy, 'classpath')
for path in classpaths:
script_path = XML.SubElement(
classpath,
'org.jvnet.hudson.plugins.groovypostbuild.'
'GroovyScriptPath',
)
XML.SubElement(script_path, 'path').text = path
def base_publish_over(xml_parent, data, console_prefix,
plugin_tag, publisher_tag,
transferset_tag, reference_plugin_tag):
outer = XML.SubElement(xml_parent, plugin_tag)
XML.SubElement(outer, 'consolePrefix').text = console_prefix
delegate = XML.SubElement(outer, 'delegate')
publishers = XML.SubElement(delegate, 'publishers')
inner = XML.SubElement(publishers, publisher_tag)
XML.SubElement(inner, 'configName').text = data['site']
XML.SubElement(inner, 'verbose').text = 'true'
transfers = XML.SubElement(inner, 'transfers')
transfersset = XML.SubElement(transfers, transferset_tag)
XML.SubElement(transfersset, 'remoteDirectory').text = data['target']
XML.SubElement(transfersset, 'sourceFiles').text = data['source']
if 'command' in data:
XML.SubElement(transfersset, 'execCommand').text = data['command']
if 'timeout' in data:
XML.SubElement(transfersset, 'execTimeout').text = str(data['timeout'])
if 'use-pty' in data:
XML.SubElement(transfersset, 'usePty').text = \
str(data.get('use-pty', False)).lower()
XML.SubElement(transfersset, 'excludes').text = data.get('excludes', '')
XML.SubElement(transfersset, 'removePrefix').text = \
data.get('remove-prefix', '')
XML.SubElement(transfersset, 'remoteDirectorySDF').text = \
str(data.get('target-is-date-format', False)).lower()
XML.SubElement(transfersset, 'flatten').text = \
str(data.get('flatten', False)).lower()
XML.SubElement(transfersset, 'cleanRemote').text = \
str(data.get('clean-remote', False)).lower()
XML.SubElement(inner, 'useWorkspaceInPromotion').text = 'false'
XML.SubElement(inner, 'usePromotionTimestamp').text = 'false'
XML.SubElement(delegate, 'continueOnError').text = 'false'
XML.SubElement(delegate, 'failOnError').text = \
str(data.get('fail-on-error', False)).lower()
XML.SubElement(delegate, 'alwaysPublishFromMaster').text = \
str(data.get('always-publish-from-master', False)).lower()
XML.SubElement(delegate, 'hostConfigurationAccess',
{'class': reference_plugin_tag,
'reference': '../..'})
return (outer, transfersset)
def cifs(parser, xml_parent, data):
"""yaml: cifs
Upload files via CIFS.
Requires the Jenkins :jenkins-wiki:`Publish over CIFS Plugin
<Publish+Over+CIFS+Plugin>`.
:arg str site: name of the cifs site/share
:arg str target: destination directory
:arg bool target-is-date-format: whether target is a date format. If true,
raw text should be quoted (default false)
:arg bool clean-remote: should the remote directory be deleted before
transferring files (default false)
:arg str source: source path specifier
:arg str excludes: excluded file pattern (optional)
:arg str remove-prefix: prefix to remove from uploaded file paths
(optional)
:arg bool fail-on-error: fail the build if an error occurs (default false).
:arg bool flatten: only create files on the server, don't create
directories (default false).
Example:
.. literalinclude:: /../../tests/publishers/fixtures/cifs001.yaml
:language: yaml
"""
console_prefix = 'CIFS: '
plugin_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisherPlugin'
publisher_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisher'
transfer_tag = 'jenkins.plugins.publish__over__cifs.CifsTransfer'
plugin_reference_tag = 'jenkins.plugins.publish_over_cifs.' \
'CifsPublisherPlugin'
base_publish_over(xml_parent,
data,
console_prefix,
plugin_tag,
publisher_tag,
transfer_tag,
plugin_reference_tag)
def cigame(parser, xml_parent, data):
"""yaml: cigame
This plugin introduces a game where users get points
for improving the builds.
Requires the Jenkins :jenkins-wiki:`The Continuous Integration Game plugin
<The+Continuous+Integration+Game+plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/cigame.yaml
:language: yaml
"""
XML.SubElement(xml_parent, 'hudson.plugins.cigame.GamePublisher')
def sonar(parser, xml_parent, data):
"""yaml: sonar
Sonar plugin support.
Requires the Jenkins `Sonar Plugin.
<http://docs.codehaus.org/pages/viewpage.action?pageId=116359341>`_
:arg str jdk: JDK to use (inherited from the job if omitted). (optional)
:arg str branch: branch onto which the analysis will be posted (optional)
:arg str language: source code language (optional)
:arg str maven-opts: options given to maven (optional)
:arg str additional-properties: sonar analysis parameters (optional)
:arg dict skip-global-triggers:
:Triggers: * **skip-when-scm-change** (`bool`): skip analysis when
build triggered by scm
* **skip-when-upstream-build** (`bool`): skip analysis when
build triggered by an upstream build
* **skip-when-envvar-defined** (`str`): skip analysis when
the specified environment variable is set to true
This publisher supports the post-build action exposed by the Jenkins
Sonar Plugin, which is triggering a Sonar Analysis with Maven.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/sonar001.yaml
:language: yaml
"""
sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
if 'jdk' in data:
XML.SubElement(sonar, 'jdk').text = data['jdk']
XML.SubElement(sonar, 'branch').text = data.get('branch', '')
XML.SubElement(sonar, 'language').text = data.get('language', '')
XML.SubElement(sonar, 'mavenOpts').text = data.get('maven-opts', '')
XML.SubElement(sonar, 'jobAdditionalProperties').text = \
data.get('additional-properties', '')
if 'skip-global-triggers' in data:
data_triggers = data['skip-global-triggers']
triggers = XML.SubElement(sonar, 'triggers')
XML.SubElement(triggers, 'skipScmCause').text = \
str(data_triggers.get('skip-when-scm-change', False)).lower()
XML.SubElement(triggers, 'skipUpstreamCause').text = \
str(data_triggers.get('skip-when-upstream-build', False)).lower()
XML.SubElement(triggers, 'envVar').text = \
data_triggers.get('skip-when-envvar-defined', '')
def performance(parser, xml_parent, data):
"""yaml: performance
Publish performance test results from jmeter and junit.
Requires the Jenkins :jenkins-wiki:`Performance Plugin
<Performance+Plugin>`.
:arg int failed-threshold: Specify the error percentage threshold that
set the build failed. A negative value means
don't use this threshold (default 0)
:arg int unstable-threshold: Specify the error percentage threshold that
set the build unstable. A negative value means
don't use this threshold (default 0)
:arg dict report:
:(jmeter or junit): (`dict` or `str`): Specify a custom report file
(optional; jmeter default \**/*.jtl, junit default **/TEST-\*.xml)
Examples:
.. literalinclude:: /../../tests/publishers/fixtures/performance001.yaml
:language: yaml
.. literalinclude:: /../../tests/publishers/fixtures/performance002.yaml
:language: yaml
.. literalinclude:: /../../tests/publishers/fixtures/performance003.yaml
:language: yaml
"""
logger = logging.getLogger(__name__)
perf = XML.SubElement(xml_parent, 'hudson.plugins.performance.'
'PerformancePublisher')
XML.SubElement(perf, 'errorFailedThreshold').text = str(data.get(
'failed-threshold', 0))
XML.SubElement(perf, 'errorUnstableThreshold').text = str(data.get(
'unstable-threshold', 0))
parsers = XML.SubElement(perf, 'parsers')
for item in data['report']:
if isinstance(item, dict):
item_name = next(iter(item.keys()))
item_values = item.get(item_name, None)
if item_name == 'jmeter':
jmhold = XML.SubElement(parsers, 'hudson.plugins.performance.'
'JMeterParser')
XML.SubElement(jmhold, 'glob').text = str(item_values)
elif item_name == 'junit':
juhold = XML.SubElement(parsers, 'hudson.plugins.performance.'
'JUnitParser')
XML.SubElement(juhold, 'glob').text = str(item_values)
else:
logger.fatal("You have not specified jmeter or junit, or "
"you have incorrectly assigned the key value.")
sys.exit(1)
elif isinstance(item, str):
if item == 'jmeter':
jmhold = XML.SubElement(parsers, 'hudson.plugins.performance.'
'JMeterParser')
XML.SubElement(jmhold, 'glob').text = '**/*.jtl'
elif item == 'junit':
juhold = XML.SubElement(parsers, 'hudson.plugins.performance.'
'JUnitParser')
XML.SubElement(juhold, 'glob').text = '**/TEST-*.xml'
else:
logger.fatal("You have not specified jmeter or junit, or "
"you have incorrectly assigned the key value.")
sys.exit(1)
def join_trigger(parser, xml_parent, data):
"""yaml: join-trigger
Trigger a job after all the immediate downstream jobs have completed
:arg list projects: list of projects to trigger
Example:
.. literalinclude:: /../../tests/publishers/fixtures/join-trigger001.yaml
:language: yaml
"""
jointrigger = XML.SubElement(xml_parent, 'join.JoinTrigger')
# Simple Project List
joinProjectsText = ','.join(data.get('projects', ['']))
XML.SubElement(jointrigger, 'joinProjects').text = joinProjectsText
def jabber(parser, xml_parent, data):
"""yaml: jabber
Integrates Jenkins with the Jabber/XMPP instant messaging protocol
Requires the Jenkins :jenkins-wiki:`Jabber Plugin <Jabber+Plugin>`.
:arg bool notify-on-build-start: Whether to send notifications
to channels when a build starts (default false)
:arg bool notify-scm-committers: Whether to send notifications
to the users that are suspected of having broken this build
(default false)
:arg bool notify-scm-culprits: Also send notifications to 'culprits'
from previous unstable/failed builds (default false)
:arg bool notify-upstream-committers: Whether to send notifications to
upstream committers if no committers were found for a broken build
(default false)
:arg bool notify-scm-fixers: Whether to send notifications to the users
that have fixed a broken build (default false)
:arg list group-targets: List of group targets to notify
:arg list individual-targets: List of individual targets to notify
:arg dict strategy: When to send notifications (default all)
:strategy values:
* **all** -- Always
* **failure** -- On any failure
* **failure-fixed** -- On failure and fixes
* **change** -- Only on state change
:arg dict message: Channel notification message (default summary-scm)
:message values:
* **summary-scm** -- Summary + SCM changes
* **summary** -- Just summary
* **summary-build** -- Summary and build parameters
* **summary-scm-fail** -- Summary, SCM changes, and failed tests
Example:
.. literalinclude:: /../../tests/publishers/fixtures/jabber001.yaml
:language: yaml
"""
j = XML.SubElement(xml_parent, 'hudson.plugins.jabber.im.transport.'
'JabberPublisher')
t = XML.SubElement(j, 'targets')
if 'group-targets' in data:
for group in data['group-targets']:
gcimt = XML.SubElement(t, 'hudson.plugins.im.'
'GroupChatIMMessageTarget')
XML.SubElement(gcimt, 'name').text = group
XML.SubElement(gcimt, 'notificationOnly').text = 'false'
if 'individual-targets' in data:
for individual in data['individual-targets']:
dimt = XML.SubElement(t, 'hudson.plugins.im.'
'DefaultIMMessageTarget')
XML.SubElement(dimt, 'value').text = individual
strategy = data.get('strategy', 'all')
strategydict = {'all': 'ALL',
'failure': 'ANY_FAILURE',
'failure-fixed': 'FAILURE_AND_FIXED',
'change': 'STATECHANGE_ONLY'}
if strategy not in strategydict:
raise JenkinsJobsException("Strategy entered is not valid, must be " +
"one of: all, failure, failure-fixed, or "
"change")
XML.SubElement(j, 'strategy').text = strategydict[strategy]
XML.SubElement(j, 'notifyOnBuildStart').text = str(
data.get('notify-on-build-start', False)).lower()
XML.SubElement(j, 'notifySuspects').text = str(
data.get('notify-scm-committers', False)).lower()
XML.SubElement(j, 'notifyCulprits').text = str(
data.get('notify-scm-culprits', False)).lower()
XML.SubElement(j, 'notifyFixers').text = str(
data.get('notify-scm-fixers', False)).lower()
XML.SubElement(j, 'notifyUpstreamCommitters').text = str(
data.get('notify-upstream-committers', False)).lower()
message = data.get('message', 'summary-scm')
messagedict = {'summary-scm': 'DefaultBuildToChatNotifier',
'summary': 'SummaryOnlyBuildToChatNotifier',
'summary-build': 'BuildParametersBuildToChatNotifier',
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
if message not in messagedict:
raise JenkinsJobsException("Message entered is not valid, must be one "
"of: summary-scm, summary, summary-build "
"or summary-scm-fail")
XML.SubElement(j, 'buildToChatNotifier', {
'class': 'hudson.plugins.im.build_notify.' + messagedict[message]})
XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS'
def workspace_cleanup(parser, xml_parent, data):
"""yaml: workspace-cleanup (post-build)
Requires the Jenkins :jenkins-wiki:`Workspace Cleanup Plugin
<Workspace+Cleanup+Plugin>`.
The pre-build workspace-cleanup is available as a wrapper.
:arg list include: list of files to be included
:arg list exclude: list of files to be excluded
:arg bool dirmatch: Apply pattern to directories too (default: false)
:arg list clean-if: clean depending on build status
:clean-if values:
* **success** (`bool`) (default: true)
* **unstable** (`bool`) (default: true)
* **failure** (`bool`) (default: true)
* **aborted** (`bool`) (default: true)
* **not-built** (`bool`) (default: true)
:arg bool fail-build: Fail the build if the cleanup fails (default: true)
:arg bool clean-parent: Cleanup matrix parent workspace (default: false)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/workspace-cleanup001.yaml
:language: yaml
"""
p = XML.SubElement(xml_parent,
'hudson.plugins.ws__cleanup.WsCleanup')
p.set("plugin", "ws-cleanup@0.14")
if "include" in data or "exclude" in data:
patterns = XML.SubElement(p, 'patterns')
for inc in data.get("include", []):
ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
XML.SubElement(ptrn, 'pattern').text = inc
XML.SubElement(ptrn, 'type').text = "INCLUDE"
for exc in data.get("exclude", []):
ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
XML.SubElement(ptrn, 'pattern').text = exc
XML.SubElement(ptrn, 'type').text = "EXCLUDE"
XML.SubElement(p, 'deleteDirs').text = \
str(data.get("dirmatch", False)).lower()
XML.SubElement(p, 'cleanupMatrixParent').text = \
str(data.get("clean-parent", False)).lower()
mask = [('success', 'cleanWhenSuccess'),
('unstable', 'cleanWhenUnstable'),
('failure', 'cleanWhenFailure'),
('not-built', 'cleanWhenNotBuilt'),
('aborted', 'cleanWhenAborted')]
clean = data.get('clean-if', [])
cdict = dict()
for d in clean:
cdict.update(d)
for k, v in mask:
XML.SubElement(p, v).text = str(cdict.pop(k, True)).lower()
if len(cdict) > 0:
raise ValueError('clean-if must be one of: %r' % list(mask.keys()))
if str(data.get("fail-build", False)).lower() == 'false':
XML.SubElement(p, 'notFailBuild').text = 'true'
else:
XML.SubElement(p, 'notFailBuild').text = 'false'
def maven_deploy(parser, xml_parent, data):
"""yaml: maven-deploy
Deploy artifacts to Maven repository.
:arg str id: Repository ID
:arg str url: Repository URL (optional)
:arg bool unique-version: Assign unique versions to snapshots
(default true)
:arg bool deploy-unstable: Deploy even if the build is unstable
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/maven-deploy001.yaml
:language: yaml
"""
p = XML.SubElement(xml_parent, 'hudson.maven.RedeployPublisher')
if 'id' in data:
XML.SubElement(p, 'id').text = data['id']
if 'url' in data:
XML.SubElement(p, 'url').text = data['url']
XML.SubElement(p, 'uniqueVersion').text = str(
data.get('unique-version', True)).lower()
XML.SubElement(p, 'evenIfUnstable').text = str(
data.get('deploy-unstable', False)).lower()
def text_finder(parser, xml_parent, data):
"""yaml: text-finder
This plugin lets you search keywords in the files you specified and
additionally check build status
Requires the Jenkins :jenkins-wiki:`Text-finder Plugin
<Text-finder+Plugin>`.
:arg str regexp: Specify a regular expression
:arg str fileset: Specify the path to search
:arg bool also-check-console-output:
Search the console output (default False)
:arg bool succeed-if-found:
Force a build to succeed if a string was found (default False)
:arg bool unstable-if-found:
Set build unstable instead of failing the build (default False)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/text-finder001.yaml
:language: yaml
"""
finder = XML.SubElement(xml_parent,
'hudson.plugins.textfinder.TextFinderPublisher')
if ('fileset' in data):
XML.SubElement(finder, 'fileSet').text = data['fileset']
XML.SubElement(finder, 'regexp').text = data['regexp']
check_output = str(data.get('also-check-console-output', False)).lower()
XML.SubElement(finder, 'alsoCheckConsoleOutput').text = check_output
succeed_if_found = str(data.get('succeed-if-found', False)).lower()
XML.SubElement(finder, 'succeedIfFound').text = succeed_if_found
unstable_if_found = str(data.get('unstable-if-found', False)).lower()
XML.SubElement(finder, 'unstableIfFound').text = unstable_if_found
def html_publisher(parser, xml_parent, data):
"""yaml: html-publisher
This plugin publishes HTML reports.
Requires the Jenkins :jenkins-wiki:`HTML Publisher Plugin
<HTML+Publisher+Plugin>`.
:arg str name: Report name
:arg str dir: HTML directory to archive
:arg str files: Specify the pages to display
:arg bool keep-all: keep HTML reports for each past build (Default False)
:arg bool allow-missing: Allow missing HTML reports (Default False)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/html-publisher001.yaml
:language: yaml
"""
reporter = XML.SubElement(xml_parent, 'htmlpublisher.HtmlPublisher')
targets = XML.SubElement(reporter, 'reportTargets')
ptarget = XML.SubElement(targets, 'htmlpublisher.HtmlPublisherTarget')
XML.SubElement(ptarget, 'reportName').text = data['name']
XML.SubElement(ptarget, 'reportDir').text = data['dir']
XML.SubElement(ptarget, 'reportFiles').text = data['files']
keep_all = str(data.get('keep-all', False)).lower()
XML.SubElement(ptarget, 'keepAll').text = keep_all
allow_missing = str(data.get('allow-missing', False)).lower()
XML.SubElement(ptarget, 'allowMissing').text = allow_missing
XML.SubElement(ptarget, 'wrapperName').text = "htmlpublisher-wrapper.html"
def rich_text_publisher(parser, xml_parent, data):
"""yaml: rich_text_publisher
This plugin puts custom rich text message to the Build pages and Job main
page.
Requires the Jenkins :jenkins-wiki:`Rich Text Publisher Plugin
<Rich+Text+Publisher+Plugin>`.
:arg str stable-text: The stable text
:arg str unstable-text: The unstable text if different from stable
(default '')
:arg str failed-text: The failed text if different from stable (default '')
:arg str parser-name: HTML, Confluence or WikiText
Example:
.. literalinclude:: /../../tests/publishers/fixtures/richtext001.yaml
:language: yaml
"""
parsers = ['HTML', 'Confluence', 'WikiText']
parser_name = data['parser-name']
if parser_name not in parsers:
raise JenkinsJobsException('parser-name must be one of: %s' %
", ".join(parsers))
reporter = XML.SubElement(
xml_parent,
'org.korosoft.jenkins.plugin.rtp.RichTextPublisher')
XML.SubElement(reporter, 'stableText').text = data['stable-text']
XML.SubElement(reporter, 'unstableText').text =\
data.get('unstable-text', '')
XML.SubElement(reporter, 'failedText').text = data.get('failed-text', '')
XML.SubElement(reporter, 'unstableAsStable').text =\
'False' if data.get('unstable-text', '') else 'True'
XML.SubElement(reporter, 'failedAsStable').text =\
'False' if data.get('failed-text', '') else 'True'
XML.SubElement(reporter, 'parserName').text = parser_name
def tap(parser, xml_parent, data):
"""yaml: tap
Adds support to TAP test result files
Requires the Jenkins :jenkins-wiki:`TAP Plugin <TAP+Plugin>`.
:arg str results: TAP test result files
:arg bool fail-if-no-results: Fail if no result (default False)
:arg bool failed-tests-mark-build-as-failure:
Mark build as failure if test fails (default False)
:arg bool output-tap-to-console: Output tap to console (default True)
:arg bool enable-subtests: Enable subtests (Default True)
:arg bool discard-old-reports: Discard old reports (Default False)
:arg bool todo-is-failure: Handle TODO's as failures (Default True)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/tap001.yaml
:language: yaml
"""
tap = XML.SubElement(xml_parent, 'org.tap4j.plugin.TapPublisher')
XML.SubElement(tap, 'testResults').text = data['results']
XML.SubElement(tap, 'failIfNoResults').text = str(
data.get('fail-if-no-results', False)).lower()
XML.SubElement(tap, 'failedTestsMarkBuildAsFailure').text = str(
data.get('failed-tests-mark-build-as-failure', False)).lower()
XML.SubElement(tap, 'outputTapToConsole').text = str(
data.get('output-tap-to-console', True)).lower()
XML.SubElement(tap, 'enableSubtests').text = str(
data.get('enable-subtests', True)).lower()
XML.SubElement(tap, 'discardOldReports').text = str(
data.get('discard-old-reports', False)).lower()
XML.SubElement(tap, 'todoIsFailure').text = str(
data.get('todo-is-failure', True)).lower()
def post_tasks(parser, xml_parent, data):
"""yaml: post-tasks
Adds support to post build task plugin
Requires the Jenkins :jenkins-wiki:`Post Build Task plugin
<Post+build+task>`.
:arg dict task: Post build task definition
:arg list task[matches]: list of matches when to run the task
:arg dict task[matches][*]: match definition
:arg str task[matches][*][log-text]: text to match against the log
:arg str task[matches][*][operator]: operator to apply with the next match
:task[matches][*][operator] values (default 'AND'):
* **AND**
* **OR**
:arg bool task[escalate-status]: Escalate the task status to the job
(default 'false')
:arg bool task[run-if-job-successful]: Run only if the job was successful
(default 'false')
:arg str task[script]: Shell script to run (default '')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/post-tasks001.yaml
:language: yaml
"""
pb_xml = XML.SubElement(xml_parent,
'hudson.plugins.postbuildtask.PostbuildTask')
tasks_xml = XML.SubElement(pb_xml, 'tasks')
for task in data:
task_xml = XML.SubElement(
tasks_xml,
'hudson.plugins.postbuildtask.TaskProperties')
matches_xml = XML.SubElement(task_xml, 'logTexts')
for match in task.get('matches', []):
lt_xml = XML.SubElement(
matches_xml,
'hudson.plugins.postbuildtask.LogProperties')
XML.SubElement(lt_xml, 'logText').text = str(
match.get('log-text', ''))
XML.SubElement(lt_xml, 'operator').text = str(
match.get('operator', 'AND')).upper()
XML.SubElement(task_xml, 'EscalateStatus').text = str(
task.get('escalate-status', False)).lower()
XML.SubElement(task_xml, 'RunIfJobSuccessful').text = str(
task.get('run-if-job-successful', False)).lower()
XML.SubElement(task_xml, 'script').text = str(
task.get('script', ''))
def postbuildscript(parser, xml_parent, data):
"""yaml: postbuildscript
Executes additional builders, script or Groovy after the build is
complete.
Requires the Jenkins :jenkins-wiki:`Post Build Script plugin
<PostBuildScript+Plugin>`.
:arg list generic-script: Paths to Batch/Shell scripts
:arg list groovy-script: Paths to Groovy scripts
:arg list groovy: Inline Groovy
:arg list builders: Any supported builders, see :doc:`builders`.
:arg bool onsuccess: Deprecated, replaced with script-only-if-succeeded
:arg bool script-only-if-succeeded: Scripts and builders are run only if
the build succeeded (default True)
:arg bool onfailure: Deprecated, replaced with script-only-if-failed
:arg bool script-only-if-failed: Scripts and builders are run only if the
build failed (default False)
:arg str execute-on: For matrix projects, scripts can be run after each
axis is built (`axes`), after all axis of the matrix
are built (`matrix`) or after each axis AND the matrix
are built (`both`).
The `script-only-if-succeeded` and `bool script-only-if-failed` options are
confusing. If you want the post build to always run regardless of the build
status, you should set them both to `false`.
Example:
.. literalinclude::
/../../tests/publishers/fixtures/postbuildscript001.yaml
:language: yaml
You can also execute :doc:`builders </builders>`:
.. literalinclude::
/../../tests/publishers/fixtures/postbuildscript002.yaml
:language: yaml
Run once after the whole matrix (all axes) is built:
.. literalinclude::
/../../tests/publishers/fixtures/postbuildscript003.yaml
:language: yaml
"""
pbs_xml = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.postbuildscript.PostBuildScript')
# Shell/Groovy in a file
script_types = {
'generic-script': 'GenericScript',
'groovy-script': 'GroovyScriptFile',
}
# Assuming yaml preserves order of input data make sure
# corresponding XML steps are generated in the same order
build_scripts = [(k, v) for k, v in data.items()
if k in script_types or k in ['groovy', 'builders']]
for step, script_data in build_scripts:
if step in script_types:
scripts_xml = XML.SubElement(pbs_xml, step[:-len('-script')] +
'ScriptFileList')
for shell_script in script_data:
script_xml = XML.SubElement(
scripts_xml,
'org.jenkinsci.plugins.postbuildscript.'
+ script_types[step])
file_path_xml = XML.SubElement(script_xml, 'filePath')
file_path_xml.text = shell_script
# Inlined Groovy
if step == 'groovy':
groovy_inline_xml = XML.SubElement(pbs_xml,
'groovyScriptContentList')
for groovy in script_data:
groovy_xml = XML.SubElement(
groovy_inline_xml,
'org.jenkinsci.plugins.postbuildscript.GroovyScriptContent'
)
groovy_content = XML.SubElement(groovy_xml, 'content')
groovy_content.text = groovy
# Inject builders
if step == 'builders':
build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps')
for builder in script_data:
parser.registry.dispatch('builder', parser, build_steps_xml,
builder)
# When to run the build? Note the plugin let one specify both options
# although they are antinomic
# onsuccess and onfailure parameters are deprecated, this is to keep
# backwards compatability
success_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfSuccess')
if 'script-only-if-succeeded' in data:
success_xml.text = str(data.get('script-only-if-succeeded',
True)).lower()
else:
success_xml.text = str(data.get('onsuccess', True)).lower()
failure_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfFailure')
if 'script-only-if-failed' in data:
failure_xml.text = str(data.get('script-only-if-failed',
False)).lower()
else:
failure_xml.text = str(data.get('onfailure', False)).lower()
# TODO: we may want to avoid setting "execute-on" on non-matrix jobs,
# either by skipping this part or by raising an error to let the user know
# an attempt was made to set execute-on on a non-matrix job. There are
# currently no easy ways to check for this though.
if 'execute-on' in data:
valid_values = ('matrix', 'axes', 'both')
execute_on = data['execute-on'].lower()
if execute_on not in valid_values:
raise JenkinsJobsException(
'execute-on must be one of %s, got %s' %
valid_values, execute_on
)
execute_on_xml = XML.SubElement(pbs_xml, 'executeOn')
execute_on_xml.text = execute_on.upper()
def xml_summary(parser, xml_parent, data):
"""yaml: xml-summary
Adds support for the Summary Display Plugin
Requires the Jenkins :jenkins-wiki:`Summary Display Plugin
<Summary+Display+Plugin>`.
:arg str files: Files to parse (default '')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/xml-summary001.yaml
:language: yaml
"""
summary = XML.SubElement(xml_parent,
'hudson.plugins.summary__report.'
'ACIPluginPublisher')
XML.SubElement(summary, 'name').text = data['files']
def robot(parser, xml_parent, data):
"""yaml: robot
Adds support for the Robot Framework Plugin
Requires the Jenkins :jenkins-wiki:`Robot Framework Plugin
<Robot+Framework+Plugin>`.
:arg str output-path: Path to directory containing robot xml and html files
relative to build workspace. (default '')
:arg str log-file-link: Name of log or report file to be linked on jobs
front page (default '')
:arg str report-html: Name of the html file containing robot test report
(default 'report.html')
:arg str log-html: Name of the html file containing detailed robot test log
(default 'log.html')
:arg str output-xml: Name of the xml file containing robot output
(default 'output.xml')
:arg str pass-threshold: Minimum percentage of passed tests to consider
the build successful (default 0.0)
:arg str unstable-threshold: Minimum percentage of passed test to
consider the build as not failed (default 0.0)
:arg bool only-critical: Take only critical tests into account when
checking the thresholds (default true)
:arg list other-files: list other files to archive (default '')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/robot001.yaml
:language: yaml
"""
parent = XML.SubElement(xml_parent, 'hudson.plugins.robot.RobotPublisher')
XML.SubElement(parent, 'outputPath').text = data['output-path']
XML.SubElement(parent, 'logFileLink').text = str(
data.get('log-file-link', ''))
XML.SubElement(parent, 'reportFileName').text = str(
data.get('report-html', 'report.html'))
XML.SubElement(parent, 'logFileName').text = str(
data.get('log-html', 'log.html'))
XML.SubElement(parent, 'outputFileName').text = str(
data.get('output-xml', 'output.xml'))
XML.SubElement(parent, 'passThreshold').text = str(
data.get('pass-threshold', 0.0))
XML.SubElement(parent, 'unstableThreshold').text = str(
data.get('unstable-threshold', 0.0))
XML.SubElement(parent, 'onlyCritical').text = str(
data.get('only-critical', True)).lower()
other_files = XML.SubElement(parent, 'otherFiles')
for other_file in data['other-files']:
XML.SubElement(other_files, 'string').text = str(other_file)
def warnings(parser, xml_parent, data):
"""yaml: warnings
Generate trend report for compiler warnings in the console log or
in log files. Requires the Jenkins :jenkins-wiki:`Warnings Plugin
<Warnings+Plugin>`.
:arg list console-log-parsers: The parser to use to scan the console
log (default '')
:arg dict workspace-file-scanners:
:workspace-file-scanners:
* **file-pattern** (`str`) -- Fileset 'includes' setting that
specifies the files to scan for warnings
* **scanner** (`str`) -- The parser to use to scan the files
provided in workspace-file-pattern (default '')
:arg str files-to-include: Comma separated list of regular
expressions that specifies the files to include in the report
(based on their absolute filename). By default all files are
included
:arg str files-to-ignore: Comma separated list of regular expressions
that specifies the files to exclude from the report (based on their
absolute filename). (default '')
:arg bool run-always: By default, this plug-in runs only for stable or
unstable builds, but not for failed builds. Set to true if the
plug-in should run even for failed builds. (default false)
:arg bool detect-modules: Determines if Ant or Maven modules should be
detected for all files that contain warnings. Activating this
option may increase your build time since the detector scans
the whole workspace for 'build.xml' or 'pom.xml' files in order
to assign the correct module names. (default false)
:arg bool resolve-relative-paths: Determines if relative paths in
warnings should be resolved using a time expensive operation that
scans the whole workspace for matching files. Deactivate this
option if you encounter performance problems. (default false)
:arg int health-threshold-high: The upper threshold for the build
health. If left empty then no health report is created. If
the actual number of warnings is between the provided
thresholds then the build health is interpolated (default '')
:arg int health-threshold-low: The lower threshold for the build
health. See health-threshold-high. (default '')
:arg dict health-priorities: Determines which warning priorities
should be considered when evaluating the build health (default
all-priorities)
:health-priorities values:
* **priority-high** -- Only priority high
* **high-and-normal** -- Priorities high and normal
* **all-priorities** -- All priorities
:arg dict total-thresholds: If the number of total warnings is greater
than one of these thresholds then a build is considered as unstable
or failed, respectively. (default '')
:total-thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
:arg dict new-thresholds: If the specified number of new warnings exceeds
one of these thresholds then a build is considered as unstable or
failed, respectively. (default '')
:new-thresholds:
* **unstable** (`dict`)
:unstable: * **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-high** (`int`)
:arg bool use-delta-for-new-warnings: If set then the number of new
warnings is calculated by subtracting the total number of warnings
of the current build from the reference build. This may lead to wrong
results if you have both fixed and new warnings in a build. If not set,
then the number of new warnings is calculated by an asymmetric set
difference of the warnings in the current and reference build. This
will find all new warnings even if the number of total warnings is
decreasing. However, sometimes false positives will be reported due
to minor changes in a warning (refactoring of variable of method
names, etc.) (default false)
:arg bool only-use-stable-builds-as-reference: The number of new warnings
will be calculated based on the last stable build, allowing reverts
of unstable builds where the number of warnings was decreased.
(default false)
:arg str default-encoding: Default encoding when parsing or showing files
Leave empty to use default encoding of platform (default '')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/warnings001.yaml
:language: yaml
"""
warnings = XML.SubElement(xml_parent,
'hudson.plugins.warnings.'
'WarningsPublisher')
console = XML.SubElement(warnings, 'consoleParsers')
for parser in data.get('console-log-parsers', []):
console_parser = XML.SubElement(console,
'hudson.plugins.warnings.'
'ConsoleParser')
XML.SubElement(console_parser, 'parserName').text = parser
workspace = XML.SubElement(warnings, 'parserConfigurations')
for wfs in data.get('workspace-file-scanners', []):
workspace_pattern = XML.SubElement(workspace,
'hudson.plugins.warnings.'
'ParserConfiguration')
XML.SubElement(workspace_pattern, 'pattern').text = \
wfs['file-pattern']
XML.SubElement(workspace_pattern, 'parserName').text = \
wfs['scanner']
warnings_to_include = data.get('files-to-include', '')
XML.SubElement(warnings, 'includePattern').text = warnings_to_include
warnings_to_ignore = data.get('files-to-ignore', '')
XML.SubElement(warnings, 'excludePattern').text = warnings_to_ignore
run_always = str(data.get('run-always', False)).lower()
XML.SubElement(warnings, 'canRunOnFailed').text = run_always
detect_modules = str(data.get('detect-modules', False)).lower()
XML.SubElement(warnings, 'shouldDetectModules').text = detect_modules
# Note the logic reversal (included here to match the GUI)
XML.SubElement(warnings, 'doNotResolveRelativePaths').text = \
str(not data.get('resolve-relative-paths', False)).lower()
health_threshold_high = str(data.get('health-threshold-high', ''))
XML.SubElement(warnings, 'healthy').text = health_threshold_high
health_threshold_low = str(data.get('health-threshold-low', ''))
XML.SubElement(warnings, 'unHealthy').text = health_threshold_low
prioritiesDict = {'priority-high': 'high',
'high-and-normal': 'normal',
'all-priorities': 'low'}
priority = data.get('health-priorities', 'all-priorities')
if priority not in prioritiesDict:
raise JenkinsJobsException("Health-Priority entered is not valid must "
"be one of: %s" %
",".join(prioritiesDict.keys()))
XML.SubElement(warnings, 'thresholdLimit').text = prioritiesDict[priority]
td = XML.SubElement(warnings, 'thresholds')
for base in ["total", "new"]:
thresholds = data.get("%s-thresholds" % base, {})
for status in ["unstable", "failed"]:
bystatus = thresholds.get(status, {})
for level in ["all", "high", "normal", "low"]:
val = str(bystatus.get("%s-%s" % (base, level), ''))
XML.SubElement(td, "%s%s%s" % (status,
base.capitalize(), level.capitalize())
).text = val
if data.get('new-thresholds'):
XML.SubElement(warnings, 'dontComputeNew').text = 'false'
delta = data.get('use-delta-for-new-warnings', False)
XML.SubElement(warnings, 'useDeltaValues').text = str(delta).lower()
use_stable_builds = data.get('only-use-stable-builds-as-reference',
False)
XML.SubElement(warnings, 'useStableBuildAsReference').text = str(
use_stable_builds).lower()
else:
XML.SubElement(warnings, 'dontComputeNew').text = 'true'
XML.SubElement(warnings, 'useStableBuildAsReference').text = 'false'
XML.SubElement(warnings, 'useDeltaValues').text = 'false'
encoding = data.get('default-encoding', '')
XML.SubElement(warnings, 'defaultEncoding').text = encoding
def sloccount(parser, xml_parent, data):
"""yaml: sloccount
Generates the trend report for SLOCCount
Requires the Jenkins :jenkins-wiki:`SLOCCount Plugin <SLOCCount+Plugin>`.
:arg str report-files: Setting that specifies the generated raw
SLOCCount report files.
Be sure not to include any non-report files into
this pattern. The report files must have been
generated by sloccount using the
"--wide --details" options.
(default: '\*\*/sloccount.sc')
:arg str charset: The character encoding to be used to read the SLOCCount
result files. (default: 'UTF-8')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/sloccount001.yaml
:language: yaml
"""
top = XML.SubElement(xml_parent,
'hudson.plugins.sloccount.SloccountPublisher')
XML.SubElement(top, 'pattern').text = data.get('report-files',
'**/sloccount.sc')
XML.SubElement(top, 'encoding').text = data.get('charset', 'UTF-8')
def ircbot(parser, xml_parent, data):
"""yaml: ircbot
ircbot enables Jenkins to send build notifications via IRC and lets you
interact with Jenkins via an IRC bot.
Requires the Jenkins :jenkins-wiki:`IRC Plugin <IRC+Plugin>`.
:arg string strategy: When to send notifications
:strategy values:
* **all** always (default)
* **any-failure** on any failure_and_fixed
* **failure-and-fixed** on failure and fixes
* **new-failure-and-fixed** on new failure and fixes
* **statechange-only** only on state change
:arg bool notify-start: Whether to send notifications to channels when a
build starts
(default: false)
:arg bool notify-committers: Whether to send notifications to the users
that are suspected of having broken this build
(default: false)
:arg bool notify-culprits: Also send notifications to 'culprits' from
previous unstable/failed builds
(default: false)
:arg bool notify-upstream: Whether to send notifications to upstream
committers if no committers were found for a
broken build
(default: false)
:arg bool notify-fixers: Whether to send notifications to the users that
have fixed a broken build
(default: false)
:arg string message-type: Channel Notification Message.
:message-type values:
* **summary-scm** for summary and SCM changes (default)
* **summary** for summary only
* **summary-params** for summary and build parameters
* **summary-scm-fail** for summary, SCM changes, failures)
:arg list channels: list channels definitions
If empty, it takes channel from Jenkins configuration.
(default: empty)
WARNING: the IRC plugin requires the channel to be
configured in the system wide configuration or the jobs
will fail to emit notifications to the channel
:Channel: * **name** (`str`) Channel name
* **password** (`str`) Channel password (optional)
* **notify-only** (`bool`) Set to true if you want to
disallow bot commands (default: false)
:arg string matrix-notifier: notify for matrix projects
instant-messaging-plugin injects an additional
field in the configuration form whenever the
project is a multi-configuration project
:matrix-notifier values:
* **all**
* **only-configurations** (default)
* **only-parent**
Example:
.. literalinclude:: /../../tests/publishers/fixtures/ircbot001.yaml
:language: yaml
"""
top = XML.SubElement(xml_parent, 'hudson.plugins.ircbot.IrcPublisher')
message_dict = {'summary-scm': 'DefaultBuildToChatNotifier',
'summary': 'SummaryOnlyBuildToChatNotifier',
'summary-params': 'BuildParametersBuildToChatNotifier',
'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
message = data.get('message-type', 'summary-scm')
if message not in message_dict:
raise JenkinsJobsException("message-type entered is not valid, must "
"be one of: %s" %
", ".join(message_dict.keys()))
message = "hudson.plugins.im.build_notify." + message_dict.get(message)
XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
strategy_dict = {'all': 'ALL',
'any-failure': 'ANY_FAILURE',
'failure-and-fixed': 'FAILURE_AND_FIXED',
'new-failure-and-fixed': 'NEW_FAILURE_AND_FIXED',
'statechange-only': 'STATECHANGE_ONLY'}
strategy = data.get('strategy', 'all')
if strategy not in strategy_dict:
raise JenkinsJobsException("strategy entered is not valid, must be "
"one of: %s" %
", ".join(strategy_dict.keys()))
XML.SubElement(top, 'strategy').text = strategy_dict.get(strategy)
targets = XML.SubElement(top, 'targets')
channels = data.get('channels', [])
for channel in channels:
sub = XML.SubElement(targets,
'hudson.plugins.im.GroupChatIMMessageTarget')
XML.SubElement(sub, 'name').text = channel.get('name')
XML.SubElement(sub, 'password').text = channel.get('password')
XML.SubElement(sub, 'notificationOnly').text = str(
channel.get('notify-only', False)).lower()
XML.SubElement(top, 'notifyOnBuildStart').text = str(
data.get('notify-start', False)).lower()
XML.SubElement(top, 'notifySuspects').text = str(
data.get('notify-committers', False)).lower()
XML.SubElement(top, 'notifyCulprits').text = str(
data.get('notify-culprits', False)).lower()
XML.SubElement(top, 'notifyFixers').text = str(
data.get('notify-fixers', False)).lower()
XML.SubElement(top, 'notifyUpstreamCommitters').text = str(
data.get('notify-upstream', False)).lower()
matrix_dict = {'all': 'ALL',
'only-configurations': 'ONLY_CONFIGURATIONS',
'only-parent': 'ONLY_PARENT'}
matrix = data.get('matrix-notifier', 'only-configurations')
if matrix not in matrix_dict:
raise JenkinsJobsException("matrix-notifier entered is not valid, "
"must be one of: %s" %
", ".join(matrix_dict.keys()))
XML.SubElement(top, 'matrixMultiplier').text = matrix_dict.get(matrix)
def plot(parser, xml_parent, data):
"""yaml: plot
Plot provides generic plotting (or graphing).
Requires the Jenkins :jenkins-wiki:`Plot Plugin <Plot+Plugin>`.
:arg str title: title for the graph
(default: '')
:arg str yaxis: title of Y axis
:arg str group: name of the group to which the plot belongs
:arg int num-builds: number of builds to plot across
(default: plot all builds)
:arg str style: Specifies the graph style of the plot
Can be: area, bar, bar3d, line, line3d, stackedArea,
stackedbar, stackedbar3d, waterfall
(default: 'line')
:arg bool use-description: When false, the X-axis labels are formed
using build numbers and dates, and the
corresponding tooltips contain the build
descriptions. When enabled, the contents of
the labels and tooltips are swapped, with the
descriptions used as X-axis labels and the
build number and date used for tooltips.
(default: False)
:arg str csv-file-name: Use for choosing the file name in which the data
will be persisted. If none specified and random
name is generated as done in the Jenkins Plot
plugin.
(default: random generated .csv filename, same
behaviour as the Jenkins Plot plugin)
:arg list series: list data series definitions
:Serie: * **file** (`str`) : files to include
* **inclusion-flag** filtering mode for CSV files. Possible
values are:
* **off** (default)
* **include-by-string**
* **exclude-by-string**
* **include-by-column**
* **exclude-by-column**
* **exclude** (`str`) : exclude pattern for CSV file.
* **url** (`str`) : for 'csv' and 'xml' file types
used when you click on a point (default: empty)
* **display-table** (`bool`) : for 'csv' file type
if true, original CSV will be shown above plot (default: False)
* **label** (`str`) : used by 'properties' file type
Specifies the legend label for this data series.
(default: empty)
* **format** (`str`) : Type of file where we get datas.
Can be: properties, csv, xml
* **xpath-type** (`str`) : The result type of the expression must
be supplied due to limitations in the java.xml.xpath parsing.
The result can be: node, nodeset, boolean, string, or number.
Strings and numbers will be converted to double. Boolean will
be converted to 1 for true, and 0 for false. (default: 'node')
* **xpath** (`str`) : used by 'xml' file type
Xpath which selects the values that should be plotted.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/plot004.yaml
:language: yaml
"""
top = XML.SubElement(xml_parent, 'hudson.plugins.plot.PlotPublisher')
plots = XML.SubElement(top, 'plots')
format_dict = {'properties': 'hudson.plugins.plot.PropertiesSeries',
'csv': 'hudson.plugins.plot.CSVSeries',
'xml': 'hudson.plugins.plot.XMLSeries'}
xpath_dict = {'nodeset': 'NODESET', 'node': 'NODE', 'string': 'STRING',
'boolean': 'BOOLEAN', 'number': 'NUMBER'}
inclusion_dict = {'off': 'OFF',
'include-by-string': 'INCLUDE_BY_STRING',
'exclude-by-string': 'EXCLUDE_BY_STRING',
'include-by-column': 'INCLUDE_BY_COLUMN',
'exclude-by-column': 'EXCLUDE_BY_COLUMN'}
for plot in data:
plugin = XML.SubElement(plots, 'hudson.plugins.plot.Plot')
XML.SubElement(plugin, 'title').text = plot.get('title', '')
XML.SubElement(plugin, 'yaxis').text = plot['yaxis']
XML.SubElement(plugin, 'csvFileName').text = \
plot.get('csv-file-name', '%s.csv' % random.randrange(2 << 32))
topseries = XML.SubElement(plugin, 'series')
series = plot['series']
for serie in series:
format_data = serie.get('format')
if format_data not in format_dict:
raise JenkinsJobsException("format entered is not valid, must "
"be one of: %s" %
" , ".join(format_dict.keys()))
subserie = XML.SubElement(topseries, format_dict.get(format_data))
XML.SubElement(subserie, 'file').text = serie.get('file')
if format_data == 'properties':
XML.SubElement(subserie, 'label').text = serie.get('label', '')
if format_data == 'csv':
inclusion_flag = serie.get('inclusion-flag', 'off')
if inclusion_flag not in inclusion_dict:
raise JenkinsJobsException("Inclusion flag result entered "
"is not valid, must be one of: "
"%s"
% ", ".join(inclusion_dict))
XML.SubElement(subserie, 'inclusionFlag').text = \
inclusion_dict.get(inclusion_flag)
XML.SubElement(subserie, 'exclusionValues').text = \
serie.get('exclude', '')
XML.SubElement(subserie, 'url').text = serie.get('url', '')
XML.SubElement(subserie, 'displayTableFlag').text = \
str(plot.get('display-table', False)).lower()
if format_data == 'xml':
XML.SubElement(subserie, 'url').text = serie.get('url', '')
XML.SubElement(subserie, 'xpathString').text = \
serie.get('xpath')
xpathtype = serie.get('xpath-type', 'node')
if xpathtype not in xpath_dict:
raise JenkinsJobsException("XPath result entered is not "
"valid, must be one of: %s" %
", ".join(xpath_dict))
XML.SubElement(subserie, 'nodeTypeString').text = \
xpath_dict.get(xpathtype)
XML.SubElement(subserie, 'fileType').text = serie.get('format')
XML.SubElement(plugin, 'group').text = plot['group']
XML.SubElement(plugin, 'useDescr').text = \
str(plot.get('use-description', False)).lower()
XML.SubElement(plugin, 'numBuilds').text = plot.get('num-builds', '')
style_list = ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea',
'stackedbar', 'stackedbar3d', 'waterfall']
style = plot.get('style', 'line')
if style not in style_list:
raise JenkinsJobsException("style entered is not valid, must be "
"one of: %s" % ", ".join(style_list))
XML.SubElement(plugin, 'style').text = style
def git(parser, xml_parent, data):
"""yaml: git
This plugin will configure the Jenkins Git plugin to
push merge results, tags, and/or branches to
remote repositories after the job completes.
Requires the Jenkins :jenkins-wiki:`Git Plugin <Git+Plugin>`.
:arg bool push-merge: push merges back to the origin specified in the
pre-build merge options (Default: False)
:arg bool push-only-if-success: Only push to remotes if the build succeeds
- otherwise, nothing will be pushed.
(Default: True)
:arg list tags: tags to push at the completion of the build
:tag: * **remote** (`str`) remote repo name to push to
(Default: 'origin')
* **name** (`str`) name of tag to push
* **message** (`str`) message content of the tag
* **create-tag** (`bool`) whether or not to create the tag
after the build, if this is False then the tag needs to
exist locally (Default: False)
* **update-tag** (`bool`) whether to overwrite a remote tag
or not (Default: False)
:arg list branches: branches to push at the completion of the build
:branch: * **remote** (`str`) remote repo name to push to
(Default: 'origin')
* **name** (`str`) name of remote branch to push to
:arg list notes: notes to push at the completion of the build
:note: * **remote** (`str`) remote repo name to push to
(Default: 'origin')
* **message** (`str`) content of the note
* **namespace** (`str`) namespace of the note
(Default: master)
* **replace-note** (`bool`) whether to overwrite a note or not
(Default: False)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/git001.yaml
:language: yaml
"""
mappings = [('push-merge', 'pushMerge', False),
('push-only-if-success', 'pushOnlyIfSuccess', True)]
tag_mappings = [('remote', 'targetRepoName', 'origin'),
('name', 'tagName', None),
('message', 'tagMessage', ''),
('create-tag', 'createTag', False),
('update-tag', 'updateTag', False)]
branch_mappings = [('remote', 'targetRepoName', 'origin'),
('name', 'branchName', None)]
note_mappings = [('remote', 'targetRepoName', 'origin'),
('message', 'noteMsg', None),
('namespace', 'noteNamespace', 'master'),
('replace-note', 'noteReplace', False)]
def handle_entity_children(entity, entity_xml, child_mapping):
for prop in child_mapping:
opt, xmlopt, default_val = prop[:3]
val = entity.get(opt, default_val)
if val is None:
raise JenkinsJobsException('Required option missing: %s' % opt)
if type(val) == bool:
val = str(val).lower()
XML.SubElement(entity_xml, xmlopt).text = val
top = XML.SubElement(xml_parent, 'hudson.plugins.git.GitPublisher')
XML.SubElement(top, 'configVersion').text = '2'
handle_entity_children(data, top, mappings)
tags = data.get('tags', [])
if tags:
xml_tags = XML.SubElement(top, 'tagsToPush')
for tag in tags:
xml_tag = XML.SubElement(
xml_tags,
'hudson.plugins.git.GitPublisher_-TagToPush')
handle_entity_children(tag['tag'], xml_tag, tag_mappings)
branches = data.get('branches', [])
if branches:
xml_branches = XML.SubElement(top, 'branchesToPush')
for branch in branches:
xml_branch = XML.SubElement(
xml_branches,
'hudson.plugins.git.GitPublisher_-BranchToPush')
handle_entity_children(branch['branch'], xml_branch,
branch_mappings)
notes = data.get('notes', [])
if notes:
xml_notes = XML.SubElement(top, 'notesToPush')
for note in notes:
xml_note = XML.SubElement(
xml_notes,
'hudson.plugins.git.GitPublisher_-NoteToPush')
handle_entity_children(note['note'], xml_note, note_mappings)
def github_notifier(parser, xml_parent, data):
"""yaml: github-notifier
Set build status on Github commit.
Requires the Jenkins :jenkins-wiki:`Github Plugin <GitHub+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/github-notifier.yaml
:language: yaml
"""
XML.SubElement(xml_parent,
'com.cloudbees.jenkins.GitHubCommitNotifier')
def build_publisher(parser, xml_parent, data):
"""yaml: build-publisher
This plugin allows records from one Jenkins to be published
on another Jenkins.
Requires the Jenkins :jenkins-wiki:`Build Publisher Plugin
<Build+Publisher+Plugin>`.
:arg bool publish-unstable-builds: publish unstable builds (default: true)
:arg bool publish-failed-builds: publish failed builds (default: true)
:arg int days-to-keep: days to keep when publishing results (optional)
:arg int num-to-keep: number of jobs to keep in the published results
(optional)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/build-publisher002.yaml
:language: yaml
"""
reporter = XML.SubElement(
xml_parent,
'hudson.plugins.build__publisher.BuildPublisher')
XML.SubElement(reporter, 'publishUnstableBuilds').text = \
str(data.get('publish-unstable-builds', True)).lower()
XML.SubElement(reporter, 'publishFailedBuilds').text = \
str(data.get('publish-failed-builds', True)).lower()
if 'days-to-keep' in data or 'num-to-keep' in data:
logrotator = XML.SubElement(reporter, 'logRotator')
XML.SubElement(logrotator, 'daysToKeep').text = \
str(data.get('days-to-keep', -1))
XML.SubElement(logrotator, 'numToKeep').text = \
str(data.get('num-to-keep', -1))
# hardcoded to -1 to emulate what the build publisher
# plugin seem to do.
XML.SubElement(logrotator, 'artifactDaysToKeep').text = "-1"
XML.SubElement(logrotator, 'artifactNumToKeep').text = "-1"
def stash(parser, xml_parent, data):
"""yaml: stash
This plugin will configure the Jenkins Stash Notifier plugin to
notify Atlassian Stash after job completes.
Requires the Jenkins :jenkins-wiki:`StashNotifier Plugin
<StashNotifier+Plugin>`.
:arg string url: Base url of Stash Server (Default: "")
:arg string username: Username of Stash Server (Default: "")
:arg string password: Password of Stash Server (Default: "")
:arg bool ignore-ssl: Ignore unverified SSL certificate (Default: False)
:arg string commit-sha1: Commit SHA1 to notify (Default: "")
:arg bool include-build-number: Include build number in key
(Default: False)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/stash001.yaml
:language: yaml
"""
top = XML.SubElement(xml_parent,
'org.jenkinsci.plugins.stashNotifier.StashNotifier')
XML.SubElement(top, 'stashServerBaseUrl').text = data.get('url', '')
XML.SubElement(top, 'stashUserName').text = data.get('username', '')
XML.SubElement(top, 'stashUserPassword').text = data.get('password', '')
XML.SubElement(top, 'ignoreUnverifiedSSLPeer').text = str(
data.get('ignore-ssl', False)).lower()
XML.SubElement(top, 'commitSha1').text = data.get('commit-sha1', '')
XML.SubElement(top, 'includeBuildNumberInKey').text = str(
data.get('include-build-number', False)).lower()
def description_setter(parser, xml_parent, data):
"""yaml: description-setter
This plugin sets the description for each build,
based upon a RegEx test of the build log file.
Requires the Jenkins :jenkins-wiki:`Description Setter Plugin
<Description+Setter+Plugin>`.
:arg str regexp: A RegEx which is used to scan the build log file
:arg str regexp-for-failed: A RegEx which is used for failed builds
(optional)
:arg str description: The description to set on the build (optional)
:arg str description-for-failed: The description to set on
the failed builds (optional)
:arg bool set-for-matrix: Also set the description on
a multi-configuration build (Default False)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/description-setter001.yaml
:language: yaml
"""
descriptionsetter = XML.SubElement(
xml_parent,
'hudson.plugins.descriptionsetter.DescriptionSetterPublisher')
XML.SubElement(descriptionsetter, 'regexp').text = data.get('regexp', '')
XML.SubElement(descriptionsetter, 'regexpForFailed').text = \
data.get('regexp-for-failed', '')
if 'description' in data:
XML.SubElement(descriptionsetter, 'description').text = \
data['description']
if 'description-for-failed' in data:
XML.SubElement(descriptionsetter, 'descriptionForFailed').text = \
data['description-for-failed']
for_matrix = str(data.get('set-for-matrix', False)).lower()
XML.SubElement(descriptionsetter, 'setForMatrix').text = for_matrix
def doxygen(parser, xml_parent, data):
"""yaml: doxygen
This plugin parses the Doxygen descriptor (Doxyfile) and provides a link to
the generated Doxygen documentation.
Requires the Jenkins :jenkins-wiki:`Doxygen Plugin <Doxygen+Plugin>`.
:arg str doxyfile: The doxyfile path
:arg bool keepall: Retain doxygen generation for each successful build
(default: false)
:arg str folder: Folder where you run doxygen (default: '')
Example:
.. literalinclude:: /../../tests/publishers/fixtures/doxygen001.yaml
:language: yaml
"""
p = XML.SubElement(xml_parent, 'hudson.plugins.doxygen.DoxygenArchiver')
if not data['doxyfile']:
raise JenkinsJobsException("The path to a doxyfile must be specified.")
XML.SubElement(p, 'doxyfilePath').text = str(data.get("doxyfile"))
XML.SubElement(p, 'keepAll').text = str(data.get("keepall", False)).lower()
XML.SubElement(p, 'folderWhereYouRunDoxygen').text = \
str(data.get("folder", ""))
def sitemonitor(parser, xml_parent, data):
"""yaml: sitemonitor
This plugin checks the availability of an url.
It requires the :jenkins-wiki:`sitemonitor plugin <SiteMonitor+Plugin>`.
:arg list sites: List of URLs to check
Example:
.. literalinclude:: /../../tests/publishers/fixtures/sitemonitor001.yaml
:language: yaml
"""
mon = XML.SubElement(xml_parent,
'hudson.plugins.sitemonitor.SiteMonitorRecorder')
if data.get('sites'):
sites = XML.SubElement(mon, 'mSites')
for siteurl in data.get('sites'):
site = XML.SubElement(sites,
'hudson.plugins.sitemonitor.model.Site')
XML.SubElement(site, 'mUrl').text = siteurl['url']
def testng(parser, xml_parent, data):
"""yaml: testng
This plugin publishes TestNG test reports.
Requires the Jenkins :jenkins-wiki:`TestNG Results Plugin <testng-plugin>`.
:arg str pattern: filename pattern to locate the TestNG XML report files
:arg bool escape-test-description: escapes the description string
associated with the test method while displaying test method details
(Default True)
:arg bool escape-exception-msg: escapes the test method's exception
messages. (Default True)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/testng001.yaml
:language: yaml
"""
reporter = XML.SubElement(xml_parent, 'hudson.plugins.testng.Publisher')
if not data['pattern']:
raise JenkinsJobsException("A filename pattern must be specified.")
XML.SubElement(reporter, 'reportFilenamePattern').text = data['pattern']
XML.SubElement(reporter, 'escapeTestDescp').text = str(data.get(
'escape-test-description', True))
XML.SubElement(reporter, 'escapeExceptionMsg').text = str(data.get(
'escape-exception-msg', True))
def artifact_deployer(parser, xml_parent, data):
"""yaml: artifact-deployer
This plugin makes it possible to copy artifacts to remote locations.
Requires the Jenkins :jenkins-wiki:`ArtifactDeployer Plugin
<ArtifactDeployer+Plugin>`.
:arg list entries:
:entries:
* **files** (`str`) - files to deploy
* **basedir** (`str`) - the dir from files are deployed
* **excludes** (`str`) - the mask to exclude files
* **remote** (`str`) - a remote output directory
* **flatten** (`bool`) - ignore the source directory structure
(Default: False)
* **delete-remote** (`bool`) - clean-up remote directory
before deployment (Default: False)
* **delete-remote-artifacts** (`bool`) - delete remote artifacts
when the build is deleted (Default: False)
* **fail-no-files** (`bool`) - fail build if there are no files
(Default: False)
* **groovy-script** (`str`) - execute a Groovy script
before a build is deleted
:arg bool deploy-if-fail: Deploy if the build is failed (Default: False)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/artifact-dep.yaml
:language: yaml
"""
deployer = XML.SubElement(xml_parent,
'org.jenkinsci.plugins.artifactdeployer.'
'ArtifactDeployerPublisher')
if data is None or 'entries' not in data:
raise Exception('entries field is missing')
elif data.get('entries', None) is None:
entries = XML.SubElement(deployer, 'entries', {'class': 'empty-list'})
else:
entries = XML.SubElement(deployer, 'entries')
for entry in data.get('entries'):
deployer_entry = XML.SubElement(
entries,
'org.jenkinsci.plugins.artifactdeployer.ArtifactDeployerEntry')
XML.SubElement(deployer_entry, 'includes').text = \
entry.get('files')
XML.SubElement(deployer_entry, 'basedir').text = \
entry.get('basedir')
XML.SubElement(deployer_entry, 'excludes').text = \
entry.get('excludes')
XML.SubElement(deployer_entry, 'remote').text = entry.get('remote')
XML.SubElement(deployer_entry, 'flatten').text = \
str(entry.get('flatten', False)).lower()
XML.SubElement(deployer_entry, 'deleteRemote').text = \
str(entry.get('delete-remote', False)).lower()
XML.SubElement(deployer_entry, 'deleteRemoteArtifacts').text = \
str(entry.get('delete-remote-artifacts', False)).lower()
XML.SubElement(deployer_entry, 'failNoFilesDeploy').text = \
str(entry.get('fail-no-files', False)).lower()
XML.SubElement(deployer_entry, 'groovyExpression').text = \
entry.get('groovy-script')
deploy_if_fail = str(data.get('deploy-if-fail', False)).lower()
XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail
def s3(parser, xml_parent, data):
"""yaml: s3
Upload build artifacts to Amazon S3.
Requires the Jenkins :jenkins-wiki:`S3 plugin <S3+Plugin>`.
:arg str s3-profile: Globally-defined S3 profile to use
:arg list entries:
:entries:
* **destination-bucket** (`str`) - Destination S3 bucket
* **source-files** (`str`) - Source files (Ant glob syntax)
* **storage-class** (`str`) - S3 storage class; one of "STANDARD"
or "REDUCED_REDUNDANCY"
* **bucket-region** (`str`) - S3 bucket region (capitalized with
underscores)
* **upload-on-failure** (`bool`) - Upload files even if the build
failed (Default: False)
* **upload-from-slave** (`bool`) - Perform the upload directly from
the Jenkins slave rather than the master node. (Default: False)
* **managed-artifacts** (`bool`) - Let Jenkins fully manage the
published artifacts, similar to when artifacts are published to
the Jenkins master. (Default: False)
:arg list metadata-tags:
:metadata-tags:
* **key** Metadata key for files from this build. It will be
prefixed by "x-amz-meta-" when uploaded to S3. Can contain macros
(e.g. environment variables).
* **value** Metadata value associated with the key. Can contain macros.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/s3001.yaml
:language: yaml
"""
deployer = XML.SubElement(xml_parent,
'hudson.plugins.s3.S3BucketPublisher')
if data is None or not data.get('entries'):
raise JenkinsJobsException('No filesets defined.')
XML.SubElement(deployer, 'profileName').text = data.get('s3-profile')
entries = XML.SubElement(deployer, 'entries')
for entry in data.get('entries'):
fileset = XML.SubElement(entries, 'hudson.plugins.s3.Entry')
# xml keys -> yaml keys
settings = [('bucket', 'destination-bucket', ''),
('sourceFile', 'source-files', ''),
('storageClass', 'storage-class', ''),
('selectedRegion', 'bucket-region', ''),
('noUploadOnFailure', 'upload-on-failure', False),
('uploadFromSlave', 'upload-from-slave', False),
('managedArtifacts', 'managed-artifacts', False)]
for xml_key, yaml_key, default in settings:
xml_config = XML.SubElement(fileset, xml_key)
config_value = entry.get(yaml_key, default)
if xml_key == 'noUploadOnFailure':
xml_config.text = str(not config_value).lower()
elif isinstance(default, bool):
xml_config.text = str(config_value).lower()
else:
xml_config.text = str(config_value)
metadata = XML.SubElement(deployer, 'userMetadata')
for tag in data.get('metadata-tags', []):
pair = XML.SubElement(metadata, 'hudson.plugins.s3.MetadataPair')
XML.SubElement(pair, 'key').text = tag.get('key')
XML.SubElement(pair, 'value').text = tag.get('value')
def ruby_metrics(parser, xml_parent, data):
"""yaml: ruby-metrics
Rcov plugin parses rcov html report files and
shows it in Jenkins with a trend graph.
Requires the Jenkins :jenkins-wiki:`Ruby metrics plugin
<RubyMetrics+plugin>`.
:arg str report-dir: Relative path to the coverage report directory
:arg dict targets:
:targets: (total-coverage, code-coverage)
* **healthy** (`int`): Healthy threshold
* **unhealthy** (`int`): Unhealthy threshold
* **unstable** (`int`): Unstable threshold
Example:
.. literalinclude:: /../../tests/publishers/fixtures/ruby-metrics.yaml
:language: yaml
"""
metrics = XML.SubElement(
xml_parent,
'hudson.plugins.rubyMetrics.rcov.RcovPublisher')
report_dir = data.get('report-dir', '')
XML.SubElement(metrics, 'reportDir').text = report_dir
targets = XML.SubElement(metrics, 'targets')
if 'target' in data:
for t in data['target']:
if not ('code-coverage' in t or 'total-coverage' in t):
raise JenkinsJobsException('Unrecognized target name')
el = XML.SubElement(
targets,
'hudson.plugins.rubyMetrics.rcov.model.MetricTarget')
if 'total-coverage' in t:
XML.SubElement(el, 'metric').text = 'TOTAL_COVERAGE'
else:
XML.SubElement(el, 'metric').text = 'CODE_COVERAGE'
for threshold_name, threshold_value in \
next(iter(t.values())).items():
elname = threshold_name.lower()
XML.SubElement(el, elname).text = str(threshold_value)
else:
raise JenkinsJobsException('Coverage metric targets must be set')
def fitnesse(parser, xml_parent, data):
"""yaml: fitnesse
Publish Fitnesse test results
Requires the Jenkins :jenkins-wiki:`Fitnesse plugin <Fitnesse+Plugin>`.
:arg str results: path specifier for results files
Example:
.. literalinclude:: /../../tests/publishers/fixtures/fitnesse001.yaml
:language: yaml
"""
fitnesse = XML.SubElement(
xml_parent,
'hudson.plugins.fitnesse.FitnesseResultsRecorder')
results = data.get('results', '')
XML.SubElement(fitnesse, 'fitnessePathToXmlResultsIn').text = results
def valgrind(parser, xml_parent, data):
"""yaml: valgrind
This plugin publishes Valgrind Memcheck XML results.
Requires the Jenkins :jenkins-wiki:`Valgrind Plugin <Valgrind+Plugin>`.
:arg str pattern: Filename pattern to locate the Valgrind XML report files
(required)
:arg dict thresholds: Mark build as failed or unstable if the number of
errors exceeds a threshold. All threshold values are optional.
:thresholds:
* **unstable** (`dict`)
:unstable: * **invalid-read-write** (`int`)
* **definitely-lost** (`int`)
* **total** (`int`)
* **failed** (`dict`)
:failed: * **invalid-read-write** (`int`)
* **definitely-lost** (`int`)
* **total** (`int`)
:arg bool fail-no-reports: Fail build if no reports are found
(default false)
:arg bool fail-invalid-reports: Fail build if reports are malformed
(default false)
:arg bool publish-if-aborted: Publish results for aborted builds
(default false)
:arg bool publish-if-failed: Publish results for failed builds
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/valgrind001.yaml
:language: yaml
"""
p = XML.SubElement(xml_parent,
'org.jenkinsci.plugins.valgrind.ValgrindPublisher')
p = XML.SubElement(p, 'valgrindPublisherConfig')
if 'pattern' not in data:
raise JenkinsJobsException("A filename pattern must be specified.")
XML.SubElement(p, 'pattern').text = data['pattern']
dthresholds = data.get('thresholds', {})
for threshold in ['unstable', 'failed']:
dthreshold = dthresholds.get(threshold, {})
threshold = threshold.replace('failed', 'fail')
XML.SubElement(p, '%sThresholdInvalidReadWrite' % threshold).text \
= str(dthreshold.get('invalid-read-write', ''))
XML.SubElement(p, '%sThresholdDefinitelyLost' % threshold).text \
= str(dthreshold.get('definitely-lost', ''))
XML.SubElement(p, '%sThresholdTotal' % threshold).text \
= str(dthreshold.get('total', ''))
XML.SubElement(p, 'failBuildOnMissingReports').text = str(
data.get('fail-no-reports', False)).lower()
XML.SubElement(p, 'failBuildOnInvalidReports').text = str(
data.get('fail-invalid-reports', False)).lower()
XML.SubElement(p, 'publishResultsForAbortedBuilds').text = str(
data.get('publish-if-aborted', False)).lower()
XML.SubElement(p, 'publishResultsForFailedBuilds').text = str(
data.get('publish-if-failed', False)).lower()
def pmd(parser, xml_parent, data):
"""yaml: pmd
Publish trend reports with PMD.
Requires the Jenkins :jenkins-wiki:`PMD Plugin <PMD+Plugin>`.
The PMD component accepts a dictionary with the following values:
:arg str pattern: Report filename pattern (optional)
:arg bool can-run-on-failed: Also runs for failed builds, instead of just
stable or unstable builds (default false)
:arg bool should-detect-modules: Determines if Ant or Maven modules should
be detected for all files that contain warnings (default false)
:arg int healthy: Sunny threshold (optional)
:arg int unhealthy: Stormy threshold (optional)
:arg str health-threshold: Threshold priority for health status
('low', 'normal' or 'high', defaulted to 'low')
:arg dict thresholds: Mark build as failed or unstable if the number of
errors exceeds a threshold. (optional)
:thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
:arg str default-encoding: Encoding for parsing or showing files (optional)
:arg bool do-not-resolve-relative-paths: (default false)
:arg bool dont-compute-new: If set to false, computes new warnings based on
the reference build (default true)
:arg bool use-stable-build-as-reference: The number of new warnings will be
calculated based on the last stable build, allowing reverts of unstable
builds where the number of warnings was decreased. (default false)
:arg bool use-delta-values: If set then the number of new warnings is
calculated by subtracting the total number of warnings of the current
build from the reference build.
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/pmd001.yaml
:language: yaml
Full example:
.. literalinclude:: /../../tests/publishers/fixtures/pmd002.yaml
:language: yaml
"""
xml_element = XML.SubElement(xml_parent, 'hudson.plugins.pmd.PmdPublisher')
build_trends_publisher('[PMD] ', xml_element, data)
def scan_build(parser, xml_parent, data):
"""yaml: scan-build
Publishes results from the Clang scan-build static analyzer.
The scan-build report has to be generated in the directory
``${WORKSPACE}/clangScanBuildReports`` for the publisher to find it.
Requires the Jenkins :jenkins-wiki:`Clang Scan-Build Plugin
<Clang+Scan-Build+Plugin>`.
:arg bool mark-unstable: Mark build as unstable if the number of bugs
exceeds a threshold (default: false)
:arg int threshold: Threshold for marking builds as unstable (default: 0)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/scan-build001.yaml
:language: yaml
"""
threshold = str(data.get('threshold', 0))
if not threshold.isdigit():
raise JenkinsJobsException("Invalid value '%s' for threshold. "
"Numeric value expected." % threshold)
p = XML.SubElement(
xml_parent,
'jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher')
XML.SubElement(p, 'markBuildUnstableWhenThresholdIsExceeded').text = \
str(data.get('mark-unstable', False)).lower()
XML.SubElement(p, 'bugThreshold').text = threshold
def dry(parser, xml_parent, data):
"""yaml: dry
Publish trend reports with DRY.
Requires the Jenkins :jenkins-wiki:`DRY Plugin <DRY+Plugin>`.
The DRY component accepts a dictionary with the following values:
:arg str pattern: Report filename pattern (optional)
:arg bool can-run-on-failed: Also runs for failed builds, instead of just
stable or unstable builds (default false)
:arg bool should-detect-modules: Determines if Ant or Maven modules should
be detected for all files that contain warnings (default false)
:arg int healthy: Sunny threshold (optional)
:arg int unhealthy: Stormy threshold (optional)
:arg str health-threshold: Threshold priority for health status
('low', 'normal' or 'high', defaulted to 'low')
:arg int high-threshold: Minimum number of duplicated lines for high
priority warnings. (default 50)
:arg int normal-threshold: Minimum number of duplicated lines for normal
priority warnings. (default 25)
:arg dict thresholds: Mark build as failed or unstable if the number of
errors exceeds a threshold. (optional)
:thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
:arg str default-encoding: Encoding for parsing or showing files (optional)
:arg bool do-not-resolve-relative-paths: (default false)
:arg bool dont-compute-new: If set to false, computes new warnings based on
the reference build (default true)
:arg bool use-stable-build-as-reference: The number of new warnings will be
calculated based on the last stable build, allowing reverts of unstable
builds where the number of warnings was decreased. (default false)
:arg bool use-delta-values: If set then the number of new warnings is
calculated by subtracting the total number of warnings of the current
build from the reference build.
(default false)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/dry001.yaml
:language: yaml
Full example:
.. literalinclude:: /../../tests/publishers/fixtures/dry004.yaml
:language: yaml
"""
xml_element = XML.SubElement(xml_parent, 'hudson.plugins.dry.DryPublisher')
build_trends_publisher('[DRY] ', xml_element, data)
# Add specific settings for this trends publisher
settings = [
('high-threshold', 'highThreshold', 50),
('normal-threshold', 'normalThreshold', 25)]
for key, tag_name, default in settings:
xml_config = XML.SubElement(xml_element, tag_name)
config_value = data.get(key, default)
xml_config.text = str(config_value)
def shining_panda(parser, xml_parent, data):
"""yaml: shining-panda
Publish coverage.py results. Requires the Jenkins
:jenkins-wiki:`ShiningPanda Plugin <ShiningPanda+Plugin>`.
:arg str html-reports-directory: path to coverage.py html results
(optional)
Example:
.. literalinclude:: /../../tests/publishers/fixtures/shiningpanda001.yaml
:language: yaml
"""
shining_panda_plugin = XML.SubElement(
xml_parent,
'jenkins.plugins.shiningpanda.publishers.CoveragePublisher')
if 'html-reports-directory' in data:
XML.SubElement(shining_panda_plugin, 'htmlDir').text = str(
data['html-reports-directory'])
def downstream_ext(parser, xml_parent, data):
"""yaml: downstream-ext
Trigger multiple downstream jobs when a job is completed and
condition is met.
Requires the Jenkins :jenkins-wiki:`Downstream-Ext Plugin
<Downstream-Ext+Plugin>`.
:arg list projects: Projects to build (required)
:arg string comparison: comparison used for the criteria.
One of 'equal-or-over', 'equal-or-under', 'equal'
(default: 'equal-or-over')
:arg string criteria: Trigger downstream job if build results meets
condition. One of 'success', 'unstable', 'failure' or
'aborted' (default: 'success')
:arg bool only-on-scm-change: Trigger only if downstream project
has SCM changes (default: false)
:arg bool only-on-local-scm-change: Trigger only if current project
has SCM changes (default: false)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/downstream-ext002.yaml
:language: yaml
"""
conditions = {
"equal-or-over": "AND_HIGHER",
"equal-or-under": "AND_LOWER",
"equal": "EQUAL"
}
p = XML.SubElement(xml_parent,
'hudson.plugins.downstream__ext.DownstreamTrigger')
if 'projects' not in data:
raise JenkinsJobsException("Missing list of downstream projects.")
XML.SubElement(p, 'childProjects').text = ','.join(data['projects'])
th = XML.SubElement(p, 'threshold')
criteria = data.get('criteria', 'success').upper()
if criteria not in hudson_model.THRESHOLDS:
raise JenkinsJobsException("criteria must be one of %s" %
", ".join(hudson_model.THRESHOLDS.keys()))
wr_threshold = hudson_model.THRESHOLDS[
criteria]
XML.SubElement(th, "name").text = wr_threshold['name']
XML.SubElement(th, "ordinal").text = wr_threshold['ordinal']
XML.SubElement(th, "color").text = wr_threshold['color']
XML.SubElement(th, "completeBuild").text = str(
wr_threshold['complete']).lower()
condition = data.get('condition', 'equal-or-over')
if condition not in conditions:
raise JenkinsJobsException('condition must be one of: %s' %
", ".join(conditions))
XML.SubElement(p, 'thresholdStrategy').text = conditions[
condition]
XML.SubElement(p, 'onlyIfSCMChanges').text = str(
data.get('only-on-scm-change', False)).lower()
XML.SubElement(p, 'onlyIfLocalSCMChanges').text = str(
data.get('only-on-local-scm-change', False)).lower()
def create_publishers(parser, action):
dummy_parent = XML.Element("dummy")
parser.registry.dispatch('publisher', parser, dummy_parent, action)
return list(dummy_parent)
def conditional_publisher(parser, xml_parent, data):
"""yaml: conditional-publisher
Conditionally execute some post-build steps. Requires the Jenkins
:jenkins-wiki:`Flexible Publish Plugin <Flexible+Publish+Plugin>`.
A Flexible Publish list of Conditional Actions is created in Jenkins.
:arg str condition-kind: Condition kind that must be verified before the
action is executed. Valid values and their additional attributes are
described in the conditions_ table.
:arg str on-evaluation-failure: What should be the outcome of the build
if the evaluation of the condition fails. Possible values are `fail`,
`mark-unstable`, `run-and-mark-unstable`, `run` and `dont-run`.
Default is `fail`.
:arg list action: Action to run if the condition is verified. Item
can be any publisher known by Jenkins Job Builder and supported
by the Flexible Publish Plugin.
.. _conditions:
================== ====================================================
Condition kind Description
================== ====================================================
always Condition is always verified
never Condition is never verified
boolean-expression Run the action if the expression expands to a
representation of true
:condition-expression: Expression to expand
current-status Run the action if the current build status is
within the configured range
:condition-worst: Accepted values are SUCCESS,
UNSTABLE, FAILURE, NOT_BUILD, ABORTED
:condition-best: Accepted values are SUCCESS,
UNSTABLE, FAILURE, NOT_BUILD, ABORTED
shell Run the action if the shell command succeeds
:condition-command: Shell command to execute
windows-shell Similar to shell, except that commands will be
executed by cmd, under Windows
:condition-command: Command to execute
file-exists Run the action if a file exists
:condition-filename: Check existence of this file
:condition-basedir: If condition-filename is
relative, it will be considered relative to
either `workspace`, `artifact-directory`,
or `jenkins-home`. Default is `workspace`.
================== ====================================================
Single Conditional Action Example:
.. literalinclude:: \
/../../tests/publishers/fixtures/conditional-publisher001.yaml
:language: yaml
Multiple Conditional Actions Example
(includes example of multiple actions per condition which requires
v0.13 or higher of the Flexible Publish plugin):
.. literalinclude:: \
/../../tests/publishers/fixtures/conditional-publisher003.yaml
:language: yaml
:download:`Multiple Conditional Actions Example for pre-v0.13 versions
<../../tests/publishers/fixtures/conditional-publisher002.yaml>`
"""
def publish_condition(cdata):
kind = cdata['condition-kind']
ctag = XML.SubElement(cond_publisher, condition_tag)
class_pkg = 'org.jenkins_ci.plugins.run_condition'
if kind == "always":
ctag.set('class',
class_pkg + '.core.AlwaysRun')
elif kind == "never":
ctag.set('class',
class_pkg + '.core.NeverRun')
elif kind == "boolean-expression":
ctag.set('class',
class_pkg + '.core.BooleanCondition')
XML.SubElement(ctag, "token").text = cdata['condition-expression']
elif kind == "current-status":
ctag.set('class',
class_pkg + '.core.StatusCondition')
wr = XML.SubElement(ctag, 'worstResult')
wr_name = cdata['condition-worst']
if wr_name not in hudson_model.THRESHOLDS:
raise JenkinsJobsException(
"threshold must be one of %s" %
", ".join(hudson_model.THRESHOLDS.keys()))
wr_threshold = hudson_model.THRESHOLDS[wr_name]
XML.SubElement(wr, "name").text = wr_threshold['name']
XML.SubElement(wr, "ordinal").text = wr_threshold['ordinal']
XML.SubElement(wr, "color").text = wr_threshold['color']
XML.SubElement(wr, "completeBuild").text = \
str(wr_threshold['complete']).lower()
br = XML.SubElement(ctag, 'bestResult')
br_name = cdata['condition-best']
if br_name not in hudson_model.THRESHOLDS:
raise JenkinsJobsException(
"threshold must be one of %s" %
", ".join(hudson_model.THRESHOLDS.keys()))
br_threshold = hudson_model.THRESHOLDS[br_name]
XML.SubElement(br, "name").text = br_threshold['name']
XML.SubElement(br, "ordinal").text = br_threshold['ordinal']
XML.SubElement(br, "color").text = br_threshold['color']
XML.SubElement(br, "completeBuild").text = \
str(wr_threshold['complete']).lower()
elif kind == "shell":
ctag.set('class',
class_pkg + '.contributed.ShellCondition')
XML.SubElement(ctag, "command").text = cdata['condition-command']
elif kind == "windows-shell":
ctag.set('class',
class_pkg + '.contributed.BatchFileCondition')
XML.SubElement(ctag, "command").text = cdata['condition-command']
elif kind == "file-exists":
ctag.set('class',
class_pkg + '.core.FileExistsCondition')
XML.SubElement(ctag, "file").text = cdata['condition-filename']
basedir = cdata.get('condition-basedir', 'workspace')
basedir_tag = XML.SubElement(ctag, "baseDir")
if "workspace" == basedir:
basedir_tag.set('class',
class_pkg + '.common.BaseDirectory$Workspace')
elif "artifact-directory" == basedir:
basedir_tag.set('class',
class_pkg + '.common.'
'BaseDirectory$ArtifactsDir')
elif "jenkins-home" == basedir:
basedir_tag.set('class',
class_pkg + '.common.'
'BaseDirectory$JenkinsHome')
else:
raise JenkinsJobsException('%s is not a valid condition-kind '
'value.' % kind)
def publish_action(parent, action):
for edited_node in create_publishers(parser, action):
if not use_publisher_list:
edited_node.set('class', edited_node.tag)
edited_node.tag = 'publisher'
parent.append(edited_node)
flex_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
'FlexiblePublisher'
cond_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
'ConditionalPublisher'
root_tag = XML.SubElement(xml_parent, flex_publisher_tag)
publishers_tag = XML.SubElement(root_tag, "publishers")
condition_tag = "condition"
evaluation_classes_pkg = 'org.jenkins_ci.plugins.run_condition'
evaluation_classes = {
'fail': evaluation_classes_pkg + '.BuildStepRunner$Fail',
'mark-unstable': evaluation_classes_pkg +
'.BuildStepRunner$Unstable',
'run-and-mark-unstable': evaluation_classes_pkg +
'.BuildStepRunner$RunUnstable',
'run': evaluation_classes_pkg + '.BuildStepRunner$Run',
'dont-run': evaluation_classes_pkg + '.BuildStepRunner$DontRun',
}
for cond_action in data:
cond_publisher = XML.SubElement(publishers_tag, cond_publisher_tag)
publish_condition(cond_action)
evaluation_flag = cond_action.get('on-evaluation-failure', 'fail')
if evaluation_flag not in evaluation_classes.keys():
raise JenkinsJobsException('on-evaluation-failure value '
'specified is not valid. Must be one '
'of: %s' % evaluation_classes.keys())
evaluation_class = evaluation_classes[evaluation_flag]
XML.SubElement(cond_publisher, "runner").set('class',
evaluation_class)
if 'action' in cond_action:
actions = cond_action['action']
action_parent = cond_publisher
plugin_info = \
parser.registry.get_plugin_info("Flexible Publish Plugin")
version = pkg_resources.parse_version(plugin_info.get('version',
'0'))
# XML tag changed from publisher to publisherList in v0.13
# check the plugin version to determine further operations
use_publisher_list = version >= pkg_resources.parse_version("0.13")
if use_publisher_list:
action_parent = XML.SubElement(cond_publisher, 'publisherList')
else:
# Check the length of actions list for versions prior to 0.13.
# Flexible Publish will overwrite action if more than one is
# specified. Limit the action list to one element.
if len(actions) is not 1:
raise JenkinsJobsException("Only one action may be "
"specified for each condition.")
for action in actions:
publish_action(action_parent, action)
else:
raise JenkinsJobsException('action must be set for each condition')
def scoverage(parser, xml_parent, data):
"""yaml: scoverage
Publish scoverage results as a trend graph.
Requires the Jenkins :jenkins-wiki:`Scoverage Plugin <Scoverage+Plugin>`.
:arg str report-directory: This is a directory that specifies the locations
where the xml scoverage report is generated
:arg str report-file: This is a file name that is given to the xml
scoverage report.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/scoverage001.yaml
:language: yaml
"""
scoverage = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.scoverage.ScoveragePublisher')
XML.SubElement(scoverage, 'reportDirectory').text = str(
data.get('report-directory', ''))
XML.SubElement(scoverage, 'reportFile').text = str(
data.get('report-file', ''))
def display_upstream_changes(parser, xml_parent, data):
"""yaml: display-upstream-changes
Display SCM changes of upstream jobs. Requires the Jenkins
:jenkins-wiki:`Display Upstream Changes Plugin
<Display+Upstream+Changes+Plugin>`.
Example:
.. literalinclude:: \
/../../tests/publishers/fixtures/display-upstream-changes.yaml
"""
XML.SubElement(
xml_parent,
'jenkins.plugins.displayupstreamchanges.'
'DisplayUpstreamChangesRecorder')
def gatling(parser, xml_parent, data):
"""yaml: gatling
Publish gatling results as a trend graph
Requires the Jenkins :jenkins-wiki:`Gatling Plugin <Gatling+Plugin>`.
Example:
.. literalinclude:: /../../tests/publishers/fixtures/gatling001.yaml
:language: yaml
"""
gatling = XML.SubElement(
xml_parent,
'io.gatling.jenkins.GatlingPublisher')
XML.SubElement(gatling, 'enabled').text = 'true'
def logstash(parser, xml_parent, data):
"""yaml: logstash
Send job's console log to Logstash for processing and analyis of
your job data. Also stores test metrics from Junit.
Requires the Jenkins :jenkins-wiki:`Logstash Plugin <Logstash+Plugin>`.
:arg num max-lines: The maximum number of log lines to send to Logstash.
( default 1000 )
:arg bool fail-build: Mark build as failed if this step fails.
( default false )
Minimal Example:
.. literalinclude:: /../../tests/publishers/fixtures/logstash-min.yaml
Full Example:
.. literalinclude:: /../../tests/publishers/fixtures/logstash-full.yaml
"""
logstash = XML.SubElement(xml_parent,
'jenkins.plugins.logstash.LogstashNotifier')
XML.SubElement(logstash, 'maxLines').text = str(
data.get('max-lines', 1000))
XML.SubElement(logstash, 'failBuild').text = str(
data.get('fail-build', False))
class Publishers(jenkins_jobs.modules.base.Base):
sequence = 70
component_type = 'publisher'
component_list_type = 'publishers'
def gen_xml(self, parser, xml_parent, data):
publishers = XML.SubElement(xml_parent, 'publishers')
for action in data.get('publishers', []):
self.registry.dispatch('publisher', parser, publishers, action)
|
apache-2.0
|
[
3,
1898,
6029,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1898,
6029,
812,
1060,
2453,
2290,
4319,
199,
3,
1898,
6171,
13,
7280,
437,
29680,
1132,
298,
2227,
285,
2,
28919,
25479,
199,
3,
1898,
6171,
13,
7280,
644,
3258,
1036,
2391,
2752,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
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,
421,
199,
624,
199,
13956,
1192,
5627,
5445,
626,
314,
32516,
3906,
1077,
5147,
2410,
199,
1589,
1900,
365,
4890,
14,
199,
199,
538,
7004,
26742,
2780,
1192,
523,
520,
24673,
26,
19704,
523,
520,
3900,
7584,
26,
29537,
63,
6920,
14,
4763,
1192,
199,
624,
421,
199,
646,
2748,
14,
9464,
14,
15325,
465,
4692,
199,
646,
29537,
63,
6920,
14,
3112,
14,
1095,
199,
504,
29537,
63,
6920,
14,
3112,
492,
394,
14577,
265,
63,
1238,
199,
504,
29537,
63,
6920,
14,
3112,
14,
7546,
492,
1900,
63,
84,
828,
795,
63,
12789,
199,
504,
29537,
63,
6920,
14,
3112,
14,
7546,
492,
2342,
13017,
63,
1751,
199,
504,
29537,
63,
6920,
14,
2550,
492,
32516,
20578,
1726,
199,
646,
2050,
199,
646,
5496,
63,
4435,
199,
646,
984,
199,
646,
3816,
199,
646,
2196,
421,
199,
318,
6359,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
6359,
272,
19521,
1912,
1900,
27990,
339,
520,
1273,
620,
27990,
26,
931,
16628,
367,
27990,
370,
6359,
272,
520,
1273,
620,
23388,
26,
931,
16628,
367,
27990,
370,
5760,
272,
520,
1273,
2155,
8839,
13,
2118,
26,
1454,
4215,
314,
27990,
687,
314,
8839,
489,
9512,
1900,
272,
520,
1273,
2155,
2040,
13,
1667,
26,
221,
986,
314,
1900,
340,
949,
27990,
787,
489,
1911,
334,
885,
3055,
9,
272,
520,
1273,
2155,
18020,
26,
18020,
1006,
3819,
12905,
27990,
334,
885,
3055,
9,
339,
5679,
26,
339,
2508,
8785,
2613,
447,
221,
1182,
9707,
2219,
15,
4763,
1192,
15,
8769,
15,
6404,
4587,
14,
5963,
2126,
520,
3671,
26,
8864,
272,
408,
272,
2512,
275,
2050,
14,
5572,
3647,
83,
26,
6404,
2,
450,
636,
354,
3368,
272,
3819,
4380,
275,
4692,
14,
10571,
8,
1652,
63,
1708,
12,
283,
10616,
795,
265,
14,
5054,
14,
1596,
10048,
8438,
4380,
358,
272,
27990,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
30129,
358,
272,
27990,
14,
505,
275,
666,
459,
30129,
418,
272,
340,
283,
26984,
7,
315,
666,
26,
267,
23388,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
26984,
358,
267,
23388,
14,
505,
275,
666,
459,
26984,
418,
272,
8839,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
7410,
5903,
358,
272,
327,
13388,
7163,
272,
8839,
63,
2118,
275,
666,
14,
362,
360,
7410,
63,
2118,
297,
756,
9,
272,
340,
283,
7410,
63,
2118,
7,
315,
666,
26,
267,
2512,
14,
4050,
360,
7410,
63,
2118,
365,
5906,
8749,
675,
8839,
13,
2118,
358,
272,
340,
283,
7410,
13,
2118,
7,
315,
666,
26,
267,
8839,
63,
2118,
275,
666,
459,
7410,
13,
2118,
418,
272,
340,
8839,
63,
2118,
26,
267,
8839,
14,
505,
275,
283,
2052,
7,
272,
587,
26,
267,
8839,
14,
505,
275,
283,
3910,
7,
339,
340,
283,
3306,
13,
1667,
7,
315,
666,
26,
267,
2701,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
3306,
4699,
13042,
358,
267,
327,
3758,
5953,
365,
370,
2449,
314,
1900,
14,
267,
2701,
14,
505,
275,
620,
8,
576,
14,
362,
360,
3306,
13,
1667,
297,
756,
4992,
2325,
342,
339,
340,
283,
15077,
7,
315,
666,
26,
267,
18020,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
15077,
358,
267,
18020,
14,
505,
275,
620,
8,
576,
14,
362,
360,
15077,
297,
756,
4992,
2325,
342,
421,
199,
318,
6826,
313,
63,
20099,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
6826,
313,
13,
20099,
272,
31949,
18932,
1923,
15266,
1380,
1900,
6918,
272,
15127,
314,
32516,
520,
25622,
13,
6797,
1705,
24613,
313,
18932,
1923,
15266,
11349,
272,
665,
24613,
313,
11,
1721,
1745,
11,
11421,
878,
11,
5061,
14943,
339,
5679,
26,
339,
2508,
8785,
2613,
447,
221,
1182,
9707,
2219,
15,
4763,
1192,
15,
8769,
15,
3345,
313,
4587,
14,
5963,
2126,
520,
3671,
26,
8864,
272,
408,
339,
4692,
14,
10571,
8,
1652,
63,
1708,
12,
673,
283,
10616,
795,
265,
14,
5265,
14,
3345,
313,
363,
20099,
363,
1404,
15266,
3530,
673,
283,
24613,
313,
1721,
1745,
5150,
15266,
27341,
358,
421,
199,
318,
1335,
29691,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
1603,
3337,
14577,
8142,
10533,
13303,
272,
6571,
282,
4340,
370,
3877,
27990,
641,
1603,
3337,
14577,
3748,
4887,
18032,
14,
272,
15127,
314,
32516,
658,
42,
3337,
14577,
11349,
14,
272,
665,
2859,
921,
6797,
14,
25622,
13,
559,
14,
1308,
15,
2918,
15,
42,
742,
43,
10789,
15,
42,
3337,
14577,
11,
5061,
18740,
339,
1603,
3337,
14577,
8142,
10533,
13303,
1471,
506,
7526,
367,
314,
32516,
1256,
14,
339,
520,
1273,
620,
4690,
26,
876,
11786,
4887,
4690,
334,
2427,
9,
272,
520,
1273,
620,
1584,
26,
1584,
370,
5802,
334,
3821,
9,
334,
2427,
9,
272,
520,
1273,
620,
19380,
26,
314,
1350,
570,
931,
334,
6188,
370,
14466,
12,
4879,
9,
272,
520,
1273,
620,
3970,
26,
314,
5724,
3970,
536,
334,
2427,
9,
272,
520,
1273,
2155,
14446,
26,
4215,
14446,
334,
885,
3055,
9,
339,
5679,
26,
339
] |
[
1898,
6029,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1898,
6029,
812,
1060,
2453,
2290,
4319,
199,
3,
1898,
6171,
13,
7280,
437,
29680,
1132,
298,
2227,
285,
2,
28919,
25479,
199,
3,
1898,
6171,
13,
7280,
644,
3258,
1036,
2391,
2752,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
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,
421,
199,
624,
199,
13956,
1192,
5627,
5445,
626,
314,
32516,
3906,
1077,
5147,
2410,
199,
1589,
1900,
365,
4890,
14,
199,
199,
538,
7004,
26742,
2780,
1192,
523,
520,
24673,
26,
19704,
523,
520,
3900,
7584,
26,
29537,
63,
6920,
14,
4763,
1192,
199,
624,
421,
199,
646,
2748,
14,
9464,
14,
15325,
465,
4692,
199,
646,
29537,
63,
6920,
14,
3112,
14,
1095,
199,
504,
29537,
63,
6920,
14,
3112,
492,
394,
14577,
265,
63,
1238,
199,
504,
29537,
63,
6920,
14,
3112,
14,
7546,
492,
1900,
63,
84,
828,
795,
63,
12789,
199,
504,
29537,
63,
6920,
14,
3112,
14,
7546,
492,
2342,
13017,
63,
1751,
199,
504,
29537,
63,
6920,
14,
2550,
492,
32516,
20578,
1726,
199,
646,
2050,
199,
646,
5496,
63,
4435,
199,
646,
984,
199,
646,
3816,
199,
646,
2196,
421,
199,
318,
6359,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
6359,
272,
19521,
1912,
1900,
27990,
339,
520,
1273,
620,
27990,
26,
931,
16628,
367,
27990,
370,
6359,
272,
520,
1273,
620,
23388,
26,
931,
16628,
367,
27990,
370,
5760,
272,
520,
1273,
2155,
8839,
13,
2118,
26,
1454,
4215,
314,
27990,
687,
314,
8839,
489,
9512,
1900,
272,
520,
1273,
2155,
2040,
13,
1667,
26,
221,
986,
314,
1900,
340,
949,
27990,
787,
489,
1911,
334,
885,
3055,
9,
272,
520,
1273,
2155,
18020,
26,
18020,
1006,
3819,
12905,
27990,
334,
885,
3055,
9,
339,
5679,
26,
339,
2508,
8785,
2613,
447,
221,
1182,
9707,
2219,
15,
4763,
1192,
15,
8769,
15,
6404,
4587,
14,
5963,
2126,
520,
3671,
26,
8864,
272,
408,
272,
2512,
275,
2050,
14,
5572,
3647,
83,
26,
6404,
2,
450,
636,
354,
3368,
272,
3819,
4380,
275,
4692,
14,
10571,
8,
1652,
63,
1708,
12,
283,
10616,
795,
265,
14,
5054,
14,
1596,
10048,
8438,
4380,
358,
272,
27990,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
30129,
358,
272,
27990,
14,
505,
275,
666,
459,
30129,
418,
272,
340,
283,
26984,
7,
315,
666,
26,
267,
23388,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
26984,
358,
267,
23388,
14,
505,
275,
666,
459,
26984,
418,
272,
8839,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
7410,
5903,
358,
272,
327,
13388,
7163,
272,
8839,
63,
2118,
275,
666,
14,
362,
360,
7410,
63,
2118,
297,
756,
9,
272,
340,
283,
7410,
63,
2118,
7,
315,
666,
26,
267,
2512,
14,
4050,
360,
7410,
63,
2118,
365,
5906,
8749,
675,
8839,
13,
2118,
358,
272,
340,
283,
7410,
13,
2118,
7,
315,
666,
26,
267,
8839,
63,
2118,
275,
666,
459,
7410,
13,
2118,
418,
272,
340,
8839,
63,
2118,
26,
267,
8839,
14,
505,
275,
283,
2052,
7,
272,
587,
26,
267,
8839,
14,
505,
275,
283,
3910,
7,
339,
340,
283,
3306,
13,
1667,
7,
315,
666,
26,
267,
2701,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
3306,
4699,
13042,
358,
267,
327,
3758,
5953,
365,
370,
2449,
314,
1900,
14,
267,
2701,
14,
505,
275,
620,
8,
576,
14,
362,
360,
3306,
13,
1667,
297,
756,
4992,
2325,
342,
339,
340,
283,
15077,
7,
315,
666,
26,
267,
18020,
275,
4692,
14,
10571,
8,
1047,
4380,
12,
283,
15077,
358,
267,
18020,
14,
505,
275,
620,
8,
576,
14,
362,
360,
15077,
297,
756,
4992,
2325,
342,
421,
199,
318,
6826,
313,
63,
20099,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
6826,
313,
13,
20099,
272,
31949,
18932,
1923,
15266,
1380,
1900,
6918,
272,
15127,
314,
32516,
520,
25622,
13,
6797,
1705,
24613,
313,
18932,
1923,
15266,
11349,
272,
665,
24613,
313,
11,
1721,
1745,
11,
11421,
878,
11,
5061,
14943,
339,
5679,
26,
339,
2508,
8785,
2613,
447,
221,
1182,
9707,
2219,
15,
4763,
1192,
15,
8769,
15,
3345,
313,
4587,
14,
5963,
2126,
520,
3671,
26,
8864,
272,
408,
339,
4692,
14,
10571,
8,
1652,
63,
1708,
12,
673,
283,
10616,
795,
265,
14,
5265,
14,
3345,
313,
363,
20099,
363,
1404,
15266,
3530,
673,
283,
24613,
313,
1721,
1745,
5150,
15266,
27341,
358,
421,
199,
318,
1335,
29691,
8,
2087,
12,
2748,
63,
1708,
12,
666,
304,
272,
408,
5963,
26,
1603,
3337,
14577,
8142,
10533,
13303,
272,
6571,
282,
4340,
370,
3877,
27990,
641,
1603,
3337,
14577,
3748,
4887,
18032,
14,
272,
15127,
314,
32516,
658,
42,
3337,
14577,
11349,
14,
272,
665,
2859,
921,
6797,
14,
25622,
13,
559,
14,
1308,
15,
2918,
15,
42,
742,
43,
10789,
15,
42,
3337,
14577,
11,
5061,
18740,
339,
1603,
3337,
14577,
8142,
10533,
13303,
1471,
506,
7526,
367,
314,
32516,
1256,
14,
339,
520,
1273,
620,
4690,
26,
876,
11786,
4887,
4690,
334,
2427,
9,
272,
520,
1273,
620,
1584,
26,
1584,
370,
5802,
334,
3821,
9,
334,
2427,
9,
272,
520,
1273,
620,
19380,
26,
314,
1350,
570,
931,
334,
6188,
370,
14466,
12,
4879,
9,
272,
520,
1273,
620,
3970,
26,
314,
5724,
3970,
536,
334,
2427,
9,
272,
520,
1273,
2155,
14446,
26,
4215,
14446,
334,
885,
3055,
9,
339,
5679,
26,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryanahall/django
|
tests/model_inheritance_regress/models.py
|
150
|
5750
|
from __future__ import unicode_literals
import datetime
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
class Meta:
ordering = ('name',)
def __str__(self):
return "%s the place" % self.name
@python_2_unicode_compatible
class Restaurant(Place):
serves_hot_dogs = models.BooleanField(default=False)
serves_pizza = models.BooleanField(default=False)
def __str__(self):
return "%s the restaurant" % self.name
@python_2_unicode_compatible
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField(default=False)
def __str__(self):
return "%s the italian restaurant" % self.name
@python_2_unicode_compatible
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
capacity = models.IntegerField()
def __str__(self):
return "%s the parking lot" % self.name
class ParkingLot2(Place):
# In lieu of any other connector, an existing OneToOneField will be
# promoted to the primary key.
parent = models.OneToOneField(Place)
class ParkingLot3(Place):
# The parent_link connector need not be the pk on the model.
primary_key = models.AutoField(primary_key=True)
parent = models.OneToOneField(Place, parent_link=True)
class ParkingLot4(models.Model):
# Test parent_link connector can be discovered in abstract classes.
parent = models.OneToOneField(Place, parent_link=True)
class Meta:
abstract = True
class ParkingLot4A(ParkingLot4, Place):
pass
class ParkingLot4B(Place, ParkingLot4):
pass
@python_2_unicode_compatible
class Supplier(models.Model):
name = models.CharField(max_length=50)
restaurant = models.ForeignKey(Restaurant)
def __str__(self):
return self.name
class Wholesaler(Supplier):
retailer = models.ForeignKey(Supplier, related_name='wholesale_supplier')
class Parent(models.Model):
created = models.DateTimeField(default=datetime.datetime.now)
class Child(Parent):
name = models.CharField(max_length=10)
class SelfRefParent(models.Model):
parent_data = models.IntegerField()
self_data = models.ForeignKey('self', null=True)
class SelfRefChild(SelfRefParent):
child_data = models.IntegerField()
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
class Meta:
ordering = ('-pub_date', 'headline')
def __str__(self):
return self.headline
class ArticleWithAuthor(Article):
author = models.CharField(max_length=100)
class M2MBase(models.Model):
articles = models.ManyToManyField(Article)
class M2MChild(M2MBase):
name = models.CharField(max_length=50)
class Evaluation(Article):
quality = models.IntegerField()
class Meta:
abstract = True
class QualityControl(Evaluation):
assignee = models.CharField(max_length=50)
@python_2_unicode_compatible
class BaseM(models.Model):
base_name = models.CharField(max_length=100)
def __str__(self):
return self.base_name
@python_2_unicode_compatible
class DerivedM(BaseM):
customPK = models.IntegerField(primary_key=True)
derived_name = models.CharField(max_length=100)
def __str__(self):
return "PK = %d, base_name = %s, derived_name = %s" % (
self.customPK, self.base_name, self.derived_name)
class AuditBase(models.Model):
planned_date = models.DateField()
class Meta:
abstract = True
verbose_name_plural = 'Audits'
class CertificationAudit(AuditBase):
class Meta(AuditBase.Meta):
abstract = True
class InternalCertificationAudit(CertificationAudit):
auditing_dept = models.CharField(max_length=20)
# Check that abstract classes don't get m2m tables autocreated.
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=100)
class Meta:
ordering = ('name',)
def __str__(self):
return self.name
@python_2_unicode_compatible
class AbstractEvent(models.Model):
name = models.CharField(max_length=100)
attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
class Meta:
abstract = True
ordering = ('name',)
def __str__(self):
return self.name
class BirthdayParty(AbstractEvent):
pass
class BachelorParty(AbstractEvent):
pass
class MessyBachelorParty(BachelorParty):
pass
# Check concrete -> abstract -> concrete inheritance
class SearchableLocation(models.Model):
keywords = models.CharField(max_length=256)
class Station(SearchableLocation):
name = models.CharField(max_length=128)
class Meta:
abstract = True
class BusStation(Station):
bus_routes = models.CommaSeparatedIntegerField(max_length=128)
inbound = models.BooleanField(default=False)
class TrainStation(Station):
zone = models.IntegerField()
class User(models.Model):
username = models.CharField(max_length=30, unique=True)
class Profile(User):
profile_id = models.AutoField(primary_key=True)
extra = models.CharField(max_length=30, blank=True)
# Check concrete + concrete -> concrete -> concrete
class Politician(models.Model):
politician_id = models.AutoField(primary_key=True)
title = models.CharField(max_length=50)
class Congressman(Person, Politician):
state = models.CharField(max_length=2)
class Senator(Congressman):
pass
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
10902,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
2287,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1257,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
354,
9538,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
4192,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
799,
14436,
8,
11613,
304,
272,
23739,
63,
8885,
63,
1117,
458,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
23739,
63,
80,
30937,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
295,
14436,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2779,
25861,
32075,
8,
32075,
304,
272,
23739,
63,
784,
679,
13175,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
652,
25861,
295,
14436,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
510,
1096,
316,
44,
357,
8,
11613,
304,
272,
327,
1626,
5027,
2142,
370,
314,
1676,
334,
1129,
883,
3304,
314,
2225,
536,
680,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
5062,
63,
498,
29,
549,
12,
1676,
63,
1073,
29,
549,
9,
272,
14893,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
623,
17443,
13918,
2,
450,
291,
14,
354,
421,
199,
533,
510,
1096,
316,
44,
357,
18,
8,
11613,
304,
272,
327,
1010,
1212,
16913,
402,
1263,
1163,
13252,
12,
376,
3411,
7309,
13216,
911,
506,
272,
327,
8023,
5731,
370,
314,
5062,
790,
14,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
9,
421,
199,
533,
510,
1096,
316,
44,
357,
19,
8,
11613,
304,
272,
327,
710,
1676,
63,
1073,
13252,
1929,
440,
506,
314,
3803,
641,
314,
1402,
14,
272,
5062,
63,
498,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
1676,
63,
1073,
29,
549,
9,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
8,
992,
14,
1685,
304,
272,
327,
1379,
1676,
63,
1073,
13252,
883,
506,
24983,
315,
9006,
3992,
14,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
1676,
63,
1073,
29,
549,
9,
339,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
33,
8,
48,
1096,
316,
44,
357,
20,
12,
10902,
304,
272,
986,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
34,
8,
11613,
12,
510,
1096,
316,
44,
357,
20,
304,
272,
986,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
29083,
5697,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
295,
14436,
275,
1709,
14,
3190,
8,
32075,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
644,
16668,
2231,
1435,
8,
30080,
304,
272,
295,
502,
3566,
275,
1709,
14,
3190,
8,
30080,
12,
4048,
63,
354,
534,
11345,
2978,
1895,
63,
17294,
358,
421,
199,
533,
16396,
8,
992,
14,
1685,
304,
272,
2737,
275,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
14,
2131,
9,
421,
199,
533,
12988,
8,
6652,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
421,
199,
533,
23820,
2891,
6652,
8,
992,
14,
1685,
304,
272,
1676,
63,
576,
275,
1709,
14,
3901,
342,
272,
291,
63,
576,
275,
1709,
14,
3190,
360,
277,
297,
2973,
29,
549,
9,
421,
199,
533,
23820,
2891,
3493,
8,
12887,
2891,
6652,
304,
272,
1982,
63,
576,
275,
1709,
14,
3901,
342,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8281,
8,
992,
14,
1685,
304,
272,
21250,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
7974,
63,
602,
275,
1709,
14,
4626,
342,
339,
1021,
6288,
26,
267,
7794,
275,
12291,
5645,
63,
602,
297,
283,
11268,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
11268,
421,
199,
533,
8281,
3007,
5949,
8,
7221,
304,
272,
4132,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
603,
18,
45,
1563,
8,
992,
14,
1685,
304,
272,
23242,
275,
1709,
14,
7624,
8,
7221,
9,
421,
199,
533,
603,
18,
45,
3493,
8,
45,
18,
45,
1563,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
533,
16494,
4086,
8,
7221,
304,
272,
11030,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
24108,
3717,
8,
29786,
304,
272,
465,
4093,
18682,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
3523,
45,
8,
992,
14,
1685,
304,
272,
1300,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1095,
63,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
27731,
45,
8,
1563,
45,
304,
272,
3537,
8884,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
7131,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
8884,
275,
450,
68,
12,
1300,
63,
354,
275,
450,
83,
12,
7131,
63,
354,
275,
450,
83,
2,
450,
334,
288,
291,
14,
4229,
8884,
12,
291,
14,
1095,
63,
354,
12,
291,
14,
19588,
63,
354,
9,
421,
199,
533,
31853
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
10902,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
2287,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1257,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
354,
9538,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
4192,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
799,
14436,
8,
11613,
304,
272,
23739,
63,
8885,
63,
1117,
458,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
23739,
63,
80,
30937,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
295,
14436,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
2779,
25861,
32075,
8,
32075,
304,
272,
23739,
63,
784,
679,
13175,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
652,
25861,
295,
14436,
2,
450,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
510,
1096,
316,
44,
357,
8,
11613,
304,
272,
327,
1626,
5027,
2142,
370,
314,
1676,
334,
1129,
883,
3304,
314,
2225,
536,
680,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
5062,
63,
498,
29,
549,
12,
1676,
63,
1073,
29,
549,
9,
272,
14893,
275,
1709,
14,
3901,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
314,
623,
17443,
13918,
2,
450,
291,
14,
354,
421,
199,
533,
510,
1096,
316,
44,
357,
18,
8,
11613,
304,
272,
327,
1010,
1212,
16913,
402,
1263,
1163,
13252,
12,
376,
3411,
7309,
13216,
911,
506,
272,
327,
8023,
5731,
370,
314,
5062,
790,
14,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
9,
421,
199,
533,
510,
1096,
316,
44,
357,
19,
8,
11613,
304,
272,
327,
710,
1676,
63,
1073,
13252,
1929,
440,
506,
314,
3803,
641,
314,
1402,
14,
272,
5062,
63,
498,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
1676,
63,
1073,
29,
549,
9,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
8,
992,
14,
1685,
304,
272,
327,
1379,
1676,
63,
1073,
13252,
883,
506,
24983,
315,
9006,
3992,
14,
272,
1676,
275,
1709,
14,
14298,
8,
11613,
12,
1676,
63,
1073,
29,
549,
9,
339,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
33,
8,
48,
1096,
316,
44,
357,
20,
12,
10902,
304,
272,
986,
421,
199,
533,
510,
1096,
316,
44,
357,
20,
34,
8,
11613,
12,
510,
1096,
316,
44,
357,
20,
304,
272,
986,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
29083,
5697,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
295,
14436,
275,
1709,
14,
3190,
8,
32075,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
644,
16668,
2231,
1435,
8,
30080,
304,
272,
295,
502,
3566,
275,
1709,
14,
3190,
8,
30080,
12,
4048,
63,
354,
534,
11345,
2978,
1895,
63,
17294,
358,
421,
199,
533,
16396,
8,
992,
14,
1685,
304,
272,
2737,
275,
1709,
14,
4626,
8,
885,
29,
2083,
14,
2083,
14,
2131,
9,
421,
199,
533,
12988,
8,
6652,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
421,
199,
533,
23820,
2891,
6652,
8,
992,
14,
1685,
304,
272,
1676,
63,
576,
275,
1709,
14,
3901,
342,
272,
291,
63,
576,
275,
1709,
14,
3190,
360,
277,
297,
2973,
29,
549,
9,
421,
199,
533,
23820,
2891,
3493,
8,
12887,
2891,
6652,
304,
272,
1982,
63,
576,
275,
1709,
14,
3901,
342,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8281,
8,
992,
14,
1685,
304,
272,
21250,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
7974,
63,
602,
275,
1709,
14,
4626,
342,
339,
1021,
6288,
26,
267,
7794,
275,
12291,
5645,
63,
602,
297,
283,
11268,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
11268,
421,
199,
533,
8281,
3007,
5949,
8,
7221,
304,
272,
4132,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
421,
199,
533,
603,
18,
45,
1563,
8,
992,
14,
1685,
304,
272,
23242,
275,
1709,
14,
7624,
8,
7221,
9,
421,
199,
533,
603,
18,
45,
3493,
8,
45,
18,
45,
1563,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
533,
16494,
4086,
8,
7221,
304,
272,
11030,
275,
1709,
14,
3901,
342,
339,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
24108,
3717,
8,
29786,
304,
272,
465,
4093,
18682,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
3523,
45,
8,
992,
14,
1685,
304,
272,
1300,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1095,
63,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
27731,
45,
8,
1563,
45,
304,
272,
3537,
8884,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
7131,
63,
354,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
8884,
275,
450,
68,
12,
1300,
63,
354,
275,
450,
83,
12,
7131,
63,
354,
275,
450,
83,
2,
450,
334,
288,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Triv90/Nova
|
nova/tests/fake_instance_actions.py
|
13
|
3211
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2013 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 nova import db
FAKE_UUID = 'b48316c5-71e8-45e4-9884-6c78055b9b13'
FAKE_REQUEST_ID1 = 'req-3293a3f1-b44c-4609-b8d2-d81b105636b8'
FAKE_REQUEST_ID2 = 'req-25517360-b757-47d3-be45-0e8d2a01b36a'
FAKE_ACTION_ID1 = 'f811a359-0c98-4daa-87a4-2948d4c21b78'
FAKE_ACTION_ID2 = '4e9594b5-4ac5-421c-ac60-2d802b11c798'
FAKE_ACTIONS = {
FAKE_UUID: {
FAKE_REQUEST_ID1: {'id': FAKE_ACTION_ID1,
'action': 'reboot',
'instance_uuid': FAKE_UUID,
'request_id': FAKE_REQUEST_ID1,
'project_id': '147',
'user_id': '789',
'start_time': '2012-12-05 00:00:00.000000',
'finish_time': '',
'message': '',
},
FAKE_REQUEST_ID2: {'id': FAKE_ACTION_ID2,
'action': 'resize',
'instance_uuid': FAKE_UUID,
'request_id': FAKE_REQUEST_ID2,
'user_id': '789',
'project_id': '842',
'start_time': '2012-12-05 01:00:00.000000',
'finish_time': '',
'message': '',
}
}
}
FAKE_EVENTS = {
FAKE_ACTION_ID1: [{'id': '1',
'event': 'schedule',
'start_time': '2012-12-05 01:00:02.000000',
'finish_time': '2012-12-05 01:02:00.000000',
'result': 'Success',
'traceback': '',
},
{'id': '2',
'event': 'compute_create',
'start_time': '2012-12-05 01:03:00.000000',
'finish_time': '2012-12-05 01:04:00.000000',
'result': 'Success',
'traceback': '',
}
],
FAKE_ACTION_ID2: [{'id': '3',
'event': 'schedule',
'start_time': '2012-12-05 03:00:00.000000',
'finish_time': '2012-12-05 03:02:00.000000',
'result': 'Error',
'traceback': ''
}
]
}
def fake_action_event_start(*args):
pass
def fake_action_event_finish(*args):
pass
def stub_out_action_events(stubs):
stubs.Set(db, 'action_event_start', fake_action_event_start)
stubs.Set(db, 'action_event_finish', fake_action_event_finish)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
3,
199,
3,
259,
1898,
6171,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
1592,
421,
199,
14623,
63,
8757,
275,
283,
66,
2006,
21376,
67,
21,
13,
3172,
69,
24,
13,
2322,
69,
20,
13,
25,
16303,
13,
22,
67,
31829,
1229,
66,
25,
66,
969,
7,
199,
14623,
63,
6780,
63,
998,
17,
275,
283,
2103,
13,
708,
3129,
65,
19,
70,
17,
13,
66,
1602,
67,
13,
2466,
1643,
13,
66,
24,
68,
18,
13,
68,
2835,
66,
709,
1367,
1344,
66,
24,
7,
199,
14623,
63,
6780,
63,
998,
18,
275,
283,
2103,
13,
2299,
1196,
11197,
13,
66,
32339,
13,
2417,
68,
19,
13,
1235,
2322,
13,
16,
69,
24,
68,
18,
65,
614,
66,
1344,
65,
7,
199,
14623,
63,
10052,
63,
998,
17,
275,
283,
70,
26623,
65,
11444,
13,
16,
67,
2905,
13,
20,
30908,
13,
1555,
65,
20,
13,
1398,
2006,
68,
20,
67,
2025,
66,
2277,
7,
199,
14623,
63,
10052,
63,
998,
18,
275,
283,
20,
69,
25,
15667,
66,
21,
13,
20,
645,
21,
13,
20,
2025,
67,
13,
645,
2259,
13,
18,
68,
11366,
66,
845,
67,
16564,
7,
199,
199,
14623,
63,
25194,
275,
469,
272,
25699,
63,
8757,
26,
469,
267,
25699,
63,
6780,
63,
998,
17,
26,
791,
344,
356,
25699,
63,
10052,
63,
998,
17,
12,
2079,
283,
1287,
356,
283,
15051,
297,
2079,
283,
842,
63,
2580,
356,
25699,
63,
8757,
12,
2079,
283,
1069,
63,
344,
356,
25699,
63,
6780,
63,
998,
17,
12,
2079,
283,
1715,
63,
344,
356,
283,
11160,
297,
2079,
283,
751,
63,
344,
356,
283,
24407,
297,
2079,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
8733,
26,
383,
26,
383,
14,
3273,
297,
2079,
283,
8192,
63,
521,
356,
3260,
2079,
283,
1188,
356,
3260,
267,
1660,
267,
25699,
63,
6780,
63,
998,
18,
26,
791,
344,
356,
25699,
63,
10052,
63,
998,
18,
12,
2079,
283,
1287,
356,
283,
8709,
297,
2079,
283,
842,
63,
2580,
356,
25699,
63,
8757,
12,
2079,
283,
1069,
63,
344,
356,
25699,
63,
6780,
63,
998,
18,
12,
2079,
283,
751,
63,
344,
356,
283,
24407,
297,
2079,
283,
1715,
63,
344,
356,
283,
18931,
297,
2079,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
383,
26,
383,
14,
3273,
297,
2079,
283,
8192,
63,
521,
356,
3260,
2079,
283,
1188,
356,
3260,
267,
789,
272,
789,
199,
93,
199,
199,
14623,
63,
8193,
51,
275,
469,
272,
25699,
63,
10052,
63,
998,
17,
26,
9016,
344,
356,
283,
17,
297,
2432,
283,
1430,
356,
283,
7211,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
383,
26,
996,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
996,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
8300,
297,
2432,
283,
6894,
356,
3260,
1993,
1660,
1993,
791,
344,
356,
283,
18,
297,
2432,
283,
1430,
356,
283,
3357,
63,
981,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
1644,
26,
383,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
966,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
8300,
297,
2432,
283,
6894,
356,
3260,
2432,
789,
272,
2156,
272,
25699,
63,
10052,
63,
998,
18,
26,
9016,
344,
356,
283,
19,
297,
2432,
283,
1430,
356,
283,
7211,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
30569,
26,
383,
26,
383,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
30569,
26,
996,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
547,
297,
2432,
283,
6894,
356,
2125,
2432,
789,
2043,
1622,
199,
93,
421,
199,
318,
4026,
63,
1287,
63,
1430,
63,
928,
2031,
589,
304,
272,
986,
421,
199,
318,
4026,
63,
1287,
63,
1430,
63,
8192,
2031,
589,
304,
272,
986,
421,
199,
318,
10098,
63,
548,
63,
1287,
63,
4368,
8,
8957,
304,
272,
22312,
14,
1084,
8,
697,
12,
283,
1287,
63,
1430,
63,
928,
297,
4026,
63,
1287,
63,
1430,
63,
928,
9,
272,
22312,
14,
1084,
8,
697,
12,
283,
1287,
63,
1430,
63,
8192,
297,
4026,
63,
1287,
63,
1430,
63,
8192,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
3,
199,
3,
259,
1898,
6171,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
1592,
421,
199,
14623,
63,
8757,
275,
283,
66,
2006,
21376,
67,
21,
13,
3172,
69,
24,
13,
2322,
69,
20,
13,
25,
16303,
13,
22,
67,
31829,
1229,
66,
25,
66,
969,
7,
199,
14623,
63,
6780,
63,
998,
17,
275,
283,
2103,
13,
708,
3129,
65,
19,
70,
17,
13,
66,
1602,
67,
13,
2466,
1643,
13,
66,
24,
68,
18,
13,
68,
2835,
66,
709,
1367,
1344,
66,
24,
7,
199,
14623,
63,
6780,
63,
998,
18,
275,
283,
2103,
13,
2299,
1196,
11197,
13,
66,
32339,
13,
2417,
68,
19,
13,
1235,
2322,
13,
16,
69,
24,
68,
18,
65,
614,
66,
1344,
65,
7,
199,
14623,
63,
10052,
63,
998,
17,
275,
283,
70,
26623,
65,
11444,
13,
16,
67,
2905,
13,
20,
30908,
13,
1555,
65,
20,
13,
1398,
2006,
68,
20,
67,
2025,
66,
2277,
7,
199,
14623,
63,
10052,
63,
998,
18,
275,
283,
20,
69,
25,
15667,
66,
21,
13,
20,
645,
21,
13,
20,
2025,
67,
13,
645,
2259,
13,
18,
68,
11366,
66,
845,
67,
16564,
7,
199,
199,
14623,
63,
25194,
275,
469,
272,
25699,
63,
8757,
26,
469,
267,
25699,
63,
6780,
63,
998,
17,
26,
791,
344,
356,
25699,
63,
10052,
63,
998,
17,
12,
2079,
283,
1287,
356,
283,
15051,
297,
2079,
283,
842,
63,
2580,
356,
25699,
63,
8757,
12,
2079,
283,
1069,
63,
344,
356,
25699,
63,
6780,
63,
998,
17,
12,
2079,
283,
1715,
63,
344,
356,
283,
11160,
297,
2079,
283,
751,
63,
344,
356,
283,
24407,
297,
2079,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
8733,
26,
383,
26,
383,
14,
3273,
297,
2079,
283,
8192,
63,
521,
356,
3260,
2079,
283,
1188,
356,
3260,
267,
1660,
267,
25699,
63,
6780,
63,
998,
18,
26,
791,
344,
356,
25699,
63,
10052,
63,
998,
18,
12,
2079,
283,
1287,
356,
283,
8709,
297,
2079,
283,
842,
63,
2580,
356,
25699,
63,
8757,
12,
2079,
283,
1069,
63,
344,
356,
25699,
63,
6780,
63,
998,
18,
12,
2079,
283,
751,
63,
344,
356,
283,
24407,
297,
2079,
283,
1715,
63,
344,
356,
283,
18931,
297,
2079,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
383,
26,
383,
14,
3273,
297,
2079,
283,
8192,
63,
521,
356,
3260,
2079,
283,
1188,
356,
3260,
267,
789,
272,
789,
199,
93,
199,
199,
14623,
63,
8193,
51,
275,
469,
272,
25699,
63,
10052,
63,
998,
17,
26,
9016,
344,
356,
283,
17,
297,
2432,
283,
1430,
356,
283,
7211,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
383,
26,
996,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
996,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
8300,
297,
2432,
283,
6894,
356,
3260,
1993,
1660,
1993,
791,
344,
356,
283,
18,
297,
2432,
283,
1430,
356,
283,
3357,
63,
981,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
1644,
26,
383,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
17163,
26,
966,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
8300,
297,
2432,
283,
6894,
356,
3260,
2432,
789,
272,
2156,
272,
25699,
63,
10052,
63,
998,
18,
26,
9016,
344,
356,
283,
19,
297,
2432,
283,
1430,
356,
283,
7211,
297,
2432,
283,
928,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
30569,
26,
383,
26,
383,
14,
3273,
297,
2432,
283,
8192,
63,
521,
356,
283,
7409,
13,
713,
13,
1717,
30569,
26,
996,
26,
383,
14,
3273,
297,
2432,
283,
1099,
356,
283,
547,
297,
2432,
283,
6894,
356,
2125,
2432,
789,
2043,
1622,
199,
93,
421,
199,
318,
4026,
63,
1287,
63,
1430,
63,
928,
2031,
589,
304,
272,
986,
421,
199,
318,
4026,
63,
1287,
63,
1430,
63,
8192,
2031,
589,
304,
272,
986,
421,
199,
318,
10098,
63,
548,
63,
1287,
63,
4368,
8,
8957,
304,
272,
22312,
14,
1084,
8,
697,
12,
283,
1287,
63,
1430,
63,
928,
297,
4026,
63,
1287,
63,
1430,
63,
928,
9,
272,
22312,
14,
1084,
8,
697,
12,
283,
1287,
63,
1430,
63,
8192,
297,
4026,
63,
1287,
63,
1430,
63,
8192,
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,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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
] |
hfp/tensorflow-xsmm
|
tensorflow/python/saved_model/builder.py
|
37
|
1183
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""SavedModel builder.
Builds a SavedModel that can be saved to storage, is language neutral, and
enables systems to produce, consume, or transform TensorFlow Models.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: disable=unused-import
from tensorflow.python.saved_model.builder_impl import _SavedModelBuilder
from tensorflow.python.saved_model.builder_impl import SavedModelBuilder
# pylint: enable=unused-import
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
21969,
1685,
6545,
14,
199,
199,
27856,
282,
29026,
1685,
626,
883,
506,
6290,
370,
4887,
12,
365,
2637,
1279,
29358,
12,
436,
199,
4296,
83,
10460,
370,
7389,
12,
9451,
12,
503,
5793,
9134,
29941,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
5649,
63,
5472,
492,
485,
21969,
1685,
6437,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
5649,
63,
5472,
492,
29026,
1685,
6437,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6900,
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,
21969,
1685,
6545,
14,
199,
199,
27856,
282,
29026,
1685,
626,
883,
506,
6290,
370,
4887,
12,
365,
2637,
1279,
29358,
12,
436,
199,
4296,
83,
10460,
370,
7389,
12,
9451,
12,
503,
5793,
9134,
29941,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
5649,
63,
5472,
492,
485,
21969,
1685,
6437,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
5649,
63,
5472,
492,
29026,
1685,
6437,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
skyostil/tracy
|
src/generator/Cheetah/Utils/Misc.py
|
1
|
2886
|
#!/usr/bin/env python
# $Id: Misc.py,v 1.1 2006-09-06 09:50:10 skyostil Exp $
"""Miscellaneous functions/objects used by Cheetah but also useful standalone.
Meta-Data
================================================================================
Author: Mike Orr <iron@mso.oz.net>
License: This software is released for unlimited distribution under the
terms of the MIT license. See the LICENSE file.
Version: $Revision: 1.1 $
Start Date: 2001/11/07
Last Revision Date: $Date: 2006-09-06 09:50:10 $
"""
__author__ = "Mike Orr <iron@mso.oz.net>"
__revision__ = "$Revision: 1.1 $"[11:-2]
import os # Used in mkdirsWithPyInitFile.
import types # Used in useOrRaise.
import sys # Used in die.
##################################################
## MISCELLANEOUS FUNCTIONS
def die(reason):
sys.stderr.write(reason + '\n')
sys.exit(1)
def useOrRaise(thing, errmsg=''):
"""Raise 'thing' if it's a subclass of Exception. Otherwise return it.
Called by: Cheetah.Servlet.cgiImport()
"""
if type(thing) == types.ClassType and issubclass(thing, Exception):
raise thing(errmsg)
return thing
def checkKeywords(dic, legalKeywords, what='argument'):
"""Verify no illegal keyword arguments were passed to a function.
in : dic, dictionary (**kw in the calling routine).
legalKeywords, list of strings, the keywords that are allowed.
what, string, suffix for error message (see function source).
out: None.
exc: TypeError if 'dic' contains a key not in 'legalKeywords'.
called by: Cheetah.Template.__init__()
"""
# XXX legalKeywords could be a set when sets get added to Python.
for k in dic.keys(): # Can be dic.iterkeys() if Python >= 2.2.
if k not in legalKeywords:
raise TypeError("'%s' is not a valid %s" % (k, what))
def removeFromList(list_, *elements):
"""Save as list_.remove(each element) but don't raise an error if
element is missing. Modifies 'list_' in place! Returns None.
"""
for elm in elements:
try:
list_.remove(elm)
except ValueError:
pass
def mkdirsWithPyInitFiles(path):
"""Same as os.makedirs (mkdir 'path' and all missing parent directories)
but also puts a Python '__init__.py' file in every directory it
creates. Does nothing (without creating an '__init__.py' file) if the
directory already exists.
"""
dir, fil = os.path.split(path)
if dir and not os.path.exists(dir):
mkdirsWithPyInitFiles(dir)
if not os.path.exists(path):
os.mkdir(path)
init = os.path.join(path, "__init__.py")
f = open(init, 'w') # Open and close to produce empty file.
f.close()
# vim: shiftwidth=4 tabstop=4 expandtab
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
2672,
1304,
26,
603,
10840,
14,
647,
12,
86,
413,
14,
17,
8315,
13,
1643,
13,
1690,
21798,
26,
1400,
26,
709,
2386,
89,
941,
382,
7910,
2672,
202,
199,
624,
30248,
3423,
15,
1462,
1202,
701,
445,
426,
1841,
72,
1325,
2597,
2997,
18042,
14,
2999,
199,
3396,
13,
1451,
202,
199,
5695,
1280,
202,
199,
5949,
26,
603,
7455,
4236,
82,
665,
26789,
32,
706,
79,
14,
26051,
14,
846,
30,
202,
199,
3761,
26,
961,
2032,
365,
14286,
367,
625,
14136,
4084,
1334,
314,
8740,
2895,
402,
314,
10697,
4190,
14,
221,
1666,
314,
5113,
570,
14,
202,
199,
3353,
26,
2672,
12714,
26,
413,
14,
17,
2672,
202,
199,
3162,
6148,
26,
12521,
15,
845,
15,
1780,
202,
199,
6090,
27095,
6148,
26,
2672,
2506,
26,
8315,
13,
1643,
13,
1690,
21798,
26,
1400,
26,
709,
2672,
202,
199,
624,
20712,
199,
363,
2502,
363,
275,
298,
45,
7455,
4236,
82,
665,
26789,
32,
706,
79,
14,
26051,
14,
846,
4335,
202,
199,
363,
5792,
363,
275,
7880,
12714,
26,
413,
14,
17,
2672,
22774,
845,
6809,
18,
61,
2999,
199,
646,
747,
3515,
327,
8051,
315,
9199,
3220,
3007,
2713,
9346,
1173,
14,
202,
199,
646,
2943,
755,
327,
8051,
315,
675,
2844,
18111,
14,
202,
199,
646,
984,
260,
327,
8051,
315,
18833,
14,
2999,
199,
22529,
309,
202,
199,
309,
603,
1311,
26474,
879,
15471,
1668,
21498,
19560,
2999,
199,
318,
18833,
8,
5764,
304,
1128,
984,
14,
3083,
14,
952,
8,
5764,
435,
1557,
78,
358,
1128,
984,
14,
2224,
8,
17,
9,
2999,
199,
318,
675,
2844,
18111,
8,
2127,
12,
22070,
9280,
1128,
408,
18111,
283,
2127,
7,
340,
652,
1159,
282,
5516,
402,
2186,
14,
221,
6630,
372,
652,
14,
2958,
12295,
701,
26,
445,
426,
1841,
72,
14,
1505,
86,
2723,
14,
13814,
6295,
342,
1128,
408,
1128,
340,
730,
8,
2127,
9,
508,
2943,
14,
31165,
436,
11602,
8,
2127,
12,
2186,
304,
1039,
746,
8377,
8,
16024,
9,
1128,
372,
8377,
8065,
199,
318,
1104,
23611,
8,
5000,
12,
18393,
23611,
12,
4052,
534,
2094,
735,
1128,
408,
7496,
949,
20282,
4252,
2368,
4898,
3032,
370,
282,
805,
14,
2958,
315,
520,
12219,
12,
2600,
334,
538,
829,
315,
314,
6358,
12981,
680,
8740,
18393,
23611,
12,
769,
402,
3326,
12,
314,
7681,
626,
787,
4370,
14,
8740,
4052,
12,
1059,
12,
4739,
367,
1125,
1245,
334,
3239,
805,
1350,
680,
1128,
734,
26,
488,
14,
1128,
3178,
26,
3146,
340,
283,
5000,
7,
3509,
282,
790,
440,
315,
283,
9666,
23611,
1370,
1128,
2797,
701,
26,
445,
426,
1841,
72,
14,
4231,
855,
826,
4533,
1128,
408,
1128,
327,
5787,
18393,
23611,
4293,
506,
282,
663,
1380,
5951,
664,
3483,
370,
2018,
14,
1128,
367,
1022,
315,
12219,
14,
1612,
837,
327,
6855,
506,
12219,
14,
16007,
342,
340,
2018,
2356,
499,
14,
18,
14,
1039,
340,
1022,
440,
315,
18393,
23611,
26,
221,
1675,
746,
3146,
21065,
83,
7,
365,
440,
282,
1686,
450,
83,
2,
450,
334,
75,
12,
4052,
430,
8065,
199,
318,
2813,
2532,
1296,
8,
513,
3131,
627,
5527,
304,
1128,
408,
8229,
465,
769,
3754,
2168,
8,
10885,
1819,
9,
1325,
2793,
1133,
746,
376,
1125,
340,
22132,
1819,
365,
4124,
14,
221,
12972,
5604,
283,
513,
8650,
315,
4192,
1,
221,
1803,
488,
14,
1128,
408,
1128,
367,
579,
77,
315,
4008,
26,
1039,
862,
26,
1675,
769,
3754,
2168,
8,
21226,
9,
1039,
871,
1722,
26,
1675,
986,
8065,
199,
318,
9199,
3220,
3007,
2713,
9346,
5535,
8,
515,
304,
1128,
408,
8479,
465,
747,
14,
8347,
334,
8215,
283,
515,
7,
436,
1006,
4124,
1676,
6602,
9,
22132,
1325,
2597,
27000,
282,
2018,
2560,
826,
4343,
647,
7,
570,
315,
4036,
2082,
652,
22132,
8491,
14,
221,
12078,
6548,
334,
7395,
6425,
376,
2560,
826,
4343,
647,
7,
570,
9,
340,
314,
22132,
2082,
2575,
3495,
14,
257,
1128,
408,
1128,
2935,
12,
1794,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
1128,
340,
2935,
436,
440,
747,
14,
515,
14,
2444,
8,
694,
304,
1039,
9199,
3220,
3007,
2713,
9346,
5535,
8,
694,
9,
1128,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
1039,
747,
14,
8215,
8,
515,
9,
1039,
4205,
275,
747,
14,
515,
14,
904,
8,
515,
12,
4396,
826,
4343,
647,
531,
1039,
289,
275,
1551,
8,
826,
12,
283,
87,
358,
327,
3232,
436,
4002,
370,
7389,
2701,
570,
14,
1039,
289,
14,
1600,
342,
1223,
8065,
199,
3,
6695,
26,
20105,
29,
20,
20849,
29,
20,
26414,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
2672,
1304,
26,
603,
10840,
14,
647,
12,
86,
413,
14,
17,
8315,
13,
1643,
13,
1690,
21798,
26,
1400,
26,
709,
2386,
89,
941,
382,
7910,
2672,
202,
199,
624,
30248,
3423,
15,
1462,
1202,
701,
445,
426,
1841,
72,
1325,
2597,
2997,
18042,
14,
2999,
199,
3396,
13,
1451,
202,
199,
5695,
1280,
202,
199,
5949,
26,
603,
7455,
4236,
82,
665,
26789,
32,
706,
79,
14,
26051,
14,
846,
30,
202,
199,
3761,
26,
961,
2032,
365,
14286,
367,
625,
14136,
4084,
1334,
314,
8740,
2895,
402,
314,
10697,
4190,
14,
221,
1666,
314,
5113,
570,
14,
202,
199,
3353,
26,
2672,
12714,
26,
413,
14,
17,
2672,
202,
199,
3162,
6148,
26,
12521,
15,
845,
15,
1780,
202,
199,
6090,
27095,
6148,
26,
2672,
2506,
26,
8315,
13,
1643,
13,
1690,
21798,
26,
1400,
26,
709,
2672,
202,
199,
624,
20712,
199,
363,
2502,
363,
275,
298,
45,
7455,
4236,
82,
665,
26789,
32,
706,
79,
14,
26051,
14,
846,
4335,
202,
199,
363,
5792,
363,
275,
7880,
12714,
26,
413,
14,
17,
2672,
22774,
845,
6809,
18,
61,
2999,
199,
646,
747,
3515,
327,
8051,
315,
9199,
3220,
3007,
2713,
9346,
1173,
14,
202,
199,
646,
2943,
755,
327,
8051,
315,
675,
2844,
18111,
14,
202,
199,
646,
984,
260,
327,
8051,
315,
18833,
14,
2999,
199,
22529,
309,
202,
199,
309,
603,
1311,
26474,
879,
15471,
1668,
21498,
19560,
2999,
199,
318,
18833,
8,
5764,
304,
1128,
984,
14,
3083,
14,
952,
8,
5764,
435,
1557,
78,
358,
1128,
984,
14,
2224,
8,
17,
9,
2999,
199,
318,
675,
2844,
18111,
8,
2127,
12,
22070,
9280,
1128,
408,
18111,
283,
2127,
7,
340,
652,
1159,
282,
5516,
402,
2186,
14,
221,
6630,
372,
652,
14,
2958,
12295,
701,
26,
445,
426,
1841,
72,
14,
1505,
86,
2723,
14,
13814,
6295,
342,
1128,
408,
1128,
340,
730,
8,
2127,
9,
508,
2943,
14,
31165,
436,
11602,
8,
2127,
12,
2186,
304,
1039,
746,
8377,
8,
16024,
9,
1128,
372,
8377,
8065,
199,
318,
1104,
23611,
8,
5000,
12,
18393,
23611,
12,
4052,
534,
2094,
735,
1128,
408,
7496,
949,
20282,
4252,
2368,
4898,
3032,
370,
282,
805,
14,
2958,
315,
520,
12219,
12,
2600,
334,
538,
829,
315,
314,
6358,
12981,
680,
8740,
18393,
23611,
12,
769,
402,
3326,
12,
314,
7681,
626,
787,
4370,
14,
8740,
4052,
12,
1059,
12,
4739,
367,
1125,
1245,
334,
3239,
805,
1350,
680,
1128,
734,
26,
488,
14,
1128,
3178,
26,
3146,
340,
283,
5000,
7,
3509,
282,
790,
440,
315,
283,
9666,
23611,
1370,
1128,
2797,
701,
26,
445,
426,
1841,
72,
14,
4231,
855,
826,
4533,
1128,
408,
1128,
327,
5787,
18393,
23611,
4293,
506,
282,
663,
1380,
5951,
664,
3483,
370,
2018,
14,
1128,
367,
1022,
315,
12219,
14,
1612,
837,
327,
6855,
506,
12219,
14,
16007,
342,
340,
2018,
2356,
499,
14,
18,
14,
1039,
340,
1022,
440,
315,
18393,
23611,
26,
221,
1675,
746,
3146,
21065,
83,
7,
365,
440,
282,
1686,
450,
83,
2,
450,
334,
75,
12,
4052,
430,
8065,
199,
318,
2813,
2532,
1296,
8,
513,
3131,
627,
5527,
304,
1128,
408,
8229,
465,
769,
3754,
2168,
8,
10885,
1819,
9,
1325,
2793,
1133,
746,
376,
1125,
340,
22132,
1819,
365,
4124,
14,
221,
12972,
5604,
283,
513,
8650,
315,
4192,
1,
221,
1803,
488,
14,
1128,
408,
1128,
367,
579,
77,
315,
4008,
26,
1039,
862,
26,
1675,
769,
3754,
2168,
8,
21226,
9,
1039,
871,
1722,
26,
1675,
986,
8065,
199,
318,
9199,
3220,
3007,
2713,
9346,
5535,
8,
515,
304,
1128,
408,
8479,
465,
747,
14,
8347,
334,
8215,
283,
515,
7,
436,
1006,
4124,
1676,
6602,
9,
22132,
1325,
2597,
27000,
282,
2018,
2560,
826,
4343,
647,
7,
570,
315,
4036,
2082,
652,
22132,
8491,
14,
221,
12078,
6548,
334,
7395,
6425,
376,
2560,
826,
4343,
647,
7,
570,
9,
340,
314,
22132,
2082,
2575,
3495,
14,
257,
1128,
408,
1128,
2935,
12,
1794,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
1128,
340,
2935,
436,
440,
747,
14,
515,
14,
2444,
8,
694,
304,
1039,
9199,
3220,
3007,
2713,
9346,
5535,
8,
694,
9,
1128,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
1039,
747,
14,
8215,
8,
515,
9,
1039,
4205,
275,
747,
14,
515,
14,
904,
8,
515,
12,
4396,
826,
4343,
647,
531,
1039,
289,
275,
1551,
8,
826,
12,
283,
87,
358,
327,
3232,
436,
4002,
370,
7389,
2701,
570,
14,
1039,
289,
14,
1600,
342,
1223,
8065,
199,
3,
6695,
26,
20105,
29,
20,
20849,
29,
20,
26414,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
byterom/android_external_chromium_org
|
tools/telemetry/telemetry/timeline/counter_unittest.py
|
53
|
1909
|
# 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 types
import unittest
from telemetry.timeline import counter as counter_module
class FakeProcess(object):
pass
class CounterIterEventsInThisContainerTest(unittest.TestCase):
def setUp(self):
parent = FakeProcess()
self.counter = counter_module.Counter(parent, 'cat', 'name')
def assertIsEmptyIterator(self, itr):
self.assertIsInstance(itr, types.GeneratorType)
self.assertRaises(StopIteration, itr.next)
def testEmptyTimestamps(self):
self.assertIsEmptyIterator(self.counter.IterEventsInThisContainer(
event_type_predicate=lambda x: True,
event_predicate=lambda x: True))
def testEventTypeMismatch(self):
self.counter.timestamps = [111, 222]
self.assertIsEmptyIterator(self.counter.IterEventsInThisContainer(
event_type_predicate=lambda x: False,
event_predicate=lambda x: True))
def testNoEventMatch(self):
self.counter.timestamps = [111, 222]
self.assertIsEmptyIterator(self.counter.IterEventsInThisContainer(
event_type_predicate=lambda x: True,
event_predicate=lambda x: False))
def testAllMatch(self):
self.counter.timestamps = [111, 222]
events = self.counter.IterEventsInThisContainer(
event_type_predicate=lambda x: True,
event_predicate=lambda x: True)
self.assertIsInstance(events, types.GeneratorType)
self.assertEqual([111, 222], [s.start for s in events])
def testPartialMatch(self):
self.counter.timestamps = [111, 222]
events = self.counter.IterEventsInThisContainer(
event_type_predicate=lambda x: True,
event_predicate=lambda x: x.start > 200)
self.assertIsInstance(events, types.GeneratorType)
self.assertEqual([222], [s.start for s in events])
|
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,
2943,
199,
646,
2882,
199,
199,
504,
17298,
14,
19369,
492,
7055,
465,
7055,
63,
578,
421,
199,
533,
7777,
3498,
8,
785,
304,
523,
986,
421,
199,
533,
14427,
3315,
11770,
607,
2765,
4076,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
1676,
275,
7777,
3498,
342,
272,
291,
14,
5337,
275,
7055,
63,
578,
14,
11348,
8,
1708,
12,
283,
3385,
297,
283,
354,
358,
819,
347,
702,
1831,
4699,
3585,
8,
277,
12,
284,
454,
304,
272,
291,
14,
6926,
8,
390,
82,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
1855,
8,
30139,
12,
284,
454,
14,
2184,
9,
819,
347,
511,
4699,
10239,
83,
8,
277,
304,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
430,
819,
347,
511,
30051,
23055,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
756,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
430,
819,
347,
511,
1944,
2390,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
756,
430,
819,
347,
511,
2422,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
4474,
275,
291,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
9,
272,
291,
14,
6926,
8,
4368,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
629,
779,
6673,
12,
26485,
467,
359,
83,
14,
928,
367,
308,
315,
4474,
566,
819,
347,
511,
18192,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
4474,
275,
291,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
671,
14,
928,
690,
1926,
9,
272,
291,
14,
6926,
8,
4368,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
629,
779,
9485,
467,
359,
83,
14,
928,
367,
308,
315,
4474,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
2943,
199,
646,
2882,
199,
199,
504,
17298,
14,
19369,
492,
7055,
465,
7055,
63,
578,
421,
199,
533,
7777,
3498,
8,
785,
304,
523,
986,
421,
199,
533,
14427,
3315,
11770,
607,
2765,
4076,
774,
8,
2796,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
1676,
275,
7777,
3498,
342,
272,
291,
14,
5337,
275,
7055,
63,
578,
14,
11348,
8,
1708,
12,
283,
3385,
297,
283,
354,
358,
819,
347,
702,
1831,
4699,
3585,
8,
277,
12,
284,
454,
304,
272,
291,
14,
6926,
8,
390,
82,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
1855,
8,
30139,
12,
284,
454,
14,
2184,
9,
819,
347,
511,
4699,
10239,
83,
8,
277,
304,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
430,
819,
347,
511,
30051,
23055,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
756,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
430,
819,
347,
511,
1944,
2390,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
291,
14,
3436,
4699,
3585,
8,
277,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
756,
430,
819,
347,
511,
2422,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
4474,
275,
291,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
715,
9,
272,
291,
14,
6926,
8,
4368,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
629,
779,
6673,
12,
26485,
467,
359,
83,
14,
928,
367,
308,
315,
4474,
566,
819,
347,
511,
18192,
4486,
8,
277,
304,
272,
291,
14,
5337,
14,
25430,
275,
359,
6673,
12,
26485,
61,
272,
4474,
275,
291,
14,
5337,
14,
3315,
11770,
607,
2765,
4076,
8,
267,
1566,
63,
466,
63,
14463,
29,
2734,
671,
26,
715,
12,
267,
1566,
63,
14463,
29,
2734,
671,
26,
671,
14,
928,
690,
1926,
9,
272,
291,
14,
6926,
8,
4368,
12,
2943,
14,
7599,
804,
9,
272,
291,
14,
629,
779,
9485,
467,
359,
83,
14,
928,
367,
308,
315,
4474,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pra85/calibre
|
src/calibre/library/server/xml.py
|
5
|
5703
|
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
__license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import __builtin__
import cherrypy
from lxml.builder import ElementMaker
from lxml import etree
from calibre.library.server import custom_fields_to_display
from calibre.library.server.utils import strftime, format_tag_string
from calibre.ebooks.metadata import fmt_sidx
from calibre.constants import preferred_encoding
from calibre import isbytestring
from calibre.utils.filenames import ascii_filename
from calibre.utils.icu import sort_key
E = ElementMaker()
class XMLServer(object):
'Serves XML and the Ajax based HTML frontend'
def add_routes(self, connect):
connect('xml', '/xml', self.xml)
def xml(self, start='0', num='50', sort=None, search=None,
_=None, order='ascending'):
'''
Serves metadata from the calibre database as XML.
:param sort: Sort results by ``sort``. Can be one of `title,author,rating`.
:param search: Filter results by ``search`` query. See :class:`SearchQueryParser` for query syntax
:param start,num: Return the slice `[start:start+num]` of the sorted and filtered results
:param _: Firefox seems to sometimes send this when using XMLHttpRequest with no caching
'''
try:
start = int(start)
except ValueError:
raise cherrypy.HTTPError(400, 'start: %s is not an integer'%start)
try:
num = int(num)
except ValueError:
raise cherrypy.HTTPError(400, 'num: %s is not an integer'%num)
order = order.lower().strip() == 'ascending'
if not search:
search = ''
if isbytestring(search):
search = search.decode('UTF-8')
ids = self.db.search_getting_ids(search.strip(), self.search_restriction)
FM = self.db.FIELD_MAP
items = [r for r in iter(self.db) if r[FM['id']] in ids]
if sort is not None:
self.sort(items, sort, order)
books = []
def serialize(x):
if isinstance(x, unicode):
return x
if isbytestring(x):
return x.decode(preferred_encoding, 'replace')
return unicode(x)
# This method uses its own book dict, not the Metadata dict. The loop
# below could be changed to use db.get_metadata instead of reading
# info directly from the record made by the view, but it doesn't seem
# worth it at the moment.
for record in items[start:start+num]:
kwargs = {}
aus = record[FM['authors']] if record[FM['authors']] else __builtin__._('Unknown')
authors = '|'.join([i.replace('|', ',') for i in aus.split(',')])
kwargs['authors'] = authors
kwargs['series_index'] = \
fmt_sidx(float(record[FM['series_index']]))
for x in ('timestamp', 'pubdate'):
kwargs[x] = strftime('%Y/%m/%d %H:%M:%S', record[FM[x]])
for x in ('id', 'title', 'sort', 'author_sort', 'rating', 'size'):
kwargs[x] = serialize(record[FM[x]])
for x in ('formats', 'series', 'tags', 'publisher',
'comments', 'identifiers'):
y = record[FM[x]]
if x == 'tags':
y = format_tag_string(y, ',', ignore_max=True)
kwargs[x] = serialize(y) if y else ''
isbn = self.db.isbn(record[FM['id']], index_is_id=True)
kwargs['isbn'] = serialize(isbn if isbn else '')
kwargs['safe_title'] = ascii_filename(kwargs['title'])
c = kwargs.pop('comments')
CFM = self.db.field_metadata
CKEYS = [key for key in sorted(custom_fields_to_display(self.db),
key=lambda x: sort_key(CFM[x]['name']))]
custcols = []
for key in CKEYS:
def concat(name, val):
return '%s:#:%s'%(name, unicode(val))
mi = self.db.get_metadata(record[CFM['id']['rec_index']], index_is_id=True)
name, val = mi.format_field(key)
if not val:
continue
datatype = CFM[key]['datatype']
if datatype in ['comments']:
continue
k = str('CF_'+key[1:])
name = CFM[key]['name']
custcols.append(k)
if datatype == 'text' and CFM[key]['is_multiple']:
kwargs[k] = \
concat('#T#'+name,
format_tag_string(val,
CFM[key]['is_multiple']['ui_to_list'],
ignore_max=True,
joinval=CFM[key]['is_multiple']['list_to_ui']))
else:
kwargs[k] = concat(name, val)
kwargs['custcols'] = ','.join(custcols)
books.append(E.book(c, **kwargs))
updated = self.db.last_modified()
kwargs = dict(
start = str(start),
updated=updated.strftime('%Y-%m-%dT%H:%M:%S+00:00'),
total=str(len(ids)),
num=str(len(books)))
ans = E.library(*books, **kwargs)
cherrypy.response.headers['Content-Type'] = 'text/xml'
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
return etree.tostring(ans, encoding='utf-8', pretty_print=True,
xml_declaration=True)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
6695,
26,
493,
2991,
29,
6610,
13,
24,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
1207,
26,
386,
26,
10329,
29,
20,
26,
5789,
199,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
6542,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
32,
7697,
5017,
1939,
31876,
14,
846,
3524,
199,
363,
21841,
363,
275,
283,
26854,
655,
7,
199,
199,
646,
636,
5351,
363,
199,
199,
646,
13397,
199,
504,
14490,
14,
5649,
492,
6566,
23560,
199,
504,
14490,
492,
7559,
199,
199,
504,
19238,
14,
4342,
14,
1000,
492,
3537,
63,
955,
63,
475,
63,
2918,
199,
504,
19238,
14,
4342,
14,
1000,
14,
1208,
492,
14053,
12,
1475,
63,
1450,
63,
875,
199,
504,
19238,
14,
69,
8858,
14,
2343,
492,
7104,
63,
4148,
88,
199,
504,
19238,
14,
5559,
492,
14388,
63,
2991,
199,
504,
19238,
492,
365,
991,
396,
5985,
199,
504,
19238,
14,
1208,
14,
10309,
492,
13294,
63,
1501,
199,
504,
19238,
14,
1208,
14,
530,
85,
492,
4069,
63,
498,
199,
199,
37,
275,
6566,
23560,
342,
199,
199,
533,
4692,
3120,
8,
785,
304,
272,
283,
1505,
2310,
4692,
436,
314,
437,
15863,
4079,
4163,
22523,
7,
339,
347,
1050,
63,
13243,
8,
277,
12,
4907,
304,
267,
4907,
360,
1652,
297,
1994,
1652,
297,
291,
14,
1652,
9,
339,
347,
2748,
8,
277,
12,
1343,
534,
16,
297,
1967,
534,
1400,
297,
4069,
29,
403,
12,
2754,
29,
403,
12,
355,
485,
29,
403,
12,
1865,
534,
10125,
3219,
735,
267,
1449,
267,
3739,
2310,
3341,
687,
314,
19238,
3050,
465,
4692,
14,
398,
520,
635,
4069,
26,
16722,
2058,
701,
1124,
3191,
4345,
6855,
506,
1373,
402,
658,
1213,
12,
2502,
12,
10417,
2313,
267,
520,
635,
2754,
26,
9388,
2058,
701,
1124,
1733,
1040,
1827,
14,
1666,
520,
533,
1705,
5278,
3227,
2842,
64,
367,
1827,
6302,
267,
520,
635,
1343,
12,
1507,
26,
1432,
314,
6014,
14505,
928,
26,
928,
11,
1507,
16090,
402,
314,
3355,
436,
9806,
2058,
267,
520,
635,
24700,
24584,
12237,
370,
15026,
3222,
642,
1380,
1808,
4692,
10441,
543,
949,
13627,
267,
1449,
267,
862,
26,
288,
1343,
275,
1109,
8,
928,
9,
267,
871,
1722,
26,
288,
746,
13397,
14,
12815,
8,
5303,
12,
283,
928,
26,
450,
83,
365,
440,
376,
3000,
5956,
928,
9,
267,
862,
26,
288,
1967,
275,
1109,
8,
1507,
9,
267,
871,
1722,
26,
288,
746,
13397,
14,
12815,
8,
5303,
12,
283,
1507,
26,
450,
83,
365,
440,
376,
3000,
5956,
1507,
9,
398,
1865,
275,
1865,
14,
2325,
1252,
1913,
342,
508,
283,
10125,
3219,
7,
398,
340,
440,
2754,
26,
288,
2754,
275,
2125,
267,
340,
365,
991,
396,
5985,
8,
1733,
304,
288,
2754,
275,
2754,
14,
2708,
360,
6610,
13,
24,
358,
398,
2762,
275,
291,
14,
697,
14,
1733,
63,
362,
1337,
63,
1580,
8,
1733,
14,
1913,
1062,
291,
14,
1733,
63,
23423,
9,
398,
481,
45,
275,
291,
14,
697,
14,
8609,
63,
5443,
398,
2974,
275,
359,
82,
367,
519,
315,
2740,
8,
277,
14,
697,
9,
340,
519,
59,
22367,
459,
344,
6538,
315,
2762,
61,
267,
340,
4069,
365,
440,
488,
26,
288,
291,
14,
3191,
8,
1744,
12,
4069,
12,
1865,
9,
398,
19040,
275,
942,
398,
347,
8437,
8,
88,
304,
288,
340,
1228,
8,
88,
12,
2649,
304,
355,
372,
671,
288,
340,
365,
991,
396,
5985,
8,
88,
304,
355,
372,
671,
14,
2708,
8,
17477,
63,
2991,
12,
283,
1814,
358,
288,
372,
2649,
8,
88,
9,
398,
327,
961,
1083,
4440,
2399,
5705,
6719,
1211,
12,
440,
314,
16160,
1211,
14,
710,
4438,
267,
327,
5084,
4293,
506,
2896,
370,
675,
1592,
14,
362,
63,
2343,
3140,
402,
7664,
267,
327,
2256,
5370,
687,
314,
2777,
6326,
701,
314,
2455,
12,
1325,
652,
3181,
1133,
17021,
267,
327,
25235,
652,
737,
314,
12427,
14,
267,
367,
2777,
315,
2974,
59,
928,
26,
928,
11,
1507,
2189,
288,
2074,
275,
1052,
288,
282,
527,
275,
2777,
59,
22367,
459,
8149,
6538,
340,
2777,
59,
22367,
459,
8149,
6538,
587,
636,
5351,
363,
423,
360,
5912,
358,
288,
11462,
275,
21590,
904,
779,
73,
14,
1814,
20137,
297,
1656,
358,
367,
284,
315,
282,
527,
14,
1294,
5102,
2023,
288,
2074,
459,
8149,
418,
275,
11462,
953,
2074,
459,
5602,
63,
1080,
418,
275,
971,
355,
7104,
63,
4148,
88,
8,
1609,
8,
3059,
59,
22367,
459,
5602,
63,
1080,
418,
2459,
953,
367,
671,
315,
661,
3954,
297,
283,
30218,
735,
355,
2074,
59,
88,
61,
275,
14053,
3508,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
297,
2777,
59,
22367,
59,
88,
3934,
953,
367,
671,
315,
661,
344,
297,
283,
1213,
297,
283,
3191,
297,
283,
2502,
63,
3191,
297,
283,
10417,
297,
283,
890,
735,
355,
2074,
59,
88,
61,
275,
8437,
8,
3059,
59,
22367,
59,
88,
3934,
953,
367,
671,
315,
661,
6321,
297,
283,
5602,
297,
283,
2969,
297,
283,
12789,
297,
490,
283,
6223,
297,
283,
14227,
735,
355,
612,
275,
2777,
59,
22367,
59,
88,
2677,
355,
340,
671,
508,
283,
2969,
356,
490,
612,
275,
1475,
63,
1450,
63,
875,
8,
89,
12,
30048,
3686,
63,
988,
29,
549,
9,
355,
2074,
59,
88,
61,
275,
8437,
8,
89,
9,
340,
612,
587,
2125,
953,
365,
10472,
275,
291,
14,
697,
14,
374,
10472,
8,
3059,
59,
22367,
459,
344,
2157,
1478,
63,
374,
63,
344,
29,
549,
9,
288,
2074,
459,
374,
10472,
418,
275,
8437,
8,
374,
10472,
340,
365,
10472,
587,
4074,
953,
2074,
459,
3489,
63,
1213,
418,
275,
13294,
63,
1501,
8,
958,
459,
1213,
1105,
953,
286,
275,
2074,
14,
1935,
360,
6223,
358,
953,
6035,
45,
275,
291,
14,
697,
14,
698,
63,
2343,
288,
445,
17434,
275,
359,
498,
367,
790,
315,
3355,
8,
4229,
63,
955,
63,
475,
63,
2918,
8,
277,
14,
697,
395,
5644,
790,
29,
2734,
671,
26,
4069,
63,
498,
8,
5487,
45,
59,
88,
2733,
354
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
6695,
26,
493,
2991,
29,
6610,
13,
24,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
1207,
26,
386,
26,
10329,
29,
20,
26,
5789,
199,
199,
363,
1682,
363,
257,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
6542,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
32,
7697,
5017,
1939,
31876,
14,
846,
3524,
199,
363,
21841,
363,
275,
283,
26854,
655,
7,
199,
199,
646,
636,
5351,
363,
199,
199,
646,
13397,
199,
504,
14490,
14,
5649,
492,
6566,
23560,
199,
504,
14490,
492,
7559,
199,
199,
504,
19238,
14,
4342,
14,
1000,
492,
3537,
63,
955,
63,
475,
63,
2918,
199,
504,
19238,
14,
4342,
14,
1000,
14,
1208,
492,
14053,
12,
1475,
63,
1450,
63,
875,
199,
504,
19238,
14,
69,
8858,
14,
2343,
492,
7104,
63,
4148,
88,
199,
504,
19238,
14,
5559,
492,
14388,
63,
2991,
199,
504,
19238,
492,
365,
991,
396,
5985,
199,
504,
19238,
14,
1208,
14,
10309,
492,
13294,
63,
1501,
199,
504,
19238,
14,
1208,
14,
530,
85,
492,
4069,
63,
498,
199,
199,
37,
275,
6566,
23560,
342,
199,
199,
533,
4692,
3120,
8,
785,
304,
272,
283,
1505,
2310,
4692,
436,
314,
437,
15863,
4079,
4163,
22523,
7,
339,
347,
1050,
63,
13243,
8,
277,
12,
4907,
304,
267,
4907,
360,
1652,
297,
1994,
1652,
297,
291,
14,
1652,
9,
339,
347,
2748,
8,
277,
12,
1343,
534,
16,
297,
1967,
534,
1400,
297,
4069,
29,
403,
12,
2754,
29,
403,
12,
355,
485,
29,
403,
12,
1865,
534,
10125,
3219,
735,
267,
1449,
267,
3739,
2310,
3341,
687,
314,
19238,
3050,
465,
4692,
14,
398,
520,
635,
4069,
26,
16722,
2058,
701,
1124,
3191,
4345,
6855,
506,
1373,
402,
658,
1213,
12,
2502,
12,
10417,
2313,
267,
520,
635,
2754,
26,
9388,
2058,
701,
1124,
1733,
1040,
1827,
14,
1666,
520,
533,
1705,
5278,
3227,
2842,
64,
367,
1827,
6302,
267,
520,
635,
1343,
12,
1507,
26,
1432,
314,
6014,
14505,
928,
26,
928,
11,
1507,
16090,
402,
314,
3355,
436,
9806,
2058,
267,
520,
635,
24700,
24584,
12237,
370,
15026,
3222,
642,
1380,
1808,
4692,
10441,
543,
949,
13627,
267,
1449,
267,
862,
26,
288,
1343,
275,
1109,
8,
928,
9,
267,
871,
1722,
26,
288,
746,
13397,
14,
12815,
8,
5303,
12,
283,
928,
26,
450,
83,
365,
440,
376,
3000,
5956,
928,
9,
267,
862,
26,
288,
1967,
275,
1109,
8,
1507,
9,
267,
871,
1722,
26,
288,
746,
13397,
14,
12815,
8,
5303,
12,
283,
1507,
26,
450,
83,
365,
440,
376,
3000,
5956,
1507,
9,
398,
1865,
275,
1865,
14,
2325,
1252,
1913,
342,
508,
283,
10125,
3219,
7,
398,
340,
440,
2754,
26,
288,
2754,
275,
2125,
267,
340,
365,
991,
396,
5985,
8,
1733,
304,
288,
2754,
275,
2754,
14,
2708,
360,
6610,
13,
24,
358,
398,
2762,
275,
291,
14,
697,
14,
1733,
63,
362,
1337,
63,
1580,
8,
1733,
14,
1913,
1062,
291,
14,
1733,
63,
23423,
9,
398,
481,
45,
275,
291,
14,
697,
14,
8609,
63,
5443,
398,
2974,
275,
359,
82,
367,
519,
315,
2740,
8,
277,
14,
697,
9,
340,
519,
59,
22367,
459,
344,
6538,
315,
2762,
61,
267,
340,
4069,
365,
440,
488,
26,
288,
291,
14,
3191,
8,
1744,
12,
4069,
12,
1865,
9,
398,
19040,
275,
942,
398,
347,
8437,
8,
88,
304,
288,
340,
1228,
8,
88,
12,
2649,
304,
355,
372,
671,
288,
340,
365,
991,
396,
5985,
8,
88,
304,
355,
372,
671,
14,
2708,
8,
17477,
63,
2991,
12,
283,
1814,
358,
288,
372,
2649,
8,
88,
9,
398,
327,
961,
1083,
4440,
2399,
5705,
6719,
1211,
12,
440,
314,
16160,
1211,
14,
710,
4438,
267,
327,
5084,
4293,
506,
2896,
370,
675,
1592,
14,
362,
63,
2343,
3140,
402,
7664,
267,
327,
2256,
5370,
687,
314,
2777,
6326,
701,
314,
2455,
12,
1325,
652,
3181,
1133,
17021,
267,
327,
25235,
652,
737,
314,
12427,
14,
267,
367,
2777,
315,
2974,
59,
928,
26,
928,
11,
1507,
2189,
288,
2074,
275,
1052,
288,
282,
527,
275,
2777,
59,
22367,
459,
8149,
6538,
340,
2777,
59,
22367,
459,
8149,
6538,
587,
636,
5351,
363,
423,
360,
5912,
358,
288,
11462,
275,
21590,
904,
779,
73,
14,
1814,
20137,
297,
1656,
358,
367,
284,
315,
282,
527,
14,
1294,
5102,
2023,
288,
2074,
459,
8149,
418,
275,
11462,
953,
2074,
459,
5602,
63,
1080,
418,
275,
971,
355,
7104,
63,
4148,
88,
8,
1609,
8,
3059,
59,
22367,
459,
5602,
63,
1080,
418,
2459,
953,
367,
671,
315,
661,
3954,
297,
283,
30218,
735,
355,
2074,
59,
88,
61,
275,
14053,
3508,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
297,
2777,
59,
22367,
59,
88,
3934,
953,
367,
671,
315,
661,
344,
297,
283,
1213,
297,
283,
3191,
297,
283,
2502,
63,
3191,
297,
283,
10417,
297,
283,
890,
735,
355,
2074,
59,
88,
61,
275,
8437,
8,
3059,
59,
22367,
59,
88,
3934,
953,
367,
671,
315,
661,
6321,
297,
283,
5602,
297,
283,
2969,
297,
283,
12789,
297,
490,
283,
6223,
297,
283,
14227,
735,
355,
612,
275,
2777,
59,
22367,
59,
88,
2677,
355,
340,
671,
508,
283,
2969,
356,
490,
612,
275,
1475,
63,
1450,
63,
875,
8,
89,
12,
30048,
3686,
63,
988,
29,
549,
9,
355,
2074,
59,
88,
61,
275,
8437,
8,
89,
9,
340,
612,
587,
2125,
953,
365,
10472,
275,
291,
14,
697,
14,
374,
10472,
8,
3059,
59,
22367,
459,
344,
2157,
1478,
63,
374,
63,
344,
29,
549,
9,
288,
2074,
459,
374,
10472,
418,
275,
8437,
8,
374,
10472,
340,
365,
10472,
587,
4074,
953,
2074,
459,
3489,
63,
1213,
418,
275,
13294,
63,
1501,
8,
958,
459,
1213,
1105,
953,
286,
275,
2074,
14,
1935,
360,
6223,
358,
953,
6035,
45,
275,
291,
14,
697,
14,
698,
63,
2343,
288,
445,
17434,
275,
359,
498,
367,
790,
315,
3355,
8,
4229,
63,
955,
63,
475,
63,
2918,
8,
277,
14,
697,
395,
5644,
790,
29,
2734,
671,
26,
4069,
63,
498,
8,
5487,
45,
59,
88,
2733,
354,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
romain-dartigues/ansible
|
lib/ansible/module_utils/aws/elbv2.py
|
23
|
29133
|
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible imports
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, get_ec2_security_group_ids_from_names, \
ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict, compare_policies as compare_dicts, \
AWSRetry
from ansible.module_utils.aws.elb_utils import get_elb, get_elb_listener, convert_tg_name_to_arn
# Non-ansible imports
try:
from botocore.exceptions import BotoCoreError, ClientError
except ImportError:
pass
import traceback
from copy import deepcopy
class ElasticLoadBalancerV2(object):
def __init__(self, connection, module):
self.connection = connection
self.module = module
self.changed = False
self.new_load_balancer = False
self.scheme = module.params.get("scheme")
self.name = module.params.get("name")
self.subnet_mappings = module.params.get("subnet_mappings")
self.subnets = module.params.get("subnets")
self.deletion_protection = module.params.get("deletion_protection")
self.wait = module.params.get("wait")
if module.params.get("tags") is not None:
self.tags = ansible_dict_to_boto3_tag_list(module.params.get("tags"))
else:
self.tags = None
self.purge_tags = module.params.get("purge_tags")
self.elb = get_elb(connection, module, self.name)
if self.elb is not None:
self.elb_attributes = self.get_elb_attributes()
self.elb['tags'] = self.get_elb_tags()
else:
self.elb_attributes = None
def wait_for_status(self, elb_arn):
"""
Wait for load balancer to reach 'active' status
:param elb_arn: The load balancer ARN
:return:
"""
try:
waiter = self.connection.get_waiter('load_balancer_available')
waiter.wait(LoadBalancerArns=[elb_arn])
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def get_elb_attributes(self):
"""
Get load balancer attributes
:return:
"""
try:
attr_list = AWSRetry.jittered_backoff()(
self.connection.describe_load_balancer_attributes
)(LoadBalancerArn=self.elb['LoadBalancerArn'])['Attributes']
elb_attributes = boto3_tag_list_to_ansible_dict(attr_list)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
# Replace '.' with '_' in attribute key names to make it more Ansibley
return dict((k.replace('.', '_'), v) for k, v in elb_attributes.items())
def update_elb_attributes(self):
"""
Update the elb_attributes parameter
:return:
"""
self.elb_attributes = self.get_elb_attributes()
def get_elb_tags(self):
"""
Get load balancer tags
:return:
"""
try:
return AWSRetry.jittered_backoff()(
self.connection.describe_tags
)(ResourceArns=[self.elb['LoadBalancerArn']])['TagDescriptions'][0]['Tags']
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def delete_tags(self, tags_to_delete):
"""
Delete elb tags
:return:
"""
try:
AWSRetry.jittered_backoff()(
self.connection.remove_tags
)(ResourceArns=[self.elb['LoadBalancerArn']], TagKeys=tags_to_delete)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def modify_tags(self):
"""
Modify elb tags
:return:
"""
try:
AWSRetry.jittered_backoff()(
self.connection.add_tags
)(ResourceArns=[self.elb['LoadBalancerArn']], Tags=self.tags)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def delete(self):
"""
Delete elb
:return:
"""
try:
AWSRetry.jittered_backoff()(
self.connection.delete_load_balancer
)(LoadBalancerArn=self.elb['LoadBalancerArn'])
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def compare_subnets(self):
"""
Compare user subnets with current ELB subnets
:return: bool True if they match otherwise False
"""
subnet_mapping_id_list = []
subnet_mappings = []
# Check if we're dealing with subnets or subnet_mappings
if self.subnets is not None:
# Convert subnets to subnet_mappings format for comparison
for subnet in self.subnets:
subnet_mappings.append({'SubnetId': subnet})
if self.subnet_mappings is not None:
# Use this directly since we're comparing as a mapping
subnet_mappings = self.subnet_mappings
# Build a subnet_mapping style struture of what's currently
# on the load balancer
for subnet in self.elb['AvailabilityZones']:
this_mapping = {'SubnetId': subnet['SubnetId']}
for address in subnet['LoadBalancerAddresses']:
if 'AllocationId' in address:
this_mapping['AllocationId'] = address['AllocationId']
break
subnet_mapping_id_list.append(this_mapping)
return set(frozenset(mapping.items()) for mapping in subnet_mapping_id_list) == set(frozenset(mapping.items()) for mapping in subnet_mappings)
def modify_subnets(self):
"""
Modify elb subnets to match module parameters
:return:
"""
try:
AWSRetry.jittered_backoff()(
self.connection.set_subnets
)(LoadBalancerArn=self.elb['LoadBalancerArn'], Subnets=self.subnets)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def update(self):
"""
Update the elb from AWS
:return:
"""
self.elb = get_elb(self.connection, self.module, self.module.params.get("name"))
self.elb['tags'] = self.get_elb_tags()
class ApplicationLoadBalancer(ElasticLoadBalancerV2):
def __init__(self, connection, connection_ec2, module):
"""
:param connection: boto3 connection
:param module: Ansible module
"""
super(ApplicationLoadBalancer, self).__init__(connection, module)
self.connection_ec2 = connection_ec2
# Ansible module parameters specific to ALBs
self.type = 'application'
if module.params.get('security_groups') is not None:
try:
self.security_groups = AWSRetry.jittered_backoff()(
get_ec2_security_group_ids_from_names
)(module.params.get('security_groups'), self.connection_ec2, boto3=True)
except ValueError as e:
self.module.fail_json(msg=str(e), exception=traceback.format_exc())
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
else:
self.security_groups = module.params.get('security_groups')
self.access_logs_enabled = module.params.get("access_logs_enabled")
self.access_logs_s3_bucket = module.params.get("access_logs_s3_bucket")
self.access_logs_s3_prefix = module.params.get("access_logs_s3_prefix")
self.idle_timeout = module.params.get("idle_timeout")
self.http2 = module.params.get("http2")
if self.elb is not None and self.elb['Type'] != 'application':
self.module.fail_json(msg="The load balancer type you are trying to manage is not application. Try elb_network_lb module instead.")
def create_elb(self):
"""
Create a load balancer
:return:
"""
# Required parameters
params = dict()
params['Name'] = self.name
params['Type'] = self.type
# Other parameters
if self.subnets is not None:
params['Subnets'] = self.subnets
if self.subnet_mappings is not None:
params['SubnetMappings'] = self.subnet_mappings
if self.security_groups is not None:
params['SecurityGroups'] = self.security_groups
params['Scheme'] = self.scheme
if self.tags:
params['Tags'] = self.tags
try:
self.elb = AWSRetry.jittered_backoff()(self.connection.create_load_balancer)(**params)['LoadBalancers'][0]
self.changed = True
self.new_load_balancer = True
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
if self.wait:
self.wait_for_status(self.elb['LoadBalancerArn'])
def modify_elb_attributes(self):
"""
Update Application ELB attributes if required
:return:
"""
update_attributes = []
if self.access_logs_enabled is not None and str(self.access_logs_enabled).lower() != self.elb_attributes['access_logs_s3_enabled']:
update_attributes.append({'Key': 'access_logs.s3.enabled', 'Value': str(self.access_logs_enabled).lower()})
if self.access_logs_s3_bucket is not None and self.access_logs_s3_bucket != self.elb_attributes['access_logs_s3_bucket']:
update_attributes.append({'Key': 'access_logs.s3.bucket', 'Value': self.access_logs_s3_bucket})
if self.access_logs_s3_prefix is not None and self.access_logs_s3_prefix != self.elb_attributes['access_logs_s3_prefix']:
update_attributes.append({'Key': 'access_logs.s3.prefix', 'Value': self.access_logs_s3_prefix})
if self.deletion_protection is not None and str(self.deletion_protection).lower() != self.elb_attributes['deletion_protection_enabled']:
update_attributes.append({'Key': 'deletion_protection.enabled', 'Value': str(self.deletion_protection).lower()})
if self.idle_timeout is not None and str(self.idle_timeout) != self.elb_attributes['idle_timeout_timeout_seconds']:
update_attributes.append({'Key': 'idle_timeout.timeout_seconds', 'Value': str(self.idle_timeout)})
if self.http2 is not None and str(self.http2).lower() != self.elb_attributes['routing_http2_enabled']:
update_attributes.append({'Key': 'routing.http2.enabled', 'Value': str(self.http2).lower()})
if update_attributes:
try:
AWSRetry.jittered_backoff()(
self.connection.modify_load_balancer_attributes
)(LoadBalancerArn=self.elb['LoadBalancerArn'], Attributes=update_attributes)
self.changed = True
except (BotoCoreError, ClientError) as e:
# Something went wrong setting attributes. If this ELB was created during this task, delete it to leave a consistent state
if self.new_load_balancer:
AWSRetry.jittered_backoff()(self.connection.delete_load_balancer)(LoadBalancerArn=self.elb['LoadBalancerArn'])
self.module.fail_json_aws(e)
def compare_security_groups(self):
"""
Compare user security groups with current ELB security groups
:return: bool True if they match otherwise False
"""
if set(self.elb['SecurityGroups']) != set(self.security_groups):
return False
else:
return True
def modify_security_groups(self):
"""
Modify elb security groups to match module parameters
:return:
"""
try:
AWSRetry.jittered_backoff()(
self.connection.set_security_groups
)(LoadBalancerArn=self.elb['LoadBalancerArn'], SecurityGroups=self.security_groups)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
class NetworkLoadBalancer(ElasticLoadBalancerV2):
def __init__(self, connection, connection_ec2, module):
"""
:param connection: boto3 connection
:param module: Ansible module
"""
super(NetworkLoadBalancer, self).__init__(connection, module)
self.connection_ec2 = connection_ec2
# Ansible module parameters specific to NLBs
self.type = 'network'
self.cross_zone_load_balancing = module.params.get('cross_zone_load_balancing')
if self.elb is not None and self.elb['Type'] != 'network':
self.module.fail_json(msg="The load balancer type you are trying to manage is not network. Try elb_application_lb module instead.")
def create_elb(self):
"""
Create a load balancer
:return:
"""
# Required parameters
params = dict()
params['Name'] = self.name
params['Type'] = self.type
# Other parameters
if self.subnets is not None:
params['Subnets'] = self.subnets
if self.subnet_mappings is not None:
params['SubnetMappings'] = self.subnet_mappings
params['Scheme'] = self.scheme
if self.tags:
params['Tags'] = self.tags
try:
self.elb = AWSRetry.jittered_backoff()(self.connection.create_load_balancer)(**params)['LoadBalancers'][0]
self.changed = True
self.new_load_balancer = True
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
if self.wait:
self.wait_for_status(self.elb['LoadBalancerArn'])
def modify_elb_attributes(self):
"""
Update Network ELB attributes if required
:return:
"""
update_attributes = []
if self.cross_zone_load_balancing is not None and str(self.cross_zone_load_balancing).lower() != \
self.elb_attributes['load_balancing_cross_zone_enabled']:
update_attributes.append({'Key': 'load_balancing.cross_zone.enabled', 'Value': str(self.cross_zone_load_balancing).lower()})
if self.deletion_protection is not None and str(self.deletion_protection).lower() != self.elb_attributes['deletion_protection_enabled']:
update_attributes.append({'Key': 'deletion_protection.enabled', 'Value': str(self.deletion_protection).lower()})
if update_attributes:
try:
AWSRetry.jittered_backoff()(
self.connection.modify_load_balancer_attributes
)(LoadBalancerArn=self.elb['LoadBalancerArn'], Attributes=update_attributes)
self.changed = True
except (BotoCoreError, ClientError) as e:
# Something went wrong setting attributes. If this ELB was created during this task, delete it to leave a consistent state
if self.new_load_balancer:
AWSRetry.jittered_backoff()(self.connection.delete_load_balancer)(LoadBalancerArn=self.elb['LoadBalancerArn'])
self.module.fail_json_aws(e)
def modify_subnets(self):
"""
Modify elb subnets to match module parameters (unsupported for NLB)
:return:
"""
self.module.fail_json(msg='Modifying subnets and elastic IPs is not supported for Network Load Balancer')
class ELBListeners(object):
def __init__(self, connection, module, elb_arn):
self.connection = connection
self.module = module
self.elb_arn = elb_arn
listeners = module.params.get("listeners")
if listeners is not None:
# Remove suboption argspec defaults of None from each listener
listeners = [dict((x, listener_dict[x]) for x in listener_dict if listener_dict[x] is not None) for listener_dict in listeners]
self.listeners = self._ensure_listeners_default_action_has_arn(listeners)
self.current_listeners = self._get_elb_listeners()
self.purge_listeners = module.params.get("purge_listeners")
self.changed = False
def update(self):
"""
Update the listeners for the ELB
:return:
"""
self.current_listeners = self._get_elb_listeners()
def _get_elb_listeners(self):
"""
Get ELB listeners
:return:
"""
try:
listener_paginator = self.connection.get_paginator('describe_listeners')
return (AWSRetry.jittered_backoff()(listener_paginator.paginate)(LoadBalancerArn=self.elb_arn).build_full_result())['Listeners']
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def _ensure_listeners_default_action_has_arn(self, listeners):
"""
If a listener DefaultAction has been passed with a Target Group Name instead of ARN, lookup the ARN and
replace the name.
:param listeners: a list of listener dicts
:return: the same list of dicts ensuring that each listener DefaultActions dict has TargetGroupArn key. If a TargetGroupName key exists, it is removed.
"""
if not listeners:
listeners = []
for listener in listeners:
if 'TargetGroupName' in listener['DefaultActions'][0]:
listener['DefaultActions'][0]['TargetGroupArn'] = convert_tg_name_to_arn(self.connection, self.module,
listener['DefaultActions'][0]['TargetGroupName'])
del listener['DefaultActions'][0]['TargetGroupName']
return listeners
def compare_listeners(self):
"""
:return:
"""
listeners_to_modify = []
listeners_to_delete = []
listeners_to_add = deepcopy(self.listeners)
# Check each current listener port to see if it's been passed to the module
for current_listener in self.current_listeners:
current_listener_passed_to_module = False
for new_listener in self.listeners[:]:
new_listener['Port'] = int(new_listener['Port'])
if current_listener['Port'] == new_listener['Port']:
current_listener_passed_to_module = True
# Remove what we match so that what is left can be marked as 'to be added'
listeners_to_add.remove(new_listener)
modified_listener = self._compare_listener(current_listener, new_listener)
if modified_listener:
modified_listener['Port'] = current_listener['Port']
modified_listener['ListenerArn'] = current_listener['ListenerArn']
listeners_to_modify.append(modified_listener)
break
# If the current listener was not matched against passed listeners and purge is True, mark for removal
if not current_listener_passed_to_module and self.purge_listeners:
listeners_to_delete.append(current_listener['ListenerArn'])
return listeners_to_add, listeners_to_modify, listeners_to_delete
def _compare_listener(self, current_listener, new_listener):
"""
Compare two listeners.
:param current_listener:
:param new_listener:
:return:
"""
modified_listener = {}
# Port
if current_listener['Port'] != new_listener['Port']:
modified_listener['Port'] = new_listener['Port']
# Protocol
if current_listener['Protocol'] != new_listener['Protocol']:
modified_listener['Protocol'] = new_listener['Protocol']
# If Protocol is HTTPS, check additional attributes
if current_listener['Protocol'] == 'HTTPS' and new_listener['Protocol'] == 'HTTPS':
# Cert
if current_listener['SslPolicy'] != new_listener['SslPolicy']:
modified_listener['SslPolicy'] = new_listener['SslPolicy']
if current_listener['Certificates'][0]['CertificateArn'] != new_listener['Certificates'][0]['CertificateArn']:
modified_listener['Certificates'] = []
modified_listener['Certificates'].append({})
modified_listener['Certificates'][0]['CertificateArn'] = new_listener['Certificates'][0]['CertificateArn']
elif current_listener['Protocol'] != 'HTTPS' and new_listener['Protocol'] == 'HTTPS':
modified_listener['SslPolicy'] = new_listener['SslPolicy']
modified_listener['Certificates'] = []
modified_listener['Certificates'].append({})
modified_listener['Certificates'][0]['CertificateArn'] = new_listener['Certificates'][0]['CertificateArn']
# Default action
# We wont worry about the Action Type because it is always 'forward'
if current_listener['DefaultActions'][0]['TargetGroupArn'] != new_listener['DefaultActions'][0]['TargetGroupArn']:
modified_listener['DefaultActions'] = []
modified_listener['DefaultActions'].append({})
modified_listener['DefaultActions'][0]['TargetGroupArn'] = new_listener['DefaultActions'][0]['TargetGroupArn']
modified_listener['DefaultActions'][0]['Type'] = 'forward'
if modified_listener:
return modified_listener
else:
return None
class ELBListener(object):
def __init__(self, connection, module, listener, elb_arn):
"""
:param connection:
:param module:
:param listener:
:param elb_arn:
"""
self.connection = connection
self.module = module
self.listener = listener
self.elb_arn = elb_arn
def add(self):
try:
# Rules is not a valid parameter for create_listener
if 'Rules' in self.listener:
self.listener.pop('Rules')
AWSRetry.jittered_backoff()(self.connection.create_listener)(LoadBalancerArn=self.elb_arn, **self.listener)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def modify(self):
try:
# Rules is not a valid parameter for modify_listener
if 'Rules' in self.listener:
self.listener.pop('Rules')
AWSRetry.jittered_backoff()(self.connection.modify_listener)(**self.listener)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def delete(self):
try:
AWSRetry.jittered_backoff()(self.connection.delete_listener)(ListenerArn=self.listener)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
class ELBListenerRules(object):
def __init__(self, connection, module, elb_arn, listener_rules, listener_port):
self.connection = connection
self.module = module
self.elb_arn = elb_arn
self.rules = self._ensure_rules_action_has_arn(listener_rules)
self.changed = False
# Get listener based on port so we can use ARN
self.current_listener = get_elb_listener(connection, module, elb_arn, listener_port)
self.listener_arn = self.current_listener['ListenerArn']
self.rules_to_add = deepcopy(self.rules)
self.rules_to_modify = []
self.rules_to_delete = []
# If the listener exists (i.e. has an ARN) get rules for the listener
if 'ListenerArn' in self.current_listener:
self.current_rules = self._get_elb_listener_rules()
else:
self.current_rules = []
def _ensure_rules_action_has_arn(self, rules):
"""
If a rule Action has been passed with a Target Group Name instead of ARN, lookup the ARN and
replace the name.
:param rules: a list of rule dicts
:return: the same list of dicts ensuring that each rule Actions dict has TargetGroupArn key. If a TargetGroupName key exists, it is removed.
"""
for rule in rules:
if 'TargetGroupName' in rule['Actions'][0]:
rule['Actions'][0]['TargetGroupArn'] = convert_tg_name_to_arn(self.connection, self.module, rule['Actions'][0]['TargetGroupName'])
del rule['Actions'][0]['TargetGroupName']
return rules
def _get_elb_listener_rules(self):
try:
return AWSRetry.jittered_backoff()(self.connection.describe_rules)(ListenerArn=self.current_listener['ListenerArn'])['Rules']
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
def _compare_condition(self, current_conditions, condition):
"""
:param current_conditions:
:param condition:
:return:
"""
condition_found = False
for current_condition in current_conditions:
if current_condition['Field'] == condition['Field'] and current_condition['Values'][0] == condition['Values'][0]:
condition_found = True
break
return condition_found
def _compare_rule(self, current_rule, new_rule):
"""
:return:
"""
modified_rule = {}
# Priority
if current_rule['Priority'] != new_rule['Priority']:
modified_rule['Priority'] = new_rule['Priority']
# Actions
# We wont worry about the Action Type because it is always 'forward'
if current_rule['Actions'][0]['TargetGroupArn'] != new_rule['Actions'][0]['TargetGroupArn']:
modified_rule['Actions'] = []
modified_rule['Actions'].append({})
modified_rule['Actions'][0]['TargetGroupArn'] = new_rule['Actions'][0]['TargetGroupArn']
modified_rule['Actions'][0]['Type'] = 'forward'
# Conditions
modified_conditions = []
for condition in new_rule['Conditions']:
if not self._compare_condition(current_rule['Conditions'], condition):
modified_conditions.append(condition)
if modified_conditions:
modified_rule['Conditions'] = modified_conditions
return modified_rule
def compare_rules(self):
"""
:return:
"""
rules_to_modify = []
rules_to_delete = []
rules_to_add = deepcopy(self.rules)
for current_rule in self.current_rules:
current_rule_passed_to_module = False
for new_rule in self.rules[:]:
if current_rule['Priority'] == str(new_rule['Priority']):
current_rule_passed_to_module = True
# Remove what we match so that what is left can be marked as 'to be added'
rules_to_add.remove(new_rule)
modified_rule = self._compare_rule(current_rule, new_rule)
if modified_rule:
modified_rule['Priority'] = int(current_rule['Priority'])
modified_rule['RuleArn'] = current_rule['RuleArn']
modified_rule['Actions'] = new_rule['Actions']
modified_rule['Conditions'] = new_rule['Conditions']
rules_to_modify.append(modified_rule)
break
# If the current rule was not matched against passed rules, mark for removal
if not current_rule_passed_to_module and not current_rule['IsDefault']:
rules_to_delete.append(current_rule['RuleArn'])
return rules_to_add, rules_to_modify, rules_to_delete
class ELBListenerRule(object):
def __init__(self, connection, module, rule, listener_arn):
self.connection = connection
self.module = module
self.rule = rule
self.listener_arn = listener_arn
self.changed = False
def create(self):
"""
Create a listener rule
:return:
"""
try:
self.rule['ListenerArn'] = self.listener_arn
self.rule['Priority'] = int(self.rule['Priority'])
AWSRetry.jittered_backoff()(self.connection.create_rule)(**self.rule)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def modify(self):
"""
Modify a listener rule
:return:
"""
try:
del self.rule['Priority']
AWSRetry.jittered_backoff()(self.connection.modify_rule)(**self.rule)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
def delete(self):
"""
Delete a listener rule
:return:
"""
try:
AWSRetry.jittered_backoff()(self.connection.delete_rule)(RuleArn=self.rule['RuleArn'])
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)
self.changed = True
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
9708,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
3,
2622,
8925,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
12,
664,
63,
825,
18,
63,
4416,
63,
923,
63,
1580,
63,
504,
63,
1247,
12,
971,
272,
3242,
63,
807,
63,
475,
63,
10914,
19,
63,
1450,
63,
513,
12,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
12,
6540,
63,
11767,
465,
6540,
63,
7892,
12,
971,
272,
10168,
12989,
199,
504,
3242,
14,
578,
63,
1208,
14,
7231,
14,
17778,
63,
1208,
492,
664,
63,
17778,
12,
664,
63,
17778,
63,
9799,
12,
3957,
63,
17699,
63,
354,
63,
475,
63,
1060,
199,
199,
3,
10172,
13,
4853,
8925,
199,
893,
26,
272,
687,
21199,
14,
3924,
492,
24411,
5402,
547,
12,
28972,
199,
2590,
3545,
26,
272,
986,
199,
646,
5190,
199,
504,
1331,
492,
14800,
421,
199,
533,
19509,
27560,
54,
18,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
12,
859,
304,
398,
291,
14,
2105,
275,
1950,
267,
291,
14,
578,
275,
859,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
1222,
63,
912,
63,
11841,
275,
756,
267,
291,
14,
5512,
275,
859,
14,
1162,
14,
362,
480,
5512,
531,
267,
291,
14,
354,
275,
859,
14,
1162,
14,
362,
480,
354,
531,
267,
291,
14,
5327,
63,
14632,
275,
859,
14,
1162,
14,
362,
480,
5327,
63,
14632,
531,
267,
291,
14,
14967,
275,
859,
14,
1162,
14,
362,
480,
14967,
531,
267,
291,
14,
14281,
63,
14103,
275,
859,
14,
1162,
14,
362,
480,
14281,
63,
14103,
531,
267,
291,
14,
2573,
275,
859,
14,
1162,
14,
362,
480,
2573,
531,
398,
340,
859,
14,
1162,
14,
362,
480,
2969,
531,
365,
440,
488,
26,
288,
291,
14,
2969,
275,
3242,
63,
807,
63,
475,
63,
10914,
19,
63,
1450,
63,
513,
8,
578,
14,
1162,
14,
362,
480,
2969,
2237,
267,
587,
26,
288,
291,
14,
2969,
275,
488,
267,
291,
14,
18254,
63,
2969,
275,
859,
14,
1162,
14,
362,
480,
18254,
63,
2969,
531,
398,
291,
14,
17778,
275,
664,
63,
17778,
8,
2105,
12,
859,
12,
291,
14,
354,
9,
267,
340,
291,
14,
17778,
365,
440,
488,
26,
288,
291,
14,
17778,
63,
2987,
275,
291,
14,
362,
63,
17778,
63,
2987,
342,
288,
291,
14,
17778,
459,
2969,
418,
275,
291,
14,
362,
63,
17778,
63,
2969,
342,
267,
587,
26,
288,
291,
14,
17778,
63,
2987,
275,
488,
339,
347,
3618,
63,
509,
63,
1205,
8,
277,
12,
27770,
63,
1060,
304,
267,
408,
267,
13144,
367,
2248,
17005,
370,
12276,
283,
2682,
7,
2004,
398,
520,
635,
27770,
63,
1060,
26,
710,
2248,
17005,
4160,
46,
267,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
27730,
275,
291,
14,
2105,
14,
362,
63,
758,
1661,
360,
912,
63,
11841,
63,
4561,
358,
288,
27730,
14,
2573,
8,
27560,
1596,
561,
1524,
17778,
63,
1060,
566,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
339,
347,
664,
63,
17778,
63,
2987,
8,
277,
304,
267,
408,
267,
2372,
2248,
17005,
3004,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
1921,
63,
513,
275,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
11935,
63,
912,
63,
11841,
63,
2987,
288,
776,
8,
27560,
20498,
29,
277,
14,
17778,
459,
27560,
20498,
1105,
459,
5379,
418,
953,
27770,
63,
2987,
275,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
8,
962,
63,
513,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
398,
327,
14402,
7815,
543,
14135,
315,
2225,
790,
1561,
370,
1852,
652,
1655,
2622,
89,
267,
372,
1211,
1332,
75,
14,
1814,
14078,
2513,
659,
373,
9,
367,
1022,
12,
373,
315,
27770,
63,
2987,
14,
1744,
1012,
339,
347,
1678,
63,
17778,
63,
2987,
8,
277,
304,
267,
408,
267,
6162,
314,
27770,
63,
2987,
2725,
267,
520,
1107,
26,
267,
408,
267,
291,
14,
17778,
63,
2987,
275,
291,
14,
362,
63,
17778,
63,
2987,
342,
339,
347,
664,
63,
17778,
63,
2969,
8,
277,
304,
267,
408,
267,
2372,
2248,
17005,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
372,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
11935,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
12121,
459,
1931,
5831,
83,
3488,
16,
2733,
9440,
418,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
339,
347,
3145,
63,
2969,
8,
277,
12,
3762,
63,
475,
63,
1807,
304,
267,
408,
267,
8496,
27770,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
2168,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
2157,
8053,
6340,
29,
2969,
63,
475,
63,
1807,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
398,
291,
14,
2489,
275,
715,
339,
347,
2811,
63,
2969,
8,
277,
304,
267,
408,
267,
22520,
27770,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
525,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
2157,
25204,
29,
277,
14,
2969,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578
] |
[
1898,
334,
67,
9,
9708,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
3,
2622,
8925,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
12,
664,
63,
825,
18,
63,
4416,
63,
923,
63,
1580,
63,
504,
63,
1247,
12,
971,
272,
3242,
63,
807,
63,
475,
63,
10914,
19,
63,
1450,
63,
513,
12,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
12,
6540,
63,
11767,
465,
6540,
63,
7892,
12,
971,
272,
10168,
12989,
199,
504,
3242,
14,
578,
63,
1208,
14,
7231,
14,
17778,
63,
1208,
492,
664,
63,
17778,
12,
664,
63,
17778,
63,
9799,
12,
3957,
63,
17699,
63,
354,
63,
475,
63,
1060,
199,
199,
3,
10172,
13,
4853,
8925,
199,
893,
26,
272,
687,
21199,
14,
3924,
492,
24411,
5402,
547,
12,
28972,
199,
2590,
3545,
26,
272,
986,
199,
646,
5190,
199,
504,
1331,
492,
14800,
421,
199,
533,
19509,
27560,
54,
18,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
12,
859,
304,
398,
291,
14,
2105,
275,
1950,
267,
291,
14,
578,
275,
859,
267,
291,
14,
2489,
275,
756,
267,
291,
14,
1222,
63,
912,
63,
11841,
275,
756,
267,
291,
14,
5512,
275,
859,
14,
1162,
14,
362,
480,
5512,
531,
267,
291,
14,
354,
275,
859,
14,
1162,
14,
362,
480,
354,
531,
267,
291,
14,
5327,
63,
14632,
275,
859,
14,
1162,
14,
362,
480,
5327,
63,
14632,
531,
267,
291,
14,
14967,
275,
859,
14,
1162,
14,
362,
480,
14967,
531,
267,
291,
14,
14281,
63,
14103,
275,
859,
14,
1162,
14,
362,
480,
14281,
63,
14103,
531,
267,
291,
14,
2573,
275,
859,
14,
1162,
14,
362,
480,
2573,
531,
398,
340,
859,
14,
1162,
14,
362,
480,
2969,
531,
365,
440,
488,
26,
288,
291,
14,
2969,
275,
3242,
63,
807,
63,
475,
63,
10914,
19,
63,
1450,
63,
513,
8,
578,
14,
1162,
14,
362,
480,
2969,
2237,
267,
587,
26,
288,
291,
14,
2969,
275,
488,
267,
291,
14,
18254,
63,
2969,
275,
859,
14,
1162,
14,
362,
480,
18254,
63,
2969,
531,
398,
291,
14,
17778,
275,
664,
63,
17778,
8,
2105,
12,
859,
12,
291,
14,
354,
9,
267,
340,
291,
14,
17778,
365,
440,
488,
26,
288,
291,
14,
17778,
63,
2987,
275,
291,
14,
362,
63,
17778,
63,
2987,
342,
288,
291,
14,
17778,
459,
2969,
418,
275,
291,
14,
362,
63,
17778,
63,
2969,
342,
267,
587,
26,
288,
291,
14,
17778,
63,
2987,
275,
488,
339,
347,
3618,
63,
509,
63,
1205,
8,
277,
12,
27770,
63,
1060,
304,
267,
408,
267,
13144,
367,
2248,
17005,
370,
12276,
283,
2682,
7,
2004,
398,
520,
635,
27770,
63,
1060,
26,
710,
2248,
17005,
4160,
46,
267,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
27730,
275,
291,
14,
2105,
14,
362,
63,
758,
1661,
360,
912,
63,
11841,
63,
4561,
358,
288,
27730,
14,
2573,
8,
27560,
1596,
561,
1524,
17778,
63,
1060,
566,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
339,
347,
664,
63,
17778,
63,
2987,
8,
277,
304,
267,
408,
267,
2372,
2248,
17005,
3004,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
1921,
63,
513,
275,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
11935,
63,
912,
63,
11841,
63,
2987,
288,
776,
8,
27560,
20498,
29,
277,
14,
17778,
459,
27560,
20498,
1105,
459,
5379,
418,
953,
27770,
63,
2987,
275,
6055,
19,
63,
1450,
63,
513,
63,
475,
63,
4853,
63,
807,
8,
962,
63,
513,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
398,
327,
14402,
7815,
543,
14135,
315,
2225,
790,
1561,
370,
1852,
652,
1655,
2622,
89,
267,
372,
1211,
1332,
75,
14,
1814,
14078,
2513,
659,
373,
9,
367,
1022,
12,
373,
315,
27770,
63,
2987,
14,
1744,
1012,
339,
347,
1678,
63,
17778,
63,
2987,
8,
277,
304,
267,
408,
267,
6162,
314,
27770,
63,
2987,
2725,
267,
520,
1107,
26,
267,
408,
267,
291,
14,
17778,
63,
2987,
275,
291,
14,
362,
63,
17778,
63,
2987,
342,
339,
347,
664,
63,
17778,
63,
2969,
8,
277,
304,
267,
408,
267,
2372,
2248,
17005,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
372,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
11935,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
12121,
459,
1931,
5831,
83,
3488,
16,
2733,
9440,
418,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
339,
347,
3145,
63,
2969,
8,
277,
12,
3762,
63,
475,
63,
1807,
304,
267,
408,
267,
8496,
27770,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
2168,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
2157,
8053,
6340,
29,
2969,
63,
475,
63,
1807,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
63,
7231,
8,
69,
9,
398,
291,
14,
2489,
275,
715,
339,
347,
2811,
63,
2969,
8,
277,
304,
267,
408,
267,
22520,
27770,
3762,
398,
520,
1107,
26,
267,
408,
398,
862,
26,
288,
10168,
12989,
14,
17676,
3014,
63,
21061,
24851,
355,
291,
14,
2105,
14,
525,
63,
2969,
288,
776,
8,
4031,
1596,
561,
1524,
277,
14,
17778,
459,
27560,
20498,
2157,
25204,
29,
277,
14,
2969,
9,
267,
871,
334,
20380,
5402,
547,
12,
28972,
9,
465,
325,
26,
288,
291,
14,
578,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nelango/ViralityAnalysis
|
model/lib/pandas/tests/test_msgpack/test_extension.py
|
9
|
2254
|
from __future__ import print_function
import array
import pandas.msgpack as msgpack
from pandas.msgpack import ExtType
def test_pack_ext_type():
def p(s):
packer = msgpack.Packer()
packer.pack_ext_type(0x42, s)
return packer.bytes()
assert p(b'A') == b'\xd4\x42A' # fixext 1
assert p(b'AB') == b'\xd5\x42AB' # fixext 2
assert p(b'ABCD') == b'\xd6\x42ABCD' # fixext 4
assert p(b'ABCDEFGH') == b'\xd7\x42ABCDEFGH' # fixext 8
assert p(b'A'*16) == b'\xd8\x42' + b'A'*16 # fixext 16
assert p(b'ABC') == b'\xc7\x03\x42ABC' # ext 8
assert p(b'A'*0x0123) == b'\xc8\x01\x23\x42' + b'A'*0x0123 # ext 16
assert p(b'A'*0x00012345) == b'\xc9\x00\x01\x23\x45\x42' + b'A'*0x00012345 # ext 32
def test_unpack_ext_type():
def check(b, expected):
assert msgpack.unpackb(b) == expected
check(b'\xd4\x42A', ExtType(0x42, b'A')) # fixext 1
check(b'\xd5\x42AB', ExtType(0x42, b'AB')) # fixext 2
check(b'\xd6\x42ABCD', ExtType(0x42, b'ABCD')) # fixext 4
check(b'\xd7\x42ABCDEFGH', ExtType(0x42, b'ABCDEFGH')) # fixext 8
check(b'\xd8\x42' + b'A'*16, ExtType(0x42, b'A'*16)) # fixext 16
check(b'\xc7\x03\x42ABC', ExtType(0x42, b'ABC')) # ext 8
check(b'\xc8\x01\x23\x42' + b'A'*0x0123,
ExtType(0x42, b'A'*0x0123)) # ext 16
check(b'\xc9\x00\x01\x23\x45\x42' + b'A'*0x00012345,
ExtType(0x42, b'A'*0x00012345)) # ext 32
def test_extension_type():
def default(obj):
print('default called', obj)
if isinstance(obj, array.array):
typecode = 123 # application specific typecode
data = obj.tostring()
return ExtType(typecode, data)
raise TypeError("Unknwon type object %r" % (obj,))
def ext_hook(code, data):
print('ext_hook called', code, data)
assert code == 123
obj = array.array('d')
obj.fromstring(data)
return obj
obj = [42, b'hello', array.array('d', [1.1, 2.2, 3.3])]
s = msgpack.packb(obj, default=default)
obj2 = msgpack.unpackb(s, ext_hook=ext_hook)
assert obj == obj2
|
mit
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
1625,
199,
646,
10634,
14,
1328,
1389,
465,
26635,
199,
504,
10634,
14,
1328,
1389,
492,
7255,
804,
421,
199,
318,
511,
63,
1389,
63,
832,
63,
466,
837,
272,
347,
299,
8,
83,
304,
267,
1706,
281,
275,
26635,
14,
2305,
281,
342,
267,
1706,
281,
14,
1389,
63,
832,
63,
466,
8,
16,
88,
2260,
12,
308,
9,
267,
372,
1706,
281,
14,
2394,
342,
272,
702,
299,
8,
66,
7,
33,
358,
263,
508,
330,
1154,
2207,
20,
60,
88,
2260,
33,
7,
3515,
327,
5325,
832,
413,
272,
702,
299,
8,
66,
7,
1217,
358,
755,
508,
330,
1154,
2207,
21,
60,
88,
2260,
1217,
7,
260,
327,
5325,
832,
499,
272,
702,
299,
8,
66,
7,
31578,
358,
258,
508,
330,
1154,
2207,
22,
60,
88,
2260,
31578,
7,
755,
327,
5325,
832,
841,
272,
702,
299,
8,
66,
7,
22897,
40,
358,
508,
330,
1154,
2207,
23,
60,
88,
2260,
22897,
40,
7,
257,
327,
5325,
832,
1695,
272,
702,
299,
8,
66,
7,
33,
16804,
975,
9,
258,
508,
330,
1154,
2207,
24,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
975,
327,
5325,
832,
3193,
272,
702,
299,
8,
66,
7,
8390,
358,
420,
508,
330,
1154,
1812,
23,
60,
88,
1644,
60,
88,
2260,
8390,
7,
263,
327,
1599,
1695,
272,
702,
299,
8,
66,
7,
33,
16804,
16,
88,
29555,
9,
258,
508,
330,
1154,
1812,
24,
60,
88,
614,
60,
88,
1789,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
29555,
327,
1599,
3193,
272,
702,
299,
8,
66,
7,
33,
16804,
16,
88,
4183,
5533,
21,
9,
508,
330,
1154,
1812,
25,
60,
88,
383,
60,
88,
614,
60,
88,
1789,
60,
88,
2322,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
327,
1599,
4337,
421,
199,
318,
511,
63,
5301,
63,
832,
63,
466,
837,
272,
347,
1104,
8,
66,
12,
1420,
304,
267,
702,
26635,
14,
5301,
66,
8,
66,
9,
508,
1420,
339,
1104,
8,
66,
1154,
2207,
20,
60,
88,
2260,
33,
297,
260,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
1333,
263,
327,
5325,
832,
413,
272,
1104,
8,
66,
1154,
2207,
21,
60,
88,
2260,
1217,
297,
263,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
1217,
1333,
755,
327,
5325,
832,
499,
272,
1104,
8,
66,
1154,
2207,
22,
60,
88,
2260,
31578,
297,
420,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
31578,
1333,
258,
327,
5325,
832,
841,
272,
1104,
8,
66,
1154,
2207,
23,
60,
88,
2260,
22897,
40,
297,
221,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
22897,
40,
1333,
327,
5325,
832,
1695,
272,
1104,
8,
66,
1154,
2207,
24,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
975,
12,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
975,
430,
259,
327,
5325,
832,
3193,
272,
1104,
8,
66,
1154,
1812,
23,
60,
88,
1644,
60,
88,
2260,
8390,
297,
257,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
8390,
1333,
420,
327,
1599,
1695,
272,
1104,
8,
66,
1154,
1812,
24,
60,
88,
614,
60,
88,
1789,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
29555,
12,
881,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
16,
88,
29555,
430,
12788,
327,
1599,
3193,
272,
1104,
8,
66,
1154,
1812,
25,
60,
88,
383,
60,
88,
614,
60,
88,
1789,
60,
88,
2322,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
12,
881,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
430,
7861,
327,
1599,
4337,
421,
199,
318,
511,
63,
3435,
63,
466,
837,
272,
347,
849,
8,
1113,
304,
267,
870,
360,
885,
2797,
297,
1559,
9,
267,
340,
1228,
8,
1113,
12,
1625,
14,
1144,
304,
288,
30573,
275,
11869,
327,
4223,
2488,
30573,
288,
666,
275,
1559,
14,
14028,
342,
288,
372,
7255,
804,
8,
21220,
12,
666,
9,
267,
746,
3146,
480,
1358,
75,
13100,
265,
730,
909,
450,
82,
2,
450,
334,
1113,
4641,
339,
347,
1599,
63,
3664,
8,
600,
12,
666,
304,
267,
870,
360,
832,
63,
3664,
2797,
297,
1233,
12,
666,
9,
267,
702,
1233,
508,
11869,
267,
1559,
275,
1625,
14,
1144,
360,
68,
358,
267,
1559,
14,
13521,
8,
576,
9,
267,
372,
1559,
339,
1559,
275,
359,
2260,
12,
330,
7,
5006,
297,
1625,
14,
1144,
360,
68,
297,
359,
17,
14,
17,
12,
499,
14,
18,
12,
650,
14,
19,
12457,
272,
308,
275,
26635,
14,
1389,
66,
8,
1113,
12,
849,
29,
885,
9,
272,
1559,
18,
275,
26635,
14,
5301,
66,
8,
83,
12,
1599,
63,
3664,
29,
832,
63,
3664,
9,
272,
702,
1559,
508,
1559,
18,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
870,
63,
1593,
199,
646,
1625,
199,
646,
10634,
14,
1328,
1389,
465,
26635,
199,
504,
10634,
14,
1328,
1389,
492,
7255,
804,
421,
199,
318,
511,
63,
1389,
63,
832,
63,
466,
837,
272,
347,
299,
8,
83,
304,
267,
1706,
281,
275,
26635,
14,
2305,
281,
342,
267,
1706,
281,
14,
1389,
63,
832,
63,
466,
8,
16,
88,
2260,
12,
308,
9,
267,
372,
1706,
281,
14,
2394,
342,
272,
702,
299,
8,
66,
7,
33,
358,
263,
508,
330,
1154,
2207,
20,
60,
88,
2260,
33,
7,
3515,
327,
5325,
832,
413,
272,
702,
299,
8,
66,
7,
1217,
358,
755,
508,
330,
1154,
2207,
21,
60,
88,
2260,
1217,
7,
260,
327,
5325,
832,
499,
272,
702,
299,
8,
66,
7,
31578,
358,
258,
508,
330,
1154,
2207,
22,
60,
88,
2260,
31578,
7,
755,
327,
5325,
832,
841,
272,
702,
299,
8,
66,
7,
22897,
40,
358,
508,
330,
1154,
2207,
23,
60,
88,
2260,
22897,
40,
7,
257,
327,
5325,
832,
1695,
272,
702,
299,
8,
66,
7,
33,
16804,
975,
9,
258,
508,
330,
1154,
2207,
24,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
975,
327,
5325,
832,
3193,
272,
702,
299,
8,
66,
7,
8390,
358,
420,
508,
330,
1154,
1812,
23,
60,
88,
1644,
60,
88,
2260,
8390,
7,
263,
327,
1599,
1695,
272,
702,
299,
8,
66,
7,
33,
16804,
16,
88,
29555,
9,
258,
508,
330,
1154,
1812,
24,
60,
88,
614,
60,
88,
1789,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
29555,
327,
1599,
3193,
272,
702,
299,
8,
66,
7,
33,
16804,
16,
88,
4183,
5533,
21,
9,
508,
330,
1154,
1812,
25,
60,
88,
383,
60,
88,
614,
60,
88,
1789,
60,
88,
2322,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
327,
1599,
4337,
421,
199,
318,
511,
63,
5301,
63,
832,
63,
466,
837,
272,
347,
1104,
8,
66,
12,
1420,
304,
267,
702,
26635,
14,
5301,
66,
8,
66,
9,
508,
1420,
339,
1104,
8,
66,
1154,
2207,
20,
60,
88,
2260,
33,
297,
260,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
1333,
263,
327,
5325,
832,
413,
272,
1104,
8,
66,
1154,
2207,
21,
60,
88,
2260,
1217,
297,
263,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
1217,
1333,
755,
327,
5325,
832,
499,
272,
1104,
8,
66,
1154,
2207,
22,
60,
88,
2260,
31578,
297,
420,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
31578,
1333,
258,
327,
5325,
832,
841,
272,
1104,
8,
66,
1154,
2207,
23,
60,
88,
2260,
22897,
40,
297,
221,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
22897,
40,
1333,
327,
5325,
832,
1695,
272,
1104,
8,
66,
1154,
2207,
24,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
975,
12,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
975,
430,
259,
327,
5325,
832,
3193,
272,
1104,
8,
66,
1154,
1812,
23,
60,
88,
1644,
60,
88,
2260,
8390,
297,
257,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
8390,
1333,
420,
327,
1599,
1695,
272,
1104,
8,
66,
1154,
1812,
24,
60,
88,
614,
60,
88,
1789,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
29555,
12,
881,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
16,
88,
29555,
430,
12788,
327,
1599,
3193,
272,
1104,
8,
66,
1154,
1812,
25,
60,
88,
383,
60,
88,
614,
60,
88,
1789,
60,
88,
2322,
60,
88,
2260,
7,
435,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
12,
881,
7255,
804,
8,
16,
88,
2260,
12,
330,
7,
33,
16804,
16,
88,
4183,
5533,
21,
430,
7861,
327,
1599,
4337,
421,
199,
318,
511,
63,
3435,
63,
466,
837,
272,
347,
849,
8,
1113,
304,
267,
870,
360,
885,
2797,
297,
1559,
9,
267,
340,
1228,
8,
1113,
12,
1625,
14,
1144,
304,
288,
30573,
275,
11869,
327,
4223,
2488,
30573,
288,
666,
275,
1559,
14,
14028,
342,
288,
372,
7255,
804,
8,
21220,
12,
666,
9,
267,
746,
3146,
480,
1358,
75,
13100,
265,
730,
909,
450,
82,
2,
450,
334,
1113,
4641,
339,
347,
1599,
63,
3664,
8,
600,
12,
666,
304,
267,
870,
360,
832,
63,
3664,
2797,
297,
1233,
12,
666,
9,
267,
702,
1233,
508,
11869,
267,
1559,
275,
1625,
14,
1144,
360,
68,
358,
267,
1559,
14,
13521,
8,
576,
9,
267,
372,
1559,
339,
1559,
275,
359,
2260,
12,
330,
7,
5006,
297,
1625,
14,
1144,
360,
68,
297,
359,
17,
14,
17,
12,
499,
14,
18,
12,
650,
14,
19,
12457,
272,
308,
275,
26635,
14,
1389,
66,
8,
1113,
12,
849,
29,
885,
9,
272,
1559,
18,
275,
26635,
14,
5301,
66,
8,
83,
12,
1599,
63,
3664,
29,
832,
63,
3664,
9,
272,
702,
1559,
508,
1559,
18,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
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
] |
orgito/ansible
|
test/units/plugins/lookup/test_aws_ssm.py
|
54
|
6480
|
#
# (c) 2017 Michael De La Rue
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
import pytest
from copy import copy
from ansible.errors import AnsibleError
from ansible.plugins.lookup import aws_ssm
try:
import boto3
from botocore.exceptions import ClientError
except ImportError:
pytestmark = pytest.mark.skip("This test requires the boto3 and botocore Python libraries")
simple_variable_success_response = {
'Parameters': [
{
'Name': 'simple_variable',
'Type': 'String',
'Value': 'simplevalue',
'Version': 1
}
],
'InvalidParameters': [],
'ResponseMetadata': {
'RequestId': '12121212-3434-5656-7878-9a9a9a9a9a9a',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'x-amzn-requestid': '12121212-3434-5656-7878-9a9a9a9a9a9a',
'content-type': 'application/x-amz-json-1.1',
'content-length': '116',
'date': 'Tue, 23 Jan 2018 11:04:27 GMT'
},
'RetryAttempts': 0
}
}
path_success_response = copy(simple_variable_success_response)
path_success_response['Parameters'] = [
{'Name': '/testpath/too', 'Type': 'String', 'Value': 'simple_value_too', 'Version': 1},
{'Name': '/testpath/won', 'Type': 'String', 'Value': 'simple_value_won', 'Version': 1}
]
missing_variable_response = copy(simple_variable_success_response)
missing_variable_response['Parameters'] = []
missing_variable_response['InvalidParameters'] = ['missing_variable']
some_missing_variable_response = copy(simple_variable_success_response)
some_missing_variable_response['Parameters'] = [
{'Name': 'simple', 'Type': 'String', 'Value': 'simple_value', 'Version': 1},
{'Name': '/testpath/won', 'Type': 'String', 'Value': 'simple_value_won', 'Version': 1}
]
some_missing_variable_response['InvalidParameters'] = ['missing_variable']
dummy_credentials = {}
dummy_credentials['boto_profile'] = None
dummy_credentials['aws_secret_key'] = "notasecret"
dummy_credentials['aws_access_key'] = "notakey"
dummy_credentials['aws_security_token'] = None
dummy_credentials['region'] = 'eu-west-1'
def test_lookup_variable(mocker):
lookup = aws_ssm.LookupModule()
lookup._load_name = "aws_ssm"
boto3_double = mocker.MagicMock()
boto3_double.Session.return_value.client.return_value.get_parameters.return_value = simple_variable_success_response
boto3_client_double = boto3_double.Session.return_value.client
with mocker.patch.object(boto3, 'session', boto3_double):
retval = lookup.run(["simple_variable"], {}, **dummy_credentials)
assert(retval[0] == "simplevalue")
boto3_client_double.assert_called_with('ssm', 'eu-west-1', aws_access_key_id='notakey',
aws_secret_access_key="notasecret", aws_session_token=None)
def test_path_lookup_variable(mocker):
lookup = aws_ssm.LookupModule()
lookup._load_name = "aws_ssm"
boto3_double = mocker.MagicMock()
get_path_fn = boto3_double.Session.return_value.client.return_value.get_parameters_by_path
get_path_fn.return_value = path_success_response
boto3_client_double = boto3_double.Session.return_value.client
with mocker.patch.object(boto3, 'session', boto3_double):
args = copy(dummy_credentials)
args["bypath"] = 'true'
retval = lookup.run(["/testpath"], {}, **args)
assert(retval[0]["/testpath/won"] == "simple_value_won")
assert(retval[0]["/testpath/too"] == "simple_value_too")
boto3_client_double.assert_called_with('ssm', 'eu-west-1', aws_access_key_id='notakey',
aws_secret_access_key="notasecret", aws_session_token=None)
get_path_fn.assert_called_with(Path="/testpath", Recursive=False, WithDecryption=True)
def test_return_none_for_missing_variable(mocker):
"""
during jinja2 templates, we can't shouldn't normally raise exceptions since this blocks the ability to use defaults.
for this reason we return ```None``` for missing variables
"""
lookup = aws_ssm.LookupModule()
lookup._load_name = "aws_ssm"
boto3_double = mocker.MagicMock()
boto3_double.Session.return_value.client.return_value.get_parameters.return_value = missing_variable_response
with mocker.patch.object(boto3, 'session', boto3_double):
retval = lookup.run(["missing_variable"], {}, **dummy_credentials)
assert(retval[0] is None)
def test_match_retvals_to_call_params_even_with_some_missing_variables(mocker):
"""
If we get a complex list of variables with some missing and some not, we still have to return a
list which matches with the original variable list.
"""
lookup = aws_ssm.LookupModule()
lookup._load_name = "aws_ssm"
boto3_double = mocker.MagicMock()
boto3_double.Session.return_value.client.return_value.get_parameters.return_value = some_missing_variable_response
with mocker.patch.object(boto3, 'session', boto3_double):
retval = lookup.run(["simple", "missing_variable", "/testpath/won", "simple"], {}, **dummy_credentials)
assert(retval == ["simple_value", None, "simple_value_won", "simple_value"])
error_response = {'Error': {'Code': 'ResourceNotFoundException', 'Message': 'Fake Testing Error'}}
operation_name = 'FakeOperation'
def test_warn_denied_variable(mocker):
lookup = aws_ssm.LookupModule()
lookup._load_name = "aws_ssm"
boto3_double = mocker.MagicMock()
boto3_double.Session.return_value.client.return_value.get_parameters.side_effect = ClientError(error_response, operation_name)
with pytest.raises(AnsibleError):
with mocker.patch.object(boto3, 'session', boto3_double):
lookup.run(["denied_variable"], {}, **dummy_credentials)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
9708,
16922,
1487,
7964,
820,
310,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
646,
4613,
199,
504,
1331,
492,
1331,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
199,
504,
3242,
14,
5265,
14,
3892,
492,
11488,
63,
385,
77,
199,
199,
893,
26,
272,
492,
6055,
19,
272,
687,
21199,
14,
3924,
492,
28972,
199,
2590,
3545,
26,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
2765,
511,
5074,
314,
6055,
19,
436,
21199,
2018,
8363,
531,
199,
199,
4129,
63,
1975,
63,
3742,
63,
1310,
275,
469,
272,
283,
5976,
356,
359,
267,
469,
288,
283,
985,
356,
283,
4129,
63,
1975,
297,
288,
283,
804,
356,
283,
1558,
297,
288,
283,
1110,
356,
283,
4129,
585,
297,
288,
283,
3353,
356,
413,
267,
789,
272,
2156,
272,
283,
3364,
5976,
356,
990,
272,
283,
2364,
5142,
356,
469,
267,
283,
2017,
1304,
356,
283,
25481,
25481,
13,
1082,
1082,
13,
1367,
1367,
13,
23,
14681,
13,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
297,
267,
283,
2856,
23018,
356,
1926,
12,
267,
283,
2856,
9883,
356,
469,
288,
283,
88,
13,
455,
31591,
13,
1069,
344,
356,
283,
25481,
25481,
13,
1082,
1082,
13,
1367,
1367,
13,
23,
14681,
13,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
297,
288,
283,
1317,
13,
466,
356,
283,
3578,
15,
88,
13,
455,
90,
13,
1001,
13,
17,
14,
17,
297,
288,
283,
1317,
13,
1267,
356,
283,
7524,
297,
288,
283,
602,
356,
283,
52,
310,
12,
6546,
17474,
14894,
4119,
26,
966,
26,
1465,
19152,
7,
267,
1660,
267,
283,
12989,
15322,
1086,
356,
378,
272,
789,
199,
93,
199,
199,
515,
63,
3742,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
515,
63,
3742,
63,
1310,
459,
5976,
418,
275,
359,
272,
791,
985,
356,
1994,
396,
515,
15,
7354,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
7354,
297,
283,
3353,
356,
413,
1386,
272,
791,
985,
356,
1994,
396,
515,
15,
87,
265,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
87,
265,
297,
283,
3353,
356,
413,
93,
199,
61,
199,
199,
4752,
63,
1975,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
4752,
63,
1975,
63,
1310,
459,
5976,
418,
275,
942,
199,
4752,
63,
1975,
63,
1310,
459,
3364,
5976,
418,
275,
788,
4752,
63,
1975,
418,
199,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
459,
5976,
418,
275,
359,
272,
791,
985,
356,
283,
4129,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
297,
283,
3353,
356,
413,
1386,
272,
791,
985,
356,
1994,
396,
515,
15,
87,
265,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
87,
265,
297,
283,
3353,
356,
413,
93,
199,
61,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
459,
3364,
5976,
418,
275,
788,
4752,
63,
1975,
418,
421,
199,
5869,
63,
6942,
275,
1052,
199,
5869,
63,
6942,
459,
10914,
63,
2913,
418,
275,
488,
199,
5869,
63,
6942,
459,
7231,
63,
4731,
63,
498,
418,
275,
298,
1397,
482,
3740,
2,
199,
5869,
63,
6942,
459,
7231,
63,
2732,
63,
498,
418,
275,
298,
1397,
65,
498,
2,
199,
5869,
63,
6942,
459,
7231,
63,
4416,
63,
1418,
418,
275,
488,
199,
5869,
63,
6942,
459,
4551,
418,
275,
283,
16913,
13,
19082,
13,
17,
7,
421,
199,
318,
511,
63,
3892,
63,
1975,
8,
27899,
304,
272,
4237,
275,
11488,
63,
385,
77,
14,
7521,
2377,
342,
272,
4237,
423,
912,
63,
354,
275,
298,
7231,
63,
385,
77,
2,
339,
6055,
19,
63,
3157,
275,
15981,
14,
11988,
342,
272,
6055,
19,
63,
3157,
14,
4434,
14,
1107,
63,
585,
14,
1258,
14,
1107,
63,
585,
14,
362,
63,
3214,
14,
1107,
63,
585,
275,
3486,
63,
1975,
63,
3742,
63,
1310,
272,
6055,
19,
63,
1258,
63,
3157,
275,
6055,
19,
63,
3157,
14,
4434,
14,
1107,
63,
585,
14,
1258,
339,
543,
15981,
14,
2068,
14,
785,
8,
10914,
19,
12,
283,
1730,
297,
6055,
19,
63,
3157,
304,
267,
9151,
275,
4237,
14,
1065,
5234,
4129,
63,
1975,
2255,
5479,
1011,
5869,
63,
6942,
9,
272,
702,
8,
18476,
59,
16,
61,
508,
298,
4129,
585,
531,
272,
6055,
19,
63,
1258,
63,
3157,
14,
479,
63,
3527,
63,
1045,
360,
385,
77,
297,
283,
16913,
13,
19082,
13,
17,
297,
11488,
63,
2732,
63,
498,
63,
344,
534,
1397,
65,
498,
297,
5644,
11488,
63,
4731,
63,
2732,
63,
498,
628,
1397,
482,
3740,
401,
11488,
63,
1730,
63,
1418,
29,
403,
9,
421,
199,
318,
511,
63,
515,
63,
3892,
63,
1975,
8,
27899,
304,
272,
4237,
275,
11488,
63,
385
] |
[
199,
3,
334,
67,
9,
9708,
16922,
1487,
7964,
820,
310,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
646,
4613,
199,
504,
1331,
492,
1331,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
199,
504,
3242,
14,
5265,
14,
3892,
492,
11488,
63,
385,
77,
199,
199,
893,
26,
272,
492,
6055,
19,
272,
687,
21199,
14,
3924,
492,
28972,
199,
2590,
3545,
26,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
2765,
511,
5074,
314,
6055,
19,
436,
21199,
2018,
8363,
531,
199,
199,
4129,
63,
1975,
63,
3742,
63,
1310,
275,
469,
272,
283,
5976,
356,
359,
267,
469,
288,
283,
985,
356,
283,
4129,
63,
1975,
297,
288,
283,
804,
356,
283,
1558,
297,
288,
283,
1110,
356,
283,
4129,
585,
297,
288,
283,
3353,
356,
413,
267,
789,
272,
2156,
272,
283,
3364,
5976,
356,
990,
272,
283,
2364,
5142,
356,
469,
267,
283,
2017,
1304,
356,
283,
25481,
25481,
13,
1082,
1082,
13,
1367,
1367,
13,
23,
14681,
13,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
297,
267,
283,
2856,
23018,
356,
1926,
12,
267,
283,
2856,
9883,
356,
469,
288,
283,
88,
13,
455,
31591,
13,
1069,
344,
356,
283,
25481,
25481,
13,
1082,
1082,
13,
1367,
1367,
13,
23,
14681,
13,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
25,
65,
297,
288,
283,
1317,
13,
466,
356,
283,
3578,
15,
88,
13,
455,
90,
13,
1001,
13,
17,
14,
17,
297,
288,
283,
1317,
13,
1267,
356,
283,
7524,
297,
288,
283,
602,
356,
283,
52,
310,
12,
6546,
17474,
14894,
4119,
26,
966,
26,
1465,
19152,
7,
267,
1660,
267,
283,
12989,
15322,
1086,
356,
378,
272,
789,
199,
93,
199,
199,
515,
63,
3742,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
515,
63,
3742,
63,
1310,
459,
5976,
418,
275,
359,
272,
791,
985,
356,
1994,
396,
515,
15,
7354,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
7354,
297,
283,
3353,
356,
413,
1386,
272,
791,
985,
356,
1994,
396,
515,
15,
87,
265,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
87,
265,
297,
283,
3353,
356,
413,
93,
199,
61,
199,
199,
4752,
63,
1975,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
4752,
63,
1975,
63,
1310,
459,
5976,
418,
275,
942,
199,
4752,
63,
1975,
63,
1310,
459,
3364,
5976,
418,
275,
788,
4752,
63,
1975,
418,
199,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
275,
1331,
8,
4129,
63,
1975,
63,
3742,
63,
1310,
9,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
459,
5976,
418,
275,
359,
272,
791,
985,
356,
283,
4129,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
297,
283,
3353,
356,
413,
1386,
272,
791,
985,
356,
1994,
396,
515,
15,
87,
265,
297,
283,
804,
356,
283,
1558,
297,
283,
1110,
356,
283,
4129,
63,
585,
63,
87,
265,
297,
283,
3353,
356,
413,
93,
199,
61,
199,
3972,
63,
4752,
63,
1975,
63,
1310,
459,
3364,
5976,
418,
275,
788,
4752,
63,
1975,
418,
421,
199,
5869,
63,
6942,
275,
1052,
199,
5869,
63,
6942,
459,
10914,
63,
2913,
418,
275,
488,
199,
5869,
63,
6942,
459,
7231,
63,
4731,
63,
498,
418,
275,
298,
1397,
482,
3740,
2,
199,
5869,
63,
6942,
459,
7231,
63,
2732,
63,
498,
418,
275,
298,
1397,
65,
498,
2,
199,
5869,
63,
6942,
459,
7231,
63,
4416,
63,
1418,
418,
275,
488,
199,
5869,
63,
6942,
459,
4551,
418,
275,
283,
16913,
13,
19082,
13,
17,
7,
421,
199,
318,
511,
63,
3892,
63,
1975,
8,
27899,
304,
272,
4237,
275,
11488,
63,
385,
77,
14,
7521,
2377,
342,
272,
4237,
423,
912,
63,
354,
275,
298,
7231,
63,
385,
77,
2,
339,
6055,
19,
63,
3157,
275,
15981,
14,
11988,
342,
272,
6055,
19,
63,
3157,
14,
4434,
14,
1107,
63,
585,
14,
1258,
14,
1107,
63,
585,
14,
362,
63,
3214,
14,
1107,
63,
585,
275,
3486,
63,
1975,
63,
3742,
63,
1310,
272,
6055,
19,
63,
1258,
63,
3157,
275,
6055,
19,
63,
3157,
14,
4434,
14,
1107,
63,
585,
14,
1258,
339,
543,
15981,
14,
2068,
14,
785,
8,
10914,
19,
12,
283,
1730,
297,
6055,
19,
63,
3157,
304,
267,
9151,
275,
4237,
14,
1065,
5234,
4129,
63,
1975,
2255,
5479,
1011,
5869,
63,
6942,
9,
272,
702,
8,
18476,
59,
16,
61,
508,
298,
4129,
585,
531,
272,
6055,
19,
63,
1258,
63,
3157,
14,
479,
63,
3527,
63,
1045,
360,
385,
77,
297,
283,
16913,
13,
19082,
13,
17,
297,
11488,
63,
2732,
63,
498,
63,
344,
534,
1397,
65,
498,
297,
5644,
11488,
63,
4731,
63,
2732,
63,
498,
628,
1397,
482,
3740,
401,
11488,
63,
1730,
63,
1418,
29,
403,
9,
421,
199,
318,
511,
63,
515,
63,
3892,
63,
1975,
8,
27899,
304,
272,
4237,
275,
11488,
63,
385,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mmauroy/SickRage
|
sickbeard/providers/nextgen.py
|
3
|
12149
|
# Author: seedboy
# URL: https://github.com/seedboy
#
# This file is part of SickRage.
#
# SickRage 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.
#
# SickRage 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 SickRage. If not, see <http://www.gnu.org/licenses/>.
import traceback
import urllib
import time
import re
import datetime
import sickbeard
import generic
from sickbeard.common import Quality
from sickbeard import logger
from sickbeard import tvcache
from sickbeard import db
from sickbeard import classes
from sickbeard import helpers
from sickbeard import show_name_helpers
import requests
from sickbeard.bs4_parser import BS4Parser
from sickbeard.helpers import sanitizeSceneName
class NextGenProvider(generic.TorrentProvider):
def __init__(self):
generic.TorrentProvider.__init__(self, "NextGen")
self.supportsBacklog = True
self.enabled = False
self.username = None
self.password = None
self.ratio = None
self.cache = NextGenCache(self)
self.urls = {'base_url': 'https://nxtgn.org/',
'search': 'https://nxtgn.org/browse.php?search=%s&cat=0&incldead=0&modes=%s',
'login_page': 'https://nxtgn.org/login.php',
'detail': 'https://nxtgn.org/details.php?id=%s',
'download': 'https://nxtgn.org/download.php?id=%s',
'takelogin': 'https://nxtgn.org/takelogin.php?csrf=',
}
self.url = self.urls['base_url']
self.categories = '&c7=1&c24=1&c17=1&c22=1&c42=1&c46=1&c26=1&c28=1&c43=1&c4=1&c31=1&c45=1&c33=1'
self.last_login_check = None
self.login_opener = None
def isEnabled(self):
return self.enabled
def imageName(self):
return 'nextgen.png'
def getQuality(self, item, anime=False):
quality = Quality.sceneQuality(item[0], anime)
return quality
def getLoginParams(self):
return {
'username': self.username,
'password': self.password,
}
def loginSuccess(self, output):
if "<title>NextGen - Login</title>" in output:
return False
else:
return True
def _doLogin(self):
now = time.time()
if self.login_opener and self.last_login_check < (now - 3600):
try:
output = self.getURL(self.urls['test'])
if self.loginSuccess(output):
self.last_login_check = now
return True
else:
self.login_opener = None
except:
self.login_opener = None
if self.login_opener:
return True
try:
login_params = self.getLoginParams()
data = self.getURL(self.urls['login_page'])
with BS4Parser(data) as bs:
csrfraw = bs.find('form', attrs={'id': 'login'})['action']
output = self.getURL(self.urls['base_url'] + csrfraw, post_data=login_params)
if self.loginSuccess(output):
self.last_login_check = now
self.login_opener = self.session
return True
error = 'unknown'
except:
error = traceback.format_exc()
self.login_opener = None
self.login_opener = None
logger.log(u'Failed to login:' + str(error), logger.ERROR)
return False
def _get_season_search_strings(self, ep_obj):
search_string = {'Season': []}
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
if ep_obj.show.air_by_date or ep_obj.show.sports:
ep_string = show_name + ' ' + str(ep_obj.airdate).split('-')[0]
elif ep_obj.show.anime:
ep_string = show_name + ' ' + "%d" % ep_obj.scene_absolute_number
else:
ep_string = show_name + ' S%02d' % int(ep_obj.scene_season) #1) showName SXX
search_string['Season'].append(ep_string)
return [search_string]
def _get_episode_search_strings(self, ep_obj, add_string=''):
search_string = {'Episode': []}
if not ep_obj:
return []
if self.show.air_by_date:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(ep_obj.airdate).replace('-', '|')
search_string['Episode'].append(ep_string)
elif self.show.sports:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
str(ep_obj.airdate).replace('-', '|') + '|' + \
ep_obj.airdate.strftime('%b')
search_string['Episode'].append(ep_string)
elif self.show.anime:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
"%i" % int(ep_obj.scene_absolute_number)
search_string['Episode'].append(ep_string)
else:
for show_name in set(show_name_helpers.allPossibleShowNames(self.show)):
ep_string = sanitizeSceneName(show_name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep_obj.scene_season,
'episodenumber': ep_obj.scene_episode} + ' %s' % add_string
search_string['Episode'].append(re.sub(r'\s+', ' ', ep_string))
return [search_string]
def _doSearch(self, search_params, search_mode='eponly', epcount=0, age=0, epObj=None):
results = []
items = {'Season': [], 'Episode': [], 'RSS': []}
if not self._doLogin():
return results
for mode in search_params.keys():
for search_string in search_params[mode]:
searchURL = self.urls['search'] % (urllib.quote(search_string.encode('utf-8')), self.categories)
logger.log(u"" + self.name + " search page URL: " + searchURL, logger.DEBUG)
data = self.getURL(searchURL)
if not data:
continue
try:
with BS4Parser(data.decode('iso-8859-1'), features=["html5lib", "permissive"]) as html:
resultsTable = html.find('div', attrs={'id': 'torrent-table-wrapper'})
if not resultsTable:
logger.log(u"The Data returned from " + self.name + " do not contains any torrent",
logger.DEBUG)
continue
# Collecting entries
entries_std = html.find_all('div', attrs={'id': 'torrent-std'})
entries_sticky = html.find_all('div', attrs={'id': 'torrent-sticky'})
entries = entries_std + entries_sticky
#Xirg STANDARD TORRENTS
#Continue only if one Release is found
if len(entries) > 0:
for result in entries:
try:
torrentName = \
((result.find('div', attrs={'id': 'torrent-udgivelse2-users'})).find('a'))['title']
torrentId = (
((result.find('div', attrs={'id': 'torrent-download'})).find('a'))['href']).replace(
'download.php?id=', '')
torrent_name = str(torrentName)
torrent_download_url = (self.urls['download'] % torrentId).encode('utf8')
torrent_details_url = (self.urls['detail'] % torrentId).encode('utf8')
#torrent_seeders = int(result.find('div', attrs = {'id' : 'torrent-seeders'}).find('a')['class'][0])
## Not used, perhaps in the future ##
#torrent_id = int(torrent['href'].replace('/details.php?id=', ''))
#torrent_leechers = int(result.find('td', attrs = {'class' : 'ac t_leechers'}).string)
except (AttributeError, TypeError):
continue
# Filter unseeded torrent and torrents with no name/url
#if mode != 'RSS' and torrent_seeders == 0:
# continue
if not torrent_name or not torrent_download_url:
continue
item = torrent_name, torrent_download_url
logger.log(u"Found result: " + torrent_name.replace(' ','.') + " (" + torrent_details_url + ")",
logger.DEBUG)
items[mode].append(item)
else:
logger.log(u"The Data returned from " + self.name + " do not contains any torrent",
logger.WARNING)
continue
except Exception, e:
logger.log(u"Failed parsing " + self.name + " Traceback: " + traceback.format_exc(),
logger.ERROR)
results += items[mode]
return results
def _get_title_and_url(self, item):
title, url = item
if title:
title = u'' + title
title = title.replace(' ', '.')
if url:
url = str(url).replace('&', '&')
return title, url
def findPropers(self, search_date=datetime.datetime.today()):
results = []
myDB = db.DBConnection()
sqlResults = myDB.select(
'SELECT s.show_name, e.showid, e.season, e.episode, e.status, e.airdate FROM tv_episodes AS e' +
' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)' +
' WHERE e.airdate >= ' + str(search_date.toordinal()) +
' AND (e.status IN (' + ','.join([str(x) for x in Quality.DOWNLOADED]) + ')' +
' OR (e.status IN (' + ','.join([str(x) for x in Quality.SNATCHED]) + ')))'
)
if not sqlResults:
return []
for sqlshow in sqlResults:
self.show = helpers.findCertainShow(sickbeard.showList, int(sqlshow["showid"]))
if self.show:
curEp = self.show.getEpisode(int(sqlshow["season"]), int(sqlshow["episode"]))
searchString = self._get_episode_search_strings(curEp, add_string='PROPER|REPACK')
for item in self._doSearch(searchString[0]):
title, url = self._get_title_and_url(item)
results.append(classes.Proper(title, url, datetime.datetime.today(), self.show))
return results
def seedRatio(self):
return self.ratio
class NextGenCache(tvcache.TVCache):
def __init__(self, provider):
tvcache.TVCache.__init__(self, provider)
# Only poll NextGen every 10 minutes max
self.minTime = 10
def _getRSSData(self):
search_params = {'RSS': ['']}
return {'entries': self.provider._doSearch(search_params)}
provider = NextGenProvider()
|
gpl-3.0
|
[
3,
6529,
26,
6347,
656,
89,
199,
3,
2851,
26,
4178,
921,
5031,
14,
957,
15,
5176,
656,
89,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28964,
31066,
14,
199,
3,
199,
3,
28964,
31066,
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,
28964,
31066,
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,
221,
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,
28964,
31066,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5190,
199,
646,
4011,
199,
646,
900,
199,
646,
295,
199,
646,
2197,
199,
646,
17898,
199,
646,
7809,
199,
504,
17898,
14,
2330,
492,
24108,
199,
504,
17898,
492,
2512,
199,
504,
17898,
492,
13466,
1637,
199,
504,
17898,
492,
1592,
199,
504,
17898,
492,
3992,
199,
504,
17898,
492,
10897,
199,
504,
17898,
492,
2498,
63,
354,
63,
7546,
199,
646,
4145,
199,
504,
17898,
14,
1533,
20,
63,
2087,
492,
699,
51,
20,
2842,
199,
504,
17898,
14,
7546,
492,
21077,
14216,
985,
421,
199,
533,
16840,
8168,
6663,
8,
6767,
14,
32004,
6663,
304,
339,
347,
636,
826,
721,
277,
304,
398,
7809,
14,
32004,
6663,
855,
826,
721,
277,
12,
298,
5765,
8168,
531,
398,
291,
14,
9823,
4540,
793,
275,
715,
398,
291,
14,
3827,
275,
756,
267,
291,
14,
2473,
275,
488,
267,
291,
14,
2060,
275,
488,
267,
291,
14,
6884,
275,
488,
398,
291,
14,
1637,
275,
16840,
8168,
4437,
8,
277,
9,
398,
291,
14,
3603,
275,
791,
1095,
63,
633,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
3678,
355,
283,
1733,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
4570,
14,
8624,
31,
1733,
2458,
83,
6,
3385,
29,
16,
6,
31941,
10957,
29,
16,
6,
10433,
2458,
83,
297,
355,
283,
2886,
63,
1606,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
2886,
14,
8624,
297,
355,
283,
5506,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
5087,
14,
8624,
31,
344,
2458,
83,
297,
355,
283,
4249,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
4249,
14,
8624,
31,
344,
2458,
83,
297,
355,
283,
11066,
2886,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
11066,
2886,
14,
8624,
31,
10088,
4009,
355,
789,
398,
291,
14,
633,
275,
291,
14,
3603,
459,
1095,
63,
633,
418,
398,
291,
14,
8906,
275,
7673,
67,
23,
29,
17,
6,
67,
1194,
29,
17,
6,
67,
1196,
29,
17,
6,
67,
1081,
29,
17,
6,
67,
2260,
29,
17,
6,
67,
2466,
29,
17,
6,
67,
1479,
29,
17,
6,
67,
1651,
29,
17,
6,
67,
2824,
29,
17,
6,
67,
20,
29,
17,
6,
67,
2192,
29,
17,
6,
67,
2322,
29,
17,
6,
67,
1153,
29,
17,
7,
398,
291,
14,
2019,
63,
2886,
63,
1074,
275,
488,
398,
291,
14,
2886,
63,
11637,
275,
488,
339,
347,
365,
6589,
8,
277,
304,
267,
372,
291,
14,
3827,
339,
347,
1834,
985,
8,
277,
304,
267,
372,
283,
2184,
2268,
14,
4524,
7,
339,
347,
664,
19436,
8,
277,
12,
1242,
12,
376,
1036,
29,
797,
304,
398,
11030,
275,
24108,
14,
10436,
19436,
8,
1053,
59,
16,
467,
376,
1036,
9,
267,
372,
11030,
339,
347,
664,
8880,
6007,
8,
277,
304,
267,
372,
469,
288,
283,
2473,
356,
291,
14,
2473,
12,
288,
283,
2060,
356,
291,
14,
2060,
12,
267,
789,
339,
347,
4676,
8300,
8,
277,
12,
1072,
304,
267,
340,
3886,
1213,
30,
5765,
8168,
446,
16430,
1108,
1213,
4335,
315,
1072,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
347,
485,
1117,
8880,
8,
277,
304,
398,
3063,
275,
900,
14,
521,
342,
267,
340,
291,
14,
2886,
63,
11637,
436,
291,
14,
2019,
63,
2886,
63,
1074,
665,
334,
2131,
446,
15751,
304,
288,
862,
26,
355,
1072,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
396,
1105,
355,
340,
291,
14,
2886,
8300,
8,
1199,
304,
490,
291,
14,
2019,
63,
2886,
63,
1074,
275,
3063,
490,
372,
715,
355,
587,
26,
490,
291,
14,
2886,
63,
11637,
275,
488,
288,
871,
26,
355,
291,
14,
2886,
63,
11637,
275,
488,
398,
340,
291,
14,
2886,
63,
11637,
26,
288,
372,
715,
398,
862,
26,
288,
4676,
63,
1162,
275,
291,
14,
362,
8880,
6007,
342,
288,
666,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
2886,
63,
1606,
1105,
288,
543,
699,
51,
20,
2842,
8,
576,
9,
465,
9922,
26,
355,
19213,
1773,
275,
9922,
14,
1623,
360,
964,
297,
3290,
3713,
344,
356,
283,
2886,
3071,
459,
1287,
418,
355,
1072,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
1095,
63,
633,
418,
435,
19213,
1773,
12,
2963,
63,
576,
29,
2886,
63,
1162,
9,
2234,
340,
291,
14,
2886,
8300,
8,
1199,
304,
490,
291,
14,
2019,
63,
2886,
63,
1074,
275,
3063,
490,
291,
14,
2886,
63,
11637,
275,
291,
14,
1730,
490,
372,
715,
2234,
1125,
275,
283,
5187,
7,
267,
871,
26,
288,
1125,
275,
5190,
14,
908,
63,
2804,
342,
288,
291,
14,
2886,
63,
11637,
275,
488,
398,
291,
14,
2886,
63,
11637,
275,
488,
267,
2512,
14,
793,
8,
85,
7,
4276,
370,
4676,
4881,
435,
620,
8,
705,
395,
2512,
14,
3170,
9,
267,
372,
756,
339,
347,
485,
362,
63,
12605,
63,
1733,
63,
5465,
8,
277,
12,
5442,
63,
1113,
304,
398,
2754,
63,
875,
275,
791,
28905,
356,
23455,
267,
367,
2498
] |
[
6529,
26,
6347,
656,
89,
199,
3,
2851,
26,
4178,
921,
5031,
14,
957,
15,
5176,
656,
89,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28964,
31066,
14,
199,
3,
199,
3,
28964,
31066,
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,
28964,
31066,
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,
221,
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,
28964,
31066,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5190,
199,
646,
4011,
199,
646,
900,
199,
646,
295,
199,
646,
2197,
199,
646,
17898,
199,
646,
7809,
199,
504,
17898,
14,
2330,
492,
24108,
199,
504,
17898,
492,
2512,
199,
504,
17898,
492,
13466,
1637,
199,
504,
17898,
492,
1592,
199,
504,
17898,
492,
3992,
199,
504,
17898,
492,
10897,
199,
504,
17898,
492,
2498,
63,
354,
63,
7546,
199,
646,
4145,
199,
504,
17898,
14,
1533,
20,
63,
2087,
492,
699,
51,
20,
2842,
199,
504,
17898,
14,
7546,
492,
21077,
14216,
985,
421,
199,
533,
16840,
8168,
6663,
8,
6767,
14,
32004,
6663,
304,
339,
347,
636,
826,
721,
277,
304,
398,
7809,
14,
32004,
6663,
855,
826,
721,
277,
12,
298,
5765,
8168,
531,
398,
291,
14,
9823,
4540,
793,
275,
715,
398,
291,
14,
3827,
275,
756,
267,
291,
14,
2473,
275,
488,
267,
291,
14,
2060,
275,
488,
267,
291,
14,
6884,
275,
488,
398,
291,
14,
1637,
275,
16840,
8168,
4437,
8,
277,
9,
398,
291,
14,
3603,
275,
791,
1095,
63,
633,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
3678,
355,
283,
1733,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
4570,
14,
8624,
31,
1733,
2458,
83,
6,
3385,
29,
16,
6,
31941,
10957,
29,
16,
6,
10433,
2458,
83,
297,
355,
283,
2886,
63,
1606,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
2886,
14,
8624,
297,
355,
283,
5506,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
5087,
14,
8624,
31,
344,
2458,
83,
297,
355,
283,
4249,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
4249,
14,
8624,
31,
344,
2458,
83,
297,
355,
283,
11066,
2886,
356,
283,
2859,
921,
78,
400,
784,
14,
1308,
15,
11066,
2886,
14,
8624,
31,
10088,
4009,
355,
789,
398,
291,
14,
633,
275,
291,
14,
3603,
459,
1095,
63,
633,
418,
398,
291,
14,
8906,
275,
7673,
67,
23,
29,
17,
6,
67,
1194,
29,
17,
6,
67,
1196,
29,
17,
6,
67,
1081,
29,
17,
6,
67,
2260,
29,
17,
6,
67,
2466,
29,
17,
6,
67,
1479,
29,
17,
6,
67,
1651,
29,
17,
6,
67,
2824,
29,
17,
6,
67,
20,
29,
17,
6,
67,
2192,
29,
17,
6,
67,
2322,
29,
17,
6,
67,
1153,
29,
17,
7,
398,
291,
14,
2019,
63,
2886,
63,
1074,
275,
488,
398,
291,
14,
2886,
63,
11637,
275,
488,
339,
347,
365,
6589,
8,
277,
304,
267,
372,
291,
14,
3827,
339,
347,
1834,
985,
8,
277,
304,
267,
372,
283,
2184,
2268,
14,
4524,
7,
339,
347,
664,
19436,
8,
277,
12,
1242,
12,
376,
1036,
29,
797,
304,
398,
11030,
275,
24108,
14,
10436,
19436,
8,
1053,
59,
16,
467,
376,
1036,
9,
267,
372,
11030,
339,
347,
664,
8880,
6007,
8,
277,
304,
267,
372,
469,
288,
283,
2473,
356,
291,
14,
2473,
12,
288,
283,
2060,
356,
291,
14,
2060,
12,
267,
789,
339,
347,
4676,
8300,
8,
277,
12,
1072,
304,
267,
340,
3886,
1213,
30,
5765,
8168,
446,
16430,
1108,
1213,
4335,
315,
1072,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
347,
485,
1117,
8880,
8,
277,
304,
398,
3063,
275,
900,
14,
521,
342,
267,
340,
291,
14,
2886,
63,
11637,
436,
291,
14,
2019,
63,
2886,
63,
1074,
665,
334,
2131,
446,
15751,
304,
288,
862,
26,
355,
1072,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
396,
1105,
355,
340,
291,
14,
2886,
8300,
8,
1199,
304,
490,
291,
14,
2019,
63,
2886,
63,
1074,
275,
3063,
490,
372,
715,
355,
587,
26,
490,
291,
14,
2886,
63,
11637,
275,
488,
288,
871,
26,
355,
291,
14,
2886,
63,
11637,
275,
488,
398,
340,
291,
14,
2886,
63,
11637,
26,
288,
372,
715,
398,
862,
26,
288,
4676,
63,
1162,
275,
291,
14,
362,
8880,
6007,
342,
288,
666,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
2886,
63,
1606,
1105,
288,
543,
699,
51,
20,
2842,
8,
576,
9,
465,
9922,
26,
355,
19213,
1773,
275,
9922,
14,
1623,
360,
964,
297,
3290,
3713,
344,
356,
283,
2886,
3071,
459,
1287,
418,
355,
1072,
275,
291,
14,
362,
2632,
8,
277,
14,
3603,
459,
1095,
63,
633,
418,
435,
19213,
1773,
12,
2963,
63,
576,
29,
2886,
63,
1162,
9,
2234,
340,
291,
14,
2886,
8300,
8,
1199,
304,
490,
291,
14,
2019,
63,
2886,
63,
1074,
275,
3063,
490,
291,
14,
2886,
63,
11637,
275,
291,
14,
1730,
490,
372,
715,
2234,
1125,
275,
283,
5187,
7,
267,
871,
26,
288,
1125,
275,
5190,
14,
908,
63,
2804,
342,
288,
291,
14,
2886,
63,
11637,
275,
488,
398,
291,
14,
2886,
63,
11637,
275,
488,
267,
2512,
14,
793,
8,
85,
7,
4276,
370,
4676,
4881,
435,
620,
8,
705,
395,
2512,
14,
3170,
9,
267,
372,
756,
339,
347,
485,
362,
63,
12605,
63,
1733,
63,
5465,
8,
277,
12,
5442,
63,
1113,
304,
398,
2754,
63,
875,
275,
791,
28905,
356,
23455,
267,
367,
2498,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BillKeenan/lets-encrypt-preview
|
acme/acme/crypto_util_test.py
|
12
|
3544
|
"""Tests for acme.crypto_util."""
import socket
import threading
import time
import unittest
from six.moves import socketserver # pylint: disable=import-error
from acme import errors
from acme import jose
from acme import test_util
class SSLSocketAndProbeSNITest(unittest.TestCase):
"""Tests for acme.crypto_util.SSLSocket/probe_sni."""
def setUp(self):
self.cert = test_util.load_cert('cert.pem')
key = test_util.load_pyopenssl_private_key('rsa512_key.pem')
# pylint: disable=protected-access
certs = {b'foo': (key, self.cert._wrapped)}
from acme.crypto_util import SSLSocket
class _TestServer(socketserver.TCPServer):
# pylint: disable=too-few-public-methods
# six.moves.* | pylint: disable=attribute-defined-outside-init,no-init
def server_bind(self): # pylint: disable=missing-docstring
self.socket = SSLSocket(socket.socket(), certs=certs)
socketserver.TCPServer.server_bind(self)
self.server = _TestServer(('', 0), socketserver.BaseRequestHandler)
self.port = self.server.socket.getsockname()[1]
self.server_thread = threading.Thread(
# pylint: disable=no-member
target=self.server.handle_request)
self.server_thread.start()
time.sleep(1) # TODO: avoid race conditions in other way
def tearDown(self):
self.server_thread.join()
def _probe(self, name):
from acme.crypto_util import probe_sni
return jose.ComparableX509(probe_sni(
name, host='127.0.0.1', port=self.port))
def test_probe_ok(self):
self.assertEqual(self.cert, self._probe(b'foo'))
def test_probe_not_recognized_name(self):
self.assertRaises(errors.Error, self._probe, b'bar')
# TODO: py33/py34 tox hangs forever on do_hendshake in second probe
#def probe_connection_error(self):
# self._probe(b'foo')
# #time.sleep(1) # TODO: avoid race conditions in other way
# self.assertRaises(errors.Error, self._probe, b'bar')
class PyOpenSSLCertOrReqSANTest(unittest.TestCase):
"""Test for acme.crypto_util._pyopenssl_cert_or_req_san."""
@classmethod
def _call(cls, loader, name):
# pylint: disable=protected-access
from acme.crypto_util import _pyopenssl_cert_or_req_san
return _pyopenssl_cert_or_req_san(loader(name))
def _call_cert(self, name):
return self._call(test_util.load_cert, name)
def _call_csr(self, name):
return self._call(test_util.load_csr, name)
def test_cert_no_sans(self):
self.assertEqual(self._call_cert('cert.pem'), [])
def test_cert_two_sans(self):
self.assertEqual(self._call_cert('cert-san.pem'),
['example.com', 'www.example.com'])
def test_csr_no_sans(self):
self.assertEqual(self._call_csr('csr-nosans.pem'), [])
def test_csr_one_san(self):
self.assertEqual(self._call_csr('csr.pem'), ['example.com'])
def test_csr_two_sans(self):
self.assertEqual(self._call_csr('csr-san.pem'),
['example.com', 'www.example.com'])
def test_csr_six_sans(self):
self.assertEqual(self._call_csr('csr-6sans.pem'),
["example.com", "example.org", "example.net",
"example.info", "subdomain.example.com",
"other.subdomain.example.com"])
if __name__ == "__main__":
unittest.main() # pragma: no cover
|
apache-2.0
|
[
624,
2925,
367,
32433,
14,
10316,
63,
1974,
1041,
199,
646,
2838,
199,
646,
5796,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
3816,
14,
4912,
492,
2838,
1000,
221,
327,
4287,
26,
3507,
29,
646,
13,
705,
199,
199,
504,
32433,
492,
2552,
199,
504,
32433,
492,
5225,
261,
199,
504,
32433,
492,
511,
63,
1974,
421,
199,
533,
7799,
3869,
3325,
16939,
8199,
649,
597,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
10316,
63,
1974,
14,
5413,
3869,
15,
15944,
63,
5167,
73,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4736,
275,
511,
63,
1974,
14,
912,
63,
4736,
360,
4736,
14,
13102,
358,
267,
790,
275,
511,
63,
1974,
14,
912,
63,
647,
14837,
63,
4239,
63,
498,
360,
13487,
7736,
63,
498,
14,
13102,
358,
267,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
25949,
275,
469,
66,
7,
1421,
356,
334,
498,
12,
291,
14,
4736,
423,
9130,
6769,
398,
687,
32433,
14,
10316,
63,
1974,
492,
7799,
3869,
398,
1021,
485,
774,
3120,
8,
3450,
1000,
14,
9735,
3120,
304,
953,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
288,
327,
3816,
14,
4912,
2795,
1204,
4287,
26,
3507,
29,
3215,
13,
4037,
13,
22431,
13,
826,
12,
889,
13,
826,
953,
347,
1654,
63,
3409,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
355,
291,
14,
3450,
275,
7799,
3869,
8,
3450,
14,
3450,
1062,
25949,
29,
8356,
9,
355,
2838,
1000,
14,
9735,
3120,
14,
1000,
63,
3409,
8,
277,
9,
398,
291,
14,
1000,
275,
485,
774,
3120,
4725,
297,
378,
395,
2838,
1000,
14,
1563,
11149,
9,
267,
291,
14,
719,
275,
291,
14,
1000,
14,
3450,
14,
27886,
3430,
17,
61,
267,
291,
14,
1000,
63,
2671,
275,
5796,
14,
4436,
8,
288,
327,
4287,
26,
3507,
29,
889,
13,
1114,
288,
1347,
29,
277,
14,
1000,
14,
2479,
63,
1069,
9,
267,
291,
14,
1000,
63,
2671,
14,
928,
342,
267,
900,
14,
4532,
8,
17,
9,
221,
327,
3254,
26,
5126,
21209,
3704,
315,
1163,
4340,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1000,
63,
2671,
14,
904,
342,
339,
347,
485,
15944,
8,
277,
12,
536,
304,
267,
687,
32433,
14,
10316,
63,
1974,
492,
22362,
63,
5167,
73,
267,
372,
5225,
261,
14,
2404,
19816,
56,
6576,
8,
15944,
63,
5167,
73,
8,
288,
536,
12,
1591,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
277,
14,
719,
430,
339,
347,
511,
63,
15944,
63,
745,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
4736,
12,
291,
423,
15944,
8,
66,
7,
1421,
1333,
339,
347,
511,
63,
15944,
63,
1397,
63,
13221,
63,
354,
8,
277,
304,
267,
291,
14,
1855,
8,
2550,
14,
547,
12,
291,
423,
15944,
12,
330,
7,
1700,
358,
339,
327,
3254,
26,
1134,
1153,
15,
647,
1082,
370,
88,
394,
20068,
28688,
641,
886,
63,
72,
500,
7228,
315,
3499,
22362,
272,
327,
318,
22362,
63,
2105,
63,
705,
8,
277,
304,
272,
327,
259,
291,
423,
15944,
8,
66,
7,
1421,
358,
272,
327,
259,
327,
521,
14,
4532,
8,
17,
9,
221,
327,
3254,
26,
5126,
21209,
3704,
315,
1163,
4340,
272,
327,
259,
291,
14,
1855,
8,
2550,
14,
547,
12,
291,
423,
15944,
12,
330,
7,
1700,
358,
421,
199,
533,
1611,
22791,
14768,
2844,
11981,
51,
879,
774,
8,
2796,
14,
1746,
304,
272,
408,
774,
367,
32433,
14,
10316,
63,
1974,
423,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
1041,
339,
768,
3744,
272,
347,
485,
1250,
8,
1886,
12,
5077,
12,
536,
304,
267,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
687,
32433,
14,
10316,
63,
1974,
492,
485,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
267,
372,
485,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
8,
3422,
8,
354,
430,
339,
347,
485,
1250,
63,
4736,
8,
277,
12,
536,
304,
267,
372,
291,
423,
1250,
8,
396,
63,
1974,
14,
912,
63,
4736,
12,
536,
9,
339,
347,
485,
1250,
63,
10101,
8,
277,
12,
536,
304,
267,
372,
291,
423,
1250,
8,
396,
63,
1974,
14,
912,
63,
10101,
12,
536,
9,
339,
347,
511,
63,
4736,
63,
889,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
4736,
360,
4736,
14,
13102,
659,
3073,
339,
347,
511,
63,
4736,
63,
5601,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
4736,
360,
4736,
13,
18904,
14,
13102,
659,
586,
788,
2694,
14,
957,
297,
283,
1544,
14,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
889,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
12712,
796,
14,
13102,
659,
3073,
339,
347,
511,
63,
10101,
63,
368,
63,
18904,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
14,
13102,
659,
788,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
5601,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
18904,
14,
13102,
659,
586,
788,
2694,
14,
957,
297,
283,
1544,
14,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
4174,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
22,
26052,
14,
13102,
659,
586,
2097,
2694,
14,
957,
401,
298,
2694,
14,
1308,
401,
298,
2694,
14,
846,
401,
2079,
298,
2694,
14,
815,
401,
298,
22806,
14,
2694,
14,
957,
401,
2079,
298,
1848,
14,
22806,
14,
2694,
14,
957,
3135,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
32433,
14,
10316,
63,
1974,
1041,
199,
646,
2838,
199,
646,
5796,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
3816,
14,
4912,
492,
2838,
1000,
221,
327,
4287,
26,
3507,
29,
646,
13,
705,
199,
199,
504,
32433,
492,
2552,
199,
504,
32433,
492,
5225,
261,
199,
504,
32433,
492,
511,
63,
1974,
421,
199,
533,
7799,
3869,
3325,
16939,
8199,
649,
597,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
10316,
63,
1974,
14,
5413,
3869,
15,
15944,
63,
5167,
73,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4736,
275,
511,
63,
1974,
14,
912,
63,
4736,
360,
4736,
14,
13102,
358,
267,
790,
275,
511,
63,
1974,
14,
912,
63,
647,
14837,
63,
4239,
63,
498,
360,
13487,
7736,
63,
498,
14,
13102,
358,
267,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
25949,
275,
469,
66,
7,
1421,
356,
334,
498,
12,
291,
14,
4736,
423,
9130,
6769,
398,
687,
32433,
14,
10316,
63,
1974,
492,
7799,
3869,
398,
1021,
485,
774,
3120,
8,
3450,
1000,
14,
9735,
3120,
304,
953,
327,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
288,
327,
3816,
14,
4912,
2795,
1204,
4287,
26,
3507,
29,
3215,
13,
4037,
13,
22431,
13,
826,
12,
889,
13,
826,
953,
347,
1654,
63,
3409,
8,
277,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
355,
291,
14,
3450,
275,
7799,
3869,
8,
3450,
14,
3450,
1062,
25949,
29,
8356,
9,
355,
2838,
1000,
14,
9735,
3120,
14,
1000,
63,
3409,
8,
277,
9,
398,
291,
14,
1000,
275,
485,
774,
3120,
4725,
297,
378,
395,
2838,
1000,
14,
1563,
11149,
9,
267,
291,
14,
719,
275,
291,
14,
1000,
14,
3450,
14,
27886,
3430,
17,
61,
267,
291,
14,
1000,
63,
2671,
275,
5796,
14,
4436,
8,
288,
327,
4287,
26,
3507,
29,
889,
13,
1114,
288,
1347,
29,
277,
14,
1000,
14,
2479,
63,
1069,
9,
267,
291,
14,
1000,
63,
2671,
14,
928,
342,
267,
900,
14,
4532,
8,
17,
9,
221,
327,
3254,
26,
5126,
21209,
3704,
315,
1163,
4340,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1000,
63,
2671,
14,
904,
342,
339,
347,
485,
15944,
8,
277,
12,
536,
304,
267,
687,
32433,
14,
10316,
63,
1974,
492,
22362,
63,
5167,
73,
267,
372,
5225,
261,
14,
2404,
19816,
56,
6576,
8,
15944,
63,
5167,
73,
8,
288,
536,
12,
1591,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1844,
29,
277,
14,
719,
430,
339,
347,
511,
63,
15944,
63,
745,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
4736,
12,
291,
423,
15944,
8,
66,
7,
1421,
1333,
339,
347,
511,
63,
15944,
63,
1397,
63,
13221,
63,
354,
8,
277,
304,
267,
291,
14,
1855,
8,
2550,
14,
547,
12,
291,
423,
15944,
12,
330,
7,
1700,
358,
339,
327,
3254,
26,
1134,
1153,
15,
647,
1082,
370,
88,
394,
20068,
28688,
641,
886,
63,
72,
500,
7228,
315,
3499,
22362,
272,
327,
318,
22362,
63,
2105,
63,
705,
8,
277,
304,
272,
327,
259,
291,
423,
15944,
8,
66,
7,
1421,
358,
272,
327,
259,
327,
521,
14,
4532,
8,
17,
9,
221,
327,
3254,
26,
5126,
21209,
3704,
315,
1163,
4340,
272,
327,
259,
291,
14,
1855,
8,
2550,
14,
547,
12,
291,
423,
15944,
12,
330,
7,
1700,
358,
421,
199,
533,
1611,
22791,
14768,
2844,
11981,
51,
879,
774,
8,
2796,
14,
1746,
304,
272,
408,
774,
367,
32433,
14,
10316,
63,
1974,
423,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
1041,
339,
768,
3744,
272,
347,
485,
1250,
8,
1886,
12,
5077,
12,
536,
304,
267,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
267,
687,
32433,
14,
10316,
63,
1974,
492,
485,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
267,
372,
485,
647,
14837,
63,
4736,
63,
269,
63,
2103,
63,
18904,
8,
3422,
8,
354,
430,
339,
347,
485,
1250,
63,
4736,
8,
277,
12,
536,
304,
267,
372,
291,
423,
1250,
8,
396,
63,
1974,
14,
912,
63,
4736,
12,
536,
9,
339,
347,
485,
1250,
63,
10101,
8,
277,
12,
536,
304,
267,
372,
291,
423,
1250,
8,
396,
63,
1974,
14,
912,
63,
10101,
12,
536,
9,
339,
347,
511,
63,
4736,
63,
889,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
4736,
360,
4736,
14,
13102,
659,
3073,
339,
347,
511,
63,
4736,
63,
5601,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
4736,
360,
4736,
13,
18904,
14,
13102,
659,
586,
788,
2694,
14,
957,
297,
283,
1544,
14,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
889,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
12712,
796,
14,
13102,
659,
3073,
339,
347,
511,
63,
10101,
63,
368,
63,
18904,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
14,
13102,
659,
788,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
5601,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
18904,
14,
13102,
659,
586,
788,
2694,
14,
957,
297,
283,
1544,
14,
2694,
14,
957,
1105,
339,
347,
511,
63,
10101,
63,
4174,
63,
26052,
8,
277,
304,
267,
291,
14,
629,
8,
277,
423,
1250,
63,
10101,
360,
10101,
13,
22,
26052,
14,
13102,
659,
586,
2097,
2694,
14,
957,
401,
298,
2694,
14,
1308,
401,
298,
2694,
14,
846,
401,
2079,
298,
2694,
14,
815,
401,
298,
22806,
14,
2694,
14,
957,
401,
2079,
298,
1848,
14,
22806,
14,
2694,
14,
957,
3135,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manuelli/director
|
src/python/director/raycastdriver.py
|
5
|
1123
|
import drc as lcmdrc
import bot_core as lcmbotcore
from director import lcmUtils
from director import affordanceurdf
class RaycastDriver(object):
def __init__(self, request_channel='TERRAIN_RAYCAST_REQUEST'):
self.request_channel = request_channel
def requestRaycast(self, affordances, lb=[-2,-2], ub=[2,2], step=0.02):
urdfStr = affordanceurdf.urdfStringFromAffordances(affordances)
msg = lcmdrc.terrain_raycast_request_t()
msg.urdf = lcmbotcore.robot_urdf_t()
msg.urdf.robot_name = "collision_environment"
msg.urdf.urdf_xml_string = urdfStr
msg.x_min = lb[0]
msg.x_step = step
msg.x_max = ub[0]
msg.y_min = lb[1]
msg.y_step = step
msg.y_max = ub[1]
max_height = None
for aff in affordances:
bounds = aff.actor.GetBounds()
zmax = bounds[-1]
max_height = max(max_height, zmax)
if max_height is not None:
msg.scanner_height = 10 + max_height
else:
msg.scanner_height = 10
lcmUtils.publish(self.request_channel, msg)
|
bsd-3-clause
|
[
646,
366,
1195,
465,
634,
1760,
1195,
199,
646,
5888,
63,
1018,
465,
16093,
887,
357,
1018,
199,
504,
487,
14521,
492,
634,
4400,
7535,
199,
504,
487,
14521,
492,
15871,
18090,
554,
300,
1587,
421,
199,
533,
30703,
2931,
6158,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1056,
63,
2775,
534,
1157,
21715,
63,
2847,
57,
18898,
63,
6780,
735,
267,
291,
14,
1069,
63,
2775,
275,
1056,
63,
2775,
339,
347,
1056,
25474,
2931,
8,
277,
12,
15871,
18090,
13236,
12,
11104,
1524,
13,
18,
3057,
18,
467,
23730,
1524,
18,
12,
18,
467,
3650,
29,
16,
14,
996,
304,
267,
7629,
1587,
2848,
275,
15871,
18090,
554,
300,
1587,
14,
300,
1587,
1558,
2532,
14799,
18090,
13236,
8,
2756,
18090,
13236,
9,
267,
1499,
275,
634,
1760,
1195,
14,
351,
6322,
63,
803,
2931,
63,
1069,
63,
84,
342,
267,
1499,
14,
300,
1587,
275,
16093,
887,
357,
1018,
14,
9751,
63,
300,
1587,
63,
84,
342,
267,
1499,
14,
300,
1587,
14,
9751,
63,
354,
275,
298,
761,
23656,
63,
5418,
2,
267,
1499,
14,
300,
1587,
14,
300,
1587,
63,
1652,
63,
875,
275,
7629,
1587,
2848,
267,
1499,
14,
88,
63,
827,
275,
11104,
59,
16,
61,
267,
1499,
14,
88,
63,
2926,
275,
3650,
267,
1499,
14,
88,
63,
988,
275,
23730,
59,
16,
61,
267,
1499,
14,
89,
63,
827,
275,
11104,
59,
17,
61,
267,
1499,
14,
89,
63,
2926,
275,
3650,
267,
1499,
14,
89,
63,
988,
275,
23730,
59,
17,
61,
398,
1390,
63,
3333,
275,
488,
267,
367,
9876,
315,
15871,
18090,
13236,
26,
288,
10461,
275,
9876,
14,
5021,
14,
1002,
23557,
342,
288,
1315,
988,
275,
10461,
1988,
17,
61,
288,
1390,
63,
3333,
275,
1390,
8,
988,
63,
3333,
12,
1315,
988,
9,
267,
340,
1390,
63,
3333,
365,
440,
488,
26,
288,
1499,
14,
16378,
63,
3333,
275,
1616,
435,
1390,
63,
3333,
267,
587,
26,
288,
1499,
14,
16378,
63,
3333,
275,
1616,
267,
634,
4400,
7535,
14,
4763,
8,
277,
14,
1069,
63,
2775,
12,
1499,
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
] |
[
366,
1195,
465,
634,
1760,
1195,
199,
646,
5888,
63,
1018,
465,
16093,
887,
357,
1018,
199,
504,
487,
14521,
492,
634,
4400,
7535,
199,
504,
487,
14521,
492,
15871,
18090,
554,
300,
1587,
421,
199,
533,
30703,
2931,
6158,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1056,
63,
2775,
534,
1157,
21715,
63,
2847,
57,
18898,
63,
6780,
735,
267,
291,
14,
1069,
63,
2775,
275,
1056,
63,
2775,
339,
347,
1056,
25474,
2931,
8,
277,
12,
15871,
18090,
13236,
12,
11104,
1524,
13,
18,
3057,
18,
467,
23730,
1524,
18,
12,
18,
467,
3650,
29,
16,
14,
996,
304,
267,
7629,
1587,
2848,
275,
15871,
18090,
554,
300,
1587,
14,
300,
1587,
1558,
2532,
14799,
18090,
13236,
8,
2756,
18090,
13236,
9,
267,
1499,
275,
634,
1760,
1195,
14,
351,
6322,
63,
803,
2931,
63,
1069,
63,
84,
342,
267,
1499,
14,
300,
1587,
275,
16093,
887,
357,
1018,
14,
9751,
63,
300,
1587,
63,
84,
342,
267,
1499,
14,
300,
1587,
14,
9751,
63,
354,
275,
298,
761,
23656,
63,
5418,
2,
267,
1499,
14,
300,
1587,
14,
300,
1587,
63,
1652,
63,
875,
275,
7629,
1587,
2848,
267,
1499,
14,
88,
63,
827,
275,
11104,
59,
16,
61,
267,
1499,
14,
88,
63,
2926,
275,
3650,
267,
1499,
14,
88,
63,
988,
275,
23730,
59,
16,
61,
267,
1499,
14,
89,
63,
827,
275,
11104,
59,
17,
61,
267,
1499,
14,
89,
63,
2926,
275,
3650,
267,
1499,
14,
89,
63,
988,
275,
23730,
59,
17,
61,
398,
1390,
63,
3333,
275,
488,
267,
367,
9876,
315,
15871,
18090,
13236,
26,
288,
10461,
275,
9876,
14,
5021,
14,
1002,
23557,
342,
288,
1315,
988,
275,
10461,
1988,
17,
61,
288,
1390,
63,
3333,
275,
1390,
8,
988,
63,
3333,
12,
1315,
988,
9,
267,
340,
1390,
63,
3333,
365,
440,
488,
26,
288,
1499,
14,
16378,
63,
3333,
275,
1616,
435,
1390,
63,
3333,
267,
587,
26,
288,
1499,
14,
16378,
63,
3333,
275,
1616,
267,
634,
4400,
7535,
14,
4763,
8,
277,
14,
1069,
63,
2775,
12,
1499,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
noironetworks/group-based-policy
|
gbpservice/contrib/tests/unit/nfp/configurator/agents/test_generic_config.py
|
1
|
12961
|
# 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 subprocess
from unittest import mock
import unittest2
from neutron.tests import base
from gbpservice.contrib.nfp.configurator.agents import generic_config as gc
from gbpservice.contrib.nfp.configurator.lib import (
generic_config_constants as const)
from gbpservice.contrib.nfp.configurator.lib import constants as common_const
from gbpservice.contrib.tests.unit.nfp.configurator.test_data import (
fw_test_data as fo)
class GenericConfigRpcManagerTestCase(base.BaseTestCase):
""" Implement test cases for RPC manager methods of generic config agent.
"""
def __init__(self, *args, **kwargs):
super(GenericConfigRpcManagerTestCase, self).__init__(
*args, **kwargs)
self.fo = fo.FakeObjects()
@mock.patch(__name__ + '.fo.FakeObjects.sc')
@mock.patch(__name__ + '.fo.FakeObjects.conf')
def _get_GenericConfigRpcManager_object(self, conf, sc):
""" Retrieves RPC manager object of generic config agent.
:param sc: mocked service controller object of process model framework
:param conf: mocked OSLO configuration file
Returns: object of generic config's RPC manager
and service controller.
"""
agent = gc.GenericConfigRpcManager(sc, conf)
return agent, sc
def _test_event_creation(self, method):
""" Tests event creation and enqueueing for create/delete
operation of generic config agent's RPC manager.
:param method: CONFIGURE_INTERFACES/CLEAR_INTERFACES/
CONFIGURE_ROUTES/CLEAR_ROUTES
Returns: none
"""
agent, sc = self._get_GenericConfigRpcManager_object()
arg_dict = {'context': self.fo.context,
'resource_data': self.fo._fake_resource_data()}
with mock.patch.object(
sc, 'new_event', return_value='foo') as mock_sc_event, (
mock.patch.object(sc, 'post_event')) as mock_sc_rpc_event:
call_method = getattr(agent, method.lower())
call_method(self.fo.context, self.fo._fake_resource_data())
if 'HEALTHMONITOR' in method:
mock_sc_event.assert_called_with(id=method,
data=arg_dict,
key=self.fo.vmid)
else:
mock_sc_event.assert_called_with(id=method,
data=arg_dict, key=None)
mock_sc_rpc_event.assert_called_with('foo')
def test_configure_interfaces_genericconfigrpcmanager(self):
""" Implements test case for configure interfaces method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CONFIGURE_INTERFACES)
def test_clear_interfaces_genericconfigrpcmanager(self):
""" Implements test case for clear interfaces method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CLEAR_INTERFACES)
def test_configure_routes_genericconfigrpcmanager(self):
""" Implements test case for configure routes method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CONFIGURE_ROUTES)
def test_clear_routes_genericconfigrpcmanager(self):
""" Implements test case for clear routes method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CLEAR_ROUTES)
def test_configure_hm_genericconfigrpcmanager(self):
""" Implements test case for configure healthmonitor method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CONFIGURE_HEALTHMONITOR)
@unittest2.skip('not implemented yet')
def test_clear_hm_genericconfigrpcmanager(self):
""" Implements test case for clear healthmonitor method
of generic config agent RPCmanager.
Returns: none
"""
self._test_event_creation(const.EVENT_CLEAR_HEALTHMONITOR)
class GenericConfigEventHandlerTestCase(base.BaseTestCase):
""" Implements test cases for event handler methods
of generic config agent.
"""
def __init__(self, *args, **kwargs):
super(GenericConfigEventHandlerTestCase, self).__init__(
*args, **kwargs)
self.fo = fo.FakeObjects()
self.empty = self.fo.empty_dict
self.context = {'notification_data': {},
'resource': 'interfaces'}
@mock.patch(__name__ + '.fo.FakeObjects.rpcmgr')
@mock.patch(__name__ + '.fo.FakeObjects.drivers')
@mock.patch(__name__ + '.fo.FakeObjects.sc')
def _get_GenericConfigEventHandler_object(self, sc, drivers, rpcmgr):
""" Retrieves event handler object of generic config.
:param sc: mocked service controller object of process model framework
:param rpcmgr: object of configurator's RPC manager
:param drivers: list of driver objects for firewall agent
Returns: object of generic config's event handler
"""
agent = gc.GenericConfigEventHandler(sc, drivers, rpcmgr)
return agent, sc
def _test_handle_event(self, ev):
""" Test handle event method of generic config agent for various
device configuration operations.
:param ev: fake event data which has to be actually sent by
process framework.
Returns: None
"""
agent, sc = self._get_GenericConfigEventHandler_object()
driver = mock.Mock()
with mock.patch.object(
driver, const.EVENT_CONFIGURE_INTERFACES.lower(),
return_value=common_const.SUCCESS) as (mock_config_inte), (
mock.patch.object(
driver, const.EVENT_CLEAR_INTERFACES.lower(),
return_value=common_const.SUCCESS)) as (mock_clear_inte), (
mock.patch.object(
driver, const.EVENT_CONFIGURE_ROUTES.lower(),
return_value=common_const.SUCCESS)) as (
mock_config_src_routes), (
mock.patch.object(
driver, const.EVENT_CLEAR_ROUTES.lower(),
return_value=common_const.SUCCESS)) as (
mock_delete_src_routes), (
mock.patch.object(
sc, 'poll_event')) as mock_hm_poll_event, (
mock.patch.object(
driver, const.EVENT_CONFIGURE_HEALTHMONITOR.lower(),
return_value=common_const.SUCCESS)), (
mock.patch.object(
driver, const.EVENT_CLEAR_HEALTHMONITOR.lower(),
return_value=common_const.SUCCESS)) as mock_clear_hm, (
mock.patch.object(
agent, '_get_driver', return_value=driver)):
if const.EVENT_CONFIGURE_HEALTHMONITOR in ev.id:
ev.id, periodicity = ev.id.split()
agent.handle_event(ev)
resource_data = self.fo._fake_resource_data()
if ev.id == const.EVENT_CONFIGURE_INTERFACES:
mock_config_inte.assert_called_with(
self.fo.context, resource_data)
elif ev.id == const.EVENT_CLEAR_INTERFACES:
mock_clear_inte.assert_called_with(
self.fo.context, resource_data)
elif ev.id == const.EVENT_CONFIGURE_ROUTES:
mock_config_src_routes.assert_called_with(
self.fo.context, resource_data)
elif ev.id == const.EVENT_CLEAR_ROUTES:
mock_delete_src_routes.assert_called_with(
self.fo.context, resource_data)
elif const.EVENT_CONFIGURE_HEALTHMONITOR in ev.id:
if periodicity == const.INITIAL:
mock_hm_poll_event.assert_called_with(
ev,
max_times=const.EVENT_CONFIGURE_HEALTHMONITOR_MAXRETRY)
elif periodicity == const.FOREVER:
mock_hm_poll_event.assert_called_with(ev)
elif ev.id == const.EVENT_CLEAR_HEALTHMONITOR:
mock_clear_hm.assert_called_with(
self.fo.context, resource_data)
def _test_handle_periodic_event(self, ev):
""" Test handle periodic event method of generic config agent
for healthmonitor configuration.
:param ev: fake event data which has to be actually sent by
process framewrok.
Returns: None
"""
agent, _ = self._get_GenericConfigEventHandler_object()
driver = mock.Mock()
with mock.patch.object(
agent, '_get_driver', return_value=driver), (
mock.patch.object(
driver, const.EVENT_CONFIGURE_HEALTHMONITOR.lower(),
return_value=common_const.SUCCESS)) as mock_dvr, (
mock.patch.object(subprocess,
'check_output', return_value=True)):
agent.handle_configure_healthmonitor(ev)
self.assertEqual(mock_dvr.return_value, common_const.SUCCESS)
def test_configure_interfaces_genericconfigeventhandler(self):
""" Implements test case for configure interfaces method
of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = const.EVENT_CONFIGURE_INTERFACES
self._test_handle_event(ev)
def test_clear_interfaces_genericconfigeventhandler(self):
""" Implements test case for clear interfaces method
of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = const.EVENT_CLEAR_INTERFACES
self._test_handle_event(ev)
def test_configure_routes_genericconfigeventhandler(self):
""" Implements test case for configure routes method
of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = const.EVENT_CONFIGURE_ROUTES
self._test_handle_event(ev)
def test_clear_routes_genericconfigeventhandler(self):
""" Implements test case for clear routes method
of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = const.EVENT_CLEAR_ROUTES
self._test_handle_event(ev)
def test_configure_hm_initial_genericconfigeventhandler(self):
""" Implements test case for configure health monitor method
with specified polling in generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = 'CONFIGURE_HEALTHMONITOR initial'
self._test_handle_event(ev)
def test_configure_hm_forever_genericconfigeventhandler(self):
""" Implements test case for configure health monitor method
with forever polling in generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.data['resource_data']['nfds'][0].update(
{'periodicity': const.FOREVER})
ev.id = 'CONFIGURE_HEALTHMONITOR forever'
self._test_handle_event(ev)
def test_clear_hm_genericconfigeventhandler(self):
""" Implements test case for clear health monitor method
of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = 'CLEAR_HEALTHMONITOR'
self._test_handle_event(ev)
def test_handle_configure_healthmonitor_genericconfigeventhandler(self):
""" Implements test case for handle configure health monitor
method of generic config event handler.
Returns: none
"""
ev = fo.FakeEventGenericConfig()
ev.id = const.EVENT_CONFIGURE_HEALTHMONITOR
self._test_handle_periodic_event(ev)
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
3873,
199,
199,
504,
2882,
492,
1683,
199,
199,
646,
2882,
18,
199,
199,
504,
8224,
14,
2219,
492,
1300,
199,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
14250,
492,
7809,
63,
888,
465,
9486,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
773,
492,
334,
2511,
7809,
63,
888,
63,
5559,
465,
950,
9,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
773,
492,
5262,
465,
2863,
63,
1297,
199,
504,
486,
10913,
1364,
14,
2828,
14,
2219,
14,
3248,
14,
78,
3997,
14,
888,
17320,
14,
396,
63,
576,
492,
334,
9144,
13908,
63,
396,
63,
576,
465,
7090,
9,
421,
199,
533,
8307,
2028,
15569,
2988,
1746,
8,
1095,
14,
20760,
304,
272,
408,
22467,
511,
5560,
367,
11785,
5256,
3102,
402,
7809,
1101,
6631,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9417,
2028,
15569,
2988,
1746,
12,
291,
2843,
826,
721,
9144,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
545,
275,
7090,
14,
8249,
11188,
342,
339,
768,
1805,
14,
2068,
3460,
354,
363,
435,
1987,
545,
14,
8249,
11188,
14,
551,
358,
272,
768,
1805,
14,
2068,
3460,
354,
363,
435,
1987,
545,
14,
8249,
11188,
14,
2190,
358,
272,
347,
485,
362,
63,
9417,
2028,
15569,
2988,
63,
785,
8,
277,
12,
3743,
12,
4061,
304,
267,
408,
27940,
11785,
5256,
909,
402,
7809,
1101,
6631,
14,
398,
520,
635,
4061,
26,
16991,
2435,
7614,
909,
402,
2112,
1402,
10059,
267,
520,
635,
3743,
26,
16991,
4403,
1484,
2897,
570,
398,
1803,
26,
909,
402,
7809,
1101,
1159,
11785,
5256,
267,
436,
2435,
7614,
14,
398,
408,
398,
6631,
275,
9486,
14,
9417,
2028,
15569,
2988,
8,
551,
12,
3743,
9,
267,
372,
6631,
12,
4061,
339,
347,
485,
396,
63,
1430,
63,
8782,
8,
277,
12,
1083,
304,
267,
408,
6496,
1566,
7143,
436,
14892,
316,
367,
1218,
15,
1807,
267,
3439,
402,
7809,
1101,
6631,
1159,
11785,
5256,
14,
398,
520,
635,
1083,
26,
15869,
3942,
63,
3843,
38,
21287,
15,
20706,
63,
3843,
38,
21287,
15,
267,
15869,
3942,
63,
14999,
654,
15,
20706,
63,
14999,
654,
398,
1803,
26,
7179,
398,
408,
398,
6631,
12,
4061,
275,
291,
423,
362,
63,
9417,
2028,
15569,
2988,
63,
785,
342,
267,
1680,
63,
807,
275,
791,
1100,
356,
291,
14,
545,
14,
1100,
12,
490,
283,
1927,
63,
576,
356,
291,
14,
545,
423,
3183,
63,
1927,
63,
576,
12737,
267,
543,
1683,
14,
2068,
14,
785,
8,
490,
4061,
12,
283,
1222,
63,
1430,
297,
372,
63,
585,
534,
1421,
358,
465,
1683,
63,
551,
63,
1430,
12,
334,
1467,
1683,
14,
2068,
14,
785,
8,
551,
12,
283,
1932,
63,
1430,
1333,
465,
1683,
63,
551,
63,
4354,
63,
1430,
26,
288,
1240,
63,
765,
275,
2519,
8,
4054,
12,
1083,
14,
2325,
1012,
953,
1240,
63,
765,
8,
277,
14,
545,
14,
1100,
12,
291,
14,
545,
423,
3183,
63,
1927,
63,
576,
1012,
953,
340,
283,
1645,
748,
2080,
32387,
726,
7,
315,
1083,
26,
355,
1683,
63,
551,
63,
1430,
14,
479,
63,
3527,
63,
1045,
8,
344,
29,
765,
12,
1740,
666,
29,
1273,
63,
807,
12,
1740,
790,
29,
277,
14,
545,
14,
2611,
344,
9,
288,
587,
26,
355,
1683,
63,
551,
63,
1430,
14,
479,
63,
3527,
63,
1045,
8,
344,
29,
765,
12,
1740,
666,
29,
1273,
63,
807,
12,
790,
29,
403,
9,
288,
1683,
63,
551,
63,
4354,
63,
1430,
14,
479,
63,
3527,
63,
1045,
360,
1421,
358,
339,
347,
511,
63,
6472,
63,
7436,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
8386,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
5569,
3942,
63,
3843,
38,
21287,
9,
339,
347,
511,
63,
3584,
63,
7436,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
5436,
8386,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
20706,
63,
3843,
38,
21287,
9,
339,
347,
511,
63,
6472,
63,
13243,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
15777,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
5569,
3942,
63,
14999,
654,
9,
339,
347,
511,
63,
3584,
63,
13243,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
5436,
15777,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
20706,
63,
14999,
654,
9,
339,
347,
511,
63,
6472,
63,
14038,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
13822,
7157,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
3873,
199,
199,
504,
2882,
492,
1683,
199,
199,
646,
2882,
18,
199,
199,
504,
8224,
14,
2219,
492,
1300,
199,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
14250,
492,
7809,
63,
888,
465,
9486,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
773,
492,
334,
2511,
7809,
63,
888,
63,
5559,
465,
950,
9,
199,
504,
486,
10913,
1364,
14,
2828,
14,
78,
3997,
14,
888,
17320,
14,
773,
492,
5262,
465,
2863,
63,
1297,
199,
504,
486,
10913,
1364,
14,
2828,
14,
2219,
14,
3248,
14,
78,
3997,
14,
888,
17320,
14,
396,
63,
576,
492,
334,
9144,
13908,
63,
396,
63,
576,
465,
7090,
9,
421,
199,
533,
8307,
2028,
15569,
2988,
1746,
8,
1095,
14,
20760,
304,
272,
408,
22467,
511,
5560,
367,
11785,
5256,
3102,
402,
7809,
1101,
6631,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
9417,
2028,
15569,
2988,
1746,
12,
291,
2843,
826,
721,
9144,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
545,
275,
7090,
14,
8249,
11188,
342,
339,
768,
1805,
14,
2068,
3460,
354,
363,
435,
1987,
545,
14,
8249,
11188,
14,
551,
358,
272,
768,
1805,
14,
2068,
3460,
354,
363,
435,
1987,
545,
14,
8249,
11188,
14,
2190,
358,
272,
347,
485,
362,
63,
9417,
2028,
15569,
2988,
63,
785,
8,
277,
12,
3743,
12,
4061,
304,
267,
408,
27940,
11785,
5256,
909,
402,
7809,
1101,
6631,
14,
398,
520,
635,
4061,
26,
16991,
2435,
7614,
909,
402,
2112,
1402,
10059,
267,
520,
635,
3743,
26,
16991,
4403,
1484,
2897,
570,
398,
1803,
26,
909,
402,
7809,
1101,
1159,
11785,
5256,
267,
436,
2435,
7614,
14,
398,
408,
398,
6631,
275,
9486,
14,
9417,
2028,
15569,
2988,
8,
551,
12,
3743,
9,
267,
372,
6631,
12,
4061,
339,
347,
485,
396,
63,
1430,
63,
8782,
8,
277,
12,
1083,
304,
267,
408,
6496,
1566,
7143,
436,
14892,
316,
367,
1218,
15,
1807,
267,
3439,
402,
7809,
1101,
6631,
1159,
11785,
5256,
14,
398,
520,
635,
1083,
26,
15869,
3942,
63,
3843,
38,
21287,
15,
20706,
63,
3843,
38,
21287,
15,
267,
15869,
3942,
63,
14999,
654,
15,
20706,
63,
14999,
654,
398,
1803,
26,
7179,
398,
408,
398,
6631,
12,
4061,
275,
291,
423,
362,
63,
9417,
2028,
15569,
2988,
63,
785,
342,
267,
1680,
63,
807,
275,
791,
1100,
356,
291,
14,
545,
14,
1100,
12,
490,
283,
1927,
63,
576,
356,
291,
14,
545,
423,
3183,
63,
1927,
63,
576,
12737,
267,
543,
1683,
14,
2068,
14,
785,
8,
490,
4061,
12,
283,
1222,
63,
1430,
297,
372,
63,
585,
534,
1421,
358,
465,
1683,
63,
551,
63,
1430,
12,
334,
1467,
1683,
14,
2068,
14,
785,
8,
551,
12,
283,
1932,
63,
1430,
1333,
465,
1683,
63,
551,
63,
4354,
63,
1430,
26,
288,
1240,
63,
765,
275,
2519,
8,
4054,
12,
1083,
14,
2325,
1012,
953,
1240,
63,
765,
8,
277,
14,
545,
14,
1100,
12,
291,
14,
545,
423,
3183,
63,
1927,
63,
576,
1012,
953,
340,
283,
1645,
748,
2080,
32387,
726,
7,
315,
1083,
26,
355,
1683,
63,
551,
63,
1430,
14,
479,
63,
3527,
63,
1045,
8,
344,
29,
765,
12,
1740,
666,
29,
1273,
63,
807,
12,
1740,
790,
29,
277,
14,
545,
14,
2611,
344,
9,
288,
587,
26,
355,
1683,
63,
551,
63,
1430,
14,
479,
63,
3527,
63,
1045,
8,
344,
29,
765,
12,
1740,
666,
29,
1273,
63,
807,
12,
790,
29,
403,
9,
288,
1683,
63,
551,
63,
4354,
63,
1430,
14,
479,
63,
3527,
63,
1045,
360,
1421,
358,
339,
347,
511,
63,
6472,
63,
7436,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
8386,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
5569,
3942,
63,
3843,
38,
21287,
9,
339,
347,
511,
63,
3584,
63,
7436,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
5436,
8386,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
20706,
63,
3843,
38,
21287,
9,
339,
347,
511,
63,
6472,
63,
13243,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
15777,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
5569,
3942,
63,
14999,
654,
9,
339,
347,
511,
63,
3584,
63,
13243,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
5436,
15777,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
63,
1430,
63,
8782,
8,
1297,
14,
8193,
63,
20706,
63,
14999,
654,
9,
339,
347,
511,
63,
6472,
63,
14038,
63,
6767,
888,
4354,
2609,
8,
277,
304,
267,
408,
24664,
511,
1930,
367,
7908,
13822,
7157,
1083,
267,
402,
7809,
1101,
6631,
11785,
2609,
14,
398,
1803,
26,
7179,
398,
408,
398,
291,
423,
396,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Quihico/repository.spartacus
|
temp/script.module.python.koding.aio/lib/koding/web.py
|
1
|
12658
|
# -*- coding: utf-8 -*-
# script.module.python.koding.aio
# Python Koding AIO (c) by whufclee (info@totalrevolution.tv)
# Python Koding AIO is licensed under a
# Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
# You should have received a copy of the license along with this
# work. If not, see http://creativecommons.org/licenses/by-nc-nd/4.0.
# IMPORTANT: If you choose to use the special noobsandnerds features which hook into their server
# please make sure you give approptiate credit in your add-on description (noobsandnerds.com)
#
# Please make sure you've read and understood the license, this code can NOT be used commercially
# and it can NOT be modified and redistributed. If you're found to be in breach of this license
# then any affected add-ons will be blacklisted and will not be able to work on the same system
# as any other add-ons which use this code. Thank you for your cooperation.
import time
import urllib
import xbmcgui
#----------------------------------------------------------------
# TUTORIAL #
def Cleanup_URL(url):
"""
Clean a url, removes whitespaces and common buggy formatting when pulling from websites
CODE: Cleanup_URL(url)
AVAILABLE PARAMS:
(*) url - This is the main url you want cleaned up.
EXAMPLE CODE:
raw_url = '" http://test.com/video/"/'
clean_url = koding.Cleanup_URL(raw_url)
dialog.ok('CLEANUP URL', 'Orig: %s'%raw_url,'Clean: %s'%clean_url)
~"""
from HTMLParser import HTMLParser
bad_chars = ['/','\\',':',';','"',"'"]
url = url.strip()
while url[0] in bad_chars or url[-1] in bad_chars:
if url[-1] in bad_chars:
url = url[:-1]
if url[0] in bad_chars:
url = url[1:]
url = url.strip()
return HTMLParser().unescape(url)
#----------------------------------------------------------------
# TUTORIAL #
def Delete_Cookies(filename='cookiejar'):
"""
This will delete your cookies file.
CODE: koding.Delete_Cookies([filename])
AVAILABLE PARAMS:
filename - By default this is set to the filename 'cookiejar'.
This is the default cookie filename which is created by the Open_URL
function but you can use any name you want and this function will
return True or False on whether or not it's successfully been removed.
EXAMPLE CODE:
Open_URL(url='http://google.com',cookiejar='google')
dialog.ok('GOOGLE COOKIES CREATED','We have just opened a page to google.com, if you check your addon_data folder for your add-on you should see a cookies folder and in there should be a cookie called "google". When you press OK this will be removed.')
~"""
from addons import Addon_Info
Addon_Version = Addon_Info(id='version')
Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
Cookie_File = os.path.join(Addon_Profile,'cookies',filename)
try:
if os.path.exists(Cookie_File):
os.remove(Cookie_File)
return True
except:
return False
#----------------------------------------------------------------
# TUTORIAL #
def Download(url, dest, dp = None):
"""
This will download a file, currently this has to be a standard download link which doesn't require cookies/login.
CODE: koding.Download(src,dst,[dp])
dp is optional, by default it is set to false
AVAILABLE PARAMS:
(*) src - This is the source file, the URL to your download. If you attempted to download an item but it's not behaving the way you think it should (e.g. a zip file not unzipping) then change the extension of the downloaded file to .txt and open up in a text editor. You'll most likely find it's just a piece of text that was returned from the URL you gave and it should have details explaining why it failed. Could be that's the wrong URL, it requires some kind of login, it only accepts certain user-agents etc.
(*) dst - This is the destination file, make sure it's a physical path and not "special://...". Also remember you need to add the actual filename to the end of the path, so if we were downloading something to the "downloads" folder and we wanted the file to be called "test.txt" we would use this path: dst = "downloads/test.txt". Of course the downloads folder would actually need to exist otherwise it would fail and based on this poor example the downloads folder would be at root level of your device as we've not specified a path prior to that so it just uses the first level that's accessible.
dp - This is optional, if you pass through the dp function as a DialogProgress() then you'll get to see the progress of the download. If you choose not to add this paramater then you'll just get a busy spinning circle icon until it's completed. See the example below for a dp example.
EXAMPLE CODE:
src = 'http://noobsandnerds.com/python_koding/my_first_addon.zip'
dst = xbmc.translatePath('special://home/my_first_addon.zip')
dp = xbmcgui.DialogProgress()
dp.create('Downloading File','Please Wait')
koding.Download(src,dst,dp)
~"""
start_time=time.time()
urllib.urlretrieve(url, dest, lambda nb, bs, fs: Download_Progress(nb, bs, fs, dp, start_time))
#----------------------------------------------------------------
def Download_Progress(numblocks, blocksize, filesize, dp, start_time):
""" internal command ~"""
try:
percent = min(numblocks * blocksize * 100 / filesize, 100)
currently_downloaded = float(numblocks) * blocksize / (1024 * 1024)
kbps_speed = numblocks * blocksize / (time.time() - start_time)
if kbps_speed > 0:
eta = (filesize - numblocks * blocksize) / kbps_speed
else:
eta = 0
kbps_speed = kbps_speed / 1024
total = float(filesize) / (1024 * 1024)
mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
e = 'Speed: %.02f Kb/s ' % kbps_speed
e += 'ETA: %02d:%02d' % divmod(eta, 60)
if dp:
dp.update(percent, mbs, e)
if dp.iscanceled():
dp.close()
except:
percent = 100
if dp:
dp.update(percent)
if dp:
if dp.iscanceled():
dp.close()
dp.close()
#----------------------------------------------------------------
# TUTORIAL #
def Get_Extension(url):
"""
Return the extension of a url
CODE: koding.Get_Extension(url)
AVAILABLE PARAMS:
(*) url - This is the url you want to grab the extension from
EXAMPLE CODE:
url_extension = koding.Get_Extension('http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4')
dialog.ok('FILE EXTENSION','The file extension of this Big Buck Bunny sample is:','','[COLOR=dodgerblue]%s[/COLOR]'%url_extension)
~"""
import os
import urlparse
parsed = urlparse.urlparse(url)
root, ext = os.path.splitext(parsed.path)
return ext
#----------------------------------------------------------------
# TUTORIAL #
def Open_URL(url='',post_type='get',payload={},headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'},cookies=True,auth=None,timeout=None,cookiejar=None):
"""
If you need to pull the contents of a webpage it's very simple to do so by using this function.
IMPORTANT: This function is designed to convert a query string into a post.
If you want to send through a post which contains ampersands or question
marks you MUST send the params through as a dictionary. By default this function
presumes the url only contains one question mark and it splits at that point and
will then split the params at every instance of an ampersand.
CODE: koding.Open_URL(url,[post_type,payload,headers,cookies,auth,timeout,cookiejar])
AVAILABLE PARAMS:
url - This is the main url you want to send through. Send it through
as a query string format even if it's a post.
post_type - By default this is set to 'get' but this can be set to 'post',
if set to post the query string will be split up into a post format automatically.
payload - By default this is not used but if you just want a standard
basic Open_URL function you can add a dictionary of params here. If you
don't enter anything in here the function will just split up your url
accordingly. Make sure you read the important information at the top
of this tutorial text.
headers - Optionally send through headers in form of a dictionary.
cookies - If set to true your request will send through and store cookies.
auth - User/pass details
timeout - Optionally set a timeout for the request.
cookiejar - An name for the location to store cookies. By default it's
set to addon_data/<addon_id>/cookies/cookiejar but if you have multiple
websites you access then you may want to use a separate filename for each site.
EXAMPLE CODE:
url_contents = koding.Open_URL('http://testpage.com?query1=value1&query2=value2', post_type='get')
koding.Text_Box('CONTENTS OF WEB PAGE',url_contents)
~"""
import os
import pickle
import requests
import sys
import xbmc
import xbmcaddon
from __init__ import converthex, dolog, Encryption, ADDON_ID, LOGIN, FORUM, USERNAME, PASSWORD, KODI_VER
from addons import Addon_Info
from filetools import Text_File
dolog('POST TYPE: %s'%post_type)
dolog('url: %s'%url)
Addon_Version = Addon_Info(id='version')
Addon_Profile = xbmc.translatePath(Addon_Info(id='profile'))
Cookie_Folder = os.path.join(Addon_Profile,'cookies')
if not os.path.exists(Cookie_Folder):
os.makedirs(Cookie_Folder)
if cookiejar == None:
Cookie_Jar = os.path.join(Cookie_Folder,'cookiejar')
else:
Cookie_Jar = os.path.join(Cookie_Folder,cookiejar)
my_cookies = None
if cookies:
if os.path.exists(Cookie_Jar):
try:
with open(Cookie_Jar, 'rb') as f:
my_cookies = pickle.load(f)
except:
my_cookies = None
# If the payload is empty we split the params
if len(payload) == 0:
dolog('###### QUERY STRING CONVERSION MODE')
# If the url sent through is not http then we presume it's hitting the NaN page
if not url.startswith(converthex('68747470')):
NaN_URL = True
args = url
post_type = 'post'
url = converthex('687474703a2f2f6e6f6f6273616e646e657264732e636f6d2f43505f53747566662f6c6f67696e5f74657374696e672e7068703f753d257326703d257326663d257326613d257326763d2573266b3d257326653d2573') % (USERNAME, PASSWORD, FORUM, ADDON_ID, Addon_Version, KODI_VER, args)
else:
NaN_URL = False
if '?' in url:
url, args = url.split('?')
args = args.split('&')
for item in args:
var, data = item.split('=')
if NaN_URL:
payload[var] = Encryption('e', data)
else:
payload[var] = data
dolog('PAYLOAD: %s'%payload)
try:
if post_type == 'post':
r = requests.post(url, payload, headers=headers, cookies=my_cookies, auth=auth, timeout=timeout)
else:
r = requests.get(url, payload, headers=headers, cookies=my_cookies, auth=auth, timeout=timeout)
except:
dolog('Failed to pull content for %s'%url)
return False
dolog('### CODE: %s | REASON: %s' % (r.status_code, r.reason))
if r.status_code >= 200 and r.status_code < 400:
content = r.text.encode('utf-8')
dolog('content: %s'%content)
if cookies:
with open(Cookie_Jar, 'wb') as f:
pickle.dump(r.cookies, f)
return content
else:
dolog('Failed to pull content for %s'%url)
return False
#----------------------------------------------------------------
# TUTORIAL #
def Validate_Link(url=''):
"""
Returns the code for a particular link, so for example 200 is a good link and 404 is a URL not found
CODE: koding.Validate_Link(url)
AVAILABLE PARAMS:
(*) url - This is url you want to check the header code for
EXAMPLE CODE:
url_code = koding.Validate_Link('http://totalrevolution.tv')
if url_code == 200:
dialog.ok('WEBSITE STATUS','The website [COLOR=dodgerblue]totalrevolution.tv[/COLOR] is [COLOR=lime]ONLINE[/COLOR]')
else:
dialog.ok('WEBSITE STATUS','The website [COLOR=dodgerblue]totalrevolution.tv[/COLOR] is [COLOR=red]OFFLINE[/COLOR]')
~"""
import requests
import xbmc
r = requests.get(url)
return r.status_code
#----------------------------------------------------------------
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
2884,
14,
578,
14,
1548,
14,
75,
2691,
14,
65,
2308,
199,
3,
2018,
1804,
2691,
437,
2090,
334,
67,
9,
701,
704,
1286,
2265,
69,
334,
815,
32,
2923,
4964,
3347,
14,
6993,
9,
199,
199,
3,
2018,
1804,
2691,
437,
2090,
365,
18233,
1334,
282,
199,
3,
9750,
1905,
7046,
4654,
2854,
15980,
13,
6932,
4373,
23012,
13,
1944,
17793,
1003,
10661,
841,
14,
16,
28220,
844,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
642,
199,
3,
1736,
14,
982,
440,
12,
1937,
1455,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
7966,
13,
977,
15,
20,
14,
16,
14,
199,
199,
3,
5025,
2596,
1441,
26,
982,
1265,
11496,
370,
675,
314,
4539,
949,
11226,
460,
1372,
795,
4534,
1314,
5759,
1901,
3932,
1654,
199,
3,
8749,
1852,
3238,
1265,
8120,
4286,
80,
280,
323,
16630,
315,
2195,
1050,
13,
265,
1369,
334,
889,
11226,
460,
1372,
795,
14,
957,
9,
199,
3,
221,
199,
3,
7754,
1852,
3238,
1265,
9064,
1586,
436,
1334,
14308,
364,
314,
4190,
12,
642,
1233,
883,
2845,
506,
1202,
2414,
2626,
559,
1183,
199,
3,
436,
652,
883,
2845,
506,
6042,
436,
295,
16832,
14,
982,
1265,
3984,
1911,
370,
506,
315,
330,
12784,
402,
642,
4190,
199,
3,
2066,
1263,
16955,
1050,
13,
4654,
911,
506,
12136,
15023,
436,
911,
440,
506,
7688,
370,
1736,
641,
314,
2011,
2656,
199,
3,
465,
1263,
1163,
1050,
13,
4654,
1314,
675,
642,
1233,
14,
3868,
3580,
1265,
367,
2195,
512,
5735,
14,
199,
199,
646,
900,
199,
646,
4011,
199,
646,
26418,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
30022,
63,
2632,
8,
633,
304,
272,
408,
199,
6580,
282,
1166,
12,
14185,
704,
31926,
436,
2863,
1032,
26435,
10803,
1380,
10299,
316,
687,
3330,
8619,
199,
199,
6012,
26,
30022,
63,
2632,
8,
633,
9,
339,
437,
54,
6593,
2617,
16565,
51,
26,
2728,
334,
13278,
1166,
257,
446,
221,
961,
365,
314,
2446,
1166,
1265,
2934,
12364,
1536,
14,
199,
199,
26900,
22547,
26,
199,
1773,
63,
633,
275,
5522,
1455,
921,
396,
14,
957,
15,
3722,
6687,
4805,
199,
3118,
63,
633,
275,
1022,
2691,
14,
7891,
63,
2632,
8,
1773,
63,
633,
9,
199,
7196,
14,
745,
360,
28663,
2160,
2851,
297,
283,
29698,
26,
450,
83,
5956,
1773,
63,
633,
2584,
6580,
26,
450,
83,
5956,
3118,
63,
633,
9,
199,
94,
624,
272,
687,
24581,
492,
24581,
339,
4875,
63,
6574,
275,
18744,
1673,
1103,
297,
356,
1673,
27,
1673,
6949,
4507,
937,
272,
1166,
275,
1166,
14,
1913,
342,
339,
1830,
1166,
59,
16,
61,
315,
4875,
63,
6574,
503,
1166,
1988,
17,
61,
315,
4875,
63,
6574,
26,
267,
340,
1166,
1988,
17,
61,
315,
4875,
63,
6574,
26,
288,
1166,
275,
1166,
4439,
17,
61,
267,
340,
1166,
59,
16,
61,
315,
4875,
63,
6574,
26,
288,
1166,
275,
1166,
59,
17,
2938,
267,
1166,
275,
1166,
14,
1913,
342,
272,
372,
24581,
1252,
22726,
8,
633,
9,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
8496,
63,
967,
5635,
8,
1501,
534,
30552,
735,
272,
408,
199,
2765,
911,
3145,
2195,
10049,
570,
14,
199,
199,
6012,
26,
1022,
2691,
14,
5392,
63,
967,
5635,
779,
1501,
566,
199,
199,
17377,
16565,
51,
26,
339,
1788,
446,
4885,
849,
642,
365,
663,
370,
314,
1788,
283,
30552,
1370,
272,
961,
365,
314,
849,
5494,
1788,
1314,
365,
2737,
701,
314,
3232,
63,
2632,
272,
805,
1325,
1265,
883,
675,
1263,
536,
1265,
2934,
436,
642,
805,
911,
272,
372,
715,
503,
756,
641,
3775,
503,
440,
652,
1159,
8792,
2757,
4829,
14,
199,
199,
26900,
22547,
26,
199,
4299,
63,
2632,
8,
633,
534,
1014,
921,
3098,
14,
957,
297,
30552,
534,
3098,
358,
199,
7196,
14,
745,
360,
24243,
5099,
3593,
2563,
15654,
6989,
1673,
6004,
1172,
2951,
12123,
282,
2034,
370,
6233,
14,
957,
12,
340,
1265,
1104,
2195,
13553,
63,
576,
4922,
367,
2195,
1050,
13,
265,
1265,
1077,
1937,
282,
10049,
4922,
436,
315,
2337,
1077,
506,
282,
5494,
2797,
298,
3098,
1674,
3979,
1265,
15105,
9949,
642,
911,
506,
4829,
2659,
199,
94,
624,
272,
687,
21293,
258,
492,
29366,
63,
2354,
272,
29366,
63,
3353,
275,
29366,
63,
2354,
8,
344,
534,
1023,
358,
272,
29366,
63,
5736,
275,
11709,
14,
5275,
2042,
8,
19654,
63,
2354,
8,
344,
534,
2913,
1333,
272,
14798,
63,
1173,
257,
275,
747,
14,
515,
14,
904,
8,
19654,
63,
5736,
2584,
7792,
297,
1501,
9,
272,
862,
26,
267,
340,
747,
14,
515,
14,
2444,
8,
7810,
63,
1173,
304,
288,
747,
14,
2168,
8,
7810,
63,
1173,
9,
267,
372,
715,
272,
871,
26,
267,
372,
756,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
17955,
8,
633,
12,
2053,
12,
12392,
275,
488,
304,
272,
408,
199,
2765,
911,
5235,
282,
570,
12,
5544,
642,
965,
370,
506,
282,
4465,
5235,
2142,
1314,
3181,
1133,
4409,
10049,
15,
2886,
14,
199,
199,
6012,
26,
1022,
2691,
14,
11950,
8,
2164,
12,
5119,
14343,
5780,
566,
199,
5780,
365,
2716,
12,
701,
849,
652,
365,
663,
370,
3055,
199,
199,
17377,
16565,
51,
26,
339,
334,
13278,
2928,
221,
446,
961,
365,
314,
1350,
570,
12,
314,
2851,
370,
2195,
5235,
14,
982,
1265,
22040,
370,
5235,
376,
1242,
1325,
652,
1159,
440,
15179,
5519,
314,
4340,
1265,
13516,
652,
1077,
334,
69,
14,
71,
14,
282,
3482,
570,
440,
29379,
4073,
9,
2066,
1570,
314,
3329,
402,
314,
13557,
570,
370,
1275,
2424,
436,
1551,
1536,
315,
282,
1318,
8823,
14,
2047,
7171,
4750,
12060,
2342,
652,
1159,
2951,
282,
14854,
402,
1318,
626,
1990,
2138,
687,
314,
2851,
1265,
486,
811,
436,
652,
1077,
1172,
2436,
27797,
316,
10842,
652,
3405,
14,
18615,
506,
626,
1159,
314,
6835,
2851,
12,
652,
5074,
2005,
4928,
402,
4676,
12,
652,
1454,
11479,
9842,
922,
13,
14250,
5423,
14,
339,
334,
13278,
5042,
221,
446,
961,
365
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
2884,
14,
578,
14,
1548,
14,
75,
2691,
14,
65,
2308,
199,
3,
2018,
1804,
2691,
437,
2090,
334,
67,
9,
701,
704,
1286,
2265,
69,
334,
815,
32,
2923,
4964,
3347,
14,
6993,
9,
199,
199,
3,
2018,
1804,
2691,
437,
2090,
365,
18233,
1334,
282,
199,
3,
9750,
1905,
7046,
4654,
2854,
15980,
13,
6932,
4373,
23012,
13,
1944,
17793,
1003,
10661,
841,
14,
16,
28220,
844,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
642,
199,
3,
1736,
14,
982,
440,
12,
1937,
1455,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
7966,
13,
977,
15,
20,
14,
16,
14,
199,
199,
3,
5025,
2596,
1441,
26,
982,
1265,
11496,
370,
675,
314,
4539,
949,
11226,
460,
1372,
795,
4534,
1314,
5759,
1901,
3932,
1654,
199,
3,
8749,
1852,
3238,
1265,
8120,
4286,
80,
280,
323,
16630,
315,
2195,
1050,
13,
265,
1369,
334,
889,
11226,
460,
1372,
795,
14,
957,
9,
199,
3,
221,
199,
3,
7754,
1852,
3238,
1265,
9064,
1586,
436,
1334,
14308,
364,
314,
4190,
12,
642,
1233,
883,
2845,
506,
1202,
2414,
2626,
559,
1183,
199,
3,
436,
652,
883,
2845,
506,
6042,
436,
295,
16832,
14,
982,
1265,
3984,
1911,
370,
506,
315,
330,
12784,
402,
642,
4190,
199,
3,
2066,
1263,
16955,
1050,
13,
4654,
911,
506,
12136,
15023,
436,
911,
440,
506,
7688,
370,
1736,
641,
314,
2011,
2656,
199,
3,
465,
1263,
1163,
1050,
13,
4654,
1314,
675,
642,
1233,
14,
3868,
3580,
1265,
367,
2195,
512,
5735,
14,
199,
199,
646,
900,
199,
646,
4011,
199,
646,
26418,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
30022,
63,
2632,
8,
633,
304,
272,
408,
199,
6580,
282,
1166,
12,
14185,
704,
31926,
436,
2863,
1032,
26435,
10803,
1380,
10299,
316,
687,
3330,
8619,
199,
199,
6012,
26,
30022,
63,
2632,
8,
633,
9,
339,
437,
54,
6593,
2617,
16565,
51,
26,
2728,
334,
13278,
1166,
257,
446,
221,
961,
365,
314,
2446,
1166,
1265,
2934,
12364,
1536,
14,
199,
199,
26900,
22547,
26,
199,
1773,
63,
633,
275,
5522,
1455,
921,
396,
14,
957,
15,
3722,
6687,
4805,
199,
3118,
63,
633,
275,
1022,
2691,
14,
7891,
63,
2632,
8,
1773,
63,
633,
9,
199,
7196,
14,
745,
360,
28663,
2160,
2851,
297,
283,
29698,
26,
450,
83,
5956,
1773,
63,
633,
2584,
6580,
26,
450,
83,
5956,
3118,
63,
633,
9,
199,
94,
624,
272,
687,
24581,
492,
24581,
339,
4875,
63,
6574,
275,
18744,
1673,
1103,
297,
356,
1673,
27,
1673,
6949,
4507,
937,
272,
1166,
275,
1166,
14,
1913,
342,
339,
1830,
1166,
59,
16,
61,
315,
4875,
63,
6574,
503,
1166,
1988,
17,
61,
315,
4875,
63,
6574,
26,
267,
340,
1166,
1988,
17,
61,
315,
4875,
63,
6574,
26,
288,
1166,
275,
1166,
4439,
17,
61,
267,
340,
1166,
59,
16,
61,
315,
4875,
63,
6574,
26,
288,
1166,
275,
1166,
59,
17,
2938,
267,
1166,
275,
1166,
14,
1913,
342,
272,
372,
24581,
1252,
22726,
8,
633,
9,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
8496,
63,
967,
5635,
8,
1501,
534,
30552,
735,
272,
408,
199,
2765,
911,
3145,
2195,
10049,
570,
14,
199,
199,
6012,
26,
1022,
2691,
14,
5392,
63,
967,
5635,
779,
1501,
566,
199,
199,
17377,
16565,
51,
26,
339,
1788,
446,
4885,
849,
642,
365,
663,
370,
314,
1788,
283,
30552,
1370,
272,
961,
365,
314,
849,
5494,
1788,
1314,
365,
2737,
701,
314,
3232,
63,
2632,
272,
805,
1325,
1265,
883,
675,
1263,
536,
1265,
2934,
436,
642,
805,
911,
272,
372,
715,
503,
756,
641,
3775,
503,
440,
652,
1159,
8792,
2757,
4829,
14,
199,
199,
26900,
22547,
26,
199,
4299,
63,
2632,
8,
633,
534,
1014,
921,
3098,
14,
957,
297,
30552,
534,
3098,
358,
199,
7196,
14,
745,
360,
24243,
5099,
3593,
2563,
15654,
6989,
1673,
6004,
1172,
2951,
12123,
282,
2034,
370,
6233,
14,
957,
12,
340,
1265,
1104,
2195,
13553,
63,
576,
4922,
367,
2195,
1050,
13,
265,
1265,
1077,
1937,
282,
10049,
4922,
436,
315,
2337,
1077,
506,
282,
5494,
2797,
298,
3098,
1674,
3979,
1265,
15105,
9949,
642,
911,
506,
4829,
2659,
199,
94,
624,
272,
687,
21293,
258,
492,
29366,
63,
2354,
272,
29366,
63,
3353,
275,
29366,
63,
2354,
8,
344,
534,
1023,
358,
272,
29366,
63,
5736,
275,
11709,
14,
5275,
2042,
8,
19654,
63,
2354,
8,
344,
534,
2913,
1333,
272,
14798,
63,
1173,
257,
275,
747,
14,
515,
14,
904,
8,
19654,
63,
5736,
2584,
7792,
297,
1501,
9,
272,
862,
26,
267,
340,
747,
14,
515,
14,
2444,
8,
7810,
63,
1173,
304,
288,
747,
14,
2168,
8,
7810,
63,
1173,
9,
267,
372,
715,
272,
871,
26,
267,
372,
756,
199,
7656,
258,
199,
3,
377,
934,
726,
4938,
327,
199,
318,
17955,
8,
633,
12,
2053,
12,
12392,
275,
488,
304,
272,
408,
199,
2765,
911,
5235,
282,
570,
12,
5544,
642,
965,
370,
506,
282,
4465,
5235,
2142,
1314,
3181,
1133,
4409,
10049,
15,
2886,
14,
199,
199,
6012,
26,
1022,
2691,
14,
11950,
8,
2164,
12,
5119,
14343,
5780,
566,
199,
5780,
365,
2716,
12,
701,
849,
652,
365,
663,
370,
3055,
199,
199,
17377,
16565,
51,
26,
339,
334,
13278,
2928,
221,
446,
961,
365,
314,
1350,
570,
12,
314,
2851,
370,
2195,
5235,
14,
982,
1265,
22040,
370,
5235,
376,
1242,
1325,
652,
1159,
440,
15179,
5519,
314,
4340,
1265,
13516,
652,
1077,
334,
69,
14,
71,
14,
282,
3482,
570,
440,
29379,
4073,
9,
2066,
1570,
314,
3329,
402,
314,
13557,
570,
370,
1275,
2424,
436,
1551,
1536,
315,
282,
1318,
8823,
14,
2047,
7171,
4750,
12060,
2342,
652,
1159,
2951,
282,
14854,
402,
1318,
626,
1990,
2138,
687,
314,
2851,
1265,
486,
811,
436,
652,
1077,
1172,
2436,
27797,
316,
10842,
652,
3405,
14,
18615,
506,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Gustry/inasafe
|
safe/utilities/profiling.py
|
2
|
3345
|
# coding=utf-8
"""This module contains logic for performance profiling.
This code was taken from http://stackoverflow.com/a/3620972
"""
import time
import inspect
from functools import wraps
from safe.utilities.memory_checker import get_free_memory
from safe.utilities.settings import setting
__copyright__ = "Vadim Shender (original poster in stack overflow), InaSAFE"
__license__ = "Creative Commons"
__email__ = "info@inasafe.org"
__revision__ = '$Format:%H$'
class Tree(object):
def __init__(self, key):
# Name of the current function
self.key = key
self.parent = None
# Time of creation
self._start_time = time.time()
# Time at the end.
self._end_time = None
if setting(key='memory_profile', expected_type=bool):
# memory at creation
self._start_memory = get_free_memory()
# memory at termination
self._end_memory = None
# Children
self.children = []
def ended(self):
"""We call this method when the function is finished."""
self._end_time = time.time()
if setting(key='memory_profile', expected_type=bool):
self._end_memory = get_free_memory()
@property
def elapsed_time(self):
"""To know the duration of the function.
This property might return None if the function is still running.
"""
if self._end_time:
elapsed_time = round(self._end_time - self._start_time, 3)
return elapsed_time
else:
return None
@property
def memory_used(self):
"""To know the allocated memory at function termination.
..versionadded:: 4.1
This property might return None if the function is still running.
This function should help to show memory leaks or ram greedy code.
"""
if self._end_memory:
memory_used = self._end_memory - self._start_memory
return memory_used
else:
return None
def append(self, node):
"""To append a new child."""
if node.parent == self.key and not self.elapsed_time:
self.children.append(node)
else:
# Recursive call
for child in self.children:
if not child.elapsed_time:
child.append(node)
def __str__(self):
# It might be a private function.
step = self.key.lstrip('_')
# Replace _ by a space
step = step.replace('_', ' ')
# Capitalize first letter
step = step.capitalize()
return step
ROOT = None
def profile(fn):
@wraps(fn)
def with_profiling(*args, **kwargs):
global ROOT
current_frame = inspect.currentframe()
parent_frame = inspect.getouterframes(current_frame)[1]
parent_name = parent_frame[3]
current_step = Tree(fn.__name__)
if ROOT:
current_step.parent = parent_name
ROOT.append(current_step)
else:
ROOT = current_step
ret = fn(*args, **kwargs)
current_step.ended()
return ret
return with_profiling
def profiling_log():
"""Get the profiling logs."""
global ROOT
return ROOT
def clear_prof_data():
global ROOT
ROOT = None
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
199,
624,
2765,
859,
3509,
9661,
367,
10238,
30238,
14,
199,
199,
2765,
1233,
1990,
9394,
687,
1455,
921,
23153,
14,
957,
15,
65,
15,
1344,
1165,
26433,
199,
199,
624,
199,
199,
646,
900,
199,
646,
6485,
199,
504,
9143,
492,
14018,
199,
504,
5048,
14,
16355,
14,
4844,
63,
6743,
492,
664,
63,
4624,
63,
4844,
199,
504,
5048,
14,
16355,
14,
1751,
492,
4260,
421,
199,
363,
7307,
363,
275,
298,
29933,
3572,
5244,
13747,
334,
5043,
2086,
351,
315,
3464,
15784,
395,
1010,
65,
27657,
2,
199,
363,
1682,
363,
275,
298,
5482,
1905,
7046,
4654,
2,
199,
363,
2123,
363,
275,
298,
815,
32,
262,
305,
6504,
14,
1308,
2,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
533,
12178,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
304,
398,
327,
2812,
402,
314,
1453,
805,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1708,
275,
488,
398,
327,
4703,
402,
7143,
267,
291,
423,
928,
63,
521,
275,
900,
14,
521,
342,
398,
327,
4703,
737,
314,
1284,
14,
267,
291,
423,
500,
63,
521,
275,
488,
398,
340,
4260,
8,
498,
534,
4844,
63,
2913,
297,
1420,
63,
466,
29,
2245,
304,
288,
327,
4402,
737,
7143,
288,
291,
423,
928,
63,
4844,
275,
664,
63,
4624,
63,
4844,
342,
953,
327,
4402,
737,
23868,
288,
291,
423,
500,
63,
4844,
275,
488,
398,
327,
12988,
828,
267,
291,
14,
3223,
275,
942,
339,
347,
22480,
8,
277,
304,
267,
408,
6004,
1240,
642,
1083,
1380,
314,
805,
365,
9158,
1041,
267,
291,
423,
500,
63,
521,
275,
900,
14,
521,
342,
398,
340,
4260,
8,
498,
534,
4844,
63,
2913,
297,
1420,
63,
466,
29,
2245,
304,
288,
291,
423,
500,
63,
4844,
275,
664,
63,
4624,
63,
4844,
342,
339,
768,
1829,
272,
347,
14439,
63,
521,
8,
277,
304,
267,
408,
1378,
5715,
314,
7373,
402,
314,
805,
14,
398,
961,
3324,
5594,
372,
488,
340,
314,
805,
365,
5139,
3879,
14,
267,
408,
267,
340,
291,
423,
500,
63,
521,
26,
288,
14439,
63,
521,
275,
6168,
8,
277,
423,
500,
63,
521,
446,
291,
423,
928,
63,
521,
12,
650,
9,
288,
372,
14439,
63,
521,
267,
587,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
4402,
63,
2972,
8,
277,
304,
267,
408,
1378,
5715,
314,
17659,
4402,
737,
805,
23868,
14,
398,
2508,
1023,
3270,
447,
841,
14,
17,
398,
961,
3324,
5594,
372,
488,
340,
314,
805,
365,
5139,
3879,
14,
398,
961,
805,
1077,
1720,
370,
2498,
4402,
1026,
14631,
503,
21394,
486,
24737,
1233,
14,
267,
408,
267,
340,
291,
423,
500,
63,
4844,
26,
288,
4402,
63,
2972,
275,
291,
423,
500,
63,
4844,
446,
291,
423,
928,
63,
4844,
288,
372,
4402,
63,
2972,
267,
587,
26,
288,
372,
488,
339,
347,
5666,
8,
277,
12,
1031,
304,
267,
408,
1378,
5666,
282,
892,
1982,
1041,
267,
340,
1031,
14,
1708,
508,
291,
14,
498,
436,
440,
291,
14,
16691,
63,
521,
26,
288,
291,
14,
3223,
14,
740,
8,
932,
9,
267,
587,
26,
288,
327,
18306,
3398,
1240,
288,
367,
1982,
315,
291,
14,
3223,
26,
355,
340,
440,
1982,
14,
16691,
63,
521,
26,
490,
1982,
14,
740,
8,
932,
9,
339,
347,
636,
495,
721,
277,
304,
267,
327,
2779,
5594,
506,
282,
5726,
805,
14,
267,
3650,
275,
291,
14,
498,
14,
10124,
26341,
398,
327,
14402,
485,
701,
282,
4601,
267,
3650,
275,
3650,
14,
1814,
20928,
283,
5320,
398,
327,
22516,
6910,
794,
1642,
8082,
267,
3650,
275,
3650,
14,
18351,
342,
398,
372,
3650,
199,
199,
5441,
275,
488,
421,
199,
318,
4690,
8,
2324,
304,
272,
768,
13582,
8,
2324,
9,
272,
347,
543,
63,
496,
19294,
2031,
589,
12,
1011,
958,
304,
267,
2288,
16547,
398,
1453,
63,
1943,
275,
6485,
14,
1818,
1943,
342,
267,
1676,
63,
1943,
275,
6485,
14,
362,
7837,
8444,
8,
1818,
63,
1943,
2788,
17,
61,
267,
1676,
63,
354,
275,
1676,
63,
1943,
59,
19,
61,
398,
1453,
63,
2926,
275,
12178,
8,
2324,
855,
354,
3368,
398,
340,
16547,
26,
288,
1453,
63,
2926,
14,
1708,
275,
1676,
63,
354,
288,
16547,
14,
740,
8,
1818,
63,
2926,
9,
267,
587,
26,
288,
16547,
275,
1453,
63,
2926,
398,
2203,
275,
4325,
2031,
589,
12,
1011,
958,
9,
398,
1453,
63,
2926,
14,
8960,
342,
267,
372,
2203,
339,
372,
543,
63,
496,
19294,
421,
199,
318,
30238,
63,
793,
837,
272,
408,
1002,
314,
30238,
9610,
1041,
272,
2288,
16547,
272,
372,
16547,
421,
199,
318,
5436,
63,
14979,
63,
576,
837,
272,
2288,
16547,
272,
16547,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
29,
1624,
13,
24,
199,
199,
624,
2765,
859,
3509,
9661,
367,
10238,
30238,
14,
199,
199,
2765,
1233,
1990,
9394,
687,
1455,
921,
23153,
14,
957,
15,
65,
15,
1344,
1165,
26433,
199,
199,
624,
199,
199,
646,
900,
199,
646,
6485,
199,
504,
9143,
492,
14018,
199,
504,
5048,
14,
16355,
14,
4844,
63,
6743,
492,
664,
63,
4624,
63,
4844,
199,
504,
5048,
14,
16355,
14,
1751,
492,
4260,
421,
199,
363,
7307,
363,
275,
298,
29933,
3572,
5244,
13747,
334,
5043,
2086,
351,
315,
3464,
15784,
395,
1010,
65,
27657,
2,
199,
363,
1682,
363,
275,
298,
5482,
1905,
7046,
4654,
2,
199,
363,
2123,
363,
275,
298,
815,
32,
262,
305,
6504,
14,
1308,
2,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
533,
12178,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
304,
398,
327,
2812,
402,
314,
1453,
805,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1708,
275,
488,
398,
327,
4703,
402,
7143,
267,
291,
423,
928,
63,
521,
275,
900,
14,
521,
342,
398,
327,
4703,
737,
314,
1284,
14,
267,
291,
423,
500,
63,
521,
275,
488,
398,
340,
4260,
8,
498,
534,
4844,
63,
2913,
297,
1420,
63,
466,
29,
2245,
304,
288,
327,
4402,
737,
7143,
288,
291,
423,
928,
63,
4844,
275,
664,
63,
4624,
63,
4844,
342,
953,
327,
4402,
737,
23868,
288,
291,
423,
500,
63,
4844,
275,
488,
398,
327,
12988,
828,
267,
291,
14,
3223,
275,
942,
339,
347,
22480,
8,
277,
304,
267,
408,
6004,
1240,
642,
1083,
1380,
314,
805,
365,
9158,
1041,
267,
291,
423,
500,
63,
521,
275,
900,
14,
521,
342,
398,
340,
4260,
8,
498,
534,
4844,
63,
2913,
297,
1420,
63,
466,
29,
2245,
304,
288,
291,
423,
500,
63,
4844,
275,
664,
63,
4624,
63,
4844,
342,
339,
768,
1829,
272,
347,
14439,
63,
521,
8,
277,
304,
267,
408,
1378,
5715,
314,
7373,
402,
314,
805,
14,
398,
961,
3324,
5594,
372,
488,
340,
314,
805,
365,
5139,
3879,
14,
267,
408,
267,
340,
291,
423,
500,
63,
521,
26,
288,
14439,
63,
521,
275,
6168,
8,
277,
423,
500,
63,
521,
446,
291,
423,
928,
63,
521,
12,
650,
9,
288,
372,
14439,
63,
521,
267,
587,
26,
288,
372,
488,
339,
768,
1829,
272,
347,
4402,
63,
2972,
8,
277,
304,
267,
408,
1378,
5715,
314,
17659,
4402,
737,
805,
23868,
14,
398,
2508,
1023,
3270,
447,
841,
14,
17,
398,
961,
3324,
5594,
372,
488,
340,
314,
805,
365,
5139,
3879,
14,
398,
961,
805,
1077,
1720,
370,
2498,
4402,
1026,
14631,
503,
21394,
486,
24737,
1233,
14,
267,
408,
267,
340,
291,
423,
500,
63,
4844,
26,
288,
4402,
63,
2972,
275,
291,
423,
500,
63,
4844,
446,
291,
423,
928,
63,
4844,
288,
372,
4402,
63,
2972,
267,
587,
26,
288,
372,
488,
339,
347,
5666,
8,
277,
12,
1031,
304,
267,
408,
1378,
5666,
282,
892,
1982,
1041,
267,
340,
1031,
14,
1708,
508,
291,
14,
498,
436,
440,
291,
14,
16691,
63,
521,
26,
288,
291,
14,
3223,
14,
740,
8,
932,
9,
267,
587,
26,
288,
327,
18306,
3398,
1240,
288,
367,
1982,
315,
291,
14,
3223,
26,
355,
340,
440,
1982,
14,
16691,
63,
521,
26,
490,
1982,
14,
740,
8,
932,
9,
339,
347,
636,
495,
721,
277,
304,
267,
327,
2779,
5594,
506,
282,
5726,
805,
14,
267,
3650,
275,
291,
14,
498,
14,
10124,
26341,
398,
327,
14402,
485,
701,
282,
4601,
267,
3650,
275,
3650,
14,
1814,
20928,
283,
5320,
398,
327,
22516,
6910,
794,
1642,
8082,
267,
3650,
275,
3650,
14,
18351,
342,
398,
372,
3650,
199,
199,
5441,
275,
488,
421,
199,
318,
4690,
8,
2324,
304,
272,
768,
13582,
8,
2324,
9,
272,
347,
543,
63,
496,
19294,
2031,
589,
12,
1011,
958,
304,
267,
2288,
16547,
398,
1453,
63,
1943,
275,
6485,
14,
1818,
1943,
342,
267,
1676,
63,
1943,
275,
6485,
14,
362,
7837,
8444,
8,
1818,
63,
1943,
2788,
17,
61,
267,
1676,
63,
354,
275,
1676,
63,
1943,
59,
19,
61,
398,
1453,
63,
2926,
275,
12178,
8,
2324,
855,
354,
3368,
398,
340,
16547,
26,
288,
1453,
63,
2926,
14,
1708,
275,
1676,
63,
354,
288,
16547,
14,
740,
8,
1818,
63,
2926,
9,
267,
587,
26,
288,
16547,
275,
1453,
63,
2926,
398,
2203,
275,
4325,
2031,
589,
12,
1011,
958,
9,
398,
1453,
63,
2926,
14,
8960,
342,
267,
372,
2203,
339,
372,
543,
63,
496,
19294,
421,
199,
318,
30238,
63,
793,
837,
272,
408,
1002,
314,
30238,
9610,
1041,
272,
2288,
16547,
272,
372,
16547,
421,
199,
318,
5436,
63,
14979,
63,
576,
837,
272,
2288,
16547,
272,
16547,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Big-B702/python-for-android
|
python3-alpha/python3-src/Lib/html/parser.py
|
45
|
16340
|
"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags are special)
# and CDATA (character data -- only end tags are special).
import _markupbase
import re
# Regular expressions used for parsing
interesting_normal = re.compile('[&<]')
interesting_cdata = re.compile(r'<(/|\Z)')
incomplete = re.compile('&[a-zA-Z#]')
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
charref = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
starttagopen = re.compile('<[a-zA-Z]')
piclose = re.compile('>')
commentclose = re.compile(r'--\s*>')
tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
# Note, the strict one of this pair isn't really strict, but we can't
# make it correctly strict without breaking backward compatibility.
attrfind = re.compile(
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?')
attrfind_tolerant = re.compile(
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[^>\s]*))?')
locatestarttagend = re.compile(r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
(?:\s+ # whitespace before attribute name
(?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name
(?:\s*=\s* # value indicator
(?:'[^']*' # LITA-enclosed value
|\"[^\"]*\" # LIT-enclosed value
|[^'\">\s]+ # bare value
)
)?
)
)*
\s* # trailing whitespace
""", re.VERBOSE)
locatestarttagend_tolerant = re.compile(r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
(?:\s* # optional whitespace before attribute name
(?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name
(?:\s*=\s* # value indicator
(?:'[^']*' # LITA-enclosed value
|\"[^\"]*\" # LIT-enclosed value
|[^'\">\s]+ # bare value
)
(?:\s*,)* # possibly followed by a comma
)?
)
)*
\s* # trailing whitespace
""", re.VERBOSE)
endendtag = re.compile('>')
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
class HTMLParseError(Exception):
"""Exception raised for all parse errors."""
def __init__(self, msg, position=(None, None)):
assert msg
self.msg = msg
self.lineno = position[0]
self.offset = position[1]
def __str__(self):
result = self.msg
if self.lineno is not None:
result = result + ", at line %d" % self.lineno
if self.offset is not None:
result = result + ", column %d" % (self.offset + 1)
return result
class HTMLParser(_markupbase.ParserBase):
"""Find tags and other markup and call handler functions.
Usage:
p = HTMLParser()
p.feed(data)
...
p.close()
Start tags are handled by calling self.handle_starttag() or
self.handle_startendtag(); end tags by self.handle_endtag(). The
data between tags is passed from the parser to the derived class
by calling self.handle_data() with the data as argument (the data
may be split up in arbitrary chunks). Entity references are
passed by calling self.handle_entityref() with the entity
reference as the argument. Numeric character references are
passed to self.handle_charref() with the string containing the
reference as the argument.
"""
CDATA_CONTENT_ELEMENTS = ("script", "style")
def __init__(self, strict=True):
"""Initialize and reset this instance.
If strict is set to True (the default), errors are raised when invalid
HTML is encountered. If set to False, an attempt is instead made to
continue parsing, making "best guesses" about the intended meaning, in
a fashion similar to what browsers typically do.
"""
self.strict = strict
self.reset()
def reset(self):
"""Reset this instance. Loses all unprocessed data."""
self.rawdata = ''
self.lasttag = '???'
self.interesting = interesting_normal
_markupbase.ParserBase.reset(self)
def feed(self, data):
r"""Feed data to the parser.
Call this as often as you want, with as little or as much text
as you want (may include '\n').
"""
self.rawdata = self.rawdata + data
self.goahead(0)
def close(self):
"""Handle any buffered data."""
self.goahead(1)
def error(self, message):
raise HTMLParseError(message, self.getpos())
__starttag_text = None
def get_starttag_text(self):
"""Return full source of start tag: '<...>'."""
return self.__starttag_text
def set_cdata_mode(self):
self.interesting = interesting_cdata
def clear_cdata_mode(self):
self.interesting = interesting_normal
# Internal -- handle data as far as reasonable. May leave state
# and data to be processed by a subsequent call. If 'end' is
# true, force handling all data as if followed by EOF marker.
def goahead(self, end):
rawdata = self.rawdata
i = 0
n = len(rawdata)
while i < n:
match = self.interesting.search(rawdata, i) # < or &
if match:
j = match.start()
else:
j = n
if i < j: self.handle_data(rawdata[i:j])
i = self.updatepos(i, j)
if i == n: break
startswith = rawdata.startswith
if startswith('<', i):
if starttagopen.match(rawdata, i): # < + letter
k = self.parse_starttag(i)
elif startswith("</", i):
k = self.parse_endtag(i)
elif startswith("<!--", i):
k = self.parse_comment(i)
elif startswith("<?", i):
k = self.parse_pi(i)
elif startswith("<!", i):
k = self.parse_declaration(i)
elif (i + 1) < n:
self.handle_data("<")
k = i + 1
else:
break
if k < 0:
if not end:
break
if self.strict:
self.error("EOF in middle of construct")
k = rawdata.find('>', i + 1)
if k < 0:
k = rawdata.find('<', i + 1)
if k < 0:
k = i + 1
else:
k += 1
self.handle_data(rawdata[i:k])
i = self.updatepos(i, k)
elif startswith("&#", i):
match = charref.match(rawdata, i)
if match:
name = match.group()[2:-1]
self.handle_charref(name)
k = match.end()
if not startswith(';', k-1):
k = k - 1
i = self.updatepos(i, k)
continue
else:
if ";" in rawdata[i:]: #bail by consuming &#
self.handle_data(rawdata[0:2])
i = self.updatepos(i, 2)
break
elif startswith('&', i):
match = entityref.match(rawdata, i)
if match:
name = match.group(1)
self.handle_entityref(name)
k = match.end()
if not startswith(';', k-1):
k = k - 1
i = self.updatepos(i, k)
continue
match = incomplete.match(rawdata, i)
if match:
# match.group() will contain at least 2 chars
if end and match.group() == rawdata[i:]:
if self.strict:
self.error("EOF in middle of entity or char ref")
else:
if k <= i:
k = n
i = self.updatepos(i, i + 1)
# incomplete
break
elif (i + 1) < n:
# not the end of the buffer, and can't be confused
# with some other construct
self.handle_data("&")
i = self.updatepos(i, i + 1)
else:
break
else:
assert 0, "interesting.search() lied"
# end while
if end and i < n:
self.handle_data(rawdata[i:n])
i = self.updatepos(i, n)
self.rawdata = rawdata[i:]
# Internal -- parse processing instr, return end or -1 if not terminated
def parse_pi(self, i):
rawdata = self.rawdata
assert rawdata[i:i+2] == '<?', 'unexpected call to parse_pi()'
match = piclose.search(rawdata, i+2) # >
if not match:
return -1
j = match.start()
self.handle_pi(rawdata[i+2: j])
j = match.end()
return j
# Internal -- handle starttag, return end or -1 if not terminated
def parse_starttag(self, i):
self.__starttag_text = None
endpos = self.check_for_whole_start_tag(i)
if endpos < 0:
return endpos
rawdata = self.rawdata
self.__starttag_text = rawdata[i:endpos]
# Now parse the data between i+1 and j into a tag and attrs
attrs = []
match = tagfind.match(rawdata, i+1)
assert match, 'unexpected call to parse_starttag()'
k = match.end()
self.lasttag = tag = rawdata[i+1:k].lower()
while k < endpos:
if self.strict:
m = attrfind.match(rawdata, k)
else:
m = attrfind_tolerant.search(rawdata, k)
if not m:
break
attrname, rest, attrvalue = m.group(1, 2, 3)
if not rest:
attrvalue = None
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
attrvalue[:1] == '"' == attrvalue[-1:]:
attrvalue = attrvalue[1:-1]
attrvalue = self.unescape(attrvalue)
attrs.append((attrname.lower(), attrvalue))
k = m.end()
end = rawdata[k:endpos].strip()
if end not in (">", "/>"):
lineno, offset = self.getpos()
if "\n" in self.__starttag_text:
lineno = lineno + self.__starttag_text.count("\n")
offset = len(self.__starttag_text) \
- self.__starttag_text.rfind("\n")
else:
offset = offset + len(self.__starttag_text)
if self.strict:
self.error("junk characters in start tag: %r"
% (rawdata[k:endpos][:20],))
self.handle_data(rawdata[i:endpos])
return endpos
if end.endswith('/>'):
# XHTML-style empty tag: <span attr="value" />
self.handle_startendtag(tag, attrs)
else:
self.handle_starttag(tag, attrs)
if tag in self.CDATA_CONTENT_ELEMENTS:
self.set_cdata_mode()
return endpos
# Internal -- check to see if we have a complete starttag; return end
# or -1 if incomplete.
def check_for_whole_start_tag(self, i):
rawdata = self.rawdata
if self.strict:
m = locatestarttagend.match(rawdata, i)
else:
m = locatestarttagend_tolerant.match(rawdata, i)
if m:
j = m.end()
next = rawdata[j:j+1]
if next == ">":
return j + 1
if next == "/":
if rawdata.startswith("/>", j):
return j + 2
if rawdata.startswith("/", j):
# buffer boundary
return -1
# else bogus input
if self.strict:
self.updatepos(i, j + 1)
self.error("malformed empty start tag")
if j > i:
return j
else:
return i + 1
if next == "":
# end of input
return -1
if next in ("abcdefghijklmnopqrstuvwxyz=/"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
# end of input in or before attribute value, or we have the
# '/' from a '/>' ending
return -1
if self.strict:
self.updatepos(i, j)
self.error("malformed start tag")
if j > i:
return j
else:
return i + 1
raise AssertionError("we should not get here!")
# Internal -- parse endtag, return end or -1 if incomplete
def parse_endtag(self, i):
rawdata = self.rawdata
assert rawdata[i:i+2] == "</", "unexpected call to parse_endtag"
match = endendtag.search(rawdata, i+1) # >
if not match:
return -1
j = match.end()
match = endtagfind.match(rawdata, i) # </ + tag + >
if not match:
if self.strict:
self.error("bad end tag: %r" % (rawdata[i:j],))
k = rawdata.find('<', i + 1, j)
if k > i:
j = k
if j <= i:
j = i + 1
self.handle_data(rawdata[i:j])
return j
tag = match.group(1)
self.handle_endtag(tag.lower())
self.clear_cdata_mode()
return j
# Overridable -- finish processing of start+end tag: <tag.../>
def handle_startendtag(self, tag, attrs):
self.handle_starttag(tag, attrs)
self.handle_endtag(tag)
# Overridable -- handle start tag
def handle_starttag(self, tag, attrs):
pass
# Overridable -- handle end tag
def handle_endtag(self, tag):
pass
# Overridable -- handle character reference
def handle_charref(self, name):
pass
# Overridable -- handle entity reference
def handle_entityref(self, name):
pass
# Overridable -- handle data
def handle_data(self, data):
pass
# Overridable -- handle comment
def handle_comment(self, data):
pass
# Overridable -- handle declaration
def handle_decl(self, decl):
pass
# Overridable -- handle processing instruction
def handle_pi(self, data):
pass
def unknown_decl(self, data):
if self.strict:
self.error("unknown declaration: %r" % (data,))
# Internal -- helper to remove special character quoting
entitydefs = None
def unescape(self, s):
if '&' not in s:
return s
def replaceEntities(s):
s = s.groups()[0]
try:
if s[0] == "#":
s = s[1:]
if s[0] in ['x','X']:
c = int(s[1:], 16)
else:
c = int(s)
return chr(c)
except ValueError:
return '&#'+ s +';'
else:
# Cannot use name2codepoint directly, because HTMLParser
# supports apos, which is not part of HTML 4
import html.entities
if HTMLParser.entitydefs is None:
entitydefs = HTMLParser.entitydefs = {'apos':"'"}
for k, v in html.entities.name2codepoint.items():
entitydefs[k] = chr(v)
try:
return self.entitydefs[s]
except KeyError:
return '&'+s+';'
return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
replaceEntities, s, re.ASCII)
|
apache-2.0
|
[
624,
33,
1798,
367,
4163,
436,
26223,
1041,
199,
199,
3,
961,
570,
365,
4079,
641,
12578,
25598,
14,
647,
12,
1325,
314,
3261,
365,
18023,
3365,
14,
199,
199,
3,
5787,
6006,
1077,
506,
282,
4340,
370,
22237,
3382,
510,
14049,
334,
6751,
199,
3,
4528,
666,
1553,
314,
3293,
1930,
395,
820,
14049,
334,
1814,
461,
4528,
199,
3,
666,
1553,
1454,
1495,
436,
4642,
6941,
436,
1284,
3762,
787,
4539,
9,
199,
3,
436,
445,
3998,
334,
10856,
666,
1553,
1454,
1284,
3762,
787,
4539,
680,
421,
199,
646,
485,
10131,
1095,
199,
646,
295,
199,
199,
3,
18528,
8455,
1202,
367,
6057,
199,
199,
30267,
63,
3302,
275,
295,
14,
2014,
11894,
6,
28,
10374,
199,
30267,
63,
15892,
275,
295,
14,
2014,
8,
82,
7601,
29478,
6113,
58,
5942,
199,
24575,
275,
295,
14,
2014,
20040,
59,
65,
13,
6353,
13,
58,
3,
10374,
199,
199,
4502,
1121,
275,
295,
14,
2014,
20040,
779,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
2788,
62,
65,
13,
6353,
13,
58,
16,
13,
25,
10374,
199,
24253,
275,
295,
14,
2014,
360,
7997,
25060,
16,
13,
25,
2807,
17884,
24110,
1527,
16,
13,
25,
65,
13,
13753,
13,
38,
2807,
2788,
62,
16,
13,
25,
65,
13,
13753,
13,
38,
10374,
199,
199,
15234,
1490,
275,
295,
14,
2014,
4827,
59,
65,
13,
6353,
13,
58,
10374,
199,
12475,
22641,
275,
295,
14,
2014,
28781,
199,
3349,
1600,
275,
295,
14,
2014,
8,
82,
27529,
60,
83,
10,
5971,
199,
1450,
1623,
275,
295,
14,
2014,
11894,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
358,
199,
3,
3390,
12,
314,
7478,
1373,
402,
642,
4092,
5712,
1133,
7710,
7478,
12,
1325,
781,
883,
1133,
199,
3,
1852,
652,
6657,
7478,
1928,
27485,
13388,
7163,
14,
199,
962,
1623,
275,
295,
14,
2014,
8,
272,
519,
1154,
83,
10,
779,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
63,
16,
13,
25,
3672,
10127,
83,
23440,
83,
10223,
272,
519,
13445,
29538,
20445,
3985,
25576,
25153,
12469,
92,
16045,
83,
3212,
7,
18987,
8637,
3672,
430,
18478,
199,
962,
1623,
63,
475,
1435,
867,
275,
295,
14,
2014,
8,
272,
519,
1154,
83,
10,
779,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
63,
16,
13,
25,
3672,
10127,
83,
23440,
83,
10223,
272,
519,
13445,
29538,
20445,
3985,
25576,
25153,
12469,
23629,
3072,
83,
3672,
430,
18478,
199,
6280,
15234,
500,
275,
295,
14,
2014,
8,
82,
624,
523,
665,
59,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
3515,
327,
1947,
536,
523,
7558,
3427,
83,
11,
17907,
327,
8139,
2544,
2225,
536,
272,
7558,
7766,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
258,
327,
2225,
536,
489,
7558,
3427,
83,
23440,
83,
10,
9326,
327,
574,
16385,
267,
16697,
16122,
418,
10223,
7861,
327,
491,
649,
33,
13,
287,
5938,
574,
881,
1204,
4451,
16045,
937,
10,
4451,
4483,
327,
491,
649,
13,
287,
5938,
574,
881,
1204,
4735,
1154,
14559,
83,
2807,
4483,
327,
18753,
574,
268,
776,
2126,
24836,
1362,
776,
2043,
776,
10,
523,
971,
83,
10,
13293,
327,
8520,
8139,
199,
7208,
295,
14,
16075,
9,
199,
6280,
15234,
500,
63,
475,
1435,
867,
275,
295,
14,
2014,
8,
82,
624,
523,
665,
59,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
3515,
327,
1947,
536,
523,
7558,
3427,
83,
10,
17907,
327,
2716,
8139,
2544,
2225,
536,
272,
7558,
7766,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
258,
327,
2225,
536,
489,
7558,
3427,
83,
23440,
83,
10,
9326,
327,
574,
16385,
267,
16697,
16122,
418,
10223,
7861,
327,
491,
649,
33,
13,
287,
5938,
574,
881,
1204,
4451,
16045,
937,
10,
4451,
4483,
327,
491,
649,
13,
287,
5938,
574,
881,
1204,
4735,
1154,
14559,
83,
2807,
4483,
327,
18753,
574,
268,
776,
268,
7558,
3427,
83,
10381,
3342,
7861,
327,
12570,
9437,
701,
282,
10029,
2126,
24836,
1362,
776,
2043,
776,
10,
523,
971,
83,
10,
13293,
327,
8520,
8139,
199,
7208,
295,
14,
16075,
9,
199,
287,
32588,
1450,
275,
295,
14,
2014,
28781,
199,
25765,
1623,
275,
295,
14,
2014,
14264,
60,
83,
10,
779,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
2862,
83,
10,
5971,
421,
199,
533,
4163,
9123,
8,
1726,
304,
272,
408,
1726,
4915,
367,
1006,
2198,
2552,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
3421,
2687,
403,
12,
488,
2298,
267,
702,
1499,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
3469,
275,
3421,
59,
16,
61,
267,
291,
14,
2743,
275,
3421,
59,
17,
61,
339,
347,
636,
495,
721,
277,
304,
267,
754,
275,
291,
14,
1328,
267,
340,
291,
14,
3469,
365,
440,
488,
26,
288,
754,
275,
754,
435,
3872,
737,
1004,
450,
68,
2,
450,
291,
14,
3469,
267,
340,
291,
14,
2743,
365,
440,
488,
26,
288,
754,
275,
754,
435,
3872,
2763,
450,
68,
2,
450,
334,
277,
14,
2743,
435,
413,
9,
267,
372,
754,
421,
199,
533,
24581,
1547,
10131,
1095,
14,
2842,
1563,
304,
272,
408,
6591,
3762,
436,
1163,
9189,
436,
1240,
3016,
3423,
14,
339,
11028,
26,
267,
299,
275,
24581,
342,
267,
299,
14,
3871,
8,
576,
9,
267,
2263,
267,
299,
14,
1600,
342,
339,
7707,
3762,
787,
8860,
701,
6358,
291,
14,
2479,
63,
15234,
342,
503,
272,
291,
14,
2479,
63,
7848,
7169,
1450,
7303,
1284,
3762,
701,
291,
14,
2479,
63,
25765,
1252,
221,
710,
272,
666,
3382,
3762,
365,
3032,
687,
314,
1798,
370,
314,
7131,
1021,
272,
701,
6358,
291,
14,
2479,
63,
576,
342,
543,
314,
666,
465,
1423,
334,
1589,
666,
272,
1443,
506,
3715,
1536,
315,
9697,
8291,
680,
221,
17680,
6941,
787
] |
[
33,
1798,
367,
4163,
436,
26223,
1041,
199,
199,
3,
961,
570,
365,
4079,
641,
12578,
25598,
14,
647,
12,
1325,
314,
3261,
365,
18023,
3365,
14,
199,
199,
3,
5787,
6006,
1077,
506,
282,
4340,
370,
22237,
3382,
510,
14049,
334,
6751,
199,
3,
4528,
666,
1553,
314,
3293,
1930,
395,
820,
14049,
334,
1814,
461,
4528,
199,
3,
666,
1553,
1454,
1495,
436,
4642,
6941,
436,
1284,
3762,
787,
4539,
9,
199,
3,
436,
445,
3998,
334,
10856,
666,
1553,
1454,
1284,
3762,
787,
4539,
680,
421,
199,
646,
485,
10131,
1095,
199,
646,
295,
199,
199,
3,
18528,
8455,
1202,
367,
6057,
199,
199,
30267,
63,
3302,
275,
295,
14,
2014,
11894,
6,
28,
10374,
199,
30267,
63,
15892,
275,
295,
14,
2014,
8,
82,
7601,
29478,
6113,
58,
5942,
199,
24575,
275,
295,
14,
2014,
20040,
59,
65,
13,
6353,
13,
58,
3,
10374,
199,
199,
4502,
1121,
275,
295,
14,
2014,
20040,
779,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
2788,
62,
65,
13,
6353,
13,
58,
16,
13,
25,
10374,
199,
24253,
275,
295,
14,
2014,
360,
7997,
25060,
16,
13,
25,
2807,
17884,
24110,
1527,
16,
13,
25,
65,
13,
13753,
13,
38,
2807,
2788,
62,
16,
13,
25,
65,
13,
13753,
13,
38,
10374,
199,
199,
15234,
1490,
275,
295,
14,
2014,
4827,
59,
65,
13,
6353,
13,
58,
10374,
199,
12475,
22641,
275,
295,
14,
2014,
28781,
199,
3349,
1600,
275,
295,
14,
2014,
8,
82,
27529,
60,
83,
10,
5971,
199,
1450,
1623,
275,
295,
14,
2014,
11894,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
358,
199,
3,
3390,
12,
314,
7478,
1373,
402,
642,
4092,
5712,
1133,
7710,
7478,
12,
1325,
781,
883,
1133,
199,
3,
1852,
652,
6657,
7478,
1928,
27485,
13388,
7163,
14,
199,
962,
1623,
275,
295,
14,
2014,
8,
272,
519,
1154,
83,
10,
779,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
63,
16,
13,
25,
3672,
10127,
83,
23440,
83,
10223,
272,
519,
13445,
29538,
20445,
3985,
25576,
25153,
12469,
92,
16045,
83,
3212,
7,
18987,
8637,
3672,
430,
18478,
199,
962,
1623,
63,
475,
1435,
867,
275,
295,
14,
2014,
8,
272,
519,
1154,
83,
10,
779,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
63,
16,
13,
25,
3672,
10127,
83,
23440,
83,
10223,
272,
519,
13445,
29538,
20445,
3985,
25576,
25153,
12469,
23629,
3072,
83,
3672,
430,
18478,
199,
6280,
15234,
500,
275,
295,
14,
2014,
8,
82,
624,
523,
665,
59,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
3515,
327,
1947,
536,
523,
7558,
3427,
83,
11,
17907,
327,
8139,
2544,
2225,
536,
272,
7558,
7766,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
258,
327,
2225,
536,
489,
7558,
3427,
83,
23440,
83,
10,
9326,
327,
574,
16385,
267,
16697,
16122,
418,
10223,
7861,
327,
491,
649,
33,
13,
287,
5938,
574,
881,
1204,
4451,
16045,
937,
10,
4451,
4483,
327,
491,
649,
13,
287,
5938,
574,
881,
1204,
4735,
1154,
14559,
83,
2807,
4483,
327,
18753,
574,
268,
776,
2126,
24836,
1362,
776,
2043,
776,
10,
523,
971,
83,
10,
13293,
327,
8520,
8139,
199,
7208,
295,
14,
16075,
9,
199,
6280,
15234,
500,
63,
475,
1435,
867,
275,
295,
14,
2014,
8,
82,
624,
523,
665,
59,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
3515,
327,
1947,
536,
523,
7558,
3427,
83,
10,
17907,
327,
2716,
8139,
2544,
2225,
536,
272,
7558,
7766,
65,
13,
6353,
13,
58,
63,
15898,
16781,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
258,
327,
2225,
536,
489,
7558,
3427,
83,
23440,
83,
10,
9326,
327,
574,
16385,
267,
16697,
16122,
418,
10223,
7861,
327,
491,
649,
33,
13,
287,
5938,
574,
881,
1204,
4451,
16045,
937,
10,
4451,
4483,
327,
491,
649,
13,
287,
5938,
574,
881,
1204,
4735,
1154,
14559,
83,
2807,
4483,
327,
18753,
574,
268,
776,
268,
7558,
3427,
83,
10381,
3342,
7861,
327,
12570,
9437,
701,
282,
10029,
2126,
24836,
1362,
776,
2043,
776,
10,
523,
971,
83,
10,
13293,
327,
8520,
8139,
199,
7208,
295,
14,
16075,
9,
199,
287,
32588,
1450,
275,
295,
14,
2014,
28781,
199,
25765,
1623,
275,
295,
14,
2014,
14264,
60,
83,
10,
779,
65,
13,
6353,
13,
58,
15898,
14,
65,
13,
6353,
13,
58,
16,
13,
25,
26,
15555,
2862,
83,
10,
5971,
421,
199,
533,
4163,
9123,
8,
1726,
304,
272,
408,
1726,
4915,
367,
1006,
2198,
2552,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
3421,
2687,
403,
12,
488,
2298,
267,
702,
1499,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
3469,
275,
3421,
59,
16,
61,
267,
291,
14,
2743,
275,
3421,
59,
17,
61,
339,
347,
636,
495,
721,
277,
304,
267,
754,
275,
291,
14,
1328,
267,
340,
291,
14,
3469,
365,
440,
488,
26,
288,
754,
275,
754,
435,
3872,
737,
1004,
450,
68,
2,
450,
291,
14,
3469,
267,
340,
291,
14,
2743,
365,
440,
488,
26,
288,
754,
275,
754,
435,
3872,
2763,
450,
68,
2,
450,
334,
277,
14,
2743,
435,
413,
9,
267,
372,
754,
421,
199,
533,
24581,
1547,
10131,
1095,
14,
2842,
1563,
304,
272,
408,
6591,
3762,
436,
1163,
9189,
436,
1240,
3016,
3423,
14,
339,
11028,
26,
267,
299,
275,
24581,
342,
267,
299,
14,
3871,
8,
576,
9,
267,
2263,
267,
299,
14,
1600,
342,
339,
7707,
3762,
787,
8860,
701,
6358,
291,
14,
2479,
63,
15234,
342,
503,
272,
291,
14,
2479,
63,
7848,
7169,
1450,
7303,
1284,
3762,
701,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
oskar456/youtube-dl
|
youtube_dl/extractor/safari.py
|
6
|
6969
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
ExtractorError,
sanitized_Request,
std_headers,
urlencode_postdata,
update_url_query,
)
class SafariBaseIE(InfoExtractor):
_LOGIN_URL = 'https://www.safaribooksonline.com/accounts/login/'
_NETRC_MACHINE = 'safari'
_API_BASE = 'https://www.safaribooksonline.com/api/v1'
_API_FORMAT = 'json'
LOGGED_IN = False
def _real_initialize(self):
self._login()
def _login(self):
(username, password) = self._get_login_info()
if username is None:
return
headers = std_headers.copy()
if 'Referer' not in headers:
headers['Referer'] = self._LOGIN_URL
login_page = self._download_webpage(
self._LOGIN_URL, None, 'Downloading login form', headers=headers)
def is_logged(webpage):
return any(re.search(p, webpage) for p in (
r'href=["\']/accounts/logout/', r'>Sign Out<'))
if is_logged(login_page):
self.LOGGED_IN = True
return
csrf = self._html_search_regex(
r"name='csrfmiddlewaretoken'\s+value='([^']+)'",
login_page, 'csrf token')
login_form = {
'csrfmiddlewaretoken': csrf,
'email': username,
'password1': password,
'login': 'Sign In',
'next': '',
}
request = sanitized_Request(
self._LOGIN_URL, urlencode_postdata(login_form), headers=headers)
login_page = self._download_webpage(
request, None, 'Logging in')
if not is_logged(login_page):
raise ExtractorError(
'Login failed; make sure your credentials are correct and try again.',
expected=True)
self.LOGGED_IN = True
class SafariIE(SafariBaseIE):
IE_NAME = 'safari'
IE_DESC = 'safaribooksonline.com online video'
_VALID_URL = r'https?://(?:www\.)?safaribooksonline\.com/library/view/[^/]+/(?P<course_id>[^/]+)/(?P<part>[^/?#&]+)\.html'
_TESTS = [{
'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/part00.html',
'md5': 'dcc5a425e79f2564148652616af1f2a3',
'info_dict': {
'id': '0_qbqx90ic',
'ext': 'mp4',
'title': 'Introduction to Hadoop Fundamentals LiveLessons',
'timestamp': 1437758058,
'upload_date': '20150724',
'uploader_id': 'stork',
},
}, {
# non-digits in course id
'url': 'https://www.safaribooksonline.com/library/view/create-a-nodejs/100000006A0210/part00.html',
'only_matching': True,
}, {
'url': 'https://www.safaribooksonline.com/library/view/learning-path-red/9780134664057/RHCE_Introduction.html',
'only_matching': True,
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = '%s/%s' % (mobj.group('course_id'), mobj.group('part'))
webpage = self._download_webpage(url, video_id)
reference_id = self._search_regex(
r'data-reference-id=(["\'])(?P<id>(?:(?!\1).)+)\1',
webpage, 'kaltura reference id', group='id')
partner_id = self._search_regex(
r'data-partner-id=(["\'])(?P<id>(?:(?!\1).)+)\1',
webpage, 'kaltura widget id', group='id')
ui_id = self._search_regex(
r'data-ui-id=(["\'])(?P<id>(?:(?!\1).)+)\1',
webpage, 'kaltura uiconf id', group='id')
query = {
'wid': '_%s' % partner_id,
'uiconf_id': ui_id,
'flashvars[referenceId]': reference_id,
}
if self.LOGGED_IN:
kaltura_session = self._download_json(
'%s/player/kaltura_session/?reference_id=%s' % (self._API_BASE, reference_id),
video_id, 'Downloading kaltura session JSON',
'Unable to download kaltura session JSON', fatal=False)
if kaltura_session:
session = kaltura_session.get('session')
if session:
query['flashvars[ks]'] = session
return self.url_result(update_url_query(
'https://cdnapisec.kaltura.com/html5/html5lib/v2.37.1/mwEmbedFrame.php', query),
'Kaltura')
class SafariApiIE(SafariBaseIE):
IE_NAME = 'safari:api'
_VALID_URL = r'https?://(?:www\.)?safaribooksonline\.com/api/v1/book/(?P<course_id>[^/]+)/chapter(?:-content)?/(?P<part>[^/?#&]+)\.html'
_TESTS = [{
'url': 'https://www.safaribooksonline.com/api/v1/book/9780133392838/chapter/part00.html',
'only_matching': True,
}, {
'url': 'https://www.safaribooksonline.com/api/v1/book/9780134664057/chapter/RHCE_Introduction.html',
'only_matching': True,
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
part = self._download_json(
url, '%s/%s' % (mobj.group('course_id'), mobj.group('part')),
'Downloading part JSON')
return self.url_result(part['web_url'], SafariIE.ie_key())
class SafariCourseIE(SafariBaseIE):
IE_NAME = 'safari:course'
IE_DESC = 'safaribooksonline.com online courses'
_VALID_URL = r'''(?x)
https?://
(?:
(?:www\.)?safaribooksonline\.com/(?:library/view/[^/]+|api/v1/book)|
techbus\.safaribooksonline\.com
)
/(?P<id>[^/]+)/?(?:[#?]|$)
'''
_TESTS = [{
'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/',
'info_dict': {
'id': '9780133392838',
'title': 'Hadoop Fundamentals LiveLessons',
},
'playlist_count': 22,
'skip': 'Requires safaribooksonline account credentials',
}, {
'url': 'https://www.safaribooksonline.com/api/v1/book/9781449396459/?override_format=json',
'only_matching': True,
}, {
'url': 'http://techbus.safaribooksonline.com/9780134426365',
'only_matching': True,
}]
def _real_extract(self, url):
course_id = self._match_id(url)
course_json = self._download_json(
'%s/book/%s/?override_format=%s' % (self._API_BASE, course_id, self._API_FORMAT),
course_id, 'Downloading course JSON')
if 'chapters' not in course_json:
raise ExtractorError(
'No chapters found for course %s' % course_id, expected=True)
entries = [
self.url_result(chapter, SafariApiIE.ie_key())
for chapter in course_json['chapters']]
course_title = course_json['title']
return self.playlist_result(entries, course_id, course_title)
|
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,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
31734,
63,
2017,
12,
272,
2418,
63,
2139,
12,
272,
16511,
63,
1932,
576,
12,
272,
1678,
63,
633,
63,
1131,
12,
199,
9,
421,
199,
533,
428,
2756,
759,
1563,
4332,
8,
18283,
304,
272,
485,
17208,
63,
2632,
275,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
8370,
15,
2886,
4805,
272,
485,
7278,
8205,
63,
20890,
275,
283,
2231,
70,
759,
7,
339,
485,
3735,
63,
5825,
275,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
1246,
15,
86,
17,
7,
272,
485,
3735,
63,
4807,
275,
283,
1001,
7,
339,
3412,
2916,
1149,
63,
568,
275,
756,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
340,
3434,
365,
488,
26,
288,
372,
398,
2323,
275,
2418,
63,
2139,
14,
1574,
342,
267,
340,
283,
28900,
7,
440,
315,
2323,
26,
288,
2323,
459,
28900,
418,
275,
291,
423,
17208,
63,
2632,
398,
4676,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
291,
423,
17208,
63,
2632,
12,
488,
12,
283,
18085,
4676,
1824,
297,
2323,
29,
2139,
9,
398,
347,
365,
63,
12419,
8,
12022,
304,
288,
372,
1263,
8,
264,
14,
1733,
8,
80,
12,
9248,
9,
367,
299,
315,
334,
355,
519,
7,
6399,
6270,
26889,
15,
8370,
15,
11646,
3678,
519,
8423,
4940,
6219,
28,
1333,
398,
340,
365,
63,
12419,
8,
2886,
63,
1606,
304,
288,
291,
14,
1484,
2916,
1149,
63,
568,
275,
715,
288,
372,
398,
19213,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
2,
354,
534,
10088,
5754,
1418,
1154,
83,
11,
585,
534,
7059,
21899,
3171,
401,
288,
4676,
63,
1606,
12,
283,
10088,
1526,
358,
398,
4676,
63,
964,
275,
469,
288,
283,
10088,
5754,
1418,
356,
19213,
12,
288,
283,
2123,
356,
3434,
12,
288,
283,
2060,
17,
356,
2505,
12,
288,
283,
2886,
356,
283,
4940,
1010,
297,
288,
283,
2184,
356,
3260,
267,
789,
398,
1056,
275,
31734,
63,
2017,
8,
288,
291,
423,
17208,
63,
2632,
12,
16511,
63,
1932,
576,
8,
2886,
63,
964,
395,
2323,
29,
2139,
9,
267,
4676,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
1056,
12,
488,
12,
283,
14054,
315,
358,
398,
340,
440,
365,
63,
12419,
8,
2886,
63,
1606,
304,
288,
746,
19783,
8,
355,
283,
8880,
3405,
27,
1852,
3238,
2195,
6235,
787,
3211,
436,
862,
4020,
3130,
355,
1420,
29,
549,
9,
398,
291,
14,
1484,
2916,
1149,
63,
568,
275,
715,
421,
199,
533,
428,
2756,
759,
4332,
8,
51,
2756,
759,
1563,
4332,
304,
272,
15292,
63,
2339,
275,
283,
2231,
70,
759,
7,
272,
15292,
63,
15119,
275,
283,
2231,
70,
759,
2706,
834,
604,
14,
957,
18470,
3991,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
2231,
70,
759,
2706,
834,
604,
4537,
957,
15,
4342,
15,
1345,
15,
26285,
9448,
48,
28,
1972,
63,
344,
26906,
2447,
2229,
48,
28,
2064,
13489,
10197,
3,
6,
18096,
14,
1360,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
15449,
13,
29569,
14040,
2551,
13,
6442,
2003,
4654,
15,
28690,
614,
29536,
1651,
1703,
15,
2064,
383,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
68,
2055,
21,
65,
24398,
69,
1965,
70,
821,
772,
1079,
15102,
25807,
2756,
17,
70,
18,
65,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
16,
63,
81,
23907,
88,
2710,
530,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
3241,
293,
5199,
370,
869,
11362,
481,
725,
14040,
2551,
24683,
10958,
4654,
297,
288,
283,
3954,
356,
29235,
12710,
1257,
2010,
12,
288,
283,
5064,
63,
602,
356,
283,
1797,
13583,
1194,
297,
288,
283,
13671,
63,
344,
356,
283,
270,
4708,
297,
267,
1660,
272,
1660,
469,
267,
327,
2222,
13,
7022,
315,
2518,
1305,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
981,
13,
65,
13,
932,
3596,
15,
17,
9084,
22,
33,
996,
709,
15,
2064,
383,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
10546,
13,
515,
13,
581,
15,
28690,
614,
12583,
12021,
1641,
15,
31809,
2089,
63,
3241,
293,
5199,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
1543,
83,
3149,
83,
7,
450,
334,
573,
468,
14,
923,
360,
1972,
63,
344,
659,
14208,
14,
923,
360,
2064,
1333,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
3659,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
4443,
13,
344,
30982,
3212,
1105,
2229,
48,
28,
344,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
297,
288,
9248,
12,
283,
75,
4478,
12417,
3659,
1305,
297,
1572,
534,
344,
358,
267,
5854,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
3899,
13,
344,
30982,
3212,
1105,
2229,
48,
28,
344,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
297,
288,
9248,
12,
283,
75,
4478,
12417,
3938,
1305,
297,
1572,
534,
344,
358,
267,
8574,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121
] |
[
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,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
31734,
63,
2017,
12,
272,
2418,
63,
2139,
12,
272,
16511,
63,
1932,
576,
12,
272,
1678,
63,
633,
63,
1131,
12,
199,
9,
421,
199,
533,
428,
2756,
759,
1563,
4332,
8,
18283,
304,
272,
485,
17208,
63,
2632,
275,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
8370,
15,
2886,
4805,
272,
485,
7278,
8205,
63,
20890,
275,
283,
2231,
70,
759,
7,
339,
485,
3735,
63,
5825,
275,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
1246,
15,
86,
17,
7,
272,
485,
3735,
63,
4807,
275,
283,
1001,
7,
339,
3412,
2916,
1149,
63,
568,
275,
756,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
340,
3434,
365,
488,
26,
288,
372,
398,
2323,
275,
2418,
63,
2139,
14,
1574,
342,
267,
340,
283,
28900,
7,
440,
315,
2323,
26,
288,
2323,
459,
28900,
418,
275,
291,
423,
17208,
63,
2632,
398,
4676,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
291,
423,
17208,
63,
2632,
12,
488,
12,
283,
18085,
4676,
1824,
297,
2323,
29,
2139,
9,
398,
347,
365,
63,
12419,
8,
12022,
304,
288,
372,
1263,
8,
264,
14,
1733,
8,
80,
12,
9248,
9,
367,
299,
315,
334,
355,
519,
7,
6399,
6270,
26889,
15,
8370,
15,
11646,
3678,
519,
8423,
4940,
6219,
28,
1333,
398,
340,
365,
63,
12419,
8,
2886,
63,
1606,
304,
288,
291,
14,
1484,
2916,
1149,
63,
568,
275,
715,
288,
372,
398,
19213,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
2,
354,
534,
10088,
5754,
1418,
1154,
83,
11,
585,
534,
7059,
21899,
3171,
401,
288,
4676,
63,
1606,
12,
283,
10088,
1526,
358,
398,
4676,
63,
964,
275,
469,
288,
283,
10088,
5754,
1418,
356,
19213,
12,
288,
283,
2123,
356,
3434,
12,
288,
283,
2060,
17,
356,
2505,
12,
288,
283,
2886,
356,
283,
4940,
1010,
297,
288,
283,
2184,
356,
3260,
267,
789,
398,
1056,
275,
31734,
63,
2017,
8,
288,
291,
423,
17208,
63,
2632,
12,
16511,
63,
1932,
576,
8,
2886,
63,
964,
395,
2323,
29,
2139,
9,
267,
4676,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
1056,
12,
488,
12,
283,
14054,
315,
358,
398,
340,
440,
365,
63,
12419,
8,
2886,
63,
1606,
304,
288,
746,
19783,
8,
355,
283,
8880,
3405,
27,
1852,
3238,
2195,
6235,
787,
3211,
436,
862,
4020,
3130,
355,
1420,
29,
549,
9,
398,
291,
14,
1484,
2916,
1149,
63,
568,
275,
715,
421,
199,
533,
428,
2756,
759,
4332,
8,
51,
2756,
759,
1563,
4332,
304,
272,
15292,
63,
2339,
275,
283,
2231,
70,
759,
7,
272,
15292,
63,
15119,
275,
283,
2231,
70,
759,
2706,
834,
604,
14,
957,
18470,
3991,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
2231,
70,
759,
2706,
834,
604,
4537,
957,
15,
4342,
15,
1345,
15,
26285,
9448,
48,
28,
1972,
63,
344,
26906,
2447,
2229,
48,
28,
2064,
13489,
10197,
3,
6,
18096,
14,
1360,
7,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
15449,
13,
29569,
14040,
2551,
13,
6442,
2003,
4654,
15,
28690,
614,
29536,
1651,
1703,
15,
2064,
383,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
68,
2055,
21,
65,
24398,
69,
1965,
70,
821,
772,
1079,
15102,
25807,
2756,
17,
70,
18,
65,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
16,
63,
81,
23907,
88,
2710,
530,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
3241,
293,
5199,
370,
869,
11362,
481,
725,
14040,
2551,
24683,
10958,
4654,
297,
288,
283,
3954,
356,
29235,
12710,
1257,
2010,
12,
288,
283,
5064,
63,
602,
356,
283,
1797,
13583,
1194,
297,
288,
283,
13671,
63,
344,
356,
283,
270,
4708,
297,
267,
1660,
272,
1660,
469,
267,
327,
2222,
13,
7022,
315,
2518,
1305,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
981,
13,
65,
13,
932,
3596,
15,
17,
9084,
22,
33,
996,
709,
15,
2064,
383,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
2231,
70,
759,
2706,
834,
604,
14,
957,
15,
4342,
15,
1345,
15,
10546,
13,
515,
13,
581,
15,
28690,
614,
12583,
12021,
1641,
15,
31809,
2089,
63,
3241,
293,
5199,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
1543,
83,
3149,
83,
7,
450,
334,
573,
468,
14,
923,
360,
1972,
63,
344,
659,
14208,
14,
923,
360,
2064,
1333,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
3659,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
4443,
13,
344,
30982,
3212,
1105,
2229,
48,
28,
344,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
297,
288,
9248,
12,
283,
75,
4478,
12417,
3659,
1305,
297,
1572,
534,
344,
358,
267,
5854,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
3899,
13,
344,
30982,
3212,
1105,
2229,
48,
28,
344,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
297,
288,
9248,
12,
283,
75,
4478,
12417,
3938,
1305,
297,
1572,
534,
344,
358,
267,
8574,
63,
344,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
5121,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Johnzero/erp
|
openerp/addons/edi/controllers/main.py
|
9
|
3764
|
import json
import textwrap
import simplejson
import werkzeug.wrappers
try:
# embedded
import openerp.addons.web.common.http as openerpweb
import openerp.addons.web.controllers.main as webmain
except ImportError:
# standalone
import web.common.http as openerpweb
import web.controllers.main as webmain
class EDI(openerpweb.Controller):
# http://hostname:8069/edi/view?db=XXXX&token=XXXXXXXXXXX
# http://hostname:8069/edi/import_url?url=URIEncodedURL
_cp_path = "/edi"
def template(self, req, mods='web,edi'):
self.wc = openerpweb.controllers_path['/web/webclient']
d = {}
d["js"] = "\n".join('<script type="text/javascript" src="%s"></script>'%i for i in self.wc.manifest_list(req, mods, 'js'))
d["css"] = "\n".join('<link rel="stylesheet" href="%s">'%i for i in self.wc.manifest_list(req, mods, 'css'))
d["modules"] = simplejson.dumps(mods.split(','))
return d
@openerpweb.httprequest
def view(self, req, db, token):
d = self.template(req)
d["init"] = 's.edi.edi_view("%s","%s");'%(db,token)
r = webmain.html_template % d
return r
@openerpweb.httprequest
def import_url(self, req, url):
d = self.template(req)
d["init"] = 's.edi.edi_import("%s");'%(url)
r = webmain.html_template % d
return r
@openerpweb.httprequest
def download(self, req, db, token):
result = req.session.proxy('edi').get_edi_document(db, token)
response = werkzeug.wrappers.Response( result, headers=[('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', len(result))])
return response
@openerpweb.httprequest
def download_attachment(self, req, db, token):
result = req.session.proxy('edi').get_edi_document(db, token)
doc = json.loads(result)[0]
attachment = doc['__attachments'] and doc['__attachments'][0]
if attachment:
result = attachment["content"].decode('base64')
import email.Utils as utils
# Encode as per RFC 2231
filename_utf8 = attachment['file_name']
filename_encoded = "%s=%s" % ('filename*',
utils.encode_rfc2231(filename_utf8, 'utf-8'))
response = werkzeug.wrappers.Response(result, headers=[('Content-Type', 'application/pdf'),
('Content-Disposition', 'inline; ' + filename_encoded),
('Content-Length', len(result))])
return response
@openerpweb.httprequest
def binary(self, req, db, token, field_path="company_address.logo", content_type='image/png'):
result = req.session.proxy('edi').get_edi_document(db, token)
doc = json.loads(result)[0]
for name in field_path.split("."):
doc = doc[name]
result = doc.decode('base64')
response = werkzeug.wrappers.Response(result, headers=[('Content-Type', content_type),
('Content-Length', len(result))])
return response
@openerpweb.jsonrequest
def get_edi_document(self, req, db, token):
result = req.session.proxy('edi').get_edi_document(db, token)
return json.loads(result)
@openerpweb.jsonrequest
def import_edi_url(self, req, url):
result = req.session.proxy('edi').import_edi_url(req.session._db, req.session._uid, req.session._password, url)
if len(result) == 1:
return {"action": webmain.clean_action(req, result[0][2])}
return True
#
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
646,
2022,
199,
646,
13390,
199,
199,
646,
13804,
199,
646,
10380,
14,
21148,
199,
199,
893,
26,
272,
327,
12169,
272,
492,
5166,
14,
10788,
14,
2520,
14,
2330,
14,
1014,
465,
5166,
2520,
272,
492,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
465,
3330,
973,
199,
2590,
3545,
26,
272,
327,
18042,
272,
492,
3330,
14,
2330,
14,
1014,
465,
5166,
2520,
272,
492,
3330,
14,
20531,
14,
973,
465,
3330,
973,
199,
199,
533,
662,
1914,
8,
11267,
2520,
14,
7506,
304,
272,
327,
1455,
921,
4269,
26,
1257,
1876,
15,
6297,
15,
1345,
31,
697,
29,
6873,
6,
1418,
29,
13312,
13933,
272,
327,
1455,
921,
4269,
26,
1257,
1876,
15,
6297,
15,
646,
63,
633,
31,
633,
29,
7639,
32149,
2632,
272,
485,
1850,
63,
515,
275,
3286,
6297,
2,
339,
347,
1978,
8,
277,
12,
2648,
12,
24496,
534,
2520,
12,
6297,
735,
267,
291,
14,
13683,
275,
5166,
2520,
14,
20531,
63,
515,
459,
15,
2520,
15,
2520,
1258,
418,
267,
366,
275,
1052,
267,
366,
905,
3596,
937,
275,
1867,
78,
1674,
904,
4827,
1579,
730,
628,
505,
15,
9554,
2,
2928,
5961,
83,
10070,
1579,
3524,
5,
73,
367,
284,
315,
291,
14,
13683,
14,
6418,
63,
513,
8,
2103,
12,
24496,
12,
283,
3596,
1333,
267,
366,
905,
3919,
937,
275,
1867,
78,
1674,
904,
4827,
1073,
4668,
628,
15479,
2,
4369,
5961,
83,
1743,
5956,
73,
367,
284,
315,
291,
14,
13683,
14,
6418,
63,
513,
8,
2103,
12,
24496,
12,
283,
3919,
1333,
267,
366,
905,
3112,
937,
275,
13804,
14,
4180,
8,
19709,
14,
1294,
5102,
1333,
267,
372,
366,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
2455,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
366,
275,
291,
14,
1160,
8,
2103,
9,
267,
366,
905,
826,
937,
275,
283,
83,
14,
6297,
14,
6297,
63,
1345,
3647,
83,
11890,
83,
3547,
13328,
697,
12,
1418,
9,
267,
519,
275,
3330,
973,
14,
1360,
63,
1160,
450,
366,
267,
372,
519,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
492,
63,
633,
8,
277,
12,
2648,
12,
1166,
304,
267,
366,
275,
291,
14,
1160,
8,
2103,
9,
267,
366,
905,
826,
937,
275,
283,
83,
14,
6297,
14,
6297,
63,
646,
3647,
83,
3547,
13328,
633,
9,
267,
519,
275,
3330,
973,
14,
1360,
63,
1160,
450,
366,
267,
372,
519,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
5235,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
754,
12,
2323,
11699,
2714,
13,
804,
297,
283,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
659,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
4960,
372,
1177,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
5235,
63,
8905,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1382,
275,
2022,
14,
3640,
8,
1099,
2788,
16,
61,
267,
12193,
275,
1382,
13742,
15855,
418,
436,
1382,
13742,
15855,
3488,
16,
61,
267,
340,
12193,
26,
288,
754,
275,
12193,
905,
1317,
4140,
2708,
360,
1095,
772,
358,
288,
492,
3031,
14,
7535,
465,
3778,
953,
327,
19244,
465,
1126,
7329,
499,
11921,
288,
1788,
63,
1624,
24,
275,
12193,
459,
493,
63,
354,
418,
288,
1788,
63,
8167,
275,
2071,
83,
2458,
83,
2,
450,
661,
1501,
7693,
5101,
3778,
14,
2143,
63,
8973,
27475,
8,
1501,
63,
1624,
24,
12,
283,
1624,
13,
24,
1333,
288,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
1099,
12,
2323,
11699,
2714,
13,
804,
297,
283,
3578,
15,
5607,
659,
28095,
661,
2714,
13,
15954,
297,
283,
6460,
27,
283,
435,
1788,
63,
8167,
395,
28095,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
288,
372,
1177,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
3366,
8,
277,
12,
2648,
12,
1592,
12,
1526,
12,
901,
63,
515,
628,
4627,
63,
1562,
14,
9733,
401,
1564,
63,
466,
534,
1569,
15,
4524,
735,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1382,
275,
2022,
14,
3640,
8,
1099,
2788,
16,
61,
267,
367,
536,
315,
901,
63,
515,
14,
1294,
480,
30946,
288,
1382,
275,
1382,
59,
354,
61,
267,
754,
275,
1382,
14,
2708,
360,
1095,
772,
358,
267,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
1099,
12,
2323,
11699,
2714,
13,
804,
297,
1564,
63,
466,
395,
17743,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
267,
372,
1177,
339,
768,
11267,
2520,
14,
1001,
1069,
272,
347,
664,
63,
6297,
63,
3554,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
372,
2022,
14,
3640,
8,
1099,
9,
339,
768,
11267,
2520,
14,
1001,
1069,
272,
347,
492,
63,
6297,
63,
633,
8,
277,
12,
2648,
12,
1166,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
646,
63,
6297,
63,
633,
8,
2103,
14,
1730,
423,
697,
12,
2648,
14,
1730,
423,
1535,
12,
2648,
14,
1730,
423,
2060,
12,
1166,
9,
267,
340,
822,
8,
1099,
9,
508,
413,
26,
288,
372,
2420,
1287,
582,
3330,
973,
14,
3118,
63,
1287,
8,
2103,
12,
754,
59,
16,
1527,
18,
566,
93,
267,
372,
715,
199,
199,
3,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2022,
199,
646,
13390,
199,
199,
646,
13804,
199,
646,
10380,
14,
21148,
199,
199,
893,
26,
272,
327,
12169,
272,
492,
5166,
14,
10788,
14,
2520,
14,
2330,
14,
1014,
465,
5166,
2520,
272,
492,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
465,
3330,
973,
199,
2590,
3545,
26,
272,
327,
18042,
272,
492,
3330,
14,
2330,
14,
1014,
465,
5166,
2520,
272,
492,
3330,
14,
20531,
14,
973,
465,
3330,
973,
199,
199,
533,
662,
1914,
8,
11267,
2520,
14,
7506,
304,
272,
327,
1455,
921,
4269,
26,
1257,
1876,
15,
6297,
15,
1345,
31,
697,
29,
6873,
6,
1418,
29,
13312,
13933,
272,
327,
1455,
921,
4269,
26,
1257,
1876,
15,
6297,
15,
646,
63,
633,
31,
633,
29,
7639,
32149,
2632,
272,
485,
1850,
63,
515,
275,
3286,
6297,
2,
339,
347,
1978,
8,
277,
12,
2648,
12,
24496,
534,
2520,
12,
6297,
735,
267,
291,
14,
13683,
275,
5166,
2520,
14,
20531,
63,
515,
459,
15,
2520,
15,
2520,
1258,
418,
267,
366,
275,
1052,
267,
366,
905,
3596,
937,
275,
1867,
78,
1674,
904,
4827,
1579,
730,
628,
505,
15,
9554,
2,
2928,
5961,
83,
10070,
1579,
3524,
5,
73,
367,
284,
315,
291,
14,
13683,
14,
6418,
63,
513,
8,
2103,
12,
24496,
12,
283,
3596,
1333,
267,
366,
905,
3919,
937,
275,
1867,
78,
1674,
904,
4827,
1073,
4668,
628,
15479,
2,
4369,
5961,
83,
1743,
5956,
73,
367,
284,
315,
291,
14,
13683,
14,
6418,
63,
513,
8,
2103,
12,
24496,
12,
283,
3919,
1333,
267,
366,
905,
3112,
937,
275,
13804,
14,
4180,
8,
19709,
14,
1294,
5102,
1333,
267,
372,
366,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
2455,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
366,
275,
291,
14,
1160,
8,
2103,
9,
267,
366,
905,
826,
937,
275,
283,
83,
14,
6297,
14,
6297,
63,
1345,
3647,
83,
11890,
83,
3547,
13328,
697,
12,
1418,
9,
267,
519,
275,
3330,
973,
14,
1360,
63,
1160,
450,
366,
267,
372,
519,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
492,
63,
633,
8,
277,
12,
2648,
12,
1166,
304,
267,
366,
275,
291,
14,
1160,
8,
2103,
9,
267,
366,
905,
826,
937,
275,
283,
83,
14,
6297,
14,
6297,
63,
646,
3647,
83,
3547,
13328,
633,
9,
267,
519,
275,
3330,
973,
14,
1360,
63,
1160,
450,
366,
267,
372,
519,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
5235,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
754,
12,
2323,
11699,
2714,
13,
804,
297,
283,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
659,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
4960,
372,
1177,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
5235,
63,
8905,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1382,
275,
2022,
14,
3640,
8,
1099,
2788,
16,
61,
267,
12193,
275,
1382,
13742,
15855,
418,
436,
1382,
13742,
15855,
3488,
16,
61,
267,
340,
12193,
26,
288,
754,
275,
12193,
905,
1317,
4140,
2708,
360,
1095,
772,
358,
288,
492,
3031,
14,
7535,
465,
3778,
953,
327,
19244,
465,
1126,
7329,
499,
11921,
288,
1788,
63,
1624,
24,
275,
12193,
459,
493,
63,
354,
418,
288,
1788,
63,
8167,
275,
2071,
83,
2458,
83,
2,
450,
661,
1501,
7693,
5101,
3778,
14,
2143,
63,
8973,
27475,
8,
1501,
63,
1624,
24,
12,
283,
1624,
13,
24,
1333,
288,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
1099,
12,
2323,
11699,
2714,
13,
804,
297,
283,
3578,
15,
5607,
659,
28095,
661,
2714,
13,
15954,
297,
283,
6460,
27,
283,
435,
1788,
63,
8167,
395,
28095,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
288,
372,
1177,
339,
768,
11267,
2520,
14,
16916,
26762,
272,
347,
3366,
8,
277,
12,
2648,
12,
1592,
12,
1526,
12,
901,
63,
515,
628,
4627,
63,
1562,
14,
9733,
401,
1564,
63,
466,
534,
1569,
15,
4524,
735,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
1382,
275,
2022,
14,
3640,
8,
1099,
2788,
16,
61,
267,
367,
536,
315,
901,
63,
515,
14,
1294,
480,
30946,
288,
1382,
275,
1382,
59,
354,
61,
267,
754,
275,
1382,
14,
2708,
360,
1095,
772,
358,
267,
1177,
275,
10380,
14,
21148,
14,
2364,
8,
1099,
12,
2323,
11699,
2714,
13,
804,
297,
1564,
63,
466,
395,
17743,
661,
2714,
13,
4625,
297,
822,
8,
1099,
18229,
267,
372,
1177,
339,
768,
11267,
2520,
14,
1001,
1069,
272,
347,
664,
63,
6297,
63,
3554,
8,
277,
12,
2648,
12,
1592,
12,
1526,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
362,
63,
6297,
63,
3554,
8,
697,
12,
1526,
9,
267,
372,
2022,
14,
3640,
8,
1099,
9,
339,
768,
11267,
2520,
14,
1001,
1069,
272,
347,
492,
63,
6297,
63,
633,
8,
277,
12,
2648,
12,
1166,
304,
267,
754,
275,
2648,
14,
1730,
14,
3280,
360,
6297,
1959,
646,
63,
6297,
63,
633,
8,
2103,
14,
1730,
423,
697,
12,
2648,
14,
1730,
423,
1535,
12,
2648,
14,
1730,
423,
2060,
12,
1166,
9,
267,
340,
822,
8,
1099,
9,
508,
413,
26,
288,
372,
2420,
1287,
582,
3330,
973,
14,
3118,
63,
1287,
8,
2103,
12,
754,
59,
16,
1527,
18,
566,
93,
267,
372,
715,
199,
199,
3,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Nepherhotep/django
|
tests/middleware/test_security.py
|
291
|
7781
|
from django.http import HttpResponse
from django.test import RequestFactory, SimpleTestCase
from django.test.utils import override_settings
class SecurityMiddlewareTest(SimpleTestCase):
@property
def middleware(self):
from django.middleware.security import SecurityMiddleware
return SecurityMiddleware()
@property
def secure_request_kwargs(self):
return {"wsgi.url_scheme": "https"}
def response(self, *args, **kwargs):
headers = kwargs.pop("headers", {})
response = HttpResponse(*args, **kwargs)
for k, v in headers.items():
response[k] = v
return response
def process_response(self, *args, **kwargs):
request_kwargs = {}
if kwargs.pop("secure", False):
request_kwargs.update(self.secure_request_kwargs)
request = (kwargs.pop("request", None) or
self.request.get("/some/url", **request_kwargs))
ret = self.middleware.process_request(request)
if ret:
return ret
return self.middleware.process_response(
request, self.response(*args, **kwargs))
request = RequestFactory()
def process_request(self, method, *args, **kwargs):
if kwargs.pop("secure", False):
kwargs.update(self.secure_request_kwargs)
req = getattr(self.request, method.lower())(*args, **kwargs)
return self.middleware.process_request(req)
@override_settings(SECURE_HSTS_SECONDS=3600)
def test_sts_on(self):
"""
With HSTS_SECONDS=3600, the middleware adds
"strict-transport-security: max-age=3600" to the response.
"""
self.assertEqual(
self.process_response(secure=True)["strict-transport-security"],
"max-age=3600")
@override_settings(SECURE_HSTS_SECONDS=3600)
def test_sts_already_present(self):
"""
The middleware will not override a "strict-transport-security" header
already present in the response.
"""
response = self.process_response(
secure=True,
headers={"strict-transport-security": "max-age=7200"})
self.assertEqual(response["strict-transport-security"], "max-age=7200")
@override_settings(HSTS_SECONDS=3600)
def test_sts_only_if_secure(self):
"""
The "strict-transport-security" header is not added to responses going
over an insecure connection.
"""
self.assertNotIn("strict-transport-security", self.process_response(secure=False))
@override_settings(HSTS_SECONDS=0)
def test_sts_off(self):
"""
With HSTS_SECONDS of 0, the middleware does not add a
"strict-transport-security" header to the response.
"""
self.assertNotIn("strict-transport-security", self.process_response(secure=True))
@override_settings(
SECURE_HSTS_SECONDS=600, SECURE_HSTS_INCLUDE_SUBDOMAINS=True)
def test_sts_include_subdomains(self):
"""
With HSTS_SECONDS non-zero and HSTS_INCLUDE_SUBDOMAINS
True, the middleware adds a "strict-transport-security" header with the
"includeSubDomains" tag to the response.
"""
response = self.process_response(secure=True)
self.assertEqual(
response["strict-transport-security"],
"max-age=600; includeSubDomains",
)
@override_settings(
SECURE_HSTS_SECONDS=600, SECURE_HSTS_INCLUDE_SUBDOMAINS=False)
def test_sts_no_include_subdomains(self):
"""
With HSTS_SECONDS non-zero and HSTS_INCLUDE_SUBDOMAINS
False, the middleware adds a "strict-transport-security" header without
the "includeSubDomains" tag to the response.
"""
response = self.process_response(secure=True)
self.assertEqual(response["strict-transport-security"], "max-age=600")
@override_settings(SECURE_CONTENT_TYPE_NOSNIFF=True)
def test_content_type_on(self):
"""
With CONTENT_TYPE_NOSNIFF set to True, the middleware adds
"x-content-type-options: nosniff" header to the response.
"""
self.assertEqual(self.process_response()["x-content-type-options"], "nosniff")
@override_settings(SECURE_CONTENT_TYPE_NO_SNIFF=True)
def test_content_type_already_present(self):
"""
The middleware will not override an "x-content-type-options" header
already present in the response.
"""
response = self.process_response(secure=True, headers={"x-content-type-options": "foo"})
self.assertEqual(response["x-content-type-options"], "foo")
@override_settings(SECURE_CONTENT_TYPE_NOSNIFF=False)
def test_content_type_off(self):
"""
With CONTENT_TYPE_NOSNIFF False, the middleware does not add an
"x-content-type-options" header to the response.
"""
self.assertNotIn("x-content-type-options", self.process_response())
@override_settings(SECURE_BROWSER_XSS_FILTER=True)
def test_xss_filter_on(self):
"""
With BROWSER_XSS_FILTER set to True, the middleware adds
"s-xss-protection: 1; mode=block" header to the response.
"""
self.assertEqual(
self.process_response()["x-xss-protection"],
"1; mode=block")
@override_settings(SECURE_BROWSER_XSS_FILTER=True)
def test_xss_filter_already_present(self):
"""
The middleware will not override an "x-xss-protection" header
already present in the response.
"""
response = self.process_response(secure=True, headers={"x-xss-protection": "foo"})
self.assertEqual(response["x-xss-protection"], "foo")
@override_settings(BROWSER_XSS_FILTER=False)
def test_xss_filter_off(self):
"""
With BROWSER_XSS_FILTER set to False, the middleware does not add an
"x-xss-protection" header to the response.
"""
self.assertNotIn("x-xss-protection", self.process_response())
@override_settings(SECURE_SSL_REDIRECT=True)
def test_ssl_redirect_on(self):
"""
With SSL_REDIRECT True, the middleware redirects any non-secure
requests to the https:// version of the same URL.
"""
ret = self.process_request("get", "/some/url?query=string")
self.assertEqual(ret.status_code, 301)
self.assertEqual(
ret["Location"], "https://testserver/some/url?query=string")
@override_settings(SECURE_SSL_REDIRECT=True)
def test_no_redirect_ssl(self):
"""
The middleware does not redirect secure requests.
"""
ret = self.process_request("get", "/some/url", secure=True)
self.assertEqual(ret, None)
@override_settings(
SECURE_SSL_REDIRECT=True, SECURE_REDIRECT_EXEMPT=["^insecure/"])
def test_redirect_exempt(self):
"""
The middleware does not redirect requests with URL path matching an
exempt pattern.
"""
ret = self.process_request("get", "/insecure/page")
self.assertEqual(ret, None)
@override_settings(
SECURE_SSL_REDIRECT=True, SECURE_SSL_HOST="secure.example.com")
def test_redirect_ssl_host(self):
"""
The middleware redirects to SSL_HOST if given.
"""
ret = self.process_request("get", "/some/url")
self.assertEqual(ret.status_code, 301)
self.assertEqual(ret["Location"], "https://secure.example.com/some/url")
@override_settings(SECURE_SSL_REDIRECT=False)
def test_ssl_redirect_off(self):
"""
With SSL_REDIRECT False, the middleware does no redirect.
"""
ret = self.process_request("get", "/some/url")
self.assertEqual(ret, None)
|
bsd-3-clause
|
[
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
396,
492,
18638,
12,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
421,
199,
533,
13863,
6608,
774,
8,
17968,
304,
272,
768,
1829,
272,
347,
10816,
8,
277,
304,
267,
687,
1639,
14,
5754,
14,
4416,
492,
13863,
6608,
267,
372,
13863,
6608,
342,
339,
768,
1829,
272,
347,
11153,
63,
1069,
63,
958,
8,
277,
304,
267,
372,
2420,
6508,
14,
633,
63,
5512,
582,
298,
2859,
3570,
339,
347,
1177,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2323,
275,
2074,
14,
1935,
480,
2139,
401,
5009,
267,
1177,
275,
6183,
2031,
589,
12,
1011,
958,
9,
267,
367,
1022,
12,
373,
315,
2323,
14,
1744,
837,
288,
1177,
59,
75,
61,
275,
373,
267,
372,
1177,
339,
347,
2112,
63,
1310,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1056,
63,
958,
275,
1052,
267,
340,
2074,
14,
1935,
480,
7817,
401,
756,
304,
288,
1056,
63,
958,
14,
873,
8,
277,
14,
7817,
63,
1069,
63,
958,
9,
267,
1056,
275,
334,
958,
14,
1935,
480,
1069,
401,
488,
9,
503,
673,
291,
14,
1069,
14,
362,
4769,
3972,
15,
633,
401,
1011,
1069,
63,
958,
430,
267,
2203,
275,
291,
14,
5754,
14,
1412,
63,
1069,
8,
1069,
9,
267,
340,
2203,
26,
288,
372,
2203,
267,
372,
291,
14,
5754,
14,
1412,
63,
1310,
8,
288,
1056,
12,
291,
14,
1310,
2031,
589,
12,
1011,
958,
430,
339,
1056,
275,
18638,
342,
339,
347,
2112,
63,
1069,
8,
277,
12,
1083,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
480,
7817,
401,
756,
304,
288,
2074,
14,
873,
8,
277,
14,
7817,
63,
1069,
63,
958,
9,
267,
2648,
275,
2519,
8,
277,
14,
1069,
12,
1083,
14,
2325,
1012,
2031,
589,
12,
1011,
958,
9,
267,
372,
291,
14,
5754,
14,
1412,
63,
1069,
8,
2103,
9,
339,
768,
4415,
63,
1751,
8,
20696,
63,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
265,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
29,
11035,
12,
314,
10816,
9584,
267,
298,
4768,
13,
5545,
13,
4416,
26,
1390,
13,
474,
29,
11035,
2,
370,
314,
1177,
14,
267,
408,
267,
291,
14,
629,
8,
288,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
26332,
4768,
13,
5545,
13,
4416,
2255,
288,
298,
988,
13,
474,
29,
11035,
531,
339,
768,
4415,
63,
1751,
8,
20696,
63,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
14039,
63,
1881,
8,
277,
304,
267,
408,
267,
710,
10816,
911,
440,
4278,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
267,
2575,
3451,
315,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
288,
11153,
29,
549,
12,
288,
2323,
8871,
4768,
13,
5545,
13,
4416,
582,
298,
988,
13,
474,
29,
23,
1840,
5984,
267,
291,
14,
629,
8,
1310,
905,
4768,
13,
5545,
13,
4416,
2255,
298,
988,
13,
474,
29,
23,
1840,
531,
339,
768,
4415,
63,
1751,
8,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
2118,
63,
692,
63,
7817,
8,
277,
304,
267,
408,
267,
710,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
365,
440,
3483,
370,
9320,
9995,
267,
1806,
376,
26097,
1950,
14,
267,
408,
267,
291,
14,
8795,
480,
4768,
13,
5545,
13,
4416,
401,
291,
14,
1412,
63,
1310,
8,
7817,
29,
797,
430,
339,
768,
4415,
63,
1751,
8,
40,
840,
51,
63,
23319,
29,
16,
9,
272,
347,
511,
63,
10329,
63,
1997,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
402,
378,
12,
314,
10816,
1630,
440,
1050,
282,
267,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
370,
314,
1177,
14,
267,
408,
267,
291,
14,
8795,
480,
4768,
13,
5545,
13,
4416,
401,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
430,
339,
768,
4415,
63,
1751,
8,
267,
24143,
3942,
63,
40,
840,
51,
63,
23319,
29,
6683,
12,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
29,
549,
9,
272,
347,
511,
63,
10329,
63,
2613,
63,
954,
9756,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
2222,
13,
4262,
436,
869,
840,
51,
63,
18171,
63,
6348,
7378,
51,
267,
715,
12,
314,
10816,
9584,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
543,
314,
267,
298,
2613,
2610,
7705,
83,
2,
1947,
370,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
9,
267,
291,
14,
629,
8,
288,
1177,
905,
4768,
13,
5545,
13,
4416,
2255,
288,
298,
988,
13,
474,
29,
6683,
27,
2387,
2610,
7705,
83,
401,
288,
776,
339,
768,
4415,
63,
1751,
8,
267,
24143,
3942,
63,
40,
840,
51,
63,
23319,
29,
6683,
12,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
29,
797,
9,
272,
347,
511,
63,
10329,
63,
889,
63,
2613,
63,
954,
9756,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
2222,
13,
4262,
436,
869,
840,
51,
63,
18171,
63,
6348,
7378,
51,
267,
756,
12,
314,
10816,
9584,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
1928,
267,
314,
298,
2613,
2610,
7705,
83,
2,
1947,
370,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
9,
267,
291,
14,
629,
8,
1310,
905,
4768,
13,
5545,
13,
4416,
2255,
298,
988,
13,
474,
29,
6683,
531,
339,
768,
4415,
63,
1751,
8,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
29,
549,
9,
272,
347,
511,
63,
1317,
63,
466,
63,
265,
8,
277,
304,
267,
408,
267,
8777,
29417,
63,
2711,
63,
2826,
8199,
24150,
663,
370,
715,
12,
314,
10816,
9584,
267,
298,
88,
13,
1317,
13,
466,
13,
1419,
26,
302,
736,
8445,
556,
2,
1406,
370,
314,
1177,
14,
267,
408,
267,
291
] |
[
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
396,
492,
18638,
12,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
421,
199,
533,
13863,
6608,
774,
8,
17968,
304,
272,
768,
1829,
272,
347,
10816,
8,
277,
304,
267,
687,
1639,
14,
5754,
14,
4416,
492,
13863,
6608,
267,
372,
13863,
6608,
342,
339,
768,
1829,
272,
347,
11153,
63,
1069,
63,
958,
8,
277,
304,
267,
372,
2420,
6508,
14,
633,
63,
5512,
582,
298,
2859,
3570,
339,
347,
1177,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2323,
275,
2074,
14,
1935,
480,
2139,
401,
5009,
267,
1177,
275,
6183,
2031,
589,
12,
1011,
958,
9,
267,
367,
1022,
12,
373,
315,
2323,
14,
1744,
837,
288,
1177,
59,
75,
61,
275,
373,
267,
372,
1177,
339,
347,
2112,
63,
1310,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1056,
63,
958,
275,
1052,
267,
340,
2074,
14,
1935,
480,
7817,
401,
756,
304,
288,
1056,
63,
958,
14,
873,
8,
277,
14,
7817,
63,
1069,
63,
958,
9,
267,
1056,
275,
334,
958,
14,
1935,
480,
1069,
401,
488,
9,
503,
673,
291,
14,
1069,
14,
362,
4769,
3972,
15,
633,
401,
1011,
1069,
63,
958,
430,
267,
2203,
275,
291,
14,
5754,
14,
1412,
63,
1069,
8,
1069,
9,
267,
340,
2203,
26,
288,
372,
2203,
267,
372,
291,
14,
5754,
14,
1412,
63,
1310,
8,
288,
1056,
12,
291,
14,
1310,
2031,
589,
12,
1011,
958,
430,
339,
1056,
275,
18638,
342,
339,
347,
2112,
63,
1069,
8,
277,
12,
1083,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
480,
7817,
401,
756,
304,
288,
2074,
14,
873,
8,
277,
14,
7817,
63,
1069,
63,
958,
9,
267,
2648,
275,
2519,
8,
277,
14,
1069,
12,
1083,
14,
2325,
1012,
2031,
589,
12,
1011,
958,
9,
267,
372,
291,
14,
5754,
14,
1412,
63,
1069,
8,
2103,
9,
339,
768,
4415,
63,
1751,
8,
20696,
63,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
265,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
29,
11035,
12,
314,
10816,
9584,
267,
298,
4768,
13,
5545,
13,
4416,
26,
1390,
13,
474,
29,
11035,
2,
370,
314,
1177,
14,
267,
408,
267,
291,
14,
629,
8,
288,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
26332,
4768,
13,
5545,
13,
4416,
2255,
288,
298,
988,
13,
474,
29,
11035,
531,
339,
768,
4415,
63,
1751,
8,
20696,
63,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
14039,
63,
1881,
8,
277,
304,
267,
408,
267,
710,
10816,
911,
440,
4278,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
267,
2575,
3451,
315,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
288,
11153,
29,
549,
12,
288,
2323,
8871,
4768,
13,
5545,
13,
4416,
582,
298,
988,
13,
474,
29,
23,
1840,
5984,
267,
291,
14,
629,
8,
1310,
905,
4768,
13,
5545,
13,
4416,
2255,
298,
988,
13,
474,
29,
23,
1840,
531,
339,
768,
4415,
63,
1751,
8,
40,
840,
51,
63,
23319,
29,
11035,
9,
272,
347,
511,
63,
10329,
63,
2118,
63,
692,
63,
7817,
8,
277,
304,
267,
408,
267,
710,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
365,
440,
3483,
370,
9320,
9995,
267,
1806,
376,
26097,
1950,
14,
267,
408,
267,
291,
14,
8795,
480,
4768,
13,
5545,
13,
4416,
401,
291,
14,
1412,
63,
1310,
8,
7817,
29,
797,
430,
339,
768,
4415,
63,
1751,
8,
40,
840,
51,
63,
23319,
29,
16,
9,
272,
347,
511,
63,
10329,
63,
1997,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
402,
378,
12,
314,
10816,
1630,
440,
1050,
282,
267,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
370,
314,
1177,
14,
267,
408,
267,
291,
14,
8795,
480,
4768,
13,
5545,
13,
4416,
401,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
430,
339,
768,
4415,
63,
1751,
8,
267,
24143,
3942,
63,
40,
840,
51,
63,
23319,
29,
6683,
12,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
29,
549,
9,
272,
347,
511,
63,
10329,
63,
2613,
63,
954,
9756,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
2222,
13,
4262,
436,
869,
840,
51,
63,
18171,
63,
6348,
7378,
51,
267,
715,
12,
314,
10816,
9584,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
543,
314,
267,
298,
2613,
2610,
7705,
83,
2,
1947,
370,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
9,
267,
291,
14,
629,
8,
288,
1177,
905,
4768,
13,
5545,
13,
4416,
2255,
288,
298,
988,
13,
474,
29,
6683,
27,
2387,
2610,
7705,
83,
401,
288,
776,
339,
768,
4415,
63,
1751,
8,
267,
24143,
3942,
63,
40,
840,
51,
63,
23319,
29,
6683,
12,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
29,
797,
9,
272,
347,
511,
63,
10329,
63,
889,
63,
2613,
63,
954,
9756,
8,
277,
304,
267,
408,
267,
8777,
869,
840,
51,
63,
23319,
2222,
13,
4262,
436,
869,
840,
51,
63,
18171,
63,
6348,
7378,
51,
267,
756,
12,
314,
10816,
9584,
282,
298,
4768,
13,
5545,
13,
4416,
2,
1406,
1928,
267,
314,
298,
2613,
2610,
7705,
83,
2,
1947,
370,
314,
1177,
14,
267,
408,
267,
1177,
275,
291,
14,
1412,
63,
1310,
8,
7817,
29,
549,
9,
267,
291,
14,
629,
8,
1310,
905,
4768,
13,
5545,
13,
4416,
2255,
298,
988,
13,
474,
29,
6683,
531,
339,
768,
4415,
63,
1751,
8,
20696,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
29,
549,
9,
272,
347,
511,
63,
1317,
63,
466,
63,
265,
8,
277,
304,
267,
408,
267,
8777,
29417,
63,
2711,
63,
2826,
8199,
24150,
663,
370,
715,
12,
314,
10816,
9584,
267,
298,
88,
13,
1317,
13,
466,
13,
1419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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DavidLP/home-assistant
|
homeassistant/components/worldtidesinfo/sensor.py
|
7
|
4085
|
"""Support for the worldtides.info API."""
from datetime import timedelta
import logging
import time
import requests
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
ATTR_ATTRIBUTION, CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by WorldTides"
DEFAULT_NAME = 'WorldTidesInfo'
SCAN_INTERVAL = timedelta(seconds=3600)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the WorldTidesInfo sensor."""
name = config.get(CONF_NAME)
lat = config.get(CONF_LATITUDE, hass.config.latitude)
lon = config.get(CONF_LONGITUDE, hass.config.longitude)
key = config.get(CONF_API_KEY)
if None in (lat, lon):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
tides = WorldTidesInfoSensor(name, lat, lon, key)
tides.update()
if tides.data.get('error') == 'No location found':
_LOGGER.error("Location not available")
return
add_entities([tides])
class WorldTidesInfoSensor(Entity):
"""Representation of a WorldTidesInfo sensor."""
def __init__(self, name, lat, lon, key):
"""Initialize the sensor."""
self._name = name
self._lat = lat
self._lon = lon
self._key = key
self.data = None
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def device_state_attributes(self):
"""Return the state attributes of this device."""
attr = {ATTR_ATTRIBUTION: ATTRIBUTION}
if 'High' in str(self.data['extremes'][0]['type']):
attr['high_tide_time_utc'] = self.data['extremes'][0]['date']
attr['high_tide_height'] = self.data['extremes'][0]['height']
attr['low_tide_time_utc'] = self.data['extremes'][1]['date']
attr['low_tide_height'] = self.data['extremes'][1]['height']
elif 'Low' in str(self.data['extremes'][0]['type']):
attr['high_tide_time_utc'] = self.data['extremes'][1]['date']
attr['high_tide_height'] = self.data['extremes'][1]['height']
attr['low_tide_time_utc'] = self.data['extremes'][0]['date']
attr['low_tide_height'] = self.data['extremes'][0]['height']
return attr
@property
def state(self):
"""Return the state of the device."""
if self.data:
if 'High' in str(self.data['extremes'][0]['type']):
tidetime = time.strftime('%I:%M %p', time.localtime(
self.data['extremes'][0]['dt']))
return "High tide at {}".format(tidetime)
if 'Low' in str(self.data['extremes'][0]['type']):
tidetime = time.strftime('%I:%M %p', time.localtime(
self.data['extremes'][0]['dt']))
return "Low tide at {}".format(tidetime)
return None
return None
def update(self):
"""Get the latest data from WorldTidesInfo API."""
start = int(time.time())
resource = ('https://www.worldtides.info/api?extremes&length=86400'
'&key={}&lat={}&lon={}&start={}').format(
self._key, self._lat, self._lon, start)
try:
self.data = requests.get(resource, timeout=10).json()
_LOGGER.debug("Data: %s", self.data)
_LOGGER.debug(
"Tide data queried with start time set to: %s", start)
except ValueError as err:
_LOGGER.error(
"Error retrieving data from WorldTidesInfo: %s", err.args)
self.data = None
|
apache-2.0
|
[
624,
11532,
367,
314,
6701,
280,
3424,
14,
815,
3261,
1041,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
646,
900,
199,
199,
646,
4145,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
5280,
26601,
12,
6392,
63,
3735,
63,
3078,
12,
6392,
63,
20307,
28742,
12,
6392,
63,
12375,
28742,
12,
6392,
63,
2339,
9,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5280,
26601,
275,
298,
1451,
2741,
701,
13064,
52,
2655,
83,
2,
199,
199,
3472,
63,
2339,
275,
283,
15943,
52,
2655,
83,
2354,
7,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
11035,
9,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
3735,
63,
3078,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
20307,
28742,
304,
6277,
14,
13331,
12,
272,
5236,
14,
7012,
8,
3103,
63,
12375,
28742,
304,
6277,
14,
13803,
12,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
199,
1552,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
13064,
52,
2655,
83,
2354,
8778,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
9,
339,
8396,
275,
1101,
14,
362,
8,
3103,
63,
20307,
28742,
12,
6298,
14,
888,
14,
13331,
9,
272,
6132,
275,
1101,
14,
362,
8,
3103,
63,
12375,
28742,
12,
6298,
14,
888,
14,
13803,
9,
272,
790,
275,
1101,
14,
362,
8,
3103,
63,
3735,
63,
3078,
9,
339,
340,
488,
315,
334,
4452,
12,
6132,
304,
267,
485,
10186,
14,
705,
480,
44,
31429,
3786,
503,
18154,
440,
663,
315,
14621,
3709,
18832,
1101,
531,
339,
3367,
3424,
275,
13064,
52,
2655,
83,
2354,
10160,
8,
354,
12,
8396,
12,
6132,
12,
790,
9,
272,
3367,
3424,
14,
873,
342,
272,
340,
3367,
3424,
14,
576,
14,
362,
360,
705,
358,
508,
283,
1944,
2909,
1911,
356,
267,
485,
10186,
14,
705,
480,
6592,
440,
2808,
531,
267,
372,
339,
1050,
63,
8327,
779,
280,
3424,
566,
421,
199,
533,
13064,
52,
2655,
83,
2354,
10160,
8,
7302,
304,
272,
408,
20609,
402,
282,
13064,
52,
2655,
83,
2354,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
8396,
12,
6132,
12,
790,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
354,
275,
536,
267,
291,
423,
4452,
275,
8396,
267,
291,
423,
5298,
275,
6132,
267,
291,
423,
498,
275,
790,
267,
291,
14,
576,
275,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
2243,
63,
929,
63,
2987,
8,
277,
304,
267,
408,
1767,
314,
1174,
3004,
402,
642,
2243,
1041,
267,
1921,
275,
469,
5280,
63,
5280,
26601,
26,
10762,
26601,
93,
398,
340,
283,
11688,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
288,
1921,
459,
6260,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
602,
418,
288,
1921,
459,
6260,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3333,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
602,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
3333,
418,
267,
916,
283,
10281,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
288,
1921,
459,
6260,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
602,
418,
288,
1921,
459,
6260,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
3333,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
602,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3333,
418,
267,
372,
1921,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
340,
291,
14,
576,
26,
288,
340,
283,
11688,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
355,
3367,
271,
521,
275,
900,
14,
6205,
3508,
41,
2689,
45,
450,
80,
297,
900,
14,
15198,
8,
490,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3583,
5156,
355,
372,
298,
11688,
3367,
271,
737,
8352,
908,
8,
280,
271,
521,
9,
288,
340,
283,
10281,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
355,
3367,
271,
521,
275,
900,
14,
6205,
3508,
41,
2689,
45,
450,
80,
297,
900,
14,
15198,
8,
490,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3583,
5156,
355,
372,
298,
10281,
3367,
271,
737,
8352,
908,
8,
280,
271,
521,
9,
288,
372,
488,
267,
372,
488,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
687,
13064,
52,
2655,
83,
2354,
3261,
1041,
267,
1343,
275,
1109,
8,
521,
14,
521,
1012,
267,
2073,
275,
661,
2859,
921,
1544,
14,
7617,
280,
3424,
14,
815,
15,
1246,
31,
832,
264,
6415,
6,
1267,
29,
24,
20543,
7,
490,
7673,
498,
7622,
6,
4452,
7622,
6,
5298,
7622,
6,
928,
7622,
1959,
908,
8,
717,
291,
423,
498,
12,
291,
423,
4452,
12,
291,
423,
5298,
12,
1343,
9,
398,
862,
26,
288
] |
[
11532,
367,
314,
6701,
280,
3424,
14,
815,
3261,
1041,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
646,
900,
199,
199,
646,
4145,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
5280,
26601,
12,
6392,
63,
3735,
63,
3078,
12,
6392,
63,
20307,
28742,
12,
6392,
63,
12375,
28742,
12,
6392,
63,
2339,
9,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5280,
26601,
275,
298,
1451,
2741,
701,
13064,
52,
2655,
83,
2,
199,
199,
3472,
63,
2339,
275,
283,
15943,
52,
2655,
83,
2354,
7,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
11035,
9,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
3735,
63,
3078,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
20307,
28742,
304,
6277,
14,
13331,
12,
272,
5236,
14,
7012,
8,
3103,
63,
12375,
28742,
304,
6277,
14,
13803,
12,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
199,
1552,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
13064,
52,
2655,
83,
2354,
8778,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
9,
339,
8396,
275,
1101,
14,
362,
8,
3103,
63,
20307,
28742,
12,
6298,
14,
888,
14,
13331,
9,
272,
6132,
275,
1101,
14,
362,
8,
3103,
63,
12375,
28742,
12,
6298,
14,
888,
14,
13803,
9,
272,
790,
275,
1101,
14,
362,
8,
3103,
63,
3735,
63,
3078,
9,
339,
340,
488,
315,
334,
4452,
12,
6132,
304,
267,
485,
10186,
14,
705,
480,
44,
31429,
3786,
503,
18154,
440,
663,
315,
14621,
3709,
18832,
1101,
531,
339,
3367,
3424,
275,
13064,
52,
2655,
83,
2354,
10160,
8,
354,
12,
8396,
12,
6132,
12,
790,
9,
272,
3367,
3424,
14,
873,
342,
272,
340,
3367,
3424,
14,
576,
14,
362,
360,
705,
358,
508,
283,
1944,
2909,
1911,
356,
267,
485,
10186,
14,
705,
480,
6592,
440,
2808,
531,
267,
372,
339,
1050,
63,
8327,
779,
280,
3424,
566,
421,
199,
533,
13064,
52,
2655,
83,
2354,
10160,
8,
7302,
304,
272,
408,
20609,
402,
282,
13064,
52,
2655,
83,
2354,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
8396,
12,
6132,
12,
790,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
354,
275,
536,
267,
291,
423,
4452,
275,
8396,
267,
291,
423,
5298,
275,
6132,
267,
291,
423,
498,
275,
790,
267,
291,
14,
576,
275,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
2243,
63,
929,
63,
2987,
8,
277,
304,
267,
408,
1767,
314,
1174,
3004,
402,
642,
2243,
1041,
267,
1921,
275,
469,
5280,
63,
5280,
26601,
26,
10762,
26601,
93,
398,
340,
283,
11688,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
288,
1921,
459,
6260,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
602,
418,
288,
1921,
459,
6260,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3333,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
602,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
3333,
418,
267,
916,
283,
10281,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
288,
1921,
459,
6260,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
602,
418,
288,
1921,
459,
6260,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
17,
2733,
3333,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
521,
63,
5834,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
602,
418,
288,
1921,
459,
674,
63,
280,
271,
63,
3333,
418,
275,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3333,
418,
267,
372,
1921,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
340,
291,
14,
576,
26,
288,
340,
283,
11688,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
355,
3367,
271,
521,
275,
900,
14,
6205,
3508,
41,
2689,
45,
450,
80,
297,
900,
14,
15198,
8,
490,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3583,
5156,
355,
372,
298,
11688,
3367,
271,
737,
8352,
908,
8,
280,
271,
521,
9,
288,
340,
283,
10281,
7,
315,
620,
8,
277,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
466,
9090,
355,
3367,
271,
521,
275,
900,
14,
6205,
3508,
41,
2689,
45,
450,
80,
297,
900,
14,
15198,
8,
490,
291,
14,
576,
459,
832,
264,
6415,
3488,
16,
2733,
3583,
5156,
355,
372,
298,
10281,
3367,
271,
737,
8352,
908,
8,
280,
271,
521,
9,
288,
372,
488,
267,
372,
488,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
687,
13064,
52,
2655,
83,
2354,
3261,
1041,
267,
1343,
275,
1109,
8,
521,
14,
521,
1012,
267,
2073,
275,
661,
2859,
921,
1544,
14,
7617,
280,
3424,
14,
815,
15,
1246,
31,
832,
264,
6415,
6,
1267,
29,
24,
20543,
7,
490,
7673,
498,
7622,
6,
4452,
7622,
6,
5298,
7622,
6,
928,
7622,
1959,
908,
8,
717,
291,
423,
498,
12,
291,
423,
4452,
12,
291,
423,
5298,
12,
1343,
9,
398,
862,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
5GExchange/escape
|
pox/pox/messenger/__init__.py
|
5
|
20137
|
# Copyright 2011,2012 James McCauley
#
# 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 POX Messenger system.
The Messenger system is a way to build services in POX that can be
consumed by external clients.
Sometimes a controller might need to interact with the outside world.
Sometimes you need to integrate with an existing piece of software and
maybe you don't get to choose how you communicate with it. Other times,
you have the opportunity and burden of rolling your own. The Messenger
system is meant to help you with the latter case.
In short, channels are a system for communicating between POX and
external programs by exchanging messages encoded in JSON. It is intended
to be quite general, both in the communication models it supports and in
the transports is supports (as of this writing, it supports a
straightforward TCP socket transport and an HTTP transport). Any
service written to use the Messenger should theoretically be usable via
any transport.
*Connections* are somehow established when a client connects via some
*Transport*. The server can individually send messages to a specific client.
A client can send messages to a *Channel* on the server. A client can also
become a member of a channel, after which it will receive any messages
the server sends to that channel. There is always a default channel with
no name.
Channels can either be permanent or temporary. Temporary channels are
automatically destroyed when they no longer contain any members.
"""
from pox.lib.revent.revent import *
from pox.core import core as core
import json
import time
import random
import hashlib
from base64 import b32encode
log = core.getLogger()
# JSON decoder used by default
defaultDecoder = json.JSONDecoder()
class ChannelJoin (Event):
""" Fired on a channel when a client joins. """
def __init__ (self, connection, channel, msg = {}):
self.con = connection
self.channel = channel
self.msg = msg
class ConnectionOpened (Event):
""" Fired by the nexus for each new connection """
def __init__ (self, connection):
self.con = connection
class ConnectionClosed (Event):
""" Fired on a connection when it closes. """
def __init__ (self, connection):
self.con = connection
class ChannelLeave (Event):
""" Fired on a channel when a client leaves. """
def __init__ (self, connection, channel):
self.con = connection
self.channel = channel
class ChannelCreate (Event):
""" Fired on a Nexus when a channel is created. """
def __init__ (self, channel):
self.channel = channel
class ChannelDestroy (Event):
"""
Fired on the channel and its Nexus right before a channel is destroyed.
Set .keep = True to keep the channel after all.
"""
def __init__ (self, channel):
self.channel = channel
self.keep = False
class ChannelDestroyed (Event):
"""
Fired on the channel and its Nexus right after a channel is destroyed.
"""
def __init__ (self, channel):
self.channel = channel
class MissingChannel (Event):
"""
Fired on a Nexus when a message has been received to a non-existant channel.
You can create the channel in response to this.
"""
def __init__ (self, connection, channel_name, msg):
self.con = connection
self.channel_name = channel_name
self.msg = msg
class MessageReceived (Event):
"""
Fired by a channel when a message has been receieved.
Always fired on the Connection itself. Also fired on the corresponding
Channel object as specified by the CHANNEL key.
The listener looks like:
def _handle_MessageReceived (event, msg):
"""
def __init__ (self, connection, channel, msg):
self.con = connection
self.msg = msg
self.channel = channel
def is_to_channel (self, channel):
"""
Returns True if this message is to the given channel
"""
if isinstance(channel, Channel):
channel = channel.name
if channel == self.channel: return True
if channel in self.channel: return True
return False
def _invoke (self, handler, *args, **kw):
# Special handling -- pass the message
return handler(self, self.msg, *args, **kw)
def _get_nexus (nexus):
if nexus is None: nexus = "MessengerNexus"
if isinstance(nexus, str):
if not core.hasComponent(nexus):
#TODO: Wait for channel Nexus
s = "MessengerNexus %s is not available" % (nexus,)
log.error(s)
raise RuntimeError(s)
return getattr(core, nexus)
assert isinstance(nexus, MessengerNexus)
return nexus
class Transport (object):
def __init__ (self, nexus):
self._nexus = _get_nexus(nexus)
def _forget (self, connection):
""" Forget about a connection """
raise RuntimeError("Not implemented")
class Connection (EventMixin):
"""
Superclass for Connections.
This could actually be a bit thinner, if someone wants to clean it up.
Maintains the state and handles message parsing and dispatch for a
single connection.
"""
_eventMixin_events = set([
MessageReceived,
ConnectionClosed,
])
def __init__ (self, transport):
"""
transport is the source of the connection (e.g, TCPTransport).
"""
EventMixin.__init__(self)
self._is_connected = True
self._transport = transport
self._newlines = False
# If we connect to another messenger, this contains our session ID as far
# as it is concerned.
self._remote_session_id = None
# Transports that don't do their own encapsulation can use _recv_raw(),
# which uses this. (Such should probably be broken into a subclass.)
self._buf = bytes()
key,num = self._transport._nexus.generate_session()
self._session_id,self._session_num = key,num
def _rx_welcome (self, event):
"""
Called by the default channelbot if we connect to another messenger.
"""
self._remote_session_id = event.msg.get('session_id')
log.debug("%s welcomed as %s.", self, self._remote_session_id)
def _send_welcome (self):
"""
Send a message to a client so they know they're connected
"""
self.send({"CHANNEL":"","cmd":"welcome","session_id":self._session_id})
def _close (self):
"""
Called internally to shut the connection down.
"""
if self._is_connected is False: return
self._transport._forget(self)
self._is_connected = False
for name,chan in self._transport._nexus._channels.items():
chan._remove_member(self)
self.raiseEventNoErrors(ConnectionClosed, self)
#self._transport._nexus.raiseEventNoErrors(ConnectionClosed, self)
def send (self, whatever):
"""
Send data over the connection.
It will first be encoded into JSON, and optionally followed with
a newline. Ultimately, it will be passed to send_raw() to actually
be sent.
"""
if self._is_connected is False: return False
s = json.dumps(whatever, default=str)
if self._newlines: s += "\n"
self.send_raw(s)
return True
def send_raw (self, data):
"""
This method should actually send data out over the connection.
Subclasses need to implement this.
"""
raise RuntimeError("Not implemented")
@property
def is_connected (self):
"""
True if this Connection is still connected.
"""
return self._is_connected
def _rx_message (self, msg):
"""
Raises events when a complete message is available.
Subclasses may want to call this when they have a new message
available. See _recv_raw().
"""
e = self.raiseEventNoErrors(MessageReceived,self,msg.get('CHANNEL'),msg)
self._transport._nexus._rx_message(self, msg)
def _rx_raw (self, data):
"""
If your subclass receives a stream instead of discrete messages, this
method can parse out individual messages and call _recv_msg() when
it has full messages.
"""
if len(data) == 0: return
if len(self._buf) == 0:
if data[0].isspace():
self._buf = data.lstrip()
else:
self._buf = data
else:
self._buf += data
while len(self._buf) > 0:
try:
msg, l = defaultDecoder.raw_decode(self._buf)
except:
# Need more data before it's a valid message
# (.. or the stream is corrupt and things will never be okay
# ever again)
return
self._buf = self._buf[l:]
if len(self._buf) != 0 and self._buf[0].isspace():
self._buf = self._buf.lstrip()
self._rx_message(msg)
def __str__ (self):
"""
Subclasses should implement better versions of this.
"""
return "<%s/%s/%i>" % (self.__class__.__name__, self._session_id,
self._session_num)
def close (self):
"""
Close the connection.
"""
self._close()
class Channel (EventMixin):
"""
Allows one to easily listen to only messages that have a CHANNEL key
with a specific name.
Generally you will not create these classes directly, but by calling
getChannel() on the ChannelNexus.
"""
_eventMixin_events = set([
MessageReceived,
ChannelJoin, # Immedaitely when a connection goes up
ChannelLeave, # When a connection goes down
ChannelDestroy,
ChannelDestroyed,
])
def __init__ (self, name, nexus = None, temporary = False):
"""
name is the name for the channel (i.e., the value for the messages'
CHANNEL key).
nexus is the specific MessengerNexus with which this channel is to be
associated (defaults to core.MessengerNexus).
"""
EventMixin.__init__(self)
assert isinstance(name, basestring)
self._name = name
self._nexus = _get_nexus(nexus)
self._nexus._channels[name] = self
self.temporary = temporary
self._members = set() # Member Connections
@property
def name (self):
return self._name
def _destroy (self):
""" Remove channel """
e = self.raiseEvent(ChannelDestroy, self)
if e:
if e.keep: return False
self._nexus.raiseEvent(e)
if e.keep: return False
del self._nexus._channels[self._name]
# We can't just do the follow because then listeners
# can't tell if the channel is now empty...
#for sub in set(self._members):
# sub.raiseEvent(ChannelLeave, sub, self)
#
#self._members.clear()
# .. so do the following really straightforward...
for sub in set(self._members):
self._remove_member(sub, allow_destroy = False)
e = ChannelDestroyed(self)
self.raiseEvent(e)
self._nexus.raiseEvent(e)
def _add_member (self, con, msg = {}):
if con in self._members: return
self._members.add(con)
self.raiseEvent(ChannelJoin, con, self, msg)
def _remove_member (self, con, allow_destroy = True):
if con not in self._members: return
self._members.remove(con)
self.raiseEvent(ChannelLeave, con, self)
if not allow_destroy: return
if self.temporary is True:
if len(self._members) == 0:
self._destroy()
def send (self, msg):
d = dict(msg)
d['CHANNEL'] = self._name
for r in list(self._members):
if not r.is_connected: continue
r.send(d)
def __str__ (self):
return "<Channel " + self.name + ">"
def reply (_msg, **kw):
if not isinstance(_msg, dict):
# We'll also take an event...
_msg = _msg.msg
kw['CHANNEL'] = _msg.get('CHANNEL')
if 'XID' in _msg: kw['XID'] = _msg.get('XID')
return kw
class ChannelBot (object):
"""
A very simple framework for writing "bots" that respond to messages
on a channel.
"""
def __str__ (self):
return "<%s@%s>" % (self.__class__.__name__, self.channel)
def __init__ (self, channel, nexus = None, weak = False, extra = {}):
self._startup(channel, nexus, weak, extra)
def _startup (self, channel, nexus = None, weak = False, extra = {}):
self._nexus = _get_nexus(nexus)
if isinstance(channel, Channel):
self.channel = channel
else:
self.channel = self._nexus.get_channel(channel, create=True)
self.listeners = self.channel.addListeners(self, weak = weak)
self.prefixes = None
self._init(extra)
if self.prefixes is None:
self.prefixes = []
for n in dir(self):
if n.startswith("_exec_"):
n = n.split("_")[2]
self.prefixes.append(n)
def _handle_ChannelDestroyed (self, event):
self.channel.removeListeners(self.listeners)
self._destroyed()
def _handle_ChannelJoin (self, event):
self._join(event, event.con, event.msg)
def _handle_ChannelLeave (self, event):
self._leave(event.con, len(self.channel._members) == 0)
def _handle_MessageReceived (self, event, msg):
for prefix in self.prefixes:
if prefix in event.msg:
cmd = "_exec_%s_%s" % (prefix, str(event.msg[prefix]))
if hasattr(self, cmd):
getattr(self, cmd)(event)
return #TODO: Return val?
for prefix in self.prefixes:
if prefix in event.msg:
cmd = "_exec_" + prefix
if hasattr(self, cmd):
getattr(self, cmd)(event, msg[prefix])
return #TODO: Return val?
self._unhandled(event)
def _unhandled (self, event):
""" Called when no command found """
pass
def _join (self, event, connection, msg):
""" Called when a connection joins """
pass
def _leave (self, connection, empty):
"""
Called when a connection leaves
If channel now has no members, empty is True
"""
pass
def _destroyed (self):
""" Called when channel is destroyed """
pass
def _init (self, extra):
"""
Called during initialization
'extra' is any additional information passed in when initializing
the bot. In particular, this may be the message that goes along
with its invitation into a channel.
"""
pass
def reply (__self, __event, **kw):
"""
Unicast reply to a specific message.
"""
__event.con.send(reply(__event, **kw))
def send (__self, __msg={}, **kw):
"""
Send a message to all members of this channel.
"""
m = {}
m.update(__msg)
m.update(kw)
__self.channel.send(m)
class DefaultChannelBot (ChannelBot):
def _init (self, extra):
self._bots = {}
def add_bot (self, bot, name = None):
"""
Registers a bot (an instance of ChannelBot) so that it can be
invited to other channels.
"""
assert issubclass(bot, ChannelBot)
if name is None:
name = bot.__name__
self._bots[name] = bot
def _exec_newlines_False (self, event):
event.con._newlines = False
def _exec_newlines_True (self, event):
event.con._newlines = True
def _exec_cmd_invite (self, event):
"""
Invites a bot that has been registered with add_bot() to a channel.
Note that you can invite a bot to an empty (new) temporary channel.
It will stay until the first member leaves.
"""
botname = event.msg.get('bot')
botclass = self._bots.get(botname)
channel = event.msg.get('channel')
new_channel = False
if channel is None:
new_channel = True
channel = self._gen_channel_name(event.msg.get("prefix", "temp"))
chan = self._nexus.get_channel(channel, create=True, temporary=True)
if chan is None:
#TODO: send an error
log.warning("A bot was invited to a nonexistent channel (%s)"
% (channel,))
return
if botclass is None:
#TODO: send an error
log.warning("A nonexistent bot (%s) was invited to a channel"
% (botname,))
return
bot = botclass(channel, self._nexus)
if new_channel:
self.reply(event, new_channel = new_channel)
def _unhandled (self, event):
log.warn("Default channel got unknown command: "
+ str(event.msg.get('cmd')))
def _gen_channel_name (self, prefix = "temp"):
""" Makes up a channel name """
prefix += "_"
import random
while True:
# Sloppy
r = random.randint(1, 100000)
n = prefix + str(r)
if r not in self._nexus._channels:
break
return n
def _exec_cmd_new_channel (self, event):
""" Generates a new channel with random name """
prefix = event.msg.get('prefix', 'temp')
n = self._gen_channel_name(prefix)
ch = self._nexus.get_channel(n, create=True, temporary=True)
ch._add_member(event.con, event.msg)
self.reply(event, new_channel = n)
def _exec_cmd_join_channel (self, event):
""" Joins/creates a channel """
temp = event.msg.get('temporary', True) # Default temporary!
ch = self._nexus.get_channel(event.msg['channel'], temporary=temp)
if ch is None: return
ch._add_member(event.con, event.msg)
def _exec_cmd_leave_channel (self, event):
ch = self._nexus.get_channel(event.msg['channel'])
if ch is None: return
ch._remove_member(event.con)
def _exec_test (self, event, value):
log.info("Default channel got: " + str(value))
self.reply(event, test = value.upper())
def _exec_cmd_welcome (self, event):
# We get this if we're connecting to another messenger.
event.con._rx_welcome(event)
class MessengerNexus (EventMixin):
"""
Transports, Channels, etc. are all associated with a MessengerNexus.
Typically, there is only one, and it is registered as
pox.core.MessengerNexus
"""
_eventMixin_events = set([
MissingChannel, # When a msg arrives to nonexistent channel
ChannelDestroy,
ChannelDestroyed,
ChannelCreate,
ConnectionOpened,
])
def __init__ (self):
EventMixin.__init__(self)
self._channels = {} # name -> Channel
self.default_bot = DefaultChannelBot("", self)
self._next_ses = 1
self._session_salt = str(time.time())
def generate_session (self):
"""
Return a new session ID tuple (key, num)
The key is a unique and not-trivial-to-guess alphanumeric value
associated with the session.
The num is a unique numerical value associated with the session.
"""
r = self._next_ses
self._next_ses += 1
key = str(random.random()) + str(time.time()) + str(r)
key += str(id(key)) + self._session_salt
key = b32encode(hashlib.md5(key).digest()).upper().replace('=','')
def alphahex (r):
""" base 16 on digits 'a' through 'p' """
r=hex(r)[2:].lower()
return ''.join(chr((10 if ord(x) >= 97 else 49) + ord(x)) for x in r)
key = alphahex(r) + key
return key,r
def register_session (self, session):
self.raiseEventNoErrors(ConnectionOpened, session)
def get_channel (self, name, create = True, temporary = False):
if name is None: name = ""
if name in self._channels:
return self._channels[name]
elif create:
c = Channel(name, self, temporary = temporary)
self.raiseEvent(ChannelCreate, c)
return c
else:
return None
def _rx_message (self, con, msg):
"""
Dispatches messages to listeners of this nexus and to its Channels.
Called by Connections.
"""
ret = False
assert isinstance(msg, dict)
if isinstance(msg, dict):
channels = msg.get('CHANNEL')
if channels is None:
channels = [""]
if not isinstance(channels, list):
channels = [channels]
for cname in channels:
channel = self.get_channel(cname, create=False)
if channel is None:
e = self.raiseEvent(MissingChannel, con, cname, msg)
if e is not None: cname = e.channel_name
channel = self.get_channel(cname, create=False)
if channel is not None:
#print "raise on", channel
channel.raiseEvent(MessageReceived, con, channel, msg)
ret = True
return ret
def launch ():
core.registerNew(MessengerNexus)
|
apache-2.0
|
[
3,
1898,
7760,
12,
7409,
1603,
14015,
22895,
3630,
443,
89,
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,
26,
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,
3625,
56,
603,
397,
23444,
2656,
14,
421,
199,
1918,
603,
397,
23444,
2656,
365,
282,
4340,
370,
1900,
8500,
315,
3625,
56,
626,
883,
506,
199,
20688,
701,
5957,
13431,
14,
199,
199,
7700,
4508,
282,
7614,
5594,
1929,
370,
17232,
543,
314,
9682,
6701,
14,
199,
7700,
4508,
1265,
1929,
370,
21494,
543,
376,
3411,
14854,
402,
2032,
436,
199,
11853,
1265,
2793,
1133,
664,
370,
11496,
4212,
1265,
26808,
543,
652,
14,
221,
5439,
5431,
12,
199,
13297,
1172,
314,
30914,
436,
330,
300,
848,
402,
882,
10564,
2195,
5705,
14,
221,
710,
603,
397,
23444,
199,
2253,
365,
18329,
370,
1720,
1265,
543,
314,
19045,
1930,
14,
199,
199,
607,
3974,
12,
9245,
787,
282,
2656,
367,
13882,
1958,
3382,
3625,
56,
436,
199,
5159,
18572,
701,
444,
29131,
3788,
5737,
315,
4840,
14,
221,
2779,
365,
11619,
199,
475,
506,
18794,
8605,
12,
3865,
315,
314,
23506,
1709,
652,
5171,
436,
315,
199,
1589,
7773,
83,
365,
5171,
334,
305,
402,
642,
3575,
12,
652,
5171,
282,
199,
14183,
1070,
6688,
13488,
2838,
7773,
436,
376,
3101,
7773,
680,
221,
6184,
199,
1364,
5313,
370,
675,
314,
603,
397,
23444,
1077,
314,
720,
17269,
506,
18025,
4799,
199,
1629,
7773,
14,
199,
199,
10,
22122,
10,
787,
29437,
23594,
1380,
282,
1890,
4907,
83,
4799,
2005,
199,
10,
7836,
4856,
221,
710,
1654,
883,
7814,
3163,
3222,
3788,
370,
282,
2488,
1890,
14,
199,
33,
1890,
883,
3222,
3788,
370,
282,
627,
5358,
10,
641,
314,
1654,
14,
221,
437,
1890,
883,
2597,
199,
13970,
282,
3653,
402,
282,
3623,
12,
2410,
1314,
652,
911,
9128,
1263,
3788,
199,
1589,
1654,
16178,
370,
626,
3623,
14,
221,
6006,
365,
3544,
282,
849,
3623,
543,
199,
889,
536,
14,
199,
199,
27138,
883,
1902,
506,
19860,
503,
7937,
14,
221,
21791,
9245,
787,
199,
2495,
17174,
28924,
1380,
2985,
949,
8088,
1395,
1263,
7556,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
1018,
492,
6170,
465,
6170,
199,
646,
2022,
199,
646,
900,
199,
646,
2196,
199,
646,
8337,
199,
504,
1300,
772,
492,
330,
708,
2143,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
3,
4840,
10334,
1202,
701,
849,
199,
885,
8326,
275,
2022,
14,
6243,
8326,
342,
421,
199,
533,
17270,
13005,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
18266,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
12,
1499,
275,
1052,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
8113,
4299,
379,
334,
2390,
304,
523,
408,
481,
16139,
701,
314,
22761,
527,
367,
1924,
892,
1950,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
8113,
15190,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
1950,
1380,
652,
27811,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
17270,
23679,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
16733,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
2499,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
3623,
365,
2737,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
14704,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2544,
282,
3623,
365,
28924,
14,
523,
2494,
1275,
3250,
275,
715,
370,
4215,
314,
3623,
2410,
1006,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
3250,
275,
756,
199,
199,
533,
17270,
14704,
379,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2410,
282,
3623,
365,
28924,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
15626,
5358,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
1245,
965,
2757,
3086,
370,
282,
2222,
13,
4494,
867,
3623,
14,
523,
2047,
883,
1218,
314,
3623,
315,
1177,
370,
642,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
63,
354,
12,
1499,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
63,
354,
275,
3623,
63,
354,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
6430,
9392,
334,
2390,
304,
523,
408,
523,
481,
16139,
701,
282,
3623,
1380,
282,
1245,
965,
2757,
295,
301,
1873,
1354,
14,
819,
16763,
31974,
641,
314,
8113,
6337,
14,
221,
6121,
31974,
641,
314,
5226,
523,
17270,
909,
465,
2013,
701,
314,
6624,
13935,
790,
14,
819,
710,
11647,
10734,
2839,
26,
523,
347,
485,
2479,
63,
2209,
9392,
334,
1430,
12,
1499,
304,
523,
408,
523,
347,
636,
826,
363
] |
[
1898,
7760,
12,
7409,
1603,
14015,
22895,
3630,
443,
89,
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,
26,
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,
3625,
56,
603,
397,
23444,
2656,
14,
421,
199,
1918,
603,
397,
23444,
2656,
365,
282,
4340,
370,
1900,
8500,
315,
3625,
56,
626,
883,
506,
199,
20688,
701,
5957,
13431,
14,
199,
199,
7700,
4508,
282,
7614,
5594,
1929,
370,
17232,
543,
314,
9682,
6701,
14,
199,
7700,
4508,
1265,
1929,
370,
21494,
543,
376,
3411,
14854,
402,
2032,
436,
199,
11853,
1265,
2793,
1133,
664,
370,
11496,
4212,
1265,
26808,
543,
652,
14,
221,
5439,
5431,
12,
199,
13297,
1172,
314,
30914,
436,
330,
300,
848,
402,
882,
10564,
2195,
5705,
14,
221,
710,
603,
397,
23444,
199,
2253,
365,
18329,
370,
1720,
1265,
543,
314,
19045,
1930,
14,
199,
199,
607,
3974,
12,
9245,
787,
282,
2656,
367,
13882,
1958,
3382,
3625,
56,
436,
199,
5159,
18572,
701,
444,
29131,
3788,
5737,
315,
4840,
14,
221,
2779,
365,
11619,
199,
475,
506,
18794,
8605,
12,
3865,
315,
314,
23506,
1709,
652,
5171,
436,
315,
199,
1589,
7773,
83,
365,
5171,
334,
305,
402,
642,
3575,
12,
652,
5171,
282,
199,
14183,
1070,
6688,
13488,
2838,
7773,
436,
376,
3101,
7773,
680,
221,
6184,
199,
1364,
5313,
370,
675,
314,
603,
397,
23444,
1077,
314,
720,
17269,
506,
18025,
4799,
199,
1629,
7773,
14,
199,
199,
10,
22122,
10,
787,
29437,
23594,
1380,
282,
1890,
4907,
83,
4799,
2005,
199,
10,
7836,
4856,
221,
710,
1654,
883,
7814,
3163,
3222,
3788,
370,
282,
2488,
1890,
14,
199,
33,
1890,
883,
3222,
3788,
370,
282,
627,
5358,
10,
641,
314,
1654,
14,
221,
437,
1890,
883,
2597,
199,
13970,
282,
3653,
402,
282,
3623,
12,
2410,
1314,
652,
911,
9128,
1263,
3788,
199,
1589,
1654,
16178,
370,
626,
3623,
14,
221,
6006,
365,
3544,
282,
849,
3623,
543,
199,
889,
536,
14,
199,
199,
27138,
883,
1902,
506,
19860,
503,
7937,
14,
221,
21791,
9245,
787,
199,
2495,
17174,
28924,
1380,
2985,
949,
8088,
1395,
1263,
7556,
14,
199,
624,
199,
199,
504,
1115,
88,
14,
773,
14,
264,
782,
14,
264,
782,
492,
627,
199,
504,
1115,
88,
14,
1018,
492,
6170,
465,
6170,
199,
646,
2022,
199,
646,
900,
199,
646,
2196,
199,
646,
8337,
199,
504,
1300,
772,
492,
330,
708,
2143,
199,
199,
793,
275,
6170,
14,
5572,
342,
199,
199,
3,
4840,
10334,
1202,
701,
849,
199,
885,
8326,
275,
2022,
14,
6243,
8326,
342,
421,
199,
533,
17270,
13005,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
18266,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
12,
1499,
275,
1052,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
8113,
4299,
379,
334,
2390,
304,
523,
408,
481,
16139,
701,
314,
22761,
527,
367,
1924,
892,
1950,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
8113,
15190,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
1950,
1380,
652,
27811,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
304,
272,
291,
14,
388,
275,
1950,
199,
199,
533,
17270,
23679,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
3623,
1380,
282,
1890,
16733,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
2499,
334,
2390,
304,
523,
408,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
3623,
365,
2737,
14,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
17270,
14704,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2544,
282,
3623,
365,
28924,
14,
523,
2494,
1275,
3250,
275,
715,
370,
4215,
314,
3623,
2410,
1006,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
272,
291,
14,
3250,
275,
756,
199,
199,
533,
17270,
14704,
379,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
314,
3623,
436,
2399,
653,
476,
527,
2451,
2410,
282,
3623,
365,
28924,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
3623,
304,
272,
291,
14,
2775,
275,
3623,
199,
199,
533,
15626,
5358,
334,
2390,
304,
523,
408,
523,
481,
16139,
641,
282,
653,
476,
527,
1380,
282,
1245,
965,
2757,
3086,
370,
282,
2222,
13,
4494,
867,
3623,
14,
523,
2047,
883,
1218,
314,
3623,
315,
1177,
370,
642,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
12,
1950,
12,
3623,
63,
354,
12,
1499,
304,
272,
291,
14,
388,
275,
1950,
272,
291,
14,
2775,
63,
354,
275,
3623,
63,
354,
272,
291,
14,
1328,
275,
1499,
199,
199,
533,
6430,
9392,
334,
2390,
304,
523,
408,
523,
481,
16139,
701,
282,
3623,
1380,
282,
1245,
965,
2757,
295,
301,
1873,
1354,
14,
819,
16763,
31974,
641,
314,
8113,
6337,
14,
221,
6121,
31974,
641,
314,
5226,
523,
17270,
909,
465,
2013,
701,
314,
6624,
13935,
790,
14,
819,
710,
11647,
10734,
2839,
26,
523,
347,
485,
2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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dhanunjaya/neutron
|
neutron/tests/unit/hacking/test_checks.py
|
24
|
6380
|
# 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 testtools
from neutron.hacking import checks
from neutron.tests import base
class HackingTestCase(base.BaseTestCase):
def assertLinePasses(self, func, line):
with testtools.ExpectedException(StopIteration):
next(func(line))
def assertLineFails(self, func, line):
self.assertIsInstance(next(func(line)), tuple)
def test_log_translations(self):
expected_marks = {
'error': '_LE',
'info': '_LI',
'warn': '_LW',
'warning': '_LW',
'critical': '_LC',
'exception': '_LE',
}
logs = expected_marks.keys()
debug = "LOG.debug('OK')"
self.assertEqual(
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
for log in logs:
bad = 'LOG.%s("Bad")' % log
self.assertEqual(
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
ok = "LOG.%s('OK') # noqa" % log
self.assertEqual(
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
ok = "LOG.%s(variable)" % log
self.assertEqual(
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
for mark in checks._all_hints:
stmt = "LOG.%s(%s('test'))" % (log, mark)
self.assertEqual(
0 if expected_marks[log] == mark else 1,
len(list(checks.validate_log_translations(stmt, stmt,
'f'))))
def test_no_translate_debug_logs(self):
for hint in checks._all_hints:
bad = "LOG.debug(%s('bad'))" % hint
self.assertEqual(
1, len(list(checks.no_translate_debug_logs(bad, 'f'))))
def test_use_jsonutils(self):
def __get_msg(fun):
msg = ("N321: jsonutils.%(fun)s must be used instead of "
"json.%(fun)s" % {'fun': fun})
return [(0, msg)]
for method in ('dump', 'dumps', 'load', 'loads'):
self.assertEqual(
__get_msg(method),
list(checks.use_jsonutils("json.%s(" % method,
"./neutron/common/rpc.py")))
self.assertEqual(0,
len(list(checks.use_jsonutils("jsonx.%s(" % method,
"./neutron/common/rpc.py"))))
self.assertEqual(0,
len(list(checks.use_jsonutils("json.%sx(" % method,
"./neutron/common/rpc.py"))))
self.assertEqual(0,
len(list(checks.use_jsonutils(
"json.%s" % method,
"./neutron/plugins/ml2/drivers/openvswitch/agent/xenapi/"
"etc/xapi.d/plugins/netwrap"))))
def test_assert_called_once_with(self):
fail_code1 = """
mock = Mock()
mock.method(1, 2, 3, test='wow')
mock.method.assert_called_once()
"""
fail_code2 = """
mock = Mock()
mock.method(1, 2, 3, test='wow')
mock.method.assertCalledOnceWith()
"""
fail_code3 = """
mock = Mock()
mock.method(1, 2, 3, test='wow')
mock.method.assert_has_called()
"""
pass_code = """
mock = Mock()
mock.method(1, 2, 3, test='wow')
mock.method.assert_called_once_with()
"""
pass_code2 = """
mock = Mock()
mock.method(1, 2, 3, test='wow')
mock.method.assert_has_calls()
"""
self.assertEqual(
1, len(list(checks.check_assert_called_once_with(fail_code1,
"neutron/tests/test_assert.py"))))
self.assertEqual(
1, len(list(checks.check_assert_called_once_with(fail_code2,
"neutron/tests/test_assert.py"))))
self.assertEqual(
0, len(list(checks.check_assert_called_once_with(pass_code,
"neutron/tests/test_assert.py"))))
self.assertEqual(
1, len(list(checks.check_assert_called_once_with(fail_code3,
"neutron/tests/test_assert.py"))))
self.assertEqual(
0, len(list(checks.check_assert_called_once_with(pass_code2,
"neutron/tests/test_assert.py"))))
def test_check_oslo_namespace_imports(self):
f = checks.check_oslo_namespace_imports
self.assertLinePasses(f, 'from oslo_utils import importutils')
self.assertLinePasses(f, 'import oslo_messaging')
self.assertLineFails(f, 'from oslo.utils import importutils')
self.assertLineFails(f, 'from oslo import messaging')
self.assertLineFails(f, 'import oslo.messaging')
def test_check_python3_xrange(self):
f = checks.check_python3_xrange
self.assertLineFails(f, 'a = xrange(1000)')
self.assertLineFails(f, 'b =xrange ( 42 )')
self.assertLineFails(f, 'c = xrange(1, 10, 2)')
self.assertLinePasses(f, 'd = range(1000)')
self.assertLinePasses(f, 'e = six.moves.range(1337)')
def test_no_basestring(self):
self.assertEqual(1,
len(list(checks.check_no_basestring("isinstance(x, basestring)"))))
def test_check_python3_iteritems(self):
f = checks.check_python3_no_iteritems
self.assertLineFails(f, "d.iteritems()")
self.assertLinePasses(f, "six.iteritems(d)")
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
30741,
199,
199,
504,
8224,
14,
20875,
316,
492,
5920,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
30802,
316,
1746,
8,
1095,
14,
20760,
304,
339,
347,
702,
3049,
48,
1916,
8,
277,
12,
2562,
12,
1004,
304,
267,
543,
30741,
14,
6964,
1726,
8,
30139,
304,
288,
2163,
8,
1532,
8,
604,
430,
339,
347,
702,
3049,
4874,
83,
8,
277,
12,
2562,
12,
1004,
304,
267,
291,
14,
6926,
8,
2184,
8,
1532,
8,
604,
1826,
2008,
9,
339,
347,
511,
63,
793,
63,
13982,
8,
277,
304,
267,
1420,
63,
10375,
275,
469,
288,
283,
705,
356,
2513,
906,
297,
288,
283,
815,
356,
2513,
2673,
297,
288,
283,
4050,
356,
2513,
20145,
297,
288,
283,
3764,
356,
2513,
20145,
297,
288,
283,
13138,
356,
2513,
7027,
297,
288,
283,
1971,
356,
2513,
906,
297,
267,
789,
267,
9610,
275,
1420,
63,
10375,
14,
1612,
342,
267,
3105,
275,
298,
4947,
14,
1757,
360,
3593,
19124,
267,
291,
14,
629,
8,
288,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
1757,
12,
3105,
12,
283,
70,
31789,
267,
367,
943,
315,
9610,
26,
288,
4875,
275,
283,
4947,
4111,
83,
480,
5725,
32292,
450,
943,
288,
291,
14,
629,
8,
355,
413,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
4087,
12,
4875,
12,
283,
70,
31789,
288,
4112,
275,
298,
4947,
4111,
83,
360,
3593,
358,
259,
327,
8151,
2,
450,
943,
288,
291,
14,
629,
8,
355,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
745,
12,
4112,
12,
283,
70,
31789,
288,
4112,
275,
298,
4947,
4111,
83,
8,
1975,
2924,
450,
943,
288,
291,
14,
629,
8,
355,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
745,
12,
4112,
12,
283,
70,
31789,
953,
367,
2216,
315,
5920,
423,
452,
63,
12354,
26,
355,
12284,
275,
298,
4947,
4111,
83,
4042,
83,
360,
396,
1333,
2,
450,
334,
793,
12,
2216,
9,
355,
291,
14,
629,
8,
490,
378,
340,
1420,
63,
10375,
59,
793,
61,
508,
2216,
587,
413,
12,
490,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
9649,
12,
12284,
12,
16854,
283,
70,
31789,
339,
347,
511,
63,
889,
63,
5275,
63,
1757,
63,
7270,
8,
277,
304,
267,
367,
8328,
315,
5920,
423,
452,
63,
12354,
26,
288,
4875,
275,
298,
4947,
14,
1757,
4042,
83,
360,
4087,
1333,
2,
450,
8328,
288,
291,
14,
629,
8,
355,
413,
12,
822,
8,
513,
8,
8625,
14,
889,
63,
5275,
63,
1757,
63,
7270,
8,
4087,
12,
283,
70,
31789,
339,
347,
511,
63,
1180,
63,
1001,
1208,
8,
277,
304,
267,
347,
636,
362,
63,
1328,
8,
7036,
304,
288,
1499,
275,
1689,
46,
12638,
26,
18705,
31706,
7036,
9,
83,
1471,
506,
1202,
3140,
402,
298,
673,
298,
1001,
31706,
7036,
9,
83,
2,
450,
791,
7036,
356,
9627,
1552,
288,
372,
3842,
16,
12,
1499,
1874,
398,
367,
1083,
315,
661,
2724,
297,
283,
4180,
297,
283,
912,
297,
283,
3640,
735,
288,
291,
14,
629,
8,
355,
636,
362,
63,
1328,
8,
765,
395,
355,
769,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
4111,
83,
480,
450,
1083,
12,
5101,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
13324,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
88,
4111,
83,
480,
450,
1083,
12,
6343,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
2237,
430,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
4111,
12915,
480,
450,
1083,
12,
6343,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
2237,
430,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
8,
490,
298,
1001,
4111,
83,
2,
450,
1083,
12,
490,
26069,
10271,
15,
5265,
15,
757,
18,
15,
13337,
15,
1490,
23201,
15,
4054,
15,
20392,
6687,
490,
298,
6839,
15,
32751,
14,
68,
15,
5265,
15,
846,
3823,
2237,
430,
339,
347,
511,
63,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
304,
267,
2449,
63,
600,
17,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
3527,
63,
5089,
342,
2049,
408,
267,
2449,
63,
600,
18,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
10474,
25690,
3007,
342,
2049,
408,
267,
2449,
63,
600,
19,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
1989,
63,
3527,
342,
2049,
408,
267,
986,
63,
600,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
2049,
408,
267,
986,
63,
600,
18,
275
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
30741,
199,
199,
504,
8224,
14,
20875,
316,
492,
5920,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
30802,
316,
1746,
8,
1095,
14,
20760,
304,
339,
347,
702,
3049,
48,
1916,
8,
277,
12,
2562,
12,
1004,
304,
267,
543,
30741,
14,
6964,
1726,
8,
30139,
304,
288,
2163,
8,
1532,
8,
604,
430,
339,
347,
702,
3049,
4874,
83,
8,
277,
12,
2562,
12,
1004,
304,
267,
291,
14,
6926,
8,
2184,
8,
1532,
8,
604,
1826,
2008,
9,
339,
347,
511,
63,
793,
63,
13982,
8,
277,
304,
267,
1420,
63,
10375,
275,
469,
288,
283,
705,
356,
2513,
906,
297,
288,
283,
815,
356,
2513,
2673,
297,
288,
283,
4050,
356,
2513,
20145,
297,
288,
283,
3764,
356,
2513,
20145,
297,
288,
283,
13138,
356,
2513,
7027,
297,
288,
283,
1971,
356,
2513,
906,
297,
267,
789,
267,
9610,
275,
1420,
63,
10375,
14,
1612,
342,
267,
3105,
275,
298,
4947,
14,
1757,
360,
3593,
19124,
267,
291,
14,
629,
8,
288,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
1757,
12,
3105,
12,
283,
70,
31789,
267,
367,
943,
315,
9610,
26,
288,
4875,
275,
283,
4947,
4111,
83,
480,
5725,
32292,
450,
943,
288,
291,
14,
629,
8,
355,
413,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
4087,
12,
4875,
12,
283,
70,
31789,
288,
4112,
275,
298,
4947,
4111,
83,
360,
3593,
358,
259,
327,
8151,
2,
450,
943,
288,
291,
14,
629,
8,
355,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
745,
12,
4112,
12,
283,
70,
31789,
288,
4112,
275,
298,
4947,
4111,
83,
8,
1975,
2924,
450,
943,
288,
291,
14,
629,
8,
355,
378,
12,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
745,
12,
4112,
12,
283,
70,
31789,
953,
367,
2216,
315,
5920,
423,
452,
63,
12354,
26,
355,
12284,
275,
298,
4947,
4111,
83,
4042,
83,
360,
396,
1333,
2,
450,
334,
793,
12,
2216,
9,
355,
291,
14,
629,
8,
490,
378,
340,
1420,
63,
10375,
59,
793,
61,
508,
2216,
587,
413,
12,
490,
822,
8,
513,
8,
8625,
14,
3502,
63,
793,
63,
13982,
8,
9649,
12,
12284,
12,
16854,
283,
70,
31789,
339,
347,
511,
63,
889,
63,
5275,
63,
1757,
63,
7270,
8,
277,
304,
267,
367,
8328,
315,
5920,
423,
452,
63,
12354,
26,
288,
4875,
275,
298,
4947,
14,
1757,
4042,
83,
360,
4087,
1333,
2,
450,
8328,
288,
291,
14,
629,
8,
355,
413,
12,
822,
8,
513,
8,
8625,
14,
889,
63,
5275,
63,
1757,
63,
7270,
8,
4087,
12,
283,
70,
31789,
339,
347,
511,
63,
1180,
63,
1001,
1208,
8,
277,
304,
267,
347,
636,
362,
63,
1328,
8,
7036,
304,
288,
1499,
275,
1689,
46,
12638,
26,
18705,
31706,
7036,
9,
83,
1471,
506,
1202,
3140,
402,
298,
673,
298,
1001,
31706,
7036,
9,
83,
2,
450,
791,
7036,
356,
9627,
1552,
288,
372,
3842,
16,
12,
1499,
1874,
398,
367,
1083,
315,
661,
2724,
297,
283,
4180,
297,
283,
912,
297,
283,
3640,
735,
288,
291,
14,
629,
8,
355,
636,
362,
63,
1328,
8,
765,
395,
355,
769,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
4111,
83,
480,
450,
1083,
12,
5101,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
13324,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
88,
4111,
83,
480,
450,
1083,
12,
6343,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
2237,
430,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
480,
1001,
4111,
12915,
480,
450,
1083,
12,
6343,
26069,
10271,
15,
2330,
15,
4354,
14,
647,
2237,
430,
953,
291,
14,
629,
8,
16,
12,
355,
822,
8,
513,
8,
8625,
14,
1180,
63,
1001,
1208,
8,
490,
298,
1001,
4111,
83,
2,
450,
1083,
12,
490,
26069,
10271,
15,
5265,
15,
757,
18,
15,
13337,
15,
1490,
23201,
15,
4054,
15,
20392,
6687,
490,
298,
6839,
15,
32751,
14,
68,
15,
5265,
15,
846,
3823,
2237,
430,
339,
347,
511,
63,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
304,
267,
2449,
63,
600,
17,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
3527,
63,
5089,
342,
2049,
408,
267,
2449,
63,
600,
18,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
10474,
25690,
3007,
342,
2049,
408,
267,
2449,
63,
600,
19,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
1989,
63,
3527,
342,
2049,
408,
267,
986,
63,
600,
275,
408,
2049,
1683,
275,
4420,
342,
2049,
1683,
14,
765,
8,
17,
12,
499,
12,
650,
12,
511,
534,
87,
583,
358,
2049,
1683,
14,
765,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
2049,
408,
267,
986,
63,
600,
18,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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pype
class AccessSlides:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Using Slides Collection to Access Slide by Index
AccessSlides.get_slide_by_index(self.dataDir)
# Using Slides Collection to Access Slide by ID
AccessSlides.get_slide_by_id(self.dataDir)
def get_slide_by_index(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Accessing a slide using its slide index
slide = pres.getSlides().get_Item(0)
print "Slide: " . slide
def get_slide_by_id(self):
# Instantiate Presentation class that represents the presentation file
pres=self.Presentation()
pres = pres(self.dataDir + 'Aspose.pptx')
# Getting Slide ID
id = pres.getSlides().get_Item(0).getSlideId()
# Accessing Slide by ID
slide = pres.getSlideById(id)
print "Slide: " . slide
class AddSlides:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation()
# Instantiate SlideCollection calss
slides = pres.getSlides()
i = 0
while (i < pres.getLayoutSlides().size()):
# Add an empty slide to the Slides collection
slides.addEmptySlide(pres.getLayoutSlides().get_Item(i))
i+=1
#Do some work on the newly added slide
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "EmptySlide.pptx", save_format.Pptx)
print "Document has been created, please check the output file."
class Background:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
self.BackgroundType=jpype.JClass("com.aspose.slides.BackgroundType")
self.FillType=jpype.JClass("com.aspose.slides.FillType")
self.PictureFillMode=jpype.JClass("com.aspose.slides.PictureFillMode")
self.Color=jpype.JClass("java.awt.Color")
self.File=jpype.JClass("java.io.File")
self.FileInputStream=jpype.JClass("java.io.FileInputStream")
def main(self):
# Setting the Background Color of a Master Slide
self.set_background_color_of_master_slide()
# Setting the Background Color of a Normal Slide
self.set_background_color_of_normal_slide()
# Setting the Slide Background to an Image
self.set_image_as_background_color()
def set_background_color_of_master_slide(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation()
# Set the background color of the Master Slide to Forest Green
backgroundType = self.BackgroundType
fillType = self.FillType
color = self.Color
pres.getMasters().get_Item(0).getBackground().setType(backgroundType.OwnBackground)
pres.getMasters().get_Item(0).getBackground().getFillFormat().setFillType(fillType.Solid)
pres.getMasters().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(color.GREEN)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "MasterBG.pptx", save_format.Pptx)
print "Set background color of master slide, please check the output file."
def set_background_color_of_normal_slide(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation()
# Set the background color of the Normal slide to Blue
backgroundType = self.BackgroundType
fillType = self.FillType
color = self.Color
pres.getSlides().get_Item(0).getBackground().setType(backgroundType.OwnBackground)
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(fillType.Solid)
pres.getSlides().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(color.BLUE)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "ContentBG.pptx", save_format.Pptx)
print "Set background color of normal slide, please check the output file."
def set_image_as_background_color(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation
# Set the background with Image
backgroundType = self.BackgroundType
fillType = self.FillType
pictureFillMode = self.PictureFillMode
pres.getSlides().get_Item(0).getBackground().setType(backgroundType.OwnBackground)
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(fillType.Picture)
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().setPictureFillMode(pictureFillMode.Stretch)
# Set the picture
imgx = pres.getImages().addImage(self.FileInputStream(self.File(self.dataDir + 'night.jpg')))
# Image imgx = pres.getImages().addImage(image)
# Add image to presentation's images collection
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "ContentBG_Image.pptx", save_format.Pptx)
print "Set image as background, please check the output file."
class ChangingPosition:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Get the slide whose position is to be changed
slide = pres.getSlides().get_Item(0)
# Set the self.position for the slide
slide.setSlideNumber(1)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "Aspose_Position.pptx", save_format.Pptx)
print "Changes slide position, please check the output file."
class CloneSlides:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Within the Same Presentation from One Position to the End
self.clone_to_end_of_presentation()
# From One Position to Anther within the Same Presentation
self.clone_to_aonther_position()
# In Another Presentation at the End of the Existing Slides
self.clone_to_other_presentation_at_end_of_existing_slide()
def clone_to_end_of_presentation(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Clone the desired slide to the end of the collection of slides in the same presentation
slides = pres.getSlides()
slides.addClone(pres.getSlides().get_Item(0))
# Saving the presentation file
save_format = self.SaveFormat
pres.save(self.dataDir + "Aspose_Cloned.pptx", save_format.Pptx)
print "Slide has been cloned, please check the output file."
def clone_to_aonther_position(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Clone the desired slide to the end of the collection of slides in the same presentation
slides = pres.getSlides()
# Clone the desired slide to the specified index in the same presentation
slides.insertClone(1, pres.getSlides().get_Item(0))
# Saving the presentation file
save_format = self.SaveFormat
pres.save(self.dataDir + "Aspose_Cloned.pptx", save_format.Pptx)
print "Slide has been cloned, please check the output file."
def clone_to_other_presentation_at_end_of_existing_slide(self):
# Instantiate Presentation class that represents the presentation file
src_pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Instantiate Presentation class for destination PPTX (where slide is to be cloned)
dest_pres = self.Presentation()
# Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation
slds = dest_pres.getSlides()
slds.addClone(src_pres.getSlides().get_Item(0))
# Saving the presentation file
save_format = self.SaveFormat
dest_pres.save(self.dataDir + "Aspose_dest2.pptx", save_format.Pptx)
print "Slide has been cloned, please check the output file."
class CreatingSvg:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
self.FileOutputStream=jpype.JClass("java.io.FileOutputStream")
def main(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation
pres = pres(self.dataDir + 'Aspose.pptx')
# Getting last slide index
last_slide_position = pres.getSlides().size()
#Iterating through every presentation slide and generating SVG image
i = 0
while (i < last_slide_position):
# Accessing Slides
slide = pres.getSlides().get_Item(i)
# Getting and saving the slide SVG image
slide.writeAsSvg(self.FileOutputStream(self.dataDir + "SvgImage#i.svg"))
i+=1
print "Created SVG images, please check output files."
class Hyperlinks:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation
pres = pres(self.dataDir + 'Aspose.pptx')
# Removing the hyperlinks from presentation
pres.getHyperlinkQueries().removeAllHyperlinks()
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "Hyperlinks.pptx", save_format.Pptx)
print "Removed hyperlinks successfully, please check the output file."
class RemoveSlides:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
def main(self):
# Using Slides Collection to Remove Slide by Index
self.remove_slide_by_index()
# Using Slides Collection to Remove Slide by ID
self.remove_slide_by_id()
def remove_slide_by_index(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Accessing a slide using its slide index
slide = pres.getSlides().get_Item(0)
# Removing a slide using its reference
pres.getSlides().remove(slide)
# Saving the presentation file
save_format = self.SaveFormat
pres.save(self.dataDir + "Modified.pptx", save_format.Pptx)
print "Removed slide by Index, please check the output file."
def remove_slide_by_id(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
# Removing a slide using its slide index
pres.getSlides().removeAt(0)
# Saving the presentation file
save_format = self.SaveFormat
pres.save(self.dataDir + "Modified.pptx", save_format.Pptx)
print "Removed slide by ID, please check the output file."
class SizeAndLayout:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
self.SlideSizeType=jpype.JClass("com.aspose.slides.SlideSizeType")
self.slidesOptions=jpype.JClass("com.aspose.slides.PdfOptions")
def main(self):
# Setting the Size and Type of a slide
self.set_size_and_type()
# Setting the page size when generating slides
self.set_page_size_for_slides()
def set_size_and_type(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
aux_pres = self.Presentation()
slide = pres.getSlides().get_Item(0)
# Set the slide size of generated presentations to that of source
aux_pres.getSlideSize().setType(pres.getSlideSize().getType())
aux_pres.getSlideSize().setSize(pres.getSlideSize().getSize())
# Clone required slide
aux_pres.getSlides().addClone(pres.getSlides().get_Item(0))
aux_pres.getSlides().removeAt(0)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "Slide_Size_Type.pptx", save_format.Pptx)
print "Set slide size and type, please check the output file."
def set_page_size_for_slides(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation()
# Set SlideSize.Type Property
slideSizeType = self.SlideSizeType
pres.getSlideSize().setType(slideSizeType.A4Paper)
# Set different properties of slides Options
opts = self.slidesOptions
opts.setSufficientResolution(600)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "Export.slides", save_format.slides, opts)
print "Set page size for slides, please check the output file."
class Thumbnail:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
self.ImageIO=jpype.JClass("javax.ImageIO")
self.File=jpype.JClass("java.io.File")
def main(self):
# Generating a Thumbnail from a Slide
self.create_thumbnail()
# Generating a Thumbnail from a Slide with User Defined Dimensions
self.create_thumbnail_custom_size()
# Generating a Thumbnail from a Slide in Notes Slides View
self.create_thumbnail_in_notes_slides_view()
# Generating a Thumbnail of User Defined Window from a Slide
self.create_thumbnail_of_user_defined_window()
def create_thumbnail(self):
# Instantiate Presentation class that represents the presentation file
pres=self.Presentation
pres = pres(self.dataDir + 'Aspose.pptx')
# Access the first slide
slide = pres.getSlides().get_Item(0)
# Create a full scale image
image = slide.getThumbnail()
# Save the image to disk in JPEG format
imageIO = self.ImageIO()
imageIO.write(image, "jpeg", self.File(self.dataDir + "ContentBG_tnail.jpg"))
print "Created thumbnail, please check the output file."
def create_thumbnail_custom_size(self):
# Instantiate Presentation class that represents the presentation file
pres=self.Presentation()
pres = pres(self.dataDir + 'Aspose.pptx')
# Access the first slide
slide = pres.getSlides().get_Item(0)
# User defined dimension
desired_x = 1200
desired_y = 800
# Getting scaled value of X and Y
scale_x = (1.0 / pres.getSlideSize().getSize().getWidth()) * desired_x
scale_y = (1.0 / pres.getSlideSize().getSize().getHeight()) * desired_y
# Create a full scale image
image = slide.getThumbnail(scale_x, scale_y)
# Save the image to disk in JPEG format
imageIO = self.ImageIO()
imageIO.write(image, "jpeg", self.File(self.dataDir + "ContentBG_tnail.jpg"))
print "Created thumbnail with custom size, please check the output file."
def create_thumbnail_in_notes_slides_view(self):
# Instantiate Presentation class that represents the presentation file
pres=self.Presentation()
pres = pres(self.dataDir + 'Aspose.pptx')
# Access the first slide
slide = pres.getSlides().get_Item(0)
# User defined dimension
desired_x = 1200
desired_y = 800
# Getting scaled value of X and Y
scale_x = (1.0 / pres.getSlideSize().getSize().getWidth()) * desired_x
scale_y = (1.0 / pres.getSlideSize().getSize().getHeight()) * desired_y
# Create a full scale image
image = slide.getNotesSlide().getThumbnail(scale_x, scale_y)
# Save the image to disk in JPEG format
imageIO = self.ImageIO()
imageIO.write(image, "jpeg", self.File(self.dataDir + "ContentBG_tnail.jpg"))
print "Created thumbnail in notes slides view, please check the output file."
def create_thumbnail_of_user_defined_window(self):
# Instantiate Presentation class that represents the presentation file
pres=self.Presentation()
pres = pres(self.dataDir + 'Aspose.pptx')
# Access the first slide
slide = pres.getSlides().get_Item(0)
# Create a full scale image
image = slide.getThumbnail(1,1)
# Getting the image of desired window inside generated slide thumnbnail
# BufferedImage window = image.getSubimage(windowX, windowY, windowsWidth, windowHeight)
window_image = image.getSubimage(100, 100, 200, 200)
# Save the image to disk in JPEG format
imageIO = self.ImageIO()
imageIO.write(image, "jpeg", self.File(self.dataDir + "ContentBG_tnail.jpg"))
print "Created thumbnail of user defined window, please check the output file."
class Transitions:
def __init__(self, dataDir):
print "init func"
self.dataDir = dataDir
self.Presentation=jpype.JClass("com.aspose.slides.Presentation")
self.SaveFormat=jpype.JClass("com.aspose.slides.SaveFormat")
self.TransitionType=jpype.JClass("com.aspose.slides.TransitionType")
def main(self):
# Instantiate Presentation class that represents the presentation file
pres = self.Presentation(self.dataDir + 'Aspose.pptx')
transition_type = self.TransitionType
# Apply circle type transition on slide 1
pres.getSlides().get_Item(0).getSlideShowTransition().setType(transition_type.Circle)
# Apply comb type transition on slide 2
pres.getSlides().get_Item(0).getSlideShowTransition().setType(transition_type.Comb)
# Saving the presentation
save_format = self.SaveFormat
pres.save(self.dataDir + "SimpleTransition.pptx", save_format.Pptx)
print "Done with simple transition, please check the output file."
|
mit
|
[
363,
2502,
363,
275,
283,
667,
72,
350,
9587,
352,
7,
199,
646,
28921,
514,
199,
199,
533,
11003,
51,
317,
3424,
26,
339,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
339,
347,
2446,
8,
277,
304,
953,
327,
11719,
428,
317,
3424,
18003,
370,
11003,
428,
8409,
701,
5499,
267,
11003,
51,
317,
3424,
14,
362,
63,
19968,
63,
991,
63,
1080,
8,
277,
14,
576,
3567,
9,
398,
327,
11719,
428,
317,
3424,
18003,
370,
11003,
428,
8409,
701,
2870,
267,
11003,
51,
317,
3424,
14,
362,
63,
19968,
63,
991,
63,
344,
8,
277,
14,
576,
3567,
9,
339,
347,
664,
63,
19968,
63,
991,
63,
1080,
8,
277,
304,
398,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
275,
291,
14,
19794,
425,
8,
277,
14,
576,
3567,
435,
283,
2822,
4070,
14,
80,
541,
88,
358,
398,
327,
11003,
316,
282,
27063,
1808,
2399,
27063,
1478,
267,
27063,
275,
25210,
14,
362,
51,
317,
3424,
1252,
362,
63,
2081,
8,
16,
9,
398,
870,
298,
51,
8409,
26,
298,
1275,
27063,
339,
347,
664,
63,
19968,
63,
991,
63,
344,
8,
277,
304,
398,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
29,
277,
14,
19794,
425,
342,
267,
25210,
275,
25210,
8,
277,
14,
576,
3567,
435,
283,
2822,
4070,
14,
80,
541,
88,
358,
398,
327,
20703,
428,
8409,
2870,
267,
1305,
275,
25210,
14,
362,
51,
317,
3424,
1252,
362,
63,
2081,
8,
16,
680,
362,
51,
8409,
1304,
342,
398,
327,
11003,
316,
428,
8409,
701,
2870,
267,
27063,
275,
25210,
14,
362,
51,
8409,
18954,
8,
344,
9,
398,
870,
298,
51,
8409,
26,
298,
1275,
27063,
199,
199,
533,
2654,
51,
317,
3424,
26,
10813,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
10813,
347,
2446,
8,
277,
304,
268,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
275,
291,
14,
19794,
425,
342,
398,
327,
32092,
428,
8409,
7768,
3213,
385,
267,
27498,
3424,
275,
25210,
14,
362,
51,
317,
3424,
342,
398,
284,
275,
378,
267,
1830,
334,
73,
665,
25210,
14,
362,
4798,
51,
317,
3424,
1252,
890,
5109,
953,
327,
2654,
376,
2701,
27063,
370,
314,
428,
317,
3424,
3245,
288,
27498,
3424,
14,
525,
4699,
51,
8409,
8,
24919,
14,
362,
4798,
51,
317,
3424,
1252,
362,
63,
2081,
8,
73,
430,
288,
284,
10365,
17,
13359,
398,
327,
2585,
2005,
1736,
641,
314,
13903,
3483,
27063,
398,
327,
428,
5519,
314,
3451,
425,
267,
3354,
63,
908,
275,
291,
14,
8229,
3484,
267,
25210,
14,
2117,
8,
277,
14,
576,
3567,
435,
298,
4699,
51,
8409,
14,
80,
541,
88,
401,
3354,
63,
908,
14,
48,
541,
88,
9,
398,
870,
298,
5564,
965,
2757,
2737,
12,
8749,
1104,
314,
1072,
570,
2122,
199,
199,
533,
10257,
3928,
26,
398,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
288,
291,
14,
14148,
804,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
14148,
804,
531,
288,
291,
14,
12914,
804,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
12914,
804,
531,
288,
291,
14,
29439,
12914,
1385,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
29439,
12914,
1385,
531,
288,
291,
14,
4117,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
65,
9115,
14,
4117,
531,
288,
291,
14,
1173,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
2308,
14,
1173,
531,
288,
291,
14,
1173,
27611,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
2308,
14,
1173,
27611,
531,
398,
347,
2446,
8,
277,
304,
7846,
327,
13510,
314,
10257,
3928,
11581,
402,
282,
26728,
428,
8409,
288,
291,
14,
409,
63,
7451,
63,
2326,
63,
1618,
63,
4133,
63,
19968,
342,
953,
327,
13510,
314,
10257,
3928,
11581,
402,
282,
11514,
428,
8409,
288,
291,
14,
409,
63,
7451,
63,
2326,
63,
1618,
63,
3302,
63,
19968,
342,
953,
327,
13510,
314,
428,
8409,
10257,
3928,
370,
376,
6047,
288,
291,
14,
409,
63,
1569,
63,
305,
63,
7451,
63,
2326,
342,
398,
347,
663,
63,
7451,
63,
2326,
63,
1618,
63,
4133,
63,
19968,
8,
277,
304,
953,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
288,
25210,
275,
291,
14,
19794,
425,
342,
953,
327,
2494,
314,
8020,
3164,
402,
314,
26728,
428,
8409,
370,
21684,
270,
32585,
288,
8020,
804,
275,
291,
14,
14148,
804,
288,
5554,
804,
275,
291,
14,
12914,
804,
288,
3164,
275,
291,
14,
4117,
953,
25210,
14,
362,
45,
305,
878,
1252,
362,
63,
2081,
8,
16,
680,
362,
14148,
1252,
409,
804,
8,
7451,
804,
14,
28492,
14148,
9,
288,
25210,
14,
362,
45,
305,
878,
1252,
362,
63,
2081,
8,
16,
680,
362,
14148,
1252,
362,
12914,
3484,
1252,
409,
12914,
804,
8,
4498,
804,
14,
5158,
7401,
9,
288,
25210,
14,
362,
45,
305,
878
] |
[
2502,
363,
275,
283,
667,
72,
350,
9587,
352,
7,
199,
646,
28921,
514,
199,
199,
533,
11003,
51,
317,
3424,
26,
339,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
339,
347,
2446,
8,
277,
304,
953,
327,
11719,
428,
317,
3424,
18003,
370,
11003,
428,
8409,
701,
5499,
267,
11003,
51,
317,
3424,
14,
362,
63,
19968,
63,
991,
63,
1080,
8,
277,
14,
576,
3567,
9,
398,
327,
11719,
428,
317,
3424,
18003,
370,
11003,
428,
8409,
701,
2870,
267,
11003,
51,
317,
3424,
14,
362,
63,
19968,
63,
991,
63,
344,
8,
277,
14,
576,
3567,
9,
339,
347,
664,
63,
19968,
63,
991,
63,
1080,
8,
277,
304,
398,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
275,
291,
14,
19794,
425,
8,
277,
14,
576,
3567,
435,
283,
2822,
4070,
14,
80,
541,
88,
358,
398,
327,
11003,
316,
282,
27063,
1808,
2399,
27063,
1478,
267,
27063,
275,
25210,
14,
362,
51,
317,
3424,
1252,
362,
63,
2081,
8,
16,
9,
398,
870,
298,
51,
8409,
26,
298,
1275,
27063,
339,
347,
664,
63,
19968,
63,
991,
63,
344,
8,
277,
304,
398,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
29,
277,
14,
19794,
425,
342,
267,
25210,
275,
25210,
8,
277,
14,
576,
3567,
435,
283,
2822,
4070,
14,
80,
541,
88,
358,
398,
327,
20703,
428,
8409,
2870,
267,
1305,
275,
25210,
14,
362,
51,
317,
3424,
1252,
362,
63,
2081,
8,
16,
680,
362,
51,
8409,
1304,
342,
398,
327,
11003,
316,
428,
8409,
701,
2870,
267,
27063,
275,
25210,
14,
362,
51,
8409,
18954,
8,
344,
9,
398,
870,
298,
51,
8409,
26,
298,
1275,
27063,
199,
199,
533,
2654,
51,
317,
3424,
26,
10813,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
10813,
347,
2446,
8,
277,
304,
268,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
267,
25210,
275,
291,
14,
19794,
425,
342,
398,
327,
32092,
428,
8409,
7768,
3213,
385,
267,
27498,
3424,
275,
25210,
14,
362,
51,
317,
3424,
342,
398,
284,
275,
378,
267,
1830,
334,
73,
665,
25210,
14,
362,
4798,
51,
317,
3424,
1252,
890,
5109,
953,
327,
2654,
376,
2701,
27063,
370,
314,
428,
317,
3424,
3245,
288,
27498,
3424,
14,
525,
4699,
51,
8409,
8,
24919,
14,
362,
4798,
51,
317,
3424,
1252,
362,
63,
2081,
8,
73,
430,
288,
284,
10365,
17,
13359,
398,
327,
2585,
2005,
1736,
641,
314,
13903,
3483,
27063,
398,
327,
428,
5519,
314,
3451,
425,
267,
3354,
63,
908,
275,
291,
14,
8229,
3484,
267,
25210,
14,
2117,
8,
277,
14,
576,
3567,
435,
298,
4699,
51,
8409,
14,
80,
541,
88,
401,
3354,
63,
908,
14,
48,
541,
88,
9,
398,
870,
298,
5564,
965,
2757,
2737,
12,
8749,
1104,
314,
1072,
570,
2122,
199,
199,
533,
10257,
3928,
26,
398,
347,
636,
826,
721,
277,
12,
666,
3567,
304,
288,
870,
298,
826,
2562,
2,
288,
291,
14,
576,
3567,
275,
666,
3567,
288,
291,
14,
19794,
425,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
19794,
425,
531,
288,
291,
14,
8229,
3484,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
8229,
3484,
531,
288,
291,
14,
14148,
804,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
14148,
804,
531,
288,
291,
14,
12914,
804,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
12914,
804,
531,
288,
291,
14,
29439,
12914,
1385,
29,
11538,
514,
14,
42,
2543,
480,
957,
14,
305,
4070,
14,
23766,
3424,
14,
29439,
12914,
1385,
531,
288,
291,
14,
4117,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
65,
9115,
14,
4117,
531,
288,
291,
14,
1173,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
2308,
14,
1173,
531,
288,
291,
14,
1173,
27611,
29,
11538,
514,
14,
42,
2543,
480,
6138,
14,
2308,
14,
1173,
27611,
531,
398,
347,
2446,
8,
277,
304,
7846,
327,
13510,
314,
10257,
3928,
11581,
402,
282,
26728,
428,
8409,
288,
291,
14,
409,
63,
7451,
63,
2326,
63,
1618,
63,
4133,
63,
19968,
342,
953,
327,
13510,
314,
10257,
3928,
11581,
402,
282,
11514,
428,
8409,
288,
291,
14,
409,
63,
7451,
63,
2326,
63,
1618,
63,
3302,
63,
19968,
342,
953,
327,
13510,
314,
428,
8409,
10257,
3928,
370,
376,
6047,
288,
291,
14,
409,
63,
1569,
63,
305,
63,
7451,
63,
2326,
342,
398,
347,
663,
63,
7451,
63,
2326,
63,
1618,
63,
4133,
63,
19968,
8,
277,
304,
953,
327,
32092,
5543,
1150,
425,
1021,
626,
8469,
314,
3451,
425,
570,
288,
25210,
275,
291,
14,
19794,
425,
342,
953,
327,
2494,
314,
8020,
3164,
402,
314,
26728,
428,
8409,
370,
21684,
270,
32585,
288,
8020,
804,
275,
291,
14,
14148,
804,
288,
5554,
804,
275,
291,
14,
12914,
804,
288,
3164,
275,
291,
14,
4117,
953,
25210,
14,
362,
45,
305,
878,
1252,
362,
63,
2081,
8,
16,
680,
362,
14148,
1252,
409,
804,
8,
7451,
804,
14,
28492,
14148,
9,
288,
25210,
14,
362,
45,
305,
878,
1252,
362,
63,
2081,
8,
16,
680,
362,
14148,
1252,
362,
12914,
3484,
1252,
409,
12914,
804,
8,
4498,
804,
14,
5158,
7401,
9,
288,
25210,
14,
362,
45,
305,
878,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
catapult-project/catapult
|
tracing/tracing/extras/symbolizer/symbolize_trace_macho_reader.py
|
4
|
1048
|
# Copyright 2017 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.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import re
import subprocess
from six.moves import range # pylint: disable=redefined-builtin
def ReadMachOTextLoadAddress(file_name):
"""
This function returns the load address of the TEXT segment of a Mach-O file.
"""
regex = re.compile(r".* vmaddr 0x([\dabcdef]*)")
cmd = ["otool", "-l", file_name]
output = subprocess.check_output(cmd).split('\n')
for i in range(len(output) - 3):
# It's possible to use a regex here instead, but these conditionals are much
# clearer.
if ("cmd LC_SEGMENT_64" in output[i] and
"cmdsize" in output[i + 1] and
"segname __TEXT" in output[i + 2] and
"vmaddr" in output[i + 3]):
result = regex.match(output[i + 3])
assert result
return int(result.group(1), 16)
return None
|
bsd-3-clause
|
[
3,
1898,
9708,
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,
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,
646,
295,
199,
646,
3873,
199,
504,
3816,
14,
4912,
492,
1425,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
421,
199,
318,
5574,
45,
1225,
1387,
832,
6200,
1476,
8,
493,
63,
354,
304,
523,
408,
523,
961,
805,
2529,
314,
2248,
2287,
402,
314,
11951,
8135,
402,
282,
30611,
13,
47,
570,
14,
523,
408,
523,
5163,
275,
295,
14,
2014,
8,
82,
1674,
10,
4169,
2697,
378,
88,
16510,
68,
10678,
3672,
6320,
523,
2088,
275,
2097,
3459,
393,
401,
3905,
76,
401,
570,
63,
354,
61,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
1760,
680,
1294,
2258,
78,
358,
523,
367,
284,
315,
1425,
8,
552,
8,
1199,
9,
446,
650,
304,
272,
327,
2779,
1159,
3962,
370,
675,
282,
5163,
2348,
3140,
12,
1325,
3520,
29265,
787,
8298,
272,
327,
15158,
21462,
14,
272,
340,
1689,
1760,
26703,
63,
27001,
63,
772,
2,
315,
1072,
59,
73,
61,
436,
267,
298,
1760,
890,
2,
315,
1072,
59,
73,
435,
413,
61,
436,
267,
298,
8359,
354,
636,
3876,
2,
315,
1072,
59,
73,
435,
499,
61,
436,
267,
298,
2611,
2697,
2,
315,
1072,
59,
73,
435,
650,
4682,
489,
754,
275,
5163,
14,
1431,
8,
1199,
59,
73,
435,
650,
566,
489,
702,
754,
489,
372,
1109,
8,
1099,
14,
923,
8,
17,
395,
3193,
9,
523,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
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,
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,
646,
295,
199,
646,
3873,
199,
504,
3816,
14,
4912,
492,
1425,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
421,
199,
318,
5574,
45,
1225,
1387,
832,
6200,
1476,
8,
493,
63,
354,
304,
523,
408,
523,
961,
805,
2529,
314,
2248,
2287,
402,
314,
11951,
8135,
402,
282,
30611,
13,
47,
570,
14,
523,
408,
523,
5163,
275,
295,
14,
2014,
8,
82,
1674,
10,
4169,
2697,
378,
88,
16510,
68,
10678,
3672,
6320,
523,
2088,
275,
2097,
3459,
393,
401,
3905,
76,
401,
570,
63,
354,
61,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
1760,
680,
1294,
2258,
78,
358,
523,
367,
284,
315,
1425,
8,
552,
8,
1199,
9,
446,
650,
304,
272,
327,
2779,
1159,
3962,
370,
675,
282,
5163,
2348,
3140,
12,
1325,
3520,
29265,
787,
8298,
272,
327,
15158,
21462,
14,
272,
340,
1689,
1760,
26703,
63,
27001,
63,
772,
2,
315,
1072,
59,
73,
61,
436,
267,
298,
1760,
890,
2,
315,
1072,
59,
73,
435,
413,
61,
436,
267,
298,
8359,
354,
636,
3876,
2,
315,
1072,
59,
73,
435,
499,
61,
436,
267,
298,
2611,
2697,
2,
315,
1072,
59,
73,
435,
650,
4682,
489,
754,
275,
5163,
14,
1431,
8,
1199,
59,
73,
435,
650,
566,
489,
702,
754,
489,
372,
1109,
8,
1099,
14,
923,
8,
17,
395,
3193,
9,
523,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ricco386/broadcaster
|
RPi.Relay/setup.py
|
1
|
1416
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# This software is licensed as described in the README.rst and LICENSE
# files, which you should have received as part of this distribution.
import setuptools
# noinspection PyPep8Naming
from raspi_mc import __version__ as VERSION
DEPS = ['RPi.Sensor>=0.5.2']
CLASSIFIERS = [
'Environment :: Console',
'Intended Audience :: System Administrators',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'Operating System :: Unix',
'Operating System :: POSIX :: Linux',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Development Status :: 1 - Alpha',
'Topic :: Utilities',
'Topic :: Home Automation',
'Topic :: System :: Hardware',
'Topic :: Terminals'
]
with open("README.rst", "r") as fp:
sensor_long_description = fp.read()
setuptools.setup(
name='RPi.Relay',
version=VERSION,
author="Richard von Kellner",
author_email="richard.kellner [at] gmail.com",
url="https://github.com/ricco386/RPi/tree/master/RPi.Relay",
description='RPi.Relay - Relay state operator',
long_description=sensor_long_description,
license="MIT",
packages=setuptools.find_packages(),
classifiers=CLASSIFIERS,
install_requires=DEPS,
scripts=['bin/raspi-relay'],
include_package_data=True
)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
2032,
365,
18233,
465,
11736,
315,
314,
27781,
14,
8332,
436,
5113,
199,
3,
1584,
12,
1314,
1265,
1077,
1172,
3086,
465,
1777,
402,
642,
4084,
14,
199,
646,
9116,
199,
3,
30870,
1611,
48,
1545,
24,
46,
9568,
199,
504,
519,
305,
1038,
63,
5466,
492,
636,
1023,
363,
465,
15945,
199,
199,
1093,
5067,
275,
788,
50,
10542,
14,
10160,
8119,
16,
14,
21,
14,
18,
418,
199,
199,
31163,
1976,
3960,
275,
359,
272,
283,
8263,
3800,
19809,
297,
272,
283,
23910,
23975,
3800,
6187,
9516,
3075,
2750,
297,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
23910,
23975,
3800,
9599,
20123,
15,
20436,
297,
272,
283,
23699,
6187,
3800,
13074,
297,
272,
283,
23699,
6187,
3800,
18169,
3800,
10130,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
272,
283,
11411,
8466,
3800,
2018,
297,
272,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
272,
283,
23753,
9795,
3800,
413,
446,
32657,
297,
272,
283,
12157,
3800,
738,
17933,
297,
272,
283,
12157,
3800,
14621,
9195,
1615,
297,
272,
283,
12157,
3800,
6187,
3800,
22825,
1068,
297,
272,
283,
12157,
3800,
20429,
2551,
7,
199,
61,
199,
199,
1045,
1551,
480,
18195,
14,
8332,
401,
298,
82,
531,
465,
4090,
26,
272,
8778,
63,
2809,
63,
1802,
275,
4090,
14,
739,
342,
199,
199,
13623,
14,
2758,
8,
272,
536,
534,
50,
10542,
14,
5640,
1187,
297,
272,
1015,
29,
4612,
12,
272,
4132,
628,
50,
1158,
1005,
373,
265,
1804,
1697,
1372,
401,
272,
4132,
63,
2123,
628,
10399,
1005,
14,
75,
1697,
1372,
359,
292,
61,
29712,
14,
957,
401,
272,
1166,
628,
2859,
921,
5031,
14,
957,
15,
1567,
331,
8040,
15,
50,
10542,
15,
2350,
15,
4133,
15,
50,
10542,
14,
5640,
1187,
401,
272,
1369,
534,
50,
10542,
14,
5640,
1187,
446,
9781,
1187,
1174,
4182,
297,
272,
1846,
63,
1802,
29,
8956,
63,
2809,
63,
1802,
12,
272,
4190,
628,
13965,
401,
272,
6117,
29,
13623,
14,
1623,
63,
5154,
1062,
272,
19137,
29,
31163,
1976,
3960,
12,
272,
3907,
63,
6537,
29,
1093,
5067,
12,
272,
10554,
2968,
1393,
15,
6360,
1038,
13,
21855,
995,
272,
2387,
63,
2491,
63,
576,
29,
549,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
2032,
365,
18233,
465,
11736,
315,
314,
27781,
14,
8332,
436,
5113,
199,
3,
1584,
12,
1314,
1265,
1077,
1172,
3086,
465,
1777,
402,
642,
4084,
14,
199,
646,
9116,
199,
3,
30870,
1611,
48,
1545,
24,
46,
9568,
199,
504,
519,
305,
1038,
63,
5466,
492,
636,
1023,
363,
465,
15945,
199,
199,
1093,
5067,
275,
788,
50,
10542,
14,
10160,
8119,
16,
14,
21,
14,
18,
418,
199,
199,
31163,
1976,
3960,
275,
359,
272,
283,
8263,
3800,
19809,
297,
272,
283,
23910,
23975,
3800,
6187,
9516,
3075,
2750,
297,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
23910,
23975,
3800,
9599,
20123,
15,
20436,
297,
272,
283,
23699,
6187,
3800,
13074,
297,
272,
283,
23699,
6187,
3800,
18169,
3800,
10130,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
272,
283,
11411,
8466,
3800,
2018,
297,
272,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
272,
283,
23753,
9795,
3800,
413,
446,
32657,
297,
272,
283,
12157,
3800,
738,
17933,
297,
272,
283,
12157,
3800,
14621,
9195,
1615,
297,
272,
283,
12157,
3800,
6187,
3800,
22825,
1068,
297,
272,
283,
12157,
3800,
20429,
2551,
7,
199,
61,
199,
199,
1045,
1551,
480,
18195,
14,
8332,
401,
298,
82,
531,
465,
4090,
26,
272,
8778,
63,
2809,
63,
1802,
275,
4090,
14,
739,
342,
199,
199,
13623,
14,
2758,
8,
272,
536,
534,
50,
10542,
14,
5640,
1187,
297,
272,
1015,
29,
4612,
12,
272,
4132,
628,
50,
1158,
1005,
373,
265,
1804,
1697,
1372,
401,
272,
4132,
63,
2123,
628,
10399,
1005,
14,
75,
1697,
1372,
359,
292,
61,
29712,
14,
957,
401,
272,
1166,
628,
2859,
921,
5031,
14,
957,
15,
1567,
331,
8040,
15,
50,
10542,
15,
2350,
15,
4133,
15,
50,
10542,
14,
5640,
1187,
401,
272,
1369,
534,
50,
10542,
14,
5640,
1187,
446,
9781,
1187,
1174,
4182,
297,
272,
1846,
63,
1802,
29,
8956,
63,
2809,
63,
1802,
12,
272,
4190,
628,
13965,
401,
272,
6117,
29,
13623,
14,
1623,
63,
5154,
1062,
272,
19137,
29,
31163,
1976,
3960,
12,
272,
3907,
63,
6537,
29,
1093,
5067,
12,
272,
10554,
2968,
1393,
15,
6360,
1038,
13,
21855,
995,
272,
2387,
63,
2491,
63,
576,
29,
549,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
pyprism/Hiren-Vault
|
password/migrations/0010_auto_20170129_0026.py
|
2
|
2626
|
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-28 18:26
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import taggit.managers
class Migration(migrations.Migration):
dependencies = [
('taggit', '0002_auto_20150616_2121'),
('password', '0009_auto_20160821_1114'),
]
operations = [
migrations.CreateModel(
name='PasswordFieldHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.TextField()),
('iv', models.CharField(max_length=500)),
('salt', models.CharField(max_length=1000)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.DeleteModel(
name='Secret',
),
migrations.AddField(
model_name='recent',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='recent',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='vault',
name='history',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='vault',
name='iv',
field=models.CharField(default=1, max_length=500),
preserve_default=False,
),
migrations.AddField(
model_name='vault',
name='salt',
field=models.CharField(default=1, max_length=1000),
preserve_default=False,
),
migrations.RemoveField(
model_name='vault',
name='tag',
),
migrations.AddField(
model_name='vault',
name='tag',
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
),
migrations.DeleteModel(
name='Tag',
),
migrations.AddField(
model_name='passwordfieldhistory',
name='vault',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='password.Vault'),
),
]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
709,
14,
21,
641,
9708,
13,
614,
13,
1651,
6155,
26,
1479,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1947,
3187,
14,
16259,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1450,
3187,
297,
283,
9425,
63,
2495,
63,
1797,
13725,
975,
63,
18,
10753,
659,
267,
661,
2060,
297,
283,
21144,
63,
2495,
63,
9261,
2036,
2025,
63,
845,
1079,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
6139,
792,
12114,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
2060,
297,
1709,
14,
6254,
4000,
355,
661,
1003,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
5783,
1826,
355,
661,
12597,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
5279,
1826,
355,
661,
3966,
63,
292,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
1826,
355,
661,
5334,
63,
292,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
5392,
1685,
8,
288,
536,
534,
13790,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
14951,
297,
288,
536,
534,
3966,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
849,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
14951,
297,
288,
536,
534,
5334,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
2495,
63,
2131,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
5570,
297,
288,
901,
29,
992,
14,
5036,
8,
885,
29,
797,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1003,
297,
288,
901,
29,
992,
14,
2183,
8,
885,
29,
17,
12,
1390,
63,
1267,
29,
5783,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
12597,
297,
288,
901,
29,
992,
14,
2183,
8,
885,
29,
17,
12,
1390,
63,
1267,
29,
5279,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1450,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1450,
297,
288,
901,
29,
1450,
3187,
14,
16259,
14,
1931,
16725,
2988,
8,
3437,
63,
505,
534,
33,
10029,
13,
12794,
769,
402,
3762,
3130,
4012,
534,
1450,
3187,
14,
26403,
2081,
297,
370,
534,
1450,
3187,
14,
1931,
297,
3376,
63,
354,
534,
9440,
659,
267,
2318,
267,
6180,
14,
5392,
1685,
8,
288,
536,
534,
1931,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
2060,
698,
5570,
297,
288,
536,
534,
10077,
297,
288,
901,
29,
992,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
2060,
14,
20229,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
709,
14,
21,
641,
9708,
13,
614,
13,
1651,
6155,
26,
1479,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
1639,
14,
1208,
14,
7145,
199,
646,
1947,
3187,
14,
16259,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1450,
3187,
297,
283,
9425,
63,
2495,
63,
1797,
13725,
975,
63,
18,
10753,
659,
267,
661,
2060,
297,
283,
21144,
63,
2495,
63,
9261,
2036,
2025,
63,
845,
1079,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
6139,
792,
12114,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
2060,
297,
1709,
14,
6254,
4000,
355,
661,
1003,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
5783,
1826,
355,
661,
12597,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
5279,
1826,
355,
661,
3966,
63,
292,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
1826,
355,
661,
5334,
63,
292,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
5392,
1685,
8,
288,
536,
534,
13790,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
14951,
297,
288,
536,
534,
3966,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
849,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
14951,
297,
288,
536,
534,
5334,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
2495,
63,
2131,
29,
549,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
5570,
297,
288,
901,
29,
992,
14,
5036,
8,
885,
29,
797,
395,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1003,
297,
288,
901,
29,
992,
14,
2183,
8,
885,
29,
17,
12,
1390,
63,
1267,
29,
5783,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
12597,
297,
288,
901,
29,
992,
14,
2183,
8,
885,
29,
17,
12,
1390,
63,
1267,
29,
5279,
395,
288,
11211,
63,
885,
29,
797,
12,
267,
2318,
267,
6180,
14,
5587,
792,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1450,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
10077,
297,
288,
536,
534,
1450,
297,
288,
901,
29,
1450,
3187,
14,
16259,
14,
1931,
16725,
2988,
8,
3437,
63,
505,
534,
33,
10029,
13,
12794,
769,
402,
3762,
3130,
4012,
534,
1450,
3187,
14,
26403,
2081,
297,
370,
534,
1450,
3187,
14,
1931,
297,
3376,
63,
354,
534,
9440,
659,
267,
2318,
267,
6180,
14,
5392,
1685,
8,
288,
536,
534,
1931,
297,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
2060,
698,
5570,
297,
288,
536,
534,
10077,
297,
288,
901,
29,
992,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
2060,
14,
20229,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
OpenQbo/qbo_webi
|
src/teleoperation/sip2rtmp/rtmplite/rtmp.py
|
4
|
65395
|
# Copyright (c) 2007-2009, Mamta Singh. All rights reserved. see README for details.
# Copyright (c) 2010-2011, Kundan Singh.
'''
This is a simple implementation of a Flash RTMP server to accept connections and stream requests. The module is organized as follows:
1. The FlashServer class is the main class to provide the server abstraction. It uses the multitask module for co-operative multitasking.
It also uses the App abstract class to implement the applications.
2. The Server class implements a simple server to receive new Client connections and inform the FlashServer application. The Client class
derived from Protocol implements the RTMP client functions. The Protocol class implements the base RTMP protocol parsing. A Client contains
various streams from the client, represented using the Stream class.
3. The Message, Header and Command represent RTMP message, header and command respectively. The FLV class implements functions to perform read
and write of FLV file format.
Typically an application can launch this server as follows:
$ python rtmp.py
To know the command line options use the -h option:
$ python rtmp.py -h
To start the server with a different directory for recording and playing FLV files from, use the following command.
$ python rtmp.py -r some-other-directory/
Note the terminal '/' in the directory name. Without this, it is just used as a prefix in FLV file names.
A test client is available in testClient directory, and can be compiled using Flex Builder. Alternatively, you can use the SWF file to launch
from testClient/bin-debug after starting the server. Once you have launched the client in the browser, you can connect to
local host by clicking on 'connect' button. Then click on publish button to publish a stream. Open another browser with
same URL and first connect then play the same stream name. If everything works fine you should be able to see the video
from first browser to the second browser. Similar, in the first browser, if you check the record box before publishing,
it will create a new FLV file for the recorded stream. You can close the publishing stream and play the recorded stream to
see your recording. Note that due to initial delay in timestamp (in case publish was clicked much later than connect),
your played video will start appearing after some initial delay.
If an application wants to use this module as a library, it can launch the server as follows:
>>> agent = FlashServer() # a new RTMP server instance
>>> agent.root = 'flvs/' # set the document root to be 'flvs' directory. Default is current './' directory.
>>> agent.start() # start the server
>>> multitask.run() # this is needed somewhere in the application to actually start the co-operative multitasking.
If an application wants to specify a different application other than the default App, it can subclass it and supply the application by
setting the server's apps property. The following example shows how to define "myapp" which invokes a 'connected()' method on client when
the client connects to the server.
class MyApp(App): # a new MyApp extends the default App in rtmp module.
def __init__(self): # constructor just invokes base class constructor
App.__init__(self)
def onConnect(self, client, *args):
result = App.onConnect(self, client, *args) # invoke base class method first
def invokeAdded(self, client): # define a method to invoke 'connected("some-arg")' on Flash client
yield client.call('connected', 'some-arg')
multitask.add(invokeAdded(self, client)) # need to invoke later so that connection is established before callback
return result # return True to accept, or None to postpone calling accept()
...
agent.apps = dict({'myapp': MyApp, 'someapp': MyApp, '*': App})
Now the client can connect to rtmp://server/myapp or rtmp://server/someapp and will get connected to this MyApp application.
If the client doesn't define "function connected(arg:String):void" in the NetConnection.client object then the server will
throw an exception and display the error message.
'''
import os, sys, time, struct, socket, traceback, multitask, amf, hashlib, hmac, random
_debug = False
class ConnectionClosed:
'raised when the client closed the connection'
def truncate(data, max=100):
return data and len(data)>max and data[:max] + '...(%d)'%(len(data),) or data
class SockStream(object):
'''A class that represents a socket as a stream'''
def __init__(self, sock):
self.sock, self.buffer = sock, ''
self.bytesWritten = self.bytesRead = 0
def close(self):
self.sock.close()
def read(self, count):
try:
while True:
if len(self.buffer) >= count: # do have enough data in buffer
data, self.buffer = self.buffer[:count], self.buffer[count:]
raise StopIteration(data)
if _debug: print 'socket.read[%d] calling recv()'%(count,)
data = (yield multitask.recv(self.sock, 4096)) # read more from socket
if not data: raise ConnectionClosed
if _debug: print 'socket.read[%d] %r'%(len(data), truncate(data))
self.bytesRead += len(data)
self.buffer += data
except StopIteration: raise
except: raise ConnectionClosed # anything else is treated as connection closed.
def unread(self, data):
self.buffer = data + self.buffer
def write(self, data):
while len(data) > 0: # write in 4K chunks each time
chunk, data = data[:4096], data[4096:]
self.bytesWritten += len(chunk)
if _debug: print 'socket.write[%d] %r'%(len(chunk), truncate(chunk))
try: yield multitask.send(self.sock, chunk)
except: raise ConnectionClosed
class Header(object):
FULL, MESSAGE, TIME, SEPARATOR, MASK = 0x00, 0x40, 0x80, 0xC0, 0xC0
def __init__(self, channel=0, time=0, size=None, type=None, streamId=0):
self.channel, self.time, self.size, self.type, self.streamId = channel, time, size, type, streamId
if channel<64: self.hdrdata = chr(channel)
elif channel<(64+256): self.hdrdata = '\x00'+chr(channel-64)
else: self.hdrdata = '\x01'+chr((channel-64)%256)+chr((channel-64)/256)
def toBytes(self, control):
data = chr(ord(self.hdrdata[0]) | control) + self.hdrdata[1:]
if control != Header.SEPARATOR:
data += struct.pack('>I', self.time if self.time < 0xFFFFFF else 0xFFFFFF)[1:] # add time in 3 bytes
if control != Header.TIME:
data += struct.pack('>I', self.size & 0xFFFFFFFF)[1:] # size
data += chr(self.type) # type
if control != Header.MESSAGE:
data += struct.pack('<I', self.streamId & 0xFFFFFFFF) # add streamId
if self.time >= 0xFFFFFF:
data += struct.pack('>I', self.time & 0xFFFFFFFF)
return data
def __repr__(self):
return ("<Header channel=%r time=%r size=%r type=%s (%r) streamId=%r>"
% (self.channel, self.time, self.size, Message.type_name.get(self.type, 'unknown'), self.type, self.streamId))
def dup(self):
return Header(channel=self.channel, time=self.time, size=self.size, type=self.type, streamId=self.streamId)
class Message(object):
# message types: RPC3, DATA3,and SHAREDOBJECT3 are used with AMF3
CHUNK_SIZE, ABORT, ACK, USER_CONTROL, WIN_ACK_SIZE, SET_PEER_BW, AUDIO, VIDEO, DATA3, SHAREDOBJ3, RPC3, DATA, SHAREDOBJ, RPC = \
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14
type_name = dict(enumerate('unknown chunk-size abort ack user-control win-ack-size set-peer-bw unknown audio video unknown unknown unknown unknown unknown data3 sharedobj3 rpc3 data sharedobj rpc'.split()))
def __init__(self, hdr=None, data=''):
self.header, self.data = hdr or Header(), data
# define properties type, streamId and time to access self.header.(property)
for p in ['type', 'streamId', 'time']:
exec 'def _g%s(self): return self.header.%s'%(p, p)
exec 'def _s%s(self, %s): self.header.%s = %s'%(p, p, p, p)
exec '%s = property(fget=_g%s, fset=_s%s)'%(p, p, p)
@property
def size(self): return len(self.data)
def __repr__(self):
return ("<Message header=%r data=%r>"% (self.header, truncate(self.data)))
def dup(self):
return Message(self.header.dup(), self.data[:])
class Protocol(object):
PING_SIZE, DEFAULT_CHUNK_SIZE, PROTOCOL_CHANNEL_ID = 1536, 128, 2 # constants
READ_WIN_SIZE, WRITE_WIN_SIZE = 1000000L, 1073741824L
def __init__(self, sock):
self.stream = SockStream(sock)
self.lastReadHeaders, self.incompletePackets, self.lastWriteHeaders = dict(), dict(), dict()
self.readChunkSize = self.writeChunkSize = Protocol.DEFAULT_CHUNK_SIZE
self.readWinSize0, self.readWinSize, self.writeWinSize0, self.writeWinSize = 0L, self.READ_WIN_SIZE, 0L, self.WRITE_WIN_SIZE
self.nextChannelId = Protocol.PROTOCOL_CHANNEL_ID + 1
self._time0 = time.time()
self.writeQueue = multitask.Queue()
@property
def relativeTime(self):
return int(1000*(time.time() - self._time0))
def messageReceived(self, msg): # override in subclass
yield
def protocolMessage(self, msg):
if msg.type == Message.ACK: # respond to ACK requests
self.writeWinSize0 = struct.unpack('>L', msg.data)[0]
# response = Message()
# response.type, response.data = msg.type, msg.data
# yield self.writeMessage(response)
elif msg.type == Message.CHUNK_SIZE:
self.readChunkSize = struct.unpack('>L', msg.data)[0]
elif msg.type == Message.WIN_ACK_SIZE:
self.readWinSize, self.readWinSize0 = struct.unpack('>L', msg.data)[0], self.stream.bytesRead
elif msg.type == Message.USER_CONTROL:
type, data = struct.unpack('>H', msg.data[:2])[0], msg.data[2:]
if type == 3: # client expects a response when it sends set buffer length
streamId, bufferTime = struct.unpack('>II', data)
response = Message()
response.time, response.type, response.data = self.relativeTime, Message.USER_CONTROL, struct.pack('>HI', 0, streamId)
yield self.writeMessage(response)
yield
def connectionClosed(self):
yield
def parse(self):
try:
yield self.parseCrossDomainPolicyRequest() # check for cross domain policy
yield self.parseHandshake() # parse rtmp handshake
yield self.parseMessages() # parse messages
except ConnectionClosed:
yield self.connectionClosed()
if _debug: print 'parse connection closed'
except:
if _debug: print 'exception, closing connection'
if _debug: traceback.print_exc()
yield self.connectionClosed()
def writeMessage(self, message):
yield self.writeQueue.put(message)
def parseCrossDomainPolicyRequest(self):
# read the request
REQUEST = '<policy-file-request/>\x00'
data = (yield self.stream.read(len(REQUEST)))
if data == REQUEST:
if _debug: print data
data = '''<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1935" secure='false'/>
</cross-domain-policy>'''
yield self.stream.write(data)
raise ConnectionClosed
else:
yield self.stream.unread(data)
SERVER_KEY = '\x47\x65\x6e\x75\x69\x6e\x65\x20\x41\x64\x6f\x62\x65\x20\x46\x6c\x61\x73\x68\x20\x4d\x65\x64\x69\x61\x20\x53\x65\x72\x76\x65\x72\x20\x30\x30\x31\xf0\xee\xc2\x4a\x80\x68\xbe\xe8\x2e\x00\xd0\xd1\x02\x9e\x7e\x57\x6e\xec\x5d\x2d\x29\x80\x6f\xab\x93\xb8\xe6\x36\xcf\xeb\x31\xae'
FLASHPLAYER_KEY = '\x47\x65\x6E\x75\x69\x6E\x65\x20\x41\x64\x6F\x62\x65\x20\x46\x6C\x61\x73\x68\x20\x50\x6C\x61\x79\x65\x72\x20\x30\x30\x31\xF0\xEE\xC2\x4A\x80\x68\xBE\xE8\x2E\x00\xD0\xD1\x02\x9E\x7E\x57\x6E\xEC\x5D\x2D\x29\x80\x6F\xAB\x93\xB8\xE6\x36\xCF\xEB\x31\xAE'
def parseHandshake(self):
'''Parses the rtmp handshake'''
data = (yield self.stream.read(Protocol.PING_SIZE + 1)) # bound version and first ping
data = Protocol.handshakeResponse(data)
yield self.stream.write(data)
data = (yield self.stream.read(Protocol.PING_SIZE))
@staticmethod
def handshakeResponse(data):
# send both data parts before reading next ping-size, to work with ffmpeg
if struct.unpack('>I', data[5:9])[0] == 0:
data = '\x03' + '\x00'*Protocol.PING_SIZE
return data + data[1:]
else:
type, data = ord(data[0]), data[1:] # first byte is ignored
scheme = None
for s in range(0, 2):
digest_offset = (sum([ord(data[i]) for i in range(772, 776)]) % 728 + 776) if s == 1 else (sum([ord(data[i]) for i in range(8, 12)]) % 728 + 12)
temp = data[0:digest_offset] + data[digest_offset+32:Protocol.PING_SIZE]
hash = Protocol._calculateHash(temp, Protocol.FLASHPLAYER_KEY[:30])
if hash == data[digest_offset:digest_offset+32]:
scheme = s
break
if scheme is None:
if _debug: print 'invalid RTMP connection data, assuming scheme 0'
scheme = 0
client_dh_offset = (sum([ord(data[i]) for i in range(768, 772)]) % 632 + 8) if scheme == 1 else (sum([ord(data[i]) for i in range(1532, 1536)]) % 632 + 772)
outgoingKp = data[client_dh_offset:client_dh_offset+128]
handshake = struct.pack('>IBBBB', 0, 1, 2, 3, 4) + ''.join([chr(random.randint(0, 255)) for i in xrange(Protocol.PING_SIZE-8)])
server_dh_offset = (sum([ord(handshake[i]) for i in range(768, 772)]) % 632 + 8) if scheme == 1 else (sum([ord(handshake[i]) for i in range(1532, 1536)]) % 632 + 772)
keys = Protocol._generateKeyPair() # (public, private)
handshake = handshake[:server_dh_offset] + keys[0][0:128] + handshake[server_dh_offset+128:]
if type > 0x03: raise Exception('encryption is not supported')
server_digest_offset = (sum([ord(handshake[i]) for i in range(772, 776)]) % 728 + 776) if scheme == 1 else (sum([ord(handshake[i]) for i in range(8, 12)]) % 728 + 12)
temp = handshake[0:server_digest_offset] + handshake[server_digest_offset+32:Protocol.PING_SIZE]
hash = Protocol._calculateHash(temp, Protocol.SERVER_KEY[:36])
handshake = handshake[:server_digest_offset] + hash + handshake[server_digest_offset+32:]
buffer = data[:Protocol.PING_SIZE-32]
key_challenge_offset = (sum([ord(buffer[i]) for i in range(772, 776)]) % 728 + 776) if scheme == 1 else (sum([ord(buffer[i]) for i in range(8, 12)]) % 728 + 12)
challenge_key = data[key_challenge_offset:key_challenge_offset+32]
hash = Protocol._calculateHash(challenge_key, Protocol.SERVER_KEY[:68])
rand_bytes = ''.join([chr(random.randint(0, 255)) for i in xrange(Protocol.PING_SIZE-32)])
last_hash = Protocol._calculateHash(rand_bytes, hash[:32])
output = chr(type) + handshake + rand_bytes + last_hash
return output
@staticmethod
def _calculateHash(msg, key): # Hmac-sha256
return hmac.new(key, msg, hashlib.sha256).digest()
@staticmethod
def _generateKeyPair(): # dummy key pair since we don't support encryption
return (''.join([chr(random.randint(0, 255)) for i in xrange(128)]), '')
def parseMessages(self):
'''Parses complete messages until connection closed. Raises ConnectionLost exception.'''
CHANNEL_MASK = 0x3F
while True:
hdrsize = ord((yield self.stream.read(1))[0]) # read header size byte
channel = hdrsize & CHANNEL_MASK
if channel == 0: # we need one more byte
channel = 64 + ord((yield self.stream.read(1))[0])
elif channel == 1: # we need two more bytes
data = (yield self.stream.read(2))
channel = 64 + ord(data[0]) + 256 * ord(data[1])
hdrtype = hdrsize & Header.MASK # read header type byte
if hdrtype == Header.FULL or not self.lastReadHeaders.has_key(channel):
header = Header(channel)
self.lastReadHeaders[channel] = header
else:
header = self.lastReadHeaders[channel]
if hdrtype < Header.SEPARATOR: # time or delta has changed
data = (yield self.stream.read(3))
header.time = struct.unpack('!I', '\x00' + data)[0]
if hdrtype < Header.TIME: # size and type also changed
data = (yield self.stream.read(3))
header.size = struct.unpack('!I', '\x00' + data)[0]
header.type = ord((yield self.stream.read(1))[0])
if hdrtype < Header.MESSAGE: # streamId also changed
data = (yield self.stream.read(4))
header.streamId = struct.unpack('<I', data)[0]
if header.time == 0xFFFFFF: # if we have extended timestamp, read it
data = (yield self.stream.read(4))
header.extendedTime = struct.unpack('!I', data)[0]
if _debug: print 'extended time stamp', '%x'%(header.extendedTime,)
else:
header.extendedTime = None
if hdrtype == Header.FULL:
header.currentTime = header.extendedTime or header.time
header.hdrtype = hdrtype
elif hdrtype in (Header.MESSAGE, Header.TIME):
header.hdrtype = hdrtype
#print header.type, '0x%02x'%(hdrtype,), header.time, header.currentTime
# if _debug: print 'R', header, header.currentTime, header.extendedTime, '0x%x'%(hdrsize,)
data = self.incompletePackets.get(channel, "") # are we continuing an incomplete packet?
count = min(header.size - (len(data)), self.readChunkSize) # how much more
data += (yield self.stream.read(count))
# check if we need to send Ack
if self.readWinSize is not None:
if self.stream.bytesRead > (self.readWinSize0 + self.readWinSize):
self.readWinSize0 = self.stream.bytesRead
ack = Message()
ack.time, ack.type, ack.data = self.relativeTime, Message.ACK, struct.pack('>L', self.readWinSize0)
yield self.writeMessage(ack)
if len(data) < header.size: # we don't have all data
self.incompletePackets[channel] = data
else: # we have all data
if hdrtype in (Header.MESSAGE, Header.TIME):
header.currentTime = header.currentTime + (header.extendedTime or header.time)
elif hdrtype == Header.SEPARATOR:
if header.hdrtype in (Header.MESSAGE, Header.TIME):
header.currentTime = header.currentTime + (header.extendedTime or header.time)
if len(data) == header.size:
if channel in self.incompletePackets:
del self.incompletePackets[channel]
else:
data, self.incompletePackets[channel] = data[:header.size], data[header.size:]
hdr = Header(channel=header.channel, time=header.currentTime, size=header.size, type=header.type, streamId=header.streamId)
msg = Message(hdr, data)
if _debug: print 'Protocol.parseMessage msg=', msg
try:
if channel == Protocol.PROTOCOL_CHANNEL_ID:
yield self.protocolMessage(msg)
else:
yield self.messageReceived(msg)
except:
if _debug: print 'Protocol.parseMessages exception', (traceback and traceback.print_exc() or None)
def write(self):
'''Writes messages to stream'''
while True:
# while self.writeQueue.empty(): (yield multitask.sleep(0.01))
# message = self.writeQueue.get() # TODO this should be used using multitask.Queue and remove previous wait.
message = yield self.writeQueue.get() # TODO this should be used using multitask.Queue and remove previous wait.
if _debug: print 'Protocol.write msg=', message
if message is None:
try: self.stream.close() # just in case TCP socket is not closed, close it.
except: pass
break
# get the header stored for the stream
if self.lastWriteHeaders.has_key(message.streamId):
header = self.lastWriteHeaders[message.streamId]
else:
if self.nextChannelId <= Protocol.PROTOCOL_CHANNEL_ID: self.nextChannelId = Protocol.PROTOCOL_CHANNEL_ID+1
header, self.nextChannelId = Header(self.nextChannelId), self.nextChannelId + 1
self.lastWriteHeaders[message.streamId] = header
if message.type < Message.AUDIO:
header = Header(Protocol.PROTOCOL_CHANNEL_ID)
# now figure out the header data bytes
if header.streamId != message.streamId or header.time == 0 or message.time <= header.time:
header.streamId, header.type, header.size, header.time, header.delta = message.streamId, message.type, message.size, message.time, message.time
control = Header.FULL
elif header.size != message.size or header.type != message.type:
header.type, header.size, header.time, header.delta = message.type, message.size, message.time, message.time-header.time
control = Header.MESSAGE
else:
header.time, header.delta = message.time, message.time-header.time
control = Header.TIME
hdr = Header(channel=header.channel, time=header.delta if control in (Header.MESSAGE, Header.TIME) else header.time, size=header.size, type=header.type, streamId=header.streamId)
assert message.size == len(message.data)
data = ''
while len(message.data) > 0:
data += hdr.toBytes(control) # gather header bytes
count = min(self.writeChunkSize, len(message.data))
data += message.data[:count]
message.data = message.data[count:]
control = Header.SEPARATOR # incomplete message continuation
try:
yield self.stream.write(data)
except ConnectionClosed:
yield self.connectionClosed()
except:
print traceback.print_exc()
class Command(object):
''' Class for command / data messages'''
def __init__(self, type=Message.RPC, name=None, id=None, tm=0, cmdData=None, args=[]):
'''Create a new command with given type, name, id, cmdData and args list.'''
self.type, self.name, self.id, self.time, self.cmdData, self.args = type, name, id, tm, cmdData, args[:]
def __repr__(self):
return ("<Command type=%r name=%r id=%r data=%r args=%r>" % (self.type, self.name, self.id, self.cmdData, self.args))
def setArg(self, arg):
self.args.append(arg)
def getArg(self, index):
return self.args[index]
@classmethod
def fromMessage(cls, message):
''' initialize from a parsed RTMP message'''
assert (message.type in [Message.RPC, Message.RPC3, Message.DATA, Message.DATA3])
length = len(message.data)
if length == 0: raise ValueError('zero length message data')
if message.type == Message.RPC3 or message.type == Message.DATA3:
assert message.data[0] == '\x00' # must be 0 in AMF3
data = message.data[1:]
else:
data = message.data
amfReader = amf.AMF0(data)
inst = cls()
inst.type = message.type
inst.time = message.time
inst.name = amfReader.read() # first field is command name
try:
if message.type == Message.RPC or message.type == Message.RPC3:
inst.id = amfReader.read() # second field *may* be message id
inst.cmdData = amfReader.read() # third is command data
else:
inst.id = 0
inst.args = [] # others are optional
while True:
inst.args.append(amfReader.read())
except EOFError:
pass
return inst
def toMessage(self):
msg = Message()
assert self.type
msg.type = self.type
msg.time = self.time
output = amf.BytesIO()
amfWriter = amf.AMF0(output)
amfWriter.write(self.name)
if msg.type == Message.RPC or msg.type == Message.RPC3:
amfWriter.write(self.id)
amfWriter.write(self.cmdData)
for arg in self.args:
amfWriter.write(arg)
output.seek(0)
#hexdump.hexdump(output)
#output.seek(0)
if msg.type == Message.RPC3 or msg.type == Message.DATA3:
data = '\x00' + output.read()
else:
data = output.read()
msg.data = data
output.close()
return msg
def getfilename(path, name, root):
'''return the file name for the given stream. The name is derived as root/scope/name.flv where scope is
the the path present in the path variable.'''
ignore, ignore, scope = path.partition('/')
if scope: scope = scope + '/'
result = root + scope + name + '.flv'
if _debug: print 'filename=', result
return result
class FLV(object):
'''An FLV file which converts between RTMP message and FLV tags.'''
def __init__(self):
self.fname = self.fp = self.type = None
self.tsp = self.tsr = 0; self.tsr0 = None
def open(self, path, type='read', mode=0775):
'''Open the file for reading (type=read) or writing (type=record or append).'''
if str(path).find('/../') >= 0 or str(path).find('\\..\\') >= 0: raise ValueError('Must not contain .. in name')
if _debug: print 'opening file', path
self.tsp = self.tsr = 0; self.tsr0 = None; self.type = type
if type in ('record', 'append'):
try: os.makedirs(os.path.dirname(path), mode)
except: pass
self.fp = open(path, ('w' if type == 'record' else 'a')+'b')
if type == 'record':
self.fp.write('FLV\x01\x05\x00\x00\x00\x09\x00\x00\x00\x00') # the header and first previousTagSize
self.writeDuration(0.0)
else:
self.fp = open(path, 'rb')
magic, version, flags, offset = struct.unpack('!3sBBI', self.fp.read(9))
if _debug: print 'FLV.open() hdr=', magic, version, flags, offset
if magic != 'FLV': raise ValueError('This is not a FLV file')
if version != 1: raise ValueError('Unsupported FLV file version')
if offset > 9: self.fp.seek(offset-9, os.SEEK_CUR)
self.fp.read(4) # ignore first previous tag size
return self
def close(self):
'''Close the underlying file for this object.'''
if _debug: print 'closing flv file'
if self.type == 'record' and self.tsr0 is not None: self.writeDuration((self.tsr - self.tsr0)/1000.0)
if self.fp is not None:
try: self.fp.close()
except: pass
self.fp = None
def delete(self, path):
'''Delete the underlying file for this object.'''
try: os.unlink(path)
except: pass
def writeDuration(self, duration):
if _debug: print 'writing duration', duration
output = amf.BytesIO()
amfWriter = amf.AMF0(output) # TODO: use AMF3 if needed
amfWriter.write('onMetaData')
amfWriter.write({"duration": duration, "videocodecid": 2})
output.seek(0); data = output.read()
length, ts = len(data), 0
data = struct.pack('>BBHBHB', Message.DATA, (length >> 16) & 0xff, length & 0x0ffff, (ts >> 16) & 0xff, ts & 0x0ffff, (ts >> 24) & 0xff) + '\x00\x00\x00' + data
data += struct.pack('>I', len(data))
lastpos = self.fp.tell()
if lastpos != 13: self.fp.seek(13, os.SEEK_SET)
self.fp.write(data)
if lastpos != 13: self.fp.seek(lastpos, os.SEEK_SET)
def write(self, message):
'''Write a message to the file, assuming it was opened for writing or appending.'''
# if message.type == Message.VIDEO:
# self.videostarted = True
# elif not hasattr(self, "videostarted"): return
if message.type == Message.AUDIO or message.type == Message.VIDEO:
length, ts = message.size, message.time
if _debug: print 'FLV.write()', message.type, ts
if self.tsr0 is None: self.tsr0 = ts
self.tsr, ts = ts, ts - self.tsr0
# if message.type == Message.AUDIO: print 'w', message.type, ts
data = struct.pack('>BBHBHB', message.type, (length >> 16) & 0xff, length & 0x0ffff, (ts >> 16) & 0xff, ts & 0x0ffff, (ts >> 24) & 0xff) + '\x00\x00\x00' + message.data
data += struct.pack('>I', len(data))
self.fp.write(data)
def reader(self, stream):
'''A generator to periodically read the file and dispatch them to the stream. The supplied stream
object must have a send(Message) method and id and client properties.'''
if _debug: print 'reader started'
yield
try:
while self.fp is not None:
bytes = self.fp.read(11)
if len(bytes) == 0:
response = Command(name='onStatus', id=stream.id, tm=stream.client.relativeTime, args=[amf.Object(level='status',code='NetStream.Play.Stop', description='File ended', details=None)])
yield stream.send(response.toMessage())
break
type, len0, len1, ts0, ts1, ts2, sid0, sid1 = struct.unpack('>BBHBHBBH', bytes)
length = (len0 << 16) | len1; ts = (ts0 << 16) | (ts1 & 0x0ffff) | (ts2 << 24)
body = self.fp.read(length); ptagsize, = struct.unpack('>I', self.fp.read(4))
if ptagsize != (length+11):
if _debug: print 'invalid previous tag-size found:', ptagsize, '!=', (length+11),'ignored.'
if stream is None or stream.client is None: break # if it is closed
#hdr = Header(3 if type == Message.AUDIO else 4, ts if ts < 0xffffff else 0xffffff, length, type, stream.id)
hdr = Header(0, ts, length, type, stream.id)
msg = Message(hdr, body)
# if _debug: print 'FLV.read() length=', length, 'hdr=', hdr
# if hdr.type == Message.AUDIO: print 'r', hdr.type, hdr.time
if type == Message.DATA: # metadata
amfReader = amf.AMF0(body) # TODO: use AMF3 if needed
name = amfReader.read()
obj = amfReader.read()
if _debug: print 'FLV.read()', name, repr(obj)
yield stream.send(msg)
if ts > self.tsp:
diff, self.tsp = ts - self.tsp, ts
if _debug: print 'FLV.read() sleep', diff
yield multitask.sleep(diff / 1000.0)
except StopIteration: pass
except:
if _debug: print 'closing the reader', (sys and sys.exc_info() or None)
if self.fp is not None:
try: self.fp.close()
except: pass
self.fp = None
def seek(self, offset):
'''For file reader, try seek to the given time. The offset is in millisec'''
if self.type == 'read':
if _debug: print 'FLV.seek() offset=', offset, 'current tsp=', self.tsp
self.fp.seek(0, os.SEEK_SET)
magic, version, flags, length = struct.unpack('!3sBBI', self.fp.read(9))
if length > 9: self.fp.seek(length-9, os.SEEK_CUR)
self.fp.seek(4, os.SEEK_CUR) # ignore first previous tag size
self.tsp, ts = int(offset), 0
while self.tsp > 0 and ts < self.tsp:
bytes = self.fp.read(11)
if not bytes: break
type, len0, len1, ts0, ts1, ts2, sid0, sid1 = struct.unpack('>BBHBHBBH', bytes)
length = (len0 << 16) | len1; ts = (ts0 << 16) | (ts1 & 0x0ffff) | (ts2 << 24)
self.fp.seek(length, os.SEEK_CUR)
ptagsize, = struct.unpack('>I', self.fp.read(4))
if ptagsize != (length+11): break
if _debug: print 'FLV.seek() new ts=', ts, 'tell', self.fp.tell()
class Stream(object):
'''The stream object that is used for RTMP stream.'''
count = 0;
def __init__(self, client):
self.client, self.id, self.name = client, 0, ''
self.recordfile = self.playfile = None # so that it doesn't complain about missing attribute
self.queue = multitask.Queue()
self._name = 'Stream[' + str(Stream.count) + ']'; Stream.count += 1
if _debug: print self, 'created'
def close(self):
if _debug: print self, 'closing'
if self.recordfile is not None: self.recordfile.close(); self.recordfile = None
if self.playfile is not None: self.playfile.close(); self.playfile = None
self.client = None # to clear the reference
pass
def __repr__(self):
return self._name;
def recv(self):
'''Generator to receive new Message on this stream, or None if stream is closed.'''
return self.queue.get()
def send(self, msg):
'''Method to send a Message or Command on this stream.'''
if isinstance(msg, Command):
msg = msg.toMessage()
msg.streamId = self.id
# if _debug: print self,'send'
if self.client is not None: yield self.client.writeMessage(msg)
class Client(Protocol):
'''The client object represents a single connected client to the server.'''
def __init__(self, sock, server):
Protocol.__init__(self, sock)
self.server, self.agent, self.streams, self._nextCallId, self._nextStreamId, self.objectEncoding = \
server, None, {}, 2, 1, 0.0
self.queue = multitask.Queue() # receive queue used by application
multitask.add(self.parse()); multitask.add(self.write())
def recv(self):
'''Generator to receive new Message (msg, arg) on this stream, or (None,None) if stream is closed.'''
return self.queue.get()
def connectionClosed(self):
'''Called when the client drops the connection'''
if _debug: 'Client.connectionClosed'
yield self.writeMessage(None)
yield self.queue.put((None,None))
def messageReceived(self, msg):
if (msg.type == Message.RPC or msg.type == Message.RPC3) and msg.streamId == 0:
cmd = Command.fromMessage(msg)
# if _debug: print 'rtmp.Client.messageReceived cmd=', cmd
if cmd.name == 'connect':
self.agent = cmd.cmdData
if _debug: print 'connect', ', '.join(['%s=%r'%(x, getattr(self.agent, x)) for x in 'app flashVer swfUrl tcUrl fpad capabilities audioCodecs videoCodecs videoFunction pageUrl objectEncoding'.split() if hasattr(self.agent, x)])
self.objectEncoding = self.agent.objectEncoding if hasattr(self.agent, 'objectEncoding') else 0.0
yield self.server.queue.put((self, cmd.args)) # new connection
elif cmd.name == 'createStream':
response = Command(name='_result', id=cmd.id, tm=self.relativeTime, type=self.rpc, args=[self._nextStreamId])
yield self.writeMessage(response.toMessage())
stream = Stream(self) # create a stream object
stream.id = self._nextStreamId
self.streams[self._nextStreamId] = stream
self._nextStreamId += 1
yield self.queue.put(('stream', stream)) # also notify others of our new stream
elif cmd.name == 'closeStream':
assert msg.streamId in self.streams
yield self.streams[msg.streamId].queue.put(None) # notify closing to others
del self.streams[msg.streamId]
else:
# if _debug: print 'Client.messageReceived cmd=', cmd
yield self.queue.put(('command', cmd)) # RPC call
else: # this has to be a message on the stream
assert msg.streamId != 0
assert msg.streamId in self.streams
# if _debug: print self.streams[msg.streamId], 'recv'
stream = self.streams[msg.streamId]
if not stream.client: stream.client = self
yield stream.queue.put(msg) # give it to stream
@property
def rpc(self):
return Message.RPC if self.objectEncoding == 0.0 else Message.RPC3
def accept(self):
'''Method to accept an incoming client.'''
response = Command()
response.id, response.name, response.type = 1, '_result', self.rpc
if _debug: print 'Client.accept() objectEncoding=', self.objectEncoding
response.setArg(amf.Object(level='status', code='NetConnection.Connect.Success',
description='Connection succeeded.', fmsVer='rtmplite/7,0', details=None,
objectEncoding=self.objectEncoding))
yield self.writeMessage(response.toMessage())
def rejectConnection(self, reason=''):
'''Method to reject an incoming client.'''
response = Command()
response.id, response.name, response.type = 1, '_error', self.rpc
response.setArg(amf.Object(level='status', code='NetConnection.Connect.Rejected',
description=reason, fmsVer='rtmplite/7,0', details=None))
yield self.writeMessage(response.toMessage())
def redirectConnection(self, url, reason='Connection failed'):
'''Method to redirect an incoming client to the given url.'''
response = Command()
response.id, response.name, response.type = 1, '_error', self.rpc
extra = dict(code=302, redirect=url)
response.setArg(amf.Object(level='status', code='NetConnection.Connect.Rejected',
description=reason, fmsVer='rtmplite/7,0', details=None, ex=extra))
yield self.writeMessage(response.toMessage())
def call(self, method, *args):
'''Call a (callback) method on the client.'''
cmd = Command()
cmd.id, cmd.time, cmd.name, cmd.type = self._nextCallId, self.relativeTime, method, self.rpc
cmd.args, cmd.cmdData = args, None
self._nextCallId += 1
if _debug: print 'Client.call method=', method, 'args=', args, ' msg=', cmd.toMessage()
yield self.writeMessage(cmd.toMessage())
def createStream(self):
''' Create a stream on the server side'''
stream = Stream(self)
stream.id = self._nextStreamId
self.streams[stream.id] = stream
self._nextStreamId += 1
return stream
class Server(object):
'''A RTMP server listens for incoming connections and informs the app.'''
def __init__(self, sock):
'''Create an RTMP server on the given bound TCP socket. The server will terminate
when the socket is disconnected, or some other error occurs in listening.'''
self.sock = sock
self.queue = multitask.Queue() # queue to receive incoming client connections
multitask.add(self.run())
def recv(self):
'''Generator to wait for incoming client connections on this server and return
(client, args) or (None, None) if the socket is closed or some error.'''
return self.queue.get()
def run(self):
try:
while True:
sock, remote = (yield multitask.accept(self.sock)) # receive client TCP
if sock == None:
if _debug: print 'rtmp.Server accept(sock) returned None.'
break
if _debug: print 'connection received from', remote
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # make it non-block
client = Client(sock, self)
except GeneratorExit: pass # terminate
except:
if _debug: print 'rtmp.Server exception ', (sys and sys.exc_info() or None)
if (self.sock):
try: self.sock.close(); self.sock = None
except: pass
if (self.queue):
yield self.queue.put((None, None))
self.queue = None
class App(object):
'''An application instance containing any number of streams. Except for constructor all methods are generators.'''
count = 0
def __init__(self):
self.name = str(self.__class__.__name__) + '[' + str(App.count) + ']'; App.count += 1
self.players, self.publishers, self._clients = {}, {}, [] # Streams indexed by stream name, and list of clients
if _debug: print self.name, 'created'
def __del__(self):
if _debug: print self.name, 'destroyed'
@property
def clients(self):
'''everytime this property is accessed it returns a new list of clients connected to this instance.'''
return self._clients[1:] if self._clients is not None else []
def onConnect(self, client, *args):
if _debug: print self.name, 'onConnect', client.path
return True
def onDisconnect(self, client):
if _debug: print self.name, 'onDisconnect', client.path
def onPublish(self, client, stream):
if _debug: print self.name, 'onPublish', client.path, stream.name
def onClose(self, client, stream):
if _debug: print self.name, 'onClose', client.path, stream.name
def onPlay(self, client, stream):
if _debug: print self.name, 'onPlay', client.path, stream.name
def onStop(self, client, stream):
if _debug: print self.name, 'onStop', client.path, stream.name
def onCommand(self, client, cmd, *args):
if _debug: print self.name, 'onCommand', cmd, args
def onStatus(self, client, info):
if _debug: print self.name, 'onStatus', info
def onResult(self, client, result):
if _debug: print self.name, 'onResult', result
def onPublishData(self, client, stream, message): # this is invoked every time some media packet is received from published stream.
return True # should return True so that the data is actually published in that stream
def onPlayData(self, client, stream, message):
return True # should return True so that data will be actually played in that stream
class Wirecast(App):
'''A wrapper around App to workaround with wirecast publisher which does not send AVC seq periodically. It defines new stream variables
such as in publish stream 'metaData' to store first published metadata Message, and 'avcSeq' to store the last published AVC seq Message,
and in play stream 'avcIntra' to indicate if AVC intra frame has been sent or not. These variables are created onPublish and onPlay.
Additional, when onPlay it also also sends any published stream.metaData if found in associated publisher. When onPlayData for video, if
it detects AVC seq it sets avcIntra so that it is not explicitly sent. This is the case with Flash Player publisher. When onPlayData for video,
if it detects avcIntra is not set, it discards the packet until AVC NALU or seq is received. If NALU is received but previous seq is not received
it uses the publisher's avcSeq message to send before this NALU if found.'''
def __init__(self):
App.__init__(self)
def onPublish(self, client, stream):
App.onPublish(self, client, stream)
if not hasattr(stream, 'metaData'): stream.metaData = None
if not hasattr(stream, 'avcSeq'): stream.avcSeq = None
def onPlay(self, client, stream):
App.onPlay(self, client, stream)
if not hasattr(stream, 'avcIntra'): stream.avcIntra = False
publisher = self.publishers.get(stream.name, None)
if publisher and publisher.metaData: # send published meta data to this player joining late
multitask.add(stream.send(publisher.metaData.dup()))
def onPublishData(self, client, stream, message):
if message.type == Message.DATA and not stream.metaData: # store the first meta data on this published stream for late joining players
stream.metaData = message.dup()
if message.type == Message.VIDEO and message.data[:2] == '\x17\x00': # H264Avc intra + seq, store it
stream.avcSeq = message.dup()
return True
def onPlayData(self, client, stream, message):
if message.type == Message.VIDEO: # only video packets need special handling
if message.data[:2] == '\x17\x00': # intra+seq is being sent, possibly by Flash Player publisher.
stream.avcIntra = True
elif not stream.avcIntra: # intra frame hasn't been sent yet.
if message.data[:2] == '\x17\x01': # intra+nalu is being sent, possibly by wirecast publisher.
publisher = self.publishers.get(stream.name, None)
if publisher and publisher.avcSeq: # if a publisher exists
def sendboth(stream, msgs):
stream.avcIntra = True
for msg in msgs: yield stream.send(msg)
multitask.add(sendboth(stream, [publisher.avcSeq.dup(), message]))
return False # so that caller doesn't send it again
return False # drop until next intra video is sent
return True
class FlashServer(object):
'''A RTMP server to record and stream Flash video.'''
def __init__(self):
'''Construct a new FlashServer. It initializes the local members.'''
self.sock = self.server = None;
self.apps = dict({'*': App, 'wirecast': Wirecast}) # supported applications: * means any as in {'*': App}
self.clients = dict() # list of clients indexed by scope. First item in list is app instance.
self.root = '';
def start(self, host='0.0.0.0', port=1935):
'''This should be used to start listening for RTMP connections on the given port, which defaults to 1935.'''
if not self.server:
sock = self.sock = socket.socket(type=socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
if _debug: print 'listening on ', sock.getsockname()
sock.listen(5)
server = self.server = Server(sock) # start rtmp server on that socket
multitask.add(self.serverlistener())
def stop(self):
if _debug: print 'stopping Flash server'
if self.server and self.sock:
try: self.sock.close(); self.sock = None
except: pass
self.server = None
def serverlistener(self):
'''Server listener (generator). It accepts all connections and invokes client listener'''
try:
while True: # main loop to receive new connections on the server
client, args = (yield self.server.recv()) # receive an incoming client connection.
# TODO: we should reject non-localhost client connections.
if not client: # if the server aborted abnormally,
break # hence close the listener.
if _debug: print 'client connection received', client, args
if client.objectEncoding != 0 and client.objectEncoding != 3:
#if client.objectEncoding != 0:
yield client.rejectConnection(reason='Unsupported encoding ' + str(client.objectEncoding) + '. Please use NetConnection.defaultObjectEncoding=ObjectEncoding.AMF0')
yield client.connectionClosed()
else:
client.path = str(client.agent.app) if hasattr(client.agent, 'app') else str(client.agent['app']) if isinstance(client.agent, dict) else None
if not client.path:
yield client.rejectConnection(reason='Missing app path')
break
name, ignore, scope = client.path.partition('/')
if '*' not in self.apps and name not in self.apps:
yield client.rejectConnection(reason='Application not found: ' + name)
else: # create application instance as needed and add in our list
if _debug: print 'name=', name, 'name in apps', str(name in self.apps)
app = self.apps[name] if name in self.apps else self.apps['*'] # application class
if client.path in self.clients: inst = self.clients[client.path][0]
else: inst = app()
win_ack = Message()
win_ack.time, win_ack.type, win_ack.data = client.relativeTime, Message.WIN_ACK_SIZE, struct.pack('>L', client.writeWinSize)
yield client.writeMessage(win_ack)
# set_peer_bw = Message()
# set_peer_bw.time, set_peer_bw.type, set_peer_bw.data = client.relativeTime, Message.SET_PEER_BW, struct.pack('>LB', client.writeWinSize, 1)
# client.writeMessage(set_peer_bw)
try:
result = inst.onConnect(client, *args)
except:
if _debug: print sys.exc_info()
yield client.rejectConnection(reason='Exception on onConnect');
continue
if result is True or result is None:
if client.path not in self.clients:
self.clients[client.path] = [inst]; inst._clients=self.clients[client.path]
self.clients[client.path].append(client)
if result is True:
yield client.accept() # TODO: else how to kill this task when rejectConnection() later
multitask.add(self.clientlistener(client)) # receive messages from client.
else:
yield client.rejectConnection(reason='Rejected in onConnect')
except GeneratorExit: pass # terminate
except StopIteration: raise
except:
if _debug: print 'serverlistener exception', traceback.print_exc()
def clientlistener(self, client):
'''Client listener (generator). It receives a command and invokes client handler, or receives a new stream and invokes streamlistener.'''
try:
while True:
msg, arg = (yield client.recv()) # receive new message from client
if not msg: # if the client disconnected,
if _debug: print 'connection closed from client'
break # come out of listening loop.
if msg == 'command': # handle a new command
multitask.add(self.clienthandler(client, arg))
elif msg == 'stream': # a new stream is created, handle the stream.
arg.client = client
multitask.add(self.streamlistener(arg))
except StopIteration: raise
except:
if _debug: print 'clientlistener exception', (sys and sys.exc_info() or None)
try:
# client is disconnected, clear our state for application instance.
if _debug: print 'cleaning up client', client.path
inst = None
if client.path in self.clients:
inst = self.clients[client.path][0]
self.clients[client.path].remove(client)
for stream in client.streams.values(): # for all streams of this client
self.closehandler(stream)
client.streams.clear() # and clear the collection of streams
if client.path in self.clients and len(self.clients[client.path]) == 1: # no more clients left, delete the instance.
if _debug: print 'removing the application instance'
inst = self.clients[client.path][0]
inst._clients = None
del self.clients[client.path]
if inst is not None: inst.onDisconnect(client)
except:
if _debug: print 'clientlistener exception', (sys and sys.exc_info() or None)
def closehandler(self, stream):
'''A stream is closed explicitly when a closeStream command is received from given client.'''
if stream.client is not None:
inst = self.clients[stream.client.path][0]
if stream.name in inst.publishers and inst.publishers[stream.name] == stream: # clear the published stream
inst.onClose(stream.client, stream)
del inst.publishers[stream.name]
if stream.name in inst.players and stream in inst.players[stream.name]:
inst.onStop(stream.client, stream)
inst.players[stream.name].remove(stream)
if len(inst.players[stream.name]) == 0:
del inst.players[stream.name]
stream.close()
def clienthandler(self, client, cmd):
'''A generator to handle a single command on the client.'''
inst = self.clients[client.path][0]
if inst:
if cmd.name == '_error':
if hasattr(inst, 'onStatus'):
result = inst.onStatus(client, cmd.args[0])
elif cmd.name == '_result':
if hasattr(inst, 'onResult'):
result = inst.onResult(client, cmd.args[0])
else:
res, code, args = Command(), '_result', dict()
try: result = inst.onCommand(client, cmd.name, *cmd.args)
except:
if _debug: print 'Client.call exception', (sys and sys.exc_info() or None)
code, args = '_error', dict()
res.id, res.time, res.name, res.type = cmd.id, client.relativeTime, code, client.rpc
res.args, res.cmdData = args, None
if _debug: print 'Client.call method=', code, 'args=', args, ' msg=', res.toMessage()
yield client.writeMessage(res.toMessage())
# TODO return result to caller
yield
def streamlistener(self, stream):
'''Stream listener (generator). It receives stream message and invokes streamhandler.'''
try:
stream.recordfile = None # so that it doesn't complain about missing attribute
while True:
msg = (yield stream.recv())
if not msg:
if _debug: print 'stream closed'
self.closehandler(stream)
break
# if _debug: msg
multitask.add(self.streamhandler(stream, msg))
except:
if _debug: print 'streamlistener exception', (sys and sys.exc_info() or None)
def streamhandler(self, stream, message):
'''A generator to handle a single message on the stream.'''
try:
if message.type == Message.RPC or message.type == Message.RPC3:
cmd = Command.fromMessage(message)
if _debug: print 'streamhandler received cmd=', cmd
if cmd.name == 'publish':
yield self.publishhandler(stream, cmd)
elif cmd.name == 'play':
yield self.playhandler(stream, cmd)
elif cmd.name == 'closeStream':
self.closehandler(stream)
elif cmd.name == 'seek':
yield self.seekhandler(stream, cmd)
else: # audio or video message
yield self.mediahandler(stream, message)
except GeneratorExit: pass
except StopIteration: raise
except:
if _debug: print 'exception in streamhandler', (sys and sys.exc_info())
def publishhandler(self, stream, cmd):
'''A new stream is published. Store the information in the application instance.'''
try:
stream.mode = 'live' if len(cmd.args) < 2 else cmd.args[1] # live, record, append
stream.name = cmd.args[0]
if _debug: print 'publishing stream=', stream.name, 'mode=', stream.mode
inst = self.clients[stream.client.path][0]
if (stream.name in inst.publishers):
raise ValueError, 'Stream name already in use'
inst.publishers[stream.name] = stream # store the client for publisher
inst.onPublish(stream.client, stream)
path = getfilename(stream.client.path, stream.name, self.root)
if stream.mode in ('record', 'append'):
stream.recordfile = FLV().open(path, stream.mode)
# elif stream.mode == 'live': FLV().delete(path) # TODO: this is commented out to avoid accidental delete
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='status', code='NetStream.Publish.Start', description='', details=None)])
yield stream.send(response)
except ValueError, E: # some error occurred. inform the app.
if _debug: print 'error in publishing stream', str(E)
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='error',code='NetStream.Publish.BadName',description=str(E),details=None)])
yield stream.send(response)
def playhandler(self, stream, cmd):
'''A new stream is being played. Just updated the players list with this stream.'''
try:
inst = self.clients[stream.client.path][0]
name = stream.name = cmd.args[0] # store the stream's name
start = cmd.args[1] if len(cmd.args) >= 2 else -2
if name not in inst.players:
inst.players[name] = [] # initialize the players for this stream name
if stream not in inst.players[name]: # store the stream as players of this name
inst.players[name].append(stream)
task = None
if start >= 0 or start == -2 and name not in inst.publishers:
path = getfilename(stream.client.path, stream.name, self.root)
if os.path.exists(path):
stream.playfile = FLV().open(path)
if start > 0: stream.playfile.seek(start)
task = stream.playfile.reader(stream)
elif start >= 0: raise ValueError, 'Stream name not found'
if _debug: print 'playing stream=', name, 'start=', start
inst.onPlay(stream.client, stream)
# m0 = Message() # SetChunkSize
# m0.time, m0.type, m0.data = stream.client.relativeTime, Message.CHUNK_SIZE, struct.pack('>L', stream.client.writeChunkSize)
# yield stream.client.writeMessage(m0)
# m1 = Message() # UserControl/StreamIsRecorded
# m1.time, m1.type, m1.data = stream.client.relativeTime, Message.USER_CONTROL, struct.pack('>HI', 4, stream.id)
# yield stream.client.writeMessage(m1)
m2 = Message() # UserControl/StreamBegin
m2.time, m2.type, m2.data = stream.client.relativeTime, Message.USER_CONTROL, struct.pack('>HI', 0, stream.id)
yield stream.client.writeMessage(m2)
# response = Command(name='onStatus', id=cmd.id, args=[amf.Object(level='status',code='NetStream.Play.Reset', description=stream.name, details=None)])
# yield stream.send(response)
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='status',code='NetStream.Play.Start', description=stream.name, details=None)])
yield stream.send(response)
# response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='status',code='NetStream.Play.PublishNotify', description=stream.name, details=None)])
# yield stream.send(response)
if task is not None: multitask.add(task)
except ValueError, E: # some error occurred. inform the app.
if _debug: print 'error in playing stream', str(E)
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='error',code='NetStream.Play.StreamNotFound',description=str(E),details=None)])
yield stream.send(response)
def seekhandler(self, stream, cmd):
'''A stream is seeked to a new position. This is allowed only for play from a file.'''
try:
offset = cmd.args[0]
if stream.playfile is None or stream.playfile.type != 'read':
raise ValueError, 'Stream is not seekable'
stream.playfile.seek(offset)
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='status',code='NetStream.Seek.Notify', description=stream.name, details=None)])
yield stream.send(response)
except ValueError, E: # some error occurred. inform the app.
if _debug: print 'error in seeking stream', str(E)
response = Command(name='onStatus', id=cmd.id, tm=stream.client.relativeTime, args=[amf.Object(level='error',code='NetStream.Seek.Failed',description=str(E),details=None)])
yield stream.send(response)
def mediahandler(self, stream, message):
'''Handle incoming media on the stream, by sending to other stream in this application instance.'''
if stream.client is not None:
inst = self.clients[stream.client.path][0]
result = inst.onPublishData(stream.client, stream, message)
if result:
for s in (inst.players.get(stream.name, [])):
#if _debug: print 'D', stream.name, s.name
m = message.dup()
result = inst.onPlayData(s.client, s, m)
if result:
yield s.send(m)
if stream.recordfile is not None:
stream.recordfile.write(message)
# The main routine to start, run and stop the service
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-i', '--host', dest='host', default='0.0.0.0', help="listening IP address. Default '0.0.0.0'")
parser.add_option('-p', '--port', dest='port', default=1935, type="int", help='listening port number. Default 1935')
parser.add_option('-r', '--root', dest='root', default='./', help="document path prefix. Directory must end with /. Default './'")
parser.add_option('-d', '--verbose', dest='verbose', default=False, action='store_true', help='enable debug trace')
(options, args) = parser.parse_args()
_debug = options.verbose
try:
agent = FlashServer()
agent.root = options.root
agent.start(options.host, options.port)
if _debug: print time.asctime(), 'Flash Server Starts - %s:%d' % (options.host, options.port)
multitask.run()
except KeyboardInterrupt:
pass
if _debug: print time.asctime(), 'Flash Server Stops'
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
10219,
13,
8664,
12,
603,
455,
502,
428,
316,
72,
14,
2900,
4481,
4644,
14,
1937,
27781,
367,
2436,
14,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
1804,
725,
290,
428,
316,
72,
14,
199,
199,
2344,
199,
2765,
365,
282,
3486,
4514,
402,
282,
11040,
1119,
820,
17983,
1654,
370,
4729,
6947,
436,
2547,
4145,
14,
710,
859,
365,
20765,
1759,
465,
11924,
26,
199,
17,
14,
710,
11040,
1119,
3120,
1021,
365,
314,
2446,
1021,
370,
5647,
314,
1654,
2236,
29639,
14,
2779,
4440,
314,
3510,
1765,
859,
367,
512,
13,
2262,
1905,
3510,
1765,
316,
14,
2043,
2779,
2597,
4440,
314,
4693,
9006,
1021,
370,
5669,
314,
13103,
14,
199,
18,
14,
710,
7146,
1021,
9031,
282,
3486,
1654,
370,
9128,
892,
6810,
6947,
436,
315,
964,
314,
11040,
1119,
3120,
4223,
14,
710,
6810,
1021,
2043,
7131,
687,
11557,
9031,
314,
820,
17983,
1890,
3423,
14,
710,
11557,
1021,
9031,
314,
1300,
820,
17983,
4113,
6057,
14,
437,
6810,
3509,
2043,
7750,
13788,
687,
314,
1890,
12,
11159,
1808,
314,
8271,
1021,
14,
199,
19,
14,
710,
6430,
12,
10240,
436,
5817,
2954,
820,
17983,
1245,
12,
1406,
436,
1414,
17342,
14,
710,
9821,
54,
1021,
9031,
3423,
370,
5147,
1586,
2043,
436,
2218,
402,
9821,
54,
570,
1475,
14,
421,
199,
21718,
7288,
376,
4223,
883,
10623,
642,
1654,
465,
11924,
26,
199,
4,
2366,
519,
2791,
14,
647,
199,
199,
1378,
5715,
314,
1414,
1004,
1511,
675,
314,
446,
72,
945,
26,
199,
4,
2366,
519,
2791,
14,
647,
446,
72,
199,
199,
1378,
1343,
314,
1654,
543,
282,
3365,
2082,
367,
20952,
436,
25692,
9821,
54,
1584,
687,
12,
675,
314,
2569,
1414,
14,
199,
4,
2366,
519,
2791,
14,
647,
446,
82,
2005,
13,
1848,
13,
3619,
15,
199,
7443,
314,
11167,
7324,
315,
314,
2082,
536,
14,
23952,
642,
12,
652,
365,
2951,
1202,
465,
282,
2403,
315,
9821,
54,
570,
1561,
14,
199,
199,
33,
511,
1890,
365,
2808,
315,
511,
3041,
2082,
12,
436,
883,
506,
10311,
1808,
481,
3113,
19286,
14,
26776,
12,
1265,
883,
675,
314,
17548,
38,
570,
370,
10623,
199,
504,
511,
3041,
15,
1393,
13,
1757,
2410,
6617,
314,
1654,
14,
19468,
1265,
1172,
27725,
314,
1890,
315,
314,
7042,
12,
1265,
883,
4907,
370,
199,
1832,
1591,
701,
8968,
316,
641,
283,
2242,
7,
5528,
14,
9442,
8968,
641,
2780,
5528,
370,
2780,
282,
2547,
14,
3232,
4573,
7042,
543,
199,
7191,
2851,
436,
1642,
4907,
2066,
5232,
314,
2011,
2547,
536,
14,
982,
8137,
5419,
15701,
1265,
1077,
506,
7688,
370,
1937,
314,
3991,
199,
504,
1642,
7042,
370,
314,
3499,
7042,
14,
20046,
12,
315,
314,
1642,
7042,
12,
340,
1265,
1104,
314,
2777,
5689,
2544,
2780,
316,
12,
199,
390,
911,
1218,
282,
892,
9821,
54,
570,
367,
314,
18894,
2547,
14,
2047,
883,
4002,
314,
2780,
316,
2547,
436,
5232,
314,
18894,
2547,
370,
199,
3239,
2195,
20952,
14,
3390,
626,
7037,
370,
2536,
7339,
315,
4913,
334,
262,
1930,
2780,
1990,
28614,
8298,
2945,
2419,
4907,
395,
199,
12695,
5232,
379,
3991,
911,
1343,
7468,
316,
2410,
2005,
2536,
7339,
14,
421,
199,
3917,
376,
4223,
15061,
370,
675,
642,
859,
465,
282,
3555,
12,
652,
883,
10623,
314,
1654,
465,
11924,
26,
199,
6071,
6631,
275,
11040,
1119,
3120,
342,
257,
327,
282,
892,
820,
17983,
1654,
1256,
199,
6071,
6631,
14,
1231,
275,
283,
2327,
3122,
4805,
259,
327,
663,
314,
2213,
1738,
370,
506,
283,
2327,
3122,
7,
2082,
14,
3758,
365,
1453,
1987,
4805,
2082,
14,
199,
6071,
6631,
14,
928,
342,
3698,
327,
1343,
314,
1654,
199,
6071,
3510,
1765,
14,
1065,
342,
260,
327,
642,
365,
4346,
23430,
315,
314,
4223,
370,
5965,
1343,
314,
512,
13,
2262,
1905,
3510,
1765,
316,
14,
421,
199,
3917,
376,
4223,
15061,
370,
4165,
282,
3365,
4223,
1163,
2419,
314,
849,
4693,
12,
652,
883,
5516,
652,
436,
17169,
314,
4223,
701,
199,
6031,
314,
1654,
1159,
8686,
3324,
14,
710,
2569,
2893,
13703,
4212,
370,
5627,
298,
1662,
571,
2,
1314,
29761,
282,
283,
7113,
11716,
1083,
641,
1890,
1380,
199,
1589,
1890,
4907,
83,
370,
314,
1654,
14,
199,
199,
533,
4932,
2640,
8,
2640,
304,
260,
327,
282,
892,
4932,
2640,
16879,
314,
849,
4693,
315,
519,
2791,
859,
14,
272,
347,
636,
826,
721,
277,
304,
257,
327,
3787,
2951,
29761,
1300,
1021,
3787,
267,
4693,
855,
826,
721,
277,
9,
272,
347,
641,
8631,
8,
277,
12,
1890,
12,
627,
589,
304,
267,
754,
275,
4693,
14,
265,
8631,
8,
277,
12,
1890,
12,
627,
589,
9,
257,
327,
12677,
1300,
1021,
1083,
1642,
267,
347,
12677,
20201,
8,
277,
12,
1890,
304,
4483,
327,
5627,
282,
1083,
370,
12677,
283,
7113,
480,
3972,
13,
1273,
32292,
641,
11040,
1119,
1890,
288,
1995,
1890,
14,
1250,
360,
7113,
297,
283,
3972,
13,
1273,
358,
267,
3510,
1765,
14,
525,
8,
15195,
20201,
8,
277,
12,
1890,
430,
420,
327,
1929,
370,
12677,
2945,
880,
626,
1950,
365,
23594,
2544,
3233,
267,
372,
754,
258,
327,
372,
715,
370,
4729,
12,
503,
488,
370,
2963,
80,
368,
6358,
4729,
342,
199,
1396,
199,
4054,
14,
5181,
275,
1211,
3252,
1662,
571,
356,
4932,
2640,
12,
283,
3972,
571,
356,
4932,
2640,
12,
22969,
4693,
1552,
199,
199,
14351,
314,
1890,
883,
4907,
370,
519,
2791,
921,
1000,
15,
1662,
571,
503,
519,
2791,
921,
1000,
15,
3972,
571,
436,
911,
664,
8539,
370,
642,
4932,
2640,
4223,
14,
199,
3917,
314,
1890,
3181,
1133,
5627,
298,
1593,
8539,
8,
1273,
26,
1558,
304,
1647,
2,
315,
314,
5365,
3225,
14,
1258,
909,
2066,
314,
1654,
911,
199,
11964,
376,
1919,
436,
2929,
314,
1125,
1245,
14,
199,
199,
2344,
199,
199,
646,
747,
12,
984,
12,
900,
12,
2702,
12,
2838,
12,
5190,
12,
3510,
1765,
12,
8140,
70,
12,
8337,
12,
20330,
12,
2196,
199,
199,
63,
1757,
275,
756,
199,
199,
533,
8113,
15190,
26,
272,
283,
21597,
1380,
314,
1890,
6876,
314,
1950,
7,
199,
199,
318,
14547,
8,
576,
12,
1390,
29,
1960
] |
[
1898,
334,
67,
9,
10219,
13,
8664,
12,
603,
455,
502,
428,
316,
72,
14,
2900,
4481,
4644,
14,
1937,
27781,
367,
2436,
14,
199,
3,
1898,
334,
67,
9,
7129,
13,
8128,
12,
1804,
725,
290,
428,
316,
72,
14,
199,
199,
2344,
199,
2765,
365,
282,
3486,
4514,
402,
282,
11040,
1119,
820,
17983,
1654,
370,
4729,
6947,
436,
2547,
4145,
14,
710,
859,
365,
20765,
1759,
465,
11924,
26,
199,
17,
14,
710,
11040,
1119,
3120,
1021,
365,
314,
2446,
1021,
370,
5647,
314,
1654,
2236,
29639,
14,
2779,
4440,
314,
3510,
1765,
859,
367,
512,
13,
2262,
1905,
3510,
1765,
316,
14,
2043,
2779,
2597,
4440,
314,
4693,
9006,
1021,
370,
5669,
314,
13103,
14,
199,
18,
14,
710,
7146,
1021,
9031,
282,
3486,
1654,
370,
9128,
892,
6810,
6947,
436,
315,
964,
314,
11040,
1119,
3120,
4223,
14,
710,
6810,
1021,
2043,
7131,
687,
11557,
9031,
314,
820,
17983,
1890,
3423,
14,
710,
11557,
1021,
9031,
314,
1300,
820,
17983,
4113,
6057,
14,
437,
6810,
3509,
2043,
7750,
13788,
687,
314,
1890,
12,
11159,
1808,
314,
8271,
1021,
14,
199,
19,
14,
710,
6430,
12,
10240,
436,
5817,
2954,
820,
17983,
1245,
12,
1406,
436,
1414,
17342,
14,
710,
9821,
54,
1021,
9031,
3423,
370,
5147,
1586,
2043,
436,
2218,
402,
9821,
54,
570,
1475,
14,
421,
199,
21718,
7288,
376,
4223,
883,
10623,
642,
1654,
465,
11924,
26,
199,
4,
2366,
519,
2791,
14,
647,
199,
199,
1378,
5715,
314,
1414,
1004,
1511,
675,
314,
446,
72,
945,
26,
199,
4,
2366,
519,
2791,
14,
647,
446,
72,
199,
199,
1378,
1343,
314,
1654,
543,
282,
3365,
2082,
367,
20952,
436,
25692,
9821,
54,
1584,
687,
12,
675,
314,
2569,
1414,
14,
199,
4,
2366,
519,
2791,
14,
647,
446,
82,
2005,
13,
1848,
13,
3619,
15,
199,
7443,
314,
11167,
7324,
315,
314,
2082,
536,
14,
23952,
642,
12,
652,
365,
2951,
1202,
465,
282,
2403,
315,
9821,
54,
570,
1561,
14,
199,
199,
33,
511,
1890,
365,
2808,
315,
511,
3041,
2082,
12,
436,
883,
506,
10311,
1808,
481,
3113,
19286,
14,
26776,
12,
1265,
883,
675,
314,
17548,
38,
570,
370,
10623,
199,
504,
511,
3041,
15,
1393,
13,
1757,
2410,
6617,
314,
1654,
14,
19468,
1265,
1172,
27725,
314,
1890,
315,
314,
7042,
12,
1265,
883,
4907,
370,
199,
1832,
1591,
701,
8968,
316,
641,
283,
2242,
7,
5528,
14,
9442,
8968,
641,
2780,
5528,
370,
2780,
282,
2547,
14,
3232,
4573,
7042,
543,
199,
7191,
2851,
436,
1642,
4907,
2066,
5232,
314,
2011,
2547,
536,
14,
982,
8137,
5419,
15701,
1265,
1077,
506,
7688,
370,
1937,
314,
3991,
199,
504,
1642,
7042,
370,
314,
3499,
7042,
14,
20046,
12,
315,
314,
1642,
7042,
12,
340,
1265,
1104,
314,
2777,
5689,
2544,
2780,
316,
12,
199,
390,
911,
1218,
282,
892,
9821,
54,
570,
367,
314,
18894,
2547,
14,
2047,
883,
4002,
314,
2780,
316,
2547,
436,
5232,
314,
18894,
2547,
370,
199,
3239,
2195,
20952,
14,
3390,
626,
7037,
370,
2536,
7339,
315,
4913,
334,
262,
1930,
2780,
1990,
28614,
8298,
2945,
2419,
4907,
395,
199,
12695,
5232,
379,
3991,
911,
1343,
7468,
316,
2410,
2005,
2536,
7339,
14,
421,
199,
3917,
376,
4223,
15061,
370,
675,
642,
859,
465,
282,
3555,
12,
652,
883,
10623,
314,
1654,
465,
11924,
26,
199,
6071,
6631,
275,
11040,
1119,
3120,
342,
257,
327,
282,
892,
820,
17983,
1654,
1256,
199,
6071,
6631,
14,
1231,
275,
283,
2327,
3122,
4805,
259,
327,
663,
314,
2213,
1738,
370,
506,
283,
2327,
3122,
7,
2082,
14,
3758,
365,
1453,
1987,
4805,
2082,
14,
199,
6071,
6631,
14,
928,
342,
3698,
327,
1343,
314,
1654,
199,
6071,
3510,
1765,
14,
1065,
342,
260,
327,
642,
365,
4346,
23430,
315,
314,
4223,
370,
5965,
1343,
314,
512,
13,
2262,
1905,
3510,
1765,
316,
14,
421,
199,
3917,
376,
4223,
15061,
370,
4165,
282,
3365,
4223,
1163,
2419,
314,
849,
4693,
12,
652,
883,
5516,
652,
436,
17169,
314,
4223,
701,
199,
6031,
314,
1654,
1159,
8686,
3324,
14,
710,
2569,
2893,
13703,
4212,
370,
5627,
298,
1662,
571,
2,
1314,
29761,
282,
283,
7113,
11716,
1083,
641,
1890,
1380,
199,
1589,
1890,
4907,
83,
370,
314,
1654,
14,
199,
199,
533,
4932,
2640,
8,
2640,
304,
260,
327,
282,
892,
4932,
2640,
16879,
314,
849,
4693,
315,
519,
2791,
859,
14,
272,
347,
636,
826,
721,
277,
304,
257,
327,
3787,
2951,
29761,
1300,
1021,
3787,
267,
4693,
855,
826,
721,
277,
9,
272,
347,
641,
8631,
8,
277,
12,
1890,
12,
627,
589,
304,
267,
754,
275,
4693,
14,
265,
8631,
8,
277,
12,
1890,
12,
627,
589,
9,
257,
327,
12677,
1300,
1021,
1083,
1642,
267,
347,
12677,
20201,
8,
277,
12,
1890,
304,
4483,
327,
5627,
282,
1083,
370,
12677,
283,
7113,
480,
3972,
13,
1273,
32292,
641,
11040,
1119,
1890,
288,
1995,
1890,
14,
1250,
360,
7113,
297,
283,
3972,
13,
1273,
358,
267,
3510,
1765,
14,
525,
8,
15195,
20201,
8,
277,
12,
1890,
430,
420,
327,
1929,
370,
12677,
2945,
880,
626,
1950,
365,
23594,
2544,
3233,
267,
372,
754,
258,
327,
372,
715,
370,
4729,
12,
503,
488,
370,
2963,
80,
368,
6358,
4729,
342,
199,
1396,
199,
4054,
14,
5181,
275,
1211,
3252,
1662,
571,
356,
4932,
2640,
12,
283,
3972,
571,
356,
4932,
2640,
12,
22969,
4693,
1552,
199,
199,
14351,
314,
1890,
883,
4907,
370,
519,
2791,
921,
1000,
15,
1662,
571,
503,
519,
2791,
921,
1000,
15,
3972,
571,
436,
911,
664,
8539,
370,
642,
4932,
2640,
4223,
14,
199,
3917,
314,
1890,
3181,
1133,
5627,
298,
1593,
8539,
8,
1273,
26,
1558,
304,
1647,
2,
315,
314,
5365,
3225,
14,
1258,
909,
2066,
314,
1654,
911,
199,
11964,
376,
1919,
436,
2929,
314,
1125,
1245,
14,
199,
199,
2344,
199,
199,
646,
747,
12,
984,
12,
900,
12,
2702,
12,
2838,
12,
5190,
12,
3510,
1765,
12,
8140,
70,
12,
8337,
12,
20330,
12,
2196,
199,
199,
63,
1757,
275,
756,
199,
199,
533,
8113,
15190,
26,
272,
283,
21597,
1380,
314,
1890,
6876,
314,
1950,
7,
199,
199,
318,
14547,
8,
576,
12,
1390,
29,
1960,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hryamzik/ansible
|
lib/ansible/modules/network/netvisor/pn_cluster.py
|
43
|
9501
|
#!/usr/bin/python
""" PN CLI cluster-create/cluster-delete """
#
# 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: pn_cluster
author: "Pluribus Networks (@amitsi)"
version_added: "2.2"
short_description: CLI command to create/delete a cluster.
description:
- Execute cluster-create or cluster-delete command.
- A cluster allows two switches to cooperate in high-availability (HA)
deployments. The nodes that form the cluster must be members of the same
fabric. Clusters are typically used in conjunction with a virtual link
aggregation group (VLAG) that allows links physically connected to two
separate switches appear as a single trunk to a third device. The third
device can be a switch,server, or any Ethernet device.
options:
pn_cliusername:
description:
- Provide login username if user is not root.
required: False
pn_clipassword:
description:
- Provide login password if user is not root.
required: False
pn_cliswitch:
description:
- Target switch to run the cli on.
required: False
state:
description:
- Specify action to perform. Use 'present' to create cluster and 'absent'
to delete cluster.
required: true
choices: ['present', 'absent']
pn_name:
description:
- Specify the name of the cluster.
required: true
pn_cluster_node1:
description:
- Specify the name of the first switch in the cluster.
- Required for 'cluster-create'.
pn_cluster_node2:
description:
- Specify the name of the second switch in the cluster.
- Required for 'cluster-create'.
pn_validate:
description:
- Validate the inter-switch links and state of switches in the cluster.
choices: ['validate', 'no-validate']
"""
EXAMPLES = """
- name: create spine cluster
pn_cluster:
state: 'present'
pn_name: 'spine-cluster'
pn_cluster_node1: 'spine01'
pn_cluster_node2: 'spine02'
pn_validate: validate
pn_quiet: True
- name: delete spine cluster
pn_cluster:
state: 'absent'
pn_name: 'spine-cluster'
pn_quiet: True
"""
RETURN = """
command:
description: The CLI command run on the target node(s).
returned: always
type: str
stdout:
description: The set of responses from the cluster command.
returned: always
type: list
stderr:
description: The set of error responses from the cluster command.
returned: on error
type: list
changed:
description: Indicates whether the CLI caused changes on the target.
returned: always
type: bool
"""
import shlex
NAME_EXISTS = None
NODE1_EXISTS = None
NODE2_EXISTS = None
def pn_cli(module):
"""
This method is to generate the cli portion to launch the Netvisor cli.
It parses the username, password, switch parameters from module.
:param module: The Ansible module to fetch username, password and switch
:return: returns the cli string for further processing
"""
username = module.params['pn_cliusername']
password = module.params['pn_clipassword']
cliswitch = module.params['pn_cliswitch']
if username and password:
cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password)
else:
cli = '/usr/bin/cli --quiet '
if cliswitch == 'local':
cli += ' switch-local '
else:
cli += ' switch ' + cliswitch
return cli
def check_cli(module, cli):
"""
This method checks for idempotency using the cluster-show command.
If a cluster with given name exists, return NAME_EXISTS as True else False.
If the given cluster-node-1 is already a part of another cluster, return
NODE1_EXISTS as True else False.
If the given cluster-node-2 is already a part of another cluster, return
NODE2_EXISTS as True else False.
:param module: The Ansible module to fetch input parameters
:param cli: The CLI string
:return Global Booleans: NAME_EXISTS, NODE1_EXISTS, NODE2_EXISTS
"""
name = module.params['pn_name']
node1 = module.params['pn_cluster_node1']
node2 = module.params['pn_cluster_node2']
show = cli + ' cluster-show format name,cluster-node-1,cluster-node-2 '
show = shlex.split(show)
out = module.run_command(show)[1]
out = out.split()
# Global flags
global NAME_EXISTS, NODE1_EXISTS, NODE2_EXISTS
if name in out:
NAME_EXISTS = True
else:
NAME_EXISTS = False
if node1 in out:
NODE1_EXISTS = True
else:
NODE2_EXISTS = False
if node2 in out:
NODE2_EXISTS = True
else:
NODE2_EXISTS = False
def run_cli(module, cli):
"""
This method executes the cli command on the target node(s) and returns the
output. The module then exits based on the output.
:param cli: the complete cli string to be executed on the target node(s).
:param module: The Ansible module to fetch command
"""
cliswitch = module.params['pn_cliswitch']
state = module.params['state']
command = get_command_from_state(state)
cmd = shlex.split(cli)
# 'out' contains the output
# 'err' contains the error messages
result, out, err = module.run_command(cmd)
print_cli = cli.split(cliswitch)[1]
# Response in JSON format
if result != 0:
module.exit_json(
command=print_cli,
stderr=err.strip(),
msg="%s operation failed" % command,
changed=False
)
if out:
module.exit_json(
command=print_cli,
stdout=out.strip(),
msg="%s operation completed" % command,
changed=True
)
else:
module.exit_json(
command=print_cli,
msg="%s operation completed" % command,
changed=True
)
def get_command_from_state(state):
"""
This method gets appropriate command name for the state specified. It
returns the command name for the specified state.
:param state: The state for which the respective command name is required.
"""
command = None
if state == 'present':
command = 'cluster-create'
if state == 'absent':
command = 'cluster-delete'
return command
def main():
""" This section is for arguments parsing """
module = AnsibleModule(
argument_spec=dict(
pn_cliusername=dict(required=False, type='str'),
pn_clipassword=dict(required=False, type='str', no_log=True),
pn_cliswitch=dict(required=False, type='str', default='local'),
state=dict(required=True, type='str',
choices=['present', 'absent']),
pn_name=dict(required=True, type='str'),
pn_cluster_node1=dict(type='str'),
pn_cluster_node2=dict(type='str'),
pn_validate=dict(type='bool')
),
required_if=(
["state", "present",
["pn_name", "pn_cluster_node1", "pn_cluster_node2"]],
["state", "absent", ["pn_name"]]
)
)
# Accessing the parameters
state = module.params['state']
name = module.params['pn_name']
cluster_node1 = module.params['pn_cluster_node1']
cluster_node2 = module.params['pn_cluster_node2']
validate = module.params['pn_validate']
command = get_command_from_state(state)
# Building the CLI command string
cli = pn_cli(module)
if command == 'cluster-create':
check_cli(module, cli)
if NAME_EXISTS is True:
module.exit_json(
skipped=True,
msg='Cluster with name %s already exists' % name
)
if NODE1_EXISTS is True:
module.exit_json(
skipped=True,
msg='Node %s already part of a cluster' % cluster_node1
)
if NODE2_EXISTS is True:
module.exit_json(
skipped=True,
msg='Node %s already part of a cluster' % cluster_node2
)
cli += ' %s name %s ' % (command, name)
cli += 'cluster-node-1 %s cluster-node-2 %s ' % (cluster_node1,
cluster_node2)
if validate is True:
cli += ' validate '
if validate is False:
cli += ' no-validate '
if command == 'cluster-delete':
check_cli(module, cli)
if NAME_EXISTS is False:
module.exit_json(
skipped=True,
msg='Cluster with name %s does not exist' % name
)
cli += ' %s name %s ' % (command, name)
run_cli(module, cli)
# AnsibleModule boilerplate
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
624,
510,
46,
14214,
4350,
13,
981,
15,
4201,
13,
1807,
408,
199,
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,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
13631,
63,
4201,
199,
2502,
26,
298,
3714,
2302,
5610,
17138,
8593,
455,
390,
338,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
14214,
1414,
370,
1218,
15,
1807,
282,
4350,
14,
199,
1802,
26,
523,
446,
17009,
4350,
13,
981,
503,
4350,
13,
1807,
1414,
14,
523,
446,
437,
4350,
6127,
2877,
24563,
370,
512,
2262,
323,
315,
4721,
13,
11856,
334,
6294,
9,
272,
12287,
1470,
14,
710,
3380,
626,
1824,
314,
4350,
1471,
506,
7556,
402,
314,
2011,
272,
2630,
14,
8465,
6811,
787,
13609,
1202,
315,
22888,
543,
282,
5791,
2142,
272,
18384,
1572,
334,
32458,
1254,
9,
626,
6127,
6220,
11831,
9916,
1183,
8539,
370,
2877,
272,
7396,
24563,
7468,
465,
282,
2849,
24764,
370,
282,
10919,
2243,
14,
710,
10919,
272,
2243,
883,
506,
282,
6258,
12,
1000,
12,
503,
1263,
26125,
2243,
14,
199,
1419,
26,
523,
13631,
63,
2764,
2473,
26,
272,
1369,
26,
489,
446,
22896,
4676,
3434,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
2060,
26,
272,
1369,
26,
489,
446,
22896,
4676,
2505,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
5656,
26,
272,
1369,
26,
489,
446,
10256,
6258,
370,
1255,
314,
5053,
641,
14,
272,
1415,
26,
756,
523,
1174,
26,
272,
1369,
26,
489,
446,
13327,
1595,
370,
5147,
14,
3645,
283,
1881,
7,
370,
1218,
4350,
436,
283,
5575,
7,
267,
370,
3145,
4350,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
13631,
63,
354,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
4350,
14,
272,
1415,
26,
2549,
523,
13631,
63,
4201,
63,
932,
17,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
1642,
6258,
315,
314,
4350,
14,
489,
446,
11105,
367,
283,
4201,
13,
981,
1370,
523,
13631,
63,
4201,
63,
932,
18,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
3499,
6258,
315,
314,
4350,
14,
489,
446,
11105,
367,
283,
4201,
13,
981,
1370,
523,
13631,
63,
3502,
26,
272,
1369,
26,
489,
446,
12134,
314,
1640,
13,
5656,
6220,
436,
1174,
402,
24563,
315,
314,
4350,
14,
272,
3415,
26,
788,
3502,
297,
283,
889,
13,
3502,
418,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
2249,
1132,
4350,
523,
13631,
63,
4201,
26,
272,
1174,
26,
283,
1881,
7,
272,
13631,
63,
354,
26,
283,
681,
1132,
13,
4201,
7,
272,
13631,
63,
4201,
63,
932,
17,
26,
283,
681,
1132,
614,
7,
272,
13631,
63,
4201,
63,
932,
18,
26,
283,
681,
1132,
996,
7,
272,
13631,
63,
3502,
26,
4107,
272,
13631,
63,
10243,
26,
715,
199,
199,
13,
536,
26,
3145,
2249,
1132,
4350,
523,
13631,
63,
4201,
26,
272,
1174,
26,
283,
5575,
7,
272,
13631,
63,
354,
26,
283,
681,
1132,
13,
4201,
7,
272,
13631,
63,
10243,
26,
715,
199,
624,
199,
199,
9677,
275,
408,
199,
1531,
26,
523,
1369,
26,
710,
14214,
1414,
1255,
641,
314,
1347,
1031,
8,
83,
680,
523,
2138,
26,
3544,
523,
730,
26,
620,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
4350,
1414,
14,
523,
2138,
26,
3544,
523,
730,
26,
769,
199,
3083,
26,
523,
1369,
26,
710,
663,
402,
1125,
9320,
687,
314,
4350,
1414,
14,
523,
2138,
26,
641,
1125,
523,
730,
26,
769,
199,
2489,
26,
523,
1369,
26,
19334,
3775,
314,
14214,
18104,
4493,
641,
314,
1347,
14,
523,
2138,
26,
3544,
523,
730,
26,
2155,
199,
624,
199,
199,
646,
16701,
199,
199,
2339,
63,
23558,
275,
488,
199,
8063,
17,
63,
23558,
275,
488,
199,
8063,
18,
63,
23558,
275,
488,
421,
199,
318,
13631,
63,
2764,
8,
578,
304,
272,
408,
272,
961,
1083,
365,
370,
3550,
314,
5053,
18046,
370,
10623,
314,
5365,
8286,
5053,
14,
272,
2779,
19953,
314,
3434,
12,
2505,
12,
6258,
2633,
687,
859,
14,
272,
520,
635,
859,
26,
710,
2622,
859,
370,
5267,
3434,
12,
2505,
436,
6258,
272,
520,
1107,
26,
2529,
314,
5053,
1059,
367,
9848,
6661,
272,
408,
272,
3434,
275,
859,
14,
1162,
459,
4812,
63,
2764,
2473,
418,
272,
2505,
275,
859,
14,
1162,
459,
4812,
63,
2764,
2060,
418,
272,
5053,
5656,
275,
859,
14,
1162,
459,
4812,
63,
2764,
5656,
418,
339,
340,
3434,
436,
2505,
26,
267,
5053,
275,
1994,
2647,
15,
1393,
15,
2764,
1553,
10243,
1553,
751,
450,
83,
2689,
83,
283,
450,
334,
2473,
12,
2505,
9,
272,
587,
26,
267,
5053,
275,
1994,
2647,
15,
1393,
15,
2764,
1553,
10243,
283,
339,
340,
5053,
5656,
508,
283,
1832,
356,
267,
5053,
847,
283,
6258,
13,
1832,
283,
272,
587,
26,
267,
5053,
847,
283
] |
[
2647,
15,
1393,
15,
1548,
199,
624,
510,
46,
14214,
4350,
13,
981,
15,
4201,
13,
1807,
408,
199,
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,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
13631,
63,
4201,
199,
2502,
26,
298,
3714,
2302,
5610,
17138,
8593,
455,
390,
338,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
14214,
1414,
370,
1218,
15,
1807,
282,
4350,
14,
199,
1802,
26,
523,
446,
17009,
4350,
13,
981,
503,
4350,
13,
1807,
1414,
14,
523,
446,
437,
4350,
6127,
2877,
24563,
370,
512,
2262,
323,
315,
4721,
13,
11856,
334,
6294,
9,
272,
12287,
1470,
14,
710,
3380,
626,
1824,
314,
4350,
1471,
506,
7556,
402,
314,
2011,
272,
2630,
14,
8465,
6811,
787,
13609,
1202,
315,
22888,
543,
282,
5791,
2142,
272,
18384,
1572,
334,
32458,
1254,
9,
626,
6127,
6220,
11831,
9916,
1183,
8539,
370,
2877,
272,
7396,
24563,
7468,
465,
282,
2849,
24764,
370,
282,
10919,
2243,
14,
710,
10919,
272,
2243,
883,
506,
282,
6258,
12,
1000,
12,
503,
1263,
26125,
2243,
14,
199,
1419,
26,
523,
13631,
63,
2764,
2473,
26,
272,
1369,
26,
489,
446,
22896,
4676,
3434,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
2060,
26,
272,
1369,
26,
489,
446,
22896,
4676,
2505,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
5656,
26,
272,
1369,
26,
489,
446,
10256,
6258,
370,
1255,
314,
5053,
641,
14,
272,
1415,
26,
756,
523,
1174,
26,
272,
1369,
26,
489,
446,
13327,
1595,
370,
5147,
14,
3645,
283,
1881,
7,
370,
1218,
4350,
436,
283,
5575,
7,
267,
370,
3145,
4350,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
13631,
63,
354,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
4350,
14,
272,
1415,
26,
2549,
523,
13631,
63,
4201,
63,
932,
17,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
1642,
6258,
315,
314,
4350,
14,
489,
446,
11105,
367,
283,
4201,
13,
981,
1370,
523,
13631,
63,
4201,
63,
932,
18,
26,
272,
1369,
26,
489,
446,
13327,
314,
536,
402,
314,
3499,
6258,
315,
314,
4350,
14,
489,
446,
11105,
367,
283,
4201,
13,
981,
1370,
523,
13631,
63,
3502,
26,
272,
1369,
26,
489,
446,
12134,
314,
1640,
13,
5656,
6220,
436,
1174,
402,
24563,
315,
314,
4350,
14,
272,
3415,
26,
788,
3502,
297,
283,
889,
13,
3502,
418,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
2249,
1132,
4350,
523,
13631,
63,
4201,
26,
272,
1174,
26,
283,
1881,
7,
272,
13631,
63,
354,
26,
283,
681,
1132,
13,
4201,
7,
272,
13631,
63,
4201,
63,
932,
17,
26,
283,
681,
1132,
614,
7,
272,
13631,
63,
4201,
63,
932,
18,
26,
283,
681,
1132,
996,
7,
272,
13631,
63,
3502,
26,
4107,
272,
13631,
63,
10243,
26,
715,
199,
199,
13,
536,
26,
3145,
2249,
1132,
4350,
523,
13631,
63,
4201,
26,
272,
1174,
26,
283,
5575,
7,
272,
13631,
63,
354,
26,
283,
681,
1132,
13,
4201,
7,
272,
13631,
63,
10243,
26,
715,
199,
624,
199,
199,
9677,
275,
408,
199,
1531,
26,
523,
1369,
26,
710,
14214,
1414,
1255,
641,
314,
1347,
1031,
8,
83,
680,
523,
2138,
26,
3544,
523,
730,
26,
620,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
4350,
1414,
14,
523,
2138,
26,
3544,
523,
730,
26,
769,
199,
3083,
26,
523,
1369,
26,
710,
663,
402,
1125,
9320,
687,
314,
4350,
1414,
14,
523,
2138,
26,
641,
1125,
523,
730,
26,
769,
199,
2489,
26,
523,
1369,
26,
19334,
3775,
314,
14214,
18104,
4493,
641,
314,
1347,
14,
523,
2138,
26,
3544,
523,
730,
26,
2155,
199,
624,
199,
199,
646,
16701,
199,
199,
2339,
63,
23558,
275,
488,
199,
8063,
17,
63,
23558,
275,
488,
199,
8063,
18,
63,
23558,
275,
488,
421,
199,
318,
13631,
63,
2764,
8,
578,
304,
272,
408,
272,
961,
1083,
365,
370,
3550,
314,
5053,
18046,
370,
10623,
314,
5365,
8286,
5053,
14,
272,
2779,
19953,
314,
3434,
12,
2505,
12,
6258,
2633,
687,
859,
14,
272,
520,
635,
859,
26,
710,
2622,
859,
370,
5267,
3434,
12,
2505,
436,
6258,
272,
520,
1107,
26,
2529,
314,
5053,
1059,
367,
9848,
6661,
272,
408,
272,
3434,
275,
859,
14,
1162,
459,
4812,
63,
2764,
2473,
418,
272,
2505,
275,
859,
14,
1162,
459,
4812,
63,
2764,
2060,
418,
272,
5053,
5656,
275,
859,
14,
1162,
459,
4812,
63,
2764,
5656,
418,
339,
340,
3434,
436,
2505,
26,
267,
5053,
275,
1994,
2647,
15,
1393,
15,
2764,
1553,
10243,
1553,
751,
450,
83,
2689,
83,
283,
450,
334,
2473,
12,
2505,
9,
272,
587,
26,
267,
5053,
275,
1994,
2647,
15,
1393,
15,
2764,
1553,
10243,
283,
339,
340,
5053,
5656,
508,
283,
1832,
356,
267,
5053,
847,
283,
6258,
13,
1832,
283,
272,
587,
26,
267,
5053,
847,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
seansu4you87/kupo
|
projects/molt/venv/lib/python2.7/site-packages/wheel/test/test_ranking.py
|
565
|
1496
|
import unittest
from wheel.pep425tags import get_supported
from wheel.install import WheelFile
WHEELPAT = "%(name)s-%(ver)s-%(pyver)s-%(abi)s-%(arch)s.whl"
def make_wheel(name, ver, pyver, abi, arch):
name = WHEELPAT % dict(name=name, ver=ver, pyver=pyver, abi=abi,
arch=arch)
return WheelFile(name)
# This relies on the fact that generate_supported will always return the
# exact pyver, abi, and architecture for its first (best) match.
sup = get_supported()
pyver, abi, arch = sup[0]
genver = 'py' + pyver[2:]
majver = genver[:3]
COMBINATIONS = (
('bar', '0.9', 'py2.py3', 'none', 'any'),
('bar', '0.9', majver, 'none', 'any'),
('bar', '0.9', genver, 'none', 'any'),
('bar', '0.9', pyver, abi, arch),
('bar', '1.3.2', majver, 'none', 'any'),
('bar', '3.1', genver, 'none', 'any'),
('bar', '3.1', pyver, abi, arch),
('foo', '1.0', majver, 'none', 'any'),
('foo', '1.1', pyver, abi, arch),
('foo', '2.1', majver + '0', 'none', 'any'),
# This will not be compatible for Python x.0. Beware when we hit Python
# 4.0, and don't test with 3.0!!!
('foo', '2.1', majver + '1', 'none', 'any'),
('foo', '2.1', pyver , 'none', 'any'),
('foo', '2.1', pyver , abi, arch),
)
WHEELS = [ make_wheel(*args) for args in COMBINATIONS ]
class TestRanking(unittest.TestCase):
def test_comparison(self):
for i in range(len(WHEELS)-1):
for j in range(i):
self.assertTrue(WHEELS[j]<WHEELS[i])
|
mit
|
[
646,
2882,
199,
199,
504,
9989,
14,
12636,
24398,
2969,
492,
664,
63,
4946,
199,
504,
9989,
14,
3174,
492,
26161,
1173,
199,
199,
31588,
2901,
2805,
275,
11792,
354,
9,
83,
13,
2840,
422,
9,
83,
13,
2840,
29686,
9,
83,
13,
2840,
14677,
9,
83,
13,
2840,
1047,
9,
83,
14,
2191,
76,
2,
199,
318,
1852,
63,
11798,
8,
354,
12,
809,
12,
1134,
422,
12,
25570,
12,
3819,
304,
272,
536,
275,
644,
1645,
2901,
2805,
450,
1211,
8,
354,
29,
354,
12,
809,
29,
422,
12,
1134,
422,
29,
29686,
12,
25570,
29,
14677,
12,
288,
3819,
29,
1047,
9,
272,
372,
26161,
1173,
8,
354,
9,
199,
199,
3,
961,
25749,
641,
314,
10572,
626,
3550,
63,
4946,
911,
3544,
372,
314,
199,
3,
5835,
1134,
422,
12,
25570,
12,
436,
15931,
367,
2399,
1642,
334,
7010,
9,
1336,
14,
199,
1961,
275,
664,
63,
4946,
342,
199,
29686,
12,
25570,
12,
3819,
275,
1029,
59,
16,
61,
199,
2268,
422,
275,
283,
647,
7,
435,
1134,
422,
59,
18,
2938,
199,
31611,
422,
275,
3805,
422,
1491,
19,
61,
199,
199,
1439,
4567,
568,
12969,
275,
334,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
283,
647,
18,
14,
647,
19,
297,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
3805,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1700,
297,
283,
17,
14,
19,
14,
18,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
19,
14,
17,
297,
3805,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
19,
14,
17,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1421,
297,
283,
17,
14,
16,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
17,
14,
17,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
610,
74,
422,
435,
283,
16,
297,
283,
3592,
297,
283,
1629,
659,
272,
327,
961,
911,
440,
506,
9025,
367,
2018,
671,
14,
16,
14,
699,
546,
1530,
1380,
781,
9793,
2018,
272,
327,
841,
14,
16,
12,
436,
2793,
1133,
511,
543,
650,
14,
16,
21512,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
610,
74,
422,
435,
283,
17,
297,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
1134,
422,
2360,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
1134,
422,
2360,
25570,
12,
3819,
395,
199,
9,
199,
199,
31588,
2901,
51,
275,
359,
1852,
63,
11798,
2031,
589,
9,
367,
1249,
315,
5099,
4567,
568,
12969,
1622,
199,
199,
533,
1379,
19486,
316,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
8547,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
31588,
2901,
51,
7216,
17,
304,
288,
367,
1335,
315,
1425,
8,
73,
304,
355,
291,
14,
1815,
8,
31588,
2901,
51,
59,
74,
61,
28,
31588,
2901,
51,
59,
73,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
199,
504,
9989,
14,
12636,
24398,
2969,
492,
664,
63,
4946,
199,
504,
9989,
14,
3174,
492,
26161,
1173,
199,
199,
31588,
2901,
2805,
275,
11792,
354,
9,
83,
13,
2840,
422,
9,
83,
13,
2840,
29686,
9,
83,
13,
2840,
14677,
9,
83,
13,
2840,
1047,
9,
83,
14,
2191,
76,
2,
199,
318,
1852,
63,
11798,
8,
354,
12,
809,
12,
1134,
422,
12,
25570,
12,
3819,
304,
272,
536,
275,
644,
1645,
2901,
2805,
450,
1211,
8,
354,
29,
354,
12,
809,
29,
422,
12,
1134,
422,
29,
29686,
12,
25570,
29,
14677,
12,
288,
3819,
29,
1047,
9,
272,
372,
26161,
1173,
8,
354,
9,
199,
199,
3,
961,
25749,
641,
314,
10572,
626,
3550,
63,
4946,
911,
3544,
372,
314,
199,
3,
5835,
1134,
422,
12,
25570,
12,
436,
15931,
367,
2399,
1642,
334,
7010,
9,
1336,
14,
199,
1961,
275,
664,
63,
4946,
342,
199,
29686,
12,
25570,
12,
3819,
275,
1029,
59,
16,
61,
199,
2268,
422,
275,
283,
647,
7,
435,
1134,
422,
59,
18,
2938,
199,
31611,
422,
275,
3805,
422,
1491,
19,
61,
199,
199,
1439,
4567,
568,
12969,
275,
334,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
283,
647,
18,
14,
647,
19,
297,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
3805,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
16,
14,
25,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1700,
297,
283,
17,
14,
19,
14,
18,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
19,
14,
17,
297,
3805,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1700,
297,
283,
19,
14,
17,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1421,
297,
283,
17,
14,
16,
297,
610,
74,
422,
12,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
17,
14,
17,
297,
1134,
422,
12,
25570,
12,
3819,
395,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
610,
74,
422,
435,
283,
16,
297,
283,
3592,
297,
283,
1629,
659,
272,
327,
961,
911,
440,
506,
9025,
367,
2018,
671,
14,
16,
14,
699,
546,
1530,
1380,
781,
9793,
2018,
272,
327,
841,
14,
16,
12,
436,
2793,
1133,
511,
543,
650,
14,
16,
21512,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
610,
74,
422,
435,
283,
17,
297,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
1134,
422,
2360,
283,
3592,
297,
283,
1629,
659,
272,
661,
1421,
297,
283,
18,
14,
17,
297,
1134,
422,
2360,
25570,
12,
3819,
395,
199,
9,
199,
199,
31588,
2901,
51,
275,
359,
1852,
63,
11798,
2031,
589,
9,
367,
1249,
315,
5099,
4567,
568,
12969,
1622,
199,
199,
533,
1379,
19486,
316,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
8547,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
31588,
2901,
51,
7216,
17,
304,
288,
367,
1335,
315,
1425,
8,
73,
304,
355,
291,
14,
1815,
8,
31588,
2901,
51,
59,
74,
61,
28,
31588,
2901,
51,
59,
73,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bluesea/zulip
|
zerver/decorator.py
|
115
|
23508
|
from __future__ import absolute_import
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.http import QueryDict, HttpResponseNotAllowed
from django.http.multipartparser import MultiPartParser
from zerver.models import UserProfile, get_client, get_user_profile_by_email
from zerver.lib.response import json_error, json_unauthorized
from django.utils.timezone import now
from django.conf import settings
import ujson
from StringIO import StringIO
from zerver.lib.queue import queue_json_publish
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.utils import statsd
from zerver.exceptions import RateLimited
from zerver.lib.rate_limiter import incr_ratelimit, is_ratelimited, \
api_calls_left
from functools import wraps
import base64
import logging
import cProfile
from zerver.lib.mandrill_client import get_mandrill_client
if settings.ZULIP_COM:
from zilencer.models import get_deployment_by_domain, Deployment
else:
from mock import Mock
get_deployment_by_domain = Mock()
Deployment = Mock()
def get_deployment_or_userprofile(role):
return get_user_profile_by_email(role) if "@" in role else get_deployment_by_domain(role)
class _RespondAsynchronously(object):
pass
# Return RespondAsynchronously from an @asynchronous view if the
# response will be provided later by calling handler.zulip_finish(),
# or has already been provided this way. We use this for longpolling
# mode.
RespondAsynchronously = _RespondAsynchronously()
def asynchronous(method):
@wraps(method)
def wrapper(request, *args, **kwargs):
return method(request, handler=request._tornado_handler, *args, **kwargs)
if getattr(method, 'csrf_exempt', False):
wrapper.csrf_exempt = True
return wrapper
def update_user_activity(request, user_profile):
# update_active_status also pushes to rabbitmq, and it seems
# redundant to log that here as well.
if request.META["PATH_INFO"] == '/json/update_active_status':
return
if hasattr(request, '_query'):
query = request._query
else:
query = request.META['PATH_INFO']
event={'query': query,
'user_profile_id': user_profile.id,
'time': datetime_to_timestamp(now()),
'client': request.client.name}
queue_json_publish("user_activity", event, lambda event: None)
# Based on django.views.decorators.http.require_http_methods
def require_post(func):
@wraps(func)
def wrapper(request, *args, **kwargs):
if (request.method != "POST"
and not (request.method == "SOCKET"
and request.META['zulip.emulated_method'] == "POST")):
if request.method == "SOCKET":
err_method = "SOCKET/%s" % (request.META['zulip.emulated_method'],)
else:
err_method = request.method
logging.warning('Method Not Allowed (%s): %s', err_method, request.path,
extra={'status_code': 405, 'request': request})
return HttpResponseNotAllowed(["POST"])
return func(request, *args, **kwargs)
return wrapper
def require_realm_admin(func):
@wraps(func)
def wrapper(request, user_profile, *args, **kwargs):
if not user_profile.has_perm('administer', user_profile.realm):
raise JsonableError("Must be a realm administrator")
return func(request, user_profile, *args, **kwargs)
return wrapper
from zerver.lib.user_agent import parse_user_agent
def get_client_name(request, is_json_view):
# If the API request specified a client in the request content,
# that has priority. Otherwise, extract the client from the
# User-Agent.
if 'client' in request.REQUEST:
return request.REQUEST['client']
elif "HTTP_USER_AGENT" in request.META:
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
# We could check for a browser's name being "Mozilla", but
# e.g. Opera and MobileSafari don't set that, and it seems
# more robust to just key off whether it was a json view
if user_agent["name"] != "ZulipDesktop" and is_json_view:
# Avoid changing the client string for browsers Once this
# is out to prod, we can name the field to something like
# Browser for consistency.
return "website"
else:
return user_agent["name"]
else:
# In the future, we will require setting USER_AGENT, but for
# now we just want to tag these requests so we can review them
# in logs and figure out the extent of the problem
if is_json_view:
return "website"
else:
return "Unspecified"
def process_client(request, user_profile, is_json_view=False):
client_name = get_client_name(request, is_json_view)
# Transitional hack for early 2014. Eventually the ios clients
# will all report ZulipiOS, and we can remove the next couple lines.
if client_name == 'ios':
client_name = 'ZulipiOS'
request.client = get_client(client_name)
update_user_activity(request, user_profile)
def validate_api_key(role, api_key):
# Remove whitespace to protect users from trivial errors.
role, api_key = role.strip(), api_key.strip()
try:
profile = get_deployment_or_userprofile(role)
except UserProfile.DoesNotExist:
raise JsonableError("Invalid user: %s" % (role,))
except Deployment.DoesNotExist:
raise JsonableError("Invalid deployment: %s" % (role,))
if api_key != profile.api_key:
if len(api_key) != 32:
reason = "Incorrect API key length (keys should be 32 characters long)"
else:
reason = "Invalid API key"
raise JsonableError(reason + " for role '%s'" % (role,))
if not profile.is_active:
raise JsonableError("Account not active")
try:
if profile.realm.deactivated:
raise JsonableError("Realm for account has been deactivated")
except AttributeError:
# Deployment objects don't have realms
pass
return profile
# Use this for webhook views that don't get an email passed in.
def api_key_only_webhook_view(view_func):
@csrf_exempt
@has_request_variables
@wraps(view_func)
def _wrapped_view_func(request, api_key=REQ,
*args, **kwargs):
try:
user_profile = UserProfile.objects.get(api_key=api_key, is_active=True)
except UserProfile.DoesNotExist:
raise JsonableError("Invalid API key")
request.user = user_profile
request._email = user_profile.email
process_client(request, user_profile)
rate_limit_user(request, user_profile, domain='all')
return view_func(request, user_profile, *args, **kwargs)
return _wrapped_view_func
def zulip_internal(view_func):
@login_required(login_url = settings.HOME_NOT_LOGGED_IN)
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
request._query = view_func.__name__
if request.user.realm.domain != 'zulip.com':
return HttpResponseRedirect(settings.HOME_NOT_LOGGED_IN)
request._email = request.user.email
process_client(request, request.user)
return view_func(request, *args, **kwargs)
return _wrapped_view_func
# authenticated_api_view will add the authenticated user's
# user_profile to the view function's arguments list, since we have to
# look it up anyway. It is deprecated in favor on the REST API
# versions.
def authenticated_api_view(view_func):
@csrf_exempt
@require_post
@has_request_variables
@wraps(view_func)
def _wrapped_view_func(request, email=REQ, api_key=REQ('api_key', default=None),
api_key_legacy=REQ('api-key', default=None),
*args, **kwargs):
if not api_key and not api_key_legacy:
raise RequestVariableMissingError("api_key")
elif not api_key:
api_key = api_key_legacy
user_profile = validate_api_key(email, api_key)
request.user = user_profile
request._email = user_profile.email
process_client(request, user_profile)
# Apply rate limiting
limited_func = rate_limit()(view_func)
return limited_func(request, user_profile, *args, **kwargs)
return _wrapped_view_func
# A more REST-y authentication decorator, using, in particular, HTTP Basic
# authentication.
def authenticated_rest_api_view(view_func):
@csrf_exempt
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
# First try block attempts to get the credentials we need to do authentication
try:
# Grab the base64-encoded authentication string, decode it, and split it into
# the email and API key
auth_type, encoded_value = request.META['HTTP_AUTHORIZATION'].split()
# case insensitive per RFC 1945
if auth_type.lower() != "basic":
return json_error("Only Basic authentication is supported.")
role, api_key = base64.b64decode(encoded_value).split(":")
except ValueError:
return json_error("Invalid authorization header for basic auth")
except KeyError:
return json_unauthorized("Missing authorization header for basic auth")
# Now we try to do authentication or die
try:
# Could be a UserProfile or a Deployment
profile = validate_api_key(role, api_key)
except JsonableError, e:
return json_unauthorized(e.error)
request.user = profile
process_client(request, profile)
if isinstance(profile, UserProfile):
request._email = profile.email
else:
request._email = "deployment:" + role
profile.rate_limits = ""
# Apply rate limiting
return rate_limit()(view_func)(request, profile, *args, **kwargs)
return _wrapped_view_func
def process_as_post(view_func):
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
# Adapted from django/http/__init__.py.
# So by default Django doesn't populate request.POST for anything besides
# POST requests. We want this dict populated for PATCH/PUT, so we have to
# do it ourselves.
#
# This will not be required in the future, a bug will be filed against
# Django upstream.
if not request.POST:
# Only take action if POST is empty.
if request.META.get('CONTENT_TYPE', '').startswith('multipart'):
# Note that request._files is just the private attribute that backs the
# FILES property, so we are essentially setting request.FILES here. (In
# Django 1.5 FILES was still a read-only property.)
request.POST, request._files = MultiPartParser(request.META, StringIO(request.body),
request.upload_handlers, request.encoding).parse()
else:
request.POST = QueryDict(request.body, encoding=request.encoding)
return view_func(request, *args, **kwargs)
return _wrapped_view_func
def authenticate_log_and_execute_json(request, view_func, *args, **kwargs):
if not request.user.is_authenticated():
return json_error("Not logged in", status=401)
user_profile = request.user
process_client(request, user_profile, True)
request._email = user_profile.email
return view_func(request, user_profile, *args, **kwargs)
# Checks if the request is a POST request and that the user is logged
# in. If not, return an error (the @login_required behavior of
# redirecting to a login page doesn't make sense for json views)
def authenticated_json_post_view(view_func):
@require_post
@has_request_variables
@wraps(view_func)
def _wrapped_view_func(request,
*args, **kwargs):
return authenticate_log_and_execute_json(request, view_func, *args, **kwargs)
return _wrapped_view_func
def authenticated_json_view(view_func):
@wraps(view_func)
def _wrapped_view_func(request,
*args, **kwargs):
return authenticate_log_and_execute_json(request, view_func, *args, **kwargs)
return _wrapped_view_func
# These views are used by the main Django server to notify the Tornado server
# of events. We protect them from the outside world by checking a shared
# secret, and also the originating IP (for now).
def authenticate_notify(request):
return (request.META['REMOTE_ADDR'] in ('127.0.0.1', '::1')
and request.POST.get('secret') == settings.SHARED_SECRET)
def internal_notify_view(view_func):
@csrf_exempt
@require_post
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
if not authenticate_notify(request):
return json_error('Access denied', status=403)
if not hasattr(request, '_tornado_handler'):
# We got called through the non-Tornado server somehow.
# This is not a security check; it's an internal assertion
# to help us find bugs.
raise RuntimeError, 'notify view called with no Tornado handler'
request._email = "internal"
return view_func(request, *args, **kwargs)
return _wrapped_view_func
class JsonableError(Exception):
def __init__(self, error):
self.error = error
def __str__(self):
return self.to_json_error_msg()
def to_json_error_msg(self):
return self.error
class RequestVariableMissingError(JsonableError):
def __init__(self, var_name):
self.var_name = var_name
def to_json_error_msg(self):
return "Missing '%s' argument" % (self.var_name,)
class RequestVariableConversionError(JsonableError):
def __init__(self, var_name, bad_value):
self.var_name = var_name
self.bad_value = bad_value
def to_json_error_msg(self):
return "Bad value for '%s': %s" % (self.var_name, self.bad_value)
# Used in conjunction with @has_request_variables, below
class REQ(object):
# NotSpecified is a sentinel value for determining whether a
# default value was specified for a request variable. We can't
# use None because that could be a valid, user-specified default
class _NotSpecified(object):
pass
NotSpecified = _NotSpecified()
def __init__(self, whence=None, converter=None, default=NotSpecified, validator=None):
"""
whence: the name of the request variable that should be used
for this parameter. Defaults to a request variable of the
same name as the parameter.
converter: a function that takes a string and returns a new
value. If specified, this will be called on the request
variable value before passing to the function
default: a value to be used for the argument if the parameter
is missing in the request
validator: similar to converter, but takes an already parsed JSON
data structure. If specified, we will parse the JSON request
variable value before passing to the function
"""
self.post_var_name = whence
self.func_var_name = None
self.converter = converter
self.validator = validator
self.default = default
if converter and validator:
raise Exception('converter and validator are mutually exclusive')
# Extracts variables from the request object and passes them as
# named function arguments. The request object must be the first
# argument to the function.
#
# To use, assign a function parameter a default value that is an
# instance of the REQ class. That paramter will then be automatically
# populated from the HTTP request. The request object must be the
# first argument to the decorated function.
#
# This should generally be the innermost (syntactically bottommost)
# decorator applied to a view, since other decorators won't preserve
# the default parameter values used by has_request_variables.
#
# Note that this can't be used in helper functions which are not
# expected to call json_error or json_success, as it uses json_error
# internally when it encounters an error
def has_request_variables(view_func):
num_params = view_func.func_code.co_argcount
if view_func.func_defaults is None:
num_default_params = 0
else:
num_default_params = len(view_func.func_defaults)
default_param_names = view_func.func_code.co_varnames[num_params - num_default_params:]
default_param_values = view_func.func_defaults
if default_param_values is None:
default_param_values = []
post_params = []
for (name, value) in zip(default_param_names, default_param_values):
if isinstance(value, REQ):
value.func_var_name = name
if value.post_var_name is None:
value.post_var_name = name
post_params.append(value)
elif value == REQ:
# If the function definition does not actually instantiate
# a REQ object but instead uses the REQ class itself as a
# value, we instantiate it as a convenience
post_var = value(name)
post_var.func_var_name = name
post_params.append(post_var)
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
for param in post_params:
if param.func_var_name in kwargs:
continue
default_assigned = False
try:
val = request.REQUEST[param.post_var_name]
except KeyError:
if param.default is REQ.NotSpecified:
raise RequestVariableMissingError(param.post_var_name)
val = param.default
default_assigned = True
if param.converter is not None and not default_assigned:
try:
val = param.converter(val)
except JsonableError:
raise
except:
raise RequestVariableConversionError(param.post_var_name, val)
# Validators are like converters, but they don't handle JSON parsing; we do.
if param.validator is not None and not default_assigned:
try:
val = ujson.loads(val)
except:
raise JsonableError('argument "%s" is not valid json.' % (param.post_var_name,))
error = param.validator(param.post_var_name, val)
if error:
raise JsonableError(error)
kwargs[param.func_var_name] = val
return view_func(request, *args, **kwargs)
return _wrapped_view_func
# Converter functions for use with has_request_variables
def to_non_negative_int(x):
x = int(x)
if x < 0:
raise ValueError("argument is negative")
return x
def to_non_negative_float(x):
x = float(x)
if x < 0:
raise ValueError("argument is negative")
return x
def flexible_boolean(boolean):
"""Returns True for any of "1", "true", or "True". Returns False otherwise."""
if boolean in ("1", "true", "True"):
return True
else:
return False
def statsd_increment(counter, val=1):
"""Increments a statsd counter on completion of the
decorated function.
Pass the name of the counter to this decorator-returning function."""
def wrapper(func):
@wraps(func)
def wrapped_func(*args, **kwargs):
ret = func(*args, **kwargs)
statsd.incr(counter, val)
return ret
return wrapped_func
return wrapper
def rate_limit_user(request, user, domain):
"""Returns whether or not a user was rate limited. Will raise a RateLimited exception
if the user has been rate limited, otherwise returns and modifies request to contain
the rate limit information"""
ratelimited, time = is_ratelimited(user, domain)
request._ratelimit_applied_limits = True
request._ratelimit_secs_to_freedom = time
request._ratelimit_over_limit = ratelimited
# Abort this request if the user is over her rate limits
if ratelimited:
statsd.incr("ratelimiter.limited.%s.%s" % (type(user), user.id))
raise RateLimited()
incr_ratelimit(user, domain)
calls_remaining, time_reset = api_calls_left(user, domain)
request._ratelimit_remaining = calls_remaining
request._ratelimit_secs_to_freedom = time_reset
def rate_limit(domain='all'):
"""Rate-limits a view. Takes an optional 'domain' param if you wish to rate limit different
types of API calls independently.
Returns a decorator"""
def wrapper(func):
@wraps(func)
def wrapped_func(request, *args, **kwargs):
# Don't rate limit requests from Django that come from our own servers,
# and don't rate-limit dev instances
no_limits = False
if request.client and request.client.name.lower() == 'internal' and \
(request.META['REMOTE_ADDR'] in ['::1', '127.0.0.1'] or settings.DEBUG):
no_limits = True
if no_limits:
return func(request, *args, **kwargs)
try:
user = request.user
except:
user = None
# Rate-limiting data is stored in redis
# We also only support rate-limiting authenticated
# views right now.
# TODO(leo) - implement per-IP non-authed rate limiting
if not settings.RATE_LIMITING or not user:
if not user:
logging.error("Requested rate-limiting on %s but user is not authenticated!" % \
func.__name__)
return func(request, *args, **kwargs)
rate_limit_user(request, user, domain)
return func(request, *args, **kwargs)
return wrapped_func
return wrapper
def profiled(func):
"""
This decorator should obviously be used only in a dev environment.
It works best when surrounding a function that you expect to be
called once. One strategy is to write a test case in zerver/tests.py
and wrap the test case with the profiled decorator.
You can run a single test case like this:
# edit zerver/tests.py and place @profiled above the test case below
./tools/test-backend zerver.RateLimitTests.test_ratelimit_decrease
Then view the results like this:
./tools/show-profile-results.py test_ratelimit_decrease.profile
"""
@wraps(func)
def wrapped_func(*args, **kwargs):
fn = func.__name__ + ".profile"
prof = cProfile.Profile()
retval = prof.runcall(func, *args, **kwargs)
prof.dump_stats(fn)
return retval
return wrapped_func
def uses_mandrill(func):
"""
This decorator takes a function with keyword argument "mail_client" and
fills it in with the mail_client for the Mandrill account.
"""
@wraps(func)
def wrapped_func(*args, **kwargs):
kwargs['mail_client'] = get_mandrill_client()
return func(*args, **kwargs)
return wrapped_func
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
25254,
199,
504,
1639,
14,
1014,
492,
8133,
2141,
12,
6183,
29967,
199,
504,
1639,
14,
1014,
14,
10123,
2087,
492,
6879,
8416,
2842,
199,
504,
19959,
14,
992,
492,
19037,
12,
664,
63,
1258,
12,
664,
63,
751,
63,
2913,
63,
991,
63,
2123,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
705,
12,
2022,
63,
324,
11497,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
399,
1001,
199,
504,
5228,
492,
5228,
199,
504,
19959,
14,
773,
14,
1825,
492,
4126,
63,
1001,
63,
4763,
199,
504,
19959,
14,
773,
14,
3954,
492,
2197,
63,
475,
63,
3954,
199,
504,
19959,
14,
773,
14,
1208,
492,
5020,
68,
199,
504,
19959,
14,
3924,
492,
26311,
7219,
5703,
199,
504,
19959,
14,
773,
14,
1866,
63,
7919,
492,
315,
1556,
63,
1866,
3097,
12,
365,
63,
1866,
14136,
12,
971,
1362,
2986,
63,
5352,
63,
3039,
199,
199,
504,
9143,
492,
14018,
199,
646,
1300,
772,
199,
646,
2050,
199,
646,
286,
5736,
199,
504,
19959,
14,
773,
14,
10333,
322,
914,
63,
1258,
492,
664,
63,
10333,
322,
914,
63,
1258,
199,
199,
692,
2202,
14,
58,
1293,
1772,
63,
11265,
26,
272,
687,
1315,
441,
78,
2247,
14,
992,
492,
664,
63,
13605,
63,
991,
63,
2261,
12,
21588,
7775,
199,
2836,
26,
272,
687,
1683,
492,
4420,
272,
664,
63,
13605,
63,
991,
63,
2261,
275,
4420,
342,
272,
21588,
7775,
275,
4420,
342,
199,
199,
318,
664,
63,
13605,
63,
269,
63,
25784,
8,
3756,
304,
272,
372,
664,
63,
751,
63,
2913,
63,
991,
63,
2123,
8,
3756,
9,
340,
9244,
2,
315,
4719,
587,
664,
63,
13605,
63,
991,
63,
2261,
8,
3756,
9,
199,
199,
533,
485,
1322,
31717,
2822,
9865,
590,
8,
785,
304,
272,
986,
199,
199,
3,
1432,
3591,
31717,
2822,
9865,
590,
687,
376,
768,
305,
9865,
2455,
340,
314,
199,
3,
1177,
911,
506,
2741,
2945,
701,
6358,
3016,
14,
14548,
63,
8192,
1062,
199,
3,
503,
965,
2575,
2757,
2741,
642,
4340,
14,
2136,
675,
642,
367,
1846,
17154,
199,
3,
818,
14,
199,
1322,
31717,
2822,
9865,
590,
275,
485,
1322,
31717,
2822,
9865,
590,
342,
199,
199,
318,
15608,
8,
765,
304,
272,
768,
13582,
8,
765,
9,
272,
347,
4975,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1083,
8,
1069,
12,
3016,
29,
1069,
423,
18443,
63,
2232,
12,
627,
589,
12,
1011,
958,
9,
272,
340,
2519,
8,
765,
12,
283,
10088,
63,
25254,
297,
756,
304,
267,
4975,
14,
10088,
63,
25254,
275,
715,
272,
372,
4975,
199,
199,
318,
1678,
63,
751,
63,
8240,
8,
1069,
12,
922,
63,
2913,
304,
272,
327,
1678,
63,
2682,
63,
1205,
2597,
6675,
397,
370,
29773,
29490,
12,
436,
652,
12237,
272,
327,
22649,
370,
943,
626,
2348,
465,
5521,
14,
272,
340,
1056,
14,
10614,
905,
3243,
63,
4531,
937,
508,
1994,
1001,
15,
873,
63,
2682,
63,
1205,
356,
267,
372,
339,
340,
2688,
8,
1069,
12,
2513,
1131,
735,
267,
1827,
275,
1056,
423,
1131,
272,
587,
26,
267,
1827,
275,
1056,
14,
10614,
459,
3243,
63,
4531,
418,
339,
1566,
3713,
1131,
356,
1827,
12,
1779,
283,
751,
63,
2913,
63,
344,
356,
922,
63,
2913,
14,
344,
12,
1779,
283,
521,
356,
2197,
63,
475,
63,
3954,
8,
2131,
4000,
1779,
283,
1258,
356,
1056,
14,
1258,
14,
354,
93,
272,
4126,
63,
1001,
63,
4763,
480,
751,
63,
8240,
401,
1566,
12,
2400,
1566,
26,
488,
9,
199,
199,
3,
21311,
641,
1639,
14,
4196,
14,
11582,
14,
1014,
14,
4365,
63,
1014,
63,
2474,
199,
318,
4409,
63,
1932,
8,
1532,
304,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
334,
1069,
14,
765,
1137,
298,
4030,
2,
288,
436,
440,
334,
1069,
14,
765,
508,
298,
17462,
2,
2151,
436,
1056,
14,
10614,
459,
14548,
14,
29809,
972,
63,
765,
418,
508,
298,
4030,
14150,
288,
340,
1056,
14,
765,
508,
298,
17462,
582,
355,
2329,
63,
765,
275,
298,
17462,
3149,
83,
2,
450,
334,
1069,
14,
10614,
459,
14548,
14,
29809,
972,
63,
765,
995,
9,
288,
587,
26,
355,
2329,
63,
765,
275,
1056,
14,
765,
288,
2050,
14,
3764,
360,
3767,
2832,
27301,
4366,
83,
304,
450,
83,
297,
2329,
63,
765,
12,
1056,
14,
515,
12,
1169,
2402,
3713,
1205,
63,
600,
356,
25766,
12,
283,
1069,
356,
1056,
1552,
288,
372,
6183,
29967,
5234,
4030,
3135,
267,
372,
2562,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
4409,
63,
7728,
63,
2113,
8,
1532,
304,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
8,
1069,
12,
922,
63,
2913,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
2913,
14,
1989,
63,
8220,
360,
2113,
1429,
297,
922,
63,
2913,
14,
7728,
304,
288,
746,
14587,
461,
547,
480,
13757,
506,
282,
10482,
31056,
531,
267,
372,
2562,
8,
1069,
12,
922,
63,
2913,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
504,
19959,
14,
773,
14,
751,
63,
4054,
492,
2198,
63,
751,
63,
4054,
199,
199,
318,
664,
63,
1258,
63,
354,
8,
1069,
12,
365,
63,
1001,
63,
1345,
304,
272,
327,
982,
314,
3261,
1056,
2013,
282,
1890,
315,
314,
1056,
1564,
12,
272,
327,
626,
965,
7464,
14,
221,
6630,
12,
5536,
314,
1890,
687,
314,
272,
327,
2876,
13,
7788,
14,
272,
340,
283,
1258,
7,
315,
1056,
14,
6780,
26,
267,
372,
1056,
14,
6780,
459,
1258,
418,
272,
916,
298,
2856,
63,
3791,
63,
14565,
2,
315,
1056,
14,
10614,
26,
267,
922,
63,
4054,
275,
2198,
63,
751,
63,
4054,
8,
1069,
14,
10614,
905,
2856,
63,
3791,
63,
14565
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
25254,
199,
504,
1639,
14,
1014,
492,
8133,
2141,
12,
6183,
29967,
199,
504,
1639,
14,
1014,
14,
10123,
2087,
492,
6879,
8416,
2842,
199,
504,
19959,
14,
992,
492,
19037,
12,
664,
63,
1258,
12,
664,
63,
751,
63,
2913,
63,
991,
63,
2123,
199,
504,
19959,
14,
773,
14,
1310,
492,
2022,
63,
705,
12,
2022,
63,
324,
11497,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
399,
1001,
199,
504,
5228,
492,
5228,
199,
504,
19959,
14,
773,
14,
1825,
492,
4126,
63,
1001,
63,
4763,
199,
504,
19959,
14,
773,
14,
3954,
492,
2197,
63,
475,
63,
3954,
199,
504,
19959,
14,
773,
14,
1208,
492,
5020,
68,
199,
504,
19959,
14,
3924,
492,
26311,
7219,
5703,
199,
504,
19959,
14,
773,
14,
1866,
63,
7919,
492,
315,
1556,
63,
1866,
3097,
12,
365,
63,
1866,
14136,
12,
971,
1362,
2986,
63,
5352,
63,
3039,
199,
199,
504,
9143,
492,
14018,
199,
646,
1300,
772,
199,
646,
2050,
199,
646,
286,
5736,
199,
504,
19959,
14,
773,
14,
10333,
322,
914,
63,
1258,
492,
664,
63,
10333,
322,
914,
63,
1258,
199,
199,
692,
2202,
14,
58,
1293,
1772,
63,
11265,
26,
272,
687,
1315,
441,
78,
2247,
14,
992,
492,
664,
63,
13605,
63,
991,
63,
2261,
12,
21588,
7775,
199,
2836,
26,
272,
687,
1683,
492,
4420,
272,
664,
63,
13605,
63,
991,
63,
2261,
275,
4420,
342,
272,
21588,
7775,
275,
4420,
342,
199,
199,
318,
664,
63,
13605,
63,
269,
63,
25784,
8,
3756,
304,
272,
372,
664,
63,
751,
63,
2913,
63,
991,
63,
2123,
8,
3756,
9,
340,
9244,
2,
315,
4719,
587,
664,
63,
13605,
63,
991,
63,
2261,
8,
3756,
9,
199,
199,
533,
485,
1322,
31717,
2822,
9865,
590,
8,
785,
304,
272,
986,
199,
199,
3,
1432,
3591,
31717,
2822,
9865,
590,
687,
376,
768,
305,
9865,
2455,
340,
314,
199,
3,
1177,
911,
506,
2741,
2945,
701,
6358,
3016,
14,
14548,
63,
8192,
1062,
199,
3,
503,
965,
2575,
2757,
2741,
642,
4340,
14,
2136,
675,
642,
367,
1846,
17154,
199,
3,
818,
14,
199,
1322,
31717,
2822,
9865,
590,
275,
485,
1322,
31717,
2822,
9865,
590,
342,
199,
199,
318,
15608,
8,
765,
304,
272,
768,
13582,
8,
765,
9,
272,
347,
4975,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1083,
8,
1069,
12,
3016,
29,
1069,
423,
18443,
63,
2232,
12,
627,
589,
12,
1011,
958,
9,
272,
340,
2519,
8,
765,
12,
283,
10088,
63,
25254,
297,
756,
304,
267,
4975,
14,
10088,
63,
25254,
275,
715,
272,
372,
4975,
199,
199,
318,
1678,
63,
751,
63,
8240,
8,
1069,
12,
922,
63,
2913,
304,
272,
327,
1678,
63,
2682,
63,
1205,
2597,
6675,
397,
370,
29773,
29490,
12,
436,
652,
12237,
272,
327,
22649,
370,
943,
626,
2348,
465,
5521,
14,
272,
340,
1056,
14,
10614,
905,
3243,
63,
4531,
937,
508,
1994,
1001,
15,
873,
63,
2682,
63,
1205,
356,
267,
372,
339,
340,
2688,
8,
1069,
12,
2513,
1131,
735,
267,
1827,
275,
1056,
423,
1131,
272,
587,
26,
267,
1827,
275,
1056,
14,
10614,
459,
3243,
63,
4531,
418,
339,
1566,
3713,
1131,
356,
1827,
12,
1779,
283,
751,
63,
2913,
63,
344,
356,
922,
63,
2913,
14,
344,
12,
1779,
283,
521,
356,
2197,
63,
475,
63,
3954,
8,
2131,
4000,
1779,
283,
1258,
356,
1056,
14,
1258,
14,
354,
93,
272,
4126,
63,
1001,
63,
4763,
480,
751,
63,
8240,
401,
1566,
12,
2400,
1566,
26,
488,
9,
199,
199,
3,
21311,
641,
1639,
14,
4196,
14,
11582,
14,
1014,
14,
4365,
63,
1014,
63,
2474,
199,
318,
4409,
63,
1932,
8,
1532,
304,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
334,
1069,
14,
765,
1137,
298,
4030,
2,
288,
436,
440,
334,
1069,
14,
765,
508,
298,
17462,
2,
2151,
436,
1056,
14,
10614,
459,
14548,
14,
29809,
972,
63,
765,
418,
508,
298,
4030,
14150,
288,
340,
1056,
14,
765,
508,
298,
17462,
582,
355,
2329,
63,
765,
275,
298,
17462,
3149,
83,
2,
450,
334,
1069,
14,
10614,
459,
14548,
14,
29809,
972,
63,
765,
995,
9,
288,
587,
26,
355,
2329,
63,
765,
275,
1056,
14,
765,
288,
2050,
14,
3764,
360,
3767,
2832,
27301,
4366,
83,
304,
450,
83,
297,
2329,
63,
765,
12,
1056,
14,
515,
12,
1169,
2402,
3713,
1205,
63,
600,
356,
25766,
12,
283,
1069,
356,
1056,
1552,
288,
372,
6183,
29967,
5234,
4030,
3135,
267,
372,
2562,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
4409,
63,
7728,
63,
2113,
8,
1532,
304,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
8,
1069,
12,
922,
63,
2913,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
2913,
14,
1989,
63,
8220,
360,
2113,
1429,
297,
922,
63,
2913,
14,
7728,
304,
288,
746,
14587,
461,
547,
480,
13757,
506,
282,
10482,
31056,
531,
267,
372,
2562,
8,
1069,
12,
922,
63,
2913,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
504,
19959,
14,
773,
14,
751,
63,
4054,
492,
2198,
63,
751,
63,
4054,
199,
199,
318,
664,
63,
1258,
63,
354,
8,
1069,
12,
365,
63,
1001,
63,
1345,
304,
272,
327,
982,
314,
3261,
1056,
2013,
282,
1890,
315,
314,
1056,
1564,
12,
272,
327,
626,
965,
7464,
14,
221,
6630,
12,
5536,
314,
1890,
687,
314,
272,
327,
2876,
13,
7788,
14,
272,
340,
283,
1258,
7,
315,
1056,
14,
6780,
26,
267,
372,
1056,
14,
6780,
459,
1258,
418,
272,
916,
298,
2856,
63,
3791,
63,
14565,
2,
315,
1056,
14,
10614,
26,
267,
922,
63,
4054,
275,
2198,
63,
751,
63,
4054,
8,
1069,
14,
10614,
905,
2856,
63,
3791,
63,
14565,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dgvncsz0f/pingpong
|
tests/transport/test_system.py
|
1
|
2079
|
# -*- coding: utf-8 -*-
# Copyright (c) 2011, Diego Souza
# 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 <ORGANIZATION> nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import mock
import unittest
from pingpong.transport import system
from tests import helper as h
class test_sys_transport(unittest.TestCase):
def test_write_uses_sys_stdout(self):
with h.mock_value(sys, "stdout") as mymock:
t = system.sys_transport()
t.write("foobar")
mymock[0].write.assert_called_with("foobar")
def test_terminate_raise_EOFError(self):
t = system.sys_transport()
self.assertRaises(EOFError, t.terminate)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7760,
12,
577,
1873,
1939,
428,
810,
8076,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
258,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
257,
627,
11443,
314,
536,
402,
314,
665,
25797,
879,
22800,
30,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
258,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
258,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
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,
421,
199,
646,
984,
199,
646,
1683,
199,
646,
2882,
199,
504,
18249,
26992,
14,
5545,
492,
2656,
199,
504,
2295,
492,
5922,
465,
394,
199,
199,
533,
511,
63,
1274,
63,
5545,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
952,
63,
5589,
63,
1274,
63,
2703,
8,
277,
304,
267,
543,
394,
14,
1805,
63,
585,
8,
1274,
12,
298,
2703,
531,
465,
3002,
1805,
26,
288,
307,
275,
2656,
14,
1274,
63,
5545,
342,
288,
307,
14,
952,
480,
9664,
531,
288,
3002,
1805,
59,
16,
1055,
952,
14,
479,
63,
3527,
63,
1045,
480,
9664,
531,
339,
347,
511,
63,
14478,
63,
3730,
63,
13178,
547,
8,
277,
304,
267,
307,
275,
2656,
14,
1274,
63,
5545,
342,
267,
291,
14,
1855,
8,
13178,
547,
12,
307,
14,
14478,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7760,
12,
577,
1873,
1939,
428,
810,
8076,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
258,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
257,
627,
11443,
314,
536,
402,
314,
665,
25797,
879,
22800,
30,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
258,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
258,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
199,
3,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
199,
3,
1549,
7056,
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,
421,
199,
646,
984,
199,
646,
1683,
199,
646,
2882,
199,
504,
18249,
26992,
14,
5545,
492,
2656,
199,
504,
2295,
492,
5922,
465,
394,
199,
199,
533,
511,
63,
1274,
63,
5545,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
952,
63,
5589,
63,
1274,
63,
2703,
8,
277,
304,
267,
543,
394,
14,
1805,
63,
585,
8,
1274,
12,
298,
2703,
531,
465,
3002,
1805,
26,
288,
307,
275,
2656,
14,
1274,
63,
5545,
342,
288,
307,
14,
952,
480,
9664,
531,
288,
3002,
1805,
59,
16,
1055,
952,
14,
479,
63,
3527,
63,
1045,
480,
9664,
531,
339,
347,
511,
63,
14478,
63,
3730,
63,
13178,
547,
8,
277,
304,
267,
307,
275,
2656,
14,
1274,
63,
5545,
342,
267,
291,
14,
1855,
8,
13178,
547,
12,
307,
14,
14478,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
oseemann/cvsreview
|
app/vclib/compat.py
|
2
|
4707
|
# -*-python-*-
#
# Copyright (C) 1999-2006 The ViewCVS Group. All Rights Reserved.
#
# By using this file, you agree to the terms and conditions set forth in
# the LICENSE.html file which can be found at the top level of the ViewVC
# distribution or at http://viewvc.org/license-1.html.
#
# For more information, visit http://viewvc.org/
#
# -----------------------------------------------------------------------
#
# compat.py: compatibility functions for operation across Python 1.5.x to 2.2.x
#
# -----------------------------------------------------------------------
import urllib
import string
import time
import calendar
import re
import os
import rfc822
import tempfile
import errno
#
# urllib.urlencode() is new to Python 1.5.2
#
try:
urlencode = urllib.urlencode
except AttributeError:
def urlencode(dict):
"Encode a dictionary as application/x-url-form-encoded."
if not dict:
return ''
quote = urllib.quote_plus
keyvalue = [ ]
for key, value in dict.items():
keyvalue.append(quote(key) + '=' + quote(str(value)))
return string.join(keyvalue, '&')
#
# time.strptime() is new to Python 1.5.2
#
if hasattr(time, 'strptime'):
def cvs_strptime(timestr):
'Parse a CVS-style date/time value.'
return time.strptime(timestr, '%Y/%m/%d %H:%M:%S')[:-1] + (0,)
else:
_re_rev_date = re.compile('([0-9]{4})/([0-9][0-9])/([0-9][0-9]) '
'([0-9][0-9]):([0-9][0-9]):([0-9][0-9])')
def cvs_strptime(timestr):
'Parse a CVS-style date/time value.'
match = _re_rev_date.match(timestr)
if match:
return tuple(map(int, match.groups())) + (0, 1, 0)
else:
raise ValueError('date is not in cvs format')
#
# os.makedirs() is new to Python 1.5.2
#
try:
makedirs = os.makedirs
except AttributeError:
def makedirs(path, mode=0777):
head, tail = os.path.split(path)
if head and tail and not os.path.exists(head):
makedirs(head, mode)
os.mkdir(path, mode)
#
# rfc822.formatdate() is new to Python 1.6
#
try:
formatdate = rfc822.formatdate
except AttributeError:
def formatdate(timeval):
if timeval is None:
timeval = time.time()
timeval = time.gmtime(timeval)
return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][timeval[6]],
timeval[2],
["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][timeval[1]-1],
timeval[0], timeval[3], timeval[4], timeval[5])
#
# calendar.timegm() is new to Python 2.x and
# calendar.leapdays() was wrong in Python 1.5.2
#
try:
timegm = calendar.timegm
except AttributeError:
def leapdays(year1, year2):
"""Return number of leap years in range [year1, year2).
Assume year1 <= year2."""
year1 = year1 - 1
year2 = year2 - 1
return (year2/4 - year1/4) - (year2/100 -
year1/100) + (year2/400 - year1/400)
EPOCH = 1970
def timegm(tuple):
"""Unrelated but handy function to calculate Unix timestamp from GMT."""
year, month, day, hour, minute, second = tuple[:6]
# assert year >= EPOCH
# assert 1 <= month <= 12
days = 365*(year-EPOCH) + leapdays(EPOCH, year)
for i in range(1, month):
days = days + calendar.mdays[i]
if month > 2 and calendar.isleap(year):
days = days + 1
days = days + day - 1
hours = days*24 + hour
minutes = hours*60 + minute
seconds = minutes*60 + second
return seconds
#
# tempfile.mkdtemp() is new to Python 2.3
#
try:
mkdtemp = tempfile.mkdtemp
except AttributeError:
def mkdtemp():
for i in range(10):
dir = tempfile.mktemp()
try:
os.mkdir(dir, 0700)
return dir
except OSError, e:
if e.errno == errno.EEXIST:
continue # try again
raise
raise IOError, (errno.EEXIST, "No usable temporary directory name found")
#
# the following stuff is *ONLY* needed for standalone.py.
# For that reason I've encapsulated it into a function.
#
def for_standalone():
import SocketServer
if not hasattr(SocketServer.TCPServer, "close_request"):
#
# method close_request() was missing until Python 2.1
#
class TCPServer(SocketServer.TCPServer):
def process_request(self, request, client_address):
"""Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
"""
self.finish_request(request, client_address)
self.close_request(request)
def close_request(self, request):
"""Called to clean up an individual request."""
request.close()
SocketServer.TCPServer = TCPServer
|
gpl-3.0
|
[
3,
1882,
1548,
13,
1837,
199,
3,
199,
3,
1898,
334,
35,
9,
21300,
13,
7968,
710,
10935,
35,
7428,
5611,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
4885,
1808,
642,
570,
12,
1265,
10601,
370,
314,
2895,
436,
3704,
663,
367,
273,
315,
199,
3,
314,
5113,
14,
1360,
570,
1314,
883,
506,
1911,
737,
314,
2746,
2166,
402,
314,
10935,
9454,
199,
3,
4084,
503,
737,
1455,
921,
1345,
6737,
14,
1308,
15,
1682,
13,
17,
14,
1360,
14,
199,
3,
199,
3,
2104,
1655,
2556,
12,
5684,
1455,
921,
1345,
6737,
14,
1308,
15,
199,
3,
199,
3,
5620,
12797,
199,
3,
199,
3,
8434,
14,
647,
26,
7163,
3423,
367,
3439,
9371,
2018,
413,
14,
21,
14,
88,
370,
499,
14,
18,
14,
88,
199,
3,
199,
3,
5620,
12797,
199,
199,
646,
4011,
199,
646,
1059,
199,
646,
900,
199,
646,
11234,
199,
646,
295,
199,
646,
747,
199,
646,
18158,
10228,
199,
646,
5549,
199,
646,
7554,
199,
199,
3,
199,
3,
4011,
14,
10738,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
16511,
275,
4011,
14,
10738,
199,
2590,
4281,
26,
523,
347,
16511,
8,
807,
304,
272,
298,
9686,
282,
2600,
465,
4223,
15,
88,
13,
633,
13,
964,
13,
8167,
2122,
272,
340,
440,
1211,
26,
489,
372,
2125,
272,
6313,
275,
4011,
14,
3513,
63,
6666,
272,
790,
585,
275,
359,
1622,
272,
367,
790,
12,
574,
315,
1211,
14,
1744,
837,
489,
790,
585,
14,
740,
8,
3513,
8,
498,
9,
435,
14051,
435,
6313,
8,
495,
8,
585,
1724,
272,
372,
1059,
14,
904,
8,
498,
585,
12,
7673,
358,
199,
199,
3,
199,
3,
900,
14,
9866,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
692,
2688,
8,
521,
12,
283,
9866,
735,
523,
347,
286,
3122,
63,
9866,
8,
521,
495,
304,
272,
283,
4003,
282,
445,
7428,
13,
2487,
1434,
15,
521,
574,
3530,
272,
372,
900,
14,
9866,
8,
521,
495,
12,
1543,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
358,
4439,
17,
61,
435,
334,
16,
4258,
199,
2836,
26,
523,
485,
264,
63,
4964,
63,
602,
275,
295,
14,
2014,
360,
779,
16,
13,
25,
8194,
20,
1552,
15,
779,
16,
13,
25,
1527,
16,
13,
25,
23067,
779,
16,
13,
25,
1527,
16,
13,
25,
566,
283,
1169,
283,
779,
16,
13,
25,
1527,
16,
13,
25,
4682,
779,
16,
13,
25,
1527,
16,
13,
25,
4682,
779,
16,
13,
25,
1527,
16,
13,
25,
566,
358,
523,
347,
286,
3122,
63,
9866,
8,
521,
495,
304,
272,
283,
4003,
282,
445,
7428,
13,
2487,
1434,
15,
521,
574,
3530,
272,
1336,
275,
485,
264,
63,
4964,
63,
602,
14,
1431,
8,
521,
495,
9,
272,
340,
1336,
26,
489,
372,
2008,
8,
1130,
8,
442,
12,
1336,
14,
2634,
4059,
435,
334,
16,
12,
413,
12,
378,
9,
272,
587,
26,
489,
746,
1722,
360,
602,
365,
440,
315,
286,
3122,
1475,
358,
199,
199,
3,
199,
3,
747,
14,
8347,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
1852,
3220,
275,
747,
14,
8347,
199,
2590,
4281,
26,
523,
347,
1852,
3220,
8,
515,
12,
818,
29,
16,
11956,
304,
272,
4854,
12,
9483,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
272,
340,
4854,
436,
9483,
436,
440,
747,
14,
515,
14,
2444,
8,
2993,
304,
489,
1852,
3220,
8,
2993,
12,
818,
9,
272,
747,
14,
8215,
8,
515,
12,
818,
9,
199,
199,
3,
199,
3,
18158,
10228,
14,
908,
602,
342,
365,
892,
370,
2018,
413,
14,
22,
199,
3,
199,
893,
26,
523,
1475,
602,
275,
18158,
10228,
14,
908,
602,
199,
2590,
4281,
26,
523,
347,
1475,
602,
8,
521,
637,
304,
272,
340,
900,
637,
365,
488,
26,
489,
900,
637,
275,
900,
14,
521,
342,
272,
900,
637,
275,
900,
14,
22227,
8,
521,
637,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
83,
450,
966,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
334,
288,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
9210,
521,
637,
59,
22,
2365,
288,
900,
637,
59,
18,
467,
288,
2097,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1467,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
9210,
521,
637,
59,
17,
11285,
17,
467,
1816,
900,
637,
59,
16,
467,
900,
637,
59,
19,
467,
900,
637,
59,
20,
467,
900,
637,
59,
21,
566,
199,
199,
3,
221,
199,
3,
11234,
14,
521,
13844,
342,
365,
892,
370,
2018,
499,
14,
88,
436,
221,
199,
3,
11234,
14,
28764,
4899,
342,
1990,
6835,
315,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
900,
13844,
275,
11234,
14,
521,
13844,
221,
199,
2590,
4281,
26,
523,
347,
29487,
4899,
8,
3403,
17,
12,
5361,
18,
304,
272,
408,
1767,
1329,
402,
29487,
17399,
315,
1425,
359,
3403,
17,
12,
5361,
18,
680,
2126,
16269,
5361,
17,
2695,
5361,
18,
1041,
272,
5361,
17,
275,
5361,
17,
446,
413,
272,
5361,
18,
275,
5361,
18,
446,
413,
272,
372,
334,
3403,
18,
15,
20,
446,
5361,
17,
15,
20,
9,
446,
334,
3403,
18,
15,
1960,
446,
221,
3303,
5361,
17,
15,
1960,
9,
435,
334,
3403,
18,
15,
5303,
446,
5361,
17,
15,
5303,
9,
819,
662,
1512,
1244,
275,
413,
20598,
523,
347,
900,
13844,
8,
2960,
304,
272,
408,
1358,
2407,
1325,
4926,
89,
805,
370,
8671,
13074,
4913,
687,
19152,
1041,
272,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
275,
2008,
1491,
22,
61,
272,
327,
702,
5361,
2356,
662,
1512,
1244,
272,
327,
702,
413,
2695,
5794,
2695,
3144,
272,
7609,
275,
28046,
5830,
3403,
13,
37,
1512,
1244,
9,
435,
29487
] |
[
1882,
1548,
13,
1837,
199,
3,
199,
3,
1898,
334,
35,
9,
21300,
13,
7968,
710,
10935,
35,
7428,
5611,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
4885,
1808,
642,
570,
12,
1265,
10601,
370,
314,
2895,
436,
3704,
663,
367,
273,
315,
199,
3,
314,
5113,
14,
1360,
570,
1314,
883,
506,
1911,
737,
314,
2746,
2166,
402,
314,
10935,
9454,
199,
3,
4084,
503,
737,
1455,
921,
1345,
6737,
14,
1308,
15,
1682,
13,
17,
14,
1360,
14,
199,
3,
199,
3,
2104,
1655,
2556,
12,
5684,
1455,
921,
1345,
6737,
14,
1308,
15,
199,
3,
199,
3,
5620,
12797,
199,
3,
199,
3,
8434,
14,
647,
26,
7163,
3423,
367,
3439,
9371,
2018,
413,
14,
21,
14,
88,
370,
499,
14,
18,
14,
88,
199,
3,
199,
3,
5620,
12797,
199,
199,
646,
4011,
199,
646,
1059,
199,
646,
900,
199,
646,
11234,
199,
646,
295,
199,
646,
747,
199,
646,
18158,
10228,
199,
646,
5549,
199,
646,
7554,
199,
199,
3,
199,
3,
4011,
14,
10738,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
16511,
275,
4011,
14,
10738,
199,
2590,
4281,
26,
523,
347,
16511,
8,
807,
304,
272,
298,
9686,
282,
2600,
465,
4223,
15,
88,
13,
633,
13,
964,
13,
8167,
2122,
272,
340,
440,
1211,
26,
489,
372,
2125,
272,
6313,
275,
4011,
14,
3513,
63,
6666,
272,
790,
585,
275,
359,
1622,
272,
367,
790,
12,
574,
315,
1211,
14,
1744,
837,
489,
790,
585,
14,
740,
8,
3513,
8,
498,
9,
435,
14051,
435,
6313,
8,
495,
8,
585,
1724,
272,
372,
1059,
14,
904,
8,
498,
585,
12,
7673,
358,
199,
199,
3,
199,
3,
900,
14,
9866,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
692,
2688,
8,
521,
12,
283,
9866,
735,
523,
347,
286,
3122,
63,
9866,
8,
521,
495,
304,
272,
283,
4003,
282,
445,
7428,
13,
2487,
1434,
15,
521,
574,
3530,
272,
372,
900,
14,
9866,
8,
521,
495,
12,
1543,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
358,
4439,
17,
61,
435,
334,
16,
4258,
199,
2836,
26,
523,
485,
264,
63,
4964,
63,
602,
275,
295,
14,
2014,
360,
779,
16,
13,
25,
8194,
20,
1552,
15,
779,
16,
13,
25,
1527,
16,
13,
25,
23067,
779,
16,
13,
25,
1527,
16,
13,
25,
566,
283,
1169,
283,
779,
16,
13,
25,
1527,
16,
13,
25,
4682,
779,
16,
13,
25,
1527,
16,
13,
25,
4682,
779,
16,
13,
25,
1527,
16,
13,
25,
566,
358,
523,
347,
286,
3122,
63,
9866,
8,
521,
495,
304,
272,
283,
4003,
282,
445,
7428,
13,
2487,
1434,
15,
521,
574,
3530,
272,
1336,
275,
485,
264,
63,
4964,
63,
602,
14,
1431,
8,
521,
495,
9,
272,
340,
1336,
26,
489,
372,
2008,
8,
1130,
8,
442,
12,
1336,
14,
2634,
4059,
435,
334,
16,
12,
413,
12,
378,
9,
272,
587,
26,
489,
746,
1722,
360,
602,
365,
440,
315,
286,
3122,
1475,
358,
199,
199,
3,
199,
3,
747,
14,
8347,
342,
365,
892,
370,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
1852,
3220,
275,
747,
14,
8347,
199,
2590,
4281,
26,
523,
347,
1852,
3220,
8,
515,
12,
818,
29,
16,
11956,
304,
272,
4854,
12,
9483,
275,
747,
14,
515,
14,
1294,
8,
515,
9,
272,
340,
4854,
436,
9483,
436,
440,
747,
14,
515,
14,
2444,
8,
2993,
304,
489,
1852,
3220,
8,
2993,
12,
818,
9,
272,
747,
14,
8215,
8,
515,
12,
818,
9,
199,
199,
3,
199,
3,
18158,
10228,
14,
908,
602,
342,
365,
892,
370,
2018,
413,
14,
22,
199,
3,
199,
893,
26,
523,
1475,
602,
275,
18158,
10228,
14,
908,
602,
199,
2590,
4281,
26,
523,
347,
1475,
602,
8,
521,
637,
304,
272,
340,
900,
637,
365,
488,
26,
489,
900,
637,
275,
900,
14,
521,
342,
272,
900,
637,
275,
900,
14,
22227,
8,
521,
637,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
83,
450,
966,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
334,
288,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
9210,
521,
637,
59,
22,
2365,
288,
900,
637,
59,
18,
467,
288,
2097,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1467,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
9210,
521,
637,
59,
17,
11285,
17,
467,
1816,
900,
637,
59,
16,
467,
900,
637,
59,
19,
467,
900,
637,
59,
20,
467,
900,
637,
59,
21,
566,
199,
199,
3,
221,
199,
3,
11234,
14,
521,
13844,
342,
365,
892,
370,
2018,
499,
14,
88,
436,
221,
199,
3,
11234,
14,
28764,
4899,
342,
1990,
6835,
315,
2018,
413,
14,
21,
14,
18,
199,
3,
199,
893,
26,
523,
900,
13844,
275,
11234,
14,
521,
13844,
221,
199,
2590,
4281,
26,
523,
347,
29487,
4899,
8,
3403,
17,
12,
5361,
18,
304,
272,
408,
1767,
1329,
402,
29487,
17399,
315,
1425,
359,
3403,
17,
12,
5361,
18,
680,
2126,
16269,
5361,
17,
2695,
5361,
18,
1041,
272,
5361,
17,
275,
5361,
17,
446,
413,
272,
5361,
18,
275,
5361,
18,
446,
413,
272,
372,
334,
3403,
18,
15,
20,
446,
5361,
17,
15,
20,
9,
446,
334,
3403,
18,
15,
1960,
446,
221,
3303,
5361,
17,
15,
1960,
9,
435,
334,
3403,
18,
15,
5303,
446,
5361,
17,
15,
5303,
9,
819,
662,
1512,
1244,
275,
413,
20598,
523,
347,
900,
13844,
8,
2960,
304,
272,
408,
1358,
2407,
1325,
4926,
89,
805,
370,
8671,
13074,
4913,
687,
19152,
1041,
272,
5361,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
275,
2008,
1491,
22,
61,
272,
327,
702,
5361,
2356,
662,
1512,
1244,
272,
327,
702,
413,
2695,
5794,
2695,
3144,
272,
7609,
275,
28046,
5830,
3403,
13,
37,
1512,
1244,
9,
435,
29487,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
iw3hxn/LibrERP
|
report_aeroo/wizard/remove_print_button.py
|
3
|
3640
|
##############################################################################
#
# Copyright (c) 2008-2012 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
# General contacts <info@alistek.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This module is GPLv3 or newer and incompatible
# with OpenERP SA "AGPL + Private Use License"!
#
# 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.
#
##############################################################################
import pooler
from tools.translate import _
from osv import osv
from osv import fields
def ir_del(cr, uid, id):
obj = pooler.get_pool(cr.dbname).get('ir.values')
return obj.unlink(cr, uid, [id])
class aeroo_remove_print_button(osv.osv_memory):
'''
Remove Print Button
'''
_name = 'aeroo.remove_print_button'
_description = 'Remove print button'
def _check(self, cr, uid, context):
report = self.pool.get(context['active_model']).browse(cr, uid, context['active_id'], context=context)
if report.report_wizard:
act_win_obj = self.pool.get('ir.actions.act_window')
act_win_ids = act_win_obj.search(cr, uid, [('res_model','=','aeroo.print_actions')], context=context)
for act_win in act_win_obj.browse(cr, uid, act_win_ids, context=context):
act_win_context = eval(act_win.context, {})
if act_win_context.get('report_action_id')==report.id:
return 'remove'
return 'no_exist'
else:
ids = self.pool.get('ir.values').search(cr, uid, [('value','=',report.type+','+str(report.id))])
if not ids:
return 'no_exist'
else:
return 'remove'
def do_action(self, cr, uid, ids, context):
this = self.browse(cr, uid, ids[0], context=context)
report = self.pool.get(context['active_model']).browse(cr, uid, context['active_id'], context=context)
if report.report_wizard:
report._unset_report_wizard()
event_id = self.pool.get('ir.values').search(cr, uid, [('value','=','ir.actions.report.xml,%d' % context['active_id'])])[0]
res = ir_del(cr, uid, event_id)
this.write({'state':'done'}, context=context)
return self.write(cr, uid, ids, {'state':'done'}, context=context)
_columns = {
'state':fields.selection([
('remove','Remove'),
('no_exist','Not Exist'),
('done','Done'),
],'State', select=True, readonly=True),
}
_defaults = {
'state': _check,
}
aeroo_remove_print_button()
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
13,
7409,
15170,
1597,
75,
12126,
334,
1014,
921,
1544,
14,
279,
29729,
75,
14,
957,
9,
2900,
5924,
5702,
14,
199,
3,
8540,
1696,
27989,
665,
815,
32,
279,
29729,
75,
14,
957,
30,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
83,
3616,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
486,
10475,
397,
436,
2291,
787,
30390,
1503,
722,
68,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
859,
365,
14629,
86,
19,
503,
15666,
436,
18457,
199,
3,
543,
7653,
13950,
298,
1254,
2749,
435,
18551,
3645,
844,
2,
1,
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,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
4605,
199,
199,
646,
1115,
79,
1435,
199,
504,
7249,
14,
5275,
492,
485,
199,
504,
9506,
492,
9506,
199,
504,
9506,
492,
1504,
199,
199,
318,
8190,
63,
2264,
8,
1556,
12,
1747,
12,
1305,
304,
272,
1559,
275,
1115,
79,
1435,
14,
362,
63,
2293,
8,
1556,
14,
13238,
680,
362,
360,
723,
14,
1459,
358,
272,
372,
1559,
14,
7162,
8,
1556,
12,
1747,
12,
359,
344,
566,
199,
199,
533,
282,
281,
1534,
63,
2168,
63,
1361,
63,
3887,
8,
4795,
14,
4795,
63,
4844,
304,
272,
1449,
272,
5852,
9101,
16005,
272,
1449,
272,
485,
354,
275,
283,
65,
281,
1534,
14,
2168,
63,
1361,
63,
3887,
7,
272,
485,
1802,
275,
283,
5587,
870,
5528,
7,
339,
347,
485,
1074,
8,
277,
12,
2467,
12,
1747,
12,
1067,
304,
267,
3622,
275,
291,
14,
2293,
14,
362,
8,
1100,
459,
2682,
63,
1238,
13227,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
340,
3622,
14,
3070,
63,
9819,
26,
288,
2454,
63,
2676,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
358,
288,
2454,
63,
2676,
63,
1580,
275,
2454,
63,
2676,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
470,
63,
1238,
1673,
29511,
65,
281,
1534,
14,
1361,
63,
3723,
2665,
1067,
29,
1100,
9,
288,
367,
2454,
63,
2676,
315,
2454,
63,
2676,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
2454,
63,
2676,
63,
1580,
12,
1067,
29,
1100,
304,
355,
2454,
63,
2676,
63,
1100,
275,
3468,
8,
2442,
63,
2676,
14,
1100,
12,
5009,
355,
340,
2454,
63,
2676,
63,
1100,
14,
362,
360,
3070,
63,
1287,
63,
344,
358,
389,
3070,
14,
344,
26,
490,
372,
283,
2168,
7,
288,
372,
283,
889,
63,
4494,
7,
267,
587,
26,
288,
2762,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1459,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
585,
18937,
3070,
14,
466,
11,
1673,
11,
495,
8,
3070,
14,
344,
18229,
288,
340,
440,
2762,
26,
507,
3322,
372,
283,
889,
63,
4494,
7,
288,
587,
26,
507,
3322,
372,
283,
2168,
7,
339,
347,
886,
63,
1287,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
304,
267,
642,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
29,
1100,
9,
267,
3622,
275,
291,
14,
2293,
14,
362,
8,
1100,
459,
2682,
63,
1238,
13227,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
340,
3622,
14,
3070,
63,
9819,
26,
288,
3622,
423,
16787,
63,
3070,
63,
9819,
342,
267,
1566,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1459,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
585,
1673,
29511,
723,
14,
3723,
14,
3070,
14,
1652,
8719,
68,
7,
450,
1067,
459,
2682,
63,
344,
1105,
11057,
16,
61,
267,
522,
275,
8190,
63,
2264,
8,
1556,
12,
1747,
12,
1566,
63,
344,
9,
267,
642,
14,
952,
3252,
929,
5242,
4456,
2267,
1067,
29,
1100,
9,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
2762,
12,
791,
929,
5242,
4456,
2267,
1067,
29,
1100,
9,
2286,
485,
3406,
275,
469,
267,
283,
929,
356,
955,
14,
5592,
779,
288,
661,
2168,
1673,
5587,
659,
288,
661,
889,
63,
4494,
1673,
1763,
1316,
631,
659,
288,
661,
4456,
1673,
10759,
659,
10631,
2156,
7,
2223,
297,
3504,
29,
549,
12,
6863,
29,
549,
395,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
929,
356,
485,
1074,
12,
5493,
789,
199,
199,
65,
281,
1534,
63,
2168,
63,
1361,
63,
3887,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
13,
7409,
15170,
1597,
75,
12126,
334,
1014,
921,
1544,
14,
279,
29729,
75,
14,
957,
9,
2900,
5924,
5702,
14,
199,
3,
8540,
1696,
27989,
665,
815,
32,
279,
29729,
75,
14,
957,
30,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
83,
3616,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
486,
10475,
397,
436,
2291,
787,
30390,
1503,
722,
68,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
859,
365,
14629,
86,
19,
503,
15666,
436,
18457,
199,
3,
543,
7653,
13950,
298,
1254,
2749,
435,
18551,
3645,
844,
2,
1,
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,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
4605,
199,
199,
646,
1115,
79,
1435,
199,
504,
7249,
14,
5275,
492,
485,
199,
504,
9506,
492,
9506,
199,
504,
9506,
492,
1504,
199,
199,
318,
8190,
63,
2264,
8,
1556,
12,
1747,
12,
1305,
304,
272,
1559,
275,
1115,
79,
1435,
14,
362,
63,
2293,
8,
1556,
14,
13238,
680,
362,
360,
723,
14,
1459,
358,
272,
372,
1559,
14,
7162,
8,
1556,
12,
1747,
12,
359,
344,
566,
199,
199,
533,
282,
281,
1534,
63,
2168,
63,
1361,
63,
3887,
8,
4795,
14,
4795,
63,
4844,
304,
272,
1449,
272,
5852,
9101,
16005,
272,
1449,
272,
485,
354,
275,
283,
65,
281,
1534,
14,
2168,
63,
1361,
63,
3887,
7,
272,
485,
1802,
275,
283,
5587,
870,
5528,
7,
339,
347,
485,
1074,
8,
277,
12,
2467,
12,
1747,
12,
1067,
304,
267,
3622,
275,
291,
14,
2293,
14,
362,
8,
1100,
459,
2682,
63,
1238,
13227,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
340,
3622,
14,
3070,
63,
9819,
26,
288,
2454,
63,
2676,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
358,
288,
2454,
63,
2676,
63,
1580,
275,
2454,
63,
2676,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
470,
63,
1238,
1673,
29511,
65,
281,
1534,
14,
1361,
63,
3723,
2665,
1067,
29,
1100,
9,
288,
367,
2454,
63,
2676,
315,
2454,
63,
2676,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
2454,
63,
2676,
63,
1580,
12,
1067,
29,
1100,
304,
355,
2454,
63,
2676,
63,
1100,
275,
3468,
8,
2442,
63,
2676,
14,
1100,
12,
5009,
355,
340,
2454,
63,
2676,
63,
1100,
14,
362,
360,
3070,
63,
1287,
63,
344,
358,
389,
3070,
14,
344,
26,
490,
372,
283,
2168,
7,
288,
372,
283,
889,
63,
4494,
7,
267,
587,
26,
288,
2762,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1459,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
585,
18937,
3070,
14,
466,
11,
1673,
11,
495,
8,
3070,
14,
344,
18229,
288,
340,
440,
2762,
26,
507,
3322,
372,
283,
889,
63,
4494,
7,
288,
587,
26,
507,
3322,
372,
283,
2168,
7,
339,
347,
886,
63,
1287,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
304,
267,
642,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
59,
16,
467,
1067,
29,
1100,
9,
267,
3622,
275,
291,
14,
2293,
14,
362,
8,
1100,
459,
2682,
63,
1238,
13227,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
340,
3622,
14,
3070,
63,
9819,
26,
288,
3622,
423,
16787,
63,
3070,
63,
9819,
342,
267,
1566,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1459,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
585,
1673,
29511,
723,
14,
3723,
14,
3070,
14,
1652,
8719,
68,
7,
450,
1067,
459,
2682,
63,
344,
1105,
11057,
16,
61,
267,
522,
275,
8190,
63,
2264,
8,
1556,
12,
1747,
12,
1566,
63,
344,
9,
267,
642,
14,
952,
3252,
929,
5242,
4456,
2267,
1067,
29,
1100,
9,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
2762,
12,
791,
929,
5242,
4456,
2267,
1067,
29,
1100,
9,
2286,
485,
3406,
275,
469,
267,
283,
929,
356,
955,
14,
5592,
779,
288,
661,
2168,
1673,
5587,
659,
288,
661,
889,
63,
4494,
1673,
1763,
1316,
631,
659,
288,
661,
4456,
1673,
10759,
659,
10631,
2156,
7,
2223,
297,
3504,
29,
549,
12,
6863,
29,
549,
395,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
929,
356,
485,
1074,
12,
5493,
789,
199,
199,
65,
281,
1534,
63,
2168,
63,
1361,
63,
3887,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,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
|
cloud/openstack/os_ironic_node.py
|
68
|
13498
|
#!/usr/bin/python
# coding: utf-8 -*-
# (c) 2015, Hewlett-Packard Development Company, L.P.
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from distutils.version import StrictVersion
DOCUMENTATION = '''
---
module: os_ironic_node
short_description: Activate/Deactivate Bare Metal Resources from OpenStack
author: "Monty Taylor (@emonty)"
extends_documentation_fragment: openstack
version_added: "2.0"
description:
- Deploy to nodes controlled by Ironic.
options:
state:
description:
- Indicates desired state of the resource
choices: ['present', 'absent']
default: present
deploy:
description:
- Indicates if the resource should be deployed. Allows for deployment
logic to be disengaged and control of the node power or maintenance
state to be changed.
choices: ['true', 'false']
default: true
uuid:
description:
- globally unique identifier (UUID) to be given to the resource.
required: false
default: None
ironic_url:
description:
- If noauth mode is utilized, this is required to be set to the
endpoint URL for the Ironic API. Use with "auth" and "auth_type"
settings set to None.
required: false
default: None
config_drive:
description:
- A configdrive file or HTTP(S) URL that will be passed along to the
node.
required: false
default: None
instance_info:
description:
- Definition of the instance information which is used to deploy
the node. This information is only required when an instance is
set to present.
suboptions:
image_source:
description:
- An HTTP(S) URL where the image can be retrieved from.
image_checksum:
description:
- The checksum of image_source.
image_disk_format:
description:
- The type of image that has been requested to be deployed.
power:
description:
- A setting to allow power state to be asserted allowing nodes
that are not yet deployed to be powered on, and nodes that
are deployed to be powered off.
choices: ['present', 'absent']
default: present
maintenance:
description:
- A setting to allow the direct control if a node is in
maintenance mode.
required: false
default: false
maintenance_reason:
description:
- A string expression regarding the reason a node is in a
maintenance mode.
required: false
default: None
wait:
description:
- A boolean value instructing the module to wait for node
activation or deactivation to complete before returning.
required: false
default: False
version_added: "2.1"
timeout:
description:
- An integer value representing the number of seconds to
wait for the node activation or deactivation to complete.
version_added: "2.1"
'''
EXAMPLES = '''
# Activate a node by booting an image with a configdrive attached
os_ironic_node:
cloud: "openstack"
uuid: "d44666e1-35b3-4f6b-acb0-88ab7052da69"
state: present
power: present
deploy: True
maintenance: False
config_drive: "http://192.168.1.1/host-configdrive.iso"
instance_info:
image_source: "http://192.168.1.1/deploy_image.img"
image_checksum: "356a6b55ecc511a20c33c946c4e678af"
image_disk_format: "qcow"
delegate_to: localhost
'''
def _choose_id_value(module):
if module.params['uuid']:
return module.params['uuid']
if module.params['name']:
return module.params['name']
return None
# TODO(TheJulia): Change this over to use the machine patch method
# in shade once it is available.
def _prepare_instance_info_patch(instance_info):
patch = []
patch.append({
'op': 'replace',
'path': '/instance_info',
'value': instance_info
})
return patch
def _is_true(value):
true_values = [True, 'yes', 'Yes', 'True', 'true', 'present', 'on']
if value in true_values:
return True
return False
def _is_false(value):
false_values = [False, None, 'no', 'No', 'False', 'false', 'absent', 'off']
if value in false_values:
return True
return False
def _check_set_maintenance(module, cloud, node):
if _is_true(module.params['maintenance']):
if _is_false(node['maintenance']):
cloud.set_machine_maintenance_state(
node['uuid'],
True,
reason=module.params['maintenance_reason'])
module.exit_json(changed=True, msg="Node has been set into "
"maintenance mode")
else:
# User has requested maintenance state, node is already in the
# desired state, checking to see if the reason has changed.
if (str(node['maintenance_reason']) not in
str(module.params['maintenance_reason'])):
cloud.set_machine_maintenance_state(
node['uuid'],
True,
reason=module.params['maintenance_reason'])
module.exit_json(changed=True, msg="Node maintenance reason "
"updated, cannot take any "
"additional action.")
elif _is_false(module.params['maintenance']):
if node['maintenance'] is True:
cloud.remove_machine_from_maintenance(node['uuid'])
return True
else:
module.fail_json(msg="maintenance parameter was set but a valid "
"the value was not recognized.")
return False
def _check_set_power_state(module, cloud, node):
if 'power on' in str(node['power_state']):
if _is_false(module.params['power']):
# User has requested the node be powered off.
cloud.set_machine_power_off(node['uuid'])
module.exit_json(changed=True, msg="Power requested off")
if 'power off' in str(node['power_state']):
if (_is_false(module.params['power']) and
_is_false(module.params['state'])):
return False
if (_is_false(module.params['power']) and
_is_false(module.params['state'])):
module.exit_json(
changed=False,
msg="Power for node is %s, node must be reactivated "
"OR set to state absent"
)
# In the event the power has been toggled on and
# deployment has been requested, we need to skip this
# step.
if (_is_true(module.params['power']) and
_is_false(module.params['deploy'])):
# Node is powered down when it is not awaiting to be provisioned
cloud.set_machine_power_on(node['uuid'])
return True
# Default False if no action has been taken.
return False
def main():
argument_spec = openstack_full_argument_spec(
uuid=dict(required=False),
name=dict(required=False),
instance_info=dict(type='dict', required=False),
config_drive=dict(required=False),
ironic_url=dict(required=False),
state=dict(required=False, default='present'),
maintenance=dict(required=False),
maintenance_reason=dict(required=False),
power=dict(required=False, default='present'),
deploy=dict(required=False, default=True),
wait=dict(type='bool', required=False, default=False),
timeout=dict(required=False, type='int', default=1800),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if (module.params['wait'] and
StrictVersion(shade.__version__) < StrictVersion('1.4.0')):
module.fail_json(msg="To utilize wait, the installed version of"
"the shade library MUST be >=1.4.0")
if (module.params['auth_type'] in [None, 'None'] and
module.params['ironic_url'] is None):
module.fail_json(msg="Authentication appears disabled, Please "
"define an ironic_url parameter")
if (module.params['ironic_url'] and
module.params['auth_type'] in [None, 'None']):
module.params['auth'] = dict(
endpoint=module.params['ironic_url']
)
node_id = _choose_id_value(module)
if not node_id:
module.fail_json(msg="A uuid or name value must be defined "
"to use this module.")
try:
cloud = shade.operator_cloud(**module.params)
node = cloud.get_machine(node_id)
if node is None:
module.fail_json(msg="node not found")
uuid = node['uuid']
instance_info = module.params['instance_info']
changed = False
wait = module.params['wait']
timeout = module.params['timeout']
# User has reqeusted desired state to be in maintenance state.
if module.params['state'] is 'maintenance':
module.params['maintenance'] = True
if node['provision_state'] in [
'cleaning',
'deleting',
'wait call-back']:
module.fail_json(msg="Node is in %s state, cannot act upon the "
"request as the node is in a transition "
"state" % node['provision_state'])
# TODO(TheJulia) This is in-development code, that requires
# code in the shade library that is still in development.
if _check_set_maintenance(module, cloud, node):
if node['provision_state'] in 'active':
module.exit_json(changed=True,
result="Maintenance state changed")
changed = True
node = cloud.get_machine(node_id)
if _check_set_power_state(module, cloud, node):
changed = True
node = cloud.get_machine(node_id)
if _is_true(module.params['state']):
if _is_false(module.params['deploy']):
module.exit_json(
changed=changed,
result="User request has explicitly disabled "
"deployment logic"
)
if 'active' in node['provision_state']:
module.exit_json(
changed=changed,
result="Node already in an active state."
)
if instance_info is None:
module.fail_json(
changed=changed,
msg="When setting an instance to present, "
"instance_info is a required variable.")
# TODO(TheJulia): Update instance info, however info is
# deployment specific. Perhaps consider adding rebuild
# support, although there is a known desire to remove
# rebuild support from Ironic at some point in the future.
patch = _prepare_instance_info_patch(instance_info)
cloud.set_node_instance_info(uuid, patch)
cloud.validate_node(uuid)
if not wait:
cloud.activate_node(uuid, module.params['config_drive'])
else:
cloud.activate_node(
uuid,
configdrive=module.params['config_drive'],
wait=wait,
timeout=timeout)
# TODO(TheJulia): Add more error checking..
module.exit_json(changed=changed, result="node activated")
elif _is_false(module.params['state']):
if node['provision_state'] not in "deleted":
cloud.purge_node_instance_info(uuid)
if not wait:
cloud.deactivate_node(uuid)
else:
cloud.deactivate_node(
uuid,
wait=wait,
timeout=timeout)
module.exit_json(changed=True, result="deleted")
else:
module.exit_json(changed=False, result="node not found")
else:
module.fail_json(msg="State must be present, absent, "
"maintenance, off")
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
32250,
272,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
199,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
723,
12732,
63,
932,
199,
3612,
63,
1802,
26,
21904,
2409,
15,
872,
8222,
699,
1530,
10072,
279,
26250,
687,
14260,
199,
2502,
26,
298,
6671,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1802,
26,
272,
446,
21588,
3374,
370,
3380,
22284,
701,
473,
20410,
14,
199,
1419,
26,
272,
1174,
26,
489,
1369,
26,
267,
446,
19334,
6387,
1174,
402,
314,
2073,
489,
3415,
26,
788,
1881,
297,
283,
5575,
418,
489,
849,
26,
3451,
272,
12287,
26,
489,
1369,
26,
2126,
446,
19334,
340,
314,
2073,
1077,
506,
26181,
14,
22819,
367,
14295,
268,
9661,
370,
506,
487,
2464,
71,
6028,
436,
3304,
402,
314,
1031,
7074,
503,
21964,
268,
1174,
370,
506,
2896,
14,
489,
3415,
26,
788,
2052,
297,
283,
3910,
418,
489,
849,
26,
2549,
272,
5377,
26,
489,
1369,
26,
267,
446,
26662,
3747,
5148,
334,
8757,
9,
370,
506,
1627,
370,
314,
2073,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
28372,
63,
633,
26,
489,
1369,
26,
267,
446,
982,
949,
1178,
818,
365,
7678,
317,
7068,
12,
642,
365,
1415,
370,
506,
663,
370,
314,
881,
6037,
2851,
367,
314,
473,
20410,
3261,
14,
221,
3645,
543,
298,
1178,
2,
436,
298,
1178,
63,
466,
2,
881,
2202,
663,
370,
488,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
1101,
63,
9541,
26,
489,
1369,
26,
267,
446,
437,
1101,
9541,
570,
503,
3101,
8,
51,
9,
2851,
626,
911,
506,
3032,
3180,
370,
314,
881,
1031,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
1256,
63,
815,
26,
489,
1369,
26,
267,
446,
29398,
402,
314,
1256,
2556,
1314,
365,
1202,
370,
12287,
881,
314,
1031,
14,
221,
961,
2556,
365,
1454,
1415,
1380,
376,
1256,
365,
881,
663,
370,
3451,
14,
489,
26265,
26,
267,
1834,
63,
1365,
26,
881,
1369,
26,
288,
446,
1626,
3101,
8,
51,
9,
2851,
2382,
314,
1834,
883,
506,
12396,
687,
14,
267,
1834,
63,
8928,
26,
881,
1369,
26,
288,
446,
710,
9040,
402,
1834,
63,
1365,
14,
267,
1834,
63,
4032,
63,
908,
26,
881,
1369,
26,
288,
446,
710,
730,
402,
1834,
626,
965,
2757,
5839,
370,
506,
26181,
14,
272,
7074,
26,
489,
1369,
26,
267,
446,
437,
4260,
370,
2040,
7074,
1174,
370,
506,
465,
9449,
17266,
3380,
881,
626,
787,
440,
5966,
26181,
370,
506,
13131,
16179,
641,
12,
436,
3380,
626,
881,
787,
26181,
370,
506,
13131,
16179,
2331,
14,
489,
3415,
26,
788,
1881,
297,
283,
5575,
418,
489,
849,
26,
3451,
272,
21964,
26,
489,
1369,
26,
267,
446,
437,
4260,
370,
2040,
314,
4125,
3304,
340,
282,
1031,
365,
315,
881,
21964,
818,
14,
489,
1415,
26,
3055,
489,
849,
26,
3055,
272,
21964,
63,
5764,
26,
489,
1369,
26,
267,
446,
437,
1059,
3965,
12602,
314,
4499,
282,
1031,
365,
315,
282,
881,
21964,
818,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
3618,
26,
489,
1369,
26,
267,
446,
437,
5046,
574,
315,
1820,
316,
314,
859,
370,
3618,
367,
1031,
881,
10361,
503,
477,
12312,
370,
4890,
2544,
8152,
14,
489,
1415,
26,
3055,
489,
849,
26,
756,
489,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
2653,
26,
489,
1369,
26,
267,
446,
1626,
3000,
574,
6144,
314,
1329,
402,
4696,
370,
881,
3618,
367,
314,
1031,
10361,
503,
477,
12312,
370,
4890,
14,
489,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
21904,
2409,
282,
1031,
701,
8498,
316,
376,
1834,
543,
282,
1101,
9541,
10102,
199,
736,
63,
723,
12732,
63,
932,
26,
523,
8002,
26,
298,
8512,
2,
523,
5377,
26,
298,
68,
1602,
11829,
69,
17,
13,
1276,
66,
19,
13,
20,
70,
22,
66,
13,
26940,
16,
13,
1299,
371,
23,
19730,
983,
1876,
2,
523,
1174,
26,
3451,
523,
7074,
26,
3451,
523,
12287,
26,
715,
523,
21964,
26,
756,
523,
1101,
63,
9541,
26,
298,
1014,
921,
5756,
14,
6568,
14,
17,
14,
17,
15,
1102,
13,
888,
9541,
14,
4595,
2,
523,
1256,
63,
815,
26,
272,
1834,
63,
1365,
26,
298,
1014,
921,
5756,
14,
6568,
14,
17,
14,
17,
15,
11060,
63,
1569,
14,
4060,
2,
272,
1834,
63,
8928,
26,
298,
13251,
65,
22,
66,
1229,
825,
67,
27176,
65,
1165,
67,
1153,
67,
30626,
67,
20,
69,
17237,
2756,
2,
272,
1834,
63,
4032,
63,
908,
26,
298,
81,
19969,
2,
523,
13080,
63,
475,
26,
11667,
199,
2344,
421,
199,
318,
485,
16143,
63,
344,
63,
585,
8,
578,
304,
272,
340,
859,
14,
1162,
459,
2580,
2565,
267,
372
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
32250,
272,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
199,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
723,
12732,
63,
932,
199,
3612,
63,
1802,
26,
21904,
2409,
15,
872,
8222,
699,
1530,
10072,
279,
26250,
687,
14260,
199,
2502,
26,
298,
6671,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1802,
26,
272,
446,
21588,
3374,
370,
3380,
22284,
701,
473,
20410,
14,
199,
1419,
26,
272,
1174,
26,
489,
1369,
26,
267,
446,
19334,
6387,
1174,
402,
314,
2073,
489,
3415,
26,
788,
1881,
297,
283,
5575,
418,
489,
849,
26,
3451,
272,
12287,
26,
489,
1369,
26,
2126,
446,
19334,
340,
314,
2073,
1077,
506,
26181,
14,
22819,
367,
14295,
268,
9661,
370,
506,
487,
2464,
71,
6028,
436,
3304,
402,
314,
1031,
7074,
503,
21964,
268,
1174,
370,
506,
2896,
14,
489,
3415,
26,
788,
2052,
297,
283,
3910,
418,
489,
849,
26,
2549,
272,
5377,
26,
489,
1369,
26,
267,
446,
26662,
3747,
5148,
334,
8757,
9,
370,
506,
1627,
370,
314,
2073,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
28372,
63,
633,
26,
489,
1369,
26,
267,
446,
982,
949,
1178,
818,
365,
7678,
317,
7068,
12,
642,
365,
1415,
370,
506,
663,
370,
314,
881,
6037,
2851,
367,
314,
473,
20410,
3261,
14,
221,
3645,
543,
298,
1178,
2,
436,
298,
1178,
63,
466,
2,
881,
2202,
663,
370,
488,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
1101,
63,
9541,
26,
489,
1369,
26,
267,
446,
437,
1101,
9541,
570,
503,
3101,
8,
51,
9,
2851,
626,
911,
506,
3032,
3180,
370,
314,
881,
1031,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
1256,
63,
815,
26,
489,
1369,
26,
267,
446,
29398,
402,
314,
1256,
2556,
1314,
365,
1202,
370,
12287,
881,
314,
1031,
14,
221,
961,
2556,
365,
1454,
1415,
1380,
376,
1256,
365,
881,
663,
370,
3451,
14,
489,
26265,
26,
267,
1834,
63,
1365,
26,
881,
1369,
26,
288,
446,
1626,
3101,
8,
51,
9,
2851,
2382,
314,
1834,
883,
506,
12396,
687,
14,
267,
1834,
63,
8928,
26,
881,
1369,
26,
288,
446,
710,
9040,
402,
1834,
63,
1365,
14,
267,
1834,
63,
4032,
63,
908,
26,
881,
1369,
26,
288,
446,
710,
730,
402,
1834,
626,
965,
2757,
5839,
370,
506,
26181,
14,
272,
7074,
26,
489,
1369,
26,
267,
446,
437,
4260,
370,
2040,
7074,
1174,
370,
506,
465,
9449,
17266,
3380,
881,
626,
787,
440,
5966,
26181,
370,
506,
13131,
16179,
641,
12,
436,
3380,
626,
881,
787,
26181,
370,
506,
13131,
16179,
2331,
14,
489,
3415,
26,
788,
1881,
297,
283,
5575,
418,
489,
849,
26,
3451,
272,
21964,
26,
489,
1369,
26,
267,
446,
437,
4260,
370,
2040,
314,
4125,
3304,
340,
282,
1031,
365,
315,
881,
21964,
818,
14,
489,
1415,
26,
3055,
489,
849,
26,
3055,
272,
21964,
63,
5764,
26,
489,
1369,
26,
267,
446,
437,
1059,
3965,
12602,
314,
4499,
282,
1031,
365,
315,
282,
881,
21964,
818,
14,
489,
1415,
26,
3055,
489,
849,
26,
488,
272,
3618,
26,
489,
1369,
26,
267,
446,
437,
5046,
574,
315,
1820,
316,
314,
859,
370,
3618,
367,
1031,
881,
10361,
503,
477,
12312,
370,
4890,
2544,
8152,
14,
489,
1415,
26,
3055,
489,
849,
26,
756,
489,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
2653,
26,
489,
1369,
26,
267,
446,
1626,
3000,
574,
6144,
314,
1329,
402,
4696,
370,
881,
3618,
367,
314,
1031,
10361,
503,
477,
12312,
370,
4890,
14,
489,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
21904,
2409,
282,
1031,
701,
8498,
316,
376,
1834,
543,
282,
1101,
9541,
10102,
199,
736,
63,
723,
12732,
63,
932,
26,
523,
8002,
26,
298,
8512,
2,
523,
5377,
26,
298,
68,
1602,
11829,
69,
17,
13,
1276,
66,
19,
13,
20,
70,
22,
66,
13,
26940,
16,
13,
1299,
371,
23,
19730,
983,
1876,
2,
523,
1174,
26,
3451,
523,
7074,
26,
3451,
523,
12287,
26,
715,
523,
21964,
26,
756,
523,
1101,
63,
9541,
26,
298,
1014,
921,
5756,
14,
6568,
14,
17,
14,
17,
15,
1102,
13,
888,
9541,
14,
4595,
2,
523,
1256,
63,
815,
26,
272,
1834,
63,
1365,
26,
298,
1014,
921,
5756,
14,
6568,
14,
17,
14,
17,
15,
11060,
63,
1569,
14,
4060,
2,
272,
1834,
63,
8928,
26,
298,
13251,
65,
22,
66,
1229,
825,
67,
27176,
65,
1165,
67,
1153,
67,
30626,
67,
20,
69,
17237,
2756,
2,
272,
1834,
63,
4032,
63,
908,
26,
298,
81,
19969,
2,
523,
13080,
63,
475,
26,
11667,
199,
2344,
421,
199,
318,
485,
16143,
63,
344,
63,
585,
8,
578,
304,
272,
340,
859,
14,
1162,
459,
2580,
2565,
267,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bob123bob/Sick-Beard
|
cherrypy/_cprequest.py
|
39
|
38091
|
from Cookie import SimpleCookie, CookieError
import os
import sys
import time
import types
import warnings
import cherrypy
from cherrypy import _cpreqbody, _cpconfig
from cherrypy._cperror import format_exc, bare_error
from cherrypy.lib import httputil, file_generator
class Hook(object):
"""A callback and its metadata: failsafe, priority, and kwargs."""
__metaclass__ = cherrypy._AttributeDocstrings
callback = None
callback__doc = """
The bare callable that this Hook object is wrapping, which will
be called when the Hook is called."""
failsafe = False
failsafe__doc = """
If True, the callback is guaranteed to run even if other callbacks
from the same call point raise exceptions."""
priority = 50
priority__doc = """
Defines the order of execution for a list of Hooks. Priority numbers
should be limited to the closed interval [0, 100], but values outside
this range are acceptable, as are fractional values."""
kwargs = {}
kwargs__doc = """
A set of keyword arguments that will be passed to the
callable on each call."""
def __init__(self, callback, failsafe=None, priority=None, **kwargs):
self.callback = callback
if failsafe is None:
failsafe = getattr(callback, "failsafe", False)
self.failsafe = failsafe
if priority is None:
priority = getattr(callback, "priority", 50)
self.priority = priority
self.kwargs = kwargs
def __cmp__(self, other):
return cmp(self.priority, other.priority)
def __call__(self):
"""Run self.callback(**self.kwargs)."""
return self.callback(**self.kwargs)
def __repr__(self):
cls = self.__class__
return ("%s.%s(callback=%r, failsafe=%r, priority=%r, %s)"
% (cls.__module__, cls.__name__, self.callback,
self.failsafe, self.priority,
", ".join(['%s=%r' % (k, v)
for k, v in self.kwargs.items()])))
class HookMap(dict):
"""A map of call points to lists of callbacks (Hook objects)."""
def __new__(cls, points=None):
d = dict.__new__(cls)
for p in points or []:
d[p] = []
return d
def __init__(self, *a, **kw):
pass
def attach(self, point, callback, failsafe=None, priority=None, **kwargs):
"""Append a new Hook made from the supplied arguments."""
self[point].append(Hook(callback, failsafe, priority, **kwargs))
def run(self, point):
"""Execute all registered Hooks (callbacks) for the given point."""
exc = None
hooks = self[point]
hooks.sort()
for hook in hooks:
# Some hooks are guaranteed to run even if others at
# the same hookpoint fail. We will still log the failure,
# but proceed on to the next hook. The only way
# to stop all processing from one of these hooks is
# to raise SystemExit and stop the whole server.
if exc is None or hook.failsafe:
try:
hook()
except (KeyboardInterrupt, SystemExit):
raise
except (cherrypy.HTTPError, cherrypy.HTTPRedirect,
cherrypy.InternalRedirect):
exc = sys.exc_info()[1]
except:
exc = sys.exc_info()[1]
cherrypy.log(traceback=True, severity=40)
if exc:
raise
def __copy__(self):
newmap = self.__class__()
# We can't just use 'update' because we want copies of the
# mutable values (each is a list) as well.
for k, v in self.items():
newmap[k] = v[:]
return newmap
copy = __copy__
def __repr__(self):
cls = self.__class__
return "%s.%s(points=%r)" % (cls.__module__, cls.__name__, self.keys())
# Config namespace handlers
def hooks_namespace(k, v):
"""Attach bare hooks declared in config."""
# Use split again to allow multiple hooks for a single
# hookpoint per path (e.g. "hooks.before_handler.1").
# Little-known fact you only get from reading source ;)
hookpoint = k.split(".", 1)[0]
if isinstance(v, basestring):
v = cherrypy.lib.attributes(v)
if not isinstance(v, Hook):
v = Hook(v)
cherrypy.serving.request.hooks[hookpoint].append(v)
def request_namespace(k, v):
"""Attach request attributes declared in config."""
# Provides config entries to set request.body attrs (like attempt_charsets).
if k[:5] == 'body.':
setattr(cherrypy.serving.request.body, k[5:], v)
else:
setattr(cherrypy.serving.request, k, v)
def response_namespace(k, v):
"""Attach response attributes declared in config."""
# Provides config entries to set default response headers
# http://cherrypy.org/ticket/889
if k[:8] == 'headers.':
cherrypy.serving.response.headers[k.split('.', 1)[1]] = v
else:
setattr(cherrypy.serving.response, k, v)
def error_page_namespace(k, v):
"""Attach error pages declared in config."""
if k != 'default':
k = int(k)
cherrypy.serving.request.error_page[k] = v
hookpoints = ['on_start_resource', 'before_request_body',
'before_handler', 'before_finalize',
'on_end_resource', 'on_end_request',
'before_error_response', 'after_error_response']
class Request(object):
"""An HTTP request.
This object represents the metadata of an HTTP request message;
that is, it contains attributes which describe the environment
in which the request URL, headers, and body were sent (if you
want tools to interpret the headers and body, those are elsewhere,
mostly in Tools). This 'metadata' consists of socket data,
transport characteristics, and the Request-Line. This object
also contains data regarding the configuration in effect for
the given URL, and the execution plan for generating a response.
"""
__metaclass__ = cherrypy._AttributeDocstrings
prev = None
prev__doc = """
The previous Request object (if any). This should be None
unless we are processing an InternalRedirect."""
# Conversation/connection attributes
local = httputil.Host("127.0.0.1", 80)
local__doc = \
"An httputil.Host(ip, port, hostname) object for the server socket."
remote = httputil.Host("127.0.0.1", 1111)
remote__doc = \
"An httputil.Host(ip, port, hostname) object for the client socket."
scheme = "http"
scheme__doc = """
The protocol used between client and server. In most cases,
this will be either 'http' or 'https'."""
server_protocol = "HTTP/1.1"
server_protocol__doc = """
The HTTP version for which the HTTP server is at least
conditionally compliant."""
base = ""
base__doc = """The (scheme://host) portion of the requested URL.
In some cases (e.g. when proxying via mod_rewrite), this may contain
path segments which cherrypy.url uses when constructing url's, but
which otherwise are ignored by CherryPy. Regardless, this value
MUST NOT end in a slash."""
# Request-Line attributes
request_line = ""
request_line__doc = """
The complete Request-Line received from the client. This is a
single string consisting of the request method, URI, and protocol
version (joined by spaces). Any final CRLF is removed."""
method = "GET"
method__doc = """
Indicates the HTTP method to be performed on the resource identified
by the Request-URI. Common methods include GET, HEAD, POST, PUT, and
DELETE. CherryPy allows any extension method; however, various HTTP
servers and gateways may restrict the set of allowable methods.
CherryPy applications SHOULD restrict the set (on a per-URI basis)."""
query_string = ""
query_string__doc = """
The query component of the Request-URI, a string of information to be
interpreted by the resource. The query portion of a URI follows the
path component, and is separated by a '?'. For example, the URI
'http://www.cherrypy.org/wiki?a=3&b=4' has the query component,
'a=3&b=4'."""
query_string_encoding = 'utf8'
query_string_encoding__doc = """
The encoding expected for query string arguments after % HEX HEX decoding).
If a query string is provided that cannot be decoded with this encoding,
404 is raised (since technically it's a different URI). If you want
arbitrary encodings to not error, set this to 'Latin-1'; you can then
encode back to bytes and re-decode to whatever encoding you like later.
"""
protocol = (1, 1)
protocol__doc = """The HTTP protocol version corresponding to the set
of features which should be allowed in the response. If BOTH
the client's request message AND the server's level of HTTP
compliance is HTTP/1.1, this attribute will be the tuple (1, 1).
If either is 1.0, this attribute will be the tuple (1, 0).
Lower HTTP protocol versions are not explicitly supported."""
params = {}
params__doc = """
A dict which combines query string (GET) and request entity (POST)
variables. This is populated in two stages: GET params are added
before the 'on_start_resource' hook, and POST params are added
between the 'before_request_body' and 'before_handler' hooks."""
# Message attributes
header_list = []
header_list__doc = """
A list of the HTTP request headers as (name, value) tuples.
In general, you should use request.headers (a dict) instead."""
headers = httputil.HeaderMap()
headers__doc = """
A dict-like object containing the request headers. Keys are header
names (in Title-Case format); however, you may get and set them in
a case-insensitive manner. That is, headers['Content-Type'] and
headers['content-type'] refer to the same value. Values are header
values (decoded according to RFC 2047 if necessary). See also:
httputil.HeaderMap, httputil.HeaderElement."""
cookie = SimpleCookie()
cookie__doc = """See help(Cookie)."""
body = None
body__doc = """See help(cherrypy.request.body)"""
rfile = None
rfile__doc = """
If the request included an entity (body), it will be available
as a stream in this attribute. However, the rfile will normally
be read for you between the 'before_request_body' hook and the
'before_handler' hook, and the resulting string is placed into
either request.params or the request.body attribute.
You may disable the automatic consumption of the rfile by setting
request.process_request_body to False, either in config for the desired
path, or in an 'on_start_resource' or 'before_request_body' hook.
WARNING: In almost every case, you should not attempt to read from the
rfile stream after CherryPy's automatic mechanism has read it. If you
turn off the automatic parsing of rfile, you should read exactly the
number of bytes specified in request.headers['Content-Length'].
Ignoring either of these warnings may result in a hung request thread
or in corruption of the next (pipelined) request.
"""
process_request_body = True
process_request_body__doc = """
If True, the rfile (if any) is automatically read and parsed,
and the result placed into request.params or request.body."""
methods_with_bodies = ("POST", "PUT")
methods_with_bodies__doc = """
A sequence of HTTP methods for which CherryPy will automatically
attempt to read a body from the rfile."""
body = None
body__doc = """
If the request Content-Type is 'application/x-www-form-urlencoded'
or multipart, this will be None. Otherwise, this will contain the
request entity body as an open file object (which you can .read());
this value is set between the 'before_request_body' and 'before_handler'
hooks (assuming that process_request_body is True)."""
body_params = None
body_params__doc = """
If the request Content-Type is 'application/x-www-form-urlencoded' or
multipart, this will be a dict of the params pulled from the entity
body; that is, it will be the portion of request.params that come
from the message body (sometimes called "POST params", although they
can be sent with various HTTP method verbs). This value is set between
the 'before_request_body' and 'before_handler' hooks (assuming that
process_request_body is True)."""
# Dispatch attributes
dispatch = cherrypy.dispatch.Dispatcher()
dispatch__doc = """
The object which looks up the 'page handler' callable and collects
config for the current request based on the path_info, other
request attributes, and the application architecture. The core
calls the dispatcher as early as possible, passing it a 'path_info'
argument.
The default dispatcher discovers the page handler by matching path_info
to a hierarchical arrangement of objects, starting at request.app.root.
See help(cherrypy.dispatch) for more information."""
script_name = ""
script_name__doc = """
The 'mount point' of the application which is handling this request.
This attribute MUST NOT end in a slash. If the script_name refers to
the root of the URI, it MUST be an empty string (not "/").
"""
path_info = "/"
path_info__doc = """
The 'relative path' portion of the Request-URI. This is relative
to the script_name ('mount point') of the application which is
handling this request."""
login = None
login__doc = """
When authentication is used during the request processing this is
set to 'False' if it failed and to the 'username' value if it succeeded.
The default 'None' implies that no authentication happened."""
# Note that cherrypy.url uses "if request.app:" to determine whether
# the call is during a real HTTP request or not. So leave this None.
app = None
app__doc = \
"""The cherrypy.Application object which is handling this request."""
handler = None
handler__doc = """
The function, method, or other callable which CherryPy will call to
produce the response. The discovery of the handler and the arguments
it will receive are determined by the request.dispatch object.
By default, the handler is discovered by walking a tree of objects
starting at request.app.root, and is then passed all HTTP params
(from the query string and POST body) as keyword arguments."""
toolmaps = {}
toolmaps__doc = """
A nested dict of all Toolboxes and Tools in effect for this request,
of the form: {Toolbox.namespace: {Tool.name: config dict}}."""
config = None
config__doc = """
A flat dict of all configuration entries which apply to the
current request. These entries are collected from global config,
application config (based on request.path_info), and from handler
config (exactly how is governed by the request.dispatch object in
effect for this request; by default, handler config can be attached
anywhere in the tree between request.app.root and the final handler,
and inherits downward)."""
is_index = None
is_index__doc = """
This will be True if the current request is mapped to an 'index'
resource handler (also, a 'default' handler if path_info ends with
a slash). The value may be used to automatically redirect the
user-agent to a 'more canonical' URL which either adds or removes
the trailing slash. See cherrypy.tools.trailing_slash."""
hooks = HookMap(hookpoints)
hooks__doc = """
A HookMap (dict-like object) of the form: {hookpoint: [hook, ...]}.
Each key is a str naming the hook point, and each value is a list
of hooks which will be called at that hook point during this request.
The list of hooks is generally populated as early as possible (mostly
from Tools specified in config), but may be extended at any time.
See also: _cprequest.Hook, _cprequest.HookMap, and cherrypy.tools."""
error_response = cherrypy.HTTPError(500).set_response
error_response__doc = """
The no-arg callable which will handle unexpected, untrapped errors
during request processing. This is not used for expected exceptions
(like NotFound, HTTPError, or HTTPRedirect) which are raised in
response to expected conditions (those should be customized either
via request.error_page or by overriding HTTPError.set_response).
By default, error_response uses HTTPError(500) to return a generic
error response to the user-agent."""
error_page = {}
error_page__doc = """
A dict of {error code: response filename or callable} pairs.
The error code must be an int representing a given HTTP error code,
or the string 'default', which will be used if no matching entry
is found for a given numeric code.
If a filename is provided, the file should contain a Python string-
formatting template, and can expect by default to receive format
values with the mapping keys %(status)s, %(message)s, %(traceback)s,
and %(version)s. The set of format mappings can be extended by
overriding HTTPError.set_response.
If a callable is provided, it will be called by default with keyword
arguments 'status', 'message', 'traceback', and 'version', as for a
string-formatting template. The callable must return a string or iterable of
strings which will be set to response.body. It may also override headers or
perform any other processing.
If no entry is given for an error code, and no 'default' entry exists,
a default template will be used.
"""
show_tracebacks = True
show_tracebacks__doc = """
If True, unexpected errors encountered during request processing will
include a traceback in the response body."""
show_mismatched_params = True
show_mismatched_params__doc = """
If True, mismatched parameters encountered during PageHandler invocation
processing will be included in the response body."""
throws = (KeyboardInterrupt, SystemExit, cherrypy.InternalRedirect)
throws__doc = \
"""The sequence of exceptions which Request.run does not trap."""
throw_errors = False
throw_errors__doc = """
If True, Request.run will not trap any errors (except HTTPRedirect and
HTTPError, which are more properly called 'exceptions', not errors)."""
closed = False
closed__doc = """
True once the close method has been called, False otherwise."""
stage = None
stage__doc = """
A string containing the stage reached in the request-handling process.
This is useful when debugging a live server with hung requests."""
namespaces = _cpconfig.NamespaceSet(
**{"hooks": hooks_namespace,
"request": request_namespace,
"response": response_namespace,
"error_page": error_page_namespace,
"tools": cherrypy.tools,
})
def __init__(self, local_host, remote_host, scheme="http",
server_protocol="HTTP/1.1"):
"""Populate a new Request object.
local_host should be an httputil.Host object with the server info.
remote_host should be an httputil.Host object with the client info.
scheme should be a string, either "http" or "https".
"""
self.local = local_host
self.remote = remote_host
self.scheme = scheme
self.server_protocol = server_protocol
self.closed = False
# Put a *copy* of the class error_page into self.
self.error_page = self.error_page.copy()
# Put a *copy* of the class namespaces into self.
self.namespaces = self.namespaces.copy()
self.stage = None
def close(self):
"""Run cleanup code. (Core)"""
if not self.closed:
self.closed = True
self.stage = 'on_end_request'
self.hooks.run('on_end_request')
self.stage = 'close'
def run(self, method, path, query_string, req_protocol, headers, rfile):
"""Process the Request. (Core)
method, path, query_string, and req_protocol should be pulled directly
from the Request-Line (e.g. "GET /path?key=val HTTP/1.0").
path should be %XX-unquoted, but query_string should not be.
They both MUST be byte strings, not unicode strings.
headers should be a list of (name, value) tuples.
rfile should be a file-like object containing the HTTP request entity.
When run() is done, the returned object should have 3 attributes:
status, e.g. "200 OK"
header_list, a list of (name, value) tuples
body, an iterable yielding strings
Consumer code (HTTP servers) should then access these response
attributes to build the outbound stream.
"""
response = cherrypy.serving.response
self.stage = 'run'
try:
self.error_response = cherrypy.HTTPError(500).set_response
self.method = method
path = path or "/"
self.query_string = query_string or ''
self.params = {}
# Compare request and server HTTP protocol versions, in case our
# server does not support the requested protocol. Limit our output
# to min(req, server). We want the following output:
# request server actual written supported response
# protocol protocol response protocol feature set
# a 1.0 1.0 1.0 1.0
# b 1.0 1.1 1.1 1.0
# c 1.1 1.0 1.0 1.0
# d 1.1 1.1 1.1 1.1
# Notice that, in (b), the response will be "HTTP/1.1" even though
# the client only understands 1.0. RFC 2616 10.5.6 says we should
# only return 505 if the _major_ version is different.
rp = int(req_protocol[5]), int(req_protocol[7])
sp = int(self.server_protocol[5]), int(self.server_protocol[7])
self.protocol = min(rp, sp)
response.headers.protocol = self.protocol
# Rebuild first line of the request (e.g. "GET /path HTTP/1.0").
url = path
if query_string:
url += '?' + query_string
self.request_line = '%s %s %s' % (method, url, req_protocol)
self.header_list = list(headers)
self.headers = httputil.HeaderMap()
self.rfile = rfile
self.body = None
self.cookie = SimpleCookie()
self.handler = None
# path_info should be the path from the
# app root (script_name) to the handler.
self.script_name = self.app.script_name
self.path_info = pi = path[len(self.script_name):]
self.stage = 'respond'
self.respond(pi)
except self.throws:
raise
except:
if self.throw_errors:
raise
else:
# Failure in setup, error handler or finalize. Bypass them.
# Can't use handle_error because we may not have hooks yet.
cherrypy.log(traceback=True, severity=40)
if self.show_tracebacks:
body = format_exc()
else:
body = ""
r = bare_error(body)
response.output_status, response.header_list, response.body = r
if self.method == "HEAD":
# HEAD requests MUST NOT return a message-body in the response.
response.body = []
try:
cherrypy.log.access()
except:
cherrypy.log.error(traceback=True)
if response.timed_out:
raise cherrypy.TimeoutError()
return response
# Uncomment for stage debugging
# stage = property(lambda self: self._stage, lambda self, v: print(v))
def respond(self, path_info):
"""Generate a response for the resource at self.path_info. (Core)"""
response = cherrypy.serving.response
try:
try:
try:
if self.app is None:
raise cherrypy.NotFound()
# Get the 'Host' header, so we can HTTPRedirect properly.
self.stage = 'process_headers'
self.process_headers()
# Make a copy of the class hooks
self.hooks = self.__class__.hooks.copy()
self.toolmaps = {}
self.stage = 'get_resource'
self.get_resource(path_info)
self.body = _cpreqbody.RequestBody(
self.rfile, self.headers, request_params=self.params)
self.namespaces(self.config)
self.stage = 'on_start_resource'
self.hooks.run('on_start_resource')
# Parse the querystring
self.stage = 'process_query_string'
self.process_query_string()
# Process the body
if self.process_request_body:
if self.method not in self.methods_with_bodies:
self.process_request_body = False
self.stage = 'before_request_body'
self.hooks.run('before_request_body')
if self.process_request_body:
self.body.process()
# Run the handler
self.stage = 'before_handler'
self.hooks.run('before_handler')
if self.handler:
self.stage = 'handler'
response.body = self.handler()
# Finalize
self.stage = 'before_finalize'
self.hooks.run('before_finalize')
response.finalize()
except (cherrypy.HTTPRedirect, cherrypy.HTTPError), inst:
inst.set_response()
self.stage = 'before_finalize (HTTPError)'
self.hooks.run('before_finalize')
response.finalize()
finally:
self.stage = 'on_end_resource'
self.hooks.run('on_end_resource')
except self.throws:
raise
except:
if self.throw_errors:
raise
self.handle_error()
def process_query_string(self):
"""Parse the query string into Python structures. (Core)"""
try:
p = httputil.parse_query_string(
self.query_string, encoding=self.query_string_encoding)
except UnicodeDecodeError:
raise cherrypy.HTTPError(
404, "The given query string could not be processed. Query "
"strings for this resource must be encoded with %r." %
self.query_string_encoding)
# Python 2 only: keyword arguments must be byte strings (type 'str').
for key, value in p.items():
if isinstance(key, unicode):
del p[key]
p[key.encode(self.query_string_encoding)] = value
self.params.update(p)
def process_headers(self):
"""Parse HTTP header data into Python structures. (Core)"""
# Process the headers into self.headers
headers = self.headers
for name, value in self.header_list:
# Call title() now (and use dict.__method__(headers))
# so title doesn't have to be called twice.
name = name.title()
value = value.strip()
# Warning: if there is more than one header entry for cookies (AFAIK,
# only Konqueror does that), only the last one will remain in headers
# (but they will be correctly stored in request.cookie).
if "=?" in value:
dict.__setitem__(headers, name, httputil.decode_TEXT(value))
else:
dict.__setitem__(headers, name, value)
# Handle cookies differently because on Konqueror, multiple
# cookies come on different lines with the same key
if name == 'Cookie':
try:
self.cookie.load(value)
except CookieError:
msg = "Illegal cookie name %s" % value.split('=')[0]
raise cherrypy.HTTPError(400, msg)
if not dict.__contains__(headers, 'Host'):
# All Internet-based HTTP/1.1 servers MUST respond with a 400
# (Bad Request) status code to any HTTP/1.1 request message
# which lacks a Host header field.
if self.protocol >= (1, 1):
msg = "HTTP/1.1 requires a 'Host' request header."
raise cherrypy.HTTPError(400, msg)
host = dict.get(headers, 'Host')
if not host:
host = self.local.name or self.local.ip
self.base = "%s://%s" % (self.scheme, host)
def get_resource(self, path):
"""Call a dispatcher (which sets self.handler and .config). (Core)"""
# First, see if there is a custom dispatch at this URI. Custom
# dispatchers can only be specified in app.config, not in _cp_config
# (since custom dispatchers may not even have an app.root).
dispatch = self.app.find_config(path, "request.dispatch", self.dispatch)
# dispatch() should set self.handler and self.config
dispatch(path)
def handle_error(self):
"""Handle the last unanticipated exception. (Core)"""
try:
self.hooks.run("before_error_response")
if self.error_response:
self.error_response()
self.hooks.run("after_error_response")
cherrypy.serving.response.finalize()
except cherrypy.HTTPRedirect, inst:
inst.set_response()
cherrypy.serving.response.finalize()
# ------------------------- Properties ------------------------- #
def _get_body_params(self):
warnings.warn(
"body_params is deprecated in CherryPy 3.2, will be removed in "
"CherryPy 3.3.",
DeprecationWarning
)
return self.body.params
body_params = property(_get_body_params,
doc="""
If the request Content-Type is 'application/x-www-form-urlencoded' or
multipart, this will be a dict of the params pulled from the entity
body; that is, it will be the portion of request.params that come
from the message body (sometimes called "POST params", although they
can be sent with various HTTP method verbs). This value is set between
the 'before_request_body' and 'before_handler' hooks (assuming that
process_request_body is True).
Deprecated in 3.2, will be removed for 3.3""")
class ResponseBody(object):
"""The body of the HTTP response (the response entity)."""
def __get__(self, obj, objclass=None):
if obj is None:
# When calling on the class instead of an instance...
return self
else:
return obj._body
def __set__(self, obj, value):
# Convert the given value to an iterable object.
if isinstance(value, basestring):
# strings get wrapped in a list because iterating over a single
# item list is much faster than iterating over every character
# in a long string.
if value:
value = [value]
else:
# [''] doesn't evaluate to False, so replace it with [].
value = []
elif isinstance(value, types.FileType):
value = file_generator(value)
elif value is None:
value = []
obj._body = value
class Response(object):
"""An HTTP Response, including status, headers, and body.
Application developers should use Response.headers (a dict) to
set or modify HTTP response headers. When the response is finalized,
Response.headers is transformed into Response.header_list as
(key, value) tuples.
"""
__metaclass__ = cherrypy._AttributeDocstrings
# Class attributes for dev-time introspection.
status = ""
status__doc = """The HTTP Status-Code and Reason-Phrase."""
header_list = []
header_list__doc = """
A list of the HTTP response headers as (name, value) tuples.
In general, you should use response.headers (a dict) instead."""
headers = httputil.HeaderMap()
headers__doc = """
A dict-like object containing the response headers. Keys are header
names (in Title-Case format); however, you may get and set them in
a case-insensitive manner. That is, headers['Content-Type'] and
headers['content-type'] refer to the same value. Values are header
values (decoded according to RFC 2047 if necessary). See also:
httputil.HeaderMap, httputil.HeaderElement."""
cookie = SimpleCookie()
cookie__doc = """See help(Cookie)."""
body = ResponseBody()
body__doc = """The body (entity) of the HTTP response."""
time = None
time__doc = """The value of time.time() when created. Use in HTTP dates."""
timeout = 300
timeout__doc = """Seconds after which the response will be aborted."""
timed_out = False
timed_out__doc = """
Flag to indicate the response should be aborted, because it has
exceeded its timeout."""
stream = False
stream__doc = """If False, buffer the response body."""
def __init__(self):
self.status = None
self.header_list = None
self._body = []
self.time = time.time()
self.headers = httputil.HeaderMap()
# Since we know all our keys are titled strings, we can
# bypass HeaderMap.update and get a big speed boost.
dict.update(self.headers, {
"Content-Type": 'text/html',
"Server": "CherryPy/" + cherrypy.__version__,
"Date": httputil.HTTPDate(self.time),
})
self.cookie = SimpleCookie()
def collapse_body(self):
"""Collapse self.body to a single string; replace it and return it."""
if isinstance(self.body, basestring):
return self.body
newbody = ''.join([chunk for chunk in self.body])
self.body = newbody
return newbody
def finalize(self):
"""Transform headers (and cookies) into self.header_list. (Core)"""
try:
code, reason, _ = httputil.valid_status(self.status)
except ValueError, x:
raise cherrypy.HTTPError(500, x.args[0])
headers = self.headers
self.output_status = str(code) + " " + headers.encode(reason)
if self.stream:
# The upshot: wsgiserver will chunk the response if
# you pop Content-Length (or set it explicitly to None).
# Note that lib.static sets C-L to the file's st_size.
if dict.get(headers, 'Content-Length') is None:
dict.pop(headers, 'Content-Length', None)
elif code < 200 or code in (204, 205, 304):
# "All 1xx (informational), 204 (no content),
# and 304 (not modified) responses MUST NOT
# include a message-body."
dict.pop(headers, 'Content-Length', None)
self.body = ""
else:
# Responses which are not streamed should have a Content-Length,
# but allow user code to set Content-Length if desired.
if dict.get(headers, 'Content-Length') is None:
content = self.collapse_body()
dict.__setitem__(headers, 'Content-Length', len(content))
# Transform our header dict into a list of tuples.
self.header_list = h = headers.output()
cookie = self.cookie.output()
if cookie:
for line in cookie.split("\n"):
if line.endswith("\r"):
# Python 2.4 emits cookies joined by LF but 2.5+ by CRLF.
line = line[:-1]
name, value = line.split(": ", 1)
if isinstance(name, unicode):
name = name.encode("ISO-8859-1")
if isinstance(value, unicode):
value = headers.encode(value)
h.append((name, value))
def check_timeout(self):
"""If now > self.time + self.timeout, set self.timed_out.
This purposefully sets a flag, rather than raising an error,
so that a monitor thread can interrupt the Response thread.
"""
if time.time() > self.time + self.timeout:
self.timed_out = True
|
gpl-3.0
|
[
199,
504,
14798,
492,
5870,
7810,
12,
14798,
547,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
2943,
199,
646,
3598,
199,
199,
646,
13397,
199,
504,
13397,
492,
485,
67,
657,
81,
2030,
12,
485,
1850,
888,
199,
504,
13397,
423,
67,
529,
451,
492,
1475,
63,
2804,
12,
18753,
63,
705,
199,
504,
13397,
14,
773,
492,
1455,
1974,
12,
570,
63,
4679,
421,
199,
533,
24837,
8,
785,
304,
272,
408,
33,
3233,
436,
2399,
3341,
26,
2449,
3489,
12,
7464,
12,
436,
2074,
1041,
2286,
636,
6577,
363,
275,
13397,
423,
1646,
3768,
5465,
2286,
3233,
275,
488,
272,
3233,
363,
1301,
275,
408,
272,
710,
18753,
4550,
626,
642,
24837,
909,
365,
19696,
12,
1314,
911,
272,
506,
2797,
1380,
314,
24837,
365,
2797,
1041,
2286,
2449,
3489,
275,
756,
272,
2449,
3489,
363,
1301,
275,
408,
272,
982,
715,
12,
314,
3233,
365,
17334,
370,
1255,
2755,
340,
1163,
13484,
272,
687,
314,
2011,
1240,
2376,
746,
4967,
1041,
2286,
7464,
275,
5238,
272,
7464,
363,
1301,
275,
408,
272,
25022,
314,
1865,
402,
6451,
367,
282,
769,
402,
24837,
83,
14,
8538,
3822,
5579,
272,
1077,
506,
13988,
370,
314,
6876,
6252,
359,
16,
12,
2948,
467,
1325,
1338,
9682,
272,
642,
1425,
787,
14712,
12,
465,
787,
27487,
1338,
1041,
2286,
2074,
275,
1052,
272,
2074,
363,
1301,
275,
408,
272,
437,
663,
402,
4252,
2368,
626,
911,
506,
3032,
370,
314,
272,
4550,
641,
1924,
1240,
1041,
2286,
347,
636,
826,
721,
277,
12,
3233,
12,
2449,
3489,
29,
403,
12,
7464,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
3058,
275,
3233,
2728,
340,
2449,
3489,
365,
488,
26,
288,
2449,
3489,
275,
2519,
8,
3058,
12,
298,
1633,
3489,
401,
756,
9,
267,
291,
14,
1633,
3489,
275,
2449,
3489,
2728,
340,
7464,
365,
488,
26,
288,
7464,
275,
2519,
8,
3058,
12,
298,
6693,
401,
5238,
9,
267,
291,
14,
6693,
275,
7464,
2728,
291,
14,
958,
275,
2074,
2286,
347,
636,
5730,
721,
277,
12,
1163,
304,
267,
372,
10467,
8,
277,
14,
6693,
12,
1163,
14,
6693,
9,
2286,
347,
636,
1250,
721,
277,
304,
267,
408,
2540,
291,
14,
3058,
3682,
277,
14,
958,
10477,
267,
372,
291,
14,
3058,
3682,
277,
14,
958,
9,
2286,
347,
636,
2722,
721,
277,
304,
267,
843,
275,
291,
855,
533,
363,
267,
372,
19426,
83,
4111,
83,
8,
3058,
2458,
82,
12,
2449,
3489,
2458,
82,
12,
7464,
2458,
82,
12,
450,
83,
2924,
355,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3108,
291,
14,
3058,
12,
673,
291,
14,
1633,
3489,
12,
291,
14,
6693,
12,
673,
3872,
3680,
904,
26861,
83,
2458,
82,
7,
450,
334,
75,
12,
373,
9,
2892,
367,
1022,
12,
373,
315,
291,
14,
958,
14,
1744,
5106,
1724,
421,
199,
533,
24837,
2956,
8,
807,
304,
272,
408,
33,
2341,
402,
1240,
4501,
370,
5548,
402,
13484,
334,
8481,
2251,
10477,
2286,
347,
636,
1222,
721,
1886,
12,
4501,
29,
403,
304,
267,
366,
275,
1211,
855,
1222,
721,
1886,
9,
267,
367,
299,
315,
4501,
503,
18410,
288,
366,
59,
80,
61,
275,
942,
267,
372,
366,
2286,
347,
636,
826,
721,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
986,
2286,
347,
6554,
8,
277,
12,
2376,
12,
3233,
12,
2449,
3489,
29,
403,
12,
7464,
29,
403,
12,
1011,
958,
304,
267,
408,
8310,
282,
892,
24837,
6326,
687,
314,
6841,
2368,
1041,
267,
291,
59,
1403,
1055,
740,
8,
8481,
8,
3058,
12,
2449,
3489,
12,
7464,
12,
1011,
958,
430,
2286,
347,
1255,
8,
277,
12,
2376,
304,
267,
408,
12049,
1006,
7264,
24837,
83,
334,
11948,
9,
367,
314,
1627,
2376,
1041,
267,
3178,
275,
488,
267,
12604,
275,
291,
59,
1403,
61,
267,
12604,
14,
3191,
342,
267,
367,
5759,
315,
12604,
26,
288,
327,
6601,
12604,
787,
17334,
370,
1255,
2755,
340,
11789,
737,
288,
327,
314,
2011,
5759,
1403,
2449,
14,
2136,
911,
5139,
943,
314,
5988,
12,
288,
327,
1325,
20320,
641,
370,
314,
2163,
5759,
14,
710,
1454,
4340,
288,
327,
370,
3631,
1006,
6661,
687,
1373,
402,
3520,
12604,
365,
288,
327,
370,
746,
14838,
436,
3631,
314,
8852,
1654,
14,
288,
340,
3178,
365,
488,
503,
5759,
14,
1633,
3489,
26,
355,
862,
26,
490,
5759,
342,
355,
871,
334,
31538,
12,
14838,
304,
490,
746,
355,
871,
334,
23438,
14,
12815,
12,
13397,
14,
2856,
7071,
12,
717,
13397,
14,
8405,
7071,
304,
490,
3178,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
355,
871,
26,
490,
3178,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
490,
13397,
14,
793,
8,
6894,
29,
549,
12,
25574,
29,
2167,
9,
267,
340,
3178,
26,
288,
746,
2286,
347,
636,
1574,
721,
277,
304,
267,
892,
1130,
275,
291,
855,
533,
4533,
267,
327,
2136,
883,
1133,
2951,
675,
283,
873,
7,
2952,
781,
2934,
6866,
402,
314,
267,
327,
17194,
1338,
334,
10885,
365,
282,
769,
9,
465,
5521,
14,
267,
367,
1022,
12,
373,
315,
291,
14,
1744,
837,
288,
892,
1130,
59,
75,
61,
275,
373,
5873,
267,
372,
892,
1130,
272,
1331,
275,
636,
1574,
363,
2286,
347,
636,
2722,
721,
277,
304,
267,
843,
275,
291,
855,
533,
363,
267,
372,
2071,
83,
4111,
83,
8,
3438,
2458,
82,
2924,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3108,
291,
14,
1612,
1012,
421,
199,
3,
4094,
3231,
8297,
199,
199,
318,
12604,
63,
3251,
8,
75,
12,
373,
304,
272,
408,
13240,
18753,
12604,
14290,
315,
1101,
1041,
272,
327,
3645,
3715,
4020,
370,
2040,
3663,
12604,
367,
282,
2849,
272,
327,
5759,
1403,
1126,
931,
334,
69,
14,
71,
14,
298,
7922,
14,
5182,
63,
2232,
14,
17,
3471,
272,
327,
491,
390,
1118,
13,
3159,
10572,
1265,
1454,
664,
687,
7664,
1350,
8700,
9,
272,
5759,
1403,
275,
1022,
14,
1294,
30381,
413,
2788,
16,
61,
272,
340,
1228,
8,
86,
12,
7116,
304,
267,
373,
275,
13397,
14,
773,
14,
2987,
8,
86,
9,
272,
340,
440,
1228,
8,
86,
12,
24837,
304
] |
[
504,
14798,
492,
5870,
7810,
12,
14798,
547,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
2943,
199,
646,
3598,
199,
199,
646,
13397,
199,
504,
13397,
492,
485,
67,
657,
81,
2030,
12,
485,
1850,
888,
199,
504,
13397,
423,
67,
529,
451,
492,
1475,
63,
2804,
12,
18753,
63,
705,
199,
504,
13397,
14,
773,
492,
1455,
1974,
12,
570,
63,
4679,
421,
199,
533,
24837,
8,
785,
304,
272,
408,
33,
3233,
436,
2399,
3341,
26,
2449,
3489,
12,
7464,
12,
436,
2074,
1041,
2286,
636,
6577,
363,
275,
13397,
423,
1646,
3768,
5465,
2286,
3233,
275,
488,
272,
3233,
363,
1301,
275,
408,
272,
710,
18753,
4550,
626,
642,
24837,
909,
365,
19696,
12,
1314,
911,
272,
506,
2797,
1380,
314,
24837,
365,
2797,
1041,
2286,
2449,
3489,
275,
756,
272,
2449,
3489,
363,
1301,
275,
408,
272,
982,
715,
12,
314,
3233,
365,
17334,
370,
1255,
2755,
340,
1163,
13484,
272,
687,
314,
2011,
1240,
2376,
746,
4967,
1041,
2286,
7464,
275,
5238,
272,
7464,
363,
1301,
275,
408,
272,
25022,
314,
1865,
402,
6451,
367,
282,
769,
402,
24837,
83,
14,
8538,
3822,
5579,
272,
1077,
506,
13988,
370,
314,
6876,
6252,
359,
16,
12,
2948,
467,
1325,
1338,
9682,
272,
642,
1425,
787,
14712,
12,
465,
787,
27487,
1338,
1041,
2286,
2074,
275,
1052,
272,
2074,
363,
1301,
275,
408,
272,
437,
663,
402,
4252,
2368,
626,
911,
506,
3032,
370,
314,
272,
4550,
641,
1924,
1240,
1041,
2286,
347,
636,
826,
721,
277,
12,
3233,
12,
2449,
3489,
29,
403,
12,
7464,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
3058,
275,
3233,
2728,
340,
2449,
3489,
365,
488,
26,
288,
2449,
3489,
275,
2519,
8,
3058,
12,
298,
1633,
3489,
401,
756,
9,
267,
291,
14,
1633,
3489,
275,
2449,
3489,
2728,
340,
7464,
365,
488,
26,
288,
7464,
275,
2519,
8,
3058,
12,
298,
6693,
401,
5238,
9,
267,
291,
14,
6693,
275,
7464,
2728,
291,
14,
958,
275,
2074,
2286,
347,
636,
5730,
721,
277,
12,
1163,
304,
267,
372,
10467,
8,
277,
14,
6693,
12,
1163,
14,
6693,
9,
2286,
347,
636,
1250,
721,
277,
304,
267,
408,
2540,
291,
14,
3058,
3682,
277,
14,
958,
10477,
267,
372,
291,
14,
3058,
3682,
277,
14,
958,
9,
2286,
347,
636,
2722,
721,
277,
304,
267,
843,
275,
291,
855,
533,
363,
267,
372,
19426,
83,
4111,
83,
8,
3058,
2458,
82,
12,
2449,
3489,
2458,
82,
12,
7464,
2458,
82,
12,
450,
83,
2924,
355,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3108,
291,
14,
3058,
12,
673,
291,
14,
1633,
3489,
12,
291,
14,
6693,
12,
673,
3872,
3680,
904,
26861,
83,
2458,
82,
7,
450,
334,
75,
12,
373,
9,
2892,
367,
1022,
12,
373,
315,
291,
14,
958,
14,
1744,
5106,
1724,
421,
199,
533,
24837,
2956,
8,
807,
304,
272,
408,
33,
2341,
402,
1240,
4501,
370,
5548,
402,
13484,
334,
8481,
2251,
10477,
2286,
347,
636,
1222,
721,
1886,
12,
4501,
29,
403,
304,
267,
366,
275,
1211,
855,
1222,
721,
1886,
9,
267,
367,
299,
315,
4501,
503,
18410,
288,
366,
59,
80,
61,
275,
942,
267,
372,
366,
2286,
347,
636,
826,
721,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
986,
2286,
347,
6554,
8,
277,
12,
2376,
12,
3233,
12,
2449,
3489,
29,
403,
12,
7464,
29,
403,
12,
1011,
958,
304,
267,
408,
8310,
282,
892,
24837,
6326,
687,
314,
6841,
2368,
1041,
267,
291,
59,
1403,
1055,
740,
8,
8481,
8,
3058,
12,
2449,
3489,
12,
7464,
12,
1011,
958,
430,
2286,
347,
1255,
8,
277,
12,
2376,
304,
267,
408,
12049,
1006,
7264,
24837,
83,
334,
11948,
9,
367,
314,
1627,
2376,
1041,
267,
3178,
275,
488,
267,
12604,
275,
291,
59,
1403,
61,
267,
12604,
14,
3191,
342,
267,
367,
5759,
315,
12604,
26,
288,
327,
6601,
12604,
787,
17334,
370,
1255,
2755,
340,
11789,
737,
288,
327,
314,
2011,
5759,
1403,
2449,
14,
2136,
911,
5139,
943,
314,
5988,
12,
288,
327,
1325,
20320,
641,
370,
314,
2163,
5759,
14,
710,
1454,
4340,
288,
327,
370,
3631,
1006,
6661,
687,
1373,
402,
3520,
12604,
365,
288,
327,
370,
746,
14838,
436,
3631,
314,
8852,
1654,
14,
288,
340,
3178,
365,
488,
503,
5759,
14,
1633,
3489,
26,
355,
862,
26,
490,
5759,
342,
355,
871,
334,
31538,
12,
14838,
304,
490,
746,
355,
871,
334,
23438,
14,
12815,
12,
13397,
14,
2856,
7071,
12,
717,
13397,
14,
8405,
7071,
304,
490,
3178,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
355,
871,
26,
490,
3178,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
490,
13397,
14,
793,
8,
6894,
29,
549,
12,
25574,
29,
2167,
9,
267,
340,
3178,
26,
288,
746,
2286,
347,
636,
1574,
721,
277,
304,
267,
892,
1130,
275,
291,
855,
533,
4533,
267,
327,
2136,
883,
1133,
2951,
675,
283,
873,
7,
2952,
781,
2934,
6866,
402,
314,
267,
327,
17194,
1338,
334,
10885,
365,
282,
769,
9,
465,
5521,
14,
267,
367,
1022,
12,
373,
315,
291,
14,
1744,
837,
288,
892,
1130,
59,
75,
61,
275,
373,
5873,
267,
372,
892,
1130,
272,
1331,
275,
636,
1574,
363,
2286,
347,
636,
2722,
721,
277,
304,
267,
843,
275,
291,
855,
533,
363,
267,
372,
2071,
83,
4111,
83,
8,
3438,
2458,
82,
2924,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3108,
291,
14,
1612,
1012,
421,
199,
3,
4094,
3231,
8297,
199,
199,
318,
12604,
63,
3251,
8,
75,
12,
373,
304,
272,
408,
13240,
18753,
12604,
14290,
315,
1101,
1041,
272,
327,
3645,
3715,
4020,
370,
2040,
3663,
12604,
367,
282,
2849,
272,
327,
5759,
1403,
1126,
931,
334,
69,
14,
71,
14,
298,
7922,
14,
5182,
63,
2232,
14,
17,
3471,
272,
327,
491,
390,
1118,
13,
3159,
10572,
1265,
1454,
664,
687,
7664,
1350,
8700,
9,
272,
5759,
1403,
275,
1022,
14,
1294,
30381,
413,
2788,
16,
61,
272,
340,
1228,
8,
86,
12,
7116,
304,
267,
373,
275,
13397,
14,
773,
14,
2987,
8,
86,
9,
272,
340,
440,
1228,
8,
86,
12,
24837,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Semi-global/edx-platform
|
common/djangoapps/util/tests/test_memcache.py
|
84
|
3681
|
"""
Tests for memcache in util app
"""
from django.test import TestCase
from django.core.cache import get_cache
from util.memcache import safe_key
class MemcacheTest(TestCase):
"""
Test memcache key cleanup
"""
# Test whitespace, control characters, and some non-ASCII UTF-16
UNICODE_CHAR_CODES = (range(30) + [127] +
[129, 500, 2 ** 8 - 1, 2 ** 8 + 1, 2 ** 16 - 1])
def setUp(self):
super(MemcacheTest, self).setUp()
self.cache = get_cache('default')
def test_safe_key(self):
key = safe_key('test', 'prefix', 'version')
self.assertEqual(key, 'prefix:version:test')
def test_numeric_inputs(self):
# Numeric key
self.assertEqual(safe_key(1, 'prefix', 'version'), 'prefix:version:1')
# Numeric prefix
self.assertEqual(safe_key('test', 5, 'version'), '5:version:test')
# Numeric version
self.assertEqual(safe_key('test', 'prefix', 5), 'prefix:5:test')
def test_safe_key_long(self):
# Choose lengths close to memcached's cutoff (250)
for length in [248, 249, 250, 251, 252]:
# Generate a key of that length
key = 'a' * length
# Make the key safe
key = safe_key(key, '', '')
# The key should now be valid
self.assertTrue(self._is_valid_key(key),
msg="Failed for key length {0}".format(length))
def test_long_key_prefix_version(self):
# Long key
key = safe_key('a' * 300, 'prefix', 'version')
self.assertTrue(self._is_valid_key(key))
# Long prefix
key = safe_key('key', 'a' * 300, 'version')
self.assertTrue(self._is_valid_key(key))
# Long version
key = safe_key('key', 'prefix', 'a' * 300)
self.assertTrue(self._is_valid_key(key))
def test_safe_key_unicode(self):
for unicode_char in self.UNICODE_CHAR_CODES:
# Generate a key with that character
key = unichr(unicode_char)
# Make the key safe
key = safe_key(key, '', '')
# The key should now be valid
self.assertTrue(self._is_valid_key(key),
msg="Failed for unicode character {0}".format(unicode_char))
def test_safe_key_prefix_unicode(self):
for unicode_char in self.UNICODE_CHAR_CODES:
# Generate a prefix with that character
prefix = unichr(unicode_char)
# Make the key safe
key = safe_key('test', prefix, '')
# The key should now be valid
self.assertTrue(self._is_valid_key(key),
msg="Failed for unicode character {0}".format(unicode_char))
def test_safe_key_version_unicode(self):
for unicode_char in self.UNICODE_CHAR_CODES:
# Generate a version with that character
version = unichr(unicode_char)
# Make the key safe
key = safe_key('test', '', version)
# The key should now be valid
self.assertTrue(self._is_valid_key(key),
msg="Failed for unicode character {0}".format(unicode_char))
def _is_valid_key(self, key):
"""
Test that a key is memcache-compatible.
Based on Django's validator in core.cache.backends.base
"""
# Check the length
if len(key) > 250:
return False
# Check that there are no spaces or control characters
for char in key:
if ord(char) < 33 or ord(char) == 127:
return False
return True
|
agpl-3.0
|
[
624,
199,
2925,
367,
21598,
315,
4884,
1145,
199,
624,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1018,
14,
1637,
492,
664,
63,
1637,
199,
504,
4884,
14,
25835,
492,
5048,
63,
498,
421,
199,
533,
30465,
1637,
774,
8,
1746,
304,
272,
408,
272,
1379,
21598,
790,
9058,
272,
408,
339,
327,
1379,
8139,
12,
3304,
4110,
12,
436,
2005,
2222,
13,
12292,
9094,
13,
975,
272,
6778,
948,
9125,
63,
5901,
63,
15639,
275,
334,
1842,
8,
1216,
9,
435,
359,
4195,
61,
435,
2079,
359,
7263,
12,
6891,
12,
499,
1011,
1695,
446,
413,
12,
499,
1011,
1695,
435,
413,
12,
499,
1011,
3193,
446,
413,
566,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14169,
1637,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
1637,
275,
664,
63,
1637,
360,
885,
358,
339,
347,
511,
63,
3489,
63,
498,
8,
277,
304,
267,
790,
275,
5048,
63,
498,
360,
396,
297,
283,
1861,
297,
283,
1023,
358,
267,
291,
14,
629,
8,
498,
12,
283,
1861,
26,
1023,
26,
396,
358,
339,
347,
511,
63,
6677,
63,
3711,
8,
277,
304,
398,
327,
19378,
790,
267,
291,
14,
629,
8,
3489,
63,
498,
8,
17,
12,
283,
1861,
297,
283,
1023,
659,
283,
1861,
26,
1023,
26,
17,
358,
398,
327,
19378,
2403,
267,
291,
14,
629,
8,
3489,
63,
498,
360,
396,
297,
959,
12,
283,
1023,
659,
283,
21,
26,
1023,
26,
396,
358,
398,
327,
19378,
1015,
267,
291,
14,
629,
8,
3489,
63,
498,
360,
396,
297,
283,
1861,
297,
959,
395,
283,
1861,
26,
21,
26,
396,
358,
339,
347,
511,
63,
3489,
63,
498,
63,
2809,
8,
277,
304,
398,
327,
29826,
17464,
4002,
370,
7573,
5245,
1159,
17875,
334,
7991,
9,
267,
367,
2582,
315,
359,
11242,
12,
499,
1887,
12,
16074,
12,
499,
2869,
12,
27210,
2189,
953,
327,
7958,
282,
790,
402,
626,
2582,
288,
790,
275,
283,
65,
7,
627,
2582,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
8,
498,
12,
3260,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
790,
2582,
469,
16,
5469,
908,
8,
1267,
430,
339,
347,
511,
63,
2809,
63,
498,
63,
1861,
63,
1023,
8,
277,
304,
398,
327,
19944,
790,
267,
790,
275,
5048,
63,
498,
360,
65,
7,
627,
9601,
12,
283,
1861,
297,
283,
1023,
358,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
398,
327,
19944,
2403,
267,
790,
275,
5048,
63,
498,
360,
498,
297,
283,
65,
7,
627,
9601,
12,
283,
1023,
358,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
398,
327,
19944,
1015,
267,
790,
275,
5048,
63,
498,
360,
498,
297,
283,
1861,
297,
283,
65,
7,
627,
9601,
9,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
790,
543,
626,
4528,
288,
790,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
8,
498,
12,
3260,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
1861,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
2403,
543,
626,
4528,
288,
2403,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
360,
396,
297,
2403,
12,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
1023,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
1015,
543,
626,
4528,
288,
1015,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
360,
396,
297,
3260,
1015,
9,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
485,
374,
63,
1078,
63,
498,
8,
277,
12,
790,
304,
267,
408,
267,
1379,
626,
282,
790,
365,
21598,
13,
6490,
14,
267,
21311,
641,
5634,
1159,
11822,
315,
6170,
14,
1637,
14,
7765,
14,
1095,
267,
408,
398,
327,
2670,
314,
2582,
267,
340,
822,
8,
498,
9,
690,
16074,
26,
288,
372,
756,
398,
327,
2670,
626,
2337,
787,
949,
7883,
503,
3304,
4110,
267,
367,
1495,
315,
790,
26,
288,
340,
6206,
8,
1560,
9,
665,
9404,
503,
6206,
8,
1560,
9,
508,
12792,
26,
355,
372,
756,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2925,
367,
21598,
315,
4884,
1145,
199,
624,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1018,
14,
1637,
492,
664,
63,
1637,
199,
504,
4884,
14,
25835,
492,
5048,
63,
498,
421,
199,
533,
30465,
1637,
774,
8,
1746,
304,
272,
408,
272,
1379,
21598,
790,
9058,
272,
408,
339,
327,
1379,
8139,
12,
3304,
4110,
12,
436,
2005,
2222,
13,
12292,
9094,
13,
975,
272,
6778,
948,
9125,
63,
5901,
63,
15639,
275,
334,
1842,
8,
1216,
9,
435,
359,
4195,
61,
435,
2079,
359,
7263,
12,
6891,
12,
499,
1011,
1695,
446,
413,
12,
499,
1011,
1695,
435,
413,
12,
499,
1011,
3193,
446,
413,
566,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14169,
1637,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
1637,
275,
664,
63,
1637,
360,
885,
358,
339,
347,
511,
63,
3489,
63,
498,
8,
277,
304,
267,
790,
275,
5048,
63,
498,
360,
396,
297,
283,
1861,
297,
283,
1023,
358,
267,
291,
14,
629,
8,
498,
12,
283,
1861,
26,
1023,
26,
396,
358,
339,
347,
511,
63,
6677,
63,
3711,
8,
277,
304,
398,
327,
19378,
790,
267,
291,
14,
629,
8,
3489,
63,
498,
8,
17,
12,
283,
1861,
297,
283,
1023,
659,
283,
1861,
26,
1023,
26,
17,
358,
398,
327,
19378,
2403,
267,
291,
14,
629,
8,
3489,
63,
498,
360,
396,
297,
959,
12,
283,
1023,
659,
283,
21,
26,
1023,
26,
396,
358,
398,
327,
19378,
1015,
267,
291,
14,
629,
8,
3489,
63,
498,
360,
396,
297,
283,
1861,
297,
959,
395,
283,
1861,
26,
21,
26,
396,
358,
339,
347,
511,
63,
3489,
63,
498,
63,
2809,
8,
277,
304,
398,
327,
29826,
17464,
4002,
370,
7573,
5245,
1159,
17875,
334,
7991,
9,
267,
367,
2582,
315,
359,
11242,
12,
499,
1887,
12,
16074,
12,
499,
2869,
12,
27210,
2189,
953,
327,
7958,
282,
790,
402,
626,
2582,
288,
790,
275,
283,
65,
7,
627,
2582,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
8,
498,
12,
3260,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
790,
2582,
469,
16,
5469,
908,
8,
1267,
430,
339,
347,
511,
63,
2809,
63,
498,
63,
1861,
63,
1023,
8,
277,
304,
398,
327,
19944,
790,
267,
790,
275,
5048,
63,
498,
360,
65,
7,
627,
9601,
12,
283,
1861,
297,
283,
1023,
358,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
398,
327,
19944,
2403,
267,
790,
275,
5048,
63,
498,
360,
498,
297,
283,
65,
7,
627,
9601,
12,
283,
1023,
358,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
398,
327,
19944,
1015,
267,
790,
275,
5048,
63,
498,
360,
498,
297,
283,
1861,
297,
283,
65,
7,
627,
9601,
9,
267,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
790,
543,
626,
4528,
288,
790,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
8,
498,
12,
3260,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
1861,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
2403,
543,
626,
4528,
288,
2403,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
360,
396,
297,
2403,
12,
4074,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
511,
63,
3489,
63,
498,
63,
1023,
63,
2975,
8,
277,
304,
398,
367,
2649,
63,
1560,
315,
291,
14,
12819,
63,
5901,
63,
15639,
26,
953,
327,
7958,
282,
1015,
543,
626,
4528,
288,
1015,
275,
17742,
8,
2975,
63,
1560,
9,
953,
327,
4155,
314,
790,
5048,
288,
790,
275,
5048,
63,
498,
360,
396,
297,
3260,
1015,
9,
953,
327,
710,
790,
1077,
3063,
506,
1686,
288,
291,
14,
1815,
8,
277,
423,
374,
63,
1078,
63,
498,
8,
498,
395,
1169,
1499,
628,
4276,
367,
2649,
4528,
469,
16,
5469,
908,
8,
2975,
63,
1560,
430,
339,
347,
485,
374,
63,
1078,
63,
498,
8,
277,
12,
790,
304,
267,
408,
267,
1379,
626,
282,
790,
365,
21598,
13,
6490,
14,
267,
21311,
641,
5634,
1159,
11822,
315,
6170,
14,
1637,
14,
7765,
14,
1095,
267,
408,
398,
327,
2670,
314,
2582,
267,
340,
822,
8,
498,
9,
690,
16074,
26,
288,
372,
756,
398,
327,
2670,
626,
2337,
787,
949,
7883,
503,
3304,
4110,
267,
367,
1495,
315,
790,
26,
288,
340,
6206,
8,
1560,
9,
665,
9404,
503,
6206,
8,
1560,
9,
508,
12792,
26,
355,
372,
756,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0
] |
matthagy/physmath
|
physmath/test.py
|
1
|
1856
|
from reload import fixup
fixup(0)
from physmath.units import parse_unit as pu
from physmath.physnum import parse_physical_number as ppn
from physmath.convert import convert, convert_factor
from physmath.annotator import annotator
from physmath import layout
import browsemath.client
reload(browsemath.client)
from browsemath.client import show_math
if 0:
label = annotator.push('stuff')
T1 = ppn('34.54s C')
T2 = convert(T1, pu('K'))
print T1, T2
acc = annotator.pop(label)
print acc
es = layout.equation_set(u'Temperature convertion', acc)
show_math(es)
if 0:
label = annotator.push('stuff')
n1 = ppn('34.54s mmol C')
n2 = convert(n1, pu('mol'))
print n1, n2
acc = annotator.pop(label)
es = layout.equation_set(u'Molar convertion', acc)
es = layout.as_ml(es)
show_math(es)
if 1:
label = annotator.push('stuff')
n1 = ppn('1.03e5s yd3 deadly gas')
n2 = convert(n1, pu('gal'))
print n1, n2
acc = annotator.pop(label)
es = layout.equation_set(u'Volume convertion', acc)
es = layout.as_ml(es)
show_math(es)
if 0:
label = annotator.push('stuff')
n1 = ppn('1.03e5s mi run')
n2 = convert(n1, pu('nm'))
print n1, n2
acc = annotator.pop(label)
es = layout.equation_set(u'Length convertion', acc)
es = layout.as_ml(es)
show_math(es)
if 0:
label = annotator.push('stuff')
n1 = ppn('1.03s mM run')
n2 = convert(n1, pu('nmol/L'))
print n1, n2
acc = annotator.pop(label)
es = layout.equation_set(u'Concentration convertion', acc)
es = layout.as_ml(es)
show_math(es)
if 0:
r = convert_factor(ppn('10.3s g carbon'), ppn('1 mol'), ppn('12.01d g'))
acc = annotator.pop(label)
es = layout.equation_set(u'Concentration convertion', acc)
es = layout.as_ml(es)
show_math(es)
print r
|
apache-2.0
|
[
199,
504,
13101,
492,
28262,
199,
30284,
8,
16,
9,
199,
199,
504,
3945,
588,
3442,
14,
5260,
492,
2198,
63,
3248,
465,
18848,
199,
504,
3945,
588,
3442,
14,
26827,
1507,
492,
2198,
63,
15020,
63,
1955,
465,
299,
4812,
199,
504,
3945,
588,
3442,
14,
3916,
492,
3957,
12,
3957,
63,
4778,
199,
504,
3945,
588,
3442,
14,
3226,
707,
492,
7032,
707,
199,
504,
3945,
588,
3442,
492,
7054,
199,
199,
646,
19249,
3442,
14,
1258,
199,
9233,
8,
4570,
3442,
14,
1258,
9,
199,
504,
19249,
3442,
14,
1258,
492,
2498,
63,
3442,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
377,
17,
275,
299,
4812,
360,
1082,
14,
1477,
83,
445,
358,
272,
377,
18,
275,
3957,
8,
52,
17,
12,
18848,
360,
43,
1333,
272,
870,
377,
17,
12,
377,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
870,
6907,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
27409,
3818,
296,
297,
6907,
9,
339,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
1082,
14,
1477,
83,
8562,
393,
445,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
16924,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
45,
393,
285,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
413,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
69,
21,
83,
612,
68,
19,
12314,
590,
486,
305,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
27074,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
6464,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
421,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
69,
21,
83,
10684,
1255,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
10756,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
4625,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
83,
333,
45,
1255,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
10756,
393,
15,
44,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
714,
19722,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
519,
275,
3957,
63,
4778,
8,
802,
78,
360,
709,
14,
19,
83,
486,
9590,
13520,
659,
299,
4812,
360,
17,
22956,
659,
299,
4812,
360,
713,
14,
614,
68,
486,
1333,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
714,
19722,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
272,
870,
519,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
504,
13101,
492,
28262,
199,
30284,
8,
16,
9,
199,
199,
504,
3945,
588,
3442,
14,
5260,
492,
2198,
63,
3248,
465,
18848,
199,
504,
3945,
588,
3442,
14,
26827,
1507,
492,
2198,
63,
15020,
63,
1955,
465,
299,
4812,
199,
504,
3945,
588,
3442,
14,
3916,
492,
3957,
12,
3957,
63,
4778,
199,
504,
3945,
588,
3442,
14,
3226,
707,
492,
7032,
707,
199,
504,
3945,
588,
3442,
492,
7054,
199,
199,
646,
19249,
3442,
14,
1258,
199,
9233,
8,
4570,
3442,
14,
1258,
9,
199,
504,
19249,
3442,
14,
1258,
492,
2498,
63,
3442,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
377,
17,
275,
299,
4812,
360,
1082,
14,
1477,
83,
445,
358,
272,
377,
18,
275,
3957,
8,
52,
17,
12,
18848,
360,
43,
1333,
272,
870,
377,
17,
12,
377,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
870,
6907,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
27409,
3818,
296,
297,
6907,
9,
339,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
1082,
14,
1477,
83,
8562,
393,
445,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
16924,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
45,
393,
285,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
413,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
69,
21,
83,
612,
68,
19,
12314,
590,
486,
305,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
27074,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
6464,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
421,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
69,
21,
83,
10684,
1255,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
10756,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
4625,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
1768,
275,
7032,
707,
14,
5335,
360,
14573,
358,
272,
302,
17,
275,
299,
4812,
360,
17,
14,
1644,
83,
333,
45,
1255,
358,
272,
302,
18,
275,
3957,
8,
78,
17,
12,
18848,
360,
10756,
393,
15,
44,
1333,
272,
870,
302,
17,
12,
302,
18,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
714,
19722,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
199,
199,
692,
378,
26,
272,
519,
275,
3957,
63,
4778,
8,
802,
78,
360,
709,
14,
19,
83,
486,
9590,
13520,
659,
299,
4812,
360,
17,
22956,
659,
299,
4812,
360,
713,
14,
614,
68,
486,
1333,
272,
6907,
275,
7032,
707,
14,
1935,
8,
1302,
9,
272,
9455,
275,
7054,
14,
27247,
63,
409,
8,
85,
7,
714,
19722,
3818,
296,
297,
6907,
9,
272,
9455,
275,
7054,
14,
305,
63,
757,
8,
397,
9,
272,
2498,
63,
3442,
8,
397,
9,
272,
870,
519,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
kwyoung11/ciml
|
labs/lab6-NaiveBayes/binary.py
|
14
|
2673
|
"""
This defines an abstract class for binary classification. It supports
both online algorithms (like perceptron) and batch algorithm (like
gradient descent).
"""
import util
from numpy import *
class BinaryClassifier:
"""
Our abstract class.
If you implement this class, you must do one of the following:
(1) be online and implement 'nextExample' and 'nextIteration'
(2) be batch and implement 'train'
"""
def __init__(self, opts):
self.opts = opts
def setOption(self, optName, optVal):
"""
set a particular option
"""
self.opts[optName] = optVal
def isOnline(self):
"""
return True if you are an online algorithm
"""
def reset(self):
"""
Reset the state of an online learning to as if it had seen nothing
"""
def predict(self, X):
"""
X is a vector that we're supposed to make a prediction about.
Semantically, a return value <0 means class -1 and a return
value >=0 means class +1
"""
util.raiseNotDefined()
def predictAll(self, X):
"""
X is a matrix that we're supposed to make a bunch of predictions about.
Semantically, a return value <0 means class -1 and a return
value >=0 means class +1
"""
N,D = X.shape
Y = zeros(N)
for n in range(N):
Y[n] = self.predict(X[n,:])
return Y
def nextExample(self, X):
"""
(ONLINE ONLY)
X is a vector training example and Y is its associated class.
We're guaranteed that Y is either +1 or -1.
"""
util.raiseNotDefined()
def nextIteration(self):
"""
(ONLINE ONLY)
Indicates to us that we've made a complete pass through the
training data.
"""
util.raiseNotDefined()
def train(self, X, Y):
"""
(BATCH ONLY)
X is a matrix of data points, Y is a vector of +1/-1 classes.
"""
if self.online():
for epoch in range(self.opts['numEpoch']):
# loop over every data point
for n in range(X.shape[0]):
# supply the example to the online learner
self.nextExample(X[n], Y[n])
# tell the online learner that we're
# done with this iteration
self.nextIteration()
else:
util.raiseNotDefined()
def getRepresentation(self):
"""
Some algorithm-specific representation
"""
util.raiseNotDefined()
|
gpl-2.0
|
[
624,
199,
2765,
7890,
376,
9006,
1021,
367,
3366,
12505,
14,
221,
2779,
5171,
199,
10727,
18470,
18036,
334,
2930,
1126,
301,
4695,
265,
9,
436,
3522,
5563,
334,
2930,
199,
7490,
31518,
680,
199,
624,
4388,
199,
646,
4884,
199,
504,
2680,
492,
627,
199,
199,
533,
14161,
8508,
26,
272,
408,
272,
25119,
9006,
1021,
14,
339,
982,
1265,
5669,
642,
1021,
12,
1265,
1471,
886,
1373,
402,
314,
2569,
26,
489,
334,
17,
9,
506,
18470,
436,
5669,
283,
2184,
9846,
7,
436,
283,
2184,
8666,
7,
489,
334,
18,
9,
506,
3522,
221,
436,
5669,
283,
2834,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3999,
304,
267,
291,
14,
3291,
275,
3999,
339,
347,
663,
2602,
8,
277,
12,
2450,
985,
12,
2450,
7562,
304,
267,
408,
267,
663,
282,
6770,
945,
267,
408,
267,
291,
14,
3291,
59,
2992,
985,
61,
275,
2450,
7562,
339,
347,
365,
28587,
8,
277,
304,
267,
408,
267,
372,
715,
340,
1265,
787,
376,
18470,
5563,
267,
408,
339,
347,
5305,
8,
277,
304,
267,
408,
267,
15510,
314,
1174,
402,
376,
18470,
9328,
370,
465,
340,
652,
10530,
6775,
6548,
267,
408,
5493,
347,
12610,
8,
277,
12,
1323,
304,
267,
408,
267,
1323,
365,
282,
5477,
626,
781,
3984,
20042,
370,
1852,
282,
12044,
3595,
14,
267,
3240,
1237,
17269,
12,
282,
372,
574,
665,
16,
4910,
1021,
446,
17,
436,
282,
372,
267,
574,
2356,
16,
4910,
1021,
435,
17,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
12610,
2422,
8,
277,
12,
1323,
304,
267,
408,
267,
1323,
365,
282,
3634,
626,
781,
3984,
20042,
370,
1852,
282,
22219,
402,
7914,
3595,
14,
267,
3240,
1237,
17269,
12,
282,
372,
574,
665,
16,
4910,
1021,
446,
17,
436,
282,
372,
267,
574,
2356,
16,
4910,
1021,
435,
17,
267,
408,
267,
653,
12,
36,
275,
1323,
14,
1392,
267,
1488,
257,
275,
10136,
8,
46,
9,
267,
367,
302,
315,
1425,
8,
46,
304,
288,
1488,
59,
78,
61,
275,
291,
14,
6892,
8,
56,
59,
78,
12,
5728,
267,
372,
1488,
339,
347,
2163,
9846,
8,
277,
12,
1323,
304,
267,
408,
267,
334,
615,
6174,
5258,
6084,
9,
2728,
1323,
365,
282,
5477,
6093,
2893,
436,
1488,
365,
2399,
4568,
1021,
14,
267,
2136,
3984,
17334,
626,
1488,
365,
1902,
435,
17,
503,
446,
17,
14,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
2163,
8666,
8,
277,
304,
267,
408,
267,
334,
615,
6174,
5258,
6084,
9,
2728,
19334,
370,
2739,
626,
781,
9064,
6326,
282,
4890,
986,
4012,
314,
267,
6093,
666,
14,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
3560,
8,
277,
12,
1323,
12,
1488,
304,
267,
408,
267,
334,
20813,
5258,
6084,
9,
398,
1323,
365,
282,
3634,
402,
666,
4501,
12,
1488,
365,
282,
5477,
402,
435,
17,
22551,
17,
3992,
14,
267,
408,
267,
340,
291,
14,
15178,
837,
288,
367,
9463,
315,
1425,
8,
277,
14,
3291,
459,
1507,
29322,
9090,
355,
327,
4438,
1806,
4036,
666,
2376,
355,
367,
302,
315,
1425,
8,
56,
14,
1392,
59,
16,
4682,
490,
327,
17169,
314,
2893,
370,
314,
18470,
22876,
490,
291,
14,
2184,
9846,
8,
56,
59,
78,
467,
1488,
59,
78,
566,
2234,
327,
11480,
314,
18470,
22876,
626,
781,
3984,
355,
327,
4224,
543,
642,
8494,
355,
291,
14,
2184,
8666,
342,
267,
587,
26,
288,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
664,
20609,
8,
277,
304,
267,
408,
267,
6601,
5563,
13,
6100,
6025,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2765,
7890,
376,
9006,
1021,
367,
3366,
12505,
14,
221,
2779,
5171,
199,
10727,
18470,
18036,
334,
2930,
1126,
301,
4695,
265,
9,
436,
3522,
5563,
334,
2930,
199,
7490,
31518,
680,
199,
624,
4388,
199,
646,
4884,
199,
504,
2680,
492,
627,
199,
199,
533,
14161,
8508,
26,
272,
408,
272,
25119,
9006,
1021,
14,
339,
982,
1265,
5669,
642,
1021,
12,
1265,
1471,
886,
1373,
402,
314,
2569,
26,
489,
334,
17,
9,
506,
18470,
436,
5669,
283,
2184,
9846,
7,
436,
283,
2184,
8666,
7,
489,
334,
18,
9,
506,
3522,
221,
436,
5669,
283,
2834,
7,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3999,
304,
267,
291,
14,
3291,
275,
3999,
339,
347,
663,
2602,
8,
277,
12,
2450,
985,
12,
2450,
7562,
304,
267,
408,
267,
663,
282,
6770,
945,
267,
408,
267,
291,
14,
3291,
59,
2992,
985,
61,
275,
2450,
7562,
339,
347,
365,
28587,
8,
277,
304,
267,
408,
267,
372,
715,
340,
1265,
787,
376,
18470,
5563,
267,
408,
339,
347,
5305,
8,
277,
304,
267,
408,
267,
15510,
314,
1174,
402,
376,
18470,
9328,
370,
465,
340,
652,
10530,
6775,
6548,
267,
408,
5493,
347,
12610,
8,
277,
12,
1323,
304,
267,
408,
267,
1323,
365,
282,
5477,
626,
781,
3984,
20042,
370,
1852,
282,
12044,
3595,
14,
267,
3240,
1237,
17269,
12,
282,
372,
574,
665,
16,
4910,
1021,
446,
17,
436,
282,
372,
267,
574,
2356,
16,
4910,
1021,
435,
17,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
12610,
2422,
8,
277,
12,
1323,
304,
267,
408,
267,
1323,
365,
282,
3634,
626,
781,
3984,
20042,
370,
1852,
282,
22219,
402,
7914,
3595,
14,
267,
3240,
1237,
17269,
12,
282,
372,
574,
665,
16,
4910,
1021,
446,
17,
436,
282,
372,
267,
574,
2356,
16,
4910,
1021,
435,
17,
267,
408,
267,
653,
12,
36,
275,
1323,
14,
1392,
267,
1488,
257,
275,
10136,
8,
46,
9,
267,
367,
302,
315,
1425,
8,
46,
304,
288,
1488,
59,
78,
61,
275,
291,
14,
6892,
8,
56,
59,
78,
12,
5728,
267,
372,
1488,
339,
347,
2163,
9846,
8,
277,
12,
1323,
304,
267,
408,
267,
334,
615,
6174,
5258,
6084,
9,
2728,
1323,
365,
282,
5477,
6093,
2893,
436,
1488,
365,
2399,
4568,
1021,
14,
267,
2136,
3984,
17334,
626,
1488,
365,
1902,
435,
17,
503,
446,
17,
14,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
2163,
8666,
8,
277,
304,
267,
408,
267,
334,
615,
6174,
5258,
6084,
9,
2728,
19334,
370,
2739,
626,
781,
9064,
6326,
282,
4890,
986,
4012,
314,
267,
6093,
666,
14,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
3560,
8,
277,
12,
1323,
12,
1488,
304,
267,
408,
267,
334,
20813,
5258,
6084,
9,
398,
1323,
365,
282,
3634,
402,
666,
4501,
12,
1488,
365,
282,
5477,
402,
435,
17,
22551,
17,
3992,
14,
267,
408,
267,
340,
291,
14,
15178,
837,
288,
367,
9463,
315,
1425,
8,
277,
14,
3291,
459,
1507,
29322,
9090,
355,
327,
4438,
1806,
4036,
666,
2376,
355,
367,
302,
315,
1425,
8,
56,
14,
1392,
59,
16,
4682,
490,
327,
17169,
314,
2893,
370,
314,
18470,
22876,
490,
291,
14,
2184,
9846,
8,
56,
59,
78,
467,
1488,
59,
78,
566,
2234,
327,
11480,
314,
18470,
22876,
626,
781,
3984,
355,
327,
4224,
543,
642,
8494,
355,
291,
14,
2184,
8666,
342,
267,
587,
26,
288,
4884,
14,
3730,
1763,
18718,
342,
339,
347,
664,
20609,
8,
277,
304,
267,
408,
267,
6601,
5563,
13,
6100,
6025,
267,
408,
267,
4884,
14,
3730,
1763,
18718,
342,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nitzanm/boundary-plugin-aws-rds-python
|
boundary_aws_plugin/cloudwatch_metrics.py
|
5
|
8218
|
from __future__ import (absolute_import, division, print_function, unicode_literals)
import boto
import boto.ec2.cloudwatch
import datetime
import logging
import abc
__version__ = '1.1.0'
class CloudwatchMetrics(object):
__metaclass__ = abc.ABCMeta
def __init__(self, access_key_id, secret_access_key, cloudwatch_namespace):
"""
Initializes the class.
@param access_key_id AWS Access Key ID.
@param secret_access_key AWS Secret Access Key.
@param cloudwatch_namespace The namespace of all metrics this class will
request from CloudWatch, e.g. 'AWS/ELB'.
"""
self.access_key_id, self.secret_access_key = access_key_id, secret_access_key
self.cloudwatch_namespace = cloudwatch_namespace
@abc.abstractmethod
def get_region_list(self):
"""
Returns a list of boto.regioninfo.RegionInfo objects for all regions this class
will be getting metrics for.
Abstract method, to be implemented by child classes.
"""
raise NotImplementedError()
@abc.abstractmethod
def get_entities_for_region(self, region):
"""
Returns a list of entities to get metrics for in a given region.
@param region The boto.regioninfo.RegionInfo object for the region to get entities for.
Abstract method, to be implemented by child classes.
"""
raise NotImplementedError()
@abc.abstractmethod
def get_entity_dimensions(self, region, entity):
"""
Returns a dictionary of dimensions needed to get metrics for a given entity (this
will be an entity returned by get_entities_for_region).
Abstract method, to be implemented by child classes.
"""
raise NotImplementedError()
def get_entity_source_name(self, entity):
"""
Returns the source name to be reported for an entity
(typically, this will be the entity's name). Override if the entities used
in a child class do not have a "name" property.
"""
return entity.name
@abc.abstractmethod
def get_metric_list(self):
"""
Returns a list of metrics to be retrieved for each entity.
Each tuple in the list should have the form
(metric_name, statistic, metric_name_id, [metric_description])
where
metric_name is the AWS metric name (e.g. HTTPCode_ELB_4XX)
statistic is the statistic to collect (e.g. Sum or Average)
metric_name_id is the metric identifier in Boundary (e.g. AWS_ELB_HTTP_CODE_4XX)
metric_description is an optional metric description (not used by the plugin directly)
Abstract method, to be implemented by child classes.
"""
raise NotImplementedError()
def get_metric_data(self, only_latest=True, start_time=None, end_time=None):
"""
Retrieves AWS ELB metrics from CloudWatch.
@param only_latest True to return only the single latest sample for each metric; False to return
all the metrics returned between start_time and end_time.
@param start_time The earliest metric time to retrieve (inclusive); defaults to 20 minutes before end_time.
@param end_time The latest metric time to retrieve (exclusive); defaults to now.
@return A dictionary, in the following format:
{(RegionId, EntityName, MetricName): [(Timestamp, Value, Statistic), (Timestamp, Value, Statistic), ...],
(RegionId, EntityName, MetricName): [(Timestamp, Value, Statistic), (Timestamp, Value, Statistic), ...], ...}
That is, the dictionary keys are tuples of the region, entity name and metric name, and the
dictionary values are lists of tuples of timestamp, value and statistic (TVS). The TVS lists are
guaranteed to be sorted in ascending order (latest timestamp last).
If only_latest is True, each TVS list is guaranteed to have at most one
value (but may have zero if no data is available for the requested range).
@note AWS reports metrics in either 60-second or 5-minute intervals, depending on monitoring service level and metric.
Keep in mind that even if end_time is now, the latest datapoint returned may be up to 5 minutes in the past.
@note The Timestamp value will be for the *beginning* of each period. For example, for a period of 60 seconds, a metric
returned with a timestamp of 11:23 will be for the period of [11:23, 11:24); or the period of 11:23:00 through 11:23:59.999.
"""
logger = logging.getLogger('CloudwatchMetrics')
# Note: although we want a 60-second period, not all CloudWatch metrics are provided in 60-second
# periods, depending on service level and metric. Instead, query the last 20 minutes, and take
# the latest period we can get.
period = 60
end_time = end_time or datetime.datetime.utcnow()
start_time = start_time or (end_time - datetime.timedelta(minutes=20))
# CloudWatch can return a maximum of 1,440 datapoints in a single call. With a period of 60 seconds, that
# works out to 1,440 minutes = 24 hours. If we need more than 24 hours of data, split into a number of
# calls. To prevent off-by-one issues, use 23 hours as the maximum time.
time_ranges = []
while end_time - start_time > datetime.timedelta(hours=23):
block_end = start_time + datetime.timedelta(hours=23)
time_ranges.append((start_time, block_end))
start_time = block_end
# Use a 30-second buffer for equality checks so we ignore things like leap seconds
# (the CloudWatch period is 60 seconds anyway, so any less than that doesn't matter)
if end_time - start_time > datetime.timedelta(seconds=30):
time_ranges.append((start_time, end_time))
out = dict()
for region in self.get_region_list():
logger.info("Region: %s", region.name)
cw = boto.ec2.cloudwatch.connect_to_region(region.name, aws_access_key_id=self.access_key_id, aws_secret_access_key=self.secret_access_key)
entities = self.get_entities_for_region(region)
for entity in entities:
logger.info("\tEntity: %s" % self.get_entity_source_name(entity))
for metric in self.get_metric_list():
metric_name, metric_statistic, metric_boundary_id = metric[:3]
metric_scale = metric[3] if len(metric) > 3 else 1
logger.info("\t\tMetric: %s %s %s" % (metric_name, metric_statistic, metric_boundary_id))
data = []
for st, et in time_ranges:
data.extend(cw.get_metric_statistics(period=period, start_time=st, end_time=et,
metric_name=metric_name, namespace=self.cloudwatch_namespace,
statistics=metric_statistic,
dimensions=self.get_entity_dimensions(region, entity)))
if not data:
logger.info("\t\t\tNo data")
continue
if only_latest:
# Pick out the latest sample only
data = [max(data, key=lambda d: d['Timestamp'])]
else:
# Output all retrieved samples as a list, sorted by timestamp
data = sorted(data, key=lambda d: d['Timestamp'])
out_metric = []
for sample in data:
sample[metric_statistic] *= metric_scale
logger.info("\t\t\tValue: %s: %s" % (sample['Timestamp'], sample[metric_statistic]))
out_metric.append((sample['Timestamp'], sample[metric_statistic], metric_statistic))
out[(region.name, self.get_entity_source_name(entity), metric_boundary_id)] = out_metric
return out
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
646,
6055,
199,
646,
6055,
14,
825,
18,
14,
4091,
6821,
199,
646,
2197,
199,
646,
2050,
199,
646,
13022,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
17,
14,
16,
7,
421,
199,
533,
8142,
6821,
17213,
8,
785,
304,
272,
636,
6577,
363,
275,
13022,
14,
22254,
339,
347,
636,
826,
721,
277,
12,
2879,
63,
498,
63,
344,
12,
7565,
63,
2732,
63,
498,
12,
8002,
6821,
63,
3251,
304,
267,
408,
267,
6026,
6491,
314,
1021,
14,
267,
768,
635,
2879,
63,
498,
63,
344,
10168,
11003,
2606,
2870,
14,
267,
768,
635,
7565,
63,
2732,
63,
498,
10168,
23580,
11003,
2606,
14,
267,
768,
635,
8002,
6821,
63,
3251,
710,
3231,
402,
1006,
7186,
642,
1021,
911,
288,
1056,
687,
8142,
13978,
12,
325,
14,
71,
14,
283,
13226,
15,
2901,
34,
1370,
267,
408,
267,
291,
14,
2732,
63,
498,
63,
344,
12,
291,
14,
4731,
63,
2732,
63,
498,
275,
2879,
63,
498,
63,
344,
12,
7565,
63,
2732,
63,
498,
267,
291,
14,
4091,
6821,
63,
3251,
275,
8002,
6821,
63,
3251,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
4551,
63,
513,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
6055,
14,
4551,
815,
14,
10708,
2354,
2251,
367,
1006,
16150,
642,
1021,
267,
911,
506,
10232,
7186,
367,
14,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
8327,
63,
509,
63,
4551,
8,
277,
12,
4897,
304,
267,
408,
267,
1803,
282,
769,
402,
9045,
370,
664,
7186,
367,
315,
282,
1627,
4897,
14,
267,
768,
635,
4897,
710,
6055,
14,
4551,
815,
14,
10708,
2354,
909,
367,
314,
4897,
370,
664,
9045,
367,
14,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
4502,
63,
13320,
8,
277,
12,
4897,
12,
4642,
304,
267,
408,
267,
1803,
282,
2600,
402,
7365,
4346,
370,
664,
7186,
367,
282,
1627,
4642,
334,
3749,
267,
911,
506,
376,
4642,
2138,
701,
664,
63,
8327,
63,
509,
63,
4551,
680,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
664,
63,
4502,
63,
1365,
63,
354,
8,
277,
12,
4642,
304,
267,
408,
267,
1803,
314,
1350,
536,
370,
506,
14581,
367,
376,
4642,
267,
334,
32251,
12,
642,
911,
506,
314,
4642,
1159,
536,
680,
221,
11041,
340,
314,
9045,
1202,
267,
315,
282,
1982,
1021,
886,
440,
1172,
282,
298,
354,
2,
3324,
14,
267,
408,
267,
372,
4642,
14,
354,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
5165,
63,
513,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
7186,
370,
506,
12396,
367,
1924,
4642,
14,
267,
7048,
2008,
315,
314,
769,
1077,
1172,
314,
1824,
288,
334,
5165,
63,
354,
12,
22394,
12,
6370,
63,
354,
63,
344,
12,
359,
5165,
63,
1802,
566,
267,
2382,
288,
6370,
63,
354,
365,
314,
10168,
6370,
536,
334,
69,
14,
71,
14,
3101,
3034,
63,
2901,
34,
63,
20,
2483,
9,
288,
22394,
365,
314,
22394,
370,
8775,
334,
69,
14,
71,
14,
12094,
503,
437,
3652,
9,
288,
6370,
63,
354,
63,
344,
365,
314,
6370,
5148,
315,
21972,
695,
334,
69,
14,
71,
14,
10168,
63,
2901,
34,
63,
2856,
63,
6012,
63,
20,
2483,
9,
288,
6370,
63,
1802,
365,
376,
2716,
6370,
1369,
334,
1397,
1202,
701,
314,
3589,
5370,
9,
398,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
664,
63,
5165,
63,
576,
8,
277,
12,
1454,
63,
7410,
29,
549,
12,
1343,
63,
521,
29,
403,
12,
1284,
63,
521,
29,
403,
304,
267,
408,
267,
27940,
10168,
662,
11568,
7186,
687,
8142,
13978,
14,
267,
768,
635,
1454,
63,
7410,
715,
370,
372,
1454,
314,
2849,
8839,
2690,
367,
1924,
6370,
27,
756,
370,
372,
288,
1006,
314,
7186,
2138,
3382,
1343,
63,
521,
436,
1284,
63,
521,
14,
267,
768,
635,
1343,
63,
521,
710,
8413,
24951,
6370,
900,
370,
8044,
334,
26062,
2736,
4243,
370,
3388,
9395,
2544,
1284,
63,
521,
14,
267,
768,
635,
1284,
63,
521,
710,
8839,
6370,
900,
370,
8044,
334,
12730,
2736,
4243,
370,
3063,
14,
267,
768,
1107,
437,
2600,
12,
315,
314,
2569,
1475,
26,
288,
26458,
10708,
1304,
12,
17680,
985,
12,
22465,
985,
304,
3842,
10239,
12,
1594,
12,
7083,
19940,
395,
334,
10239,
12,
1594,
12,
7083,
19940,
395,
2263,
467,
1467,
334,
10708,
1304,
12,
17680,
985,
12,
22465,
985,
304,
3842,
10239,
12,
1594,
12,
7083,
19940,
395,
334,
10239,
12,
1594,
12,
7083,
19940,
395,
2263,
467,
2263,
93,
288,
10314,
365,
12,
314,
2600,
2883,
787,
6346,
402,
314,
4897,
12,
4642,
536,
436,
6370,
536,
12,
436,
314,
288,
2600,
1338,
787,
5548,
402,
6346,
402,
4913,
12,
574,
436,
22394,
334,
52,
7428,
680,
221,
710,
377,
7428,
5548,
787,
288,
17334,
370,
506,
3355,
315,
24525,
1865,
334,
7410,
4913,
2061,
680,
288,
982,
1454,
63,
7410,
365,
715,
12,
1924,
377,
7428,
769,
365,
17334,
370,
1172,
737,
4750,
1373,
288,
574,
334,
7911,
1443,
1172,
4697,
340,
949,
666,
365,
2808,
367,
314,
5839,
1425,
680,
398,
768,
4610,
10168,
13924,
7186,
315,
1902,
5212,
13,
4375,
503,
959,
13,
10698,
15802,
12,
10298,
641,
20391,
2435,
2166,
436,
6370,
14,
288,
14797,
315,
25169,
626,
2755,
340,
1284,
63,
521,
365,
3063,
12,
314,
8839,
666,
1403,
2138,
1443,
506,
1536,
370,
959,
9395,
315,
314,
13541,
14,
267,
768,
4610,
710,
18267,
574,
911,
506,
367,
314,
627,
31272,
10,
402,
1924,
6247,
14,
221,
2104,
2893,
12,
367,
282,
6247,
402,
5212,
4696,
12,
282,
6370,
288,
2138,
543,
282,
4913,
402,
4119,
26,
1789,
911,
506,
367,
314,
6247,
402,
359,
845,
26,
1789,
12,
4119,
26,
1194
] |
[
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
646,
6055,
199,
646,
6055,
14,
825,
18,
14,
4091,
6821,
199,
646,
2197,
199,
646,
2050,
199,
646,
13022,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
17,
14,
16,
7,
421,
199,
533,
8142,
6821,
17213,
8,
785,
304,
272,
636,
6577,
363,
275,
13022,
14,
22254,
339,
347,
636,
826,
721,
277,
12,
2879,
63,
498,
63,
344,
12,
7565,
63,
2732,
63,
498,
12,
8002,
6821,
63,
3251,
304,
267,
408,
267,
6026,
6491,
314,
1021,
14,
267,
768,
635,
2879,
63,
498,
63,
344,
10168,
11003,
2606,
2870,
14,
267,
768,
635,
7565,
63,
2732,
63,
498,
10168,
23580,
11003,
2606,
14,
267,
768,
635,
8002,
6821,
63,
3251,
710,
3231,
402,
1006,
7186,
642,
1021,
911,
288,
1056,
687,
8142,
13978,
12,
325,
14,
71,
14,
283,
13226,
15,
2901,
34,
1370,
267,
408,
267,
291,
14,
2732,
63,
498,
63,
344,
12,
291,
14,
4731,
63,
2732,
63,
498,
275,
2879,
63,
498,
63,
344,
12,
7565,
63,
2732,
63,
498,
267,
291,
14,
4091,
6821,
63,
3251,
275,
8002,
6821,
63,
3251,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
4551,
63,
513,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
6055,
14,
4551,
815,
14,
10708,
2354,
2251,
367,
1006,
16150,
642,
1021,
267,
911,
506,
10232,
7186,
367,
14,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
8327,
63,
509,
63,
4551,
8,
277,
12,
4897,
304,
267,
408,
267,
1803,
282,
769,
402,
9045,
370,
664,
7186,
367,
315,
282,
1627,
4897,
14,
267,
768,
635,
4897,
710,
6055,
14,
4551,
815,
14,
10708,
2354,
909,
367,
314,
4897,
370,
664,
9045,
367,
14,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
4502,
63,
13320,
8,
277,
12,
4897,
12,
4642,
304,
267,
408,
267,
1803,
282,
2600,
402,
7365,
4346,
370,
664,
7186,
367,
282,
1627,
4642,
334,
3749,
267,
911,
506,
376,
4642,
2138,
701,
664,
63,
8327,
63,
509,
63,
4551,
680,
267,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
664,
63,
4502,
63,
1365,
63,
354,
8,
277,
12,
4642,
304,
267,
408,
267,
1803,
314,
1350,
536,
370,
506,
14581,
367,
376,
4642,
267,
334,
32251,
12,
642,
911,
506,
314,
4642,
1159,
536,
680,
221,
11041,
340,
314,
9045,
1202,
267,
315,
282,
1982,
1021,
886,
440,
1172,
282,
298,
354,
2,
3324,
14,
267,
408,
267,
372,
4642,
14,
354,
339,
768,
3175,
14,
10315,
272,
347,
664,
63,
5165,
63,
513,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
7186,
370,
506,
12396,
367,
1924,
4642,
14,
267,
7048,
2008,
315,
314,
769,
1077,
1172,
314,
1824,
288,
334,
5165,
63,
354,
12,
22394,
12,
6370,
63,
354,
63,
344,
12,
359,
5165,
63,
1802,
566,
267,
2382,
288,
6370,
63,
354,
365,
314,
10168,
6370,
536,
334,
69,
14,
71,
14,
3101,
3034,
63,
2901,
34,
63,
20,
2483,
9,
288,
22394,
365,
314,
22394,
370,
8775,
334,
69,
14,
71,
14,
12094,
503,
437,
3652,
9,
288,
6370,
63,
354,
63,
344,
365,
314,
6370,
5148,
315,
21972,
695,
334,
69,
14,
71,
14,
10168,
63,
2901,
34,
63,
2856,
63,
6012,
63,
20,
2483,
9,
288,
6370,
63,
1802,
365,
376,
2716,
6370,
1369,
334,
1397,
1202,
701,
314,
3589,
5370,
9,
398,
11836,
1083,
12,
370,
506,
6366,
701,
1982,
3992,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
664,
63,
5165,
63,
576,
8,
277,
12,
1454,
63,
7410,
29,
549,
12,
1343,
63,
521,
29,
403,
12,
1284,
63,
521,
29,
403,
304,
267,
408,
267,
27940,
10168,
662,
11568,
7186,
687,
8142,
13978,
14,
267,
768,
635,
1454,
63,
7410,
715,
370,
372,
1454,
314,
2849,
8839,
2690,
367,
1924,
6370,
27,
756,
370,
372,
288,
1006,
314,
7186,
2138,
3382,
1343,
63,
521,
436,
1284,
63,
521,
14,
267,
768,
635,
1343,
63,
521,
710,
8413,
24951,
6370,
900,
370,
8044,
334,
26062,
2736,
4243,
370,
3388,
9395,
2544,
1284,
63,
521,
14,
267,
768,
635,
1284,
63,
521,
710,
8839,
6370,
900,
370,
8044,
334,
12730,
2736,
4243,
370,
3063,
14,
267,
768,
1107,
437,
2600,
12,
315,
314,
2569,
1475,
26,
288,
26458,
10708,
1304,
12,
17680,
985,
12,
22465,
985,
304,
3842,
10239,
12,
1594,
12,
7083,
19940,
395,
334,
10239,
12,
1594,
12,
7083,
19940,
395,
2263,
467,
1467,
334,
10708,
1304,
12,
17680,
985,
12,
22465,
985,
304,
3842,
10239,
12,
1594,
12,
7083,
19940,
395,
334,
10239,
12,
1594,
12,
7083,
19940,
395,
2263,
467,
2263,
93,
288,
10314,
365,
12,
314,
2600,
2883,
787,
6346,
402,
314,
4897,
12,
4642,
536,
436,
6370,
536,
12,
436,
314,
288,
2600,
1338,
787,
5548,
402,
6346,
402,
4913,
12,
574,
436,
22394,
334,
52,
7428,
680,
221,
710,
377,
7428,
5548,
787,
288,
17334,
370,
506,
3355,
315,
24525,
1865,
334,
7410,
4913,
2061,
680,
288,
982,
1454,
63,
7410,
365,
715,
12,
1924,
377,
7428,
769,
365,
17334,
370,
1172,
737,
4750,
1373,
288,
574,
334,
7911,
1443,
1172,
4697,
340,
949,
666,
365,
2808,
367,
314,
5839,
1425,
680,
398,
768,
4610,
10168,
13924,
7186,
315,
1902,
5212,
13,
4375,
503,
959,
13,
10698,
15802,
12,
10298,
641,
20391,
2435,
2166,
436,
6370,
14,
288,
14797,
315,
25169,
626,
2755,
340,
1284,
63,
521,
365,
3063,
12,
314,
8839,
666,
1403,
2138,
1443,
506,
1536,
370,
959,
9395,
315,
314,
13541,
14,
267,
768,
4610,
710,
18267,
574,
911,
506,
367,
314,
627,
31272,
10,
402,
1924,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
chris48s/UK-Polling-Stations
|
polling_stations/apps/data_collection/views.py
|
1
|
1334
|
from datetime import datetime
from django.conf import settings
from django.db.models import Case, IntegerField, Q, Value, When
from django.shortcuts import get_object_or_404, render
from django.views.generic import ListView, TemplateView
from .models import DataQuality
class LeagueTable(ListView):
model = DataQuality
queryset = DataQuality.objects\
.all()\
.select_related('council')\
.defer('council__area')\
.annotate(has_report=Case(
When(Q(report=''), then=Value(0)),
When(~Q(report=''), then=Value(1)),
output_field=IntegerField()
)
)\
.order_by('-has_report', 'council__name')
def data_quality(request, council_id):
data = get_object_or_404(DataQuality.objects.select_related('council'),
pk=council_id)
context = {
'summary': data
}
return render(request, 'data_collection/dataquality_detail.html', context)
class TimeHelper:
@staticmethod
def parse_timestamp(timestamp, tz=True):
if tz:
return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f+00:00')
else:
return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f')
@staticmethod
def days_ago(timestamp):
return abs(datetime.utcnow() - timestamp).days
|
bsd-3-clause
|
[
504,
2197,
492,
2197,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
992,
492,
12425,
12,
26141,
12,
1413,
12,
1594,
12,
3979,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
12,
3795,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
12,
5458,
2768,
199,
504,
1275,
992,
492,
3918,
19436,
421,
199,
533,
7005,
30904,
3186,
8,
23239,
304,
272,
1402,
275,
3918,
19436,
272,
7594,
275,
3918,
19436,
14,
1462,
60,
267,
1275,
452,
17158,
267,
1275,
2416,
63,
2407,
360,
331,
1097,
382,
24431,
267,
1275,
11610,
360,
331,
1097,
382,
363,
6789,
24431,
267,
1275,
10898,
8,
1989,
63,
3070,
29,
1538,
8,
355,
3979,
8,
49,
8,
3070,
534,
659,
2066,
29,
1110,
8,
16,
1826,
355,
3979,
26428,
49,
8,
3070,
534,
659,
2066,
29,
1110,
8,
17,
1826,
355,
1072,
63,
698,
29,
3901,
342,
288,
776,
267,
776,
60,
267,
1275,
1648,
63,
991,
3654,
1989,
63,
3070,
297,
283,
331,
1097,
382,
363,
354,
358,
421,
199,
318,
666,
63,
9161,
8,
1069,
12,
512,
1097,
382,
63,
344,
304,
272,
666,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
1451,
19436,
14,
1462,
14,
2416,
63,
2407,
360,
331,
1097,
382,
659,
267,
3803,
29,
331,
1097,
382,
63,
344,
9,
272,
1067,
275,
469,
267,
283,
4705,
356,
666,
272,
789,
272,
372,
3795,
8,
1069,
12,
283,
576,
63,
3627,
15,
576,
9161,
63,
5506,
14,
1360,
297,
1067,
9,
421,
199,
533,
4703,
4433,
26,
339,
768,
4639,
272,
347,
2198,
63,
3954,
8,
3954,
12,
5823,
29,
549,
304,
267,
340,
5823,
26,
288,
372,
2197,
14,
9866,
8,
3954,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
11,
383,
26,
383,
358,
267,
587,
26,
288,
372,
2197,
14,
9866,
8,
3954,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
358,
339,
768,
4639,
272,
347,
7609,
63,
14315,
8,
3954,
304,
267,
372,
2853,
8,
2083,
14,
10779,
342,
446,
4913,
680,
4899,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2197,
492,
2197,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
992,
492,
12425,
12,
26141,
12,
1413,
12,
1594,
12,
3979,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
12,
3795,
199,
504,
1639,
14,
4196,
14,
6767,
492,
3820,
2768,
12,
5458,
2768,
199,
504,
1275,
992,
492,
3918,
19436,
421,
199,
533,
7005,
30904,
3186,
8,
23239,
304,
272,
1402,
275,
3918,
19436,
272,
7594,
275,
3918,
19436,
14,
1462,
60,
267,
1275,
452,
17158,
267,
1275,
2416,
63,
2407,
360,
331,
1097,
382,
24431,
267,
1275,
11610,
360,
331,
1097,
382,
363,
6789,
24431,
267,
1275,
10898,
8,
1989,
63,
3070,
29,
1538,
8,
355,
3979,
8,
49,
8,
3070,
534,
659,
2066,
29,
1110,
8,
16,
1826,
355,
3979,
26428,
49,
8,
3070,
534,
659,
2066,
29,
1110,
8,
17,
1826,
355,
1072,
63,
698,
29,
3901,
342,
288,
776,
267,
776,
60,
267,
1275,
1648,
63,
991,
3654,
1989,
63,
3070,
297,
283,
331,
1097,
382,
363,
354,
358,
421,
199,
318,
666,
63,
9161,
8,
1069,
12,
512,
1097,
382,
63,
344,
304,
272,
666,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
1451,
19436,
14,
1462,
14,
2416,
63,
2407,
360,
331,
1097,
382,
659,
267,
3803,
29,
331,
1097,
382,
63,
344,
9,
272,
1067,
275,
469,
267,
283,
4705,
356,
666,
272,
789,
272,
372,
3795,
8,
1069,
12,
283,
576,
63,
3627,
15,
576,
9161,
63,
5506,
14,
1360,
297,
1067,
9,
421,
199,
533,
4703,
4433,
26,
339,
768,
4639,
272,
347,
2198,
63,
3954,
8,
3954,
12,
5823,
29,
549,
304,
267,
340,
5823,
26,
288,
372,
2197,
14,
9866,
8,
3954,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
11,
383,
26,
383,
358,
267,
587,
26,
288,
372,
2197,
14,
9866,
8,
3954,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
4111,
70,
358,
339,
768,
4639,
272,
347,
7609,
63,
14315,
8,
3954,
304,
267,
372,
2853,
8,
2083,
14,
10779,
342,
446,
4913,
680,
4899,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
caorong/mysql-connector-python
|
tests/test_constants.py
|
13
|
17686
|
# MySQL Connector/Python - MySQL driver written in Python.
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
# MySQL Connector/Python is licensed under the terms of the GPLv2
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
# MySQL Connectors. There are special exceptions to the terms and
# conditions of the GPLv2 as it is applied to this software, see the
# FOSS License Exception
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""Unittests for mysql.connector.constants
"""
import tests
from mysql.connector import constants, errors
class Helpers(tests.MySQLConnectorTests):
def test_flag_is_set(self):
"""Check if a particular flag/bit is set"""
data = [
1 << 3,
1 << 5,
1 << 7,
]
flags = 0
for flag in data:
flags |= flag
for flag in data:
self.assertTrue(constants.flag_is_set(flag, flags))
self.assertFalse(constants.flag_is_set(1 << 4, flags))
def test_MAX_PACKET_LENGTH(self):
"""Check MAX_PACKET_LENGTH"""
self.assertEqual(16777215, constants.MAX_PACKET_LENGTH)
def test_NET_BUFFER_LENGTH(self):
"""Check NET_BUFFER_LENGTH"""
self.assertEqual(8192, constants.NET_BUFFER_LENGTH)
class FieldTypeTests(tests.MySQLConnectorTests):
desc = {
'DECIMAL': (0x00, 'DECIMAL'),
'TINY': (0x01, 'TINY'),
'SHORT': (0x02, 'SHORT'),
'LONG': (0x03, 'LONG'),
'FLOAT': (0x04, 'FLOAT'),
'DOUBLE': (0x05, 'DOUBLE'),
'NULL': (0x06, 'NULL'),
'TIMESTAMP': (0x07, 'TIMESTAMP'),
'LONGLONG': (0x08, 'LONGLONG'),
'INT24': (0x09, 'INT24'),
'DATE': (0x0a, 'DATE'),
'TIME': (0x0b, 'TIME'),
'DATETIME': (0x0c, 'DATETIME'),
'YEAR': (0x0d, 'YEAR'),
'NEWDATE': (0x0e, 'NEWDATE'),
'VARCHAR': (0x0f, 'VARCHAR'),
'BIT': (0x10, 'BIT'),
'NEWDECIMAL': (0xf6, 'NEWDECIMAL'),
'ENUM': (0xf7, 'ENUM'),
'SET': (0xf8, 'SET'),
'TINY_BLOB': (0xf9, 'TINY_BLOB'),
'MEDIUM_BLOB': (0xfa, 'MEDIUM_BLOB'),
'LONG_BLOB': (0xfb, 'LONG_BLOB'),
'BLOB': (0xfc, 'BLOB'),
'VAR_STRING': (0xfd, 'VAR_STRING'),
'STRING': (0xfe, 'STRING'),
'GEOMETRY': (0xff, 'GEOMETRY'),
}
type_groups = {
'string': [
constants.FieldType.VARCHAR,
constants.FieldType.ENUM,
constants.FieldType.VAR_STRING, constants.FieldType.STRING,
],
'binary': [
constants.FieldType.TINY_BLOB, constants.FieldType.MEDIUM_BLOB,
constants.FieldType.LONG_BLOB, constants.FieldType.BLOB,
],
'number': [
constants.FieldType.DECIMAL, constants.FieldType.NEWDECIMAL,
constants.FieldType.TINY, constants.FieldType.SHORT,
constants.FieldType.LONG,
constants.FieldType.FLOAT, constants.FieldType.DOUBLE,
constants.FieldType.LONGLONG, constants.FieldType.INT24,
constants.FieldType.BIT,
constants.FieldType.YEAR,
],
'datetime': [
constants.FieldType.DATETIME, constants.FieldType.TIMESTAMP,
],
}
def test_attributes(self):
"""Check attributes for FieldType"""
self.assertEqual('FIELD_TYPE_', constants.FieldType.prefix)
for key, value in self.desc.items():
self.assertTrue(key in constants.FieldType.__dict__,
'{0} is not an attribute of FieldType'.format(key))
self.assertEqual(
value[0], constants.FieldType.__dict__[key],
'{0} attribute of FieldType has wrong value'.format(key))
def test_get_desc(self):
"""Get field type by name"""
for key, value in self.desc.items():
exp = value[1]
res = constants.FieldType.get_desc(key)
self.assertEqual(exp, res)
self.assertEqual(None, constants.FieldType.get_desc('FooBar'))
def test_get_info(self):
"""Get field type by id"""
for _, value in self.desc.items():
exp = value[1]
res = constants.FieldType.get_info(value[0])
self.assertEqual(exp, res)
self.assertEqual(None, constants.FieldType.get_info(999999999))
def test_get_string_types(self):
"""DBAPI string types"""
self.assertEqual(self.type_groups['string'],
constants.FieldType.get_string_types())
def test_get_binary_types(self):
"""DBAPI string types"""
self.assertEqual(self.type_groups['binary'],
constants.FieldType.get_binary_types())
def test_get_number_types(self):
"""DBAPI number types"""
self.assertEqual(self.type_groups['number'],
constants.FieldType.get_number_types())
def test_get_timestamp_types(self):
"""DBAPI datetime types"""
self.assertEqual(self.type_groups['datetime'],
constants.FieldType.get_timestamp_types())
class FieldFlagTests(tests.MySQLConnectorTests):
desc = {
'NOT_NULL': (1 << 0, "Field can't be NULL"),
'PRI_KEY': (1 << 1, "Field is part of a primary key"),
'UNIQUE_KEY': (1 << 2, "Field is part of a unique key"),
'MULTIPLE_KEY': (1 << 3, "Field is part of a key"),
'BLOB': (1 << 4, "Field is a blob"),
'UNSIGNED': (1 << 5, "Field is unsigned"),
'ZEROFILL': (1 << 6, "Field is zerofill"),
'BINARY': (1 << 7, "Field is binary "),
'ENUM': (1 << 8, "field is an enum"),
'AUTO_INCREMENT': (1 << 9, "field is a autoincrement field"),
'TIMESTAMP': (1 << 10, "Field is a timestamp"),
'SET': (1 << 11, "field is a set"),
'NO_DEFAULT_VALUE': (1 << 12, "Field doesn't have default value"),
'ON_UPDATE_NOW': (1 << 13, "Field is set to NOW on UPDATE"),
'NUM': (1 << 14, "Field is num (for clients)"),
'PART_KEY': (1 << 15, "Intern; Part of some key"),
'GROUP': (1 << 14, "Intern: Group field"), # Same as NUM
'UNIQUE': (1 << 16, "Intern: Used by sql_yacc"),
'BINCMP': (1 << 17, "Intern: Used by sql_yacc"),
'GET_FIXED_FIELDS': (1 << 18, "Used to get fields in item tree"),
'FIELD_IN_PART_FUNC': (1 << 19, "Field part of partition func"),
'FIELD_IN_ADD_INDEX': (1 << 20, "Intern: Field used in ADD INDEX"),
'FIELD_IS_RENAMED': (1 << 21, "Intern: Field is being renamed"),
}
def test_attributes(self):
"""Check attributes for FieldFlag"""
self.assertEqual('', constants.FieldFlag._prefix)
for key, value in self.desc.items():
self.assertTrue(key in constants.FieldFlag.__dict__,
'{0} is not an attribute of FieldFlag'.format(key))
self.assertEqual(
value[0], constants.FieldFlag.__dict__[key],
'{0} attribute of FieldFlag has wrong value'.format(key))
def test_get_desc(self):
"""Get field flag by name"""
for key, value in self.desc.items():
exp = value[1]
res = constants.FieldFlag.get_desc(key)
self.assertEqual(exp, res)
def test_get_info(self):
"""Get field flag by id"""
for exp, info in self.desc.items():
# Ignore the NUM/GROUP (bug in MySQL source code)
if info[0] == 1 << 14:
break
res = constants.FieldFlag.get_info(info[0])
self.assertEqual(exp, res)
def test_get_bit_info(self):
"""Get names of the set flags"""
data = 0
data |= constants.FieldFlag.BLOB
data |= constants.FieldFlag.BINARY
exp = ['BINARY', 'BLOB'].sort()
self.assertEqual(exp, constants.FieldFlag.get_bit_info(data).sort())
class ClientFlagTests(tests.MySQLConnectorTests):
desc = {
'LONG_PASSWD': (1 << 0, 'New more secure passwords'),
'FOUND_ROWS': (1 << 1, 'Found instead of affected rows'),
'LONG_FLAG': (1 << 2, 'Get all column flags'),
'CONNECT_WITH_DB': (1 << 3, 'One can specify db on connect'),
'NO_SCHEMA': (1 << 4, "Don't allow database.table.column"),
'COMPRESS': (1 << 5, 'Can use compression protocol'),
'ODBC': (1 << 6, 'ODBC client'),
'LOCAL_FILES': (1 << 7, 'Can use LOAD DATA LOCAL'),
'IGNORE_SPACE': (1 << 8, "Ignore spaces before ''"),
'PROTOCOL_41': (1 << 9, 'New 4.1 protocol'),
'INTERACTIVE': (1 << 10, 'This is an interactive client'),
'SSL': (1 << 11, 'Switch to SSL after handshake'),
'IGNORE_SIGPIPE': (1 << 12, 'IGNORE sigpipes'),
'TRANSACTIONS': (1 << 13, 'Client knows about transactions'),
'RESERVED': (1 << 14, 'Old flag for 4.1 protocol'),
'SECURE_CONNECTION': (1 << 15, 'New 4.1 authentication'),
'MULTI_STATEMENTS': (1 << 16, 'Enable/disable multi-stmt support'),
'MULTI_RESULTS': (1 << 17, 'Enable/disable multi-results'),
'SSL_VERIFY_SERVER_CERT': (1 << 30, ''),
'REMEMBER_OPTIONS': (1 << 31, ''),
}
def test_attributes(self):
"""Check attributes for ClientFlag"""
for key, value in self.desc.items():
self.assertTrue(key in constants.ClientFlag.__dict__,
'{0} is not an attribute of FieldFlag'.format(key))
self.assertEqual(
value[0], constants.ClientFlag.__dict__[key],
'{0} attribute of FieldFlag has wrong value'.format(key))
def test_get_desc(self):
"""Get client flag by name"""
for key, value in self.desc.items():
exp = value[1]
res = constants.ClientFlag.get_desc(key)
self.assertEqual(exp, res)
def test_get_info(self):
"""Get client flag by id"""
for exp, info in self.desc.items():
res = constants.ClientFlag.get_info(info[0])
self.assertEqual(exp, res)
def test_get_bit_info(self):
"""Get names of the set flags"""
data = 0
data |= constants.ClientFlag.LONG_FLAG
data |= constants.ClientFlag.LOCAL_FILES
exp = ['LONG_FLAG', 'LOCAL_FILES'].sort()
self.assertEqual(exp, constants.ClientFlag.get_bit_info(data).sort())
def test_get_default(self):
"""Get client flags which are set by default.
"""
data = [
constants.ClientFlag.LONG_PASSWD,
constants.ClientFlag.LONG_FLAG,
constants.ClientFlag.CONNECT_WITH_DB,
constants.ClientFlag.PROTOCOL_41,
constants.ClientFlag.TRANSACTIONS,
constants.ClientFlag.SECURE_CONNECTION,
constants.ClientFlag.MULTI_STATEMENTS,
constants.ClientFlag.MULTI_RESULTS,
constants.ClientFlag.LOCAL_FILES,
]
exp = 0
for option in data:
exp |= option
self.assertEqual(exp, constants.ClientFlag.get_default())
class CharacterSetTests(tests.MySQLConnectorTests):
"""Tests for constants.CharacterSet"""
def test_get_info(self):
"""Get info about charset using MySQL ID"""
exp = ('utf8', 'utf8_general_ci')
data = 33
self.assertEqual(exp, constants.CharacterSet.get_info(data))
exception = errors.ProgrammingError
data = 50000
self.assertRaises(exception, constants.CharacterSet.get_info, data)
def test_get_desc(self):
"""Get info about charset using MySQL ID as string"""
exp = 'utf8/utf8_general_ci'
data = 33
self.assertEqual(exp, constants.CharacterSet.get_desc(data))
exception = errors.ProgrammingError
data = 50000
self.assertRaises(exception, constants.CharacterSet.get_desc, data)
def test_get_default_collation(self):
"""Get default collation for a given Character Set"""
func = constants.CharacterSet.get_default_collation
data = 'sjis'
exp = ('sjis_japanese_ci', data, 13)
self.assertEqual(exp, func(data))
self.assertEqual(exp, func(exp[2]))
exception = errors.ProgrammingError
data = 'foobar'
self.assertRaises(exception, func, data)
def test_get_charset_info(self):
"""Get info about charset by name and collation"""
func = constants.CharacterSet.get_charset_info
exp = (209, 'utf8', 'utf8_esperanto_ci')
data = exp[1:]
self.assertEqual(exp, func(data[0], data[1]))
self.assertEqual(exp, func(None, data[1]))
self.assertEqual(exp, func(exp[0]))
self.assertRaises(errors.ProgrammingError,
constants.CharacterSet.get_charset_info, 666)
self.assertRaises(
errors.ProgrammingError,
constants.CharacterSet.get_charset_info, charset='utf8',
collation='utf8_spam_ci')
self.assertRaises(
errors.ProgrammingError,
constants.CharacterSet.get_charset_info,
collation='utf8_spam_ci')
def test_get_supported(self):
"""Get list of all supported character sets"""
exp = (
'big5', 'latin2', 'dec8', 'cp850', 'latin1', 'hp8', 'koi8r',
'swe7', 'ascii', 'ujis', 'sjis', 'cp1251', 'hebrew', 'tis620',
'euckr', 'latin7', 'koi8u', 'gb2312', 'greek', 'cp1250', 'gbk',
'cp1257', 'latin5', 'armscii8', 'utf8', 'ucs2', 'cp866', 'keybcs2',
'macce', 'macroman', 'cp852', 'utf8mb4','utf16', 'utf16le',
'cp1256', 'utf32', 'binary', 'geostd8', 'cp932', 'eucjpms',
'gb18030',
)
self.assertEqual(exp, constants.CharacterSet.get_supported())
class SQLModesTests(tests.MySQLConnectorTests):
modes = (
'REAL_AS_FLOAT',
'PIPES_AS_CONCAT',
'ANSI_QUOTES',
'IGNORE_SPACE',
'NOT_USED',
'ONLY_FULL_GROUP_BY',
'NO_UNSIGNED_SUBTRACTION',
'NO_DIR_IN_CREATE',
'POSTGRESQL',
'ORACLE',
'MSSQL',
'DB2',
'MAXDB',
'NO_KEY_OPTIONS',
'NO_TABLE_OPTIONS',
'NO_FIELD_OPTIONS',
'MYSQL323',
'MYSQL40',
'ANSI',
'NO_AUTO_VALUE_ON_ZERO',
'NO_BACKSLASH_ESCAPES',
'STRICT_TRANS_TABLES',
'STRICT_ALL_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'INVALID_DATES',
'ERROR_FOR_DIVISION_BY_ZERO',
'TRADITIONAL',
'NO_AUTO_CREATE_USER',
'HIGH_NOT_PRECEDENCE',
'NO_ENGINE_SUBSTITUTION',
'PAD_CHAR_TO_FULL_LENGTH',
)
def test_get_info(self):
for mode in SQLModesTests.modes:
self.assertEqual(mode, getattr(constants.SQLMode, mode),
'Wrong info for SQL Mode {0}'.format(mode))
def test_get_full_info(self):
modes = tuple(sorted(SQLModesTests.modes))
self.assertEqual(modes,
constants.SQLMode.get_full_info())
class ShutdownTypeTests(tests.MySQLConnectorTests):
"""Test COM_SHUTDOWN types"""
desc = {
'SHUTDOWN_DEFAULT': (
0,
"defaults to SHUTDOWN_WAIT_ALL_BUFFERS"
),
'SHUTDOWN_WAIT_CONNECTIONS': (
1,
"wait for existing connections to finish"
),
'SHUTDOWN_WAIT_TRANSACTIONS': (
2,
"wait for existing trans to finish"
),
'SHUTDOWN_WAIT_UPDATES': (
8,
"wait for existing updates to finish"
),
'SHUTDOWN_WAIT_ALL_BUFFERS': (
16,
"flush InnoDB and other storage engine buffers"
),
'SHUTDOWN_WAIT_CRITICAL_BUFFERS': (
17,
"don't flush InnoDB buffers, flush other storage engines' buffers"
),
'KILL_QUERY': (
254, "(no description)"
),
'KILL_CONNECTION': (
255, "(no description)"
),
}
def test_attributes(self):
"""Check attributes for FieldType"""
self.assertEqual('', constants.ShutdownType.prefix)
for key, value in self.desc.items():
self.assertTrue(key in constants.ShutdownType.__dict__,
'{0} is not an attribute of FieldType'.format(key))
self.assertEqual(
value[0], constants.ShutdownType.__dict__[key],
'{0} attribute of ShutdownType has wrong value'.format(key))
def test_get_desc(self):
"""Get field flag by name"""
for key, value in self.desc.items():
exp = value[1]
res = constants.ShutdownType.get_desc(key)
self.assertEqual(exp, res)
|
gpl-2.0
|
[
3,
11200,
13482,
2406,
15,
4718,
446,
11200,
5253,
5313,
315,
2018,
14,
199,
3,
1898,
334,
67,
9,
8937,
12,
6927,
12,
15309,
436,
15,
269,
2399,
29172,
2335,
14,
2900,
4481,
4644,
14,
199,
199,
3,
11200,
13482,
2406,
15,
4718,
365,
18233,
1334,
314,
2895,
402,
314,
14629,
86,
18,
199,
3,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
11692,
13,
18,
14,
16,
14,
1360,
6244,
2839,
4750,
199,
3,
11200,
13482,
9177,
14,
6006,
787,
4539,
4967,
370,
314,
2895,
436,
199,
3,
3704,
402,
314,
14629,
86,
18,
465,
652,
365,
6781,
370,
642,
2032,
12,
1937,
314,
199,
3,
481,
47,
2300,
844,
2186,
199,
3,
665,
1014,
921,
1544,
14,
8644,
14,
957,
15,
10254,
15,
9666,
15,
606,
25843,
15,
545,
385,
13,
1971,
14,
1360,
10827,
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,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
199,
199,
624,
1358,
1770,
83,
367,
12896,
14,
11815,
14,
5559,
199,
624,
199,
199,
646,
2295,
199,
504,
12896,
14,
11815,
492,
5262,
12,
2552,
421,
199,
533,
11642,
83,
8,
2219,
14,
20784,
20476,
2925,
304,
339,
347,
511,
63,
4173,
63,
374,
63,
409,
8,
277,
304,
267,
408,
1799,
340,
282,
6770,
3305,
15,
2075,
365,
663,
624,
398,
666,
275,
359,
288,
413,
5213,
650,
12,
288,
413,
5213,
959,
12,
288,
413,
5213,
1520,
12,
267,
1622,
267,
3285,
275,
378,
267,
367,
3305,
315,
666,
26,
288,
3285,
8901,
3305,
398,
367,
3305,
315,
666,
26,
288,
291,
14,
1815,
8,
5559,
14,
4173,
63,
374,
63,
409,
8,
4173,
12,
3285,
430,
398,
291,
14,
3334,
8,
5559,
14,
4173,
63,
374,
63,
409,
8,
17,
5213,
841,
12,
3285,
430,
339,
347,
511,
63,
4283,
63,
18058,
63,
9127,
8,
277,
304,
267,
408,
1799,
9141,
63,
18058,
63,
9127,
624,
267,
291,
14,
629,
8,
975,
1138,
2819,
1046,
12,
5262,
14,
4283,
63,
18058,
63,
9127,
9,
339,
347,
511,
63,
7278,
63,
10960,
63,
9127,
8,
277,
304,
267,
408,
1799,
18340,
63,
10960,
63,
9127,
624,
267,
291,
14,
629,
8,
31526,
12,
5262,
14,
7278,
63,
10960,
63,
9127,
9,
421,
199,
533,
5024,
804,
2925,
8,
2219,
14,
20784,
20476,
2925,
304,
339,
4328,
275,
469,
267,
283,
23925,
356,
755,
334,
16,
88,
383,
12,
283,
23925,
659,
267,
283,
31178,
356,
3515,
334,
16,
88,
614,
12,
283,
31178,
659,
267,
283,
13003,
356,
260,
334,
16,
88,
996,
12,
283,
13003,
659,
267,
283,
12375,
356,
3515,
334,
16,
88,
1644,
12,
283,
12375,
659,
267,
283,
11783,
356,
260,
334,
16,
88,
966,
12,
283,
11783,
659,
267,
283,
14989,
356,
263,
334,
16,
88,
1717,
12,
283,
14989,
659,
267,
283,
8084,
356,
3515,
334,
16,
88,
1690,
12,
283,
8084,
659,
267,
283,
20277,
356,
258,
334,
16,
88,
1780,
12,
283,
20277,
659,
267,
283,
44,
615,
2226,
7770,
356,
420,
334,
16,
88,
2036,
12,
283,
44,
615,
2226,
7770,
659,
267,
283,
2919,
1194,
356,
260,
334,
16,
88,
1643,
12,
283,
2919,
1194,
659,
267,
283,
5390,
356,
3515,
334,
16,
88,
16,
65,
12,
283,
5390,
659,
267,
283,
4961,
356,
3515,
334,
16,
88,
16,
66,
12,
283,
4961,
659,
267,
283,
12488,
356,
420,
334,
16,
88,
16,
67,
12,
283,
12488,
659,
267,
283,
19216,
356,
3515,
334,
16,
88,
16,
68,
12,
283,
19216,
659,
267,
283,
11365,
5390,
356,
755,
334,
16,
88,
16,
69,
12,
283,
11365,
5390,
659,
267,
283,
24800,
356,
755,
334,
16,
88,
16,
70,
12,
283,
24800,
659,
267,
283,
11970,
356,
3698,
334,
16,
88,
709,
12,
283,
11970,
659,
267,
283,
11365,
23925,
356,
259,
334,
16,
1949,
22,
12,
283,
11365,
23925,
659,
267,
283,
17563,
356,
3515,
334,
16,
1949,
23,
12,
283,
17563,
659,
267,
283,
3597,
356,
3698,
334,
16,
1949,
24,
12,
283,
3597,
659,
267,
283,
31178,
63,
26275,
356,
258,
334,
16,
1949,
25,
12,
283,
31178,
63,
26275,
659,
267,
283,
9754,
2639,
63,
26275,
356,
257,
334,
16,
10500,
12,
283,
9754,
2639,
63,
26275,
659,
267,
283,
12375,
63,
26275,
356,
258,
334,
16,
10272,
12,
283,
12375,
63,
26275,
659,
267,
283,
26275,
356,
3515,
334,
16,
10347,
12,
283,
26275,
659,
267,
283,
5568,
63,
5353,
356,
259,
334,
16,
11208,
12,
283,
5568,
63,
5353,
659,
267,
283,
5353,
356,
263,
334,
16,
8371,
12,
283,
5353,
659,
267,
283,
28472,
356,
420,
334,
16,
3581,
12,
283,
28472,
659,
272,
789,
339,
730,
63,
2634,
275,
469,
267,
283,
875,
356,
359,
288,
5262,
14,
792,
804,
14,
24800,
12,
288,
5262,
14,
792,
804,
14,
17563,
12,
288,
5262,
14,
792,
804,
14,
5568,
63,
5353,
12,
5262,
14,
792,
804,
14,
5353,
12,
267,
2156,
267,
283,
3008,
356,
359,
288,
5262,
14,
792,
804,
14,
31178,
63,
26275,
12,
5262,
14,
792,
804,
14,
9754,
2639,
63,
26275,
12,
288,
5262,
14,
792,
804,
14,
12375,
63,
26275,
12,
5262,
14,
792,
804,
14,
26275,
12,
267,
2156,
267,
283,
1955,
356,
359,
288,
5262,
14,
792,
804,
14,
23925,
12,
5262,
14,
792,
804,
14,
11365,
23925,
12,
288,
5262,
14,
792,
804,
14,
31178,
12,
5262,
14
] |
[
11200,
13482,
2406,
15,
4718,
446,
11200,
5253,
5313,
315,
2018,
14,
199,
3,
1898,
334,
67,
9,
8937,
12,
6927,
12,
15309,
436,
15,
269,
2399,
29172,
2335,
14,
2900,
4481,
4644,
14,
199,
199,
3,
11200,
13482,
2406,
15,
4718,
365,
18233,
1334,
314,
2895,
402,
314,
14629,
86,
18,
199,
3,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
11692,
13,
18,
14,
16,
14,
1360,
6244,
2839,
4750,
199,
3,
11200,
13482,
9177,
14,
6006,
787,
4539,
4967,
370,
314,
2895,
436,
199,
3,
3704,
402,
314,
14629,
86,
18,
465,
652,
365,
6781,
370,
642,
2032,
12,
1937,
314,
199,
3,
481,
47,
2300,
844,
2186,
199,
3,
665,
1014,
921,
1544,
14,
8644,
14,
957,
15,
10254,
15,
9666,
15,
606,
25843,
15,
545,
385,
13,
1971,
14,
1360,
10827,
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,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
199,
199,
624,
1358,
1770,
83,
367,
12896,
14,
11815,
14,
5559,
199,
624,
199,
199,
646,
2295,
199,
504,
12896,
14,
11815,
492,
5262,
12,
2552,
421,
199,
533,
11642,
83,
8,
2219,
14,
20784,
20476,
2925,
304,
339,
347,
511,
63,
4173,
63,
374,
63,
409,
8,
277,
304,
267,
408,
1799,
340,
282,
6770,
3305,
15,
2075,
365,
663,
624,
398,
666,
275,
359,
288,
413,
5213,
650,
12,
288,
413,
5213,
959,
12,
288,
413,
5213,
1520,
12,
267,
1622,
267,
3285,
275,
378,
267,
367,
3305,
315,
666,
26,
288,
3285,
8901,
3305,
398,
367,
3305,
315,
666,
26,
288,
291,
14,
1815,
8,
5559,
14,
4173,
63,
374,
63,
409,
8,
4173,
12,
3285,
430,
398,
291,
14,
3334,
8,
5559,
14,
4173,
63,
374,
63,
409,
8,
17,
5213,
841,
12,
3285,
430,
339,
347,
511,
63,
4283,
63,
18058,
63,
9127,
8,
277,
304,
267,
408,
1799,
9141,
63,
18058,
63,
9127,
624,
267,
291,
14,
629,
8,
975,
1138,
2819,
1046,
12,
5262,
14,
4283,
63,
18058,
63,
9127,
9,
339,
347,
511,
63,
7278,
63,
10960,
63,
9127,
8,
277,
304,
267,
408,
1799,
18340,
63,
10960,
63,
9127,
624,
267,
291,
14,
629,
8,
31526,
12,
5262,
14,
7278,
63,
10960,
63,
9127,
9,
421,
199,
533,
5024,
804,
2925,
8,
2219,
14,
20784,
20476,
2925,
304,
339,
4328,
275,
469,
267,
283,
23925,
356,
755,
334,
16,
88,
383,
12,
283,
23925,
659,
267,
283,
31178,
356,
3515,
334,
16,
88,
614,
12,
283,
31178,
659,
267,
283,
13003,
356,
260,
334,
16,
88,
996,
12,
283,
13003,
659,
267,
283,
12375,
356,
3515,
334,
16,
88,
1644,
12,
283,
12375,
659,
267,
283,
11783,
356,
260,
334,
16,
88,
966,
12,
283,
11783,
659,
267,
283,
14989,
356,
263,
334,
16,
88,
1717,
12,
283,
14989,
659,
267,
283,
8084,
356,
3515,
334,
16,
88,
1690,
12,
283,
8084,
659,
267,
283,
20277,
356,
258,
334,
16,
88,
1780,
12,
283,
20277,
659,
267,
283,
44,
615,
2226,
7770,
356,
420,
334,
16,
88,
2036,
12,
283,
44,
615,
2226,
7770,
659,
267,
283,
2919,
1194,
356,
260,
334,
16,
88,
1643,
12,
283,
2919,
1194,
659,
267,
283,
5390,
356,
3515,
334,
16,
88,
16,
65,
12,
283,
5390,
659,
267,
283,
4961,
356,
3515,
334,
16,
88,
16,
66,
12,
283,
4961,
659,
267,
283,
12488,
356,
420,
334,
16,
88,
16,
67,
12,
283,
12488,
659,
267,
283,
19216,
356,
3515,
334,
16,
88,
16,
68,
12,
283,
19216,
659,
267,
283,
11365,
5390,
356,
755,
334,
16,
88,
16,
69,
12,
283,
11365,
5390,
659,
267,
283,
24800,
356,
755,
334,
16,
88,
16,
70,
12,
283,
24800,
659,
267,
283,
11970,
356,
3698,
334,
16,
88,
709,
12,
283,
11970,
659,
267,
283,
11365,
23925,
356,
259,
334,
16,
1949,
22,
12,
283,
11365,
23925,
659,
267,
283,
17563,
356,
3515,
334,
16,
1949,
23,
12,
283,
17563,
659,
267,
283,
3597,
356,
3698,
334,
16,
1949,
24,
12,
283,
3597,
659,
267,
283,
31178,
63,
26275,
356,
258,
334,
16,
1949,
25,
12,
283,
31178,
63,
26275,
659,
267,
283,
9754,
2639,
63,
26275,
356,
257,
334,
16,
10500,
12,
283,
9754,
2639,
63,
26275,
659,
267,
283,
12375,
63,
26275,
356,
258,
334,
16,
10272,
12,
283,
12375,
63,
26275,
659,
267,
283,
26275,
356,
3515,
334,
16,
10347,
12,
283,
26275,
659,
267,
283,
5568,
63,
5353,
356,
259,
334,
16,
11208,
12,
283,
5568,
63,
5353,
659,
267,
283,
5353,
356,
263,
334,
16,
8371,
12,
283,
5353,
659,
267,
283,
28472,
356,
420,
334,
16,
3581,
12,
283,
28472,
659,
272,
789,
339,
730,
63,
2634,
275,
469,
267,
283,
875,
356,
359,
288,
5262,
14,
792,
804,
14,
24800,
12,
288,
5262,
14,
792,
804,
14,
17563,
12,
288,
5262,
14,
792,
804,
14,
5568,
63,
5353,
12,
5262,
14,
792,
804,
14,
5353,
12,
267,
2156,
267,
283,
3008,
356,
359,
288,
5262,
14,
792,
804,
14,
31178,
63,
26275,
12,
5262,
14,
792,
804,
14,
9754,
2639,
63,
26275,
12,
288,
5262,
14,
792,
804,
14,
12375,
63,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ceb8/astroquery
|
astroquery/open_exoplanet_catalogue/utils.py
|
2
|
8998
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
class Number:
""" Number class for values containing errors. Math operations use
the value given. Checking for no 'value' must use "==". Numbers with
upper or lower limits as assumed to have no value.
Examples
--------
>>> num = Number(10, errorminus=0.5, errorplus=0.8)
>>> str(num)
'10.0 +0.8 -0.5'
>>> num * 2
20.0
>>> num + 2
12.0
>>> num.errorminus
0.5
>>> num = Number(None, upperlimit=10)
>>> str(num)
'<10.0'
>>> num == None
True
>>> num is None
False
"""
def __init__(self, value=None, upperlimit=None, lowerlimit=None,
errorplus=None, errorminus=None):
"""
Parameters
----------
value: float
the value of this number. Numbers with upper or lower limits
assume None as value.
upperlimit: float
if upper limit exists, there should be no value
lowerlimit: float
if lower limit exists, there should be no value
errorplus: float
unsigned value
errorminus: float
unsigned value
Notes
-----
Number object acts as a typical float object, but can hold
errorminus, errorplus, lowerlimit, upperlimit mathematical
operations only use value attribute. Number == Number will compare
the error values as well as value.
Returns
-------
Number object.
"""
if value is None:
self.value = None
else:
try:
self.value = float(value)
except ValueError:
self.value = value
self.upperlimit = upperlimit
self.lowerlimit = lowerlimit
self.errorplus = errorplus
self.errorminus = errorminus
def __str__(self):
"""
Example outputs
---------------
>>> str(Number(2.0))
'2.0'
>>> str(Number(2.0, errorplus=1.0, errorminus=1.5))
'2.0 +1.0 -1.5'
>>> str(Number(2.0, errorplus=1.0, errorminus=1.0))
'2.0 +/-1.0'
>>> str(Number(lowerlimit=2.0))
'>2.0'
>>> str(Number(upperlimit=2.0))
'<2.0'
"""
tempstr = ""
if self.value is not None:
tempstr += str(self.value)
if hasattr(self, "errorplus") and self.errorplus is not None and\
hasattr(self, "errorminus") and self.errorminus is not None:
if self.errorplus == self.errorminus:
tempstr += " +/-" + str(self.errorplus)
else:
tempstr += (" +" + str(self.errorplus) + " -" +
str(self.errorminus))
if hasattr(self, "upperlimit") and self.upperlimit is not None:
tempstr += "<" + str(self.upperlimit)
elif hasattr(self, "lowerlimit") and self.lowerlimit is not None:
tempstr += ">" + str(self.lowerlimit)
return tempstr
def machine_readable(self, separator="\t", missingval="None"):
"""
Creates a string intended for a machine to read (ex, gnuplot)
prints as follows
value(separator)errorplus(separator)errorminus(separator)upperlimit(separator)lowerlimit
if the value does not exist, the missingval is added instead
Parameters
----------
separator: str
string used to separate values while printing
missingval: str
string to use for NoneType values
Returns
-------
str
"""
temp = ""
if hasattr(self, "value") and self.value is not None:
temp += str(self.value) + separator
else:
temp += missingval + separator
if hasattr(self, "errorplus") and self.errorplus is not None:
temp += str(self.errorplus) + separator
else:
temp += missingval + separator
if hasattr(self, "errorminus") and self.errorminus is not None:
temp += str(self.errorminus) + separator
else:
temp += missingval + separator
if hasattr(self, "upperlimit") and self.upperlimit is not None:
temp += str(self.upperlimit) + separator
else:
temp += missingval + separator
if hasattr(self, "lowerlimit") and self.lowerlimit is not None:
temp += str(self.lowerlimit) + separator
else:
temp += missingval + separator
return temp.strip(separator)
def __setattr__(self, key, val):
if val is not None:
try:
self.__dict__[key] = float(val)
except ValueError:
self.__dict__[key] = val
else:
self.__dict__[key] = val
def __eq__(self, num):
"""
Parameters
----------
num: Number, float or int
Number types check both the value and the uncertainties.
Returns
-------
bool
"""
if isinstance(num, Number):
return self.value == num.value and\
self.errorminus == num.errorminus and\
self.errorplus == num.errorplus and\
self.lowerlimit == num.lowerlimit and\
self.upperlimit == num.upperlimit
else:
return self.value == num
def __add__(self, num):
return self.value + num
def __sub__(self, num):
return self.value - num
def __lt__(self, num):
return self.value < num
def __le__(self, num):
return self.value <= num
def __ne__(self, num):
"""
Parameters
----------
num: Number, float or int
Number types check both the value and the uncertainties.
Returns
-------
bool
"""
if isinstance(num, Number):
return self.value != num.value and\
self.errorminus != num.errorminus and\
self.errorplus != num.errorplus
else:
return self.value != num
def __gt__(self, num):
return self.value > num
def __ge__(self, num):
return self.value >= num
def __mul__(self, num):
return self.value * num
def __div__(self, num):
return self.value / num
def __floordiv__(self, num):
return self.value // num
def __mod__(self, num):
return self.value % num
def __divmod__(self, num):
return divmod(self.value, num)
def __pow__(self, num, *z):
return pow(self.value, num, *z)
def __float__(self):
return float(self.value)
def __cmp__(self, num):
return cmp(self.value, num)
def __and__(self, num):
return self.value & num
def __abs__(self):
return abs(self.value)
def __coerce__(self, num):
return coerce(self.value, num)
def __hash__(self):
return hash(self.value)
def __hex__(self):
return hex(self.value)
def __int__(self):
return int(self.value)
def __invert__(self):
return ~self.value
def __long__(self):
return long(self.value)
def __lshift__(self, num):
return self.value << num
def __neg__(self):
return -self.value
def __nonzero__(self):
return self.value != 0
def __oct__(self):
return oct(self.value)
def __or__(self, num):
return self.value | num
def __pos__(self):
return +self.value
def __radd__(self, num):
return num + self.value
def __rdiv__(self, num):
return num / self.value
def __rdivmod(self, num):
return divmod(num, self.value)
def __repr__(self):
return str(self)
def __rfloordiv__(self, num):
return num // self.value
def __rlshift__(self, num):
return num << self.value
def __rmod__(self, num):
return num % self.value
def __rmul__(self, num):
return num * self.value
def __ror__(self, num):
return num | self.value
def __rpow__(self, num, *z):
return pow(num, self.value, *z)
def __rrshift__(self, num):
return num >> self.value
def __rshift__(self, num):
return self.value >> num
def __rsub__(self, num):
return num - self.value
def __rtruediv__(self, num):
return num / self.value
def __rxor__(self, num):
return num ^ self.value
def __truediv__(self, num):
return self.value / num
def __xor__(self, num):
return self.value ^ num
def bit_length(self):
return self.value.bit_length()
def asymmetric(self):
"""
Notes
-----
Returns true if the errorplus and errorminus are not equal
Returns
-------
bool
"""
return self.errorminus != self.errorplus
|
bsd-3-clause
|
[
3,
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
421,
199,
533,
4860,
26,
272,
408,
4860,
1021,
367,
1338,
3035,
2552,
14,
21066,
5331,
675,
272,
314,
574,
1627,
14,
25109,
367,
949,
283,
585,
7,
1471,
675,
298,
389,
1674,
4860,
83,
543,
272,
7008,
503,
5117,
10976,
465,
10826,
370,
1172,
949,
574,
14,
339,
6058,
272,
3001,
339,
1306,
1967,
275,
4860,
8,
709,
12,
1125,
13084,
29,
16,
14,
21,
12,
1125,
6666,
29,
16,
14,
24,
9,
272,
1306,
620,
8,
1507,
9,
272,
283,
709,
14,
16,
435,
16,
14,
24,
446,
16,
14,
21,
7,
339,
1306,
1967,
627,
499,
272,
3388,
14,
16,
339,
1306,
1967,
435,
499,
272,
3144,
14,
16,
339,
1306,
1967,
14,
705,
13084,
272,
378,
14,
21,
339,
1306,
1967,
275,
4860,
8,
403,
12,
7008,
3097,
29,
709,
9,
272,
1306,
620,
8,
1507,
9,
272,
2650,
709,
14,
16,
7,
339,
1306,
1967,
508,
488,
272,
715,
339,
1306,
1967,
365,
488,
272,
756,
272,
408,
339,
347,
636,
826,
721,
277,
12,
574,
29,
403,
12,
7008,
3097,
29,
403,
12,
5117,
3097,
29,
403,
12,
326,
1125,
6666,
29,
403,
12,
1125,
13084,
29,
403,
304,
267,
408,
267,
3897,
267,
4143,
267,
574,
26,
2069,
288,
314,
574,
402,
642,
1329,
14,
4860,
83,
543,
7008,
503,
5117,
10976,
288,
5534,
488,
465,
574,
14,
267,
7008,
3097,
26,
2069,
288,
340,
7008,
2304,
3495,
12,
2337,
1077,
506,
949,
574,
267,
5117,
3097,
26,
2069,
288,
340,
5117,
2304,
3495,
12,
2337,
1077,
506,
949,
574,
267,
1125,
6666,
26,
2069,
288,
7381,
574,
267,
1125,
13084,
26,
2069,
288,
7381,
574,
398,
8144,
267,
9063,
398,
4860,
909,
17795,
465,
282,
25780,
2069,
909,
12,
1325,
883,
10266,
267,
1125,
13084,
12,
1125,
6666,
12,
5117,
3097,
12,
7008,
3097,
610,
28491,
267,
5331,
1454,
675,
574,
2225,
14,
4860,
508,
4860,
911,
6540,
267,
314,
1125,
1338,
465,
5521,
465,
574,
14,
398,
1803,
267,
5514,
267,
4860,
909,
14,
267,
408,
267,
340,
574,
365,
488,
26,
288,
291,
14,
585,
275,
488,
267,
587,
26,
288,
862,
26,
355,
291,
14,
585,
275,
2069,
8,
585,
9,
288,
871,
1722,
26,
355,
291,
14,
585,
275,
574,
267,
291,
14,
4142,
3097,
275,
7008,
3097,
267,
291,
14,
2325,
3097,
275,
5117,
3097,
267,
291,
14,
705,
6666,
275,
1125,
6666,
267,
291,
14,
705,
13084,
275,
1125,
13084,
339,
347,
636,
495,
721,
277,
304,
267,
408,
267,
5679,
4704,
267,
3001,
12797,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
430,
267,
283,
18,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
12,
1125,
6666,
29,
17,
14,
16,
12,
1125,
13084,
29,
17,
14,
21,
430,
267,
283,
18,
14,
16,
435,
17,
14,
16,
446,
17,
14,
21,
7,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
12,
1125,
6666,
29,
17,
14,
16,
12,
1125,
13084,
29,
17,
14,
16,
430,
267,
283,
18,
14,
16,
435,
22551,
17,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
2325,
3097,
29,
18,
14,
16,
430,
267,
12696,
18,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
4142,
3097,
29,
18,
14,
16,
430,
267,
2650,
18,
14,
16,
7,
267,
408,
398,
2388,
495,
275,
3087,
267,
340,
291,
14,
585,
365,
440,
488,
26,
288,
2388,
495,
847,
620,
8,
277,
14,
585,
9,
267,
340,
2688,
8,
277,
12,
298,
705,
6666,
531,
436,
291,
14,
705,
6666,
365,
440,
488,
436,
60,
355,
2688,
8,
277,
12,
298,
705,
13084,
531,
436,
291,
14,
705,
13084,
365,
440,
488,
26,
288,
340,
291,
14,
705,
6666,
508,
291,
14,
705,
13084,
26,
355,
2388,
495,
847,
298,
435,
22551,
2,
435,
620,
8,
277,
14,
705,
6666,
9,
288,
587,
26,
355,
2388,
495,
847,
1689,
435,
2,
435,
620,
8,
277,
14,
705,
6666,
9,
435,
298,
446,
2,
435,
1169,
620,
8,
277,
14,
705,
13084,
430,
267,
340,
2688,
8,
277,
12,
298,
4142,
3097,
531,
436,
291,
14,
4142,
3097,
365,
440,
488,
26,
288,
2388,
495,
847,
3886,
2,
435,
620,
8,
277,
14,
4142,
3097,
9,
267,
916,
2688,
8,
277,
12,
298,
2325,
3097,
531,
436,
291,
14,
2325,
3097,
365,
440,
488,
26,
288,
2388,
495,
847,
28192,
435,
620,
8,
277,
14,
2325,
3097,
9,
267,
372,
2388,
495,
339,
347,
6844,
63,
11875,
8,
277,
12,
9432,
21024,
84,
401,
4124,
637,
628,
403,
2349,
267,
408,
267,
10560,
282,
1059,
11619,
367,
282,
6844,
370,
1586,
334,
476,
12,
31448,
9,
267,
14767,
465,
11924,
267,
574,
8,
9896,
9,
705,
6666,
8,
9896,
9,
705,
13084,
8,
9896,
9,
4142,
3097,
8,
9896,
9,
2325,
3097,
398,
340,
314,
574,
1630,
440,
2187,
12,
314,
4124,
637,
365,
3483,
3140,
398,
3897,
267,
4143,
267,
9432,
26,
620,
288,
1059,
1202,
370,
7396,
1338,
1830,
16116,
267,
4124,
637,
26,
620,
288,
1059,
370,
675,
367,
488,
804,
1338,
398,
1803,
267,
5514,
267,
620,
267,
408,
398,
2388,
275,
3087,
267,
340,
2688,
8,
277,
12,
298,
585,
531,
436,
291,
14,
585,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
585,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
705,
6666,
531,
436,
291,
14,
705,
6666,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
705,
6666,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
705,
13084,
531,
436,
291,
14,
705,
13084,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
705,
13084,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
4142,
3097,
531,
436,
291,
14,
4142,
3097,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
4142,
3097,
9,
435,
9432,
267,
587,
26,
288,
2388
] |
[
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
421,
199,
533,
4860,
26,
272,
408,
4860,
1021,
367,
1338,
3035,
2552,
14,
21066,
5331,
675,
272,
314,
574,
1627,
14,
25109,
367,
949,
283,
585,
7,
1471,
675,
298,
389,
1674,
4860,
83,
543,
272,
7008,
503,
5117,
10976,
465,
10826,
370,
1172,
949,
574,
14,
339,
6058,
272,
3001,
339,
1306,
1967,
275,
4860,
8,
709,
12,
1125,
13084,
29,
16,
14,
21,
12,
1125,
6666,
29,
16,
14,
24,
9,
272,
1306,
620,
8,
1507,
9,
272,
283,
709,
14,
16,
435,
16,
14,
24,
446,
16,
14,
21,
7,
339,
1306,
1967,
627,
499,
272,
3388,
14,
16,
339,
1306,
1967,
435,
499,
272,
3144,
14,
16,
339,
1306,
1967,
14,
705,
13084,
272,
378,
14,
21,
339,
1306,
1967,
275,
4860,
8,
403,
12,
7008,
3097,
29,
709,
9,
272,
1306,
620,
8,
1507,
9,
272,
2650,
709,
14,
16,
7,
339,
1306,
1967,
508,
488,
272,
715,
339,
1306,
1967,
365,
488,
272,
756,
272,
408,
339,
347,
636,
826,
721,
277,
12,
574,
29,
403,
12,
7008,
3097,
29,
403,
12,
5117,
3097,
29,
403,
12,
326,
1125,
6666,
29,
403,
12,
1125,
13084,
29,
403,
304,
267,
408,
267,
3897,
267,
4143,
267,
574,
26,
2069,
288,
314,
574,
402,
642,
1329,
14,
4860,
83,
543,
7008,
503,
5117,
10976,
288,
5534,
488,
465,
574,
14,
267,
7008,
3097,
26,
2069,
288,
340,
7008,
2304,
3495,
12,
2337,
1077,
506,
949,
574,
267,
5117,
3097,
26,
2069,
288,
340,
5117,
2304,
3495,
12,
2337,
1077,
506,
949,
574,
267,
1125,
6666,
26,
2069,
288,
7381,
574,
267,
1125,
13084,
26,
2069,
288,
7381,
574,
398,
8144,
267,
9063,
398,
4860,
909,
17795,
465,
282,
25780,
2069,
909,
12,
1325,
883,
10266,
267,
1125,
13084,
12,
1125,
6666,
12,
5117,
3097,
12,
7008,
3097,
610,
28491,
267,
5331,
1454,
675,
574,
2225,
14,
4860,
508,
4860,
911,
6540,
267,
314,
1125,
1338,
465,
5521,
465,
574,
14,
398,
1803,
267,
5514,
267,
4860,
909,
14,
267,
408,
267,
340,
574,
365,
488,
26,
288,
291,
14,
585,
275,
488,
267,
587,
26,
288,
862,
26,
355,
291,
14,
585,
275,
2069,
8,
585,
9,
288,
871,
1722,
26,
355,
291,
14,
585,
275,
574,
267,
291,
14,
4142,
3097,
275,
7008,
3097,
267,
291,
14,
2325,
3097,
275,
5117,
3097,
267,
291,
14,
705,
6666,
275,
1125,
6666,
267,
291,
14,
705,
13084,
275,
1125,
13084,
339,
347,
636,
495,
721,
277,
304,
267,
408,
267,
5679,
4704,
267,
3001,
12797,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
430,
267,
283,
18,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
12,
1125,
6666,
29,
17,
14,
16,
12,
1125,
13084,
29,
17,
14,
21,
430,
267,
283,
18,
14,
16,
435,
17,
14,
16,
446,
17,
14,
21,
7,
267,
1306,
620,
8,
3259,
8,
18,
14,
16,
12,
1125,
6666,
29,
17,
14,
16,
12,
1125,
13084,
29,
17,
14,
16,
430,
267,
283,
18,
14,
16,
435,
22551,
17,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
2325,
3097,
29,
18,
14,
16,
430,
267,
12696,
18,
14,
16,
7,
267,
1306,
620,
8,
3259,
8,
4142,
3097,
29,
18,
14,
16,
430,
267,
2650,
18,
14,
16,
7,
267,
408,
398,
2388,
495,
275,
3087,
267,
340,
291,
14,
585,
365,
440,
488,
26,
288,
2388,
495,
847,
620,
8,
277,
14,
585,
9,
267,
340,
2688,
8,
277,
12,
298,
705,
6666,
531,
436,
291,
14,
705,
6666,
365,
440,
488,
436,
60,
355,
2688,
8,
277,
12,
298,
705,
13084,
531,
436,
291,
14,
705,
13084,
365,
440,
488,
26,
288,
340,
291,
14,
705,
6666,
508,
291,
14,
705,
13084,
26,
355,
2388,
495,
847,
298,
435,
22551,
2,
435,
620,
8,
277,
14,
705,
6666,
9,
288,
587,
26,
355,
2388,
495,
847,
1689,
435,
2,
435,
620,
8,
277,
14,
705,
6666,
9,
435,
298,
446,
2,
435,
1169,
620,
8,
277,
14,
705,
13084,
430,
267,
340,
2688,
8,
277,
12,
298,
4142,
3097,
531,
436,
291,
14,
4142,
3097,
365,
440,
488,
26,
288,
2388,
495,
847,
3886,
2,
435,
620,
8,
277,
14,
4142,
3097,
9,
267,
916,
2688,
8,
277,
12,
298,
2325,
3097,
531,
436,
291,
14,
2325,
3097,
365,
440,
488,
26,
288,
2388,
495,
847,
28192,
435,
620,
8,
277,
14,
2325,
3097,
9,
267,
372,
2388,
495,
339,
347,
6844,
63,
11875,
8,
277,
12,
9432,
21024,
84,
401,
4124,
637,
628,
403,
2349,
267,
408,
267,
10560,
282,
1059,
11619,
367,
282,
6844,
370,
1586,
334,
476,
12,
31448,
9,
267,
14767,
465,
11924,
267,
574,
8,
9896,
9,
705,
6666,
8,
9896,
9,
705,
13084,
8,
9896,
9,
4142,
3097,
8,
9896,
9,
2325,
3097,
398,
340,
314,
574,
1630,
440,
2187,
12,
314,
4124,
637,
365,
3483,
3140,
398,
3897,
267,
4143,
267,
9432,
26,
620,
288,
1059,
1202,
370,
7396,
1338,
1830,
16116,
267,
4124,
637,
26,
620,
288,
1059,
370,
675,
367,
488,
804,
1338,
398,
1803,
267,
5514,
267,
620,
267,
408,
398,
2388,
275,
3087,
267,
340,
2688,
8,
277,
12,
298,
585,
531,
436,
291,
14,
585,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
585,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
705,
6666,
531,
436,
291,
14,
705,
6666,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
705,
6666,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
705,
13084,
531,
436,
291,
14,
705,
13084,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
705,
13084,
9,
435,
9432,
267,
587,
26,
288,
2388,
847,
4124,
637,
435,
9432,
267,
340,
2688,
8,
277,
12,
298,
4142,
3097,
531,
436,
291,
14,
4142,
3097,
365,
440,
488,
26,
288,
2388,
847,
620,
8,
277,
14,
4142,
3097,
9,
435,
9432,
267,
587,
26,
288,
2388,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jinankjain/zamboni
|
scripts/monitors/check_wsgi.py
|
8
|
1259
|
#!/usr/bin/python2.6
"""Makes sure mod_wsgi has been restarted after the last code push i.e,
mod_wsgi is fresher than the mtime on all *.py files in the application dir.
"""
from datetime import datetime
from optparse import OptionParser
import os
from subprocess import PIPE, Popen
import urllib2
def check_modwsgi(app_dir):
find_ = Popen("find %s -name '*.py'" % app_dir, stdout=PIPE, shell=True).communicate()[0]
py_files = find_.strip().split("\n")
newest_mtime = max((os.stat(f).st_mtime, f) for f in py_files)
req = urllib2.Request("http://localhost:81/z/services/loaded",
headers={'Host': 'addons.mozilla.org'})
mod_wsgi = datetime.strptime(urllib2.urlopen(req).read().strip(), '%Y-%m-%d %H:%M:%S.%f')
if mod_wsgi < datetime.fromtimestamp(newest_mtime[0]):
print "CRITICAL: %s is newer than modwsgi (restart apache)" % newest_mtime[1]
return 2
else:
print "OK: mod_wsgi is fresh"
return 0
if __name__ == "__main__":
parser = OptionParser()
parser.add_option('-d', '--app_dir',
help="directory of mod_wsgi app e.g., /data/amo_python/www/prod/zamboni")
options, args = parser.parse_args()
exit(check_modwsgi(options.app_dir))
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
22,
199,
624,
27142,
3238,
3413,
63,
6508,
965,
2757,
32277,
2410,
314,
2061,
1233,
6675,
284,
14,
69,
12,
2043,
3413,
63,
6508,
365,
17480,
281,
2419,
314,
15005,
641,
1006,
23588,
647,
1584,
315,
314,
4223,
2935,
14,
199,
624,
199,
504,
2197,
492,
2197,
199,
504,
8691,
492,
13491,
199,
646,
747,
199,
504,
3873,
492,
22773,
12,
13995,
199,
646,
4011,
18,
199,
199,
318,
1104,
63,
1494,
6508,
8,
571,
63,
694,
304,
272,
2342,
63,
275,
13995,
480,
1623,
450,
83,
446,
354,
11937,
647,
4065,
450,
1145,
63,
694,
12,
3839,
29,
6089,
12,
5218,
29,
549,
680,
10664,
3430,
16,
61,
339,
1134,
63,
1725,
275,
2342,
3754,
1913,
1252,
1294,
4582,
78,
531,
272,
29608,
63,
8180,
275,
1390,
1332,
736,
14,
3736,
8,
70,
680,
270,
63,
8180,
12,
289,
9,
367,
289,
315,
1134,
63,
1725,
9,
339,
2648,
275,
4011,
18,
14,
2017,
480,
1014,
921,
5967,
26,
2835,
15,
90,
15,
5950,
15,
4591,
401,
1169,
2323,
3713,
4965,
356,
283,
10788,
14,
12102,
14,
1308,
3071,
339,
3413,
63,
6508,
275,
2197,
14,
9866,
8,
4078,
18,
14,
10890,
8,
2103,
680,
739,
1252,
1913,
1062,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
358,
339,
340,
3413,
63,
6508,
665,
2197,
14,
18531,
8,
1222,
597,
63,
8180,
59,
16,
4682,
267,
870,
298,
21539,
26,
450,
83,
365,
15666,
2419,
3413,
6508,
334,
10506,
17098,
2924,
450,
29608,
63,
8180,
59,
17,
61,
267,
372,
499,
272,
587,
26,
267,
870,
298,
3593,
26,
3413,
63,
6508,
365,
17480,
2,
267,
372,
378,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
13491,
342,
272,
1798,
14,
525,
63,
1422,
3654,
68,
297,
2850,
571,
63,
694,
297,
267,
1720,
628,
3619,
402,
3413,
63,
6508,
1145,
325,
14,
71,
2020,
1182,
576,
15,
4393,
63,
1548,
15,
1544,
15,
8788,
15,
90,
11020,
265,
73,
531,
2286,
1511,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
4458,
8,
1074,
63,
1494,
6508,
8,
1419,
14,
571,
63,
694,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
18,
14,
22,
199,
624,
27142,
3238,
3413,
63,
6508,
965,
2757,
32277,
2410,
314,
2061,
1233,
6675,
284,
14,
69,
12,
2043,
3413,
63,
6508,
365,
17480,
281,
2419,
314,
15005,
641,
1006,
23588,
647,
1584,
315,
314,
4223,
2935,
14,
199,
624,
199,
504,
2197,
492,
2197,
199,
504,
8691,
492,
13491,
199,
646,
747,
199,
504,
3873,
492,
22773,
12,
13995,
199,
646,
4011,
18,
199,
199,
318,
1104,
63,
1494,
6508,
8,
571,
63,
694,
304,
272,
2342,
63,
275,
13995,
480,
1623,
450,
83,
446,
354,
11937,
647,
4065,
450,
1145,
63,
694,
12,
3839,
29,
6089,
12,
5218,
29,
549,
680,
10664,
3430,
16,
61,
339,
1134,
63,
1725,
275,
2342,
3754,
1913,
1252,
1294,
4582,
78,
531,
272,
29608,
63,
8180,
275,
1390,
1332,
736,
14,
3736,
8,
70,
680,
270,
63,
8180,
12,
289,
9,
367,
289,
315,
1134,
63,
1725,
9,
339,
2648,
275,
4011,
18,
14,
2017,
480,
1014,
921,
5967,
26,
2835,
15,
90,
15,
5950,
15,
4591,
401,
1169,
2323,
3713,
4965,
356,
283,
10788,
14,
12102,
14,
1308,
3071,
339,
3413,
63,
6508,
275,
2197,
14,
9866,
8,
4078,
18,
14,
10890,
8,
2103,
680,
739,
1252,
1913,
1062,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
358,
339,
340,
3413,
63,
6508,
665,
2197,
14,
18531,
8,
1222,
597,
63,
8180,
59,
16,
4682,
267,
870,
298,
21539,
26,
450,
83,
365,
15666,
2419,
3413,
6508,
334,
10506,
17098,
2924,
450,
29608,
63,
8180,
59,
17,
61,
267,
372,
499,
272,
587,
26,
267,
870,
298,
3593,
26,
3413,
63,
6508,
365,
17480,
2,
267,
372,
378,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1798,
275,
13491,
342,
272,
1798,
14,
525,
63,
1422,
3654,
68,
297,
2850,
571,
63,
694,
297,
267,
1720,
628,
3619,
402,
3413,
63,
6508,
1145,
325,
14,
71,
2020,
1182,
576,
15,
4393,
63,
1548,
15,
1544,
15,
8788,
15,
90,
11020,
265,
73,
531,
2286,
1511,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
4458,
8,
1074,
63,
1494,
6508,
8,
1419,
14,
571,
63,
694,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
NicoVarg99/daf-recipes
|
ckan/ckan/ckanext-dcatapit/ckanext/dcatapit/dcat/profiles.py
|
1
|
31302
|
import ast
import logging
import datetime
from pylons import config
from rdflib.namespace import Namespace, RDF, SKOS
from rdflib import URIRef, BNode, Literal
import ckan.logic as logic
from ckanext.dcat.profiles import RDFProfile, DCAT, LOCN, VCARD, DCT, FOAF, ADMS
from ckanext.dcat.utils import catalog_uri, dataset_uri, resource_uri
import ckanext.dcatapit.interfaces as interfaces
import ckanext.dcatapit.helpers as helpers
DCATAPIT = Namespace('http://dati.gov.it/onto/dcatapit#')
it_namespaces = {
'dcatapit': DCATAPIT,
}
THEME_BASE_URI = 'http://publications.europa.eu/resource/authority/data-theme/'
LANG_BASE_URI = 'http://publications.europa.eu/resource/authority/language/'
FREQ_BASE_URI = 'http://publications.europa.eu/resource/authority/frequency/'
FORMAT_BASE_URI = 'http://publications.europa.eu/resource/authority/file-type/'
GEO_BASE_URI = 'http://publications.europa.eu/resource/authority/place/'
# vocabulary name, base URI
THEME_CONCEPTS = ('eu_themes', THEME_BASE_URI)
LANG_CONCEPTS = ('languages', LANG_BASE_URI)
GEO_CONCEPTS = ('places', GEO_BASE_URI)
FREQ_CONCEPTS = ('frequencies', FREQ_BASE_URI)
FORMAT_CONCEPTS = ('filetype', FORMAT_BASE_URI)
DEFAULT_VOCABULARY_KEY = 'OP_DATPRO'
DEFAULT_THEME_KEY = DEFAULT_VOCABULARY_KEY
DEFAULT_FORMAT_CODE = DEFAULT_VOCABULARY_KEY
DEFAULT_FREQ_CODE = 'UNKNOWN'
LOCALISED_DICT_NAME_BASE = 'DCATAPIT_MULTILANG_BASE'
LOCALISED_DICT_NAME_RESOURCES = 'DCATAPIT_MULTILANG_RESOURCES'
lang_mapping_ckan_to_voc = {
'it': 'ITA',
'de': 'DEU',
'en': 'ENG',
'en_GB': 'ENG',
}
lang_mapping_xmllang_to_ckan = {
'it' : 'it',
'de' : 'de',
'en' : 'en_GB' ,
}
format_mapping = {
'WMS': 'MAP_SRVC',
'HTML': 'HTML_SIMPL',
'CSV': 'CSV',
'XLS': 'XLS',
'ODS': 'ODS',
'ZIP': 'OP_DATPRO', # requires to be more specific, can't infer
}
log = logging.getLogger(__name__)
class ItalianDCATAPProfile(RDFProfile):
'''
An RDF profile for the Italian DCAT-AP recommendation for data portals
It requires the European DCAT-AP profile (`euro_dcat_ap`)
'''
def parse_dataset(self, dataset_dict, dataset_ref):
# check the dataset type
if (dataset_ref, RDF.type, DCATAPIT.Dataset) not in self.g:
# not a DCATAPIT dataset
return dataset_dict
# date info
for predicate, key, logf in (
(DCT.issued, 'issued', log.debug),
(DCT.modified, 'modified', log.warn),
):
value = self._object_value(dataset_ref, predicate)
if value:
self._remove_from_extra(dataset_dict, key)
value = helpers.format(value, '%Y-%m-%d', 'date')
dataset_dict[key] = value
else:
logf('No %s found for dataset "%s"', predicate, dataset_dict.get('title', '---'))
# 0..1 predicates
for predicate, key, logf in (
(DCT.identifier, 'identifier', log.warn),
):
value = self._object_value(dataset_ref, predicate)
if value:
self._remove_from_extra(dataset_dict, key)
dataset_dict[key] = value
else:
logf('No %s found for dataset "%s"', predicate, dataset_dict.get('title', '---'))
# 0..n predicates list
for predicate, key, logf in (
(ADMS.identifier, 'alternate_identifier', log.debug),
(DCT.isVersionOf, 'is_version_of', log.debug),
):
valueList = self._object_value_list(dataset_ref, predicate)
if valueList:
self._remove_from_extra(dataset_dict, key)
value = ','.join(valueList)
dataset_dict[key] = value
else:
logf('No %s found for dataset "%s"', predicate, dataset_dict.get('title', '---'))
# conformsTo
self._remove_from_extra(dataset_dict, 'conforms_to')
conform_list = []
for conforms_to in self.g.objects(dataset_ref, DCT.conformsTo):
conform_list.append(self._object_value(conforms_to, DCT.identifier))
if conform_list:
value = ','.join(conform_list)
dataset_dict['conforms_to'] = value
else:
log.debug('No DCT.conformsTo found for dataset "%s"', dataset_dict.get('title', '---'))
# Temporal
start, end = self._time_interval(dataset_ref, DCT.temporal)
for v, key, logf in (
(start, 'temporal_start', log.debug),
(end, 'temporal_end', log.debug),
):
if v:
self._remove_from_extra(dataset_dict, key)
value = helpers.format(v, '%Y-%m-%d', 'date')
dataset_dict[key] = value
else:
log.warn('No %s Date found for dataset "%s"', key, dataset_dict.get('title', '---'))
# URI 0..1
for predicate, key, base_uri in (
(DCT.accrualPeriodicity, 'frequency', FREQ_BASE_URI),
):
valueRef = self._object_value(dataset_ref, predicate)
if valueRef:
self._remove_from_extra(dataset_dict, key)
value = self._strip_uri(valueRef, base_uri)
dataset_dict[key] = value
else:
log.warn('No %s found for dataset "%s"', predicate, dataset_dict.get('title', '---'))
# URI lists
for predicate, key, base_uri in (
(DCT.language, 'language', LANG_BASE_URI),
(DCAT.theme, 'theme', THEME_BASE_URI),
):
self._remove_from_extra(dataset_dict, key)
valueRefList = self._object_value_list(dataset_ref, predicate)
valueList = [self._strip_uri(valueRef, base_uri) for valueRef in valueRefList]
value = ','.join(valueList)
if len(valueList) > 1:
value = '{'+value+'}'
dataset_dict[key] = value
# Spatial
spatial_tags = []
geonames_url = None
for spatial in self.g.objects(dataset_ref, DCT.spatial):
for spatial_literal in self.g.objects(spatial, DCATAPIT.geographicalIdentifier):
spatial_value = spatial_literal.value
if GEO_BASE_URI in spatial_value:
spatial_tags.append(self._strip_uri(spatial_value, GEO_BASE_URI))
else:
if geonames_url:
log.warn("GeoName URL is already set to %s, value %s will not be imported", geonames_url, spatial_value)
else:
geonames_url = spatial_value
if len(spatial_tags) > 0:
value = ','.join(spatial_tags)
if len(spatial_tags) > 1:
value = '{'+value+'}'
dataset_dict['geographical_name'] = value
if geonames_url:
dataset_dict['geographical_geonames_url'] = geonames_url
### Collect strings from multilang fields
# { 'field_name': {'it': 'italian loc', 'de': 'german loc', ...}, ...}
localized_dict = {}
for key, predicate in (
('title', DCT.title),
('notes', DCT.description),
):
self._collect_multilang_strings(dataset_dict, key, dataset_ref, predicate, localized_dict)
# Agents
for predicate, basekey in (
(DCT.publisher, 'publisher'),
(DCT.rightsHolder, 'holder'),
(DCT.creator, 'creator'),
):
agent_dict, agent_loc_dict = self._parse_agent(dataset_ref, predicate, basekey)
for key,v in agent_dict.iteritems():
self._remove_from_extra(dataset_dict, key)
dataset_dict[key] = v
localized_dict.update(agent_loc_dict)
# when all localized data have been parsed, check if there really any and add it to the dict
if len(localized_dict) > 0:
log.debug('Found multilang metadata')
dataset_dict[LOCALISED_DICT_NAME_BASE] = localized_dict
### Resources
resources_loc_dict = {}
# In ckan, the license is a dataset property, not resource's
# We'll collect all of the resources' licenses, then we will postprocess them
licenses = [] # contains tuples (url, name)
for resource_dict in dataset_dict.get('resources', []):
resource_uri = resource_dict['uri']
if not resource_uri:
log.warn("URI not defined for resource %s", resource_dict['name'])
continue
distribution = URIRef(resource_uri)
if not (dataset_ref, DCAT.distribution, distribution) in self.g:
log.warn("Distribution not found in dataset %s", resource_uri)
continue
# URI 0..1
for predicate, key, base_uri in (
(DCT['format'], 'format', FORMAT_BASE_URI), # Format
):
valueRef = self._object_value(distribution, predicate)
if valueRef:
value = self._strip_uri(valueRef, base_uri)
resource_dict[key] = value
else:
log.warn('No %s found for resource "%s"::"%s"',
predicate,
dataset_dict.get('title', '---'),
resource_dict.get('name', '---'))
# License
license = self._object(distribution, DCT.license)
if license:
# just add this info in the resource extras
resource_dict['license_url'] = str(license)
license_name = self._object_value(license, FOAF.name) # may be either the title or the id
if(license_name):
# just add this info in the resource extras
resource_dict['license_name'] = license_name
else:
license_name = "unknown"
licenses.append((str(license), license_name))
else:
log.warn('No license found for resource "%s"::"%s"',
dataset_dict.get('title', '---'),
resource_dict.get('name', '---'))
# Multilang
loc_dict = {}
for key, predicate in (
('name', DCT.title),
('description', DCT.description),
):
self._collect_multilang_strings(resource_dict, key, distribution, predicate, loc_dict)
if len(loc_dict) > 0:
log.debug('Found multilang metadata in resource %s', resource_dict['name'])
resources_loc_dict[resource_uri] = loc_dict
if len(resources_loc_dict) > 0:
log.debug('Found multilang metadata in resources')
dataset_dict[LOCALISED_DICT_NAME_RESOURCES] = resources_loc_dict
# postprocess licenses
# license_ids = {id for url,id in licenses} # does not work in python 2.6
license_ids = set()
for url,id in licenses:
license_ids.add(id)
if license_ids:
if len(license_ids) > 1:
log.warn('More than one license found for dataset "%s"', dataset_dict.get('title', '---'))
dataset_dict['license_id'] = license_ids.pop() # take a random one
return dataset_dict
def _collect_multilang_strings(self, base_dict, key, subj, pred, loc_dict):
'''
Search for multilang Literals matching (subj, pred).
- Literals not localized will be stored as source_dict[key] -- possibly replacing the value set by the EURO parser
- Localized literals will be stored into target_dict[key][lang]
'''
for obj in self.g.objects(subj, pred):
value = obj.value
lang = obj.language
if not lang:
# force default value in dataset
base_dict[key] = value
else:
# add localized string
lang_dict = loc_dict.setdefault(key, {})
lang_dict[lang_mapping_xmllang_to_ckan.get(lang)] = value
def _remove_from_extra(self, dataset_dict, key):
# search and replace
for extra in dataset_dict.get('extras', []):
if extra['key'] == key:
dataset_dict['extras'].pop(dataset_dict['extras'].index(extra))
return
def _add_or_replace_extra(self, dataset_dict, key, value):
# search and replace
for extra in dataset_dict.get('extras', []):
if extra['key'] == key:
extra['value'] = value
return
# add if not found
dataset_dict['extras'].append({'key': key, 'value': value})
def _parse_agent(self, subject, predicate, base_name):
agent_dict = {}
loc_dict= {}
for agent in self.g.objects(subject, predicate):
agent_dict[base_name + '_identifier'] = self._object_value(agent, DCT.identifier)
self._collect_multilang_strings(agent_dict, base_name + '_name', agent, FOAF.name, loc_dict)
return agent_dict, loc_dict
def _strip_uri(self, value, base_uri):
return value.replace(base_uri, '')
def graph_from_dataset(self, dataset_dict, dataset_ref):
title = dataset_dict.get('title')
g = self.g
for prefix, namespace in it_namespaces.iteritems():
g.bind(prefix, namespace)
### add a further type for the Dataset node
g.add((dataset_ref, RDF.type, DCATAPIT.Dataset))
### replace themes
value = self._get_dict_value(dataset_dict, 'theme')
if value:
for theme in value.split(','):
self.g.remove((dataset_ref, DCAT.theme, URIRef(theme)))
theme = theme.replace('{','').replace('}','')
self.g.add((dataset_ref, DCAT.theme, URIRef(THEME_BASE_URI + theme)))
self._add_concept(THEME_CONCEPTS, theme)
else:
self.g.add((dataset_ref, DCAT.theme, URIRef(THEME_BASE_URI + DEFAULT_THEME_KEY)))
self._add_concept(THEME_CONCEPTS, DEFAULT_THEME_KEY)
### replace languages
value = self._get_dict_value(dataset_dict, 'language')
if value:
for lang in value.split(','):
self.g.remove((dataset_ref, DCT.language, Literal(lang)))
lang = lang.replace('{','').replace('}','')
self.g.add((dataset_ref, DCT.language, URIRef(LANG_BASE_URI + lang)))
# self._add_concept(LANG_CONCEPTS, lang)
### add spatial (EU URI)
value = self._get_dict_value(dataset_dict, 'geographical_name')
if value:
for gname in value.split(','):
gname = gname.replace('{','').replace('}','')
dct_location = BNode()
self.g.add((dataset_ref, DCT.spatial, dct_location))
self.g.add((dct_location, RDF['type'], DCT.Location))
# Try and add a Concept from the spatial vocabulary
if self._add_concept(GEO_CONCEPTS, gname):
self.g.add((dct_location, DCATAPIT.geographicalIdentifier, Literal(GEO_BASE_URI + gname)))
# geo concept is not really required, but may be a useful adding
self.g.add((dct_location, LOCN.geographicalName, URIRef(GEO_BASE_URI + gname)))
else:
# The dataset field is not a controlled tag, let's create a Concept out of the label we have
concept = BNode()
self.g.add((concept, RDF['type'], SKOS.Concept))
self.g.add((concept, SKOS.prefLabel, Literal(gname)))
self.g.add((dct_location, LOCN.geographicalName, concept))
### add spatial (GeoNames)
value = self._get_dict_value(dataset_dict, 'geographical_geonames_url')
if value:
dct_location = BNode()
self.g.add((dataset_ref, DCT.spatial, dct_location))
self.g.add((dct_location, RDF['type'], DCT.Location))
self.g.add((dct_location, DCATAPIT.geographicalIdentifier, Literal(value)))
### replace periodicity
self._remove_node(dataset_dict, dataset_ref, ('frequency', DCT.accrualPeriodicity, None, Literal))
self._add_uri_node(dataset_dict, dataset_ref, ('frequency', DCT.accrualPeriodicity, DEFAULT_FREQ_CODE, URIRef), FREQ_BASE_URI)
# self._add_concept(FREQ_CONCEPTS, dataset_dict.get('frequency', DEFAULT_VOCABULARY_KEY))
### replace landing page
self._remove_node(dataset_dict, dataset_ref, ('url', DCAT.landingPage, None, URIRef))
landing_page_uri = None
if dataset_dict.get('name'):
landing_page_uri = '{0}/dataset/{1}'.format(catalog_uri().rstrip('/'), dataset_dict['name'])
else:
landing_page_uri = dataset_uri(dataset_dict) # TODO: preserve original URI if harvested
self.g.add((dataset_ref, DCAT.landingPage, URIRef(landing_page_uri)))
### conformsTo
self.g.remove((dataset_ref, DCT.conformsTo, None))
value = self._get_dict_value(dataset_dict, 'conforms_to')
if value:
for item in value.split(','):
standard = BNode()
self.g.add((dataset_ref, DCT.conformsTo, standard))
self.g.add((standard, RDF['type'], DCT.Standard))
self.g.add((standard, RDF['type'], DCATAPIT.Standard))
self.g.add((standard, DCT.identifier, Literal(item)))
### publisher
# DCAT by default creates this node
# <dct:publisher>
# <foaf:Organization rdf:about="http://10.10.100.75/organization/55535226-f82a-4cf7-903a-3e10afeaa79a">
# <foaf:name>orga2_test</foaf:name>
# </foaf:Organization>
# </dct:publisher>
for s,p,o in g.triples( (dataset_ref, DCT.publisher, None) ):
#log.info("Removing publisher %r", o)
g.remove((s, p, o))
self._add_agent(dataset_dict, dataset_ref, 'publisher', DCT.publisher)
### Rights holder : Agent
holder_ref = self._add_agent(dataset_dict, dataset_ref, 'holder', DCT.rightsHolder)
### Autore : Agent
self._add_agent(dataset_dict, dataset_ref, 'creator', DCT.creator)
### Point of Contact
# <dcat:contactPoint rdf:resource="http://dati.gov.it/resource/PuntoContatto/contactPointRegione_r_liguri"/>
# <!-- http://dati.gov.it/resource/PuntoContatto/contactPointRegione_r_liguri -->
# <dcatapit:Organization rdf:about="http://dati.gov.it/resource/PuntoContatto/contactPointRegione_r_liguri">
# <rdf:type rdf:resource="&vcard;Kind"/>
# <rdf:type rdf:resource="&vcard;Organization"/>
# <vcard:hasEmail rdf:resource="mailto:infoter@regione.liguria.it"/>
# <vcard:fn>Regione Liguria - Sportello Cartografico</vcard:fn>
# </dcatapit:Organization>
# TODO: preserve original info if harvested
# retrieve the contactPoint added by the euro serializer
euro_poc = g.value(subject=dataset_ref, predicate=DCAT.contactPoint, object=None, any=False)
# euro poc has this format:
# <dcat:contactPoint>
# <vcard:Organization rdf:nodeID="Nfcd06f452bcd41f48f33c45b0c95979e">
# <vcard:fn>THE ORGANIZATION NAME</vcard:fn>
# <vcard:hasEmail>THE ORGANIZATION EMAIL</vcard:hasEmail>
# </vcard:Organization>
# </dcat:contactPoint>
if euro_poc:
g.remove((dataset_ref, DCAT.contactPoint, euro_poc))
org_id = dataset_dict.get('organization',{}).get('id')
# get orga info
org_show = logic.get_action('organization_show')
try:
org_dict = org_show({},
{'id': org_id,
'include_datasets': False,
'include_tags': False,
'include_users': False,
'include_groups': False,
'include_extras': True,
'include_followers': False})
except Exception, e:
org_dict = {}
org_uri = organization_uri(org_dict)
poc = URIRef(org_uri)
g.add((dataset_ref, DCAT.contactPoint, poc))
g.add((poc, RDF.type, DCATAPIT.Organization))
g.add((poc, RDF.type, VCARD.Kind))
g.add((poc, RDF.type, VCARD.Organization))
g.add((poc, VCARD.fn, Literal(org_dict.get('name'))))
if 'email' in org_dict.keys(): # this element is mandatory for dcatapit, but it may not have been filled for imported datasets
g.add((poc, VCARD.hasEmail, URIRef(org_dict.get('email'))))
if 'telephone' in org_dict.keys():
g.add((poc, VCARD.hasTelephone, Literal(org_dict.get('telephone'))))
if 'site' in org_dict.keys():
g.add((poc, VCARD.hasURL, Literal(org_dict.get('site'))))
### Multilingual
# Add localized entries in dataset
# TODO: should we remove the non-localized nodes?
loc_dict = interfaces.get_for_package(dataset_dict['id'])
# The multilang fields
loc_package_mapping = {
'title': (dataset_ref, DCT.title),
'notes': (dataset_ref, DCT.description),
'holder_name': (holder_ref, FOAF.name)
}
self._add_multilang_values(loc_dict, loc_package_mapping)
### Resources
for resource_dict in dataset_dict.get('resources', []):
distribution = URIRef(resource_uri(resource_dict)) # TODO: preserve original info if harvested
# Add the DCATAPIT type
g.add((distribution, RDF.type, DCATAPIT.Distribution))
### format
self._remove_node(resource_dict, distribution, ('format', DCT['format'], None, Literal))
if not self._add_uri_node(resource_dict, distribution, ('distribution_format', DCT['format'], None, URIRef), FORMAT_BASE_URI):
guessed_format = guess_format(resource_dict)
if guessed_format:
self.g.add((distribution, DCT['format'], URIRef(FORMAT_BASE_URI + guessed_format)))
else:
log.warn('No format for resource: %s / %s', dataset_dict.get('title', 'N/A'), resource_dict.get('description', 'N/A') )
self.g.add((distribution, DCT['format'], URIRef(FORMAT_BASE_URI + DEFAULT_FORMAT_CODE)))
### license
# <dct:license rdf:resource="http://creativecommons.org/licenses/by/3.0/it/"/>
#
# <dcatapit:LicenseDocument rdf:about="http://creativecommons.org/licenses/by/3.0/it/">
# <rdf:type rdf:resource="&dct;LicenseDocument"/>
# <owl:versionInfo>3.0 ITA</owl:versionInfo>
# <foaf:name>CC BY</foaf:name>
# <dct:type rdf:resource="http://purl.org/adms/licencetype/Attribution"/>
# </dcatapit:LicenseDocument>
# "license_id" : "cc-zero"
# "license_title" : "Creative Commons CCZero",
# "license_url" : "http://www.opendefinition.org/licenses/cc-zero",
license_url = dataset_dict.get('license_url', '')
license_id = dataset_dict.get('license_id', '')
license_title = dataset_dict.get('license_title', '')
if license_url:
license = URIRef(license_url)
g.add((license, RDF['type'], DCATAPIT.LicenseDocument))
g.add((license, RDF['type'], DCT.LicenseDocument))
g.add((license, DCT['type'], URIRef('http://purl.org/adms/licencetype/Attribution'))) # TODO: infer from CKAN license
g.add((distribution, DCT.license, license))
if license_id:
# log.debug('Adding license id: %s', license_id)
g.add((license, FOAF.name, Literal(license_id)))
elif license_title:
# log.debug('Adding license title: %s', license_title)
g.add((license, FOAF.name, Literal(license_title)))
else:
g.add((license, FOAF.name, Literal('unknown')))
log.warn('License not found for dataset: %s', title)
### Multilingual
# Add localized entries in resource
# TODO: should we remove the not-localized nodes?
loc_dict = interfaces.get_for_resource(resource_dict['id'])
# The multilang fields
loc_resource_mapping = {
'name': (distribution, DCT.title),
'description': (distribution, DCT.description),
}
self._add_multilang_values(loc_dict, loc_resource_mapping)
def _add_multilang_values(self, loc_dict, loc_mapping):
if loc_dict:
for field_name, lang_dict in loc_dict.iteritems():
ref, pred = loc_mapping.get(field_name, (None, None))
if not pred:
log.warn('Multilang field not mapped "%s"', field_name)
continue
for lang, value in lang_dict.iteritems():
lang = lang.split('_')[0] # rdflib is quite picky in lang names
self.g.add((ref, pred, Literal(value, lang=lang)))
def _add_agent(self, _dict, ref, basekey, _type):
''' Stores the Agent in this format:
<dct:publisher rdf:resource="http://dati.gov.it/resource/Amministrazione/r_liguri"/>
<dcatapit:Agent rdf:about="http://dati.gov.it/resource/Amministrazione/r_liguri">
<rdf:type rdf:resource="&foaf;Agent"/>
<dct:identifier>r_liguri</dct:identifier>
<foaf:name>Regione Liguria</foaf:name>
</dcatapit:Agent>
Returns the ref to the agent node
'''
agent_name = self._get_dict_value(_dict, basekey + '_name', 'N/A')
agent_id = self._get_dict_value(_dict, basekey + '_identifier','N/A')
agent = BNode()
self.g.add((agent, RDF['type'], DCATAPIT.Agent))
self.g.add((agent, RDF['type'], FOAF.Agent))
self.g.add((ref, _type, agent))
self.g.add((agent, FOAF.name, Literal(agent_name)))
self.g.add((agent, DCT.identifier, Literal(agent_id)))
return agent
def _add_uri_node(self, _dict, ref, item, base_uri=''):
key, pred, fallback, _type = item
value = self._get_dict_value(_dict, key)
if value:
self.g.add((ref, pred, _type(base_uri + value)))
return True
elif fallback:
self.g.add((ref, pred, _type(base_uri + fallback)))
return False
else:
return False
def _remove_node(self, _dict, ref, item):
key, pred, fallback, _type = item
value = self._get_dict_value(_dict, key)
if value:
self.g.remove((ref, pred, _type(value)))
def _add_concept(self, concepts, tag):
# Localized concepts should be serialized as:
#
# <dcat:theme rdf:resource="http://publications.europa.eu/resource/authority/data-theme/ENVI"/>
#
# <skos:Concept rdf:about="http://publications.europa.eu/resource/authority/data-theme/ENVI">
# <skos:prefLabel xml:lang="it">Ambiente</skos:prefLabel>
# </skos:Concept>
#
# Return true if Concept has been added
voc, base_uri = concepts
loc_dict = interfaces.get_all_localized_tag_labels(tag)
if loc_dict and len(loc_dict) > 0:
concept = URIRef(base_uri + tag)
self.g.add((concept, RDF['type'], SKOS.Concept))
for lang, label in loc_dict.iteritems():
lang = lang.split('_')[0] # rdflib is quite picky in lang names
self.g.add((concept, SKOS.prefLabel, Literal(label, lang=lang)))
return True
return False
def graph_from_catalog(self, catalog_dict, catalog_ref):
g = self.g
for prefix, namespace in it_namespaces.iteritems():
g.bind(prefix, namespace)
### Add a further type for the Catalog node
g.add((catalog_ref, RDF.type, DCATAPIT.Catalog))
### Replace homepage
# Try to avoid to have the Catalog URIRef identical to the homepage URI
g.remove((catalog_ref, FOAF.homepage, URIRef(config.get('ckan.site_url'))))
g.add((catalog_ref, FOAF.homepage, URIRef(catalog_uri() + '/#')))
### publisher
pub_agent_name = config.get('ckanext.dcatapit_configpublisher_name', 'unknown')
pub_agent_id = config.get('ckanext.dcatapit_configpublisher_code_identifier', 'unknown')
agent = BNode()
self.g.add((agent, RDF['type'], DCATAPIT.Agent))
self.g.add((agent, RDF['type'], FOAF.Agent))
self.g.add((catalog_ref, DCT.publisher, agent))
self.g.add((agent, FOAF.name, Literal(pub_agent_name)))
self.g.add((agent, DCT.identifier, Literal(pub_agent_id)))
### issued date
issued = config.get('ckanext.dcatapit_config.catalog_issued', '1900-01-01')
if issued:
self._add_date_triple(catalog_ref, DCT.issued, issued)
### theme taxonomy
# <dcat:themeTaxonomy rdf:resource="http://publications.europa.eu/resource/authority/data-theme"/>
# <skos:ConceptScheme rdf:about="http://publications.europa.eu/resource/authority/data-theme">
# <dct:title xml:lang="it">Il Vocabolario Data Theme</dct:title>
# </skos:ConceptScheme>
taxonomy = URIRef(THEME_BASE_URI.rstrip('/'))
self.g.add((catalog_ref, DCAT.themeTaxonomy, taxonomy))
self.g.add((taxonomy, RDF.type, SKOS.ConceptScheme))
self.g.add((taxonomy, DCT.title, Literal('Il Vocabolario Data Theme', lang='it')))
### language
langs = config.get('ckan.locales_offered', 'it')
for lang_offered in langs.split():
lang_code = lang_mapping_ckan_to_voc.get(lang_offered)
self.g.add((catalog_ref, DCT.language, URIRef(LANG_BASE_URI + lang_code)))
self.g.remove((catalog_ref, DCT.language, Literal(config.get('ckan.locale_default', 'en'))))
def organization_uri(orga_dict):
'''
Returns an URI for the organization
This will be used to uniquely reference the organization on the RDF serializations.
The value will be
`catalog_uri()` + '/organization/' + `orga_id`
Check the documentation for `catalog_uri()` for the recommended ways of
setting it.
Returns a string with the resource URI.
'''
uri = '{0}/organization/{1}'.format(catalog_uri().rstrip('/'), orga_dict.get('id', None))
return uri
def guess_format(resource_dict):
f = resource_dict.get('format')
if not f:
log.info('No format found')
return None
ret = format_mapping.get(f, None)
if not ret:
log.info('Mapping not found for format %s', f)
return ret
|
gpl-3.0
|
[
199,
646,
6073,
199,
646,
2050,
199,
646,
2197,
199,
199,
504,
1134,
76,
4654,
492,
1101,
199,
199,
504,
18148,
773,
14,
3251,
492,
19317,
12,
820,
3888,
12,
20062,
3100,
199,
504,
18148,
773,
492,
9022,
2891,
12,
699,
1716,
12,
18271,
199,
199,
646,
22030,
290,
14,
15370,
465,
9661,
199,
199,
504,
22030,
290,
832,
14,
68,
3385,
14,
11225,
492,
820,
3888,
5736,
12,
577,
11206,
12,
3412,
12874,
12,
24955,
7816,
12,
577,
1028,
12,
481,
47,
5699,
12,
16271,
3053,
199,
504,
22030,
290,
832,
14,
68,
3385,
14,
1208,
492,
10594,
63,
2302,
12,
4789,
63,
2302,
12,
2073,
63,
2302,
199,
199,
646,
22030,
290,
832,
14,
3833,
419,
80,
390,
14,
7436,
465,
8386,
199,
646,
22030,
290,
832,
14,
3833,
419,
80,
390,
14,
7546,
465,
10897,
421,
199,
5196,
619,
2642,
275,
19317,
360,
1014,
921,
983,
280,
14,
16294,
14,
390,
15,
26296,
15,
3833,
419,
80,
390,
3,
358,
199,
199,
390,
63,
9247,
275,
469,
272,
283,
3833,
419,
80,
390,
356,
577,
11206,
2642,
12,
199,
93,
199,
199,
18061,
3635,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
576,
13,
7915,
4805,
199,
7442,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
3671,
4805,
199,
38,
14583,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
11132,
4805,
199,
4807,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
493,
13,
466,
4805,
199,
18120,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
2778,
4805,
199,
199,
3,
17515,
536,
12,
1300,
9022,
199,
18061,
3635,
63,
1864,
7177,
51,
275,
661,
16913,
63,
23900,
297,
2334,
3635,
63,
5825,
63,
7639,
9,
199,
7442,
63,
1864,
7177,
51,
275,
661,
13209,
297,
25029,
63,
5825,
63,
7639,
9,
199,
18120,
63,
1864,
7177,
51,
275,
661,
10696,
297,
21390,
63,
5825,
63,
7639,
9,
199,
38,
14583,
63,
1864,
7177,
51,
275,
661,
70,
17085,
297,
481,
14583,
63,
5825,
63,
7639,
9,
199,
4807,
63,
1864,
7177,
51,
275,
661,
30358,
297,
11295,
619,
63,
5825,
63,
7639,
9,
199,
199,
3472,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
275,
283,
1938,
63,
6521,
2514,
7,
199,
3472,
63,
18061,
3635,
63,
3078,
275,
6186,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
199,
3472,
63,
4807,
63,
6012,
275,
6186,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
199,
3472,
63,
38,
14583,
63,
6012,
275,
283,
11588,
7,
199,
199,
7486,
9359,
63,
12511,
63,
2339,
63,
5825,
275,
283,
5196,
619,
2642,
63,
15635,
3986,
63,
5825,
7,
199,
7486,
9359,
63,
12511,
63,
2339,
63,
3830,
11237,
16734,
275,
283,
5196,
619,
2642,
63,
15635,
3986,
63,
3830,
11237,
16734,
7,
199,
199,
4159,
63,
4745,
63,
346,
290,
63,
475,
63,
86,
679,
275,
469,
272,
283,
390,
356,
283,
649,
33,
297,
272,
283,
271,
356,
283,
1093,
53,
297,
272,
283,
287,
356,
283,
742,
39,
297,
272,
283,
287,
63,
6487,
356,
283,
742,
39,
297,
199,
93,
199,
199,
4159,
63,
4745,
63,
1652,
4159,
63,
475,
63,
346,
290,
275,
469,
272,
283,
390,
7,
520,
283,
390,
297,
272,
283,
271,
7,
520,
283,
271,
297,
272,
283,
287,
7,
520,
283,
287,
63,
6487,
7,
2360,
199,
93,
199,
199,
908,
63,
4745,
275,
469,
272,
283,
55,
3053,
356,
283,
5443,
63,
5943,
9454,
297,
272,
283,
4943,
356,
283,
4943,
63,
16590,
2749,
297,
272,
283,
19018,
356,
283,
19018,
297,
272,
283,
56,
5296,
356,
283,
56,
5296,
297,
272,
283,
47,
3177,
356,
283,
47,
3177,
297,
272,
283,
16977,
356,
283,
1938,
63,
6521,
2514,
297,
327,
5074,
370,
506,
1655,
2488,
12,
883,
1133,
18538,
199,
199,
93,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
2779,
25861,
5196,
619,
1282,
5736,
8,
28949,
5736,
304,
272,
1449,
272,
1626,
820,
3888,
4690,
367,
314,
2779,
25861,
577,
11206,
13,
1282,
295,
22105,
367,
666,
1844,
2551,
272,
2779,
5074,
314,
31615,
290,
577,
11206,
13,
1282,
4690,
13493,
27089,
63,
68,
3385,
63,
439,
10522,
272,
1449,
339,
347,
2198,
63,
5214,
8,
277,
12,
4789,
63,
807,
12,
4789,
63,
1121,
304,
398,
327,
1104,
314,
4789,
730,
267,
340,
334,
5214,
63,
1121,
12,
820,
3888,
14,
466,
12,
577,
11206,
2642,
14,
9271,
9,
440,
315,
291,
14,
71,
26,
288,
327,
440,
282,
577,
11206,
2642,
4789,
288,
372,
4789,
63,
807,
398,
327,
1434,
2256,
267,
367,
11944,
12,
790,
12,
943,
70,
315,
334,
355,
334,
36,
1028,
14,
5237,
68,
12,
283,
5237,
68,
297,
943,
14,
1757,
395,
355,
334,
36,
1028,
14,
5540,
12,
283,
5540,
297,
943,
14,
4050,
395,
355,
3461,
288,
574,
275,
291,
423,
785,
63,
585,
8,
5214,
63,
1121,
12,
11944,
9,
288,
340,
574,
26,
355,
291,
423,
2168,
63,
504,
63,
2911,
8,
5214,
63,
807,
12,
790,
9,
2234,
574,
275,
10897,
14,
908,
8,
585,
12,
1543,
57,
3295,
77,
3295,
68,
297,
283,
602,
358,
355,
4789,
63,
807,
59,
498,
61,
275,
574,
288,
587,
26,
355,
943,
70,
360,
1944,
450,
83,
1911,
367,
4789,
2071,
83,
6949,
11944,
12,
4789,
63,
807,
14,
362,
360,
1213,
297,
283,
2595,
1333,
398,
327,
378,
703,
17,
11944,
83,
267,
367,
11944,
12,
790,
12,
943,
70,
315,
334,
355,
334,
36,
1028,
14,
5364,
12,
283,
5364,
297,
943,
14,
4050,
395,
355,
3461,
288,
574,
275,
291,
423,
785,
63,
585,
8,
5214,
63,
1121,
12,
11944,
9,
288,
340,
574,
26,
355,
291,
423,
2168,
63,
504,
63,
2911,
8,
5214,
63,
807,
12,
790,
9,
355,
4789,
63,
807,
59,
498,
61,
275,
574,
288,
587,
26,
355,
943,
70,
360,
1944
] |
[
646,
6073,
199,
646,
2050,
199,
646,
2197,
199,
199,
504,
1134,
76,
4654,
492,
1101,
199,
199,
504,
18148,
773,
14,
3251,
492,
19317,
12,
820,
3888,
12,
20062,
3100,
199,
504,
18148,
773,
492,
9022,
2891,
12,
699,
1716,
12,
18271,
199,
199,
646,
22030,
290,
14,
15370,
465,
9661,
199,
199,
504,
22030,
290,
832,
14,
68,
3385,
14,
11225,
492,
820,
3888,
5736,
12,
577,
11206,
12,
3412,
12874,
12,
24955,
7816,
12,
577,
1028,
12,
481,
47,
5699,
12,
16271,
3053,
199,
504,
22030,
290,
832,
14,
68,
3385,
14,
1208,
492,
10594,
63,
2302,
12,
4789,
63,
2302,
12,
2073,
63,
2302,
199,
199,
646,
22030,
290,
832,
14,
3833,
419,
80,
390,
14,
7436,
465,
8386,
199,
646,
22030,
290,
832,
14,
3833,
419,
80,
390,
14,
7546,
465,
10897,
421,
199,
5196,
619,
2642,
275,
19317,
360,
1014,
921,
983,
280,
14,
16294,
14,
390,
15,
26296,
15,
3833,
419,
80,
390,
3,
358,
199,
199,
390,
63,
9247,
275,
469,
272,
283,
3833,
419,
80,
390,
356,
577,
11206,
2642,
12,
199,
93,
199,
199,
18061,
3635,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
576,
13,
7915,
4805,
199,
7442,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
3671,
4805,
199,
38,
14583,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
11132,
4805,
199,
4807,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
493,
13,
466,
4805,
199,
18120,
63,
5825,
63,
7639,
275,
283,
1014,
921,
27190,
14,
27089,
387,
14,
16913,
15,
1927,
15,
23635,
15,
2778,
4805,
199,
199,
3,
17515,
536,
12,
1300,
9022,
199,
18061,
3635,
63,
1864,
7177,
51,
275,
661,
16913,
63,
23900,
297,
2334,
3635,
63,
5825,
63,
7639,
9,
199,
7442,
63,
1864,
7177,
51,
275,
661,
13209,
297,
25029,
63,
5825,
63,
7639,
9,
199,
18120,
63,
1864,
7177,
51,
275,
661,
10696,
297,
21390,
63,
5825,
63,
7639,
9,
199,
38,
14583,
63,
1864,
7177,
51,
275,
661,
70,
17085,
297,
481,
14583,
63,
5825,
63,
7639,
9,
199,
4807,
63,
1864,
7177,
51,
275,
661,
30358,
297,
11295,
619,
63,
5825,
63,
7639,
9,
199,
199,
3472,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
275,
283,
1938,
63,
6521,
2514,
7,
199,
3472,
63,
18061,
3635,
63,
3078,
275,
6186,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
199,
3472,
63,
4807,
63,
6012,
275,
6186,
63,
10662,
35,
1217,
3038,
57,
63,
3078,
199,
3472,
63,
38,
14583,
63,
6012,
275,
283,
11588,
7,
199,
199,
7486,
9359,
63,
12511,
63,
2339,
63,
5825,
275,
283,
5196,
619,
2642,
63,
15635,
3986,
63,
5825,
7,
199,
7486,
9359,
63,
12511,
63,
2339,
63,
3830,
11237,
16734,
275,
283,
5196,
619,
2642,
63,
15635,
3986,
63,
3830,
11237,
16734,
7,
199,
199,
4159,
63,
4745,
63,
346,
290,
63,
475,
63,
86,
679,
275,
469,
272,
283,
390,
356,
283,
649,
33,
297,
272,
283,
271,
356,
283,
1093,
53,
297,
272,
283,
287,
356,
283,
742,
39,
297,
272,
283,
287,
63,
6487,
356,
283,
742,
39,
297,
199,
93,
199,
199,
4159,
63,
4745,
63,
1652,
4159,
63,
475,
63,
346,
290,
275,
469,
272,
283,
390,
7,
520,
283,
390,
297,
272,
283,
271,
7,
520,
283,
271,
297,
272,
283,
287,
7,
520,
283,
287,
63,
6487,
7,
2360,
199,
93,
199,
199,
908,
63,
4745,
275,
469,
272,
283,
55,
3053,
356,
283,
5443,
63,
5943,
9454,
297,
272,
283,
4943,
356,
283,
4943,
63,
16590,
2749,
297,
272,
283,
19018,
356,
283,
19018,
297,
272,
283,
56,
5296,
356,
283,
56,
5296,
297,
272,
283,
47,
3177,
356,
283,
47,
3177,
297,
272,
283,
16977,
356,
283,
1938,
63,
6521,
2514,
297,
327,
5074,
370,
506,
1655,
2488,
12,
883,
1133,
18538,
199,
199,
93,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
2779,
25861,
5196,
619,
1282,
5736,
8,
28949,
5736,
304,
272,
1449,
272,
1626,
820,
3888,
4690,
367,
314,
2779,
25861,
577,
11206,
13,
1282,
295,
22105,
367,
666,
1844,
2551,
272,
2779,
5074,
314,
31615,
290,
577,
11206,
13,
1282,
4690,
13493,
27089,
63,
68,
3385,
63,
439,
10522,
272,
1449,
339,
347,
2198,
63,
5214,
8,
277,
12,
4789,
63,
807,
12,
4789,
63,
1121,
304,
398,
327,
1104,
314,
4789,
730,
267,
340,
334,
5214,
63,
1121,
12,
820,
3888,
14,
466,
12,
577,
11206,
2642,
14,
9271,
9,
440,
315,
291,
14,
71,
26,
288,
327,
440,
282,
577,
11206,
2642,
4789,
288,
372,
4789,
63,
807,
398,
327,
1434,
2256,
267,
367,
11944,
12,
790,
12,
943,
70,
315,
334,
355,
334,
36,
1028,
14,
5237,
68,
12,
283,
5237,
68,
297,
943,
14,
1757,
395,
355,
334,
36,
1028,
14,
5540,
12,
283,
5540,
297,
943,
14,
4050,
395,
355,
3461,
288,
574,
275,
291,
423,
785,
63,
585,
8,
5214,
63,
1121,
12,
11944,
9,
288,
340,
574,
26,
355,
291,
423,
2168,
63,
504,
63,
2911,
8,
5214,
63,
807,
12,
790,
9,
2234,
574,
275,
10897,
14,
908,
8,
585,
12,
1543,
57,
3295,
77,
3295,
68,
297,
283,
602,
358,
355,
4789,
63,
807,
59,
498,
61,
275,
574,
288,
587,
26,
355,
943,
70,
360,
1944,
450,
83,
1911,
367,
4789,
2071,
83,
6949,
11944,
12,
4789,
63,
807,
14,
362,
360,
1213,
297,
283,
2595,
1333,
398,
327,
378,
703,
17,
11944,
83,
267,
367,
11944,
12,
790,
12,
943,
70,
315,
334,
355,
334,
36,
1028,
14,
5364,
12,
283,
5364,
297,
943,
14,
4050,
395,
355,
3461,
288,
574,
275,
291,
423,
785,
63,
585,
8,
5214,
63,
1121,
12,
11944,
9,
288,
340,
574,
26,
355,
291,
423,
2168,
63,
504,
63,
2911,
8,
5214,
63,
807,
12,
790,
9,
355,
4789,
63,
807,
59,
498,
61,
275,
574,
288,
587,
26,
355,
943,
70,
360,
1944,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Smana/setup-kubernetes
|
library/kpm.py
|
16
|
3305
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import kpm.deploy
from ansible.module_utils.basic import *
DOCUMENTATION = """
---
module: kpm
short_description: Application deployment on kubernetes with kpm registry
description:
- Create, remove, and update resources within a Kubernetes Cluster
version_added: "2.0"
options:
name:
required: true
default: null
description:
- The name of the kpm package
namespace:
required: false
default: 'default'
description:
- The namespace to deploy package. It will be created if doesn't exist
force:
required: false
default: false
description:
- A flag to indicate to force delete, replace.
registry:
required: false
default: 'https://api.kpm.sh'
description:
- The registry url to fetch packages
version:
required: false
default: 'None'
description:
- The package version
variables:
required: false
default: 'None'
description:
- Set package variables
state:
required: false
choices: ['present', 'absent']
default: present
description:
- present handles checking existence or creating resources,
absent handles deleting resource(s).
requirements:
- kubectl
- kpm
author: "Antoine Legrand (ant31_2t@msn.com)"
"""
EXAMPLES = """
- name: check presence or install ghost
kpm: name=ghost/ghost state=present
- name: check absence or remove rocketchat
kpm: name=ant31/rocketchat state=absent
"""
RETURN = """
"""
def check_changed(result, state='present'):
no_change = ["ok", 'protected', 'absent']
for r in result:
if r['status'] not in no_change:
return True
return False
def main():
module = AnsibleModule(
supports_check_mode=True,
argument_spec = dict(
version = dict(default=None, required=False),
state = dict(default='present', choices=['present', 'absent']),
name = dict(required=True),
force = dict(required=False, default=False, type='bool'),
variables = dict(required=False, default=None, type='dict'),
registry = dict(required=False, default="https://api.kpm.sh"),
namespace=dict(default='default', required=False)))
params = {"version": module.params.get("version"),
"namespace": module.params.get('namespace'),
"variables": module.params.get('variables'),
"endpoint": module.params.get('registry'),
"dry": module.check_mode,
"proxy": None,
"fmt": "json"}
state = module.params.get("state")
try:
if state == 'present':
r = kpm.deploy.deploy(module.params.get('name'), **params)
elif state == 'absent':
r = kpm.deploy.delete(module.params.get('name'), **params)
except Exception as e:
module.fail_json(msg=e.message)
res = {}
res['kpm'] = r
res['changed'] = check_changed(r, state)
module.exit_json(**res)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
1022,
7073,
14,
11060,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1022,
7073,
199,
3612,
63,
1802,
26,
13515,
14295,
641,
31160,
543,
1022,
7073,
7086,
199,
1802,
26,
523,
446,
2790,
12,
2813,
12,
436,
1678,
5944,
4453,
282,
28723,
16454,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
536,
26,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
1022,
7073,
2559,
523,
3231,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
885,
7,
272,
1369,
26,
489,
446,
710,
3231,
370,
12287,
2559,
14,
2779,
911,
506,
2737,
340,
3181,
1133,
2187,
523,
3542,
26,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
1369,
26,
489,
446,
437,
3305,
370,
6623,
370,
3542,
3145,
12,
3350,
14,
523,
7086,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
2859,
921,
1246,
14,
75,
7073,
14,
609,
7,
272,
1369,
26,
489,
446,
710,
7086,
1166,
370,
5267,
6117,
523,
1015,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
403,
7,
272,
1369,
26,
489,
446,
710,
2559,
1015,
523,
2860,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
403,
7,
272,
1369,
26,
489,
446,
2494,
2559,
2860,
523,
1174,
26,
272,
1415,
26,
3055,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
272,
1369,
26,
489,
446,
3451,
10022,
7907,
23780,
503,
6425,
5944,
12,
267,
9552,
10022,
13794,
2073,
8,
83,
680,
199,
7538,
26,
523,
446,
1022,
31532,
523,
446,
1022,
7073,
199,
2502,
26,
298,
33,
29680,
1132,
7005,
22655,
334,
867,
2192,
63,
18,
84,
32,
706,
78,
14,
957,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1104,
20024,
503,
3907,
486,
1102,
523,
1022,
7073,
26,
536,
29,
71,
1102,
15,
71,
1102,
1174,
29,
1881,
199,
199,
13,
536,
26,
1104,
2236,
14073,
503,
2813,
882,
2284,
10289,
523,
1022,
7073,
26,
536,
29,
867,
2192,
15,
293,
2284,
10289,
1174,
29,
5575,
199,
624,
199,
199,
9677,
275,
408,
199,
624,
421,
199,
318,
1104,
63,
2489,
8,
1099,
12,
1174,
534,
1881,
735,
267,
949,
63,
1461,
275,
2097,
745,
401,
283,
6798,
297,
283,
5575,
418,
267,
367,
519,
315,
754,
26,
355,
340,
519,
459,
1205,
418,
440,
315,
949,
63,
1461,
26,
717,
372,
715,
267,
372,
756,
421,
199,
318,
2446,
837,
267,
859,
275,
6953,
8,
355,
5171,
63,
1074,
63,
632,
29,
549,
12,
355,
1423,
63,
1650,
275,
1211,
8,
717,
1015,
275,
1211,
8,
885,
29,
403,
12,
1415,
29,
797,
395,
717,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
717,
536,
275,
1211,
8,
2427,
29,
549,
395,
717,
3542,
275,
1211,
8,
2427,
29,
797,
12,
849,
29,
797,
12,
730,
534,
2245,
659,
717,
2860,
275,
1211,
8,
2427,
29,
797,
12,
849,
29,
403,
12,
730,
534,
807,
659,
717,
7086,
275,
1211,
8,
2427,
29,
797,
12,
849,
628,
2859,
921,
1246,
14,
75,
7073,
14,
609,
1288,
717,
3231,
29,
807,
8,
885,
534,
885,
297,
1415,
29,
797,
1724,
398,
1862,
275,
2420,
1023,
582,
859,
14,
1162,
14,
362,
480,
1023,
1288,
2116,
298,
3251,
582,
859,
14,
1162,
14,
362,
360,
3251,
659,
2116,
298,
3669,
582,
859,
14,
1162,
14,
362,
360,
3669,
659,
2116,
298,
6520,
582,
859,
14,
1162,
14,
362,
360,
5189,
659,
2116,
298,
10481,
582,
859,
14,
1074,
63,
632,
12,
2116,
298,
3280,
582,
488,
12,
2116,
298,
5045,
582,
298,
1001,
3570,
267,
1174,
275,
859,
14,
1162,
14,
362,
480,
929,
531,
267,
862,
26,
355,
340,
1174,
508,
283,
1881,
356,
717,
519,
275,
1022,
7073,
14,
11060,
14,
11060,
8,
578,
14,
1162,
14,
362,
360,
354,
659,
1011,
1162,
9,
355,
916,
1174,
508,
283,
5575,
356,
717,
519,
275,
1022,
7073,
14,
11060,
14,
1807,
8,
578,
14,
1162,
14,
362,
360,
354,
659,
1011,
1162,
9,
267,
871,
2186,
465,
325,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
29,
69,
14,
1188,
9,
267,
522,
275,
1052,
267,
522,
459,
75,
7073,
418,
275,
519,
267,
522,
459,
2489,
418,
275,
1104,
63,
2489,
8,
82,
12,
1174,
9,
267,
859,
14,
2224,
63,
1001,
3682,
470,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
267,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
1022,
7073,
14,
11060,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1022,
7073,
199,
3612,
63,
1802,
26,
13515,
14295,
641,
31160,
543,
1022,
7073,
7086,
199,
1802,
26,
523,
446,
2790,
12,
2813,
12,
436,
1678,
5944,
4453,
282,
28723,
16454,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
536,
26,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
1022,
7073,
2559,
523,
3231,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
885,
7,
272,
1369,
26,
489,
446,
710,
3231,
370,
12287,
2559,
14,
2779,
911,
506,
2737,
340,
3181,
1133,
2187,
523,
3542,
26,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
1369,
26,
489,
446,
437,
3305,
370,
6623,
370,
3542,
3145,
12,
3350,
14,
523,
7086,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
2859,
921,
1246,
14,
75,
7073,
14,
609,
7,
272,
1369,
26,
489,
446,
710,
7086,
1166,
370,
5267,
6117,
523,
1015,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
403,
7,
272,
1369,
26,
489,
446,
710,
2559,
1015,
523,
2860,
26,
272,
1415,
26,
3055,
272,
849,
26,
283,
403,
7,
272,
1369,
26,
489,
446,
2494,
2559,
2860,
523,
1174,
26,
272,
1415,
26,
3055,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
272,
1369,
26,
489,
446,
3451,
10022,
7907,
23780,
503,
6425,
5944,
12,
267,
9552,
10022,
13794,
2073,
8,
83,
680,
199,
7538,
26,
523,
446,
1022,
31532,
523,
446,
1022,
7073,
199,
2502,
26,
298,
33,
29680,
1132,
7005,
22655,
334,
867,
2192,
63,
18,
84,
32,
706,
78,
14,
957,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1104,
20024,
503,
3907,
486,
1102,
523,
1022,
7073,
26,
536,
29,
71,
1102,
15,
71,
1102,
1174,
29,
1881,
199,
199,
13,
536,
26,
1104,
2236,
14073,
503,
2813,
882,
2284,
10289,
523,
1022,
7073,
26,
536,
29,
867,
2192,
15,
293,
2284,
10289,
1174,
29,
5575,
199,
624,
199,
199,
9677,
275,
408,
199,
624,
421,
199,
318,
1104,
63,
2489,
8,
1099,
12,
1174,
534,
1881,
735,
267,
949,
63,
1461,
275,
2097,
745,
401,
283,
6798,
297,
283,
5575,
418,
267,
367,
519,
315,
754,
26,
355,
340,
519,
459,
1205,
418,
440,
315,
949,
63,
1461,
26,
717,
372,
715,
267,
372,
756,
421,
199,
318,
2446,
837,
267,
859,
275,
6953,
8,
355,
5171,
63,
1074,
63,
632,
29,
549,
12,
355,
1423,
63,
1650,
275,
1211,
8,
717,
1015,
275,
1211,
8,
885,
29,
403,
12,
1415,
29,
797,
395,
717,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
717,
536,
275,
1211,
8,
2427,
29,
549,
395,
717,
3542,
275,
1211,
8,
2427,
29,
797,
12,
849,
29,
797,
12,
730,
534,
2245,
659,
717,
2860,
275,
1211,
8,
2427,
29,
797,
12,
849,
29,
403,
12,
730,
534,
807,
659,
717,
7086,
275,
1211,
8,
2427,
29,
797,
12,
849,
628,
2859,
921,
1246,
14,
75,
7073,
14,
609,
1288,
717,
3231,
29,
807,
8,
885,
534,
885,
297,
1415,
29,
797,
1724,
398,
1862,
275,
2420,
1023,
582,
859,
14,
1162,
14,
362,
480,
1023,
1288,
2116,
298,
3251,
582,
859,
14,
1162,
14,
362,
360,
3251,
659,
2116,
298,
3669,
582,
859,
14,
1162,
14,
362,
360,
3669,
659,
2116,
298,
6520,
582,
859,
14,
1162,
14,
362,
360,
5189,
659,
2116,
298,
10481,
582,
859,
14,
1074,
63,
632,
12,
2116,
298,
3280,
582,
488,
12,
2116,
298,
5045,
582,
298,
1001,
3570,
267,
1174,
275,
859,
14,
1162,
14,
362,
480,
929,
531,
267,
862,
26,
355,
340,
1174,
508,
283,
1881,
356,
717,
519,
275,
1022,
7073,
14,
11060,
14,
11060,
8,
578,
14,
1162,
14,
362,
360,
354,
659,
1011,
1162,
9,
355,
916,
1174,
508,
283,
5575,
356,
717,
519,
275,
1022,
7073,
14,
11060,
14,
1807,
8,
578,
14,
1162,
14,
362,
360,
354,
659,
1011,
1162,
9,
267,
871,
2186,
465,
325,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
29,
69,
14,
1188,
9,
267,
522,
275,
1052,
267,
522,
459,
75,
7073,
418,
275,
519,
267,
522,
459,
2489,
418,
275,
1104,
63,
2489,
8,
82,
12,
1174,
9,
267,
859,
14,
2224,
63,
1001,
3682,
470,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
267,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
msebire/intellij-community
|
python/helpers/py3only/docutils/io.py
|
44
|
17042
|
# $Id: io.py 7596 2013-01-25 13:42:17Z 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
exist for a variety of input/output mechanisms.
"""
__docformat__ = 'reStructuredText'
import codecs
import os
import re
import sys
from docutils import TransformSpec
from docutils._compat import b
from docutils.utils.error_reporting import locale_encoding, ErrorString, ErrorOutput
class InputError(IOError): pass
class OutputError(IOError): pass
def check_encoding(stream, encoding):
"""Test, whether the encoding of `stream` matches `encoding`.
Returns
:None: if `encoding` or `stream.encoding` are not a valid encoding
argument (e.g. ``None``) or `stream.encoding is missing.
:True: if the encoding argument resolves to the same value as `encoding`,
:False: if the encodings differ.
"""
try:
return codecs.lookup(stream.encoding) == codecs.lookup(encoding)
except (LookupError, AttributeError, TypeError):
return None
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, str), (
'input encoding is "unicode" '
'but input is not a unicode object')
if isinstance(data, str):
# 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', 'latin-1']
if locale_encoding:
encodings.insert(1, locale_encoding)
for enc in encodings:
try:
decoded = str(data, enc, self.error_handler)
self.successful_encoding = enc
# Return decoded, removing BOMs.
return decoded.replace('\ufeff', '')
except (UnicodeError, LookupError) as err:
error = err # in Python 3, the <exception instance> is
# local to the except clause
raise UnicodeError(
'Unable to decode input data. Tried the following encodings: '
'%s.\n(%s)' % (', '.join([repr(enc) for enc in encodings]),
ErrorString(error)))
coding_slug = re.compile(b("coding[:=]\s*([-\w.]+)"))
"""Encoding declaration pattern."""
byte_order_marks = ((codecs.BOM_UTF8, 'utf-8'), # 'utf-8-sig' new in v2.5
(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, str), (
'the encoding given is "unicode" but the output is not '
'a Unicode string')
return data
if not isinstance(data, str):
# Non-unicode (e.g. bytes) 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=True, handle_io_errors=None, 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 (except when
`sys.stdin` is the source).
- `handle_io_errors`: ignored, deprecated, will be removed.
- `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._stderr = ErrorOutput()
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 as error:
raise InputError(error.errno, error.strerror, source_path)
else:
self.source = sys.stdin
elif (sys.version_info >= (3,0) and
check_encoding(self.source, self.encoding) is False):
# TODO: re-open, warn or raise error?
raise UnicodeError('Encoding clash: encoding given is "%s" '
'but source is opened with encoding "%s".' %
(self.encoding, self.source.encoding))
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: # In Python < 2.5, try...except has to be nested in try...finally.
try:
if self.source is sys.stdin and sys.version_info >= (3,0):
# read as binary data to circumvent auto-decoding
data = self.source.buffer.read()
# normalize newlines
data = b('\n').join(data.splitlines()) + b('\n')
else:
data = self.source.read()
except (UnicodeError, LookupError) as err: # (in Py3k read() decodes)
if not self.encoding and self.source_path:
# re-read in binary mode and decode with heuristics
b_source = open(self.source_path, 'rb')
data = b_source.read()
b_source.close()
# normalize newlines
data = b('\n').join(data.splitlines()) + b('\n')
else:
raise
finally:
if self.autoclose:
self.close()
return self.decode(data)
def readlines(self):
"""
Return lines of a single file as list of Unicode strings.
"""
return self.read().splitlines(True)
def close(self):
if self.source is not sys.stdin:
self.source.close()
class FileOutput(Output):
"""
Output for single, simple file-like objects.
"""
mode = 'w'
"""The mode argument for `open()`."""
# 'wb' for binary (e.g. OpenOffice) files (see also `BinaryFileOutput`).
# (Do not use binary mode ('wb') for text files, as this prevents the
# conversion of newlines to the system specific default.)
def __init__(self, destination=None, destination_path=None,
encoding=None, error_handler='strict', autoclose=True,
handle_io_errors=None, mode=None):
"""
: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.
- `encoding`: the text encoding of the output file.
- `error_handler`: the encoding error handler to use.
- `autoclose`: close automatically after write (except when
`sys.stdout` or `sys.stderr` is the destination).
- `handle_io_errors`: ignored, deprecated, will be removed.
- `mode`: how the file is to be opened (see standard function
`open`). The default is 'w', providing universal newline
support for text files.
"""
Output.__init__(self, destination, destination_path,
encoding, error_handler)
self.opened = True
self.autoclose = autoclose
if mode is not None:
self.mode = mode
self._stderr = ErrorOutput()
if destination is None:
if destination_path:
self.opened = False
else:
self.destination = sys.stdout
elif (# destination is file-type object -> check mode:
mode and hasattr(self.destination, 'mode')
and mode != self.destination.mode):
print(('Warning: Destination mode "%s" '
'differs from specified mode "%s"' %
(self.destination.mode, mode)), file=self._stderr)
if not destination_path:
try:
self.destination_path = self.destination.name
except AttributeError:
pass
def open(self):
# Specify encoding in Python 3.
if sys.version_info >= (3,0) and 'b' not in self.mode:
kwargs = {'encoding': self.encoding,
'errors': self.error_handler}
else:
kwargs = {}
try:
self.destination = open(self.destination_path, self.mode, **kwargs)
except IOError as error:
raise OutputError(error.errno, error.strerror,
self.destination_path)
self.opened = True
def write(self, data):
"""Encode `data`, write it to a single file, and return it.
With Python 3 or binary output mode, `data` is returned unchanged,
except when specified encoding and output encoding differ.
"""
if not self.opened:
self.open()
if ('b' not in self.mode and sys.version_info < (3,0)
or check_encoding(self.destination, self.encoding) is False
):
if sys.version_info >= (3,0) and os.linesep != '\n':
data = data.replace('\n', os.linesep) # fix endings
data = self.encode(data)
try: # In Python < 2.5, try...except has to be nested in try...finally.
try:
self.destination.write(data)
except TypeError as e:
if sys.version_info >= (3,0) and isinstance(data, bytes):
try:
self.destination.buffer.write(data)
except AttributeError:
if check_encoding(self.destination,
self.encoding) is False:
raise ValueError('Encoding of %s (%s) differs \n'
' from specified encoding (%s)' %
(self.destination_path or 'destination',
self.destination.encoding, self.encoding))
else:
raise e
except (UnicodeError, LookupError) as err:
raise UnicodeError(
'Unable to encode output data. output-encoding is: '
'%s.\n(%s)' % (self.encoding, ErrorString(err)))
finally:
if self.autoclose:
self.close()
return data
def close(self):
if self.destination not in (sys.stdout, sys.stderr):
self.destination.close()
self.opened = False
class BinaryFileOutput(FileOutput):
"""
A version of docutils.io.FileOutput which writes to a binary file.
"""
# Used by core.publish_cmdline_to_binary() which in turn is used by
# rst2odt (OpenOffice writer)
mode = 'wb'
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 ''
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,
1520,
15112,
6171,
13,
614,
13,
821,
4944,
26,
2260,
26,
1196,
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,
4494,
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,
6010,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
504,
18382,
492,
19463,
5307,
199,
504,
18382,
423,
5819,
492,
330,
199,
504,
18382,
14,
1208,
14,
705,
63,
28071,
492,
5867,
63,
2991,
12,
4520,
1558,
12,
4520,
2959,
421,
199,
533,
6924,
547,
8,
13760,
304,
986,
199,
533,
7242,
547,
8,
13760,
304,
986,
199,
199,
318,
1104,
63,
2991,
8,
1745,
12,
2644,
304,
272,
408,
774,
12,
3775,
314,
2644,
402,
658,
1745,
64,
4450,
658,
2991,
2313,
339,
1803,
339,
520,
403,
26,
221,
340,
658,
2991,
64,
503,
658,
1745,
14,
2991,
64,
787,
440,
282,
1686,
2644,
288,
1423,
334,
69,
14,
71,
14,
1124,
403,
16580,
503,
658,
1745,
14,
2991,
365,
4124,
14,
272,
520,
549,
26,
221,
340,
314,
2644,
1423,
32253,
370,
314,
2011,
574,
465,
658,
2991,
3559,
272,
520,
797,
26,
340,
314,
14134,
14460,
14,
272,
408,
272,
862,
26,
267,
372,
6010,
14,
3892,
8,
1745,
14,
2991,
9,
508,
6010,
14,
3892,
8,
2991,
9,
272,
871,
334,
32060,
12,
4281,
12,
3146,
304,
267,
372,
488,
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,
620,
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,
620,
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,
297,
283,
10378,
13,
17,
418,
355,
340,
5867,
63,
2991,
26,
490,
14134,
14,
3176,
8,
17,
12,
5867,
63,
2991,
9,
267,
367,
12011,
315,
14134,
26,
288,
862,
26,
355,
11203,
275,
620,
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,
2258,
7224,
556,
297,
4074,
288,
871,
334,
7087,
547,
12,
19021,
9,
465,
2329,
26,
355,
1125,
275,
2329,
327,
315,
2018,
650,
12,
314,
665,
1971,
1256,
30,
365,
1169,
327,
2257,
370,
314,
871,
8502,
267,
746,
20872,
8,
288,
283,
6005,
370,
4849,
1324,
666,
14,
221,
12480,
379,
314,
2569,
14134,
26,
283,
288,
1543,
83,
3134,
78,
4042,
83,
3171,
450,
334,
297,
1987,
904,
779,
2722,
8,
10945,
9,
367,
12011,
315,
14134,
2522,
586,
4520,
1558,
8,
705,
1724,
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,
283,
1624,
13,
24,
13,
4093,
7,
892,
315,
373,
18,
14,
21,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
12,
283,
1624,
13,
975,
13,
1235,
659,
717,
334,
8933,
14
] |
[
2672,
1304,
26,
5890,
14,
647,
1520,
15112,
6171,
13,
614,
13,
821,
4944,
26,
2260,
26,
1196,
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,
4494,
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,
6010,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
504,
18382,
492,
19463,
5307,
199,
504,
18382,
423,
5819,
492,
330,
199,
504,
18382,
14,
1208,
14,
705,
63,
28071,
492,
5867,
63,
2991,
12,
4520,
1558,
12,
4520,
2959,
421,
199,
533,
6924,
547,
8,
13760,
304,
986,
199,
533,
7242,
547,
8,
13760,
304,
986,
199,
199,
318,
1104,
63,
2991,
8,
1745,
12,
2644,
304,
272,
408,
774,
12,
3775,
314,
2644,
402,
658,
1745,
64,
4450,
658,
2991,
2313,
339,
1803,
339,
520,
403,
26,
221,
340,
658,
2991,
64,
503,
658,
1745,
14,
2991,
64,
787,
440,
282,
1686,
2644,
288,
1423,
334,
69,
14,
71,
14,
1124,
403,
16580,
503,
658,
1745,
14,
2991,
365,
4124,
14,
272,
520,
549,
26,
221,
340,
314,
2644,
1423,
32253,
370,
314,
2011,
574,
465,
658,
2991,
3559,
272,
520,
797,
26,
340,
314,
14134,
14460,
14,
272,
408,
272,
862,
26,
267,
372,
6010,
14,
3892,
8,
1745,
14,
2991,
9,
508,
6010,
14,
3892,
8,
2991,
9,
272,
871,
334,
32060,
12,
4281,
12,
3146,
304,
267,
372,
488,
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,
620,
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,
620,
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,
297,
283,
10378,
13,
17,
418,
355,
340,
5867,
63,
2991,
26,
490,
14134,
14,
3176,
8,
17,
12,
5867,
63,
2991,
9,
267,
367,
12011,
315,
14134,
26,
288,
862,
26,
355,
11203,
275,
620,
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,
2258,
7224,
556,
297,
4074,
288,
871,
334,
7087,
547,
12,
19021,
9,
465,
2329,
26,
355,
1125,
275,
2329,
327,
315,
2018,
650,
12,
314,
665,
1971,
1256,
30,
365,
1169,
327,
2257,
370,
314,
871,
8502,
267,
746,
20872,
8,
288,
283,
6005,
370,
4849,
1324,
666,
14,
221,
12480,
379,
314,
2569,
14134,
26,
283,
288,
1543,
83,
3134,
78,
4042,
83,
3171,
450,
334,
297,
1987,
904,
779,
2722,
8,
10945,
9,
367,
12011,
315,
14134,
2522,
586,
4520,
1558,
8,
705,
1724,
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,
283,
1624,
13,
24,
13,
4093,
7,
892,
315,
373,
18,
14,
21,
717,
334,
8933,
14,
19550,
63,
6610,
975,
63,
6773,
12,
283,
1624,
13,
975,
13,
1235,
659,
717,
334,
8933,
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,
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
] |
mikewiebe-ansible/ansible
|
lib/ansible/modules/network/nxos/nxos_feature.py
|
94
|
8046
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
DOCUMENTATION = '''
---
module: nxos_feature
extends_documentation_fragment: nxos
version_added: "2.1"
short_description: Manage features in NX-OS switches.
description:
- Offers ability to enable and disable features in NX-OS.
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
options:
feature:
description:
- Name of feature.
required: true
state:
description:
- Desired state of the feature.
required: false
default: 'enabled'
choices: ['enabled','disabled']
'''
EXAMPLES = '''
- name: Ensure lacp is enabled
nxos_feature:
feature: lacp
state: enabled
- name: Ensure ospf is disabled
nxos_feature:
feature: ospf
state: disabled
- name: Ensure vpc is enabled
nxos_feature:
feature: vpc
state: enabled
'''
RETURN = '''
commands:
description: The set of commands to be sent to the remote device
returned: always
type: list
sample: ['nv overlay evpn']
'''
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
def get_available_features(feature, module):
available_features = {}
feature_regex = r'(?P<feature>\S+)\s+\d+\s+(?P<state>.*)'
command = {'command': 'show feature', 'output': 'text'}
try:
body = run_commands(module, [command])[0]
split_body = body.splitlines()
except (KeyError, IndexError):
return {}
for line in split_body:
try:
match_feature = re.match(feature_regex, line, re.DOTALL)
feature_group = match_feature.groupdict()
feature = feature_group['feature']
state = feature_group['state']
except AttributeError:
feature = ''
state = ''
if feature and state:
if 'enabled' in state:
state = 'enabled'
if feature not in available_features:
available_features[feature] = state
else:
if available_features[feature] == 'disabled' and state == 'enabled':
available_features[feature] = state
return available_features
def get_commands(proposed, existing, state, module):
feature = validate_feature(module, mode='config')
commands = []
feature_check = proposed == existing
if not feature_check:
if state == 'enabled':
command = 'feature {0}'.format(feature)
commands.append(command)
elif state == 'disabled':
command = "no feature {0}".format(feature)
commands.append(command)
return commands
def validate_feature(module, mode='show'):
'''Some features may need to be mapped due to inconsistency
between how they appear from "show feature" output and
how they are configured'''
feature = module.params['feature']
try:
info = get_capabilities(module)
device_info = info.get('device_info', {})
os_version = device_info.get('network_os_version', '')
except ConnectionError:
os_version = ''
if '8.1' in os_version:
feature_to_be_mapped = {
'show': {
'nv overlay': 'nve',
'vn-segment-vlan-based': 'vnseg_vlan',
'hsrp': 'hsrp_engine',
'fabric multicast': 'fabric_mcast',
'scp-server': 'scpServer',
'sftp-server': 'sftpServer',
'sla responder': 'sla_responder',
'sla sender': 'sla_sender',
'ssh': 'sshServer',
'tacacs+': 'tacacs',
'telnet': 'telnetServer',
'ethernet-link-oam': 'elo'
},
'config': {
'nve': 'nv overlay',
'vnseg_vlan': 'vn-segment-vlan-based',
'hsrp_engine': 'hsrp',
'fabric_mcast': 'fabric multicast',
'scpServer': 'scp-server',
'sftpServer': 'sftp-server',
'sla_sender': 'sla sender',
'sla_responder': 'sla responder',
'sshServer': 'ssh',
'tacacs': 'tacacs+',
'telnetServer': 'telnet',
'elo': 'ethernet-link-oam'
}
}
else:
feature_to_be_mapped = {
'show': {
'nv overlay': 'nve',
'vn-segment-vlan-based': 'vnseg_vlan',
'hsrp': 'hsrp_engine',
'fabric multicast': 'fabric_mcast',
'scp-server': 'scpServer',
'sftp-server': 'sftpServer',
'sla responder': 'sla_responder',
'sla sender': 'sla_sender',
'ssh': 'sshServer',
'tacacs+': 'tacacs',
'telnet': 'telnetServer',
'ethernet-link-oam': 'elo',
'port-security': 'eth_port_sec'
},
'config': {
'nve': 'nv overlay',
'vnseg_vlan': 'vn-segment-vlan-based',
'hsrp_engine': 'hsrp',
'fabric_mcast': 'fabric multicast',
'scpServer': 'scp-server',
'sftpServer': 'sftp-server',
'sla_sender': 'sla sender',
'sla_responder': 'sla responder',
'sshServer': 'ssh',
'tacacs': 'tacacs+',
'telnetServer': 'telnet',
'elo': 'ethernet-link-oam',
'eth_port_sec': 'port-security'
}
}
if feature in feature_to_be_mapped[mode]:
feature = feature_to_be_mapped[mode][feature]
return feature
def main():
argument_spec = dict(
feature=dict(type='str', required=True),
state=dict(choices=['enabled', 'disabled'], default='enabled')
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
warnings = list()
results = dict(changed=False, warnings=warnings)
feature = validate_feature(module)
state = module.params['state'].lower()
available_features = get_available_features(feature, module)
if feature not in available_features:
module.fail_json(
msg='Invalid feature name.',
features_currently_supported=available_features,
invalid_feature=feature)
else:
existstate = available_features[feature]
existing = dict(state=existstate)
proposed = dict(state=state)
results['changed'] = False
cmds = get_commands(proposed, existing, state, module)
if cmds:
# On N35 A8 images, some features return a yes/no prompt
# on enablement or disablement. Bypass using terminal dont-ask
cmds.insert(0, 'terminal dont-ask')
if not module.check_mode:
load_config(module, cmds)
results['changed'] = True
results['commands'] = cmds
module.exit_json(**results)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
1200,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
4445,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
14944,
4534,
315,
653,
56,
13,
3100,
24563,
14,
199,
1802,
26,
523,
446,
593,
10776,
21255,
370,
4756,
436,
3507,
4534,
315,
653,
56,
13,
3100,
14,
199,
2502,
26,
523,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
523,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
1419,
26,
523,
3878,
26,
272,
1369,
26,
489,
446,
2812,
402,
3878,
14,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
1174,
402,
314,
3878,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
3827,
7,
272,
3415,
26,
788,
3827,
1673,
7011,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
7523,
1127,
1850,
365,
5223,
523,
22072,
63,
4445,
26,
272,
3878,
26,
1127,
1850,
272,
1174,
26,
5223,
199,
199,
13,
536,
26,
7523,
26494,
365,
6980,
523,
22072,
63,
4445,
26,
272,
3878,
26,
26494,
272,
1174,
26,
6980,
199,
199,
13,
536,
26,
7523,
12830,
365,
5223,
523,
22072,
63,
4445,
26,
272,
3878,
26,
12830,
272,
1174,
26,
5223,
199,
2344,
199,
199,
9677,
275,
1449,
199,
4405,
26,
272,
1369,
26,
710,
663,
402,
3718,
370,
506,
4847,
370,
314,
3982,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
788,
15969,
24393,
8145,
4812,
418,
199,
2344,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
25417,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
17982,
14,
17982,
492,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
17982,
14,
17982,
492,
664,
63,
10732,
12,
22072,
63,
2094,
63,
1650,
421,
199,
318,
664,
63,
4561,
63,
3179,
8,
4445,
12,
859,
304,
272,
2808,
63,
3179,
275,
1052,
272,
3878,
63,
3821,
275,
519,
10120,
48,
28,
4445,
3072,
51,
13439,
83,
7896,
68,
7896,
83,
11,
2229,
48,
28,
929,
23742,
3171,
272,
1414,
275,
791,
1531,
356,
283,
2384,
3878,
297,
283,
1199,
356,
283,
505,
936,
339,
862,
26,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
359,
1531,
11057,
16,
61,
267,
3715,
63,
2030,
275,
2396,
14,
7644,
342,
272,
871,
334,
10230,
12,
7888,
304,
267,
372,
1052,
339,
367,
1004,
315,
3715,
63,
2030,
26,
267,
862,
26,
288,
1336,
63,
4445,
275,
295,
14,
1431,
8,
4445,
63,
3821,
12,
1004,
12,
295,
14,
16504,
9,
288,
3878,
63,
923,
275,
1336,
63,
4445,
14,
20567,
342,
288,
3878,
275,
3878,
63,
923,
459,
4445,
418,
288,
1174,
275,
3878,
63,
923,
459,
929,
418,
267,
871,
4281,
26,
288,
3878,
275,
2125,
288,
1174,
275,
2125,
398,
340,
3878,
436,
1174,
26,
288,
340,
283,
3827,
7,
315,
1174,
26,
355,
1174,
275,
283,
3827,
7,
953,
340,
3878,
440,
315,
2808,
63,
3179,
26,
355,
2808,
63,
3179,
59,
4445,
61,
275,
1174,
288,
587,
26,
355,
340,
2808,
63,
3179,
59,
4445,
61,
508,
283,
7011,
7,
436,
1174,
508,
283,
3827,
356,
490,
2808,
63,
3179,
59,
4445,
61,
275,
1174,
339,
372,
2808,
63,
3179,
421,
199,
318,
664,
63,
4405,
8,
15676,
12,
3411,
12,
1174,
12,
859,
304,
272,
3878,
275,
4107,
63,
4445,
8,
578,
12,
818,
534,
888,
358,
272,
3718,
275,
942,
272,
3878,
63,
1074,
275,
14075,
508,
3411,
272,
340,
440,
3878,
63,
1074,
26,
267,
340,
1174,
508,
283,
3827,
356,
288,
1414,
275,
283,
4445,
469,
16,
5285,
908,
8,
4445,
9,
288,
3718,
14,
740,
8,
1531,
9,
267,
916,
1174,
508,
283,
7011,
356,
288,
1414,
275,
298,
889,
3878,
469,
16,
5469,
908,
8,
4445,
9,
288,
3718,
14,
740,
8,
1531,
9,
272,
372,
3718,
421,
199,
318,
4107,
63,
4445,
8,
578,
12,
818,
534,
2384,
735,
272,
1449,
7700,
4534,
1443,
1929,
370,
506,
9994,
7037,
370,
315,
20249,
272,
3382,
4212,
2985,
7468,
687,
298,
2384,
3878,
2,
1072,
436,
272,
4212,
2985,
787,
7526,
2344,
339,
3878,
275,
859,
14,
1162,
459,
4445,
418,
339,
862,
26,
267,
2256,
275,
664,
63,
10732,
8,
578,
9,
267,
2243,
63,
815,
275,
2256,
14,
362,
360,
1782,
63,
815,
297,
5009,
267,
747,
63,
1023,
275,
2243,
63,
815,
14,
362,
360,
1200,
63,
736,
63,
1023,
297,
4074,
272,
871,
25417,
26,
267,
747,
63,
1023,
275,
2125,
339,
340,
283,
24,
14,
17,
7,
315,
747,
63,
1023,
26,
267,
3878,
63,
475,
63,
1235,
63,
11663,
275,
469,
288,
283,
2384,
356,
469,
355,
283,
15969,
24393,
356,
283,
78,
432,
297,
355,
283,
6002,
13,
9255
] |
[
2647,
15,
1393,
15,
1548,
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,
1200,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
4445,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
14944,
4534,
315,
653,
56,
13,
3100,
24563,
14,
199,
1802,
26,
523,
446,
593,
10776,
21255,
370,
4756,
436,
3507,
4534,
315,
653,
56,
13,
3100,
14,
199,
2502,
26,
523,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
523,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
1419,
26,
523,
3878,
26,
272,
1369,
26,
489,
446,
2812,
402,
3878,
14,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
1174,
402,
314,
3878,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
3827,
7,
272,
3415,
26,
788,
3827,
1673,
7011,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
7523,
1127,
1850,
365,
5223,
523,
22072,
63,
4445,
26,
272,
3878,
26,
1127,
1850,
272,
1174,
26,
5223,
199,
199,
13,
536,
26,
7523,
26494,
365,
6980,
523,
22072,
63,
4445,
26,
272,
3878,
26,
26494,
272,
1174,
26,
6980,
199,
199,
13,
536,
26,
7523,
12830,
365,
5223,
523,
22072,
63,
4445,
26,
272,
3878,
26,
12830,
272,
1174,
26,
5223,
199,
2344,
199,
199,
9677,
275,
1449,
199,
4405,
26,
272,
1369,
26,
710,
663,
402,
3718,
370,
506,
4847,
370,
314,
3982,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
788,
15969,
24393,
8145,
4812,
418,
199,
2344,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
25417,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
17982,
14,
17982,
492,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
17982,
14,
17982,
492,
664,
63,
10732,
12,
22072,
63,
2094,
63,
1650,
421,
199,
318,
664,
63,
4561,
63,
3179,
8,
4445,
12,
859,
304,
272,
2808,
63,
3179,
275,
1052,
272,
3878,
63,
3821,
275,
519,
10120,
48,
28,
4445,
3072,
51,
13439,
83,
7896,
68,
7896,
83,
11,
2229,
48,
28,
929,
23742,
3171,
272,
1414,
275,
791,
1531,
356,
283,
2384,
3878,
297,
283,
1199,
356,
283,
505,
936,
339,
862,
26,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
359,
1531,
11057,
16,
61,
267,
3715,
63,
2030,
275,
2396,
14,
7644,
342,
272,
871,
334,
10230,
12,
7888,
304,
267,
372,
1052,
339,
367,
1004,
315,
3715,
63,
2030,
26,
267,
862,
26,
288,
1336,
63,
4445,
275,
295,
14,
1431,
8,
4445,
63,
3821,
12,
1004,
12,
295,
14,
16504,
9,
288,
3878,
63,
923,
275,
1336,
63,
4445,
14,
20567,
342,
288,
3878,
275,
3878,
63,
923,
459,
4445,
418,
288,
1174,
275,
3878,
63,
923,
459,
929,
418,
267,
871,
4281,
26,
288,
3878,
275,
2125,
288,
1174,
275,
2125,
398,
340,
3878,
436,
1174,
26,
288,
340,
283,
3827,
7,
315,
1174,
26,
355,
1174,
275,
283,
3827,
7,
953,
340,
3878,
440,
315,
2808,
63,
3179,
26,
355,
2808,
63,
3179,
59,
4445,
61,
275,
1174,
288,
587,
26,
355,
340,
2808,
63,
3179,
59,
4445,
61,
508,
283,
7011,
7,
436,
1174,
508,
283,
3827,
356,
490,
2808,
63,
3179,
59,
4445,
61,
275,
1174,
339,
372,
2808,
63,
3179,
421,
199,
318,
664,
63,
4405,
8,
15676,
12,
3411,
12,
1174,
12,
859,
304,
272,
3878,
275,
4107,
63,
4445,
8,
578,
12,
818,
534,
888,
358,
272,
3718,
275,
942,
272,
3878,
63,
1074,
275,
14075,
508,
3411,
272,
340,
440,
3878,
63,
1074,
26,
267,
340,
1174,
508,
283,
3827,
356,
288,
1414,
275,
283,
4445,
469,
16,
5285,
908,
8,
4445,
9,
288,
3718,
14,
740,
8,
1531,
9,
267,
916,
1174,
508,
283,
7011,
356,
288,
1414,
275,
298,
889,
3878,
469,
16,
5469,
908,
8,
4445,
9,
288,
3718,
14,
740,
8,
1531,
9,
272,
372,
3718,
421,
199,
318,
4107,
63,
4445,
8,
578,
12,
818,
534,
2384,
735,
272,
1449,
7700,
4534,
1443,
1929,
370,
506,
9994,
7037,
370,
315,
20249,
272,
3382,
4212,
2985,
7468,
687,
298,
2384,
3878,
2,
1072,
436,
272,
4212,
2985,
787,
7526,
2344,
339,
3878,
275,
859,
14,
1162,
459,
4445,
418,
339,
862,
26,
267,
2256,
275,
664,
63,
10732,
8,
578,
9,
267,
2243,
63,
815,
275,
2256,
14,
362,
360,
1782,
63,
815,
297,
5009,
267,
747,
63,
1023,
275,
2243,
63,
815,
14,
362,
360,
1200,
63,
736,
63,
1023,
297,
4074,
272,
871,
25417,
26,
267,
747,
63,
1023,
275,
2125,
339,
340,
283,
24,
14,
17,
7,
315,
747,
63,
1023,
26,
267,
3878,
63,
475,
63,
1235,
63,
11663,
275,
469,
288,
283,
2384,
356,
469,
355,
283,
15969,
24393,
356,
283,
78,
432,
297,
355,
283,
6002,
13,
9255,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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6798
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_config import cfg
from cinder import context
from cinder import exception
from cinder.tests.unit.targets import targets_fixture as tf
from cinder import utils
from cinder.volume import configuration as conf
from cinder.volume.targets import fake
from cinder.volume.targets import iscsi
class FakeIncompleteDriver(iscsi.ISCSITarget):
def null_method():
pass
class TestBaseISCSITargetDriver(tf.TargetDriverFixture):
def setUp(self):
super(TestBaseISCSITargetDriver, self).setUp()
self.target = fake.FakeTarget(root_helper=utils.get_root_helper(),
configuration=self.configuration)
def test_abc_methods_not_present_fails(self):
configuration = conf.Configuration(cfg.StrOpt('iscsi_target_prefix',
default='foo',
help='you wish'))
self.assertRaises(TypeError,
FakeIncompleteDriver,
configuration=configuration)
def test_get_iscsi_properties(self):
self.assertEqual(self.expected_iscsi_properties,
self.target._get_iscsi_properties(self.testvol))
def test_get_iscsi_properties_multiple_targets(self):
testvol = self.testvol.copy()
expected_iscsi_properties = self.expected_iscsi_properties.copy()
iqn = expected_iscsi_properties['target_iqn']
testvol.update(
{'provider_location': '10.10.7.1:3260;10.10.8.1:3260 '
'iqn.2010-10.org.openstack:'
'volume-%s 0' % self.fake_volume_id})
expected_iscsi_properties.update(
{'target_portals': ['10.10.7.1:3260', '10.10.8.1:3260'],
'target_iqns': [iqn, iqn],
'target_luns': [0, 0]})
self.assertEqual(expected_iscsi_properties,
self.target._get_iscsi_properties(testvol))
def test_build_iscsi_auth_string(self):
auth_string = 'chap chap-user chap-password'
self.assertEqual(auth_string,
self.target._iscsi_authentication('chap',
'chap-user',
'chap-password'))
def test_do_iscsi_discovery(self):
with mock.patch.object(self.configuration,
'safe_get', return_value='127.0.0.1'),\
mock.patch('cinder.utils.execute',
return_value=(self.target_string, '')):
self.assertEqual(self.target_string,
self.target._do_iscsi_discovery(self.testvol))
def test_remove_export(self):
with mock.patch.object(self.target, '_get_target_and_lun') as \
mock_get_target,\
mock.patch.object(self.target, 'show_target'),\
mock.patch.object(self.target, 'remove_iscsi_target') as \
mock_remove_target:
mock_get_target.return_value = (0, 1)
iscsi_target, lun = mock_get_target.return_value
ctxt = context.get_admin_context()
self.target.remove_export(ctxt, self.testvol)
mock_remove_target.assert_called_once_with(
iscsi_target,
lun,
'ed2c2222-5fc0-11e4-aa15-123b93f75cba',
'testvol')
def test_remove_export_notfound(self):
with mock.patch.object(self.target, '_get_target_and_lun') as \
mock_get_target,\
mock.patch.object(self.target, 'show_target'),\
mock.patch.object(self.target, 'remove_iscsi_target'):
mock_get_target.side_effect = exception.NotFound
ctxt = context.get_admin_context()
self.assertEqual(None, self.target.remove_export(ctxt,
self.testvol))
def test_remove_export_show_error(self):
with mock.patch.object(self.target, '_get_target_and_lun') as \
mock_get_target,\
mock.patch.object(self.target, 'show_target') as mshow,\
mock.patch.object(self.target, 'remove_iscsi_target'):
mock_get_target.return_value = (0, 1)
iscsi_target, lun = mock_get_target.return_value
mshow.side_effect = Exception
ctxt = context.get_admin_context()
self.assertEqual(None, self.target.remove_export(ctxt,
self.testvol))
def test_initialize_connection(self):
expected = {'driver_volume_type': 'iscsi',
'data': self.expected_iscsi_properties}
self.assertEqual(expected,
self.target.initialize_connection(self.testvol, {}))
def test_validate_connector(self):
bad_connector = {'no_initiator': 'nada'}
self.assertRaises(exception.InvalidConnectorException,
self.target.validate_connector,
bad_connector)
connector = {'initiator': 'fake_init'}
self.assertTrue(self.target.validate_connector,
connector)
def test_show_target_error(self):
self.assertRaises(exception.InvalidParameterValue,
self.target.show_target,
0, None)
with mock.patch.object(self.target, '_get_target') as mock_get_target:
mock_get_target.side_effect = exception.NotFound()
self.assertRaises(exception.NotFound,
self.target.show_target, 0,
self.expected_iscsi_properties['target_iqn'])
def test_iscsi_location(self):
location = self.target._iscsi_location('portal', 1, 'target', 2)
self.assertEqual('portal:3260,1 target 2', location)
location = self.target._iscsi_location('portal', 1, 'target', 2,
['portal2'])
self.assertEqual('portal:3260;portal2:3260,1 target 2', location)
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
1919,
199,
504,
13069,
14,
2219,
14,
3248,
14,
4684,
492,
4545,
63,
5997,
465,
2833,
199,
504,
13069,
492,
3778,
199,
504,
13069,
14,
2405,
492,
2897,
465,
3743,
199,
504,
13069,
14,
2405,
14,
4684,
492,
4026,
199,
504,
13069,
14,
2405,
14,
4684,
492,
22144,
421,
199,
533,
7777,
31962,
6158,
8,
17139,
14,
1311,
3298,
649,
839,
304,
272,
347,
2973,
63,
765,
837,
267,
986,
421,
199,
533,
1379,
1563,
1311,
3298,
649,
839,
6158,
8,
3249,
14,
4277,
6158,
12812,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14440,
1311,
3298,
649,
839,
6158,
12,
291,
680,
5996,
342,
267,
291,
14,
1375,
275,
4026,
14,
8249,
4277,
8,
1231,
63,
3676,
29,
1208,
14,
362,
63,
1231,
63,
3676,
1062,
4228,
2897,
29,
277,
14,
4758,
9,
339,
347,
511,
63,
3175,
63,
2474,
63,
1397,
63,
1881,
63,
15762,
8,
277,
304,
267,
2897,
275,
3743,
14,
5688,
8,
4128,
14,
19340,
360,
17139,
63,
1375,
63,
1861,
297,
10028,
849,
534,
1421,
297,
10028,
1720,
534,
13297,
13809,
1333,
267,
291,
14,
1855,
8,
4333,
12,
2079,
7777,
31962,
6158,
12,
2079,
2897,
29,
4758,
9,
339,
347,
511,
63,
362,
63,
17139,
63,
3282,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2062,
63,
17139,
63,
3282,
12,
586,
291,
14,
1375,
423,
362,
63,
17139,
63,
3282,
8,
277,
14,
396,
5650,
430,
339,
347,
511,
63,
362,
63,
17139,
63,
3282,
63,
6048,
63,
4684,
8,
277,
304,
267,
511,
5650,
275,
291,
14,
396,
5650,
14,
1574,
342,
267,
1420,
63,
17139,
63,
3282,
275,
291,
14,
2062,
63,
17139,
63,
3282,
14,
1574,
342,
267,
284,
15156,
275,
1420,
63,
17139,
63,
3282,
459,
1375,
63,
27071,
418,
267,
511,
5650,
14,
873,
8,
288,
791,
3780,
63,
1985,
356,
283,
709,
14,
709,
14,
23,
14,
17,
26,
708,
2259,
27,
709,
14,
709,
14,
24,
14,
17,
26,
708,
2259,
283,
3303,
283,
27071,
14,
6542,
13,
709,
14,
1308,
14,
8512,
4881,
3303,
283,
2405,
3295,
83,
378,
7,
450,
291,
14,
3183,
63,
2405,
63,
344,
1552,
267,
1420,
63,
17139,
63,
3282,
14,
873,
8,
288,
791,
1375,
63,
719,
2551,
356,
788,
709,
14,
709,
14,
23,
14,
17,
26,
708,
2259,
297,
283,
709,
14,
709,
14,
24,
14,
17,
26,
708,
2259,
995,
1467,
283,
1375,
63,
9962,
561,
356,
359,
27071,
12,
284,
15156,
467,
1467,
283,
1375,
63,
13542,
83,
356,
359,
16,
12,
378,
13412,
267,
291,
14,
629,
8,
2062,
63,
17139,
63,
3282,
12,
586,
291,
14,
1375,
423,
362,
63,
17139,
63,
3282,
8,
396,
5650,
430,
339,
347,
511,
63,
1506,
63,
17139,
63,
1178,
63,
875,
8,
277,
304,
267,
1790,
63,
875,
275,
283,
28765,
682,
439,
13,
751,
682,
439,
13,
2060,
7,
267,
291,
14,
629,
8,
1178,
63,
875,
12,
586,
291,
14,
1375,
423,
17139,
63,
11725,
360,
28765,
297,
15491,
283,
28765,
13,
751,
297,
15491,
283,
28765,
13,
2060,
1333,
339,
347,
511,
63,
1117,
63,
17139,
63,
14859,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
4758,
12,
3044,
283,
3489,
63,
362,
297,
372,
63,
585,
534,
4195,
14,
16,
14,
16,
14,
17,
659,
60,
355,
1683,
14,
2068,
360,
12372,
14,
1208,
14,
2526,
297,
2574,
372,
63,
585,
2687,
277,
14,
1375,
63,
875,
12,
4074,
304,
288,
291,
14,
629,
8,
277,
14,
1375,
63,
875,
12,
2490,
291,
14,
1375,
423,
1117,
63,
17139,
63,
14859,
8,
277,
14,
396,
5650,
430,
339,
347,
511,
63,
2168,
63,
3790,
8,
277,
304,
398,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
2513,
362,
63,
1375,
63,
460,
63,
13542,
358,
465,
971,
355,
1683,
63,
362,
63,
1375,
4202,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2384,
63,
1375,
659,
60,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2168,
63,
17139,
63,
1375,
358,
465,
971,
355,
1683,
63,
2168,
63,
1375,
26,
953,
1683,
63,
362,
63,
1375,
14,
1107,
63,
585,
275,
334,
16,
12,
413,
9,
288,
22144,
63,
1375,
12,
19465,
275,
1683,
63,
362,
63,
1375,
14,
1107,
63,
585,
288,
11216,
275,
1067,
14,
362,
63,
2113,
63,
1100,
342,
288,
291,
14,
1375,
14,
2168,
63,
3790,
8,
6725,
12,
291,
14,
396,
5650,
9,
288,
1683,
63,
2168,
63,
1375,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
22144,
63,
1375,
12,
355,
19465,
12,
355,
283,
379,
18,
67,
9993,
13,
21,
3003,
16,
13,
845,
69,
20,
13,
2158,
1046,
13,
4288,
66,
3129,
70,
2194,
28995,
297,
355,
283,
396,
5650,
358,
339,
347,
511,
63,
2168,
63,
3790,
63,
32353,
8,
277,
304,
398,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
2513,
362,
63,
1375,
63,
460,
63,
13542,
358,
465,
971,
355,
1683,
63,
362,
63,
1375,
4202,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2384,
63,
1375,
659,
60,
355,
1683,
14,
2068,
14,
785,
8
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
1919,
199,
504,
13069,
14,
2219,
14,
3248,
14,
4684,
492,
4545,
63,
5997,
465,
2833,
199,
504,
13069,
492,
3778,
199,
504,
13069,
14,
2405,
492,
2897,
465,
3743,
199,
504,
13069,
14,
2405,
14,
4684,
492,
4026,
199,
504,
13069,
14,
2405,
14,
4684,
492,
22144,
421,
199,
533,
7777,
31962,
6158,
8,
17139,
14,
1311,
3298,
649,
839,
304,
272,
347,
2973,
63,
765,
837,
267,
986,
421,
199,
533,
1379,
1563,
1311,
3298,
649,
839,
6158,
8,
3249,
14,
4277,
6158,
12812,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
14440,
1311,
3298,
649,
839,
6158,
12,
291,
680,
5996,
342,
267,
291,
14,
1375,
275,
4026,
14,
8249,
4277,
8,
1231,
63,
3676,
29,
1208,
14,
362,
63,
1231,
63,
3676,
1062,
4228,
2897,
29,
277,
14,
4758,
9,
339,
347,
511,
63,
3175,
63,
2474,
63,
1397,
63,
1881,
63,
15762,
8,
277,
304,
267,
2897,
275,
3743,
14,
5688,
8,
4128,
14,
19340,
360,
17139,
63,
1375,
63,
1861,
297,
10028,
849,
534,
1421,
297,
10028,
1720,
534,
13297,
13809,
1333,
267,
291,
14,
1855,
8,
4333,
12,
2079,
7777,
31962,
6158,
12,
2079,
2897,
29,
4758,
9,
339,
347,
511,
63,
362,
63,
17139,
63,
3282,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
2062,
63,
17139,
63,
3282,
12,
586,
291,
14,
1375,
423,
362,
63,
17139,
63,
3282,
8,
277,
14,
396,
5650,
430,
339,
347,
511,
63,
362,
63,
17139,
63,
3282,
63,
6048,
63,
4684,
8,
277,
304,
267,
511,
5650,
275,
291,
14,
396,
5650,
14,
1574,
342,
267,
1420,
63,
17139,
63,
3282,
275,
291,
14,
2062,
63,
17139,
63,
3282,
14,
1574,
342,
267,
284,
15156,
275,
1420,
63,
17139,
63,
3282,
459,
1375,
63,
27071,
418,
267,
511,
5650,
14,
873,
8,
288,
791,
3780,
63,
1985,
356,
283,
709,
14,
709,
14,
23,
14,
17,
26,
708,
2259,
27,
709,
14,
709,
14,
24,
14,
17,
26,
708,
2259,
283,
3303,
283,
27071,
14,
6542,
13,
709,
14,
1308,
14,
8512,
4881,
3303,
283,
2405,
3295,
83,
378,
7,
450,
291,
14,
3183,
63,
2405,
63,
344,
1552,
267,
1420,
63,
17139,
63,
3282,
14,
873,
8,
288,
791,
1375,
63,
719,
2551,
356,
788,
709,
14,
709,
14,
23,
14,
17,
26,
708,
2259,
297,
283,
709,
14,
709,
14,
24,
14,
17,
26,
708,
2259,
995,
1467,
283,
1375,
63,
9962,
561,
356,
359,
27071,
12,
284,
15156,
467,
1467,
283,
1375,
63,
13542,
83,
356,
359,
16,
12,
378,
13412,
267,
291,
14,
629,
8,
2062,
63,
17139,
63,
3282,
12,
586,
291,
14,
1375,
423,
362,
63,
17139,
63,
3282,
8,
396,
5650,
430,
339,
347,
511,
63,
1506,
63,
17139,
63,
1178,
63,
875,
8,
277,
304,
267,
1790,
63,
875,
275,
283,
28765,
682,
439,
13,
751,
682,
439,
13,
2060,
7,
267,
291,
14,
629,
8,
1178,
63,
875,
12,
586,
291,
14,
1375,
423,
17139,
63,
11725,
360,
28765,
297,
15491,
283,
28765,
13,
751,
297,
15491,
283,
28765,
13,
2060,
1333,
339,
347,
511,
63,
1117,
63,
17139,
63,
14859,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
4758,
12,
3044,
283,
3489,
63,
362,
297,
372,
63,
585,
534,
4195,
14,
16,
14,
16,
14,
17,
659,
60,
355,
1683,
14,
2068,
360,
12372,
14,
1208,
14,
2526,
297,
2574,
372,
63,
585,
2687,
277,
14,
1375,
63,
875,
12,
4074,
304,
288,
291,
14,
629,
8,
277,
14,
1375,
63,
875,
12,
2490,
291,
14,
1375,
423,
1117,
63,
17139,
63,
14859,
8,
277,
14,
396,
5650,
430,
339,
347,
511,
63,
2168,
63,
3790,
8,
277,
304,
398,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
2513,
362,
63,
1375,
63,
460,
63,
13542,
358,
465,
971,
355,
1683,
63,
362,
63,
1375,
4202,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2384,
63,
1375,
659,
60,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2168,
63,
17139,
63,
1375,
358,
465,
971,
355,
1683,
63,
2168,
63,
1375,
26,
953,
1683,
63,
362,
63,
1375,
14,
1107,
63,
585,
275,
334,
16,
12,
413,
9,
288,
22144,
63,
1375,
12,
19465,
275,
1683,
63,
362,
63,
1375,
14,
1107,
63,
585,
288,
11216,
275,
1067,
14,
362,
63,
2113,
63,
1100,
342,
288,
291,
14,
1375,
14,
2168,
63,
3790,
8,
6725,
12,
291,
14,
396,
5650,
9,
288,
1683,
63,
2168,
63,
1375,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
22144,
63,
1375,
12,
355,
19465,
12,
355,
283,
379,
18,
67,
9993,
13,
21,
3003,
16,
13,
845,
69,
20,
13,
2158,
1046,
13,
4288,
66,
3129,
70,
2194,
28995,
297,
355,
283,
396,
5650,
358,
339,
347,
511,
63,
2168,
63,
3790,
63,
32353,
8,
277,
304,
398,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
2513,
362,
63,
1375,
63,
460,
63,
13542,
358,
465,
971,
355,
1683,
63,
362,
63,
1375,
4202,
355,
1683,
14,
2068,
14,
785,
8,
277,
14,
1375,
12,
283,
2384,
63,
1375,
659,
60,
355,
1683,
14,
2068,
14,
785,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
slaveofcode/rajaongkir
|
rajaongkir/api.py
|
1
|
6138
|
from __future__ import unicode_literals
import requests
import json
from json.encoder import JSONEncoder
JNE = 'jne'
POS = 'pos'
TIKI = 'tiki'
ALL_COURIER = 'all'
class ApiRequest(object):
"""Basic Api request with using requests library
"""
json_encoder_class = JSONEncoder
def __init__(self, endpoint):
self.endpoint = endpoint
def get(self, headers=None, url_parameters={}):
return requests.get(
self.endpoint,
params=url_parameters,
headers=headers
)
def post(self, headers=None, url_parameters={}, payload={}):
return requests.post(
self.endpoint,
data=json.dumps(payload, cls=self.json_encoder_class),
params=url_parameters,
headers=headers
)
def put(self, headers=None, url_parameters={}, payload={}):
return requests.put(
self.endpoint,
data=json.dumps(payload, cls=self.json_encoder_class),
params=url_parameters,
headers=headers
)
def delete(self, headers=None, url_parameters={}):
return requests.delete(
self.endpoint,
params=url_parameters,
headers=headers
)
def options(self, headers=None, url_parameters={}):
return requests.options(
self.endpoint,
params=url_parameters,
headers=headers
)
class ApiErrorException(Exception):
pass
class RajaOngkirApi(object):
key_list = 'rajaongkir'
endpoint = 'http://api.rajaongkir.com/starter/'
def __init__(self, api_key):
self.api_key = api_key
@classmethod
def __grab(cls, json_results):
return json_results.get(cls.key_list)
@staticmethod
def __status(response_json):
"""Checking the status of response api
:param response_json:
:return:
"""
if not response_json:
raise ApiErrorException('Response Api is None, cannot fetch the status of api')
status = response_json.get('status')
assert status is not None, \
'Response Status is not Available'
assert status.get('code') == requests.codes.ok, \
'Response status not clear, should be any error occurred: {}'.format(status.get('description'))
def __get(self, service_endpoint, params=None):
"""Separate GET request into individual method,
because it's will be used multiple times, short-code=better
:param service_endpoint: `str` specific api endpoint
:param params: `dict` url parameter to include
:return: `dict` results of returned api
"""
req_params = {
'headers': {
'Accept': 'application/json',
'key': self.api_key
}
}
if params is not None:
req_params['url_parameters'] = params
api = ApiRequest(endpoint=service_endpoint)
response = api.get(**req_params)
return self.__grab(response.json()) if response.status_code == requests.codes.ok else None
@staticmethod
def __parse(response_json):
"""Get the actual result of json response
:param response_json:
:return:
"""
return response_json.get('results') if response_json is not None else None
def provinces(self):
"""Get list of all provinces
:return:
"""
provinces = self.__get('{}province'.format(self.endpoint))
self.__status(provinces)
return self.__parse(provinces)
def province_by_id(self, province_id):
"""Get specific province by id
:param province_id:
:return:
"""
province = self.__get('{}province'.format(self.endpoint), params={'id': province_id})
self.__status(province)
return self.__parse(province)
def cities(self):
"""Get list of all cities
:return:
"""
cities = self.__get('{}city'.format(self.endpoint))
self.__status(cities)
return self.__parse(cities)
def city_by_id(self, city_id):
"""Get specific city by id
:param city_id:
:return:
"""
city = self.__get('{}city'.format(self.endpoint), params={'id': city_id})
self.__status(city)
return self.__parse(city)
def cities_by_province(self, province_id):
"""Get specific city by province id
:param province_id:
:return:
"""
city = self.__get('{}city'.format(self.endpoint), params={'province': province_id})
self.__status(city)
return self.__parse(city)
def city_by_province_and_city(self, province_id, city_id):
"""Get specific city by province and city id
:param province_id: int
:param city_id: int
:return:
"""
city = self.__get('{}city'.format(self.endpoint), params={'id': city_id, 'province': province_id})
self.__status(city)
return self.__parse(city)
def cost_between_city(self, source, destination, weight_in_grams=0, courier=ALL_COURIER):
"""Get cost result
:param source: `int` city id of source place
:param destination: `int` city id of destination
:param weight_in_grams: `int` weight in grams
:param courier: `str` the courier type
:return:
"""
post_data = {
u"origin": source,
u"destination": destination,
u"weight": int(weight_in_grams),
u"courier": courier
}
api = ApiRequest(endpoint='{}cost'.format(self.endpoint))
response = api.post(
headers={
'key': self.api_key,
'Accept': 'application/json',
'Content-Type': 'application/json',
'charset': 'utf8'
},
payload=post_data
)
costs = self.__grab(response.json()) if response.status_code == requests.codes.ok else None
self.__status(costs)
return self.__parse(costs)
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
4145,
199,
646,
2022,
199,
504,
2022,
14,
9347,
492,
4840,
6679,
199,
199,
42,
6388,
275,
283,
74,
685,
7,
199,
9263,
275,
283,
1712,
7,
199,
13247,
16944,
275,
283,
280,
8810,
7,
199,
1761,
63,
1439,
7639,
540,
275,
283,
452,
7,
421,
199,
533,
13986,
2017,
8,
785,
304,
272,
408,
6845,
13986,
1056,
543,
1808,
4145,
3555,
339,
408,
272,
2022,
63,
9347,
63,
533,
275,
4840,
6679,
339,
347,
636,
826,
721,
277,
12,
6037,
304,
267,
291,
14,
6520,
275,
6037,
339,
347,
664,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
362,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
2963,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
10324,
4886,
16420,
267,
372,
4145,
14,
1932,
8,
288,
291,
14,
6520,
12,
288,
666,
29,
1001,
14,
4180,
8,
4749,
12,
843,
29,
277,
14,
1001,
63,
9347,
63,
533,
395,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
5324,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
10324,
4886,
16420,
267,
372,
4145,
14,
524,
8,
288,
291,
14,
6520,
12,
288,
666,
29,
1001,
14,
4180,
8,
4749,
12,
843,
29,
277,
14,
1001,
63,
9347,
63,
533,
395,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
3145,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
1807,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
1511,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
1419,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
421,
199,
533,
13986,
547,
1726,
8,
1726,
304,
272,
986,
421,
199,
533,
3898,
3387,
47,
2753,
75,
723,
7394,
8,
785,
304,
339,
790,
63,
513,
275,
283,
345,
3387,
951,
75,
723,
7,
272,
6037,
275,
283,
1014,
921,
1246,
14,
345,
3387,
951,
75,
723,
14,
957,
15,
7848,
351,
4805,
339,
347,
636,
826,
721,
277,
12,
2986,
63,
498,
304,
267,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
339,
768,
3744,
272,
347,
636,
22090,
8,
1886,
12,
2022,
63,
2604,
304,
267,
372,
2022,
63,
2604,
14,
362,
8,
1886,
14,
498,
63,
513,
9,
339,
768,
4639,
272,
347,
636,
1205,
8,
1310,
63,
1001,
304,
267,
408,
14740,
314,
2004,
402,
1177,
2986,
398,
520,
635,
1177,
63,
1001,
26,
267,
520,
1107,
26,
267,
408,
398,
340,
440,
1177,
63,
1001,
26,
288,
746,
13986,
547,
1726,
360,
2364,
13986,
365,
488,
12,
3913,
5267,
314,
2004,
402,
2986,
358,
398,
2004,
275,
1177,
63,
1001,
14,
362,
360,
1205,
358,
398,
702,
2004,
365,
440,
488,
12,
971,
288,
283,
2364,
9795,
365,
440,
23840,
7,
398,
702,
2004,
14,
362,
360,
600,
358,
508,
4145,
14,
6021,
14,
745,
12,
971,
288,
283,
2364,
2004,
440,
5436,
12,
1077,
506,
1263,
1125,
8920,
26,
9499,
908,
8,
1205,
14,
362,
360,
1802,
1333,
339,
347,
636,
362,
8,
277,
12,
2435,
63,
6520,
12,
1862,
29,
403,
304,
267,
408,
12653,
323,
9576,
1056,
1901,
8212,
1083,
12,
267,
2952,
652,
1159,
911,
506,
1202,
3663,
5431,
12,
3974,
13,
600,
29,
9549,
351,
398,
520,
635,
2435,
63,
6520,
26,
658,
495,
64,
2488,
2986,
6037,
267,
520,
635,
1862,
26,
658,
807,
64,
1166,
2725,
370,
2387,
267,
520,
1107,
26,
658,
807,
64,
2058,
402,
2138,
2986,
267,
408,
267,
2648,
63,
1162,
275,
469,
288,
283,
2139,
356,
469,
355,
283,
8422,
356,
283,
3578,
15,
1001,
297,
355,
283,
498,
356,
291,
14,
1246,
63,
498,
288,
789,
267,
789,
398,
340,
1862,
365,
440,
488,
26,
288,
2648,
63,
1162,
459,
633,
63,
3214,
418,
275,
1862,
398,
2986,
275,
13986,
2017,
8,
6520,
29,
1364,
63,
6520,
9,
267,
1177,
275,
2986,
14,
362,
3682,
2103,
63,
1162,
9,
398,
372,
291,
855,
22090,
8,
1310,
14,
1001,
1012,
340,
1177,
14,
1205,
63,
600,
508,
4145,
14,
6021,
14,
745,
587,
488,
339,
768,
4639,
272,
347,
636,
1122,
8,
1310,
63,
1001,
304,
267,
408,
1002,
314,
3503,
754,
402,
2022,
1177,
398,
520,
635,
1177,
63,
1001,
26,
267,
520,
1107,
26,
267,
408,
267,
372,
1177,
63,
1001,
14,
362,
360,
2604,
358,
340,
1177,
63,
1001,
365,
440,
488,
587,
488,
339,
347,
557,
11908,
823,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
557,
11908,
823,
398,
520,
1107,
26,
267,
408,
267,
557,
11908,
823,
275,
291,
855,
362,
17519,
20397,
2855,
1370,
908,
8,
277,
14,
6520,
430,
398,
291,
855,
1205,
8,
496,
11908,
823,
9,
398,
372,
291,
855,
1122,
8,
496,
11908,
823,
9,
339,
347,
24074,
2855,
63,
991,
63,
344,
8,
277,
12,
24074,
2855,
63,
344,
304,
267,
408,
1002,
2488,
24074,
2855,
701,
1305,
398,
520,
635,
24074,
2855,
63,
344,
26,
267,
520,
1107,
26,
267,
408,
267,
24074,
2855,
275,
291,
855,
362,
17519,
20397,
2855,
1370,
908,
8,
277,
14,
6520,
395,
1862,
3713,
344,
356,
24074,
2855,
63,
344,
1552,
398,
291,
855,
1205,
8,
20397,
2855,
9,
398,
372,
291,
855,
1122,
8,
20397,
2855,
9,
339,
347,
286,
12107,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
286,
12107,
398,
520,
1107,
26,
267,
408,
267,
286,
12107,
275,
291,
855,
362,
17519,
3690,
1370,
908,
8,
277,
14,
6520,
430,
398,
291,
855,
1205,
8,
18207,
9,
398,
372,
291,
855,
1122,
8,
18207,
9,
339,
347,
14492,
63,
991,
63,
344,
8,
277,
12,
14492,
63,
344,
304,
267,
408,
1002,
2488,
14492,
701,
1305,
398,
520,
635,
14492,
63,
344,
26,
267,
520,
1107,
26,
267,
408,
267,
14492,
275,
291,
855,
362,
17519,
3690,
1370,
908
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
4145,
199,
646,
2022,
199,
504,
2022,
14,
9347,
492,
4840,
6679,
199,
199,
42,
6388,
275,
283,
74,
685,
7,
199,
9263,
275,
283,
1712,
7,
199,
13247,
16944,
275,
283,
280,
8810,
7,
199,
1761,
63,
1439,
7639,
540,
275,
283,
452,
7,
421,
199,
533,
13986,
2017,
8,
785,
304,
272,
408,
6845,
13986,
1056,
543,
1808,
4145,
3555,
339,
408,
272,
2022,
63,
9347,
63,
533,
275,
4840,
6679,
339,
347,
636,
826,
721,
277,
12,
6037,
304,
267,
291,
14,
6520,
275,
6037,
339,
347,
664,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
362,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
2963,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
10324,
4886,
16420,
267,
372,
4145,
14,
1932,
8,
288,
291,
14,
6520,
12,
288,
666,
29,
1001,
14,
4180,
8,
4749,
12,
843,
29,
277,
14,
1001,
63,
9347,
63,
533,
395,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
5324,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
10324,
4886,
16420,
267,
372,
4145,
14,
524,
8,
288,
291,
14,
6520,
12,
288,
666,
29,
1001,
14,
4180,
8,
4749,
12,
843,
29,
277,
14,
1001,
63,
9347,
63,
533,
395,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
3145,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
1807,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
339,
347,
1511,
8,
277,
12,
2323,
29,
403,
12,
1166,
63,
3214,
16420,
267,
372,
4145,
14,
1419,
8,
288,
291,
14,
6520,
12,
288,
1862,
29,
633,
63,
3214,
12,
288,
2323,
29,
2139,
267,
776,
421,
199,
533,
13986,
547,
1726,
8,
1726,
304,
272,
986,
421,
199,
533,
3898,
3387,
47,
2753,
75,
723,
7394,
8,
785,
304,
339,
790,
63,
513,
275,
283,
345,
3387,
951,
75,
723,
7,
272,
6037,
275,
283,
1014,
921,
1246,
14,
345,
3387,
951,
75,
723,
14,
957,
15,
7848,
351,
4805,
339,
347,
636,
826,
721,
277,
12,
2986,
63,
498,
304,
267,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
339,
768,
3744,
272,
347,
636,
22090,
8,
1886,
12,
2022,
63,
2604,
304,
267,
372,
2022,
63,
2604,
14,
362,
8,
1886,
14,
498,
63,
513,
9,
339,
768,
4639,
272,
347,
636,
1205,
8,
1310,
63,
1001,
304,
267,
408,
14740,
314,
2004,
402,
1177,
2986,
398,
520,
635,
1177,
63,
1001,
26,
267,
520,
1107,
26,
267,
408,
398,
340,
440,
1177,
63,
1001,
26,
288,
746,
13986,
547,
1726,
360,
2364,
13986,
365,
488,
12,
3913,
5267,
314,
2004,
402,
2986,
358,
398,
2004,
275,
1177,
63,
1001,
14,
362,
360,
1205,
358,
398,
702,
2004,
365,
440,
488,
12,
971,
288,
283,
2364,
9795,
365,
440,
23840,
7,
398,
702,
2004,
14,
362,
360,
600,
358,
508,
4145,
14,
6021,
14,
745,
12,
971,
288,
283,
2364,
2004,
440,
5436,
12,
1077,
506,
1263,
1125,
8920,
26,
9499,
908,
8,
1205,
14,
362,
360,
1802,
1333,
339,
347,
636,
362,
8,
277,
12,
2435,
63,
6520,
12,
1862,
29,
403,
304,
267,
408,
12653,
323,
9576,
1056,
1901,
8212,
1083,
12,
267,
2952,
652,
1159,
911,
506,
1202,
3663,
5431,
12,
3974,
13,
600,
29,
9549,
351,
398,
520,
635,
2435,
63,
6520,
26,
658,
495,
64,
2488,
2986,
6037,
267,
520,
635,
1862,
26,
658,
807,
64,
1166,
2725,
370,
2387,
267,
520,
1107,
26,
658,
807,
64,
2058,
402,
2138,
2986,
267,
408,
267,
2648,
63,
1162,
275,
469,
288,
283,
2139,
356,
469,
355,
283,
8422,
356,
283,
3578,
15,
1001,
297,
355,
283,
498,
356,
291,
14,
1246,
63,
498,
288,
789,
267,
789,
398,
340,
1862,
365,
440,
488,
26,
288,
2648,
63,
1162,
459,
633,
63,
3214,
418,
275,
1862,
398,
2986,
275,
13986,
2017,
8,
6520,
29,
1364,
63,
6520,
9,
267,
1177,
275,
2986,
14,
362,
3682,
2103,
63,
1162,
9,
398,
372,
291,
855,
22090,
8,
1310,
14,
1001,
1012,
340,
1177,
14,
1205,
63,
600,
508,
4145,
14,
6021,
14,
745,
587,
488,
339,
768,
4639,
272,
347,
636,
1122,
8,
1310,
63,
1001,
304,
267,
408,
1002,
314,
3503,
754,
402,
2022,
1177,
398,
520,
635,
1177,
63,
1001,
26,
267,
520,
1107,
26,
267,
408,
267,
372,
1177,
63,
1001,
14,
362,
360,
2604,
358,
340,
1177,
63,
1001,
365,
440,
488,
587,
488,
339,
347,
557,
11908,
823,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
557,
11908,
823,
398,
520,
1107,
26,
267,
408,
267,
557,
11908,
823,
275,
291,
855,
362,
17519,
20397,
2855,
1370,
908,
8,
277,
14,
6520,
430,
398,
291,
855,
1205,
8,
496,
11908,
823,
9,
398,
372,
291,
855,
1122,
8,
496,
11908,
823,
9,
339,
347,
24074,
2855,
63,
991,
63,
344,
8,
277,
12,
24074,
2855,
63,
344,
304,
267,
408,
1002,
2488,
24074,
2855,
701,
1305,
398,
520,
635,
24074,
2855,
63,
344,
26,
267,
520,
1107,
26,
267,
408,
267,
24074,
2855,
275,
291,
855,
362,
17519,
20397,
2855,
1370,
908,
8,
277,
14,
6520,
395,
1862,
3713,
344,
356,
24074,
2855,
63,
344,
1552,
398,
291,
855,
1205,
8,
20397,
2855,
9,
398,
372,
291,
855,
1122,
8,
20397,
2855,
9,
339,
347,
286,
12107,
8,
277,
304,
267,
408,
1002,
769,
402,
1006,
286,
12107,
398,
520,
1107,
26,
267,
408,
267,
286,
12107,
275,
291,
855,
362,
17519,
3690,
1370,
908,
8,
277,
14,
6520,
430,
398,
291,
855,
1205,
8,
18207,
9,
398,
372,
291,
855,
1122,
8,
18207,
9,
339,
347,
14492,
63,
991,
63,
344,
8,
277,
12,
14492,
63,
344,
304,
267,
408,
1002,
2488,
14492,
701,
1305,
398,
520,
635,
14492,
63,
344,
26,
267,
520,
1107,
26,
267,
408,
267,
14492,
275,
291,
855,
362,
17519,
3690,
1370,
908,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
diegonc/client175
|
covers.py
|
3
|
7145
|
#!/usr/bin/env python
#
# covers.py
#
# Copyright 2009 Chris Seickel
#
# 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., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# The design of this module was inspired by the cover search found in
# Exaile (http://www.exaile.org/).
import hashlib, re, urllib, os, time, shutil, threading
from xml.etree import ElementTree as ET
from datetime import datetime, timedelta
class CoverSearch():
"""
Searches for covers from amazon.com (via musicbrainz.org),
then Last.fm. If neither return a valid album image, an
artist image from last.fm will be used.
"""
def __init__(self, cover_dir=None, local_covers=[]):
self.local_covers = local_covers
if cover_dir is not None:
self.cover_dir = cover_dir
else:
self.cover_dir = os.path.expanduser(os.path.join('~','.Covers'))
if not os.path.exists(self.cover_dir):
os.makedirs(self.cover_dir)
self.urlMB = 'http://musicbrainz.org/ws/1/release/?type=xml&title=%(album)s&artist=%(artist)s&limit=1'
self.regexMB = re.compile('\<asin\>([^\<]*)\<\/asin\>', re.IGNORECASE)
self.urlFM = "http://ws.audioscrobbler.com/1.0/album/%(artist)s/%(album)s/info.xml"
self.urlFM_artist = "http://ws.audioscrobbler.com/1.0/artist/%s/similar.xml"
self.regexFM_artist = re.compile('picture\=\"([^\"]*)\"', re.IGNORECASE)
self.lock = threading.RLock()
self.delta = timedelta(seconds=1)
def _delay(self, timeVar):
# Be kind, don't make more than one request per second to
# each service.
lastSearch = self.__dict__.get(timeVar, None)
if lastSearch:
n = datetime.utcnow()
dif = n - lastSearch
while dif < self.delta:
time.sleep(0.1)
n = datetime.utcnow()
dif = n - self.__dict__[timeVar]
try:
self.lock.acquire()
self.__dict__[timeVar] = datetime.utcnow()
finally:
self.lock.release()
def _findMusicBrainz(self, vars):
self._delay('last_MB_lookup')
data = urllib.urlopen(self.urlMB % vars).read()
m = self.regexMB.search(data)
if not m:
return False
else:
asin = m.group(1)
url = "http://images.amazon.com/images/P/%s.01.%sZZZZZZZ.jpg"
for sz in ['L', 'M']:
image = url % (asin, sz)
h = urllib.urlopen(image)
data = h.read()
h.close()
if len(data) > 1000:
return data
return False
def _findLastFM_album(self, vars):
self._delay('last_FM_lookup')
data = urllib.urlopen(self.urlFM % vars).read()
x = ET.XML(data)
if len(x) == 0:
print 'LASTFM SEARCH: ERROR PARSING LASTFM DATA!'
return False
c = x.find('coverart')
if len(c) == 0:
print 'LASTFM SEARCH: NO COVERART NODE IN LASTFM DATA!'
return False
for sz in ['large', 'medium', 'small']:
image = c.findtext(sz, '')
if image > '' and not image.lower().endswith('.gif'):
h = urllib.urlopen(image)
data = h.read()
h.close()
if hashlib.sha1(data).hexdigest() != "57b2c37343f711c94e83a37bd91bc4d18d2ed9d5":
return data
return False
def _findLastFM_artist(self, vars):
self._delay('last_FM_lookup')
data = urllib.urlopen(self.urlFM_artist % vars['artist']).read()
m = self.regexFM_artist.search(data)
if m:
image = m.group(1)
if image.lower().endswith('.gif'):
return False
h = urllib.urlopen(image)
data = h.read()
h.close()
if hashlib.sha1(data).hexdigest() != "57b2c37343f711c94e83a37bd91bc4d18d2ed9d5":
return data
return False
def find(self, path='', artist='', album=''):
for p in self.local_covers:
coverpath = p.replace("{folder}", path)
coverpath = coverpath.replace("{artist}", artist)
coverpath = coverpath.replace("{album}", album)
if os.path.exists(coverpath):
ext = coverpath.split(".")[-1]
covername = '%s - %s.%s' % (artist, album, ext)
cover_destination = os.path.join(self.cover_dir, covername)
if not os.path.exists(cover_destination):
try:
shutil.copy2(coverpath, cover_destination)
except IOError:
print "Could not save cover to: " + cover_destination
print "For best performance, please ensure that the directory exists and is writable."
h = open(coverpath, 'r')
data = h.read()
h.close()
return "", data
return covername, None
if not artist:
return False, None
if album:
covername = '%s - %s.jpg' % (artist, album)
lookups = [
self._findMusicBrainz,
self._findLastFM_album,
self._findLastFM_artist
]
else:
album = ''
covername = '%s.jpg' % artist
lookups = [self._findLastFM_artist]
coverpath = os.path.join(self.cover_dir, covername)
if os.path.isfile(coverpath):
return covername, None
vars = {
'album': urllib.quote_plus(album.encode("utf-8")),
'artist': urllib.quote_plus(artist.encode("utf-8"))
}
for fn in lookups:
try:
data = fn(vars)
if data:
try:
h = open(coverpath, 'w')
h.write(data)
h.close()
except:
print "Could not save cover to: " + coverpath
print "For best performance, please ensure that the directory exists and is writable."
covername = ""
return covername, data
except:
pass
return False, None
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
755,
25858,
14,
647,
199,
3,
199,
3,
755,
1898,
8937,
2799,
5719,
3240,
2000,
352,
199,
3,
199,
3,
755,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
755,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
755,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
755,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
755,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
755,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
755,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
755,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
755,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
755,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
755,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
199,
3,
755,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
755,
710,
12899,
402,
642,
859,
1990,
315,
8721,
581,
701,
314,
8486,
2754,
1911,
315,
199,
3,
755,
1316,
65,
441,
334,
1014,
921,
1544,
14,
476,
65,
441,
14,
1308,
15,
680,
421,
199,
646,
8337,
12,
295,
12,
4011,
12,
747,
12,
900,
12,
5145,
12,
5796,
199,
504,
2748,
14,
9464,
492,
13139,
465,
12265,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
533,
1849,
422,
5278,
837,
272,
408,
267,
8730,
397,
367,
25858,
687,
282,
8872,
14,
957,
334,
12897,
8504,
338,
2894,
6322,
90,
14,
1308,
395,
267,
2066,
15237,
14,
10886,
14,
221,
982,
15564,
372,
282,
1686,
16379,
1834,
12,
376,
267,
16459,
1834,
687,
2061,
14,
10886,
911,
506,
1202,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
8486,
63,
694,
29,
403,
12,
2257,
63,
5899,
83,
17894,
267,
291,
14,
1832,
63,
5899,
83,
275,
2257,
63,
5899,
83,
267,
340,
8486,
63,
694,
365,
440,
488,
26,
288,
291,
14,
5899,
63,
694,
275,
8486,
63,
694,
267,
587,
26,
288,
291,
14,
5899,
63,
694,
275,
747,
14,
515,
14,
12131,
8,
736,
14,
515,
14,
904,
21114,
26409,
967,
14895,
1333,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
5899,
63,
694,
304,
288,
747,
14,
8347,
8,
277,
14,
5899,
63,
694,
9,
398,
291,
14,
633,
4567,
275,
283,
1014,
921,
6553,
338,
2894,
6322,
90,
14,
1308,
15,
3569,
15,
17,
15,
3221,
10197,
466,
29,
1652,
6,
1213,
15438,
12110,
9,
83,
6,
11215,
15438,
11215,
9,
83,
6,
3097,
29,
17,
7,
267,
291,
14,
3821,
4567,
275,
295,
14,
2014,
2258,
28,
24202,
60,
30,
21690,
28,
3672,
2862,
28,
19814,
24202,
60,
4206,
295,
14,
15434,
9,
398,
291,
14,
633,
22367,
275,
298,
1014,
921,
3569,
14,
8130,
551,
293,
26722,
14,
957,
15,
17,
14,
16,
15,
12110,
21275,
11215,
9,
83,
21275,
12110,
9,
83,
15,
815,
14,
1652,
2,
398,
291,
14,
633,
22367,
63,
11215,
275,
298,
1014,
921,
3569,
14,
8130,
551,
293,
26722,
14,
957,
15,
17,
14,
16,
15,
11215,
3149,
83,
15,
23079,
14,
1652,
2,
267,
291,
14,
3821,
22367,
63,
11215,
275,
295,
14,
2014,
360,
12538,
60,
8178,
21690,
937,
10,
2862,
6949,
295,
14,
15434,
9,
398,
291,
14,
831,
275,
5796,
14,
30550,
342,
267,
291,
14,
3136,
275,
6871,
8,
4515,
29,
17,
9,
2378,
347,
485,
5814,
8,
277,
12,
900,
5894,
304,
267,
327,
6423,
4928,
12,
2793,
1133,
1852,
1655,
2419,
1373,
1056,
1126,
3499,
370,
267,
327,
1924,
2435,
14,
267,
2061,
5278,
275,
291,
855,
807,
4343,
362,
8,
521,
5894,
12,
488,
9,
267,
340,
2061,
5278,
26,
288,
302,
275,
2197,
14,
10779,
342,
288,
487,
70,
275,
302,
446,
2061,
5278,
288,
1830,
487,
70,
665,
291,
14,
3136,
26,
355,
900,
14,
4532,
8,
16,
14,
17,
9,
355,
302,
275,
2197,
14,
10779,
342,
355,
487,
70,
275,
302,
446,
291,
855,
807,
12298,
521,
5894,
61,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
288,
291,
855,
807,
12298,
521,
5894,
61,
275,
2197,
14,
10779,
342,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
2378,
347,
485,
1623,
29869,
34,
6322,
90,
8,
277,
12,
6802,
304,
267,
291,
423,
5814,
360,
2019,
63,
4567,
63,
3892,
358,
267,
666,
275,
4011,
14,
10890,
8,
277,
14,
633,
4567,
450,
6802,
680,
739,
342,
267,
333,
275,
291,
14,
3821,
4567,
14,
1733,
8,
576,
9,
267,
340,
440,
333,
26,
288,
372,
756,
267,
587,
26,
288,
465,
262,
275,
333,
14,
923,
8,
17,
9,
288,
1166,
275,
298,
1014,
921,
4782,
14,
15144,
14,
957,
15,
4782,
15,
48,
3149,
83,
14,
614,
4111,
83,
22186,
9909,
58,
14,
8476,
2,
288,
367,
17176,
315,
788,
44,
297,
283,
45,
2565,
355,
1834,
275,
1166,
450,
334,
24202,
12,
17176,
9,
355,
394,
275,
4011,
14,
10890,
8,
1569,
9,
355,
666,
275,
394,
14,
739,
342,
355,
394,
14,
1600,
342,
355,
340,
822,
8,
576,
9,
690,
5198,
26,
490,
372,
666,
267,
372,
756,
2378,
347,
485,
1623,
6090,
22367,
63,
12110,
8,
277,
12,
6802,
304,
267,
291,
423,
5814,
360,
2019,
63,
22367,
63,
3892,
358,
267,
666,
275,
4011,
14,
10890,
8,
277,
14,
633,
22367,
450,
6802,
680,
739,
342,
267,
671,
275,
12265,
14,
4317,
8,
576,
9,
267,
340,
822,
8,
88,
9,
508,
378,
26,
288,
870,
283,
16901,
22367,
5795,
7762,
26,
12539,
10263,
12567,
491,
11307,
22367,
7126,
11213,
288,
372,
756,
398,
286,
275,
671,
14,
1623,
360,
5899,
580,
358,
267,
340,
822,
8,
67,
9,
508,
378,
26,
288,
870,
283,
16901,
22367,
5795,
7762,
26,
4825,
5099,
2111,
2294,
4825,
1093,
1621,
491,
11307,
22367,
7126
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
755,
25858,
14,
647,
199,
3,
199,
3,
755,
1898,
8937,
2799,
5719,
3240,
2000,
352,
199,
3,
199,
3,
755,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
755,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
755,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
755,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
755,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
755,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
755,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
755,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
755,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
755,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
755,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
199,
3,
755,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
755,
710,
12899,
402,
642,
859,
1990,
315,
8721,
581,
701,
314,
8486,
2754,
1911,
315,
199,
3,
755,
1316,
65,
441,
334,
1014,
921,
1544,
14,
476,
65,
441,
14,
1308,
15,
680,
421,
199,
646,
8337,
12,
295,
12,
4011,
12,
747,
12,
900,
12,
5145,
12,
5796,
199,
504,
2748,
14,
9464,
492,
13139,
465,
12265,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
533,
1849,
422,
5278,
837,
272,
408,
267,
8730,
397,
367,
25858,
687,
282,
8872,
14,
957,
334,
12897,
8504,
338,
2894,
6322,
90,
14,
1308,
395,
267,
2066,
15237,
14,
10886,
14,
221,
982,
15564,
372,
282,
1686,
16379,
1834,
12,
376,
267,
16459,
1834,
687,
2061,
14,
10886,
911,
506,
1202,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
8486,
63,
694,
29,
403,
12,
2257,
63,
5899,
83,
17894,
267,
291,
14,
1832,
63,
5899,
83,
275,
2257,
63,
5899,
83,
267,
340,
8486,
63,
694,
365,
440,
488,
26,
288,
291,
14,
5899,
63,
694,
275,
8486,
63,
694,
267,
587,
26,
288,
291,
14,
5899,
63,
694,
275,
747,
14,
515,
14,
12131,
8,
736,
14,
515,
14,
904,
21114,
26409,
967,
14895,
1333,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
5899,
63,
694,
304,
288,
747,
14,
8347,
8,
277,
14,
5899,
63,
694,
9,
398,
291,
14,
633,
4567,
275,
283,
1014,
921,
6553,
338,
2894,
6322,
90,
14,
1308,
15,
3569,
15,
17,
15,
3221,
10197,
466,
29,
1652,
6,
1213,
15438,
12110,
9,
83,
6,
11215,
15438,
11215,
9,
83,
6,
3097,
29,
17,
7,
267,
291,
14,
3821,
4567,
275,
295,
14,
2014,
2258,
28,
24202,
60,
30,
21690,
28,
3672,
2862,
28,
19814,
24202,
60,
4206,
295,
14,
15434,
9,
398,
291,
14,
633,
22367,
275,
298,
1014,
921,
3569,
14,
8130,
551,
293,
26722,
14,
957,
15,
17,
14,
16,
15,
12110,
21275,
11215,
9,
83,
21275,
12110,
9,
83,
15,
815,
14,
1652,
2,
398,
291,
14,
633,
22367,
63,
11215,
275,
298,
1014,
921,
3569,
14,
8130,
551,
293,
26722,
14,
957,
15,
17,
14,
16,
15,
11215,
3149,
83,
15,
23079,
14,
1652,
2,
267,
291,
14,
3821,
22367,
63,
11215,
275,
295,
14,
2014,
360,
12538,
60,
8178,
21690,
937,
10,
2862,
6949,
295,
14,
15434,
9,
398,
291,
14,
831,
275,
5796,
14,
30550,
342,
267,
291,
14,
3136,
275,
6871,
8,
4515,
29,
17,
9,
2378,
347,
485,
5814,
8,
277,
12,
900,
5894,
304,
267,
327,
6423,
4928,
12,
2793,
1133,
1852,
1655,
2419,
1373,
1056,
1126,
3499,
370,
267,
327,
1924,
2435,
14,
267,
2061,
5278,
275,
291,
855,
807,
4343,
362,
8,
521,
5894,
12,
488,
9,
267,
340,
2061,
5278,
26,
288,
302,
275,
2197,
14,
10779,
342,
288,
487,
70,
275,
302,
446,
2061,
5278,
288,
1830,
487,
70,
665,
291,
14,
3136,
26,
355,
900,
14,
4532,
8,
16,
14,
17,
9,
355,
302,
275,
2197,
14,
10779,
342,
355,
487,
70,
275,
302,
446,
291,
855,
807,
12298,
521,
5894,
61,
267,
862,
26,
288,
291,
14,
831,
14,
8174,
342,
288,
291,
855,
807,
12298,
521,
5894,
61,
275,
2197,
14,
10779,
342,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
2378,
347,
485,
1623,
29869,
34,
6322,
90,
8,
277,
12,
6802,
304,
267,
291,
423,
5814,
360,
2019,
63,
4567,
63,
3892,
358,
267,
666,
275,
4011,
14,
10890,
8,
277,
14,
633,
4567,
450,
6802,
680,
739,
342,
267,
333,
275,
291,
14,
3821,
4567,
14,
1733,
8,
576,
9,
267,
340,
440,
333,
26,
288,
372,
756,
267,
587,
26,
288,
465,
262,
275,
333,
14,
923,
8,
17,
9,
288,
1166,
275,
298,
1014,
921,
4782,
14,
15144,
14,
957,
15,
4782,
15,
48,
3149,
83,
14,
614,
4111,
83,
22186,
9909,
58,
14,
8476,
2,
288,
367,
17176,
315,
788,
44,
297,
283,
45,
2565,
355,
1834,
275,
1166,
450,
334,
24202,
12,
17176,
9,
355,
394,
275,
4011,
14,
10890,
8,
1569,
9,
355,
666,
275,
394,
14,
739,
342,
355,
394,
14,
1600,
342,
355,
340,
822,
8,
576,
9,
690,
5198,
26,
490,
372,
666,
267,
372,
756,
2378,
347,
485,
1623,
6090,
22367,
63,
12110,
8,
277,
12,
6802,
304,
267,
291,
423,
5814,
360,
2019,
63,
22367,
63,
3892,
358,
267,
666,
275,
4011,
14,
10890,
8,
277,
14,
633,
22367,
450,
6802,
680,
739,
342,
267,
671,
275,
12265,
14,
4317,
8,
576,
9,
267,
340,
822,
8,
88,
9,
508,
378,
26,
288,
870,
283,
16901,
22367,
5795,
7762,
26,
12539,
10263,
12567,
491,
11307,
22367,
7126,
11213,
288,
372,
756,
398,
286,
275,
671,
14,
1623,
360,
5899,
580,
358,
267,
340,
822,
8,
67,
9,
508,
378,
26,
288,
870,
283,
16901,
22367,
5795,
7762,
26,
4825,
5099,
2111,
2294,
4825,
1093,
1621,
491,
11307,
22367,
7126,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ahmedbodi/terracoin
|
contrib/testgen/gen_base58_test_vectors.py
|
1000
|
4343
|
#!/usr/bin/env python
'''
Generate valid and invalid base58 address and private key test vectors.
Usage:
gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json
gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json
'''
# 2012 Wladimir J. van der Laan
# Released under MIT License
import os
from itertools import islice
from base58 import b58encode, b58decode, b58encode_chk, b58decode_chk, b58chars
import random
from binascii import b2a_hex
# key types
PUBKEY_ADDRESS = 0
SCRIPT_ADDRESS = 5
PUBKEY_ADDRESS_TEST = 111
SCRIPT_ADDRESS_TEST = 196
PRIVKEY = 128
PRIVKEY_TEST = 239
metadata_keys = ['isPrivkey', 'isTestnet', 'addrType', 'isCompressed']
# templates for valid sequences
templates = [
# prefix, payload_size, suffix, metadata
# None = N/A
((PUBKEY_ADDRESS,), 20, (), (False, False, 'pubkey', None)),
((SCRIPT_ADDRESS,), 20, (), (False, False, 'script', None)),
((PUBKEY_ADDRESS_TEST,), 20, (), (False, True, 'pubkey', None)),
((SCRIPT_ADDRESS_TEST,), 20, (), (False, True, 'script', None)),
((PRIVKEY,), 32, (), (True, False, None, False)),
((PRIVKEY,), 32, (1,), (True, False, None, True)),
((PRIVKEY_TEST,), 32, (), (True, True, None, False)),
((PRIVKEY_TEST,), 32, (1,), (True, True, None, True))
]
def is_valid(v):
'''Check vector v for validity'''
result = b58decode_chk(v)
if result is None:
return False
valid = False
for template in templates:
prefix = str(bytearray(template[0]))
suffix = str(bytearray(template[2]))
if result.startswith(prefix) and result.endswith(suffix):
if (len(result) - len(prefix) - len(suffix)) == template[1]:
return True
return False
def gen_valid_vectors():
'''Generate valid test vectors'''
while True:
for template in templates:
prefix = str(bytearray(template[0]))
payload = os.urandom(template[1])
suffix = str(bytearray(template[2]))
rv = b58encode_chk(prefix + payload + suffix)
assert is_valid(rv)
metadata = dict([(x,y) for (x,y) in zip(metadata_keys,template[3]) if y is not None])
yield (rv, b2a_hex(payload), metadata)
def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt_suffix):
'''Generate possibly invalid vector'''
if corrupt_prefix:
prefix = os.urandom(1)
else:
prefix = str(bytearray(template[0]))
if randomize_payload_size:
payload = os.urandom(max(int(random.expovariate(0.5)), 50))
else:
payload = os.urandom(template[1])
if corrupt_suffix:
suffix = os.urandom(len(template[2]))
else:
suffix = str(bytearray(template[2]))
return b58encode_chk(prefix + payload + suffix)
def randbool(p = 0.5):
'''Return True with P(p)'''
return random.random() < p
def gen_invalid_vectors():
'''Generate invalid test vectors'''
# start with some manual edge-cases
yield "",
yield "x",
while True:
# kinds of invalid vectors:
# invalid prefix
# invalid payload length
# invalid (randomized) suffix (add random data)
# corrupt checksum
for template in templates:
val = gen_invalid_vector(template, randbool(0.2), randbool(0.2), randbool(0.2))
if random.randint(0,10)<1: # line corruption
if randbool(): # add random character to end
val += random.choice(b58chars)
else: # replace random character in the middle
n = random.randint(0, len(val))
val = val[0:n] + random.choice(b58chars) + val[n+1:]
if not is_valid(val):
yield val,
if __name__ == '__main__':
import sys, json
iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
try:
uiter = iters[sys.argv[1]]
except IndexError:
uiter = gen_valid_vectors
try:
count = int(sys.argv[2])
except IndexError:
count = 0
data = list(islice(uiter(), count))
json.dump(data, sys.stdout, sort_keys=True, indent=4)
sys.stdout.write('\n')
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
199,
6864,
1686,
436,
3866,
1300,
2010,
2287,
436,
5726,
790,
511,
11102,
14,
199,
199,
7692,
26,
5591,
3805,
63,
1095,
2010,
63,
396,
63,
12280,
14,
647,
1686,
5238,
690,
24272,
5093,
2164,
15,
396,
15,
576,
15,
1095,
2010,
63,
1612,
63,
1078,
14,
1001,
272,
3805,
63,
1095,
2010,
63,
396,
63,
12280,
14,
647,
3866,
5238,
690,
24272,
5093,
2164,
15,
396,
15,
576,
15,
1095,
2010,
63,
1612,
63,
3197,
14,
1001,
199,
2344,
199,
3,
6029,
644,
416,
3572,
723,
1603,
14,
20744,
16921,
7964,
290,
199,
3,
17646,
68,
1334,
10697,
844,
199,
646,
747,
199,
504,
7975,
492,
365,
3037,
199,
504,
1300,
2010,
492,
330,
2010,
2143,
12,
330,
2010,
2708,
12,
330,
2010,
2143,
63,
14823,
12,
330,
2010,
2708,
63,
14823,
12,
330,
2010,
6574,
199,
646,
2196,
199,
504,
14755,
492,
330,
18,
65,
63,
4097,
199,
199,
3,
790,
2943,
199,
13047,
3078,
63,
12368,
275,
378,
199,
10484,
63,
12368,
275,
959,
199,
13047,
3078,
63,
12368,
63,
2864,
275,
20128,
199,
10484,
63,
12368,
63,
2864,
275,
32132,
199,
13420,
3078,
275,
7960,
199,
13420,
3078,
63,
2864,
275,
499,
1355,
199,
199,
2343,
63,
1612,
275,
788,
374,
4562,
86,
498,
297,
283,
374,
774,
846,
297,
283,
2697,
804,
297,
283,
374,
25428,
418,
199,
3,
7009,
367,
1686,
8013,
199,
5876,
275,
359,
523,
327,
2403,
12,
4886,
63,
890,
12,
4739,
12,
3341,
523,
327,
22456,
488,
275,
653,
15,
33,
523,
3666,
13047,
3078,
63,
12368,
4706,
420,
3388,
12,
11969,
257,
334,
797,
12,
756,
12,
283,
17178,
297,
488,
1826,
523,
3666,
10484,
63,
12368,
4706,
420,
3388,
12,
11969,
257,
334,
797,
12,
756,
12,
283,
1579,
297,
221,
488,
1826,
523,
3666,
13047,
3078,
63,
12368,
63,
2864,
4706,
3388,
12,
11969,
257,
334,
797,
12,
715,
12,
221,
283,
17178,
297,
488,
1826,
523,
3666,
10484,
63,
12368,
63,
2864,
4706,
3388,
12,
11969,
257,
334,
797,
12,
715,
12,
221,
283,
1579,
297,
221,
488,
1826,
523,
3666,
13420,
3078,
4706,
3777,
4337,
12,
11969,
257,
334,
549,
12,
221,
756,
12,
488,
12,
221,
756,
1826,
523,
3666,
13420,
3078,
4706,
3777,
4337,
12,
334,
17,
4706,
334,
549,
12,
221,
756,
12,
488,
12,
221,
715,
1826,
523,
3666,
13420,
3078,
63,
2864,
4706,
263,
4337,
12,
11969,
257,
334,
549,
12,
221,
715,
12,
221,
488,
12,
221,
756,
1826,
523,
3666,
13420,
3078,
63,
2864,
4706,
263,
4337,
12,
334,
17,
4706,
334,
549,
12,
221,
715,
12,
221,
488,
12,
221,
715,
430,
199,
61,
199,
199,
318,
365,
63,
1078,
8,
86,
304,
272,
1449,
1799,
5477,
373,
367,
25667,
2344,
272,
754,
275,
330,
2010,
2708,
63,
14823,
8,
86,
9,
272,
340,
754,
365,
488,
26,
267,
372,
756,
272,
1686,
275,
756,
272,
367,
1978,
315,
7009,
26,
267,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
267,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
267,
340,
754,
14,
2460,
8,
1861,
9,
436,
754,
14,
4130,
8,
4511,
304,
288,
340,
334,
552,
8,
1099,
9,
446,
822,
8,
1861,
9,
446,
822,
8,
4511,
430,
508,
1978,
59,
17,
2189,
355,
372,
715,
272,
372,
756,
199,
199,
318,
3805,
63,
1078,
63,
12280,
837,
272,
1449,
6864,
1686,
511,
11102,
2344,
272,
1830,
715,
26,
267,
367,
1978,
315,
7009,
26,
288,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
288,
4886,
275,
747,
14,
22776,
8,
1160,
59,
17,
566,
7205,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
288,
4336,
275,
330,
2010,
2143,
63,
14823,
8,
1861,
435,
4886,
435,
4739,
9,
288,
702,
365,
63,
1078,
8,
6310,
9,
288,
3341,
275,
1211,
7694,
88,
12,
89,
9,
367,
334,
88,
12,
89,
9,
315,
3482,
8,
2343,
63,
1612,
12,
1160,
59,
19,
566,
340,
612,
365,
440,
488,
566,
288,
1995,
334,
6310,
12,
330,
18,
65,
63,
4097,
8,
4749,
395,
3341,
9,
199,
199,
318,
3805,
63,
3197,
63,
4106,
8,
1160,
12,
29221,
63,
1861,
12,
2196,
794,
63,
4749,
63,
890,
12,
29221,
63,
4511,
304,
272,
1449,
6864,
12570,
3866,
5477,
2344,
272,
340,
29221,
63,
1861,
26,
267,
2403,
275,
747,
14,
22776,
8,
17,
9,
272,
587,
26,
267,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
2286,
340,
2196,
794,
63,
4749,
63,
890,
26,
267,
4886,
275,
747,
14,
22776,
8,
988,
8,
442,
8,
2355,
14,
476,
555,
13805,
8,
16,
14,
21,
1826,
5238,
430,
272,
587,
26,
267,
4886,
275,
747,
14,
22776,
8,
1160,
59,
17,
566,
2286,
340,
29221,
63,
4511,
26,
267,
4739,
275,
747,
14,
22776,
8,
552,
8,
1160,
59,
18,
2459,
272,
587,
26,
267,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
339,
372,
330,
2010,
2143,
63,
14823,
8,
1861,
435,
4886,
435,
4739,
9,
199,
199,
318,
10261,
2245,
8,
80,
275,
378,
14,
21,
304,
272,
1449,
1767,
715,
543,
510,
8,
80,
9,
2344,
272,
372,
2196,
14,
2355,
342,
665,
299,
199,
199,
318,
3805,
63,
3197,
63,
12280,
837,
272,
1449,
6864,
3866,
511,
11102,
2344,
272,
327,
1343,
543,
2005,
8722,
6275,
13,
9403,
272,
1995,
4873,
272,
1995,
298,
88,
401,
272,
1830,
715,
26,
267,
327,
24241,
402,
3866,
11102,
26,
267,
327,
257,
3866,
2403,
267,
327,
257,
3866,
4886,
2582,
267,
327,
257,
3866,
334,
2355,
1759,
9,
4739,
334,
525,
2196,
666,
9,
267,
327,
257,
29221,
9040,
267,
367,
1978,
315,
7009,
26,
288,
1139,
275,
3805,
63,
3197,
63,
4106,
8,
1160,
12,
10261,
2245,
8,
16,
14,
18,
395,
10261,
2245,
8,
16,
14,
18,
395,
10261,
2245,
8,
16,
14,
18,
430,
288,
340,
2196,
14,
8393,
8,
16,
12,
709,
21528,
17,
26,
327,
1004,
1970,
5505,
296,
355,
340,
10261,
2245,
837,
327,
1050,
2196,
4528,
370,
1284,
490,
1139,
847,
2196,
14,
5095,
8,
66,
2010,
6574,
9,
355
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
199,
6864,
1686,
436,
3866,
1300,
2010,
2287,
436,
5726,
790,
511,
11102,
14,
199,
199,
7692,
26,
5591,
3805,
63,
1095,
2010,
63,
396,
63,
12280,
14,
647,
1686,
5238,
690,
24272,
5093,
2164,
15,
396,
15,
576,
15,
1095,
2010,
63,
1612,
63,
1078,
14,
1001,
272,
3805,
63,
1095,
2010,
63,
396,
63,
12280,
14,
647,
3866,
5238,
690,
24272,
5093,
2164,
15,
396,
15,
576,
15,
1095,
2010,
63,
1612,
63,
3197,
14,
1001,
199,
2344,
199,
3,
6029,
644,
416,
3572,
723,
1603,
14,
20744,
16921,
7964,
290,
199,
3,
17646,
68,
1334,
10697,
844,
199,
646,
747,
199,
504,
7975,
492,
365,
3037,
199,
504,
1300,
2010,
492,
330,
2010,
2143,
12,
330,
2010,
2708,
12,
330,
2010,
2143,
63,
14823,
12,
330,
2010,
2708,
63,
14823,
12,
330,
2010,
6574,
199,
646,
2196,
199,
504,
14755,
492,
330,
18,
65,
63,
4097,
199,
199,
3,
790,
2943,
199,
13047,
3078,
63,
12368,
275,
378,
199,
10484,
63,
12368,
275,
959,
199,
13047,
3078,
63,
12368,
63,
2864,
275,
20128,
199,
10484,
63,
12368,
63,
2864,
275,
32132,
199,
13420,
3078,
275,
7960,
199,
13420,
3078,
63,
2864,
275,
499,
1355,
199,
199,
2343,
63,
1612,
275,
788,
374,
4562,
86,
498,
297,
283,
374,
774,
846,
297,
283,
2697,
804,
297,
283,
374,
25428,
418,
199,
3,
7009,
367,
1686,
8013,
199,
5876,
275,
359,
523,
327,
2403,
12,
4886,
63,
890,
12,
4739,
12,
3341,
523,
327,
22456,
488,
275,
653,
15,
33,
523,
3666,
13047,
3078,
63,
12368,
4706,
420,
3388,
12,
11969,
257,
334,
797,
12,
756,
12,
283,
17178,
297,
488,
1826,
523,
3666,
10484,
63,
12368,
4706,
420,
3388,
12,
11969,
257,
334,
797,
12,
756,
12,
283,
1579,
297,
221,
488,
1826,
523,
3666,
13047,
3078,
63,
12368,
63,
2864,
4706,
3388,
12,
11969,
257,
334,
797,
12,
715,
12,
221,
283,
17178,
297,
488,
1826,
523,
3666,
10484,
63,
12368,
63,
2864,
4706,
3388,
12,
11969,
257,
334,
797,
12,
715,
12,
221,
283,
1579,
297,
221,
488,
1826,
523,
3666,
13420,
3078,
4706,
3777,
4337,
12,
11969,
257,
334,
549,
12,
221,
756,
12,
488,
12,
221,
756,
1826,
523,
3666,
13420,
3078,
4706,
3777,
4337,
12,
334,
17,
4706,
334,
549,
12,
221,
756,
12,
488,
12,
221,
715,
1826,
523,
3666,
13420,
3078,
63,
2864,
4706,
263,
4337,
12,
11969,
257,
334,
549,
12,
221,
715,
12,
221,
488,
12,
221,
756,
1826,
523,
3666,
13420,
3078,
63,
2864,
4706,
263,
4337,
12,
334,
17,
4706,
334,
549,
12,
221,
715,
12,
221,
488,
12,
221,
715,
430,
199,
61,
199,
199,
318,
365,
63,
1078,
8,
86,
304,
272,
1449,
1799,
5477,
373,
367,
25667,
2344,
272,
754,
275,
330,
2010,
2708,
63,
14823,
8,
86,
9,
272,
340,
754,
365,
488,
26,
267,
372,
756,
272,
1686,
275,
756,
272,
367,
1978,
315,
7009,
26,
267,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
267,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
267,
340,
754,
14,
2460,
8,
1861,
9,
436,
754,
14,
4130,
8,
4511,
304,
288,
340,
334,
552,
8,
1099,
9,
446,
822,
8,
1861,
9,
446,
822,
8,
4511,
430,
508,
1978,
59,
17,
2189,
355,
372,
715,
272,
372,
756,
199,
199,
318,
3805,
63,
1078,
63,
12280,
837,
272,
1449,
6864,
1686,
511,
11102,
2344,
272,
1830,
715,
26,
267,
367,
1978,
315,
7009,
26,
288,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
288,
4886,
275,
747,
14,
22776,
8,
1160,
59,
17,
566,
7205,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
288,
4336,
275,
330,
2010,
2143,
63,
14823,
8,
1861,
435,
4886,
435,
4739,
9,
288,
702,
365,
63,
1078,
8,
6310,
9,
288,
3341,
275,
1211,
7694,
88,
12,
89,
9,
367,
334,
88,
12,
89,
9,
315,
3482,
8,
2343,
63,
1612,
12,
1160,
59,
19,
566,
340,
612,
365,
440,
488,
566,
288,
1995,
334,
6310,
12,
330,
18,
65,
63,
4097,
8,
4749,
395,
3341,
9,
199,
199,
318,
3805,
63,
3197,
63,
4106,
8,
1160,
12,
29221,
63,
1861,
12,
2196,
794,
63,
4749,
63,
890,
12,
29221,
63,
4511,
304,
272,
1449,
6864,
12570,
3866,
5477,
2344,
272,
340,
29221,
63,
1861,
26,
267,
2403,
275,
747,
14,
22776,
8,
17,
9,
272,
587,
26,
267,
2403,
275,
620,
8,
20108,
8,
1160,
59,
16,
2459,
2286,
340,
2196,
794,
63,
4749,
63,
890,
26,
267,
4886,
275,
747,
14,
22776,
8,
988,
8,
442,
8,
2355,
14,
476,
555,
13805,
8,
16,
14,
21,
1826,
5238,
430,
272,
587,
26,
267,
4886,
275,
747,
14,
22776,
8,
1160,
59,
17,
566,
2286,
340,
29221,
63,
4511,
26,
267,
4739,
275,
747,
14,
22776,
8,
552,
8,
1160,
59,
18,
2459,
272,
587,
26,
267,
4739,
275,
620,
8,
20108,
8,
1160,
59,
18,
2459,
339,
372,
330,
2010,
2143,
63,
14823,
8,
1861,
435,
4886,
435,
4739,
9,
199,
199,
318,
10261,
2245,
8,
80,
275,
378,
14,
21,
304,
272,
1449,
1767,
715,
543,
510,
8,
80,
9,
2344,
272,
372,
2196,
14,
2355,
342,
665,
299,
199,
199,
318,
3805,
63,
3197,
63,
12280,
837,
272,
1449,
6864,
3866,
511,
11102,
2344,
272,
327,
1343,
543,
2005,
8722,
6275,
13,
9403,
272,
1995,
4873,
272,
1995,
298,
88,
401,
272,
1830,
715,
26,
267,
327,
24241,
402,
3866,
11102,
26,
267,
327,
257,
3866,
2403,
267,
327,
257,
3866,
4886,
2582,
267,
327,
257,
3866,
334,
2355,
1759,
9,
4739,
334,
525,
2196,
666,
9,
267,
327,
257,
29221,
9040,
267,
367,
1978,
315,
7009,
26,
288,
1139,
275,
3805,
63,
3197,
63,
4106,
8,
1160,
12,
10261,
2245,
8,
16,
14,
18,
395,
10261,
2245,
8,
16,
14,
18,
395,
10261,
2245,
8,
16,
14,
18,
430,
288,
340,
2196,
14,
8393,
8,
16,
12,
709,
21528,
17,
26,
327,
1004,
1970,
5505,
296,
355,
340,
10261,
2245,
837,
327,
1050,
2196,
4528,
370,
1284,
490,
1139,
847,
2196,
14,
5095,
8,
66,
2010,
6574,
9,
355,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
suziesparkle/wagtail
|
wagtail/wagtailsearch/models.py
|
5
|
3229
|
from django.db import models
from django.utils import timezone
from indexed import Indexed
import datetime
import string
class Query(models.Model):
query_string = models.CharField(max_length=255, unique=True)
def save(self, *args, **kwargs):
# Normalise query string
self.query_string = self.normalise_query_string(self.query_string)
super(Query, self).save(*args, **kwargs)
def add_hit(self, date=None):
if date is None:
date = timezone.now().date()
daily_hits, created = QueryDailyHits.objects.get_or_create(query=self, date=date)
daily_hits.hits = models.F('hits') + 1
daily_hits.save()
def __unicode__(self):
return self.query_string
@property
def hits(self):
hits = self.daily_hits.aggregate(models.Sum('hits'))['hits__sum']
return hits if hits else 0
@classmethod
def garbage_collect(cls):
"""
Deletes all Query records that have no daily hits or editors picks
"""
cls.objects.filter(daily_hits__isnull=True, editors_picks__isnull=True).delete()
@classmethod
def get(cls, query_string):
return cls.objects.get_or_create(query_string=cls.normalise_query_string(query_string))[0]
@classmethod
def get_most_popular(cls, date_since=None):
# TODO: Implement date_since
return cls.objects.filter(daily_hits__isnull=False).annotate(_hits=models.Sum('daily_hits__hits')).distinct().order_by('-_hits')
@staticmethod
def normalise_query_string(query_string):
# Convert query_string to lowercase
query_string = query_string.lower()
# Strip punctuation characters
query_string = ''.join([c for c in query_string if c not in string.punctuation])
# Remove double spaces
query_string = ' '.join(query_string.split())
return query_string
class QueryDailyHits(models.Model):
query = models.ForeignKey(Query, db_index=True, related_name='daily_hits')
date = models.DateField()
hits = models.IntegerField(default=0)
@classmethod
def garbage_collect(cls):
"""
Deletes all QueryDailyHits records that are older than 7 days
"""
min_date = timezone.now().date() - datetime.timedelta(days=7)
cls.objects.filter(date__lt=min_date).delete()
class Meta:
unique_together = (
('query', 'date'),
)
class EditorsPick(models.Model):
query = models.ForeignKey(Query, db_index=True, related_name='editors_picks')
page = models.ForeignKey('wagtailcore.Page')
sort_order = models.IntegerField(null=True, blank=True, editable=False)
description = models.TextField(blank=True)
class Meta:
ordering = ('sort_order', )
# Used for tests
class SearchTest(models.Model, Indexed):
title = models.CharField(max_length=255)
content = models.TextField()
live = models.BooleanField(default=False)
indexed_fields = ("title", "content", "callable_indexed_field", "live")
def callable_indexed_field(self):
return "Callable"
class SearchTestChild(SearchTest):
extra_content = models.TextField()
indexed_fields = "extra_content"
|
bsd-3-clause
|
[
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
199,
504,
15235,
492,
26437,
199,
646,
2197,
199,
646,
1059,
421,
199,
533,
8133,
8,
992,
14,
1685,
304,
272,
1827,
63,
875,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
11514,
572,
1827,
1059,
267,
291,
14,
1131,
63,
875,
275,
291,
14,
3302,
572,
63,
1131,
63,
875,
8,
277,
14,
1131,
63,
875,
9,
398,
1613,
8,
3227,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
1050,
63,
12948,
8,
277,
12,
1434,
29,
403,
304,
267,
340,
1434,
365,
488,
26,
288,
1434,
275,
7137,
14,
2131,
1252,
602,
342,
267,
26122,
63,
16595,
12,
2737,
275,
8133,
36,
17550,
40,
1405,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
1131,
29,
277,
12,
1434,
29,
602,
9,
267,
26122,
63,
16595,
14,
16595,
275,
1709,
14,
38,
360,
16595,
358,
435,
413,
267,
26122,
63,
16595,
14,
2117,
342,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
1131,
63,
875,
339,
768,
1829,
272,
347,
19745,
8,
277,
304,
267,
19745,
275,
291,
14,
18621,
63,
16595,
14,
7516,
8,
992,
14,
6959,
360,
16595,
1333,
459,
16595,
363,
1838,
418,
267,
372,
19745,
340,
19745,
587,
378,
339,
768,
3744,
272,
347,
17516,
63,
7112,
8,
1886,
304,
267,
408,
267,
28382,
1006,
8133,
5767,
626,
1172,
949,
26122,
19745,
503,
5283,
1384,
31055,
267,
408,
267,
843,
14,
1462,
14,
1541,
8,
18621,
63,
16595,
363,
15114,
29,
549,
12,
5283,
1384,
63,
4510,
83,
363,
15114,
29,
549,
680,
1807,
342,
339,
768,
3744,
272,
347,
664,
8,
1886,
12,
1827,
63,
875,
304,
267,
372,
843,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
1131,
63,
875,
29,
1886,
14,
3302,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
11515,
16,
61,
339,
768,
3744,
272,
347,
664,
63,
2786,
63,
1935,
2238,
8,
1886,
12,
1434,
63,
8585,
29,
403,
304,
267,
327,
3254,
26,
22467,
1434,
63,
8585,
267,
372,
843,
14,
1462,
14,
1541,
8,
18621,
63,
16595,
363,
15114,
29,
797,
680,
10898,
1547,
16595,
29,
992,
14,
6959,
360,
18621,
63,
16595,
363,
16595,
11103,
12926,
1252,
1648,
63,
991,
3654,
63,
16595,
358,
339,
768,
4639,
272,
347,
3293,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
304,
267,
327,
7905,
1827,
63,
875,
370,
12141,
267,
1827,
63,
875,
275,
1827,
63,
875,
14,
2325,
342,
398,
327,
19828,
22929,
4110,
267,
1827,
63,
875,
275,
6522,
904,
779,
67,
367,
286,
315,
1827,
63,
875,
340,
286,
440,
315,
1059,
14,
25181,
566,
398,
327,
5852,
4270,
7883,
267,
1827,
63,
875,
275,
283,
1987,
904,
8,
1131,
63,
875,
14,
1294,
1012,
398,
372,
1827,
63,
875,
421,
199,
533,
8133,
36,
17550,
40,
1405,
8,
992,
14,
1685,
304,
272,
1827,
275,
1709,
14,
3190,
8,
3227,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
534,
18621,
63,
16595,
358,
272,
1434,
275,
1709,
14,
14071,
342,
272,
19745,
275,
1709,
14,
3901,
8,
885,
29,
16,
9,
339,
768,
3744,
272,
347,
17516,
63,
7112,
8,
1886,
304,
267,
408,
267,
28382,
1006,
8133,
36,
17550,
40,
1405,
5767,
626,
787,
12731,
2419,
1520,
7609,
267,
408,
267,
1748,
63,
602,
275,
7137,
14,
2131,
1252,
602,
342,
446,
2197,
14,
7473,
8,
4899,
29,
23,
9,
398,
843,
14,
1462,
14,
1541,
8,
602,
363,
4116,
29,
827,
63,
602,
680,
1807,
342,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
334,
288,
661,
1131,
297,
283,
602,
659,
267,
776,
421,
199,
533,
16407,
1384,
8587,
8,
992,
14,
1685,
304,
272,
1827,
275,
1709,
14,
3190,
8,
3227,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
534,
3773,
1384,
63,
4510,
83,
358,
272,
2034,
275,
1709,
14,
3190,
360,
31439,
14,
3276,
358,
272,
4069,
63,
1648,
275,
1709,
14,
3901,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
14783,
29,
797,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
3191,
63,
1648,
297,
776,
421,
199,
3,
8051,
367,
2295,
199,
199,
533,
8730,
774,
8,
992,
14,
1685,
12,
26437,
304,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
9,
272,
1564,
275,
1709,
14,
6254,
342,
272,
12166,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
15235,
63,
955,
275,
1689,
1213,
401,
298,
1317,
401,
298,
8296,
63,
16821,
63,
698,
401,
298,
6442,
531,
339,
347,
4550,
63,
16821,
63,
698,
8,
277,
304,
267,
372,
298,
16410,
2,
421,
199,
533,
8730,
774,
3493,
8,
5278,
774,
304,
272,
2402,
63,
1317,
275,
1709,
14,
6254,
342,
339,
15235,
63,
955,
275,
298,
2911,
63,
1317,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
199,
504,
15235,
492,
26437,
199,
646,
2197,
199,
646,
1059,
421,
199,
533,
8133,
8,
992,
14,
1685,
304,
272,
1827,
63,
875,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
11514,
572,
1827,
1059,
267,
291,
14,
1131,
63,
875,
275,
291,
14,
3302,
572,
63,
1131,
63,
875,
8,
277,
14,
1131,
63,
875,
9,
398,
1613,
8,
3227,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
1050,
63,
12948,
8,
277,
12,
1434,
29,
403,
304,
267,
340,
1434,
365,
488,
26,
288,
1434,
275,
7137,
14,
2131,
1252,
602,
342,
267,
26122,
63,
16595,
12,
2737,
275,
8133,
36,
17550,
40,
1405,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
1131,
29,
277,
12,
1434,
29,
602,
9,
267,
26122,
63,
16595,
14,
16595,
275,
1709,
14,
38,
360,
16595,
358,
435,
413,
267,
26122,
63,
16595,
14,
2117,
342,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
1131,
63,
875,
339,
768,
1829,
272,
347,
19745,
8,
277,
304,
267,
19745,
275,
291,
14,
18621,
63,
16595,
14,
7516,
8,
992,
14,
6959,
360,
16595,
1333,
459,
16595,
363,
1838,
418,
267,
372,
19745,
340,
19745,
587,
378,
339,
768,
3744,
272,
347,
17516,
63,
7112,
8,
1886,
304,
267,
408,
267,
28382,
1006,
8133,
5767,
626,
1172,
949,
26122,
19745,
503,
5283,
1384,
31055,
267,
408,
267,
843,
14,
1462,
14,
1541,
8,
18621,
63,
16595,
363,
15114,
29,
549,
12,
5283,
1384,
63,
4510,
83,
363,
15114,
29,
549,
680,
1807,
342,
339,
768,
3744,
272,
347,
664,
8,
1886,
12,
1827,
63,
875,
304,
267,
372,
843,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
1131,
63,
875,
29,
1886,
14,
3302,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
11515,
16,
61,
339,
768,
3744,
272,
347,
664,
63,
2786,
63,
1935,
2238,
8,
1886,
12,
1434,
63,
8585,
29,
403,
304,
267,
327,
3254,
26,
22467,
1434,
63,
8585,
267,
372,
843,
14,
1462,
14,
1541,
8,
18621,
63,
16595,
363,
15114,
29,
797,
680,
10898,
1547,
16595,
29,
992,
14,
6959,
360,
18621,
63,
16595,
363,
16595,
11103,
12926,
1252,
1648,
63,
991,
3654,
63,
16595,
358,
339,
768,
4639,
272,
347,
3293,
572,
63,
1131,
63,
875,
8,
1131,
63,
875,
304,
267,
327,
7905,
1827,
63,
875,
370,
12141,
267,
1827,
63,
875,
275,
1827,
63,
875,
14,
2325,
342,
398,
327,
19828,
22929,
4110,
267,
1827,
63,
875,
275,
6522,
904,
779,
67,
367,
286,
315,
1827,
63,
875,
340,
286,
440,
315,
1059,
14,
25181,
566,
398,
327,
5852,
4270,
7883,
267,
1827,
63,
875,
275,
283,
1987,
904,
8,
1131,
63,
875,
14,
1294,
1012,
398,
372,
1827,
63,
875,
421,
199,
533,
8133,
36,
17550,
40,
1405,
8,
992,
14,
1685,
304,
272,
1827,
275,
1709,
14,
3190,
8,
3227,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
534,
18621,
63,
16595,
358,
272,
1434,
275,
1709,
14,
14071,
342,
272,
19745,
275,
1709,
14,
3901,
8,
885,
29,
16,
9,
339,
768,
3744,
272,
347,
17516,
63,
7112,
8,
1886,
304,
267,
408,
267,
28382,
1006,
8133,
36,
17550,
40,
1405,
5767,
626,
787,
12731,
2419,
1520,
7609,
267,
408,
267,
1748,
63,
602,
275,
7137,
14,
2131,
1252,
602,
342,
446,
2197,
14,
7473,
8,
4899,
29,
23,
9,
398,
843,
14,
1462,
14,
1541,
8,
602,
363,
4116,
29,
827,
63,
602,
680,
1807,
342,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
334,
288,
661,
1131,
297,
283,
602,
659,
267,
776,
421,
199,
533,
16407,
1384,
8587,
8,
992,
14,
1685,
304,
272,
1827,
275,
1709,
14,
3190,
8,
3227,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
534,
3773,
1384,
63,
4510,
83,
358,
272,
2034,
275,
1709,
14,
3190,
360,
31439,
14,
3276,
358,
272,
4069,
63,
1648,
275,
1709,
14,
3901,
8,
2307,
29,
549,
12,
4596,
29,
549,
12,
14783,
29,
797,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
3191,
63,
1648,
297,
776,
421,
199,
3,
8051,
367,
2295,
199,
199,
533,
8730,
774,
8,
992,
14,
1685,
12,
26437,
304,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
9,
272,
1564,
275,
1709,
14,
6254,
342,
272,
12166,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
15235,
63,
955,
275,
1689,
1213,
401,
298,
1317,
401,
298,
8296,
63,
16821,
63,
698,
401,
298,
6442,
531,
339,
347,
4550,
63,
16821,
63,
698,
8,
277,
304,
267,
372,
298,
16410,
2,
421,
199,
533,
8730,
774,
3493,
8,
5278,
774,
304,
272,
2402,
63,
1317,
275,
1709,
14,
6254,
342,
339,
15235,
63,
955,
275,
298,
2911,
63,
1317,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Julius2342/pyvlx
|
test/frame_set_node_name_req_test.py
|
1
|
1465
|
"""Unit tests for FrameSetNodeNameRequest."""
import unittest
from pyvlx.api.frame_creation import frame_from_raw
from pyvlx.api.frames import FrameSetNodeNameRequest
class TestFrameSetNodeNameRequest(unittest.TestCase):
"""Test class FrameSetNodeNameRequest."""
# pylint: disable=too-many-public-methods,invalid-name
EXAMPLE_FRAME = (
b"\x00D\x02\x08\x04Fnord\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x1b"
)
def test_bytes(self):
"""Test FrameSetNodeNameRequest with NO_TYPE."""
frame = FrameSetNodeNameRequest(node_id=4, name="Fnord")
self.assertEqual(bytes(frame), self.EXAMPLE_FRAME)
def test_frame_from_raw(self):
"""Test parse FrameSetNodeNameRequest from raw."""
frame = frame_from_raw(self.EXAMPLE_FRAME)
self.assertTrue(isinstance(frame, FrameSetNodeNameRequest))
self.assertEqual(frame.node_id, 4)
self.assertEqual(frame.name, "Fnord")
def test_str(self):
"""Test string representation of FrameSetNodeNameRequest."""
frame = FrameSetNodeNameRequest(node_id=4, name="Fnord")
self.assertEqual(
str(frame), '<FrameSetNodeNameRequest node_id="4" name="Fnord"/>'
)
|
lgpl-3.0
|
[
624,
5072,
2295,
367,
11726,
31599,
985,
2017,
1041,
199,
646,
2882,
199,
199,
504,
1134,
7300,
88,
14,
1246,
14,
1943,
63,
8782,
492,
2787,
63,
504,
63,
1773,
199,
504,
1134,
7300,
88,
14,
1246,
14,
8444,
492,
11726,
31599,
985,
2017,
421,
199,
533,
1379,
3160,
31599,
985,
2017,
8,
2796,
14,
1746,
304,
272,
408,
774,
1021,
11726,
31599,
985,
2017,
1041,
339,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
3455,
13,
2474,
12,
3197,
13,
354,
339,
3651,
10818,
63,
12683,
275,
334,
267,
330,
3212,
88,
383,
36,
60,
88,
996,
60,
88,
2036,
60,
88,
966,
9656,
2181,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
17,
66,
2,
272,
776,
339,
347,
511,
63,
2394,
8,
277,
304,
267,
408,
774,
11726,
31599,
985,
2017,
543,
4825,
63,
2711,
1041,
267,
2787,
275,
11726,
31599,
985,
2017,
8,
932,
63,
344,
29,
20,
12,
536,
628,
9656,
2181,
531,
267,
291,
14,
629,
8,
2394,
8,
1943,
395,
291,
14,
26900,
63,
12683,
9,
339,
347,
511,
63,
1943,
63,
504,
63,
1773,
8,
277,
304,
267,
408,
774,
2198,
11726,
31599,
985,
2017,
687,
3066,
1041,
267,
2787,
275,
2787,
63,
504,
63,
1773,
8,
277,
14,
26900,
63,
12683,
9,
267,
291,
14,
1815,
8,
6074,
8,
1943,
12,
11726,
31599,
985,
2017,
430,
267,
291,
14,
629,
8,
1943,
14,
932,
63,
344,
12,
841,
9,
267,
291,
14,
629,
8,
1943,
14,
354,
12,
298,
9656,
2181,
531,
339,
347,
511,
63,
495,
8,
277,
304,
267,
408,
774,
1059,
6025,
402,
11726,
31599,
985,
2017,
1041,
267,
2787,
275,
11726,
31599,
985,
2017,
8,
932,
63,
344,
29,
20,
12,
536,
628,
9656,
2181,
531,
267,
291,
14,
629,
8,
288,
620,
8,
1943,
395,
2650,
3160,
31599,
985,
2017,
1031,
63,
344,
628,
20,
2,
536,
628,
9656,
2181,
7897,
7,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5072,
2295,
367,
11726,
31599,
985,
2017,
1041,
199,
646,
2882,
199,
199,
504,
1134,
7300,
88,
14,
1246,
14,
1943,
63,
8782,
492,
2787,
63,
504,
63,
1773,
199,
504,
1134,
7300,
88,
14,
1246,
14,
8444,
492,
11726,
31599,
985,
2017,
421,
199,
533,
1379,
3160,
31599,
985,
2017,
8,
2796,
14,
1746,
304,
272,
408,
774,
1021,
11726,
31599,
985,
2017,
1041,
339,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
3455,
13,
2474,
12,
3197,
13,
354,
339,
3651,
10818,
63,
12683,
275,
334,
267,
330,
3212,
88,
383,
36,
60,
88,
996,
60,
88,
2036,
60,
88,
966,
9656,
2181,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
2,
267,
330,
3212,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
17,
66,
2,
272,
776,
339,
347,
511,
63,
2394,
8,
277,
304,
267,
408,
774,
11726,
31599,
985,
2017,
543,
4825,
63,
2711,
1041,
267,
2787,
275,
11726,
31599,
985,
2017,
8,
932,
63,
344,
29,
20,
12,
536,
628,
9656,
2181,
531,
267,
291,
14,
629,
8,
2394,
8,
1943,
395,
291,
14,
26900,
63,
12683,
9,
339,
347,
511,
63,
1943,
63,
504,
63,
1773,
8,
277,
304,
267,
408,
774,
2198,
11726,
31599,
985,
2017,
687,
3066,
1041,
267,
2787,
275,
2787,
63,
504,
63,
1773,
8,
277,
14,
26900,
63,
12683,
9,
267,
291,
14,
1815,
8,
6074,
8,
1943,
12,
11726,
31599,
985,
2017,
430,
267,
291,
14,
629,
8,
1943,
14,
932,
63,
344,
12,
841,
9,
267,
291,
14,
629,
8,
1943,
14,
354,
12,
298,
9656,
2181,
531,
339,
347,
511,
63,
495,
8,
277,
304,
267,
408,
774,
1059,
6025,
402,
11726,
31599,
985,
2017,
1041,
267,
2787,
275,
11726,
31599,
985,
2017,
8,
932,
63,
344,
29,
20,
12,
536,
628,
9656,
2181,
531,
267,
291,
14,
629,
8,
288,
620,
8,
1943,
395,
2650,
3160,
31599,
985,
2017,
1031,
63,
344,
628,
20,
2,
536,
628,
9656,
2181,
7897,
7,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cainmatt/django
|
tests/template_tests/filter_tests/test_slugify.py
|
324
|
1430
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.template.defaultfilters import slugify
from django.test import SimpleTestCase
from django.utils.safestring import mark_safe
from ..utils import setup
class SlugifyTests(SimpleTestCase):
"""
Running slugify on a pre-escaped string leads to odd behavior,
but the result is still safe.
"""
@setup({'slugify01': '{% autoescape off %}{{ a|slugify }} {{ b|slugify }}{% endautoescape %}'})
def test_slugify01(self):
output = self.engine.render_to_string('slugify01', {'a': 'a & b', 'b': mark_safe('a & b')})
self.assertEqual(output, 'a-b a-amp-b')
@setup({'slugify02': '{{ a|slugify }} {{ b|slugify }}'})
def test_slugify02(self):
output = self.engine.render_to_string('slugify02', {'a': 'a & b', 'b': mark_safe('a & b')})
self.assertEqual(output, 'a-b a-amp-b')
class FunctionTests(SimpleTestCase):
def test_slugify(self):
self.assertEqual(
slugify(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/'),
'jack-jill-like-numbers-123-and-4-and-silly-characters',
)
def test_unicode(self):
self.assertEqual(
slugify("Un \xe9l\xe9phant \xe0 l'or\xe9e du bois"),
'un-elephant-a-loree-du-bois',
)
def test_non_string_input(self):
self.assertEqual(slugify(123), '123')
|
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,
1160,
14,
885,
4273,
492,
29864,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
428,
32047,
2021,
2925,
8,
17968,
304,
272,
408,
272,
26848,
29864,
641,
282,
876,
13,
13572,
1059,
27401,
370,
16699,
5953,
12,
272,
1325,
314,
754,
365,
5139,
5048,
14,
272,
408,
339,
768,
2758,
3252,
5464,
2021,
614,
356,
12100,
19102,
2331,
17337,
282,
92,
5464,
2021,
3586,
8448,
330,
92,
5464,
2021,
20104,
1284,
15818,
17776,
272,
347,
511,
63,
5464,
2021,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
5464,
2021,
614,
297,
791,
65,
356,
283,
65,
1253,
330,
297,
283,
66,
356,
2216,
63,
3489,
360,
65,
1253,
5282,
27,
330,
22220,
267,
291,
14,
629,
8,
1199,
12,
283,
65,
13,
66,
282,
13,
5282,
13,
66,
358,
339,
768,
2758,
3252,
5464,
2021,
996,
356,
11400,
282,
92,
5464,
2021,
3586,
8448,
330,
92,
5464,
2021,
29281,
272,
347,
511,
63,
5464,
2021,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
5464,
2021,
996,
297,
791,
65,
356,
283,
65,
1253,
330,
297,
283,
66,
356,
2216,
63,
3489,
360,
65,
1253,
5282,
27,
330,
22220,
267,
291,
14,
629,
8,
1199,
12,
283,
65,
13,
66,
282,
13,
5282,
13,
66,
358,
421,
199,
533,
6801,
2925,
8,
17968,
304,
339,
347,
511,
63,
5464,
2021,
8,
277,
304,
267,
291,
14,
629,
8,
288,
29864,
360,
1603,
564,
1253,
1603,
778,
2839,
5579,
413,
12,
18,
12,
19,
436,
841,
436,
24968,
590,
4110,
5805,
17229,
4,
1,
20467,
288,
283,
19193,
13,
74,
778,
13,
2930,
13,
10548,
13,
4288,
13,
460,
13,
20,
13,
460,
13,
20329,
590,
13,
16516,
297,
267,
776,
339,
347,
511,
63,
2975,
8,
277,
304,
267,
291,
14,
629,
8,
288,
29864,
480,
1358,
971,
1845,
25,
76,
60,
1845,
25,
838,
867,
971,
1845,
16,
634,
7,
269,
60,
1845,
25,
69,
15776,
1234,
374,
1288,
288,
283,
324,
13,
8081,
838,
867,
13,
65,
13,
320,
850,
13,
2033,
13,
656,
374,
297,
267,
776,
339,
347,
511,
63,
2865,
63,
875,
63,
1210,
8,
277,
304,
267,
291,
14,
629,
8,
5464,
2021,
8,
4288,
395,
283,
4288,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
1160,
14,
885,
4273,
492,
29864,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
428,
32047,
2021,
2925,
8,
17968,
304,
272,
408,
272,
26848,
29864,
641,
282,
876,
13,
13572,
1059,
27401,
370,
16699,
5953,
12,
272,
1325,
314,
754,
365,
5139,
5048,
14,
272,
408,
339,
768,
2758,
3252,
5464,
2021,
614,
356,
12100,
19102,
2331,
17337,
282,
92,
5464,
2021,
3586,
8448,
330,
92,
5464,
2021,
20104,
1284,
15818,
17776,
272,
347,
511,
63,
5464,
2021,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
5464,
2021,
614,
297,
791,
65,
356,
283,
65,
1253,
330,
297,
283,
66,
356,
2216,
63,
3489,
360,
65,
1253,
5282,
27,
330,
22220,
267,
291,
14,
629,
8,
1199,
12,
283,
65,
13,
66,
282,
13,
5282,
13,
66,
358,
339,
768,
2758,
3252,
5464,
2021,
996,
356,
11400,
282,
92,
5464,
2021,
3586,
8448,
330,
92,
5464,
2021,
29281,
272,
347,
511,
63,
5464,
2021,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
5464,
2021,
996,
297,
791,
65,
356,
283,
65,
1253,
330,
297,
283,
66,
356,
2216,
63,
3489,
360,
65,
1253,
5282,
27,
330,
22220,
267,
291,
14,
629,
8,
1199,
12,
283,
65,
13,
66,
282,
13,
5282,
13,
66,
358,
421,
199,
533,
6801,
2925,
8,
17968,
304,
339,
347,
511,
63,
5464,
2021,
8,
277,
304,
267,
291,
14,
629,
8,
288,
29864,
360,
1603,
564,
1253,
1603,
778,
2839,
5579,
413,
12,
18,
12,
19,
436,
841,
436,
24968,
590,
4110,
5805,
17229,
4,
1,
20467,
288,
283,
19193,
13,
74,
778,
13,
2930,
13,
10548,
13,
4288,
13,
460,
13,
20,
13,
460,
13,
20329,
590,
13,
16516,
297,
267,
776,
339,
347,
511,
63,
2975,
8,
277,
304,
267,
291,
14,
629,
8,
288,
29864,
480,
1358,
971,
1845,
25,
76,
60,
1845,
25,
838,
867,
971,
1845,
16,
634,
7,
269,
60,
1845,
25,
69,
15776,
1234,
374,
1288,
288,
283,
324,
13,
8081,
838,
867,
13,
65,
13,
320,
850,
13,
2033,
13,
656,
374,
297,
267,
776,
339,
347,
511,
63,
2865,
63,
875,
63,
1210,
8,
277,
304,
267,
291,
14,
629,
8,
5464,
2021,
8,
4288,
395,
283,
4288,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ref import WeakKeyDictionary
from time import time
import sys
from PodSixNet.Server import Server
from PodSixNet.Channel import Channel
class LagTimeChannel(Channel):
"""
This is the server representation of a single connected client.
"""
def __init__(self, *args, **kwargs):
Channel.__init__(self, *args, **kwargs)
self.count = 0
self.times = []
def Close(self):
print(self, 'Client disconnected')
##################################
### Network specific callbacks ###
##################################
def Network_ping(self, data):
print(self, "ping %d round trip time was %f" % (data["count"], time() - self.times[data["count"]]))
self.Ping()
def Ping(self):
print(self, "Ping:", self.count)
self.times.append(time())
self.Send({"action": "ping", "count": self.count})
self.count += 1
class LagTimeServer(Server):
channelClass = LagTimeChannel
def __init__(self, *args, **kwargs):
Server.__init__(self, *args, **kwargs)
print('Server launched')
def Connected(self, channel, addr):
print(channel, "Channel connected")
channel.Ping()
def Launch(self):
while True:
self.Pump()
sleep(0.0001)
# get command line argument of server, port
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage:", sys.argv[0], "host:port")
print("e.g.", sys.argv[0], "localhost:31425")
else:
host, port = sys.argv[1].split(":")
s = LagTimeServer(localaddr=(host, int(port)))
s.Launch()
|
lgpl-3.0
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
900,
492,
9435,
12,
2257,
521,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
504,
900,
492,
900,
199,
646,
984,
199,
199,
504,
510,
364,
26241,
2480,
14,
3120,
492,
7146,
199,
504,
510,
364,
26241,
2480,
14,
5358,
492,
17270,
199,
199,
533,
491,
643,
1366,
5358,
8,
5358,
304,
272,
408,
272,
961,
365,
314,
1654,
6025,
402,
282,
2849,
8539,
1890,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
17270,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
835,
275,
378,
267,
291,
14,
4508,
275,
942,
2286,
347,
15524,
8,
277,
304,
267,
870,
8,
277,
12,
283,
3041,
25602,
358,
2286,
10371,
309,
272,
6754,
7220,
2488,
13484,
6754,
272,
10371,
309,
2286,
347,
7220,
63,
4073,
8,
277,
12,
666,
304,
267,
870,
8,
277,
12,
298,
4073,
450,
68,
6168,
18038,
900,
1990,
450,
70,
2,
450,
334,
576,
905,
835,
2255,
900,
342,
446,
291,
14,
4508,
59,
576,
905,
835,
937,
2459,
267,
291,
14,
22638,
342,
2286,
347,
510,
316,
8,
277,
304,
267,
870,
8,
277,
12,
298,
22638,
6783,
291,
14,
835,
9,
267,
291,
14,
4508,
14,
740,
8,
521,
1012,
267,
291,
14,
6795,
6333,
1287,
582,
298,
4073,
401,
298,
835,
582,
291,
14,
835,
1552,
267,
291,
14,
835,
847,
413,
199,
199,
533,
491,
643,
1366,
3120,
8,
3120,
304,
272,
3623,
2543,
275,
491,
643,
1366,
5358,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
7146,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
870,
360,
3120,
27725,
358,
2286,
347,
1448,
4636,
8,
277,
12,
3623,
12,
5552,
304,
267,
870,
8,
2775,
12,
298,
5358,
8539,
531,
267,
3623,
14,
22638,
342,
2286,
347,
23615,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
14,
48,
1220,
342,
288,
9435,
8,
16,
14,
4183,
9,
199,
199,
3,
664,
1414,
1004,
1423,
402,
1654,
12,
1844,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
480,
7692,
6783,
984,
14,
3020,
59,
16,
467,
298,
1102,
26,
719,
531,
267,
870,
480,
69,
14,
71,
4765,
984,
14,
3020,
59,
16,
467,
298,
5967,
26,
8988,
821,
531,
272,
587,
26,
267,
1591,
12,
1844,
275,
984,
14,
3020,
59,
17,
1055,
1294,
20063,
267,
308,
275,
491,
643,
1366,
3120,
8,
1832,
2697,
2687,
1102,
12,
1109,
8,
719,
1724,
267,
308,
14,
18543,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
900,
492,
9435,
12,
2257,
521,
199,
504,
13852,
492,
28224,
1197,
11728,
199,
504,
900,
492,
900,
199,
646,
984,
199,
199,
504,
510,
364,
26241,
2480,
14,
3120,
492,
7146,
199,
504,
510,
364,
26241,
2480,
14,
5358,
492,
17270,
199,
199,
533,
491,
643,
1366,
5358,
8,
5358,
304,
272,
408,
272,
961,
365,
314,
1654,
6025,
402,
282,
2849,
8539,
1890,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
17270,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
835,
275,
378,
267,
291,
14,
4508,
275,
942,
2286,
347,
15524,
8,
277,
304,
267,
870,
8,
277,
12,
283,
3041,
25602,
358,
2286,
10371,
309,
272,
6754,
7220,
2488,
13484,
6754,
272,
10371,
309,
2286,
347,
7220,
63,
4073,
8,
277,
12,
666,
304,
267,
870,
8,
277,
12,
298,
4073,
450,
68,
6168,
18038,
900,
1990,
450,
70,
2,
450,
334,
576,
905,
835,
2255,
900,
342,
446,
291,
14,
4508,
59,
576,
905,
835,
937,
2459,
267,
291,
14,
22638,
342,
2286,
347,
510,
316,
8,
277,
304,
267,
870,
8,
277,
12,
298,
22638,
6783,
291,
14,
835,
9,
267,
291,
14,
4508,
14,
740,
8,
521,
1012,
267,
291,
14,
6795,
6333,
1287,
582,
298,
4073,
401,
298,
835,
582,
291,
14,
835,
1552,
267,
291,
14,
835,
847,
413,
199,
199,
533,
491,
643,
1366,
3120,
8,
3120,
304,
272,
3623,
2543,
275,
491,
643,
1366,
5358,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
7146,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
870,
360,
3120,
27725,
358,
2286,
347,
1448,
4636,
8,
277,
12,
3623,
12,
5552,
304,
267,
870,
8,
2775,
12,
298,
5358,
8539,
531,
267,
3623,
14,
22638,
342,
2286,
347,
23615,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
14,
48,
1220,
342,
288,
9435,
8,
16,
14,
4183,
9,
199,
199,
3,
664,
1414,
1004,
1423,
402,
1654,
12,
1844,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
267,
870,
480,
7692,
6783,
984,
14,
3020,
59,
16,
467,
298,
1102,
26,
719,
531,
267,
870,
480,
69,
14,
71,
4765,
984,
14,
3020,
59,
16,
467,
298,
5967,
26,
8988,
821,
531,
272,
587,
26,
267,
1591,
12,
1844,
275,
984,
14,
3020,
59,
17,
1055,
1294,
20063,
267,
308,
275,
491,
643,
1366,
3120,
8,
1832,
2697,
2687,
1102,
12,
1109,
8,
719,
1724,
267,
308,
14,
18543,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ryString,action,secret):
#1. Create the entire query string for your API call without the checksum parameter "name=Test+Meeting&meetingID=abc123&attendeePW=111222&moderatorPW=333444"
#2. Prepend the call name to your string "createname=Test+Meeting&meetingID=abc123&attendeePW=111222&moderatorPW=333444"
#3. Now, append the shared secret to your string "createname=Test+Meeting&meetingID=abc123&attendeePW=111222&moderatorPW=333444639259d4-9dd8-4b25-bf01-95f9567eaf4b"
checksum = action+queryString+secret
#4. Now, find the SHA-1 sum for that string "1fcbb0c4fc1f039f73aa6d697d2db9ba7f803f17"
sha1 = hashlib.sha1(checksum)
sha1Hex = sha1.hexdigest()
# print "debug sha1hex = "+sha1Hex
#5. Add a checksum parameter to your query string that contains this checksum "name=Test+Meeting&meetingID=abc123&attendeePW=111222&moderatorPW=333444&checksum=1fcbb0c4fc1f039f73aa6d697d2db9ba7f803f17"
finalChecksumUrl = action+"?"+queryString+"&checksum="+sha1Hex
return finalChecksumUrl
|
mit
|
[
3,
1353,
281,
634,
7,
633,
282,
6046,
27970,
9040,
199,
199,
646,
8337,
199,
199,
318,
9040,
6417,
8,
1131,
1558,
12,
1287,
12,
4731,
304,
199,
198,
3,
17,
14,
2790,
314,
8039,
1827,
1059,
367,
2195,
3261,
1240,
1928,
314,
9040,
2725,
298,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
2,
199,
198,
3,
18,
14,
510,
1155,
500,
314,
1240,
536,
370,
2195,
1059,
298,
981,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
2,
199,
198,
3,
19,
14,
7356,
12,
5666,
314,
5709,
7565,
370,
2195,
1059,
221,
298,
981,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
19792,
1355,
11990,
68,
20,
13,
25,
617,
24,
13,
20,
66,
821,
13,
4361,
614,
13,
2720,
70,
25,
5308,
69,
2756,
20,
66,
2,
199,
198,
8928,
275,
1595,
11,
1131,
1558,
11,
4731,
199,
198,
3,
20,
14,
7356,
12,
2342,
314,
12002,
13,
17,
3089,
367,
626,
1059,
298,
17,
3003,
2501,
16,
67,
20,
3003,
17,
70,
10005,
70,
2898,
2158,
22,
68,
19301,
68,
18,
697,
25,
2470,
23,
70,
14187,
70,
1196,
2,
199,
198,
4835,
17,
275,
8337,
14,
4835,
17,
8,
8928,
9,
199,
198,
4835,
17,
10373,
275,
7793,
17,
14,
11453,
342,
199,
3,
198,
1361,
298,
1757,
7793,
17,
4097,
275,
7210,
4835,
17,
10373,
199,
198,
3,
21,
14,
2654,
282,
9040,
2725,
370,
2195,
1827,
1059,
626,
3509,
642,
9040,
298,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
6,
8928,
29,
17,
3003,
2501,
16,
67,
20,
3003,
17,
70,
10005,
70,
2898,
2158,
22,
68,
19301,
68,
18,
697,
25,
2470,
23,
70,
14187,
70,
1196,
2,
199,
198,
5094,
17394,
6417,
275,
1595,
5207,
31,
7709,
1131,
1558,
5207,
6,
8928,
16368,
4835,
17,
10373,
199,
198,
1107,
4242,
17394,
6417,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1353,
281,
634,
7,
633,
282,
6046,
27970,
9040,
199,
199,
646,
8337,
199,
199,
318,
9040,
6417,
8,
1131,
1558,
12,
1287,
12,
4731,
304,
199,
198,
3,
17,
14,
2790,
314,
8039,
1827,
1059,
367,
2195,
3261,
1240,
1928,
314,
9040,
2725,
298,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
2,
199,
198,
3,
18,
14,
510,
1155,
500,
314,
1240,
536,
370,
2195,
1059,
298,
981,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
2,
199,
198,
3,
19,
14,
7356,
12,
5666,
314,
5709,
7565,
370,
2195,
1059,
221,
298,
981,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
19792,
1355,
11990,
68,
20,
13,
25,
617,
24,
13,
20,
66,
821,
13,
4361,
614,
13,
2720,
70,
25,
5308,
69,
2756,
20,
66,
2,
199,
198,
8928,
275,
1595,
11,
1131,
1558,
11,
4731,
199,
198,
3,
20,
14,
7356,
12,
2342,
314,
12002,
13,
17,
3089,
367,
626,
1059,
298,
17,
3003,
2501,
16,
67,
20,
3003,
17,
70,
10005,
70,
2898,
2158,
22,
68,
19301,
68,
18,
697,
25,
2470,
23,
70,
14187,
70,
1196,
2,
199,
198,
4835,
17,
275,
8337,
14,
4835,
17,
8,
8928,
9,
199,
198,
4835,
17,
10373,
275,
7793,
17,
14,
11453,
342,
199,
3,
198,
1361,
298,
1757,
7793,
17,
4097,
275,
7210,
4835,
17,
10373,
199,
198,
3,
21,
14,
2654,
282,
9040,
2725,
370,
2195,
1827,
1059,
626,
3509,
642,
9040,
298,
354,
29,
774,
11,
1352,
13800,
6,
278,
13800,
998,
29,
3175,
4288,
6,
30469,
10780,
29,
31558,
1081,
6,
25597,
10780,
29,
1153,
1082,
1602,
6,
8928,
29,
17,
3003,
2501,
16,
67,
20,
3003,
17,
70,
10005,
70,
2898,
2158,
22,
68,
19301,
68,
18,
697,
25,
2470,
23,
70,
14187,
70,
1196,
2,
199,
198,
5094,
17394,
6417,
275,
1595,
5207,
31,
7709,
1131,
1558,
5207,
6,
8928,
16368,
4835,
17,
10373,
199,
198,
1107,
4242,
17394,
6417,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
dav1x/ansible
|
lib/ansible/modules/system/user.py
|
10
|
76166
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: user
author: "Stephen Fromm (@sfromm)"
version_added: "0.2"
short_description: Manage user accounts
notes:
- There are specific requirements per platform on user management utilities. However
they generally come pre-installed with the system and Ansible will require they
are present at runtime. If they are not, a descriptive error message will be shown.
description:
- Manage user accounts and user attributes.
options:
name:
required: true
aliases: [ "user" ]
description:
- Name of the user to create, remove or modify.
comment:
required: false
description:
- Optionally sets the description (aka I(GECOS)) of user account.
uid:
required: false
description:
- Optionally sets the I(UID) of the user.
non_unique:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- Optionally when used with the -u option, this option allows to
change the user ID to a non-unique value.
version_added: "1.1"
seuser:
required: false
description:
- Optionally sets the seuser type (user_u) on selinux enabled systems.
version_added: "2.1"
group:
required: false
description:
- Optionally sets the user's primary group (takes a group name).
groups:
required: false
description:
- Puts the user in list of groups. When set to the empty string ('groups='),
the user is removed from all groups except the primary group.
- Before version 2.3, the only input format allowed was a 'comma separated string',
now it should be able to accept YAML lists also.
append:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- If C(yes), will only add groups, not set them to just the list
in I(groups).
shell:
required: false
description:
- Optionally set the user's shell.
home:
required: false
description:
- Optionally set the user's home directory.
skeleton:
required: false
description:
- Optionally set a home skeleton directory. Requires createhome option!
version_added: "2.0"
password:
required: false
description:
- Optionally set the user's password to this crypted value. See
the user example in the github examples directory for what this looks
like in a playbook. See U(http://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module)
for details on various ways to generate these password values.
Note on Darwin system, this value has to be cleartext.
Beware of security issues.
state:
required: false
default: "present"
choices: [ present, absent ]
description:
- Whether the account should exist or not, taking action if the state is different from what is stated.
createhome:
required: false
default: "yes"
choices: [ "yes", "no" ]
description:
- Unless set to C(no), a home directory will be made for the user
when the account is created or if the home directory does not
exist.
move_home:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- If set to C(yes) when used with C(home=), attempt to move the
user's home directory to the specified directory if it isn't there
already.
system:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- When creating an account, setting this to C(yes) makes the user a
system account. This setting cannot be changed on existing users.
force:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- When used with C(state=absent), behavior is as with
C(userdel --force).
login_class:
required: false
description:
- Optionally sets the user's login class for FreeBSD, OpenBSD and NetBSD systems.
remove:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- When used with C(state=absent), behavior is as with
C(userdel --remove).
generate_ssh_key:
required: false
default: "no"
choices: [ "yes", "no" ]
version_added: "0.9"
description:
- Whether to generate a SSH key for the user in question.
This will B(not) overwrite an existing SSH key.
ssh_key_bits:
required: false
default: default set by ssh-keygen
version_added: "0.9"
description:
- Optionally specify number of bits in SSH key to create.
ssh_key_type:
required: false
default: rsa
version_added: "0.9"
description:
- Optionally specify the type of SSH key to generate.
Available SSH key types will depend on implementation
present on target host.
ssh_key_file:
required: false
default: .ssh/id_rsa
version_added: "0.9"
description:
- Optionally specify the SSH key filename. If this is a relative
filename then it will be relative to the user's home directory.
ssh_key_comment:
required: false
default: ansible-generated on $HOSTNAME
version_added: "0.9"
description:
- Optionally define the comment for the SSH key.
ssh_key_passphrase:
required: false
version_added: "0.9"
description:
- Set a passphrase for the SSH key. If no
passphrase is provided, the SSH key will default to
having no passphrase.
update_password:
required: false
default: always
choices: ['always', 'on_create']
version_added: "1.3"
description:
- C(always) will update passwords if they differ. C(on_create) will only set the password for newly created users.
expires:
version_added: "1.9"
required: false
default: "None"
description:
- An expiry time for the user in epoch, it will be ignored on platforms that do not support this.
Currently supported on Linux and FreeBSD.
'''
EXAMPLES = '''
# Add the user 'johnd' with a specific uid and a primary group of 'admin'
- user:
name: johnd
comment: "John Doe"
uid: 1040
group: admin
# Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
- user:
name: james
shell: /bin/bash
groups: admins,developers
append: yes
# Remove the user 'johnd'
- user:
name: johnd
state: absent
remove: yes
# Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
- user:
name: jsmith
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
# added a consultant whose account you want to expire
- user:
name: james18
shell: /bin/zsh
groups: developers
expires: 1422403387
'''
import os
import pwd
import grp
import platform
import socket
import time
import shutil
from ansible.module_utils._text import to_native
from ansible.module_utils.basic import load_platform_subclass, AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
try:
import spwd
HAVE_SPWD=True
except:
HAVE_SPWD=False
class User(object):
"""
This is a generic User manipulation class that is subclassed
based on platform.
A subclass may wish to override the following action methods:-
- create_user()
- remove_user()
- modify_user()
- ssh_key_gen()
- ssh_key_fingerprint()
- user_exists()
All subclasses MUST define platform and distribution (which may be None).
"""
platform = 'Generic'
distribution = None
SHADOWFILE = '/etc/shadow'
DATE_FORMAT = '%Y-%m-%d'
def __new__(cls, *args, **kwargs):
return load_platform_subclass(User, args, kwargs)
def __init__(self, module):
self.module = module
self.state = module.params['state']
self.name = module.params['name']
self.uid = module.params['uid']
self.non_unique = module.params['non_unique']
self.seuser = module.params['seuser']
self.group = module.params['group']
self.comment = module.params['comment']
self.shell = module.params['shell']
self.password = module.params['password']
self.force = module.params['force']
self.remove = module.params['remove']
self.createhome = module.params['createhome']
self.move_home = module.params['move_home']
self.skeleton = module.params['skeleton']
self.system = module.params['system']
self.login_class = module.params['login_class']
self.append = module.params['append']
self.sshkeygen = module.params['generate_ssh_key']
self.ssh_bits = module.params['ssh_key_bits']
self.ssh_type = module.params['ssh_key_type']
self.ssh_comment = module.params['ssh_key_comment']
self.ssh_passphrase = module.params['ssh_key_passphrase']
self.update_password = module.params['update_password']
self.home = module.params['home']
self.expires = None
self.groups = None
if module.params['groups'] is not None:
self.groups = ','.join(module.params['groups'])
if module.params['expires']:
try:
self.expires = time.gmtime(module.params['expires'])
except Exception:
e = get_exception()
module.fail_json(msg="Invalid expires time %s: %s" %(self.expires, str(e)))
if module.params['ssh_key_file'] is not None:
self.ssh_file = module.params['ssh_key_file']
else:
self.ssh_file = os.path.join('.ssh', 'id_%s' % self.ssh_type)
def execute_command(self, cmd, use_unsafe_shell=False, data=None, obey_checkmode=True):
if self.module.check_mode and obey_checkmode:
self.module.debug('In check mode, would have run: "%s"' % cmd)
return (0, '','')
else:
# cast all args to strings ansible-modules-core/issues/4397
cmd = [str(x) for x in cmd]
return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data)
def remove_user_userdel(self):
cmd = [self.module.get_bin_path('userdel', True)]
if self.force:
cmd.append('-f')
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def create_user_useradd(self, command_name='useradd'):
cmd = [self.module.get_bin_path(command_name, True)]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.seuser is not None:
cmd.append('-Z')
cmd.append(self.seuser)
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
elif self.group_exists(self.name):
# use the -N option (no user group) if a group already
# exists with the same name as the user to prevent
# errors from useradd trying to create a group when
# USERGROUPS_ENAB is set in /etc/login.defs.
if os.path.exists('/etc/redhat-release'):
dist = platform.dist()
major_release = int(dist[1].split('.')[0])
if major_release <= 5:
cmd.append('-n')
else:
cmd.append('-N')
else:
cmd.append('-N')
if self.groups is not None and len(self.groups):
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.expires:
cmd.append('--expiredate')
cmd.append(time.strftime(self.DATE_FORMAT, self.expires))
if self.password is not None:
cmd.append('-p')
cmd.append(self.password)
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
else:
cmd.append('-M')
if self.system:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def _check_usermod_append(self):
# check if this version of usermod can append groups
usermod_path = self.module.get_bin_path('usermod', True)
# for some reason, usermod --help cannot be used by non root
# on RH/Fedora, due to lack of execute bit for others
if not os.access(usermod_path, os.X_OK):
return False
cmd = [usermod_path, '--help']
(rc, data1, data2) = self.execute_command(cmd, obey_checkmode=False)
helpout = data1 + data2
# check if --append exists
lines = to_native(helpout).split('\n')
for line in lines:
if line.strip().startswith('-a, --append'):
return True
return False
def modify_user_usermod(self):
cmd = [self.module.get_bin_path('usermod', True)]
info = self.user_info()
has_append = self._check_usermod_append()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
# get a list of all groups for the user, including the primary
current_groups = self.user_group_membership(exclude_primary=False)
groups_need_mod = False
groups = []
if self.groups == '':
if current_groups and not self.append:
groups_need_mod = True
else:
groups = self.get_groups_set(remove_existing=False)
group_diff = set(current_groups).symmetric_difference(groups)
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
if has_append:
cmd.append('-a')
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
if self.append and not has_append:
cmd.append('-A')
cmd.append(','.join(group_diff))
else:
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
cmd.append('-d')
cmd.append(self.home)
if self.move_home:
cmd.append('-m')
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
if self.expires:
cmd.append('--expiredate')
cmd.append(time.strftime(self.DATE_FORMAT, self.expires))
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
cmd.append('-p')
cmd.append(self.password)
# skip if no changes to be made
if len(cmd) == 1:
return (None, '', '')
cmd.append(self.name)
return self.execute_command(cmd)
def group_exists(self,group):
try:
# Try group as a gid first
grp.getgrgid(int(group))
return True
except (ValueError, KeyError):
try:
grp.getgrnam(group)
return True
except KeyError:
return False
def group_info(self, group):
if not self.group_exists(group):
return False
try:
# Try group as a gid first
return list(grp.getgrgid(int(group)))
except (ValueError, KeyError):
return list(grp.getgrnam(group))
def get_groups_set(self, remove_existing=True):
if self.groups is None:
return None
info = self.user_info()
groups = set(x.strip() for x in self.groups.split(',') if x)
for g in groups.copy():
if not self.group_exists(g):
self.module.fail_json(msg="Group %s does not exist" % (g))
if info and remove_existing and self.group_info(g)[2] == info[3]:
groups.remove(g)
return groups
def user_group_membership(self, exclude_primary=True):
''' Return a list of groups the user belongs to '''
groups = []
info = self.get_pwd_info()
for group in grp.getgrall():
if self.name in group.gr_mem:
# Exclude the user's primary group by default
if not exclude_primary:
groups.append(group[0])
else:
if info[3] != group.gr_gid:
groups.append(group[0])
return groups
def user_exists(self):
try:
if pwd.getpwnam(self.name):
return True
except KeyError:
return False
def get_pwd_info(self):
if not self.user_exists():
return False
return list(pwd.getpwnam(self.name))
def user_info(self):
if not self.user_exists():
return False
info = self.get_pwd_info()
if len(info[1]) == 1 or len(info[1]) == 0:
info[1] = self.user_password()
return info
def user_password(self):
passwd = ''
if HAVE_SPWD:
try:
passwd = spwd.getspnam(self.name)[1]
except KeyError:
return passwd
if not self.user_exists():
return passwd
elif self.SHADOWFILE:
# Read shadow file for user's encrypted password string
if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK):
for line in open(self.SHADOWFILE).readlines():
if line.startswith('%s:' % self.name):
passwd = line.split(':')[1]
return passwd
def get_ssh_key_path(self):
info = self.user_info()
if os.path.isabs(self.ssh_file):
ssh_key_file = self.ssh_file
else:
ssh_key_file = os.path.join(info[5], self.ssh_file)
return ssh_key_file
def ssh_key_gen(self):
info = self.user_info()
if not os.path.exists(info[5]) and not self.module.check_mode:
return (1, '', 'User %s home directory does not exist' % self.name)
ssh_key_file = self.get_ssh_key_path()
ssh_dir = os.path.dirname(ssh_key_file)
if not os.path.exists(ssh_dir):
if self.module.check_mode:
return (0, '', '')
try:
os.mkdir(ssh_dir, int('0700', 8))
os.chown(ssh_dir, info[2], info[3])
except OSError:
e = get_exception()
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
if os.path.exists(ssh_key_file):
return (None, 'Key already exists', '')
cmd = [self.module.get_bin_path('ssh-keygen', True)]
cmd.append('-t')
cmd.append(self.ssh_type)
if self.ssh_bits > 0:
cmd.append('-b')
cmd.append(self.ssh_bits)
cmd.append('-C')
cmd.append(self.ssh_comment)
cmd.append('-f')
cmd.append(ssh_key_file)
cmd.append('-N')
if self.ssh_passphrase is not None:
cmd.append(self.ssh_passphrase)
else:
cmd.append('')
(rc, out, err) = self.execute_command(cmd)
if rc == 0 and not self.module.check_mode:
# If the keys were successfully created, we should be able
# to tweak ownership.
os.chown(ssh_key_file, info[2], info[3])
os.chown('%s.pub' % ssh_key_file, info[2], info[3])
return (rc, out, err)
def ssh_key_fingerprint(self):
ssh_key_file = self.get_ssh_key_path()
if not os.path.exists(ssh_key_file):
return (1, 'SSH Key file %s does not exist' % ssh_key_file, '')
cmd = [ self.module.get_bin_path('ssh-keygen', True) ]
cmd.append('-l')
cmd.append('-f')
cmd.append(ssh_key_file)
return self.execute_command(cmd, obey_checkmode=False)
def get_ssh_public_key(self):
ssh_public_key_file = '%s.pub' % self.get_ssh_key_path()
try:
f = open(ssh_public_key_file)
ssh_public_key = f.read().strip()
f.close()
except IOError:
return None
return ssh_public_key
def create_user(self):
# by default we use the create_user_useradd method
return self.create_user_useradd()
def remove_user(self):
# by default we use the remove_user_userdel method
return self.remove_user_userdel()
def modify_user(self):
# by default we use the modify_user_usermod method
return self.modify_user_usermod()
def create_homedir(self, path):
if not os.path.exists(path):
if self.skeleton is not None:
skeleton = self.skeleton
else:
skeleton = '/etc/skel'
if os.path.exists(skeleton):
try:
shutil.copytree(skeleton, path, symlinks=True)
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
else:
try:
os.makedirs(path)
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
def chown_homedir(self, uid, gid, path):
try:
os.chown(path, uid, gid)
for root, dirs, files in os.walk(path):
for d in dirs:
os.chown(path, uid, gid)
for f in files:
os.chown(os.path.join(root, f), uid, gid)
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
# ===========================================
class FreeBsdUser(User):
"""
This is a FreeBSD User manipulation class - it uses the pw command
to manipulate the user database, followed by the chpass command
to change the password.
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'FreeBSD'
distribution = None
SHADOWFILE = '/etc/master.passwd'
def remove_user(self):
cmd = [
self.module.get_bin_path('pw', True),
'userdel',
'-n',
self.name
]
if self.remove:
cmd.append('-r')
return self.execute_command(cmd)
def create_user(self):
cmd = [
self.module.get_bin_path('pw', True),
'useradd',
'-n',
self.name,
]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
cmd.append('-L')
cmd.append(self.login_class)
if self.expires:
days =( time.mktime(self.expires) - time.time() ) / 86400
cmd.append('-e')
cmd.append(str(int(days)))
# system cannot be handled currently - should we error if its requested?
# create the user
(rc, out, err) = self.execute_command(cmd)
if rc is not None and rc != 0:
self.module.fail_json(name=self.name, msg=err, rc=rc)
# we have to set the password in a second command
if self.password is not None:
cmd = [
self.module.get_bin_path('chpass', True),
'-p',
self.password,
self.name
]
return self.execute_command(cmd)
return (rc, out, err)
def modify_user(self):
cmd = [
self.module.get_bin_path('pw', True),
'usermod',
'-n',
self.name
]
cmd_len = len(cmd)
info = self.user_info()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
if self.move_home:
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
# find current login class
user_login_class = None
if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK):
for line in open(self.SHADOWFILE).readlines():
if line.startswith('%s:' % self.name):
user_login_class = line.split(':')[4]
# act only if login_class change
if self.login_class != user_login_class:
cmd.append('-L')
cmd.append(self.login_class)
if self.groups is not None:
current_groups = self.user_group_membership()
groups = self.get_groups_set()
group_diff = set(current_groups).symmetric_difference(groups)
groups_need_mod = False
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
cmd.append('-G')
new_groups = groups
if self.append:
new_groups = groups | set(current_groups)
cmd.append(','.join(new_groups))
if self.expires:
days = ( time.mktime(self.expires) - time.time() ) / 86400
cmd.append('-e')
cmd.append(str(int(days)))
# modify the user if cmd will do anything
if cmd_len != len(cmd):
(rc, out, err) = self.execute_command(cmd)
if rc is not None and rc != 0:
self.module.fail_json(name=self.name, msg=err, rc=rc)
else:
(rc, out, err) = (None, '', '')
# we have to set the password in a second command
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
cmd = [
self.module.get_bin_path('chpass', True),
'-p',
self.password,
self.name
]
return self.execute_command(cmd)
return (rc, out, err)
# ===========================================
class OpenBSDUser(User):
"""
This is a OpenBSD User manipulation class.
Main differences are that OpenBSD:-
- has no concept of "system" account.
- has no force delete user
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'OpenBSD'
distribution = None
SHADOWFILE = '/etc/master.passwd'
def create_user(self):
cmd = [self.module.get_bin_path('useradd', True)]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
cmd.append('-L')
cmd.append(self.login_class)
if self.password is not None and self.password != '*':
cmd.append('-p')
cmd.append(self.password)
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name)
return self.execute_command(cmd)
def remove_user_userdel(self):
cmd = [self.module.get_bin_path('userdel', True)]
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def modify_user(self):
cmd = [self.module.get_bin_path('usermod', True)]
info = self.user_info()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
current_groups = self.user_group_membership()
groups_need_mod = False
groups_option = '-G'
groups = []
if self.groups == '':
if current_groups and not self.append:
groups_need_mod = True
else:
groups = self.get_groups_set()
group_diff = set(current_groups).symmetric_difference(groups)
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
groups_option = '-S'
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
cmd.append(groups_option)
cmd.append(','.join(groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
if self.move_home:
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
# find current login class
user_login_class = None
userinfo_cmd = [self.module.get_bin_path('userinfo', True), self.name]
(rc, out, err) = self.execute_command(userinfo_cmd, obey_checkmode=False)
for line in out.splitlines():
tokens = line.split()
if tokens[0] == 'class' and len(tokens) == 2:
user_login_class = tokens[1]
# act only if login_class change
if self.login_class != user_login_class:
cmd.append('-L')
cmd.append(self.login_class)
if self.update_password == 'always' and self.password is not None \
and self.password != '*' and info[1] != self.password:
cmd.append('-p')
cmd.append(self.password)
# skip if no changes to be made
if len(cmd) == 1:
return (None, '', '')
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
class NetBSDUser(User):
"""
This is a NetBSD User manipulation class.
Main differences are that NetBSD:-
- has no concept of "system" account.
- has no force delete user
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'NetBSD'
distribution = None
SHADOWFILE = '/etc/master.passwd'
def create_user(self):
cmd = [self.module.get_bin_path('useradd', True)]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
groups = self.get_groups_set()
if len(groups) > 16:
self.module.fail_json(msg="Too many groups (%d) NetBSD allows for 16 max." % len(groups))
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
cmd.append('-L')
cmd.append(self.login_class)
if self.password is not None:
cmd.append('-p')
cmd.append(self.password)
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name)
return self.execute_command(cmd)
def remove_user_userdel(self):
cmd = [self.module.get_bin_path('userdel', True)]
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def modify_user(self):
cmd = [self.module.get_bin_path('usermod', True)]
info = self.user_info()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
current_groups = self.user_group_membership()
groups_need_mod = False
groups = []
if self.groups == '':
if current_groups and not self.append:
groups_need_mod = True
else:
groups = self.get_groups_set()
group_diff = set(current_groups).symmetric_difference(groups)
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
groups = set(current_groups).union(groups)
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
if len(groups) > 16:
self.module.fail_json(msg="Too many groups (%d) NetBSD allows for 16 max." % len(groups))
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
if self.move_home:
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
if self.login_class is not None:
cmd.append('-L')
cmd.append(self.login_class)
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
cmd.append('-p')
cmd.append(self.password)
# skip if no changes to be made
if len(cmd) == 1:
return (None, '', '')
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
class SunOS(User):
"""
This is a SunOS User manipulation class - The main difference between
this class and the generic user class is that Solaris-type distros
don't support the concept of a "system" account and we need to
edit the /etc/shadow file manually to set a password. (Ugh)
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'SunOS'
distribution = None
SHADOWFILE = '/etc/shadow'
def get_password_defaults(self):
# Read password aging defaults
try:
minweeks = ''
maxweeks = ''
warnweeks = ''
for line in open("/etc/default/passwd", 'r'):
line = line.strip()
if (line.startswith('#') or line == ''):
continue
key, value = line.split('=')
if key == "MINWEEKS":
minweeks = value.rstrip('\n')
elif key == "MAXWEEKS":
maxweeks = value.rstrip('\n')
elif key == "WARNWEEKS":
warnweeks = value.rstrip('\n')
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to read /etc/default/passwd: %s" % str(err))
return (minweeks, maxweeks, warnweeks)
def remove_user(self):
cmd = [self.module.get_bin_path('userdel', True)]
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def create_user(self):
cmd = [self.module.get_bin_path('useradd', True)]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd)
if rc is not None and rc != 0:
self.module.fail_json(name=self.name, msg=err, rc=rc)
if not self.module.check_mode:
# we have to set the password by editing the /etc/shadow file
if self.password is not None:
minweeks, maxweeks, warnweeks = self.get_password_defaults()
try:
lines = []
for line in open(self.SHADOWFILE, 'rb').readlines():
fields = line.strip().split(':')
if not fields[0] == self.name:
lines.append(line)
continue
fields[1] = self.password
fields[2] = str(int(time.time() / 86400))
if minweeks:
fields[3] = str(int(minweeks) * 7)
if maxweeks:
fields[4] = str(int(maxweeks) * 7)
if warnweeks:
fields[5] = str(int(warnweeks) * 7)
line = ':'.join(fields)
lines.append('%s\n' % line)
open(self.SHADOWFILE, 'w+').writelines(lines)
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update users password: %s" % str(err))
return (rc, out, err)
def modify_user_usermod(self):
cmd = [self.module.get_bin_path('usermod', True)]
cmd_len = len(cmd)
info = self.user_info()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
current_groups = self.user_group_membership()
groups = self.get_groups_set()
group_diff = set(current_groups).symmetric_difference(groups)
groups_need_mod = False
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
cmd.append('-G')
new_groups = groups
if self.append:
new_groups.update(current_groups)
cmd.append(','.join(new_groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
if self.move_home:
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
# modify the user if cmd will do anything
if cmd_len != len(cmd):
cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd)
if rc is not None and rc != 0:
self.module.fail_json(name=self.name, msg=err, rc=rc)
else:
(rc, out, err) = (None, '', '')
# we have to set the password by editing the /etc/shadow file
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
(rc, out, err) = (0, '', '')
if not self.module.check_mode:
minweeks, maxweeks, warnweeks = self.get_password_defaults()
try:
lines = []
for line in open(self.SHADOWFILE, 'rb').readlines():
fields = line.strip().split(':')
if not fields[0] == self.name:
lines.append(line)
continue
fields[1] = self.password
fields[2] = str(int(time.time() / 86400))
if minweeks:
fields[3] = str(int(minweeks) * 7)
if maxweeks:
fields[4] = str(int(maxweeks) * 7)
if warnweeks:
fields[5] = str(int(warnweeks) * 7)
line = ':'.join(fields)
lines.append('%s\n' % line)
open(self.SHADOWFILE, 'w+').writelines(lines)
rc = 0
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update users password: %s" % str(err))
return (rc, out, err)
# ===========================================
class DarwinUser(User):
"""
This is a Darwin Mac OS X User manipulation class.
Main differences are that Darwin:-
- Handles accounts in a database managed by dscl(1)
- Has no useradd/groupadd
- Does not create home directories
- User password must be cleartext
- UID must be given
- System users must ben under 500
This overrides the following methods from the generic class:-
- user_exists()
- create_user()
- remove_user()
- modify_user()
"""
platform = 'Darwin'
distribution = None
SHADOWFILE = None
dscl_directory = '.'
fields = [
('comment', 'RealName'),
('home', 'NFSHomeDirectory'),
('shell', 'UserShell'),
('uid', 'UniqueID'),
('group', 'PrimaryGroupID'),
]
def _get_dscl(self):
return [ self.module.get_bin_path('dscl', True), self.dscl_directory ]
def _list_user_groups(self):
cmd = self._get_dscl()
cmd += [ '-search', '/Groups', 'GroupMembership', self.name ]
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
groups = []
for line in out.splitlines():
if line.startswith(' ') or line.startswith(')'):
continue
groups.append(line.split()[0])
return groups
def _get_user_property(self, property):
'''Return user PROPERTY as given my dscl(1) read or None if not found.'''
cmd = self._get_dscl()
cmd += [ '-read', '/Users/%s' % self.name, property ]
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
if rc != 0:
return None
# from dscl(1)
# if property contains embedded spaces, the list will instead be
# displayed one entry per line, starting on the line after the key.
lines = out.splitlines()
#sys.stderr.write('*** |%s| %s -> %s\n' % (property, out, lines))
if len(lines) == 1:
return lines[0].split(': ')[1]
else:
if len(lines) > 2:
return '\n'.join([ lines[1].strip() ] + lines[2:])
else:
if len(lines) == 2:
return lines[1].strip()
else:
return None
def _get_next_uid(self, system=None):
'''
Return the next available uid. If system=True, then
uid should be below of 500, if possible.
'''
cmd = self._get_dscl()
cmd += ['-list', '/Users', 'UniqueID']
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
if rc != 0:
self.module.fail_json(
msg="Unable to get the next available uid",
rc=rc,
out=out,
err=err
)
max_uid = 0
max_system_uid = 0
for line in out.splitlines():
current_uid = int(line.split(' ')[-1])
if max_uid < current_uid:
max_uid = current_uid
if max_system_uid < current_uid and current_uid < 500:
max_system_uid = current_uid
if system and (0 < max_system_uid < 499):
return max_system_uid + 1
return max_uid + 1
def _change_user_password(self):
'''Change password for SELF.NAME against SELF.PASSWORD.
Please note that password must be cleartext.
'''
# some documentation on how is stored passwords on OSX:
# http://blog.lostpassword.com/2012/07/cracking-mac-os-x-lion-accounts-passwords/
# http://null-byte.wonderhowto.com/how-to/hack-mac-os-x-lion-passwords-0130036/
# http://pastebin.com/RYqxi7Ca
# on OSX 10.8+ hash is SALTED-SHA512-PBKDF2
# https://pythonhosted.org/passlib/lib/passlib.hash.pbkdf2_digest.html
# https://gist.github.com/nueh/8252572
cmd = self._get_dscl()
if self.password:
cmd += [ '-passwd', '/Users/%s' % self.name, self.password]
else:
cmd += [ '-create', '/Users/%s' % self.name, 'Password', '*']
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json(msg='Error when changing password', err=err, out=out, rc=rc)
return (rc, out, err)
def _make_group_numerical(self):
'''Convert SELF.GROUP to is stringed numerical value suitable for dscl.'''
if self.group is None:
self.group = 'nogroup'
try:
self.group = grp.getgrnam(self.group).gr_gid
except KeyError:
self.module.fail_json(msg='Group "%s" not found. Try to create it first using "group" module.' % self.group)
# We need to pass a string to dscl
self.group = str(self.group)
def __modify_group(self, group, action):
'''Add or remove SELF.NAME to or from GROUP depending on ACTION.
ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. '''
if action == 'add':
option = '-a'
else:
option = '-d'
cmd = [ 'dseditgroup', '-o', 'edit', option, self.name, '-t', 'user', group ]
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json(msg='Cannot %s user "%s" to group "%s".'
% (action, self.name, group), err=err, out=out, rc=rc)
return (rc, out, err)
def _modify_group(self):
'''Add or remove SELF.NAME to or from GROUP depending on ACTION.
ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. '''
rc = 0
out = ''
err = ''
changed = False
current = set(self._list_user_groups())
if self.groups is not None:
target = set(self.groups.split(','))
else:
target = set([])
if self.append is False:
for remove in current - target:
(_rc, _err, _out) = self.__modify_group(remove, 'delete')
rc += rc
out += _out
err += _err
changed = True
for add in target - current:
(_rc, _err, _out) = self.__modify_group(add, 'add')
rc += _rc
out += _out
err += _err
changed = True
return (rc, err, out, changed)
def _update_system_user(self):
'''Hide or show user on login window according SELF.SYSTEM.
Returns 0 if a change has been made, None otherwhise.'''
plist_file = '/Library/Preferences/com.apple.loginwindow.plist'
# http://support.apple.com/kb/HT5017?viewlocale=en_US
cmd = [ 'defaults', 'read', plist_file, 'HiddenUsersList' ]
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
# returned value is
# (
# "_userA",
# "_UserB",
# userc
# )
hidden_users = []
for x in out.splitlines()[1:-1]:
try:
x = x.split('"')[1]
except IndexError:
x = x.strip()
hidden_users.append(x)
if self.system:
if not self.name in hidden_users:
cmd = [ 'defaults', 'write', plist_file,
'HiddenUsersList', '-array-add', self.name ]
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json( msg='Cannot user "%s" to hidden user list.' % self.name, err=err, out=out, rc=rc)
return 0
else:
if self.name in hidden_users:
del(hidden_users[hidden_users.index(self.name)])
cmd = [ 'defaults', 'write', plist_file, 'HiddenUsersList', '-array' ] + hidden_users
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json( msg='Cannot remove user "%s" from hidden user list.' % self.name, err=err, out=out, rc=rc)
return 0
def user_exists(self):
'''Check is SELF.NAME is a known user on the system.'''
cmd = self._get_dscl()
cmd += [ '-list', '/Users/%s' % self.name]
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
return rc == 0
def remove_user(self):
'''Delete SELF.NAME. If SELF.FORCE is true, remove its home directory.'''
info = self.user_info()
cmd = self._get_dscl()
cmd += [ '-delete', '/Users/%s' % self.name]
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json( msg='Cannot delete user "%s".' % self.name, err=err, out=out, rc=rc)
if self.force:
if os.path.exists(info[5]):
shutil.rmtree(info[5])
out += "Removed %s" % info[5]
return (rc, out, err)
def create_user(self, command_name='dscl'):
cmd = self._get_dscl()
cmd += [ '-create', '/Users/%s' % self.name]
(rc, err, out) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json( msg='Cannot create user "%s".' % self.name, err=err, out=out, rc=rc)
self._make_group_numerical()
if self.uid is None:
self.uid = str(self._get_next_uid(self.system))
# Homedir is not created by default
if self.createhome:
if self.home is None:
self.home = '/Users/%s' % self.name
if not self.module.check_mode:
if not os.path.exists(self.home):
os.makedirs(self.home)
self.chown_homedir(int(self.uid), int(self.group), self.home)
for field in self.fields:
if field[0] in self.__dict__ and self.__dict__[field[0]]:
cmd = self._get_dscl()
cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
(rc, _err, _out) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json( msg='Cannot add property "%s" to user "%s".'
% (field[0], self.name), err=err, out=out, rc=rc)
out += _out
err += _err
if rc != 0:
return (rc, _err, _out)
(rc, _err, _out) = self._change_user_password()
out += _out
err += _err
self._update_system_user()
# here we don't care about change status since it is a creation,
# thus changed is always true.
if self.groups:
(rc, _out, _err, changed) = self._modify_group()
out += _out
err += _err
return (rc, err, out)
def modify_user(self):
changed = None
out = ''
err = ''
if self.group:
self._make_group_numerical()
for field in self.fields:
if field[0] in self.__dict__ and self.__dict__[field[0]]:
current = self._get_user_property(field[1])
if current is None or current != self.__dict__[field[0]]:
cmd = self._get_dscl()
cmd += [ '-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
(rc, _err, _out) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json(
msg='Cannot update property "%s" for user "%s".'
% (field[0], self.name), err=err, out=out, rc=rc)
changed = rc
out += _out
err += _err
if self.update_password == 'always' and self.password is not None:
(rc, _err, _out) = self._change_user_password()
out += _out
err += _err
changed = rc
if self.groups:
(rc, _out, _err, _changed) = self._modify_group()
out += _out
err += _err
if _changed is True:
changed = rc
rc = self._update_system_user()
if rc == 0:
changed = rc
return (changed, out, err)
# ===========================================
class AIX(User):
"""
This is a AIX User manipulation class.
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'AIX'
distribution = None
SHADOWFILE = '/etc/security/passwd'
def remove_user(self):
cmd = [self.module.get_bin_path('userdel', True)]
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def create_user_useradd(self, command_name='useradd'):
cmd = [self.module.get_bin_path(command_name, True)]
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None and len(self.groups):
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.createhome:
cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd)
# set password with chpasswd
if self.password is not None:
cmd = []
cmd.append(self.module.get_bin_path('chpasswd', True))
cmd.append('-e')
cmd.append('-c')
self.execute_command(' '.join(cmd), data="%s:%s" % (self.name, self.password))
return (rc, out, err)
def modify_user_usermod(self):
cmd = [self.module.get_bin_path('usermod', True)]
info = self.user_info()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
current_groups = self.user_group_membership()
groups_need_mod = False
groups = []
if self.groups == '':
if current_groups and not self.append:
groups_need_mod = True
else:
groups = self.get_groups_set()
group_diff = set(current_groups).symmetric_difference(groups)
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
if self.move_home:
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
# skip if no changes to be made
if len(cmd) == 1:
(rc, out, err) = (None, '', '')
else:
cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd)
# set password with chpasswd
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
cmd = []
cmd.append(self.module.get_bin_path('chpasswd', True))
cmd.append('-e')
cmd.append('-c')
(rc2, out2, err2) = self.execute_command(' '.join(cmd), data="%s:%s" % (self.name, self.password))
else:
(rc2, out2, err2) = (None, '', '')
if rc is not None:
return (rc, out+out2, err+err2)
else:
return (rc2, out+out2, err+err2)
# ===========================================
class HPUX(User):
"""
This is a HP-UX User manipulation class.
This overrides the following methods from the generic class:-
- create_user()
- remove_user()
- modify_user()
"""
platform = 'HP-UX'
distribution = None
SHADOWFILE = '/etc/shadow'
def create_user(self):
cmd = ['/usr/sam/lbin/useradd.sam']
if self.uid is not None:
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None and len(self.groups):
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None:
cmd.append('-d')
cmd.append(self.home)
if self.shell is not None:
cmd.append('-s')
cmd.append(self.shell)
if self.password is not None:
cmd.append('-p')
cmd.append(self.password)
if self.createhome:
cmd.append('-m')
else:
cmd.append('-M')
if self.system:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def remove_user(self):
cmd = ['/usr/sam/lbin/userdel.sam']
if self.force:
cmd.append('-F')
if self.remove:
cmd.append('-r')
cmd.append(self.name)
return self.execute_command(cmd)
def modify_user(self):
cmd = ['/usr/sam/lbin/usermod.sam']
info = self.user_info()
has_append = self._check_usermod_append()
if self.uid is not None and info[2] != int(self.uid):
cmd.append('-u')
cmd.append(self.uid)
if self.non_unique:
cmd.append('-o')
if self.group is not None:
if not self.group_exists(self.group):
self.module.fail_json(msg="Group %s does not exist" % self.group)
ginfo = self.group_info(self.group)
if info[3] != ginfo[2]:
cmd.append('-g')
cmd.append(self.group)
if self.groups is not None:
current_groups = self.user_group_membership()
groups_need_mod = False
groups = []
if self.groups == '':
if current_groups and not self.append:
groups_need_mod = True
else:
groups = self.get_groups_set(remove_existing=False)
group_diff = set(current_groups).symmetric_difference(groups)
if group_diff:
if self.append:
for g in groups:
if g in group_diff:
if has_append:
cmd.append('-a')
groups_need_mod = True
break
else:
groups_need_mod = True
if groups_need_mod:
if self.append and not has_append:
cmd.append('-A')
cmd.append(','.join(group_diff))
else:
cmd.append('-G')
cmd.append(','.join(groups))
if self.comment is not None and info[4] != self.comment:
cmd.append('-c')
cmd.append(self.comment)
if self.home is not None and info[5] != self.home:
cmd.append('-d')
cmd.append(self.home)
if self.move_home:
cmd.append('-m')
if self.shell is not None and info[6] != self.shell:
cmd.append('-s')
cmd.append(self.shell)
if self.update_password == 'always' and self.password is not None and info[1] != self.password:
cmd.append('-p')
cmd.append(self.password)
# skip if no changes to be made
if len(cmd) == 1:
return (None, '', '')
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
def main():
ssh_defaults = {
'bits': 0,
'type': 'rsa',
'passphrase': None,
'comment': 'ansible-generated on %s' % socket.gethostname()
}
module = AnsibleModule(
argument_spec = dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(required=True, aliases=['user'], type='str'),
uid=dict(default=None, type='str'),
non_unique=dict(default='no', type='bool'),
group=dict(default=None, type='str'),
groups=dict(default=None, type='list'),
comment=dict(default=None, type='str'),
home=dict(default=None, type='path'),
shell=dict(default=None, type='str'),
password=dict(default=None, type='str', no_log=True),
login_class=dict(default=None, type='str'),
# following options are specific to selinux
seuser=dict(default=None, type='str'),
# following options are specific to userdel
force=dict(default='no', type='bool'),
remove=dict(default='no', type='bool'),
# following options are specific to useradd
createhome=dict(default='yes', type='bool'),
skeleton=dict(default=None, type='str'),
system=dict(default='no', type='bool'),
# following options are specific to usermod
move_home=dict(default='no', type='bool'),
append=dict(default='no', type='bool'),
# following are specific to ssh key generation
generate_ssh_key=dict(type='bool'),
ssh_key_bits=dict(default=ssh_defaults['bits'], type='int'),
ssh_key_type=dict(default=ssh_defaults['type'], type='str'),
ssh_key_file=dict(default=None, type='path'),
ssh_key_comment=dict(default=ssh_defaults['comment'], type='str'),
ssh_key_passphrase=dict(default=None, type='str', no_log=True),
update_password=dict(default='always',choices=['always','on_create'],type='str'),
expires=dict(default=None, type='float'),
),
supports_check_mode=True
)
user = User(module)
module.debug('User instantiated - platform %s' % user.platform)
if user.distribution:
module.debug('User instantiated - distribution %s' % user.distribution)
rc = None
out = ''
err = ''
result = {}
result['name'] = user.name
result['state'] = user.state
if user.state == 'absent':
if user.user_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = user.remove_user()
if rc != 0:
module.fail_json(name=user.name, msg=err, rc=rc)
result['force'] = user.force
result['remove'] = user.remove
elif user.state == 'present':
if not user.user_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = user.create_user()
if module.check_mode:
result['system'] = user.name
else:
result['system'] = user.system
result['createhome'] = user.createhome
else:
# modify user (note: this function is check mode aware)
(rc, out, err) = user.modify_user()
result['append'] = user.append
result['move_home'] = user.move_home
if rc is not None and rc != 0:
module.fail_json(name=user.name, msg=err, rc=rc)
if user.password is not None:
result['password'] = 'NOT_LOGGING_PASSWORD'
if rc is None:
result['changed'] = False
else:
result['changed'] = True
if out:
result['stdout'] = out
if err:
result['stderr'] = err
if user.user_exists():
info = user.user_info()
if info is False:
result['msg'] = "failed to look up user name: %s" % user.name
result['failed'] = True
result['uid'] = info[2]
result['group'] = info[3]
result['comment'] = info[4]
result['home'] = info[5]
result['shell'] = info[6]
result['uid'] = info[2]
if user.groups is not None:
result['groups'] = user.groups
# handle missing homedirs
info = user.user_info()
if user.home is None:
user.home = info[5]
if not os.path.exists(user.home) and user.createhome:
if not module.check_mode:
user.create_homedir(user.home)
user.chown_homedir(info[2], info[3], user.home)
result['changed'] = True
# deal with ssh key
if user.sshkeygen:
# generate ssh key (note: this function is check mode aware)
(rc, out, err) = user.ssh_key_gen()
if rc is not None and rc != 0:
module.fail_json(name=user.name, msg=err, rc=rc)
if rc == 0:
result['changed'] = True
(rc, out, err) = user.ssh_key_fingerprint()
if rc == 0:
result['ssh_fingerprint'] = out.strip()
else:
result['ssh_fingerprint'] = err.strip()
result['ssh_key_file'] = user.get_ssh_key_path()
result['ssh_public_key'] = user.get_ssh_public_key()
module.exit_json(**result)
# import module snippets
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
922,
199,
2502,
26,
298,
26696,
17579,
11606,
77,
8593,
83,
504,
77,
2924,
199,
1023,
63,
3270,
26,
298,
16,
14,
18,
2,
199,
3612,
63,
1802,
26,
14944,
922,
12639,
199,
5983,
26,
523,
446,
6006,
787,
2488,
9760,
1126,
4298,
641,
922,
10041,
15841,
14,
9738,
272,
2985,
16711,
11492,
876,
13,
7657,
543,
314,
2656,
436,
2622,
911,
4409,
2985,
272,
787,
3451,
737,
8836,
14,
982,
2985,
787,
440,
12,
282,
30262,
1125,
1245,
911,
506,
9164,
14,
199,
1802,
26,
272,
446,
14944,
922,
12639,
436,
922,
3004,
14,
199,
1419,
26,
272,
536,
26,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
751,
2,
1622,
267,
1369,
26,
288,
446,
2812,
402,
314,
922,
370,
1218,
12,
2813,
503,
2811,
14,
272,
3721,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
1369,
334,
24685,
473,
8,
4962,
1439,
51,
430,
402,
922,
2933,
14,
272,
1747,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
473,
8,
6685,
9,
402,
314,
922,
14,
272,
2222,
63,
3235,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
22383,
1380,
1202,
543,
314,
446,
85,
945,
12,
642,
945,
6127,
370,
1598,
1570,
314,
922,
2870,
370,
282,
2222,
13,
3235,
574,
14,
267,
1015,
63,
3270,
26,
298,
17,
14,
17,
2,
272,
542,
751,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
542,
751,
730,
334,
751,
63,
85,
9,
641,
542,
5135,
5223,
10460,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
1572,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
922,
1159,
5062,
1572,
334,
31613,
282,
1572,
536,
680,
272,
4652,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
510,
14608,
314,
922,
315,
221,
769,
402,
4652,
14,
3979,
663,
370,
314,
2701,
1059,
661,
2634,
29,
659,
1598,
314,
922,
365,
4829,
687,
1006,
4652,
871,
314,
5062,
1572,
14,
288,
446,
21467,
1015,
499,
14,
19,
12,
314,
1454,
1324,
1475,
4370,
1990,
282,
283,
13184,
11673,
1059,
297,
1598,
3063,
652,
1077,
506,
7688,
370,
4729,
18916,
5548,
2597,
14,
272,
5666,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
982,
445,
8,
5066,
395,
911,
1454,
1050,
4652,
12,
440,
663,
3062,
370,
2951,
314,
769,
1598,
315,
473,
8,
2634,
680,
272,
5218,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
5218,
14,
272,
5629,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
5629,
2082,
14,
272,
30537,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
282,
5629,
30537,
2082,
14,
15127,
1218,
4219,
945,
1,
267,
1015,
63,
3270,
26,
298,
18,
14,
16,
2,
272,
2505,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
2505,
370,
642,
286,
651,
4979,
574,
14,
221,
1666,
1598,
314,
922,
2893,
315,
314,
12869,
7251,
2082,
367,
4052,
642,
10734,
1598,
2839,
315,
282,
15695,
14,
1666,
738,
8,
1014,
921,
4757,
14,
4853,
14,
957,
15,
4853,
15,
667,
81,
14,
1360,
3,
1917,
13,
1117,
13,
73,
13,
4208,
13,
8274,
13,
28608,
13,
509,
13,
1589,
13,
751,
13,
578,
9,
1598,
367,
2436,
641,
7750,
15217,
370,
3550,
3520,
2505,
1338,
14,
1598,
3390,
641,
577,
22822,
2656,
12,
642,
574,
965,
370,
506,
5436,
505,
14,
1598,
699,
546,
1530,
402,
6391,
10876,
14,
272,
1174,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
3451,
12,
9552,
1622,
267,
1369,
26,
288,
446,
7480,
314,
2933,
1077,
2187,
503,
440,
12,
16466,
1595,
340,
314,
1174,
365,
3365,
687,
4052,
365,
410,
972,
14,
272,
1218,
4219,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
5066,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
4158,
663,
370,
445,
8,
889,
395,
282,
5629,
2082,
911,
506,
6326,
367,
314,
922,
1598,
1380,
314,
2933,
365,
2737,
503,
340,
314,
5629,
2082,
1630,
440,
1598,
2187,
14,
272,
4057,
63,
4219,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
982,
663,
370,
445,
8,
5066,
9,
1380,
1202,
543,
445,
8,
4219,
29,
395
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
922,
199,
2502,
26,
298,
26696,
17579,
11606,
77,
8593,
83,
504,
77,
2924,
199,
1023,
63,
3270,
26,
298,
16,
14,
18,
2,
199,
3612,
63,
1802,
26,
14944,
922,
12639,
199,
5983,
26,
523,
446,
6006,
787,
2488,
9760,
1126,
4298,
641,
922,
10041,
15841,
14,
9738,
272,
2985,
16711,
11492,
876,
13,
7657,
543,
314,
2656,
436,
2622,
911,
4409,
2985,
272,
787,
3451,
737,
8836,
14,
982,
2985,
787,
440,
12,
282,
30262,
1125,
1245,
911,
506,
9164,
14,
199,
1802,
26,
272,
446,
14944,
922,
12639,
436,
922,
3004,
14,
199,
1419,
26,
272,
536,
26,
267,
1415,
26,
2549,
267,
5481,
26,
359,
298,
751,
2,
1622,
267,
1369,
26,
288,
446,
2812,
402,
314,
922,
370,
1218,
12,
2813,
503,
2811,
14,
272,
3721,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
1369,
334,
24685,
473,
8,
4962,
1439,
51,
430,
402,
922,
2933,
14,
272,
1747,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
473,
8,
6685,
9,
402,
314,
922,
14,
272,
2222,
63,
3235,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
22383,
1380,
1202,
543,
314,
446,
85,
945,
12,
642,
945,
6127,
370,
1598,
1570,
314,
922,
2870,
370,
282,
2222,
13,
3235,
574,
14,
267,
1015,
63,
3270,
26,
298,
17,
14,
17,
2,
272,
542,
751,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
542,
751,
730,
334,
751,
63,
85,
9,
641,
542,
5135,
5223,
10460,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
1572,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
5951,
314,
922,
1159,
5062,
1572,
334,
31613,
282,
1572,
536,
680,
272,
4652,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
510,
14608,
314,
922,
315,
221,
769,
402,
4652,
14,
3979,
663,
370,
314,
2701,
1059,
661,
2634,
29,
659,
1598,
314,
922,
365,
4829,
687,
1006,
4652,
871,
314,
5062,
1572,
14,
288,
446,
21467,
1015,
499,
14,
19,
12,
314,
1454,
1324,
1475,
4370,
1990,
282,
283,
13184,
11673,
1059,
297,
1598,
3063,
652,
1077,
506,
7688,
370,
4729,
18916,
5548,
2597,
14,
272,
5666,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
982,
445,
8,
5066,
395,
911,
1454,
1050,
4652,
12,
440,
663,
3062,
370,
2951,
314,
769,
1598,
315,
473,
8,
2634,
680,
272,
5218,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
5218,
14,
272,
5629,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
5629,
2082,
14,
272,
30537,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
282,
5629,
30537,
2082,
14,
15127,
1218,
4219,
945,
1,
267,
1015,
63,
3270,
26,
298,
18,
14,
16,
2,
272,
2505,
26,
267,
1415,
26,
3055,
267,
1369,
26,
288,
446,
22383,
663,
314,
922,
1159,
2505,
370,
642,
286,
651,
4979,
574,
14,
221,
1666,
1598,
314,
922,
2893,
315,
314,
12869,
7251,
2082,
367,
4052,
642,
10734,
1598,
2839,
315,
282,
15695,
14,
1666,
738,
8,
1014,
921,
4757,
14,
4853,
14,
957,
15,
4853,
15,
667,
81,
14,
1360,
3,
1917,
13,
1117,
13,
73,
13,
4208,
13,
8274,
13,
28608,
13,
509,
13,
1589,
13,
751,
13,
578,
9,
1598,
367,
2436,
641,
7750,
15217,
370,
3550,
3520,
2505,
1338,
14,
1598,
3390,
641,
577,
22822,
2656,
12,
642,
574,
965,
370,
506,
5436,
505,
14,
1598,
699,
546,
1530,
402,
6391,
10876,
14,
272,
1174,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
3451,
12,
9552,
1622,
267,
1369,
26,
288,
446,
7480,
314,
2933,
1077,
2187,
503,
440,
12,
16466,
1595,
340,
314,
1174,
365,
3365,
687,
4052,
365,
410,
972,
14,
272,
1218,
4219,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
5066,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
4158,
663,
370,
445,
8,
889,
395,
282,
5629,
2082,
911,
506,
6326,
367,
314,
922,
1598,
1380,
314,
2933,
365,
2737,
503,
340,
314,
5629,
2082,
1630,
440,
1598,
2187,
14,
272,
4057,
63,
4219,
26,
267,
1415,
26,
3055,
267,
849,
26,
298,
889,
2,
267,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
267,
1369,
26,
288,
446,
982,
663,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bchappet/dnfpy
|
src/dnfpyUtils/stats/clusterMap.py
|
1
|
7473
|
from dnfpy.core.map2D import Map2D
import numpy as np
from sklearn.cluster import DBSCAN
import scipy.spatial.distance as dist
from dnfpyUtils.stats.statistic import Statistic
class ClusterMap(Statistic):
"""
Params:
"continuity" : float if different of 0.0, we assume that the cluster are continuous
A continuous cluster allow a loss of activity during continuity seconds.
Otherwise, the cluster is deleted
We add the last cluster in the current coords
Then we deduce what label labels the new cluster
The first iteration determines the labels for the next ones
"threshold" : threshold for activity value to be considered
"min_sample" : how many activation are enough to be considered as a cluster
"clustSize" : in [0,1] max size of the expected cluster
"expectedNumberOfCluster" : as its name suggest. We will not compute anything if
the number of activation is higher than
(np.pi*(clustSize_/2.0)**2)*expectedNumberOfCluster
where clustSize_ is the actual clustSize = clustSize*size
Results:
_data = np array (nb_clust*2) with cluster barycenter coords X,Y:
1,2
3,5
3.8,3.4
"nbOutliners" : int nb outliners found at the last compute
if continuity > 0
"nbNewCluster": int nb of newly build cluster
"""
def __init__(self,name,size=0,dt=0.1,threshold=0.4,min_samples=3,
clustSize=0.15,sizeNpArr=1,continuity=1.0,expectedNumberOfCluster=1,
**kwargs):
super(ClusterMap,self).__init__(name=name,size=size,dt=dt,threshold=threshold,
clustSize=clustSize,min_samples=min_samples,sizeNpArr=sizeNpArr,
continuity=continuity,expectedNumberOfCluster=expectedNumberOfCluster,
**kwargs)
self.trace = []
def getTrace(self):
return self.trace
def reset(self):
super().reset()
self.clusters = []#cluster coords saved
#if continuity > 0, the cluster shoul not be off for more than continuity seconds
self.clusterOff = [] #we save the number of iteration that the cluster is off in this list
self.setArg(nbOutliners=0)
self.setArg(nbNewCluster=0)
self.setArg(nbComputationEmpty=0)
self.sumNbClusterSave = []
self.setArg(nbClusterSum=0)
self.setArg(maxNbAct=0)
self.nbActList = []
self.nbActivation = 0
self.diffNbClusterSum = 0 #add |nbClust - expectedNumberOfCluster| at every step
self._data = []
self.trace = []
self.dictOutCluster = {} #dict cluster -> output cluster
self.outputCluster = []
def _compute(self,size,np_arr,threshold,min_samples,clustSize_,continuity,expectedNumberOfCluster,dt,dim):
self.toProf(size,np_arr,threshold,min_samples,clustSize_,continuity,expectedNumberOfCluster,dt,dim)
def getMaxNbAct(self):
if len(self.nbActList) > 0:
return np.max(self.nbActList)
else:
return np.nan
def getMeanNbAct(self):
if len(self.nbActList) > 0:
return np.mean(self.nbActList)
else:
return np.nan
def toProf(self,size,np_arr,threshold,min_samples,clustSize_,continuity,
expectedNumberOfCluster,dt,dim):
maxArr = np.max(np_arr)
coords = np.where(np_arr > maxArr/1.2)
self.nbActivation = len(coords[0])
#print(self.nbActivation)
#if nbActivation > 0 and nbActivation < np_arr.shape[0]*1.6:
#print(expectedNumberOfCluster,clustSize_)
nbActMax = (np.pi*(clustSize_/2.0)**2)*expectedNumberOfCluster
if self.nbActivation < nbActMax and (self.nbActivation > 0 or (continuity > 0) and (len(self.clusters)>0)):
#print("nbActivation : %s"%self.nbActivation)
self.nbActList.append(self.nbActivation)
coordsArray = list(zip(coords[1],coords[0]))
if continuity > 0:
clusters = []
#we add the previous valid clusters to the coordArray : hence we 'll have the same label
for i in range(len(self._data)):
if not(np.any(np.isnan(self._data[i]))):
clust = {'id':i,'coord':self._data[i]}
coordsArray.insert(0,clust['coord'])
clusters.append(clust)
nbClust = len(clusters)
coordsArrayNp = np.array(coordsArray)
distanceMat = dist.cdist(coordsArrayNp,coordsArrayNp)
db = DBSCAN(min_samples=min_samples,eps=clustSize_).fit(distanceMat)
#set of labels (minus outliners)
unique_labels = set(db.labels_) - set([-1])
#print(db.labels_)
set_label = list(set(db.labels_))
#print(set_label)
clusterLabelList = []
for i in range(len(clusters)):
#lab = db.labels_[-1-i]
#print("index %s nb %s"%(-1-i,len(set_label)))
if i < len(set_label):
lab = db.labels_[i]#the labels are in the same ordre as the coordArray we added
else:
print("to few label!")
break
print("i : %s. label %s , sum %s"%(i,lab,np.sum(db.labels_==lab)))
clusters[i]['label'] = lab
clusterLabelList.append( lab)
#outliner are the labels which are -1 and not in the cluster list
nb_outliners = len(np.where(db.labels_ == -1)[0])
#update cluster positions
for cluster in clusters:
lab = cluster['label']
if lab != -1 :
cluster['coord'] = self.__getBarycenter(coordsArrayNp,db.labels_,lab)
else:
cluster['coord'] = np.array((np.nan,)*dim)
#check for new cluster
nbNewCluster = 0
for lab in set(set_label) -set(clusterLabelList):
barycenter = self.__getBarycenter(coordsArrayNp,db.labels_,lab)
#print("add cluster")
self._data.append(barycenter)
nbNewCluster += 1
#print("nb cluster ",len(self.clusters))
#print("nb clusterOff ",len(self.clusterOff))
self.setArg(nbNewCluster=nbNewCluster)
self.setArg(nbOutliners=nb_outliners)
for cluster in clusters:
self._data[cluster['id']] = cluster['coord']
print(self._data)
elif self.nbActivation == 0:
self.setArg(nbComputationEmpty=self.getArg("nbComputationEmpty")+1)
else:
#to many activation we don't compute cluster
self._data = np.array([np.array([-1,-1])])
self.trace.append(np.copy(self._data))
def __getBarycenter(self,coordsArrayNp,labels,lab):
coorBary = coordsArrayNp[np.where(labels == lab)]
barycenter = np.mean(coorBary,axis=0)
return barycenter
def _onParamsUpdate(self,clustSize,sizeNpArr):
clustSize_ = clustSize * sizeNpArr
return dict(clustSize_=clustSize_)
|
gpl-2.0
|
[
504,
28215,
647,
14,
1018,
14,
1130,
18,
36,
492,
9672,
18,
36,
199,
646,
2680,
465,
980,
199,
504,
6357,
14,
4201,
492,
6249,
24078,
199,
646,
7026,
14,
11679,
14,
5590,
465,
2917,
199,
504,
28215,
647,
7535,
14,
3200,
14,
26065,
492,
7083,
19940,
421,
199,
533,
16454,
2956,
8,
3391,
19940,
304,
272,
408,
272,
30370,
26,
272,
298,
12875,
24180,
2,
520,
2069,
340,
3365,
402,
378,
14,
16,
12,
781,
5534,
626,
314,
4350,
787,
19922,
267,
437,
19922,
4350,
2040,
282,
5621,
402,
10679,
5309,
9832,
24180,
4696,
14,
267,
6630,
12,
314,
4350,
365,
5463,
267,
2136,
1050,
314,
2061,
4350,
315,
314,
1453,
13259,
267,
9442,
781,
477,
3402,
4052,
1768,
3628,
314,
892,
4350,
267,
710,
1642,
8494,
16756,
314,
3628,
367,
314,
2163,
7869,
272,
298,
7227,
2,
520,
8765,
367,
10679,
574,
370,
506,
8652,
272,
298,
827,
63,
3271,
2,
520,
4212,
5002,
10361,
787,
8321,
370,
506,
8652,
465,
282,
4350,
272,
298,
429,
833,
2320,
2,
520,
315,
359,
16,
12,
17,
61,
1390,
1568,
402,
314,
1420,
4350,
272,
298,
2062,
16030,
9581,
2,
520,
465,
2399,
536,
18453,
14,
2136,
911,
440,
4526,
7003,
340,
272,
314,
1329,
402,
10361,
365,
10948,
2419,
267,
334,
1590,
14,
1038,
5830,
429,
833,
2320,
63,
15,
18,
14,
16,
6422,
18,
3342,
2062,
16030,
9581,
267,
2382,
824,
833,
2320,
63,
365,
314,
3503,
824,
833,
2320,
275,
824,
833,
2320,
10,
890,
2378,
24288,
26,
267,
485,
576,
275,
980,
1625,
334,
4994,
63,
429,
833,
10,
18,
9,
543,
4350,
330,
695,
4218,
13259,
1323,
12,
57,
26,
288,
413,
12,
18,
288,
650,
12,
21,
288,
650,
14,
24,
12,
19,
14,
20,
272,
298,
4994,
2204,
472,
1192,
2,
520,
1109,
8526,
734,
472,
1192,
1911,
737,
314,
2061,
4526,
272,
340,
9832,
24180,
690,
378,
272,
298,
4994,
4665,
9581,
582,
1109,
8526,
402,
13903,
1900,
4350,
339,
408,
272,
347,
636,
826,
721,
277,
12,
354,
12,
890,
29,
16,
12,
3583,
29,
16,
14,
17,
12,
7227,
29,
16,
14,
20,
12,
827,
63,
3356,
29,
19,
12,
326,
824,
833,
2320,
29,
16,
14,
1046,
12,
890,
46,
80,
22011,
29,
17,
12,
12875,
24180,
29,
17,
14,
16,
12,
2062,
16030,
9581,
29,
17,
12,
326,
1011,
958,
304,
267,
1613,
8,
9581,
2956,
12,
277,
2843,
826,
721,
354,
29,
354,
12,
890,
29,
890,
12,
3583,
29,
3583,
12,
7227,
29,
7227,
12,
288,
824,
833,
2320,
29,
429,
833,
2320,
12,
827,
63,
3356,
29,
827,
63,
3356,
12,
890,
46,
80,
22011,
29,
890,
46,
80,
22011,
12,
288,
9832,
24180,
29,
12875,
24180,
12,
2062,
16030,
9581,
29,
2062,
16030,
9581,
12,
3147,
1011,
958,
9,
398,
291,
14,
3446,
275,
942,
339,
347,
664,
3921,
8,
277,
304,
267,
372,
291,
14,
3446,
339,
347,
5305,
8,
277,
304,
267,
1613,
1252,
3958,
342,
267,
291,
14,
9170,
275,
942,
3,
4201,
13259,
6290,
267,
327,
692,
9832,
24180,
690,
378,
12,
314,
4350,
930,
348,
440,
506,
2331,
367,
1655,
2419,
9832,
24180,
4696,
267,
291,
14,
4201,
5195,
275,
942,
327,
1129,
3354,
314,
1329,
402,
8494,
626,
314,
4350,
365,
2331,
315,
642,
769,
267,
291,
14,
409,
6373,
8,
4994,
2204,
472,
1192,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
4994,
4665,
9581,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
4994,
2404,
10326,
4699,
29,
16,
9,
267,
291,
14,
1838,
26183,
9581,
8229,
275,
942,
267,
291,
14,
409,
6373,
8,
4994,
9581,
6959,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
988,
26183,
19348,
29,
16,
9,
267,
291,
14,
4994,
19348,
1296,
275,
942,
267,
291,
14,
4994,
19535,
275,
378,
267,
291,
14,
3028,
26183,
9581,
6959,
275,
378,
327,
525,
1204,
4994,
1968,
833,
446,
1420,
16030,
9581,
92,
737,
4036,
3650,
267,
291,
423,
576,
275,
942,
267,
291,
14,
3446,
275,
942,
267,
291,
14,
807,
2204,
9581,
275,
1052,
327,
807,
4350,
1035,
1072,
4350,
267,
291,
14,
1199,
9581,
275,
942,
2378,
347,
485,
3357,
8,
277,
12,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2062,
16030,
9581,
12,
3583,
12,
3572,
304,
267,
291,
14,
475,
919,
70,
8,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2062,
16030,
9581,
12,
3583,
12,
3572,
9,
339,
347,
664,
4261,
26183,
19348,
8,
277,
304,
267,
340,
822,
8,
277,
14,
4994,
19348,
1296,
9,
690,
378,
26,
288,
372,
980,
14,
988,
8,
277,
14,
4994,
19348,
1296,
9,
267,
587,
26,
288,
372,
980,
14,
4304,
339,
347,
664,
14825,
26183,
19348,
8,
277,
304,
267,
340,
822,
8,
277,
14,
4994,
19348,
1296,
9,
690,
378,
26,
288,
372,
980,
14,
3670,
8,
277,
14,
4994,
19348,
1296,
9,
267,
587,
26,
288,
372,
980,
14,
4304,
339,
347,
370,
919,
70,
8,
277,
12,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2049,
1420,
16030,
9581,
12,
3583,
12,
3572,
304,
267,
1390,
22011,
275,
980,
14,
988,
8,
1590,
63,
5250,
9,
267,
13259,
275,
980,
14,
4509,
8,
1590,
63,
5250,
690,
1390,
22011,
15,
17,
14,
18,
9,
267,
291,
14,
4994,
19535,
275,
822,
8,
8032,
59,
16,
566,
267,
327,
1361,
8,
277,
14,
4994,
19535,
9,
267,
327,
692,
8526,
19535,
690,
378,
436,
8526,
19535,
665,
980,
63,
5250,
14,
1392,
59,
16,
3672,
17,
14,
22,
26,
2728,
327,
1361,
8,
2062,
16030,
9581,
12,
429,
833,
2320,
4602,
267,
8526,
19348,
4261,
275,
334,
1590,
14,
1038,
5830,
429,
833,
2320,
63,
15,
18,
14,
16,
6422,
18,
3342,
2062,
16030,
9581,
267,
340,
291,
14,
4994,
19535,
665,
8526,
19348,
4261,
436,
334,
277,
14,
4994,
19535,
690,
378,
503,
334,
12875,
24180,
690,
378,
9,
436,
334,
552,
8,
277,
14,
9170,
13032,
16,
2298,
288,
327
] |
[
28215,
647,
14,
1018,
14,
1130,
18,
36,
492,
9672,
18,
36,
199,
646,
2680,
465,
980,
199,
504,
6357,
14,
4201,
492,
6249,
24078,
199,
646,
7026,
14,
11679,
14,
5590,
465,
2917,
199,
504,
28215,
647,
7535,
14,
3200,
14,
26065,
492,
7083,
19940,
421,
199,
533,
16454,
2956,
8,
3391,
19940,
304,
272,
408,
272,
30370,
26,
272,
298,
12875,
24180,
2,
520,
2069,
340,
3365,
402,
378,
14,
16,
12,
781,
5534,
626,
314,
4350,
787,
19922,
267,
437,
19922,
4350,
2040,
282,
5621,
402,
10679,
5309,
9832,
24180,
4696,
14,
267,
6630,
12,
314,
4350,
365,
5463,
267,
2136,
1050,
314,
2061,
4350,
315,
314,
1453,
13259,
267,
9442,
781,
477,
3402,
4052,
1768,
3628,
314,
892,
4350,
267,
710,
1642,
8494,
16756,
314,
3628,
367,
314,
2163,
7869,
272,
298,
7227,
2,
520,
8765,
367,
10679,
574,
370,
506,
8652,
272,
298,
827,
63,
3271,
2,
520,
4212,
5002,
10361,
787,
8321,
370,
506,
8652,
465,
282,
4350,
272,
298,
429,
833,
2320,
2,
520,
315,
359,
16,
12,
17,
61,
1390,
1568,
402,
314,
1420,
4350,
272,
298,
2062,
16030,
9581,
2,
520,
465,
2399,
536,
18453,
14,
2136,
911,
440,
4526,
7003,
340,
272,
314,
1329,
402,
10361,
365,
10948,
2419,
267,
334,
1590,
14,
1038,
5830,
429,
833,
2320,
63,
15,
18,
14,
16,
6422,
18,
3342,
2062,
16030,
9581,
267,
2382,
824,
833,
2320,
63,
365,
314,
3503,
824,
833,
2320,
275,
824,
833,
2320,
10,
890,
2378,
24288,
26,
267,
485,
576,
275,
980,
1625,
334,
4994,
63,
429,
833,
10,
18,
9,
543,
4350,
330,
695,
4218,
13259,
1323,
12,
57,
26,
288,
413,
12,
18,
288,
650,
12,
21,
288,
650,
14,
24,
12,
19,
14,
20,
272,
298,
4994,
2204,
472,
1192,
2,
520,
1109,
8526,
734,
472,
1192,
1911,
737,
314,
2061,
4526,
272,
340,
9832,
24180,
690,
378,
272,
298,
4994,
4665,
9581,
582,
1109,
8526,
402,
13903,
1900,
4350,
339,
408,
272,
347,
636,
826,
721,
277,
12,
354,
12,
890,
29,
16,
12,
3583,
29,
16,
14,
17,
12,
7227,
29,
16,
14,
20,
12,
827,
63,
3356,
29,
19,
12,
326,
824,
833,
2320,
29,
16,
14,
1046,
12,
890,
46,
80,
22011,
29,
17,
12,
12875,
24180,
29,
17,
14,
16,
12,
2062,
16030,
9581,
29,
17,
12,
326,
1011,
958,
304,
267,
1613,
8,
9581,
2956,
12,
277,
2843,
826,
721,
354,
29,
354,
12,
890,
29,
890,
12,
3583,
29,
3583,
12,
7227,
29,
7227,
12,
288,
824,
833,
2320,
29,
429,
833,
2320,
12,
827,
63,
3356,
29,
827,
63,
3356,
12,
890,
46,
80,
22011,
29,
890,
46,
80,
22011,
12,
288,
9832,
24180,
29,
12875,
24180,
12,
2062,
16030,
9581,
29,
2062,
16030,
9581,
12,
3147,
1011,
958,
9,
398,
291,
14,
3446,
275,
942,
339,
347,
664,
3921,
8,
277,
304,
267,
372,
291,
14,
3446,
339,
347,
5305,
8,
277,
304,
267,
1613,
1252,
3958,
342,
267,
291,
14,
9170,
275,
942,
3,
4201,
13259,
6290,
267,
327,
692,
9832,
24180,
690,
378,
12,
314,
4350,
930,
348,
440,
506,
2331,
367,
1655,
2419,
9832,
24180,
4696,
267,
291,
14,
4201,
5195,
275,
942,
327,
1129,
3354,
314,
1329,
402,
8494,
626,
314,
4350,
365,
2331,
315,
642,
769,
267,
291,
14,
409,
6373,
8,
4994,
2204,
472,
1192,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
4994,
4665,
9581,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
4994,
2404,
10326,
4699,
29,
16,
9,
267,
291,
14,
1838,
26183,
9581,
8229,
275,
942,
267,
291,
14,
409,
6373,
8,
4994,
9581,
6959,
29,
16,
9,
267,
291,
14,
409,
6373,
8,
988,
26183,
19348,
29,
16,
9,
267,
291,
14,
4994,
19348,
1296,
275,
942,
267,
291,
14,
4994,
19535,
275,
378,
267,
291,
14,
3028,
26183,
9581,
6959,
275,
378,
327,
525,
1204,
4994,
1968,
833,
446,
1420,
16030,
9581,
92,
737,
4036,
3650,
267,
291,
423,
576,
275,
942,
267,
291,
14,
3446,
275,
942,
267,
291,
14,
807,
2204,
9581,
275,
1052,
327,
807,
4350,
1035,
1072,
4350,
267,
291,
14,
1199,
9581,
275,
942,
2378,
347,
485,
3357,
8,
277,
12,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2062,
16030,
9581,
12,
3583,
12,
3572,
304,
267,
291,
14,
475,
919,
70,
8,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2062,
16030,
9581,
12,
3583,
12,
3572,
9,
339,
347,
664,
4261,
26183,
19348,
8,
277,
304,
267,
340,
822,
8,
277,
14,
4994,
19348,
1296,
9,
690,
378,
26,
288,
372,
980,
14,
988,
8,
277,
14,
4994,
19348,
1296,
9,
267,
587,
26,
288,
372,
980,
14,
4304,
339,
347,
664,
14825,
26183,
19348,
8,
277,
304,
267,
340,
822,
8,
277,
14,
4994,
19348,
1296,
9,
690,
378,
26,
288,
372,
980,
14,
3670,
8,
277,
14,
4994,
19348,
1296,
9,
267,
587,
26,
288,
372,
980,
14,
4304,
339,
347,
370,
919,
70,
8,
277,
12,
890,
12,
1590,
63,
5250,
12,
7227,
12,
827,
63,
3356,
12,
429,
833,
2320,
3131,
12875,
24180,
12,
2049,
1420,
16030,
9581,
12,
3583,
12,
3572,
304,
267,
1390,
22011,
275,
980,
14,
988,
8,
1590,
63,
5250,
9,
267,
13259,
275,
980,
14,
4509,
8,
1590,
63,
5250,
690,
1390,
22011,
15,
17,
14,
18,
9,
267,
291,
14,
4994,
19535,
275,
822,
8,
8032,
59,
16,
566,
267,
327,
1361,
8,
277,
14,
4994,
19535,
9,
267,
327,
692,
8526,
19535,
690,
378,
436,
8526,
19535,
665,
980,
63,
5250,
14,
1392,
59,
16,
3672,
17,
14,
22,
26,
2728,
327,
1361,
8,
2062,
16030,
9581,
12,
429,
833,
2320,
4602,
267,
8526,
19348,
4261,
275,
334,
1590,
14,
1038,
5830,
429,
833,
2320,
63,
15,
18,
14,
16,
6422,
18,
3342,
2062,
16030,
9581,
267,
340,
291,
14,
4994,
19535,
665,
8526,
19348,
4261,
436,
334,
277,
14,
4994,
19535,
690,
378,
503,
334,
12875,
24180,
690,
378,
9,
436,
334,
552,
8,
277,
14,
9170,
13032,
16,
2298,
288,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nkgilley/home-assistant
|
homeassistant/components/myq/binary_sensor.py
|
6
|
2948
|
"""Support for MyQ gateways."""
import logging
from pymyq.const import (
DEVICE_FAMILY as MYQ_DEVICE_FAMILY,
DEVICE_FAMILY_GATEWAY as MYQ_DEVICE_FAMILY_GATEWAY,
DEVICE_STATE as MYQ_DEVICE_STATE,
DEVICE_STATE_ONLINE as MYQ_DEVICE_STATE_ONLINE,
KNOWN_MODELS,
MANUFACTURER,
)
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
BinarySensorEntity,
)
from .const import DOMAIN, MYQ_COORDINATOR, MYQ_GATEWAY
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up mysq covers."""
data = hass.data[DOMAIN][config_entry.entry_id]
myq = data[MYQ_GATEWAY]
coordinator = data[MYQ_COORDINATOR]
entities = []
for device in myq.devices.values():
if device.device_json[MYQ_DEVICE_FAMILY] == MYQ_DEVICE_FAMILY_GATEWAY:
entities.append(MyQBinarySensorEntity(coordinator, device))
async_add_entities(entities, True)
class MyQBinarySensorEntity(BinarySensorEntity):
"""Representation of a MyQ gateway."""
def __init__(self, coordinator, device):
"""Initialize with API object, device id."""
self._coordinator = coordinator
self._device = device
@property
def device_class(self):
"""We track connectivity for gateways."""
return DEVICE_CLASS_CONNECTIVITY
@property
def name(self):
"""Return the name of the garage door if any."""
return f"{self._device.name} MyQ Gateway"
@property
def is_on(self):
"""Return if the device is online."""
if not self._coordinator.last_update_success:
return False
# Not all devices report online so assume True if its missing
return self._device.device_json[MYQ_DEVICE_STATE].get(
MYQ_DEVICE_STATE_ONLINE, True
)
@property
def unique_id(self):
"""Return a unique, Home Assistant friendly identifier for this entity."""
return self._device.device_id
async def async_update(self):
"""Update status of cover."""
await self._coordinator.async_request_refresh()
@property
def device_info(self):
"""Return the device_info of the device."""
device_info = {
"identifiers": {(DOMAIN, self._device.device_id)},
"name": self.name,
"manufacturer": MANUFACTURER,
"sw_version": self._device.firmware_version,
}
model = KNOWN_MODELS.get(self._device.device_id[2:4])
if model:
device_info["model"] = model
return device_info
@property
def should_poll(self):
"""Return False, updates are controlled via coordinator."""
return False
async def async_added_to_hass(self):
"""Subscribe to updates."""
self.async_on_remove(
self._coordinator.async_add_listener(self.async_write_ha_state)
)
|
apache-2.0
|
[
624,
11532,
367,
4932,
49,
17036,
2885,
1041,
199,
646,
2050,
199,
199,
504,
1134,
1662,
81,
14,
1297,
492,
334,
272,
11643,
63,
38,
1156,
1193,
57,
465,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
12,
272,
11643,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
465,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
12,
272,
11643,
63,
6689,
465,
603,
57,
49,
63,
10555,
63,
6689,
12,
272,
11643,
63,
6689,
63,
615,
6174,
465,
603,
57,
49,
63,
10555,
63,
6689,
63,
615,
6174,
12,
272,
1804,
9165,
63,
11429,
51,
12,
272,
26688,
53,
18164,
1230,
540,
12,
199,
9,
199,
199,
504,
8846,
14,
4608,
14,
3008,
63,
8956,
492,
334,
272,
11643,
63,
6885,
63,
14657,
6882,
1922,
12,
272,
14161,
10160,
7302,
12,
199,
9,
199,
199,
504,
1275,
1297,
492,
15265,
12,
603,
57,
49,
63,
21901,
568,
6467,
12,
603,
57,
49,
63,
26624,
17488,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
1084,
1536,
333,
588,
81,
25858,
1041,
272,
666,
275,
6298,
14,
576,
59,
7378,
1527,
888,
63,
2373,
14,
2373,
63,
344,
61,
272,
3002,
81,
275,
666,
59,
12339,
49,
63,
26624,
17488,
61,
272,
29186,
275,
666,
59,
12339,
49,
63,
21901,
568,
6467,
61,
339,
9045,
275,
942,
339,
367,
2243,
315,
3002,
81,
14,
6410,
14,
1459,
837,
267,
340,
2243,
14,
1782,
63,
1001,
59,
12339,
49,
63,
10555,
63,
38,
1156,
1193,
57,
61,
508,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
26,
288,
9045,
14,
740,
8,
5713,
49,
6636,
10160,
7302,
8,
27380,
12,
2243,
430,
339,
5316,
63,
525,
63,
8327,
8,
8327,
12,
715,
9,
421,
199,
533,
4932,
49,
6636,
10160,
7302,
8,
6636,
10160,
7302,
304,
272,
408,
20609,
402,
282,
4932,
49,
10391,
1041,
339,
347,
636,
826,
721,
277,
12,
29186,
12,
2243,
304,
267,
408,
9345,
543,
3261,
909,
12,
2243,
1305,
1041,
267,
291,
423,
27380,
275,
29186,
267,
291,
423,
1782,
275,
2243,
339,
768,
1829,
272,
347,
2243,
63,
533,
8,
277,
304,
267,
408,
6004,
4426,
20170,
367,
17036,
2885,
1041,
267,
372,
11643,
63,
6885,
63,
14657,
6882,
1922,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
486,
285,
474,
886,
269,
340,
1263,
1041,
267,
372,
289,
14381,
277,
423,
1782,
14,
354,
93,
4932,
49,
27166,
2,
339,
768,
1829,
272,
347,
365,
63,
265,
8,
277,
304,
267,
408,
1767,
340,
314,
2243,
365,
18470,
1041,
267,
340,
440,
291,
423,
27380,
14,
2019,
63,
873,
63,
3742,
26,
288,
372,
756,
398,
327,
2832,
1006,
7256,
3622,
18470,
880,
5534,
715,
340,
2399,
4124,
267,
372,
291,
423,
1782,
14,
1782,
63,
1001,
59,
12339,
49,
63,
10555,
63,
6689,
1055,
362,
8,
288,
603,
57,
49,
63,
10555,
63,
6689,
63,
615,
6174,
12,
715,
267,
776,
339,
768,
1829,
272,
347,
3747,
63,
344,
8,
277,
304,
267,
408,
1767,
282,
3747,
12,
14621,
3709,
18832,
21428,
5148,
367,
642,
4642,
1041,
267,
372,
291,
423,
1782,
14,
1782,
63,
344,
339,
5316,
347,
5316,
63,
873,
8,
277,
304,
267,
408,
4152,
2004,
402,
8486,
1041,
267,
5517,
291,
423,
27380,
14,
4146,
63,
1069,
63,
6635,
342,
339,
768,
1829,
272,
347,
2243,
63,
815,
8,
277,
304,
267,
408,
1767,
314,
2243,
63,
815,
402,
314,
2243,
1041,
267,
2243,
63,
815,
275,
469,
288,
298,
14227,
582,
26458,
7378,
12,
291,
423,
1782,
14,
1782,
63,
344,
16658,
288,
298,
354,
582,
291,
14,
354,
12,
288,
298,
32214,
582,
26688,
53,
18164,
1230,
540,
12,
288,
298,
3519,
63,
1023,
582,
291,
423,
1782,
14,
26374,
63,
1023,
12,
267,
789,
267,
1402,
275,
1804,
9165,
63,
11429,
51,
14,
362,
8,
277,
423,
1782,
14,
1782,
63,
344,
59,
18,
26,
20,
566,
267,
340,
1402,
26,
288,
2243,
63,
815,
905,
1238,
937,
275,
1402,
398,
372,
2243,
63,
815,
339,
768,
1829,
272,
347,
1077,
63,
6843,
8,
277,
304,
267,
408,
1767,
756,
12,
7029,
787,
22284,
4799,
29186,
1041,
267,
372,
756,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2610,
5355,
370,
7029,
1041,
267,
291,
14,
4146,
63,
265,
63,
2168,
8,
288,
291,
423,
27380,
14,
4146,
63,
525,
63,
9799,
8,
277,
14,
4146,
63,
952,
63,
2411,
63,
929,
9,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11532,
367,
4932,
49,
17036,
2885,
1041,
199,
646,
2050,
199,
199,
504,
1134,
1662,
81,
14,
1297,
492,
334,
272,
11643,
63,
38,
1156,
1193,
57,
465,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
12,
272,
11643,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
465,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
12,
272,
11643,
63,
6689,
465,
603,
57,
49,
63,
10555,
63,
6689,
12,
272,
11643,
63,
6689,
63,
615,
6174,
465,
603,
57,
49,
63,
10555,
63,
6689,
63,
615,
6174,
12,
272,
1804,
9165,
63,
11429,
51,
12,
272,
26688,
53,
18164,
1230,
540,
12,
199,
9,
199,
199,
504,
8846,
14,
4608,
14,
3008,
63,
8956,
492,
334,
272,
11643,
63,
6885,
63,
14657,
6882,
1922,
12,
272,
14161,
10160,
7302,
12,
199,
9,
199,
199,
504,
1275,
1297,
492,
15265,
12,
603,
57,
49,
63,
21901,
568,
6467,
12,
603,
57,
49,
63,
26624,
17488,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
1084,
1536,
333,
588,
81,
25858,
1041,
272,
666,
275,
6298,
14,
576,
59,
7378,
1527,
888,
63,
2373,
14,
2373,
63,
344,
61,
272,
3002,
81,
275,
666,
59,
12339,
49,
63,
26624,
17488,
61,
272,
29186,
275,
666,
59,
12339,
49,
63,
21901,
568,
6467,
61,
339,
9045,
275,
942,
339,
367,
2243,
315,
3002,
81,
14,
6410,
14,
1459,
837,
267,
340,
2243,
14,
1782,
63,
1001,
59,
12339,
49,
63,
10555,
63,
38,
1156,
1193,
57,
61,
508,
603,
57,
49,
63,
10555,
63,
38,
1156,
1193,
57,
63,
26624,
17488,
26,
288,
9045,
14,
740,
8,
5713,
49,
6636,
10160,
7302,
8,
27380,
12,
2243,
430,
339,
5316,
63,
525,
63,
8327,
8,
8327,
12,
715,
9,
421,
199,
533,
4932,
49,
6636,
10160,
7302,
8,
6636,
10160,
7302,
304,
272,
408,
20609,
402,
282,
4932,
49,
10391,
1041,
339,
347,
636,
826,
721,
277,
12,
29186,
12,
2243,
304,
267,
408,
9345,
543,
3261,
909,
12,
2243,
1305,
1041,
267,
291,
423,
27380,
275,
29186,
267,
291,
423,
1782,
275,
2243,
339,
768,
1829,
272,
347,
2243,
63,
533,
8,
277,
304,
267,
408,
6004,
4426,
20170,
367,
17036,
2885,
1041,
267,
372,
11643,
63,
6885,
63,
14657,
6882,
1922,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
486,
285,
474,
886,
269,
340,
1263,
1041,
267,
372,
289,
14381,
277,
423,
1782,
14,
354,
93,
4932,
49,
27166,
2,
339,
768,
1829,
272,
347,
365,
63,
265,
8,
277,
304,
267,
408,
1767,
340,
314,
2243,
365,
18470,
1041,
267,
340,
440,
291,
423,
27380,
14,
2019,
63,
873,
63,
3742,
26,
288,
372,
756,
398,
327,
2832,
1006,
7256,
3622,
18470,
880,
5534,
715,
340,
2399,
4124,
267,
372,
291,
423,
1782,
14,
1782,
63,
1001,
59,
12339,
49,
63,
10555,
63,
6689,
1055,
362,
8,
288,
603,
57,
49,
63,
10555,
63,
6689,
63,
615,
6174,
12,
715,
267,
776,
339,
768,
1829,
272,
347,
3747,
63,
344,
8,
277,
304,
267,
408,
1767,
282,
3747,
12,
14621,
3709,
18832,
21428,
5148,
367,
642,
4642,
1041,
267,
372,
291,
423,
1782,
14,
1782,
63,
344,
339,
5316,
347,
5316,
63,
873,
8,
277,
304,
267,
408,
4152,
2004,
402,
8486,
1041,
267,
5517,
291,
423,
27380,
14,
4146,
63,
1069,
63,
6635,
342,
339,
768,
1829,
272,
347,
2243,
63,
815,
8,
277,
304,
267,
408,
1767,
314,
2243,
63,
815,
402,
314,
2243,
1041,
267,
2243,
63,
815,
275,
469,
288,
298,
14227,
582,
26458,
7378,
12,
291,
423,
1782,
14,
1782,
63,
344,
16658,
288,
298,
354,
582,
291,
14,
354,
12,
288,
298,
32214,
582,
26688,
53,
18164,
1230,
540,
12,
288,
298,
3519,
63,
1023,
582,
291,
423,
1782,
14,
26374,
63,
1023,
12,
267,
789,
267,
1402,
275,
1804,
9165,
63,
11429,
51,
14,
362,
8,
277,
423,
1782,
14,
1782,
63,
344,
59,
18,
26,
20,
566,
267,
340,
1402,
26,
288,
2243,
63,
815,
905,
1238,
937,
275,
1402,
398,
372,
2243,
63,
815,
339,
768,
1829,
272,
347,
1077,
63,
6843,
8,
277,
304,
267,
408,
1767,
756,
12,
7029,
787,
22284,
4799,
29186,
1041,
267,
372,
756,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2610,
5355,
370,
7029,
1041,
267,
291,
14,
4146,
63,
265,
63,
2168,
8,
288,
291,
423,
27380,
14,
4146,
63,
525,
63,
9799,
8,
277,
14,
4146,
63,
952,
63,
2411,
63,
929,
9,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
heracek/django-nonrel
|
django/contrib/gis/gdal/feature.py
|
321
|
3998
|
# The GDAL C library, OGR exception, and the Field object
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.error import OGRException, OGRIndexError
from django.contrib.gis.gdal.field import Field
from django.contrib.gis.gdal.geometries import OGRGeometry, OGRGeomType
from django.contrib.gis.gdal.srs import SpatialReference
# ctypes function prototypes
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
# The OGR_F_* routines are relevant here.
class Feature(GDALBase):
"A class that wraps an OGR Feature, needs to be instantiated from a Layer object."
#### Python 'magic' routines ####
def __init__(self, feat, fdefn):
"Initializes on the pointers for the feature and the layer definition."
if not feat or not fdefn:
raise OGRException('Cannot create OGR Feature, invalid pointer given.')
self.ptr = feat
self._fdefn = fdefn
def __del__(self):
"Releases a reference to this object."
if self._ptr: capi.destroy_feature(self._ptr)
def __getitem__(self, index):
"""
Gets the Field object at the specified index, which may be either
an integer or the Field's string label. Note that the Field object
is not the field's _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a Field instance.
"""
if isinstance(index, basestring):
i = self.index(index)
else:
if index < 0 or index > self.num_fields:
raise OGRIndexError('index out of range')
i = index
return Field(self.ptr, i)
def __iter__(self):
"Iterates over each field in the Feature."
for i in xrange(self.num_fields):
yield self[i]
def __len__(self):
"Returns the count of fields in this feature."
return self.num_fields
def __str__(self):
"The string name of the feature."
return 'Feature FID %d in Layer<%s>' % (self.fid, self.layer_name)
def __eq__(self, other):
"Does equivalence testing on the features."
return bool(capi.feature_equal(self.ptr, other._ptr))
#### Feature Properties ####
@property
def fid(self):
"Returns the feature identifier."
return capi.get_fid(self.ptr)
@property
def layer_name(self):
"Returns the name of the layer for the feature."
return capi.get_feat_name(self._fdefn)
@property
def num_fields(self):
"Returns the number of fields in the Feature."
return capi.get_feat_field_count(self.ptr)
@property
def fields(self):
"Returns a list of fields in the Feature."
return [capi.get_field_name(capi.get_field_defn(self._fdefn, i))
for i in xrange(self.num_fields)]
@property
def geom(self):
"Returns the OGR Geometry for this Feature."
# Retrieving the geometry pointer for the feature.
geom_ptr = capi.get_feat_geom_ref(self.ptr)
return OGRGeometry(geom_api.clone_geom(geom_ptr))
@property
def geom_type(self):
"Returns the OGR Geometry Type for this Feture."
return OGRGeomType(capi.get_fd_geom_type(self._fdefn))
#### Feature Methods ####
def get(self, field):
"""
Returns the value of the field, instead of an instance of the Field
object. May take a string of the field name or a Field object as
parameters.
"""
field_name = getattr(field, 'name', field)
return self[field_name].value
def index(self, field_name):
"Returns the index of the given field name."
i = capi.get_field_index(self.ptr, field_name)
if i < 0: raise OGRIndexError('invalid OFT field name given: "%s"' % field_name)
return i
|
bsd-3-clause
|
[
3,
710,
15801,
445,
3555,
12,
10904,
1919,
12,
436,
314,
5024,
909,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
12,
10904,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
698,
492,
5024,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
21626,
492,
24220,
12,
25756,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
12722,
492,
24324,
199,
199,
3,
5577,
805,
19393,
83,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
12,
9671,
465,
9671,
63,
1246,
199,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
38,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
13407,
8,
17835,
1563,
304,
272,
298,
33,
1021,
626,
14018,
376,
10904,
13407,
12,
4839,
370,
506,
17544,
687,
282,
11915,
909,
2122,
339,
14055,
2018,
283,
11523,
7,
14975,
14055,
272,
347,
636,
826,
721,
277,
12,
13953,
12,
289,
27950,
304,
267,
298,
23489,
641,
314,
21116,
367,
314,
3878,
436,
314,
4045,
5492,
2122,
267,
340,
440,
13953,
503,
440,
289,
27950,
26,
288,
746,
19746,
907,
16010,
360,
6612,
1218,
10904,
13407,
12,
3866,
7849,
1627,
2659,
267,
291,
14,
4695,
275,
13953,
267,
291,
423,
70,
27950,
275,
289,
27950,
339,
347,
636,
2264,
721,
277,
304,
267,
298,
9625,
83,
282,
3659,
370,
642,
909,
2122,
267,
340,
291,
423,
4695,
26,
13648,
14,
7237,
63,
4445,
8,
277,
423,
4695,
9,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
267,
14509,
314,
5024,
909,
737,
314,
2013,
1478,
12,
1314,
1443,
506,
1902,
267,
376,
3000,
503,
314,
5024,
1159,
1059,
1768,
14,
221,
3390,
626,
314,
5024,
909,
267,
365,
440,
314,
901,
1159,
485,
585,
63,
1553,
675,
314,
658,
362,
64,
1083,
3140,
370,
4960,
8044,
314,
574,
334,
69,
14,
71,
14,
376,
3000,
9,
3140,
402,
282,
5024,
1256,
14,
267,
408,
267,
340,
1228,
8,
1080,
12,
7116,
304,
288,
284,
275,
291,
14,
1080,
8,
1080,
9,
267,
587,
26,
288,
340,
1478,
665,
378,
503,
1478,
690,
291,
14,
1507,
63,
955,
26,
355,
746,
10904,
12129,
360,
1080,
734,
402,
1425,
358,
288,
284,
275,
1478,
267,
372,
5024,
8,
277,
14,
4695,
12,
284,
9,
2286,
347,
636,
1661,
721,
277,
304,
267,
298,
3315,
2335,
1806,
1924,
901,
315,
314,
13407,
2122,
267,
367,
284,
315,
4945,
8,
277,
14,
1507,
63,
955,
304,
288,
1995,
291,
59,
73,
61,
339,
347,
636,
552,
721,
277,
304,
267,
298,
3407,
314,
2338,
402,
1504,
315,
642,
3878,
2122,
267,
372,
291,
14,
1507,
63,
955,
5493,
347,
636,
495,
721,
277,
304,
267,
298,
1918,
1059,
536,
402,
314,
3878,
2122,
267,
372,
283,
5968,
481,
998,
450,
68,
315,
11915,
21110,
83,
3524,
450,
334,
277,
14,
9430,
12,
291,
14,
1897,
63,
354,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
298,
6586,
325,
22810,
5343,
641,
314,
4534,
2122,
267,
372,
2155,
8,
14145,
14,
4445,
63,
1452,
8,
277,
14,
4695,
12,
1163,
423,
4695,
430,
339,
14055,
13407,
19329,
14055,
272,
768,
1829,
272,
347,
8289,
8,
277,
304,
267,
298,
3407,
314,
3878,
5148,
2122,
267,
372,
13648,
14,
362,
63,
9430,
8,
277,
14,
4695,
9,
5493,
768,
1829,
272,
347,
4045,
63,
354,
8,
277,
304,
267,
298,
3407,
314,
536,
402,
314,
4045,
367,
314,
3878,
2122,
267,
372,
13648,
14,
362,
63,
11873,
63,
354,
8,
277,
423,
70,
27950,
9,
339,
768,
1829,
272,
347,
1967,
63,
955,
8,
277,
304,
267,
298,
3407,
314,
1329,
402,
1504,
315,
314,
13407,
2122,
267,
372,
13648,
14,
362,
63,
11873,
63,
698,
63,
835,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
1504,
8,
277,
304,
267,
298,
3407,
282,
769,
402,
1504,
315,
314,
13407,
2122,
267,
372,
359,
14145,
14,
362,
63,
698,
63,
354,
8,
14145,
14,
362,
63,
698,
63,
27950,
8,
277,
423,
70,
27950,
12,
284,
430,
8892,
367,
284,
315,
4945,
8,
277,
14,
1507,
63,
955,
1874,
339,
768,
1829,
272,
347,
9671,
8,
277,
304,
267,
298,
3407,
314,
10904,
10579,
367,
642,
13407,
2122,
267,
327,
8747,
11317,
4007,
314,
3400,
7849,
367,
314,
3878,
14,
267,
9671,
63,
4695,
275,
13648,
14,
362,
63,
11873,
63,
6481,
63,
1121,
8,
277,
14,
4695,
9,
267,
372,
24220,
8,
6481,
63,
1246,
14,
6311,
63,
6481,
8,
6481,
63,
4695,
430,
339,
768,
1829,
272,
347,
9671,
63,
466,
8,
277,
304,
267,
298,
3407,
314,
10904,
10579,
2434,
367,
642,
481,
386,
608,
2122,
267,
372,
25756,
8,
14145,
14,
362,
63,
2592,
63,
6481,
63,
466,
8,
277,
423,
70,
27950,
430,
2286,
14055,
13407,
17653,
14055,
272,
347,
664,
8,
277,
12,
901,
304,
267,
408,
267,
1803,
314,
574,
402,
314,
901,
12,
3140,
402,
376,
1256,
402,
314,
5024,
267,
909,
14,
221,
10162,
5452,
282,
1059,
402,
314,
901,
536,
503,
282,
5024,
909,
465,
267,
2633,
14,
267,
408,
267,
901,
63,
354,
275,
2519,
8,
698,
12,
283,
354,
297,
901,
9,
267,
372,
291,
59,
698,
63,
354,
1055,
585,
339,
347,
1478,
8,
277,
12,
901,
63,
354,
304,
267,
298,
3407,
314,
1478,
402,
314,
1627,
901,
536,
2122,
267,
284,
275,
13648,
14,
362,
63,
698,
63,
1080,
8,
277,
14,
4695,
12,
901,
63,
354,
9,
267,
340,
284,
665,
378,
26,
746,
10904,
12129,
360,
3197,
20025,
901,
536,
1627,
26,
2071,
83,
4507,
450,
901,
63,
354,
9,
267,
372,
284,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
710,
15801,
445,
3555,
12,
10904,
1919,
12,
436,
314,
5024,
909,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
12,
10904,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
698,
492,
5024,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
21626,
492,
24220,
12,
25756,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
12722,
492,
24324,
199,
199,
3,
5577,
805,
19393,
83,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
12,
9671,
465,
9671,
63,
1246,
199,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
38,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
13407,
8,
17835,
1563,
304,
272,
298,
33,
1021,
626,
14018,
376,
10904,
13407,
12,
4839,
370,
506,
17544,
687,
282,
11915,
909,
2122,
339,
14055,
2018,
283,
11523,
7,
14975,
14055,
272,
347,
636,
826,
721,
277,
12,
13953,
12,
289,
27950,
304,
267,
298,
23489,
641,
314,
21116,
367,
314,
3878,
436,
314,
4045,
5492,
2122,
267,
340,
440,
13953,
503,
440,
289,
27950,
26,
288,
746,
19746,
907,
16010,
360,
6612,
1218,
10904,
13407,
12,
3866,
7849,
1627,
2659,
267,
291,
14,
4695,
275,
13953,
267,
291,
423,
70,
27950,
275,
289,
27950,
339,
347,
636,
2264,
721,
277,
304,
267,
298,
9625,
83,
282,
3659,
370,
642,
909,
2122,
267,
340,
291,
423,
4695,
26,
13648,
14,
7237,
63,
4445,
8,
277,
423,
4695,
9,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
267,
14509,
314,
5024,
909,
737,
314,
2013,
1478,
12,
1314,
1443,
506,
1902,
267,
376,
3000,
503,
314,
5024,
1159,
1059,
1768,
14,
221,
3390,
626,
314,
5024,
909,
267,
365,
440,
314,
901,
1159,
485,
585,
63,
1553,
675,
314,
658,
362,
64,
1083,
3140,
370,
4960,
8044,
314,
574,
334,
69,
14,
71,
14,
376,
3000,
9,
3140,
402,
282,
5024,
1256,
14,
267,
408,
267,
340,
1228,
8,
1080,
12,
7116,
304,
288,
284,
275,
291,
14,
1080,
8,
1080,
9,
267,
587,
26,
288,
340,
1478,
665,
378,
503,
1478,
690,
291,
14,
1507,
63,
955,
26,
355,
746,
10904,
12129,
360,
1080,
734,
402,
1425,
358,
288,
284,
275,
1478,
267,
372,
5024,
8,
277,
14,
4695,
12,
284,
9,
2286,
347,
636,
1661,
721,
277,
304,
267,
298,
3315,
2335,
1806,
1924,
901,
315,
314,
13407,
2122,
267,
367,
284,
315,
4945,
8,
277,
14,
1507,
63,
955,
304,
288,
1995,
291,
59,
73,
61,
339,
347,
636,
552,
721,
277,
304,
267,
298,
3407,
314,
2338,
402,
1504,
315,
642,
3878,
2122,
267,
372,
291,
14,
1507,
63,
955,
5493,
347,
636,
495,
721,
277,
304,
267,
298,
1918,
1059,
536,
402,
314,
3878,
2122,
267,
372,
283,
5968,
481,
998,
450,
68,
315,
11915,
21110,
83,
3524,
450,
334,
277,
14,
9430,
12,
291,
14,
1897,
63,
354,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
298,
6586,
325,
22810,
5343,
641,
314,
4534,
2122,
267,
372,
2155,
8,
14145,
14,
4445,
63,
1452,
8,
277,
14,
4695,
12,
1163,
423,
4695,
430,
339,
14055,
13407,
19329,
14055,
272,
768,
1829,
272,
347,
8289,
8,
277,
304,
267,
298,
3407,
314,
3878,
5148,
2122,
267,
372,
13648,
14,
362,
63,
9430,
8,
277,
14,
4695,
9,
5493,
768,
1829,
272,
347,
4045,
63,
354,
8,
277,
304,
267,
298,
3407,
314,
536,
402,
314,
4045,
367,
314,
3878,
2122,
267,
372,
13648,
14,
362,
63,
11873,
63,
354,
8,
277,
423,
70,
27950,
9,
339,
768,
1829,
272,
347,
1967,
63,
955,
8,
277,
304,
267,
298,
3407,
314,
1329,
402,
1504,
315,
314,
13407,
2122,
267,
372,
13648,
14,
362,
63,
11873,
63,
698,
63,
835,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
1504,
8,
277,
304,
267,
298,
3407,
282,
769,
402,
1504,
315,
314,
13407,
2122,
267,
372,
359,
14145,
14,
362,
63,
698,
63,
354,
8,
14145,
14,
362,
63,
698,
63,
27950,
8,
277,
423,
70,
27950,
12,
284,
430,
8892,
367,
284,
315,
4945,
8,
277,
14,
1507,
63,
955,
1874,
339,
768,
1829,
272,
347,
9671,
8,
277,
304,
267,
298,
3407,
314,
10904,
10579,
367,
642,
13407,
2122,
267,
327,
8747,
11317,
4007,
314,
3400,
7849,
367,
314,
3878,
14,
267,
9671,
63,
4695,
275,
13648,
14,
362,
63,
11873,
63,
6481,
63,
1121,
8,
277,
14,
4695,
9,
267,
372,
24220,
8,
6481,
63,
1246,
14,
6311,
63,
6481,
8,
6481,
63,
4695,
430,
339,
768,
1829,
272,
347,
9671,
63,
466,
8,
277,
304,
267,
298,
3407,
314,
10904,
10579,
2434,
367,
642,
481,
386,
608,
2122,
267,
372,
25756,
8,
14145,
14,
362,
63,
2592,
63,
6481,
63,
466,
8,
277,
423,
70,
27950,
430,
2286,
14055,
13407,
17653,
14055,
272,
347,
664,
8,
277,
12,
901,
304,
267,
408,
267,
1803,
314,
574,
402,
314,
901,
12,
3140,
402,
376,
1256,
402,
314,
5024,
267,
909,
14,
221,
10162,
5452,
282,
1059,
402,
314,
901,
536,
503,
282,
5024,
909,
465,
267,
2633,
14,
267,
408,
267,
901,
63,
354,
275,
2519,
8,
698,
12,
283,
354,
297,
901,
9,
267,
372,
291,
59,
698,
63,
354,
1055,
585,
339,
347,
1478,
8,
277,
12,
901,
63,
354,
304,
267,
298,
3407,
314,
1478,
402,
314,
1627,
901,
536,
2122,
267,
284,
275,
13648,
14,
362,
63,
698,
63,
1080,
8,
277,
14,
4695,
12,
901,
63,
354,
9,
267,
340,
284,
665,
378,
26,
746,
10904,
12129,
360,
3197,
20025,
901,
536,
1627,
26,
2071,
83,
4507,
450,
901,
63,
354,
9,
267,
372,
284,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wayward710/django-oidc-provider
|
oidc_provider/models.py
|
1
|
2568
|
import json
from django.db import models
from django.utils import timezone
from django.conf import settings
class Client(models.Model):
RESPONSE_TYPE_CHOICES = [
('code', 'code (Authorization Code Flow)'),
('id_token', 'id_token (Implicit Flow)'),
('id_token token', 'id_token token (Implicit Flow)'),
]
name = models.CharField(max_length=100, default='')
client_id = models.CharField(max_length=255, unique=True)
client_secret = models.CharField(max_length=255, unique=True)
response_type = models.CharField(max_length=30,
choices=RESPONSE_TYPE_CHOICES)
_redirect_uris = models.TextField(default='')
def __str__(self):
return u'%s'.format(self.name)
def __unicode__(self):
return self.__str__()
def redirect_uris():
def fget(self):
return self._redirect_uris.splitlines()
def fset(self, value):
self._redirect_uris = '\n'.join(value)
return locals()
redirect_uris = property(**redirect_uris())
@property
def default_redirect_uri(self):
return self.redirect_uris[0] if self.redirect_uris else ''
class BaseCodeTokenModel(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
client = models.ForeignKey(Client)
expires_at = models.DateTimeField()
_scope = models.TextField(default='')
def scope():
def fget(self):
return self._scope.split()
def fset(self, value):
self._scope = ' '.join(value)
return locals()
scope = property(**scope())
def has_expired(self):
return timezone.now() >= self.expires_at
def __str__(self):
return u'%s - %s (%s)'.format(self.client, self.user.email, self.expires_at)
def __unicode__(self):
return self.__str__()
class Meta:
abstract = True
class Code(BaseCodeTokenModel):
code = models.CharField(max_length=255, unique=True)
nonce = models.CharField(max_length=255, blank=True, default='')
class Token(BaseCodeTokenModel):
access_token = models.CharField(max_length=255, unique=True)
refresh_token = models.CharField(max_length=255, unique=True, null=True)
_id_token = models.TextField()
def id_token():
def fget(self):
return json.loads(self._id_token)
def fset(self, value):
self._id_token = json.dumps(value)
return locals()
id_token = property(**id_token())
class UserConsent(BaseCodeTokenModel):
pass
|
mit
|
[
646,
2022,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
6810,
8,
992,
14,
1685,
304,
339,
820,
7613,
11827,
63,
2711,
63,
16236,
275,
359,
267,
661,
600,
297,
283,
600,
334,
11626,
5495,
20823,
11218,
267,
661,
344,
63,
1418,
297,
283,
344,
63,
1418,
334,
8499,
3137,
20823,
11218,
267,
661,
344,
63,
1418,
1526,
297,
283,
344,
63,
1418,
1526,
334,
8499,
3137,
20823,
11218,
272,
1622,
339,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
272,
1890,
63,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
1890,
63,
4731,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
1177,
63,
466,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3660,
3415,
29,
12801,
63,
2711,
63,
16236,
9,
339,
485,
4876,
63,
17656,
275,
1709,
14,
6254,
8,
885,
13275,
339,
347,
636,
495,
721,
277,
304,
267,
372,
399,
5956,
83,
1370,
908,
8,
277,
14,
354,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
855,
495,
4533,
2286,
347,
4660,
63,
17656,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
291,
423,
4876,
63,
17656,
14,
7644,
342,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
4876,
63,
17656,
275,
1557,
78,
1370,
904,
8,
585,
9,
267,
372,
9480,
342,
272,
4660,
63,
17656,
275,
3324,
3682,
4876,
63,
17656,
1012,
339,
768,
1829,
272,
347,
849,
63,
4876,
63,
2302,
8,
277,
304,
267,
372,
291,
14,
4876,
63,
17656,
59,
16,
61,
340,
291,
14,
4876,
63,
17656,
587,
2125,
421,
199,
533,
3523,
3034,
3264,
1685,
8,
992,
14,
1685,
304,
339,
922,
275,
1709,
14,
3190,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
9,
272,
1890,
275,
1709,
14,
3190,
8,
3041,
9,
272,
12261,
63,
292,
275,
1709,
14,
4626,
342,
272,
485,
2645,
275,
1709,
14,
6254,
8,
885,
13275,
339,
347,
4194,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
291,
423,
2645,
14,
1294,
342,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
2645,
275,
283,
1987,
904,
8,
585,
9,
267,
372,
9480,
342,
272,
4194,
275,
3324,
3682,
2645,
1012,
339,
347,
965,
63,
16340,
8,
277,
304,
267,
372,
7137,
14,
2131,
342,
2356,
291,
14,
12342,
63,
292,
339,
347,
636,
495,
721,
277,
304,
267,
372,
399,
5956,
83,
446,
450,
83,
4366,
83,
9,
1370,
908,
8,
277,
14,
1258,
12,
291,
14,
751,
14,
2123,
12,
291,
14,
12342,
63,
292,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
855,
495,
4533,
2286,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
5495,
8,
1563,
3034,
3264,
1685,
304,
339,
1233,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
13711,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
12,
849,
13275,
421,
199,
533,
8767,
8,
1563,
3034,
3264,
1685,
304,
339,
2879,
63,
1418,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
9236,
63,
1418,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
12,
2973,
29,
549,
9,
272,
485,
344,
63,
1418,
275,
1709,
14,
6254,
342,
272,
347,
1305,
63,
1418,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
2022,
14,
3640,
8,
277,
423,
344,
63,
1418,
9,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
344,
63,
1418,
275,
2022,
14,
4180,
8,
585,
9,
267,
372,
9480,
342,
272,
1305,
63,
1418,
275,
3324,
3682,
344,
63,
1418,
1012,
421,
199,
533,
2876,
714,
1150,
8,
1563,
3034,
3264,
1685,
304,
339,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2022,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
6810,
8,
992,
14,
1685,
304,
339,
820,
7613,
11827,
63,
2711,
63,
16236,
275,
359,
267,
661,
600,
297,
283,
600,
334,
11626,
5495,
20823,
11218,
267,
661,
344,
63,
1418,
297,
283,
344,
63,
1418,
334,
8499,
3137,
20823,
11218,
267,
661,
344,
63,
1418,
1526,
297,
283,
344,
63,
1418,
1526,
334,
8499,
3137,
20823,
11218,
272,
1622,
339,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
849,
13275,
272,
1890,
63,
344,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
1890,
63,
4731,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
1177,
63,
466,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
3660,
3415,
29,
12801,
63,
2711,
63,
16236,
9,
339,
485,
4876,
63,
17656,
275,
1709,
14,
6254,
8,
885,
13275,
339,
347,
636,
495,
721,
277,
304,
267,
372,
399,
5956,
83,
1370,
908,
8,
277,
14,
354,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
855,
495,
4533,
2286,
347,
4660,
63,
17656,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
291,
423,
4876,
63,
17656,
14,
7644,
342,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
4876,
63,
17656,
275,
1557,
78,
1370,
904,
8,
585,
9,
267,
372,
9480,
342,
272,
4660,
63,
17656,
275,
3324,
3682,
4876,
63,
17656,
1012,
339,
768,
1829,
272,
347,
849,
63,
4876,
63,
2302,
8,
277,
304,
267,
372,
291,
14,
4876,
63,
17656,
59,
16,
61,
340,
291,
14,
4876,
63,
17656,
587,
2125,
421,
199,
533,
3523,
3034,
3264,
1685,
8,
992,
14,
1685,
304,
339,
922,
275,
1709,
14,
3190,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
9,
272,
1890,
275,
1709,
14,
3190,
8,
3041,
9,
272,
12261,
63,
292,
275,
1709,
14,
4626,
342,
272,
485,
2645,
275,
1709,
14,
6254,
8,
885,
13275,
339,
347,
4194,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
291,
423,
2645,
14,
1294,
342,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
2645,
275,
283,
1987,
904,
8,
585,
9,
267,
372,
9480,
342,
272,
4194,
275,
3324,
3682,
2645,
1012,
339,
347,
965,
63,
16340,
8,
277,
304,
267,
372,
7137,
14,
2131,
342,
2356,
291,
14,
12342,
63,
292,
339,
347,
636,
495,
721,
277,
304,
267,
372,
399,
5956,
83,
446,
450,
83,
4366,
83,
9,
1370,
908,
8,
277,
14,
1258,
12,
291,
14,
751,
14,
2123,
12,
291,
14,
12342,
63,
292,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
855,
495,
4533,
2286,
1021,
6288,
26,
267,
9006,
275,
715,
421,
199,
533,
5495,
8,
1563,
3034,
3264,
1685,
304,
339,
1233,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
13711,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
4596,
29,
549,
12,
849,
13275,
421,
199,
533,
8767,
8,
1563,
3034,
3264,
1685,
304,
339,
2879,
63,
1418,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
272,
9236,
63,
1418,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3747,
29,
549,
12,
2973,
29,
549,
9,
272,
485,
344,
63,
1418,
275,
1709,
14,
6254,
342,
272,
347,
1305,
63,
1418,
837,
267,
347,
289,
362,
8,
277,
304,
288,
372,
2022,
14,
3640,
8,
277,
423,
344,
63,
1418,
9,
267,
347,
289,
409,
8,
277,
12,
574,
304,
288,
291,
423,
344,
63,
1418,
275,
2022,
14,
4180,
8,
585,
9,
267,
372,
9480,
342,
272,
1305,
63,
1418,
275,
3324,
3682,
344,
63,
1418,
1012,
421,
199,
533,
2876,
714,
1150,
8,
1563,
3034,
3264,
1685,
304,
339,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tadgh/ArgoRevisit
|
third_party/nltk/classify/megam.py
|
4
|
5817
|
# Natural Language Toolkit: Interface to Megam Classifier
#
# Copyright (C) 2001-2011 NLTK Project
# Author: Edward Loper <edloper@gradient.cis.upenn.edu>
# URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT
#
# $Id: naivebayes.py 2063 2004-07-17 21:02:24Z edloper $
"""
A set of functions used to interface with the external U{megam
<http://www.cs.utah.edu/~hal/megam/>} maxent optimization package.
Before C{megam} can be used, you should tell NLTK where it can find
the C{megam} binary, using the L{config_megam()} function. Typical
usage:
>>> import nltk
>>> nltk.config_megam('.../path/to/megam')
>>> classifier = nltk.MaxentClassifier.train(corpus, 'megam')
"""
__docformat__ = 'epytext en'
import os
import os.path
import subprocess
from nltk.internals import find_binary
try:
import numpy
except ImportError:
numpy = None
######################################################################
#{ Configuration
######################################################################
_megam_bin = None
def config_megam(bin=None):
"""
Configure NLTK's interface to the C{megam} maxent optimization
package.
@param bin: The full path to the C{megam} binary. If not specified,
then nltk will search the system for a C{megam} binary; and if
one is not found, it will raise a C{LookupError} exception.
@type bin: C{string}
"""
global _megam_bin
_megam_bin = find_binary(
'megam', bin,
env_vars=['MEGAM', 'MEGAMHOME'],
binary_names=['megam.opt', 'megam', 'megam_686', 'megam_i686.opt'],
url='http://www.cs.utah.edu/~hal/megam/')
######################################################################
#{ Megam Interface Functions
######################################################################
def write_megam_file(train_toks, encoding, stream,
bernoulli=True, explicit=True):
"""
Generate an input file for C{megam} based on the given corpus of
classified tokens.
@type train_toks: C{list} of C{tuples} of (C{dict}, C{str})
@param train_toks: Training data, represented as a list of
pairs, the first member of which is a feature dictionary,
and the second of which is a classification label.
@type encoding: L{MaxentFeatureEncodingI}
@param encoding: A feature encoding, used to convert featuresets
into feature vectors.
@type stream: C{stream}
@param stream: The stream to which the megam input file should be
written.
@param bernoulli: If true, then use the 'bernoulli' format. I.e.,
all joint features have binary values, and are listed iff they
are true. Otherwise, list feature values explicitly. If
C{bernoulli=False}, then you must call C{megam} with the
C{-fvals} option.
@param explicit: If true, then use the 'explicit' format. I.e.,
list the features that would fire for any of the possible
labels, for each token. If C{explicit=True}, then you must
call C{megam} with the C{-explicit} option.
"""
# Look up the set of labels.
labels = encoding.labels()
labelnum = dict([(label, i) for (i, label) in enumerate(labels)])
# Write the file, which contains one line per instance.
for featureset, label in train_toks:
# First, the instance number.
stream.write('%d' % labelnum[label])
# For implicit file formats, just list the features that fire
# for this instance's actual label.
if not explicit:
_write_megam_features(encoding.encode(featureset, label),
stream, bernoulli)
# For explicit formats, list the features that would fire for
# any of the possible labels.
else:
for l in labels:
stream.write(' #')
_write_megam_features(encoding.encode(featureset, l),
stream, bernoulli)
# End of the isntance.
stream.write('\n')
def parse_megam_weights(s, features_count, explicit=True):
"""
Given the stdout output generated by C{megam} when training a
model, return a C{numpy} array containing the corresponding weight
vector. This function does not currently handle bias features.
"""
if numpy is None:
raise ValueError('This function requires that numpy be installed')
assert explicit, 'non-explicit not supported yet'
lines = s.strip().split('\n')
weights = numpy.zeros(features_count, 'd')
for line in lines:
if line.strip():
fid, weight = line.split()
weights[int(fid)] = float(weight)
return weights
def _write_megam_features(vector, stream, bernoulli):
if not vector:
raise ValueError('MEGAM classifier requires the use of an '
'always-on feature.')
for (fid, fval) in vector:
if bernoulli:
if fval == 1:
stream.write(' %s' % fid)
elif fval != 0:
raise ValueError('If bernoulli=True, then all'
'features must be binary.')
else:
stream.write(' %s %s' % (fid, fval))
def call_megam(args):
"""
Call the C{megam} binary with the given arguments.
"""
if isinstance(args, basestring):
raise TypeError('args should be a list of strings')
if _megam_bin is None:
config_megam()
# Call megam via a subprocess
cmd = [_megam_bin] + args
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
(stdout, stderr) = p.communicate()
# Check the return code.
if p.returncode != 0:
print
print stderr
raise OSError('megam command failed!')
return stdout
|
apache-2.0
|
[
3,
653,
292,
4889,
8466,
15650,
6065,
26,
14816,
370,
3194,
17740,
8465,
5541,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
13,
8128,
24719,
15263,
7290,
199,
3,
6529,
26,
17379,
3079,
491,
2262,
665,
379,
320,
529,
32,
7490,
14,
67,
374,
14,
384,
287,
78,
14,
8654,
30,
199,
3,
2851,
26,
665,
1014,
921,
1544,
14,
7530,
2663,
14,
1308,
3133,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
3,
199,
3,
2672,
1304,
26,
19995,
19558,
397,
14,
647,
499,
22653,
8353,
13,
1780,
13,
1196,
7829,
26,
996,
26,
1194,
58,
3988,
320,
529,
2672,
199,
199,
624,
199,
33,
663,
402,
3423,
1202,
370,
3217,
543,
314,
5957,
738,
91,
278,
17740,
199,
28,
1014,
921,
1544,
14,
1259,
14,
337,
11326,
14,
8654,
22500,
19785,
15,
278,
17740,
3133,
93,
1390,
484,
13712,
2559,
14,
199,
13569,
445,
91,
278,
17740,
93,
883,
506,
1202,
12,
1265,
1077,
11480,
24719,
15263,
2382,
652,
883,
2342,
199,
1589,
445,
91,
278,
17740,
93,
3366,
12,
1808,
314,
491,
91,
888,
63,
278,
17740,
12737,
805,
14,
221,
29267,
199,
3807,
26,
339,
1306,
492,
24706,
272,
1306,
24706,
14,
888,
63,
278,
17740,
360,
1396,
15,
515,
15,
475,
15,
278,
17740,
358,
272,
1306,
12429,
275,
24706,
14,
4261,
484,
8508,
14,
2834,
8,
16780,
12,
283,
278,
17740,
358,
199,
199,
624,
199,
363,
21841,
363,
275,
283,
69,
647,
505,
655,
7,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
199,
504,
24706,
14,
4404,
2551,
492,
2342,
63,
3008,
199,
893,
26,
272,
492,
2680,
199,
2590,
3545,
26,
272,
2680,
275,
488,
199,
199,
18022,
199,
3,
91,
11595,
199,
18022,
199,
199,
63,
278,
17740,
63,
1393,
275,
488,
199,
318,
1101,
63,
278,
17740,
8,
1393,
29,
403,
304,
272,
408,
272,
15453,
24719,
15263,
1159,
3217,
370,
314,
445,
91,
278,
17740,
93,
1390,
484,
13712,
272,
2559,
14,
339,
768,
635,
2517,
26,
710,
2615,
931,
370,
314,
445,
91,
278,
17740,
93,
3366,
14,
221,
982,
440,
2013,
12,
267,
2066,
24706,
911,
2754,
314,
2656,
367,
282,
445,
91,
278,
17740,
93,
3366,
27,
436,
340,
267,
1373,
365,
440,
1911,
12,
652,
911,
746,
282,
445,
91,
32060,
93,
1919,
14,
272,
768,
466,
2517,
26,
445,
91,
875,
93,
272,
408,
272,
2288,
485,
278,
17740,
63,
1393,
272,
485,
278,
17740,
63,
1393,
275,
2342,
63,
3008,
8,
267,
283,
278,
17740,
297,
2517,
12,
267,
2589,
63,
2936,
2968,
3635,
39,
1156,
297,
221,
283,
3635,
39,
1156,
9524,
995,
267,
3366,
63,
1247,
2968,
278,
17740,
14,
2992,
297,
283,
278,
17740,
297,
283,
278,
17740,
63,
10253,
297,
283,
278,
17740,
63,
73,
10253,
14,
2992,
995,
267,
1166,
534,
1014,
921,
1544,
14,
1259,
14,
337,
11326,
14,
8654,
22500,
19785,
15,
278,
17740,
6217,
199,
199,
18022,
199,
3,
91,
3194,
17740,
14816,
17471,
199,
18022,
199,
199,
318,
2218,
63,
278,
17740,
63,
493,
8,
2834,
63,
29328,
12,
2644,
12,
2547,
12,
2151,
330,
281,
24992,
29,
549,
12,
5027,
29,
549,
304,
272,
408,
272,
7958,
376,
1324,
570,
367,
445,
91,
278,
17740,
93,
4079,
641,
314,
1627,
16831,
402,
272,
11534,
1290,
4645,
14,
339,
768,
466,
3560,
63,
29328,
26,
445,
91,
513,
93,
402,
445,
91,
11760,
93,
402,
334,
35,
91,
807,
1386,
445,
91,
495,
1552,
272,
768,
635,
3560,
63,
29328,
26,
22859,
666,
12,
11159,
465,
282,
769,
402,
267,
6342,
12,
314,
1642,
3653,
402,
1314,
365,
282,
3878,
2600,
12,
267,
436,
314,
3499,
402,
1314,
365,
282,
12505,
1768,
14,
339,
768,
466,
2644,
26,
491,
91,
4261,
484,
5968,
7630,
41,
93,
272,
768,
635,
2644,
26,
437,
3878,
2644,
12,
1202,
370,
3957,
3878,
2193,
267,
1901,
3878,
11102,
14,
339,
768,
466,
2547,
26,
445,
91,
1745,
93,
272,
768,
635,
2547,
26,
710,
2547,
370,
1314,
314,
562,
17740,
1324,
570,
1077,
506,
267,
5313,
14,
339,
768,
635,
330,
281,
24992,
26,
982,
2549,
12,
2066,
675,
314,
283,
605,
24992,
7,
1475,
14,
221,
473,
14,
69,
2020,
267,
1006,
22211,
4534,
1172,
3366,
1338,
12,
436,
787,
10532,
17963,
2985,
267,
787,
2549,
14,
221,
6630,
12,
769,
3878,
1338,
7662,
14,
221,
982,
267,
445,
91,
605,
24992,
29,
797,
1386,
2066,
1265,
1471,
1240,
445,
91,
278,
17740,
93,
543,
314,
267,
445,
91,
13,
70,
3643,
93,
945,
14,
339,
768,
635,
5027,
26,
982,
2549,
12,
2066,
675,
314,
283,
10306,
7,
1475,
14,
221,
473,
14,
69,
2020,
267,
769,
314,
4534,
626,
3955,
8344,
367,
1263,
402,
314,
3962,
267,
3628,
12,
367,
1924,
1526,
14,
221,
982,
445,
91,
10306,
29,
549,
1386,
2066,
1265,
1471,
267,
1240,
445,
91,
278,
17740,
93,
543,
314,
445,
91,
13,
10306,
93,
945,
14,
272,
408,
272,
327,
12077,
1536,
314,
663,
402,
3628,
14,
272,
3628,
275,
2644,
14,
3512,
342,
272,
1768,
1507,
275,
1211,
7694,
1302,
12,
284,
9,
367,
334,
73,
12,
1768,
9,
315,
3874,
8,
3512,
3948,
339,
327,
6990,
314,
570,
12,
1314,
3509,
1373,
1004,
1126,
1256,
14,
272,
367,
3878,
409,
12,
1768,
315,
3560,
63,
29328,
26,
267,
327,
7758,
12,
314,
1256,
1329,
14,
267,
2547,
14,
952,
3508,
68,
7,
450,
1768,
1507,
59,
1302,
566,
398,
327,
2104,
9227,
570,
6752,
12,
2951,
769,
314,
4534,
626,
8344,
267,
327,
367,
642,
1256,
1159,
3503,
1768,
14,
267,
340,
440,
5027,
26,
288,
485,
952,
63,
278,
17740,
63,
3179,
8,
2991,
14,
2143,
8,
4445,
409,
12,
1768,
395,
3303,
2547,
12,
330,
281,
24992,
9,
398,
327,
2104,
5027,
6752,
12,
769,
314,
4534,
626,
3955,
8344,
367,
267,
327,
1263,
402,
314,
3962,
3628,
14,
267,
587,
26,
288,
367,
634,
315,
3628,
26,
355,
2547,
14,
952,
360,
327,
358,
355,
485,
952,
63,
278,
17740,
63,
3179,
8,
2991,
14,
2143,
8,
4445,
409,
12,
634,
395,
4228,
2547,
12,
330,
281,
24992,
9,
398
] |
[
653,
292,
4889,
8466,
15650,
6065,
26,
14816,
370,
3194,
17740,
8465,
5541,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
13,
8128,
24719,
15263,
7290,
199,
3,
6529,
26,
17379,
3079,
491,
2262,
665,
379,
320,
529,
32,
7490,
14,
67,
374,
14,
384,
287,
78,
14,
8654,
30,
199,
3,
2851,
26,
665,
1014,
921,
1544,
14,
7530,
2663,
14,
1308,
3133,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
3,
199,
3,
2672,
1304,
26,
19995,
19558,
397,
14,
647,
499,
22653,
8353,
13,
1780,
13,
1196,
7829,
26,
996,
26,
1194,
58,
3988,
320,
529,
2672,
199,
199,
624,
199,
33,
663,
402,
3423,
1202,
370,
3217,
543,
314,
5957,
738,
91,
278,
17740,
199,
28,
1014,
921,
1544,
14,
1259,
14,
337,
11326,
14,
8654,
22500,
19785,
15,
278,
17740,
3133,
93,
1390,
484,
13712,
2559,
14,
199,
13569,
445,
91,
278,
17740,
93,
883,
506,
1202,
12,
1265,
1077,
11480,
24719,
15263,
2382,
652,
883,
2342,
199,
1589,
445,
91,
278,
17740,
93,
3366,
12,
1808,
314,
491,
91,
888,
63,
278,
17740,
12737,
805,
14,
221,
29267,
199,
3807,
26,
339,
1306,
492,
24706,
272,
1306,
24706,
14,
888,
63,
278,
17740,
360,
1396,
15,
515,
15,
475,
15,
278,
17740,
358,
272,
1306,
12429,
275,
24706,
14,
4261,
484,
8508,
14,
2834,
8,
16780,
12,
283,
278,
17740,
358,
199,
199,
624,
199,
363,
21841,
363,
275,
283,
69,
647,
505,
655,
7,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
199,
504,
24706,
14,
4404,
2551,
492,
2342,
63,
3008,
199,
893,
26,
272,
492,
2680,
199,
2590,
3545,
26,
272,
2680,
275,
488,
199,
199,
18022,
199,
3,
91,
11595,
199,
18022,
199,
199,
63,
278,
17740,
63,
1393,
275,
488,
199,
318,
1101,
63,
278,
17740,
8,
1393,
29,
403,
304,
272,
408,
272,
15453,
24719,
15263,
1159,
3217,
370,
314,
445,
91,
278,
17740,
93,
1390,
484,
13712,
272,
2559,
14,
339,
768,
635,
2517,
26,
710,
2615,
931,
370,
314,
445,
91,
278,
17740,
93,
3366,
14,
221,
982,
440,
2013,
12,
267,
2066,
24706,
911,
2754,
314,
2656,
367,
282,
445,
91,
278,
17740,
93,
3366,
27,
436,
340,
267,
1373,
365,
440,
1911,
12,
652,
911,
746,
282,
445,
91,
32060,
93,
1919,
14,
272,
768,
466,
2517,
26,
445,
91,
875,
93,
272,
408,
272,
2288,
485,
278,
17740,
63,
1393,
272,
485,
278,
17740,
63,
1393,
275,
2342,
63,
3008,
8,
267,
283,
278,
17740,
297,
2517,
12,
267,
2589,
63,
2936,
2968,
3635,
39,
1156,
297,
221,
283,
3635,
39,
1156,
9524,
995,
267,
3366,
63,
1247,
2968,
278,
17740,
14,
2992,
297,
283,
278,
17740,
297,
283,
278,
17740,
63,
10253,
297,
283,
278,
17740,
63,
73,
10253,
14,
2992,
995,
267,
1166,
534,
1014,
921,
1544,
14,
1259,
14,
337,
11326,
14,
8654,
22500,
19785,
15,
278,
17740,
6217,
199,
199,
18022,
199,
3,
91,
3194,
17740,
14816,
17471,
199,
18022,
199,
199,
318,
2218,
63,
278,
17740,
63,
493,
8,
2834,
63,
29328,
12,
2644,
12,
2547,
12,
2151,
330,
281,
24992,
29,
549,
12,
5027,
29,
549,
304,
272,
408,
272,
7958,
376,
1324,
570,
367,
445,
91,
278,
17740,
93,
4079,
641,
314,
1627,
16831,
402,
272,
11534,
1290,
4645,
14,
339,
768,
466,
3560,
63,
29328,
26,
445,
91,
513,
93,
402,
445,
91,
11760,
93,
402,
334,
35,
91,
807,
1386,
445,
91,
495,
1552,
272,
768,
635,
3560,
63,
29328,
26,
22859,
666,
12,
11159,
465,
282,
769,
402,
267,
6342,
12,
314,
1642,
3653,
402,
1314,
365,
282,
3878,
2600,
12,
267,
436,
314,
3499,
402,
1314,
365,
282,
12505,
1768,
14,
339,
768,
466,
2644,
26,
491,
91,
4261,
484,
5968,
7630,
41,
93,
272,
768,
635,
2644,
26,
437,
3878,
2644,
12,
1202,
370,
3957,
3878,
2193,
267,
1901,
3878,
11102,
14,
339,
768,
466,
2547,
26,
445,
91,
1745,
93,
272,
768,
635,
2547,
26,
710,
2547,
370,
1314,
314,
562,
17740,
1324,
570,
1077,
506,
267,
5313,
14,
339,
768,
635,
330,
281,
24992,
26,
982,
2549,
12,
2066,
675,
314,
283,
605,
24992,
7,
1475,
14,
221,
473,
14,
69,
2020,
267,
1006,
22211,
4534,
1172,
3366,
1338,
12,
436,
787,
10532,
17963,
2985,
267,
787,
2549,
14,
221,
6630,
12,
769,
3878,
1338,
7662,
14,
221,
982,
267,
445,
91,
605,
24992,
29,
797,
1386,
2066,
1265,
1471,
1240,
445,
91,
278,
17740,
93,
543,
314,
267,
445,
91,
13,
70,
3643,
93,
945,
14,
339,
768,
635,
5027,
26,
982,
2549,
12,
2066,
675,
314,
283,
10306,
7,
1475,
14,
221,
473,
14,
69,
2020,
267,
769,
314,
4534,
626,
3955,
8344,
367,
1263,
402,
314,
3962,
267,
3628,
12,
367,
1924,
1526,
14,
221,
982,
445,
91,
10306,
29,
549,
1386,
2066,
1265,
1471,
267,
1240,
445,
91,
278,
17740,
93,
543,
314,
445,
91,
13,
10306,
93,
945,
14,
272,
408,
272,
327,
12077,
1536,
314,
663,
402,
3628,
14,
272,
3628,
275,
2644,
14,
3512,
342,
272,
1768,
1507,
275,
1211,
7694,
1302,
12,
284,
9,
367,
334,
73,
12,
1768,
9,
315,
3874,
8,
3512,
3948,
339,
327,
6990,
314,
570,
12,
1314,
3509,
1373,
1004,
1126,
1256,
14,
272,
367,
3878,
409,
12,
1768,
315,
3560,
63,
29328,
26,
267,
327,
7758,
12,
314,
1256,
1329,
14,
267,
2547,
14,
952,
3508,
68,
7,
450,
1768,
1507,
59,
1302,
566,
398,
327,
2104,
9227,
570,
6752,
12,
2951,
769,
314,
4534,
626,
8344,
267,
327,
367,
642,
1256,
1159,
3503,
1768,
14,
267,
340,
440,
5027,
26,
288,
485,
952,
63,
278,
17740,
63,
3179,
8,
2991,
14,
2143,
8,
4445,
409,
12,
1768,
395,
3303,
2547,
12,
330,
281,
24992,
9,
398,
327,
2104,
5027,
6752,
12,
769,
314,
4534,
626,
3955,
8344,
367,
267,
327,
1263,
402,
314,
3962,
3628,
14,
267,
587,
26,
288,
367,
634,
315,
3628,
26,
355,
2547,
14,
952,
360,
327,
358,
355,
485,
952,
63,
278,
17740,
63,
3179,
8,
2991,
14,
2143,
8,
4445,
409,
12,
634,
395,
4228,
2547,
12,
330,
281,
24992,
9,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
FrancoCotter/ReactTimerAPP
|
node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py
|
2779
|
1665
|
# Copyright (c) 2011 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.
"""gypsh output module
gypsh is a GYP shell. It's not really a generator per se. All it does is
fire up an interactive Python session with a few local variables set to the
variables passed to the generator. Like gypd, it's intended as a debugging
aid, to facilitate the exploration of .gyp structures after being processed
by the input module.
The expected usage is "gyp -f gypsh -D OS=desired_os".
"""
import code
import sys
# All of this stuff about generator variables was lovingly ripped from gypd.py.
# That module has a much better description of what's going on and why.
_generator_identity_variables = [
'EXECUTABLE_PREFIX',
'EXECUTABLE_SUFFIX',
'INTERMEDIATE_DIR',
'PRODUCT_DIR',
'RULE_INPUT_ROOT',
'RULE_INPUT_DIRNAME',
'RULE_INPUT_EXT',
'RULE_INPUT_NAME',
'RULE_INPUT_PATH',
'SHARED_INTERMEDIATE_DIR',
]
generator_default_variables = {
}
for v in _generator_identity_variables:
generator_default_variables[v] = '<(%s)' % v
def GenerateOutput(target_list, target_dicts, data, params):
locals = {
'target_list': target_list,
'target_dicts': target_dicts,
'data': data,
}
# Use a banner that looks like the stock Python one and like what
# code.interact uses by default, but tack on something to indicate what
# locals are available, and identify gypsh.
banner='Python %s on %s\nlocals.keys() = %s\ngypsh' % \
(sys.version, sys.platform, repr(sorted(locals.keys())))
code.interact(banner, local=locals)
|
mit
|
[
3,
1898,
334,
67,
9,
7760,
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,
6179,
609,
1072,
859,
199,
199,
6179,
609,
365,
282,
25686,
5218,
14,
221,
2779,
1159,
440,
7710,
282,
4306,
1126,
542,
14,
221,
2900,
652,
1630,
365,
199,
8935,
1536,
376,
12777,
2018,
2351,
543,
282,
9284,
2257,
2860,
663,
370,
314,
199,
3669,
3032,
370,
314,
4306,
14,
221,
16485,
4902,
68,
12,
652,
1159,
11619,
465,
282,
10201,
199,
21745,
12,
370,
30242,
1051,
323,
314,
31337,
402,
1275,
6179,
13955,
2410,
3769,
7686,
199,
991,
314,
1324,
859,
14,
199,
199,
1918,
1420,
4503,
365,
298,
6179,
446,
70,
4902,
609,
446,
36,
4403,
29,
16035,
63,
736,
1674,
199,
624,
421,
199,
646,
1233,
199,
646,
984,
421,
199,
3,
2900,
402,
642,
8292,
3595,
4306,
2860,
1990,
560,
4007,
590,
8012,
80,
1915,
687,
4902,
68,
14,
647,
14,
199,
3,
10314,
859,
965,
282,
8298,
8034,
1369,
402,
4052,
1159,
9995,
641,
436,
10842,
14,
199,
63,
4679,
63,
5582,
63,
3669,
275,
359,
523,
283,
21623,
63,
6351,
297,
523,
283,
21623,
63,
12273,
297,
523,
283,
23227,
63,
3022,
297,
523,
283,
14853,
63,
3022,
297,
523,
283,
13578,
63,
7321,
63,
5441,
297,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
297,
523,
283,
13578,
63,
7321,
63,
2472,
297,
523,
283,
13578,
63,
7321,
63,
2339,
297,
523,
283,
13578,
63,
7321,
63,
3243,
297,
523,
283,
13772,
63,
23227,
63,
3022,
297,
199,
61,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
199,
93,
199,
199,
509,
373,
315,
485,
4679,
63,
5582,
63,
3669,
26,
523,
4306,
63,
885,
63,
3669,
59,
86,
61,
275,
2650,
4042,
83,
3171,
450,
373,
421,
199,
318,
7958,
2959,
8,
1375,
63,
513,
12,
1347,
63,
7892,
12,
666,
12,
1862,
304,
523,
9480,
275,
469,
267,
283,
1375,
63,
513,
356,
221,
1347,
63,
513,
12,
267,
283,
1375,
63,
7892,
356,
1347,
63,
7892,
12,
267,
283,
576,
356,
260,
666,
12,
489,
789,
819,
327,
3645,
282,
20997,
626,
10734,
2839,
314,
10952,
2018,
1373,
436,
2839,
4052,
523,
327,
1233,
14,
25850,
4440,
701,
849,
12,
1325,
307,
564,
641,
6020,
370,
6623,
4052,
523,
327,
9480,
787,
2808,
12,
436,
10405,
4902,
609,
14,
523,
20997,
534,
4718,
450,
83,
641,
450,
83,
60,
78,
9350,
14,
1612,
342,
275,
450,
83,
60,
2753,
2279,
609,
7,
450,
971,
268,
334,
1274,
14,
1023,
12,
984,
14,
3246,
12,
4700,
8,
5917,
8,
9350,
14,
1612,
16890,
819,
1233,
14,
25850,
8,
13066,
12,
2257,
29,
9350,
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
] |
[
1898,
334,
67,
9,
7760,
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,
6179,
609,
1072,
859,
199,
199,
6179,
609,
365,
282,
25686,
5218,
14,
221,
2779,
1159,
440,
7710,
282,
4306,
1126,
542,
14,
221,
2900,
652,
1630,
365,
199,
8935,
1536,
376,
12777,
2018,
2351,
543,
282,
9284,
2257,
2860,
663,
370,
314,
199,
3669,
3032,
370,
314,
4306,
14,
221,
16485,
4902,
68,
12,
652,
1159,
11619,
465,
282,
10201,
199,
21745,
12,
370,
30242,
1051,
323,
314,
31337,
402,
1275,
6179,
13955,
2410,
3769,
7686,
199,
991,
314,
1324,
859,
14,
199,
199,
1918,
1420,
4503,
365,
298,
6179,
446,
70,
4902,
609,
446,
36,
4403,
29,
16035,
63,
736,
1674,
199,
624,
421,
199,
646,
1233,
199,
646,
984,
421,
199,
3,
2900,
402,
642,
8292,
3595,
4306,
2860,
1990,
560,
4007,
590,
8012,
80,
1915,
687,
4902,
68,
14,
647,
14,
199,
3,
10314,
859,
965,
282,
8298,
8034,
1369,
402,
4052,
1159,
9995,
641,
436,
10842,
14,
199,
63,
4679,
63,
5582,
63,
3669,
275,
359,
523,
283,
21623,
63,
6351,
297,
523,
283,
21623,
63,
12273,
297,
523,
283,
23227,
63,
3022,
297,
523,
283,
14853,
63,
3022,
297,
523,
283,
13578,
63,
7321,
63,
5441,
297,
523,
283,
13578,
63,
7321,
63,
3022,
2339,
297,
523,
283,
13578,
63,
7321,
63,
2472,
297,
523,
283,
13578,
63,
7321,
63,
2339,
297,
523,
283,
13578,
63,
7321,
63,
3243,
297,
523,
283,
13772,
63,
23227,
63,
3022,
297,
199,
61,
199,
199,
4679,
63,
885,
63,
3669,
275,
469,
199,
93,
199,
199,
509,
373,
315,
485,
4679,
63,
5582,
63,
3669,
26,
523,
4306,
63,
885,
63,
3669,
59,
86,
61,
275,
2650,
4042,
83,
3171,
450,
373,
421,
199,
318,
7958,
2959,
8,
1375,
63,
513,
12,
1347,
63,
7892,
12,
666,
12,
1862,
304,
523,
9480,
275,
469,
267,
283,
1375,
63,
513,
356,
221,
1347,
63,
513,
12,
267,
283,
1375,
63,
7892,
356,
1347,
63,
7892,
12,
267,
283,
576,
356,
260,
666,
12,
489,
789,
819,
327,
3645,
282,
20997,
626,
10734,
2839,
314,
10952,
2018,
1373,
436,
2839,
4052,
523,
327,
1233,
14,
25850,
4440,
701,
849,
12,
1325,
307,
564,
641,
6020,
370,
6623,
4052,
523,
327,
9480,
787,
2808,
12,
436,
10405,
4902,
609,
14,
523,
20997,
534,
4718,
450,
83,
641,
450,
83,
60,
78,
9350,
14,
1612,
342,
275,
450,
83,
60,
2753,
2279,
609,
7,
450,
971,
268,
334,
1274,
14,
1023,
12,
984,
14,
3246,
12,
4700,
8,
5917,
8,
9350,
14,
1612,
16890,
819,
1233,
14,
25850,
8,
13066,
12,
2257,
29,
9350,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vinicius-alves/InternetBanking
|
env/lib/python3.4/site-packages/django/contrib/admin/actions.py
|
66
|
3365
|
"""
Built-in, globally-available admin actions.
"""
from django.contrib import messages
from django.contrib.admin import helpers
from django.contrib.admin.utils import get_deleted_objects, model_ngettext
from django.core.exceptions import PermissionDenied
from django.db import router
from django.template.response import TemplateResponse
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _, ugettext_lazy
def delete_selected(modeladmin, request, queryset):
"""
Default action which deletes the selected objects.
This action first displays a confirmation page which shows all the
deleteable objects, or, if the user has no permission one of the related
childs (foreignkeys), a "permission denied" message.
Next, it deletes all selected objects and redirects back to the change list.
"""
opts = modeladmin.model._meta
app_label = opts.app_label
# Check that the user has delete permission for the actual model
if not modeladmin.has_delete_permission(request):
raise PermissionDenied
using = router.db_for_write(modeladmin.model)
# Populate deletable_objects, a data structure of all related objects that
# will also be deleted.
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, opts, request.user, modeladmin.admin_site, using)
# The user has already confirmed the deletion.
# Do the deletion and return a None to display the change list view again.
if request.POST.get('post') and not protected:
if perms_needed:
raise PermissionDenied
n = queryset.count()
if n:
for obj in queryset:
obj_display = force_text(obj)
modeladmin.log_deletion(request, obj, obj_display)
queryset.delete()
modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % {
"count": n, "items": model_ngettext(modeladmin.opts, n)
}, messages.SUCCESS)
# Return None to display the change list page again.
return None
if len(queryset) == 1:
objects_name = force_text(opts.verbose_name)
else:
objects_name = force_text(opts.verbose_name_plural)
if perms_needed or protected:
title = _("Cannot delete %(name)s") % {"name": objects_name}
else:
title = _("Are you sure?")
context = dict(
modeladmin.admin_site.each_context(request),
title=title,
objects_name=objects_name,
deletable_objects=[deletable_objects],
model_count=dict(model_count).items(),
queryset=queryset,
perms_lacking=perms_needed,
protected=protected,
opts=opts,
action_checkbox_name=helpers.ACTION_CHECKBOX_NAME,
media=modeladmin.media,
)
request.current_app = modeladmin.admin_site.name
# Display the confirmation page
return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [
"admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name),
"admin/%s/delete_selected_confirmation.html" % app_label,
"admin/delete_selected_confirmation.html"
], context)
delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s")
|
gpl-3.0
|
[
624,
199,
32406,
13,
262,
12,
26662,
13,
4561,
4628,
5445,
14,
199,
624,
199,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
2113,
492,
10897,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1208,
492,
664,
63,
6062,
63,
1462,
12,
1402,
63,
28234,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
5501,
10366,
63,
6395,
421,
199,
318,
3145,
63,
5511,
8,
1238,
2113,
12,
1056,
12,
7594,
304,
272,
408,
272,
3758,
1595,
1314,
21812,
314,
4895,
2251,
14,
339,
961,
1595,
1642,
17561,
282,
18791,
2034,
1314,
13703,
1006,
314,
272,
3145,
461,
2251,
12,
503,
12,
340,
314,
922,
965,
949,
4983,
1373,
402,
314,
4048,
272,
1982,
83,
334,
6846,
1612,
395,
282,
298,
5693,
23355,
2,
1245,
14,
339,
16840,
12,
652,
21812,
1006,
4895,
2251,
436,
17784,
1771,
370,
314,
1570,
769,
14,
272,
408,
272,
3999,
275,
1402,
2113,
14,
1238,
423,
2024,
272,
1145,
63,
1302,
275,
3999,
14,
571,
63,
1302,
339,
327,
2670,
626,
314,
922,
965,
3145,
4983,
367,
314,
3503,
1402,
272,
340,
440,
1402,
2113,
14,
1989,
63,
1807,
63,
5693,
8,
1069,
304,
267,
746,
23724,
339,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
1238,
2113,
14,
1238,
9,
339,
327,
31731,
6070,
1224,
63,
1462,
12,
282,
666,
5523,
402,
1006,
4048,
2251,
626,
272,
327,
911,
2597,
506,
5463,
14,
272,
6070,
1224,
63,
1462,
12,
1402,
63,
835,
12,
17340,
63,
11368,
12,
17819,
275,
664,
63,
6062,
63,
1462,
8,
267,
7594,
12,
3999,
12,
1056,
14,
751,
12,
1402,
2113,
14,
2113,
63,
2124,
12,
1808,
9,
339,
327,
710,
922,
965,
2575,
22763,
314,
14068,
14,
272,
327,
4226,
314,
14068,
436,
372,
282,
488,
370,
2929,
314,
1570,
769,
2455,
4020,
14,
272,
340,
1056,
14,
4030,
14,
362,
360,
1932,
358,
436,
440,
17819,
26,
267,
340,
17340,
63,
11368,
26,
288,
746,
23724,
267,
302,
275,
7594,
14,
835,
342,
267,
340,
302,
26,
288,
367,
1559,
315,
7594,
26,
355,
1559,
63,
2918,
275,
3542,
63,
505,
8,
1113,
9,
355,
1402,
2113,
14,
793,
63,
14281,
8,
1069,
12,
1559,
12,
1559,
63,
2918,
9,
288,
7594,
14,
1807,
342,
288,
1402,
2113,
14,
1188,
63,
751,
8,
1069,
12,
3824,
25001,
5463,
2818,
835,
9,
68,
2818,
1744,
9,
83,
2685,
450,
469,
355,
298,
835,
582,
302,
12,
298,
1744,
582,
1402,
63,
28234,
8,
1238,
2113,
14,
3291,
12,
302,
9,
288,
1660,
3788,
14,
12779,
9,
267,
327,
1432,
488,
370,
2929,
314,
1570,
769,
2034,
4020,
14,
267,
372,
488,
339,
340,
822,
8,
7924,
9,
508,
413,
26,
267,
2251,
63,
354,
275,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
9,
272,
587,
26,
267,
2251,
63,
354,
275,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
63,
10019,
9,
339,
340,
17340,
63,
11368,
503,
17819,
26,
267,
2538,
275,
3824,
6612,
3145,
2818,
354,
9,
83,
531,
450,
2420,
354,
582,
2251,
63,
354,
93,
272,
587,
26,
267,
2538,
275,
3824,
17683,
1265,
3238,
18582,
339,
1067,
275,
1211,
8,
267,
1402,
2113,
14,
2113,
63,
2124,
14,
10885,
63,
1100,
8,
1069,
395,
267,
2538,
29,
1213,
12,
267,
2251,
63,
354,
29,
1462,
63,
354,
12,
267,
6070,
1224,
63,
1462,
1524,
7346,
1224,
63,
1462,
467,
267,
1402,
63,
835,
29,
807,
8,
1238,
63,
835,
680,
1744,
1062,
267,
7594,
29,
7924,
12,
267,
17340,
63,
5143,
316,
29,
12068,
63,
11368,
12,
267,
17819,
29,
6798,
12,
267,
3999,
29,
3291,
12,
267,
1595,
63,
13456,
63,
354,
29,
7546,
14,
10052,
63,
8936,
15694,
63,
2339,
12,
267,
5898,
29,
1238,
2113,
14,
4603,
12,
272,
776,
339,
1056,
14,
1818,
63,
571,
275,
1402,
2113,
14,
2113,
63,
2124,
14,
354,
339,
327,
12175,
314,
18791,
2034,
272,
372,
29264,
8,
1069,
12,
1402,
2113,
14,
1807,
63,
5511,
63,
20903,
63,
1160,
503,
359,
267,
298,
2113,
3149,
83,
3149,
83,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
450,
334,
571,
63,
1302,
12,
3999,
14,
1238,
63,
354,
395,
267,
298,
2113,
3149,
83,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
450,
1145,
63,
1302,
12,
267,
298,
2113,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
272,
2156,
1067,
9,
199,
199,
1807,
63,
5511,
14,
3612,
63,
1802,
275,
10366,
63,
6395,
480,
5392,
4895,
2818,
3832,
63,
354,
63,
10019,
9,
83,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
32406,
13,
262,
12,
26662,
13,
4561,
4628,
5445,
14,
199,
624,
199,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
2113,
492,
10897,
199,
504,
1639,
14,
2828,
14,
2113,
14,
1208,
492,
664,
63,
6062,
63,
1462,
12,
1402,
63,
28234,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
697,
492,
6197,
199,
504,
1639,
14,
1160,
14,
1310,
492,
29264,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
5501,
10366,
63,
6395,
421,
199,
318,
3145,
63,
5511,
8,
1238,
2113,
12,
1056,
12,
7594,
304,
272,
408,
272,
3758,
1595,
1314,
21812,
314,
4895,
2251,
14,
339,
961,
1595,
1642,
17561,
282,
18791,
2034,
1314,
13703,
1006,
314,
272,
3145,
461,
2251,
12,
503,
12,
340,
314,
922,
965,
949,
4983,
1373,
402,
314,
4048,
272,
1982,
83,
334,
6846,
1612,
395,
282,
298,
5693,
23355,
2,
1245,
14,
339,
16840,
12,
652,
21812,
1006,
4895,
2251,
436,
17784,
1771,
370,
314,
1570,
769,
14,
272,
408,
272,
3999,
275,
1402,
2113,
14,
1238,
423,
2024,
272,
1145,
63,
1302,
275,
3999,
14,
571,
63,
1302,
339,
327,
2670,
626,
314,
922,
965,
3145,
4983,
367,
314,
3503,
1402,
272,
340,
440,
1402,
2113,
14,
1989,
63,
1807,
63,
5693,
8,
1069,
304,
267,
746,
23724,
339,
1808,
275,
6197,
14,
697,
63,
509,
63,
952,
8,
1238,
2113,
14,
1238,
9,
339,
327,
31731,
6070,
1224,
63,
1462,
12,
282,
666,
5523,
402,
1006,
4048,
2251,
626,
272,
327,
911,
2597,
506,
5463,
14,
272,
6070,
1224,
63,
1462,
12,
1402,
63,
835,
12,
17340,
63,
11368,
12,
17819,
275,
664,
63,
6062,
63,
1462,
8,
267,
7594,
12,
3999,
12,
1056,
14,
751,
12,
1402,
2113,
14,
2113,
63,
2124,
12,
1808,
9,
339,
327,
710,
922,
965,
2575,
22763,
314,
14068,
14,
272,
327,
4226,
314,
14068,
436,
372,
282,
488,
370,
2929,
314,
1570,
769,
2455,
4020,
14,
272,
340,
1056,
14,
4030,
14,
362,
360,
1932,
358,
436,
440,
17819,
26,
267,
340,
17340,
63,
11368,
26,
288,
746,
23724,
267,
302,
275,
7594,
14,
835,
342,
267,
340,
302,
26,
288,
367,
1559,
315,
7594,
26,
355,
1559,
63,
2918,
275,
3542,
63,
505,
8,
1113,
9,
355,
1402,
2113,
14,
793,
63,
14281,
8,
1069,
12,
1559,
12,
1559,
63,
2918,
9,
288,
7594,
14,
1807,
342,
288,
1402,
2113,
14,
1188,
63,
751,
8,
1069,
12,
3824,
25001,
5463,
2818,
835,
9,
68,
2818,
1744,
9,
83,
2685,
450,
469,
355,
298,
835,
582,
302,
12,
298,
1744,
582,
1402,
63,
28234,
8,
1238,
2113,
14,
3291,
12,
302,
9,
288,
1660,
3788,
14,
12779,
9,
267,
327,
1432,
488,
370,
2929,
314,
1570,
769,
2034,
4020,
14,
267,
372,
488,
339,
340,
822,
8,
7924,
9,
508,
413,
26,
267,
2251,
63,
354,
275,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
9,
272,
587,
26,
267,
2251,
63,
354,
275,
3542,
63,
505,
8,
3291,
14,
3832,
63,
354,
63,
10019,
9,
339,
340,
17340,
63,
11368,
503,
17819,
26,
267,
2538,
275,
3824,
6612,
3145,
2818,
354,
9,
83,
531,
450,
2420,
354,
582,
2251,
63,
354,
93,
272,
587,
26,
267,
2538,
275,
3824,
17683,
1265,
3238,
18582,
339,
1067,
275,
1211,
8,
267,
1402,
2113,
14,
2113,
63,
2124,
14,
10885,
63,
1100,
8,
1069,
395,
267,
2538,
29,
1213,
12,
267,
2251,
63,
354,
29,
1462,
63,
354,
12,
267,
6070,
1224,
63,
1462,
1524,
7346,
1224,
63,
1462,
467,
267,
1402,
63,
835,
29,
807,
8,
1238,
63,
835,
680,
1744,
1062,
267,
7594,
29,
7924,
12,
267,
17340,
63,
5143,
316,
29,
12068,
63,
11368,
12,
267,
17819,
29,
6798,
12,
267,
3999,
29,
3291,
12,
267,
1595,
63,
13456,
63,
354,
29,
7546,
14,
10052,
63,
8936,
15694,
63,
2339,
12,
267,
5898,
29,
1238,
2113,
14,
4603,
12,
272,
776,
339,
1056,
14,
1818,
63,
571,
275,
1402,
2113,
14,
2113,
63,
2124,
14,
354,
339,
327,
12175,
314,
18791,
2034,
272,
372,
29264,
8,
1069,
12,
1402,
2113,
14,
1807,
63,
5511,
63,
20903,
63,
1160,
503,
359,
267,
298,
2113,
3149,
83,
3149,
83,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
450,
334,
571,
63,
1302,
12,
3999,
14,
1238,
63,
354,
395,
267,
298,
2113,
3149,
83,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
450,
1145,
63,
1302,
12,
267,
298,
2113,
15,
1807,
63,
5511,
63,
20903,
14,
1360,
2,
272,
2156,
1067,
9,
199,
199,
1807,
63,
5511,
14,
3612,
63,
1802,
275,
10366,
63,
6395,
480,
5392,
4895,
2818,
3832,
63,
354,
63,
10019,
9,
83,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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